Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Federico Ciuffardi Alves
pgMappingCooperativo
Commits
009b7fdf
Commit
009b7fdf
authored
Oct 19, 2020
by
Federico Ciuffardi
Browse files
obst_condition refactor
parent
ad73d466
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/lib/GVD/GVDIC.cpp
View file @
009b7fdf
...
...
@@ -31,63 +31,55 @@ pos_set updated_obst_size;
// wrapers to set (or replace) and to insert (or union) obstacles that checks if obst_cond_to_false must be modified
void
GVDIC
::
set_obsts
(
CellDataO
&
cd
,
pos_set
new_obsts
,
pos
p
){
cd
.
obsts
=
new_obsts
;
int
new_size
=
cd
.
obsts
.
size
();
if
(
cd
.
old_obsts_size
>
1
&&
new_size
>
1
){
// must be called after a obsts update
void
obsts_updated_hook
(
pos
p
,
int
old_size
,
int
pre_update_size
,
int
updated_size
,
bool
is_obst
=
false
){
if
(
pre_update_size
==
updated_size
){
return
;
}
if
(
!
is_obst
&&
old_size
>
1
&&
updated_size
<=
1
){
/* cout<<"insert "<<p<<endl; */
obst_cond_to_false
.
insert
(
p
);
}
if
(
old_size
>
1
&&
updated_size
>
1
){
obst_cond_to_false
.
erase
(
p
);
}
if
(
cd
.
old_obsts
_size
!=
new
_size
){
if
(
old
_size
!=
updated
_size
){
updated_obst_size
.
insert
(
p
);
}
else
{
updated_obst_size
.
erase
(
p
);
}
}
void
GVDIC
::
set_obsts
(
CellDataO
&
cd
,
pos_set
new_obsts
,
pos
p
){
int
pre_updated_size
=
cd
.
obsts
.
size
();
cd
.
obsts
=
new_obsts
;
obsts_updated_hook
(
p
,
cd
.
old_obsts_size
,
pre_updated_size
,
cd
.
obsts
.
size
());
}
void
GVDIC
::
set_obsts
(
CellDataO
&
cd
,
vector
<
pos
>
new_obsts
,
pos
p
){
int
pre_updated_size
=
cd
.
obsts
.
size
();
cd
.
obsts
.
clear
();
cd
.
obsts
.
insert
(
new_obsts
.
begin
(),
new_obsts
.
end
());
int
new_size
=
cd
.
obsts
.
size
();
if
(
cd
.
old_obsts_size
>
1
&&
new_size
>
1
){
obst_cond_to_false
.
erase
(
p
);
}
if
(
cd
.
old_obsts_size
!=
new_size
){
updated_obst_size
.
insert
(
p
);
}
else
{
updated_obst_size
.
erase
(
p
);
}
obsts_updated_hook
(
p
,
cd
.
old_obsts_size
,
pre_updated_size
,
cd
.
obsts
.
size
());
}
void
GVDIC
::
insert_obsts
(
CellDataO
&
cd
,
pos_set
new_obsts
,
pos
p
){
int
pre_updated_size
=
cd
.
obsts
.
size
();
cd
.
obsts
.
insert
(
new_obsts
.
begin
(),
new_obsts
.
end
());
int
new_size
=
cd
.
obsts
.
size
();
if
(
cd
.
old_obsts_size
>
1
&&
new_size
>
1
){
obst_cond_to_false
.
erase
(
p
);
}
if
(
cd
.
old_obsts_size
!=
new_size
){
updated_obst_size
.
insert
(
p
);
}
else
{
updated_obst_size
.
erase
(
p
);
}
obsts_updated_hook
(
p
,
cd
.
old_obsts_size
,
pre_updated_size
,
cd
.
obsts
.
size
());
}
void
GVDIC
::
insert_obsts
(
CellDataO
&
cd
,
vector
<
pos
>
new_obsts
,
pos
p
){
int
pre_updated_size
=
cd
.
obsts
.
size
();
cd
.
obsts
.
insert
(
new_obsts
.
begin
(),
new_obsts
.
end
());
int
new_size
=
cd
.
obsts
.
size
();
if
(
cd
.
old_obsts_size
>
1
&&
new_size
>
1
){
obst_cond_to_false
.
erase
(
p
);
}
if
(
cd
.
old_obsts_size
!=
new_size
){
updated_obst_size
.
insert
(
p
);
}
else
{
updated_obst_size
.
erase
(
p
);
}
obsts_updated_hook
(
p
,
cd
.
old_obsts_size
,
pre_updated_size
,
cd
.
obsts
.
size
());
}
// recheck obstacles of n removing the invalid ones O(1) as you can only
// have up to 8 equidistant obstacles in a 2D grid
bool
GVDIC
::
is_occ
(
CellDataO
&
cd
,
pos
p
)
{
int
pre_updated_size
=
cd
.
obsts
.
size
();
for
(
auto
it
=
cd
.
obsts
.
begin
();
it
!=
cd
.
obsts
.
end
();)
{
pos
obst
=
(
*
it
);
if
(
gt
[
obst
.
first
][
obst
.
second
]
!=
Occupied
)
{
...
...
@@ -96,18 +88,7 @@ bool GVDIC::is_occ(CellDataO& cd, pos p) {
++
it
;
}
}
int
new_size
=
cd
.
obsts
.
size
();
// cout << p << "(" << cd.old_obsts_size << "," << new_size << ")" << endl;
// cd.dist > 0 if and only if p is not an obstacle
if
(
cd
.
old_obsts_size
>
1
&&
new_size
<=
1
&&
cd
.
dist
>
0
){
/* cout<<"insert "<<p<<endl; */
obst_cond_to_false
.
insert
(
p
);
}
if
(
cd
.
old_obsts_size
!=
new_size
){
updated_obst_size
.
insert
(
p
);
}
else
{
updated_obst_size
.
erase
(
p
);
}
obsts_updated_hook
(
p
,
cd
.
old_obsts_size
,
pre_updated_size
,
cd
.
obsts
.
size
(),
cd
.
dist
==
0
);
return
cd
.
obsts
.
size
()
>
0
;
}
...
...
@@ -159,7 +140,7 @@ void GVDIC::set_voro(bool value, pos n) {
if
(
!
is_elem
(
gvd
.
full_graph
,
n
)){
voro_to_true
.
insert
(
n
);
}
else
{
// could check if the distance actually changes to avoid adding n
// could check if the distance actually changes to avoid adding n
when not necessary
if
(
n_cd
.
dist
!=
n_cd
.
dist_old
){
distance_update
.
insert
(
n
);
}
else
{
...
...
@@ -170,8 +151,8 @@ void GVDIC::set_voro(bool value, pos n) {
}
else
{
if
(
is_elem
(
gvd
.
full_graph
,
n
)){
voro_to_false
.
insert
(
n
);
}
else
{
distance_update
.
erase
(
n
);
}
else
{
voro_to_true
.
erase
(
n
);
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment