Commit 1fed6bb4 authored by Romina Julieta Parada Venossa's avatar Romina Julieta Parada Venossa
Browse files

frontiers have only one critical

parent 06ef4343
......@@ -11,21 +11,34 @@ DisMapIC::CellData::CellData() {
dist = MAXFLOAT;
is_cleared = true;
to_raise = false;
first_source = NULL_POS;
}
void DisMapIC::CellData::clear_cell() {
dist = MAXFLOAT;
is_cleared = true;
sources.clear();
first_source = NULL_POS;
}
// recheck sources of n removing the invalid ones O(1) as you can only
// have up to 8 equidistant sources in a 2D grid
void DisMapIC::clean_invalid_sources(pos_set& sources) {
void DisMapIC::clean_invalid_sources(pos p) {
CellData& cd = cell_data[p];
pos_set& sources = cd.sources;
for (auto it = sources.begin(); it != sources.end();) {
pos source = (*it);
if (cell_data[source].dist!=0) {
it = sources.erase(it);
if (source == cd.first_source) {
save_frontier_old_source(p);
if(sources.empty()){
cd.first_source = NULL_POS;
}else{
cd.first_source = (*sources.begin());
}
}
} else {
++it;
}
......@@ -35,8 +48,9 @@ void DisMapIC::clean_invalid_sources(pos_set& sources) {
/* returns true only if the cd has a valid source and
has a parent thats also has a parent.
reason: not taking the next ring of a raise as valid */
bool DisMapIC::valid(CellData cd){
clean_invalid_sources(cd.sources);
bool DisMapIC::valid(pos p){
CellData& cd = cell_data[p];
clean_invalid_sources(p);
if(cd.sources.empty() || cd.parents.empty()){
return false;
}
......@@ -50,13 +64,18 @@ bool DisMapIC::valid(CellData cd){
}
// save in a map (frontier, old sources)
void DisMapIC::save_frontier_old_sources(pos frontier, bool empty_sources = false){
void DisMapIC::save_frontier_old_source(pos frontier){
// if is frontier and is the first time to save on the iteration
if(is_elem((*frontiers), frontier) && !is_elem(updated_frontiers, frontier)){
if(!empty_sources){
updated_frontiers[frontier] = cell_data[frontier].sources;
pos first_source = cell_data[frontier].first_source;
if(first_source != NULL_POS){
//updated_frontiers[frontier] = cell_data[frontier].first_source;
updated_frontiers[frontier].clear();
updated_frontiers[frontier].insert(first_source);
//updated_frontiers[frontier] = cell_data[frontier].sources;
}else{
updated_frontiers[frontier] = pos_set();
//updated_frontiers[frontier] = NULL_POS;
updated_frontiers[frontier].clear();
}
}
}
......@@ -75,7 +94,7 @@ void DisMapIC::process_lower(pos p) {
if (d < n_cd.dist) {
//specific for critic detection
//if is a frontier then save old sources
save_frontier_old_sources(n);
save_frontier_old_source(n);
// cout << "lowered: " <<n << endl;
n_cd.dist = d;
......@@ -84,6 +103,7 @@ void DisMapIC::process_lower(pos p) {
n_cd.parents.insert(p);
n_cd.sources.clear();
n_cd.sources.insert(p_cd.sources.begin(), p_cd.sources.end());
n_cd.first_source = (*p_cd.sources.begin());
n_cd.is_cleared = false;
open.push(make_pair(d, n));
......@@ -91,7 +111,7 @@ void DisMapIC::process_lower(pos p) {
//specific for critic detection
//if is a frontier then add it to the map so it will update critis
//should use a different collection(different meaning)
save_frontier_old_sources(n, false);
//save_frontier_old_source(n, false);
n_cd.parents.insert(p);
n_cd.sources.insert(p_cd.sources.begin(), p_cd.sources.end());
......@@ -115,7 +135,7 @@ void DisMapIC::process_raise(pos p) {
// if n is not valid it should propagate the process raise
n_cd.parents.erase(p);
//cout<<n<<" parents "<<n_cd.parents<<endl;
if (!valid(n_cd)) {
if (!valid(n)) {
// cout << "raised: " <<n << endl;
open.push(make_pair(n_cd.dist, n));
n_cd.clear_cell();
......@@ -143,13 +163,14 @@ void DisMapIC::process_raise(pos p) {
if (min_d < MAXFLOAT) {
//specific for critic detection
//if is a frontier then save old sources
save_frontier_old_sources(p);
save_frontier_old_source(p);
p_cd.dist = min_d;
p_cd.parents.clear();
p_cd.parents.insert(p_parents.begin(), p_parents.end());
p_cd.sources.clear();
p_cd.sources.insert(p_closest_sources.begin(), p_closest_sources.end());
p_cd.first_source = (*p_cd.sources.begin());
p_cd.is_cleared = false;
open.push(make_pair(p_cd.dist, p));
}
......@@ -166,7 +187,7 @@ void DisMapIC::set_consistent_borders(vector<pos> obstructed_to_free) {
for (auto it = adj_p.begin(); it != adj_p.end(); it++) {
pos n = (*it);
CellData& n_cd = cell_data[n];
if (valid(n_cd) && !is_elem(inserted, p)) {
if (valid(n) && !is_elem(inserted, p)) {
// cout << " border:"<<n << endl;
open.push(make_pair(n_cd.dist, n));
inserted.insert(n);
......@@ -184,6 +205,7 @@ void DisMapIC::set_source(pos p) {
p_cd.parents.insert(p);
p_cd.sources.clear();
p_cd.sources.insert(p);
p_cd.first_source = p;
p_cd.is_cleared = false;
open.push(make_pair(0, p));
}
......@@ -262,7 +284,7 @@ void DisMapIC::raise_and_lower(){
if (p_cd.to_raise) {
//cout << "Process RAISE "<<p << endl;
process_raise(p);
} else if (valid(p_cd)) {
} else if (valid(p)) {
//cout << "Process LOWER "<<p << endl;
process_lower(p);
}
......
......@@ -11,6 +11,7 @@ class DisMapIC{
struct CellData {
float dist;
pos first_source;
pos_set sources;
pos_set parents;
......@@ -27,8 +28,8 @@ class DisMapIC{
CellDataPQ open;
// functions
bool valid(CellData cd);
void clean_invalid_sources(pos_set& sources);
bool valid(pos p);
void clean_invalid_sources(pos p);
void check_voro(pos s, pos n);
void set_source(pos p);
......@@ -62,7 +63,7 @@ class DisMapIC{
boost::unordered_map<pos, pos_set> updated_frontiers;
//pos_set new_frontiers;
void save_frontier_old_sources(pos frontier, bool empty_sources);
void save_frontier_old_source(pos frontier);
void update_distance_map(pos_set source_to_true, pos_set source_to_false);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment