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

GVD add_v

parent edf4dad8
......@@ -168,6 +168,7 @@ struct collapsedGraph : genericGraph<graph> {
// syncronized structure (collapse gvd needs uncollapse to add and remove vertexs)
boost::unordered_set<pos> full_graph;
boost::unordered_map<pos, bool> is_local_min;
// vertex is uncollapsed
bool is_uncollapsed(pos p) { return is_elem(this->positions, p); }
......@@ -177,7 +178,8 @@ struct collapsedGraph : genericGraph<graph> {
// TODO
bool is_collapsable(pos p) {
return true; //! is_min(p) && deg(p) == 2;
return super::deg(p) == 2 && !is_local_min[p];
}
bool is_uncollapsable(pos p) { return !is_collapsable(p); }
......@@ -219,10 +221,16 @@ struct collapsedGraph : genericGraph<graph> {
// TODO
void collapse(pos p) {
pos_set adj = all_adj(p);
for (auto it = adj.begin(); it != adj.end(); it++) {
// if()
AdjacencyIterator it, it_end;
boost::tie(it, it_end) = super::neighbors(p);
pos adj1 = this->g[*it].p - p;
++it;
pos adj2 = this->g[*it].p - p;
if(same_direction(adj1,adj2)){
super::add_e(adj1, adj2);
super::erase_v(p);
}
}
......@@ -269,6 +277,15 @@ struct collapsedGraph : genericGraph<graph> {
void add_v(pos p) {
if (is_elem(full_graph, p)) {
/// update local min
if(is_local_min[p]){
if(is_collapsed(p)){
uncollapse(p)
}
}else if is_uncollapsed(p){
if(is_collapsable(p)){
collapse(p);
}
}
return;
}
......@@ -279,10 +296,13 @@ struct collapsedGraph : genericGraph<graph> {
// 1. uncolloapse collapsed neighbors of p
uncollapse_neighbors(p, true);
// 2. connect all the neighbors of p
// 2. connect all the neighbors of p (already done in step 1)
// 3. collapse p if possible
collapse(p);
if(is_collapsable(p)){
collapse(p);
}
// 4. collapse neighbors of p if possible
collapse_neighbors(p);
......
......@@ -74,14 +74,17 @@ void GVDIC::CellDataC::clear_cell() {
void GVDIC::set_voro(bool value, pos n) {
CellDataO& n_cd = cell_data_o[n];
if (!value && !n_cd.is_voro)
return;
//coment this if
//if (!value && !n_cd.is_voro)
//return;
// cout<<"Celda: "<<n<<" valor: "<<value<<endl;
if (value) {
voro_to_true.insert(n);
// if n in !full
voro_to_true.insert(n);
voro_to_false.erase(n); // TODO maybe there is a more efficient way to control the changes
} else {
voro_to_false.insert(n);
// if n in full
voro_to_false.insert(n);
voro_to_true.erase(n); // TODO maybe there is a more efficient way to control the changes
}
n_cd.is_voro = value;
......@@ -412,7 +415,8 @@ boost::tuple<pos_set, pos_set> GVDIC::erosion(pos_set voro_to_true) {
cell_data_o[p].is_voro = false;
to_erase.insert(p);
} else {
to_add.insert(p);
//if is !in full
to_add.insert(p);
}
}
return boost::make_tuple(to_add, to_erase);
......@@ -426,8 +430,9 @@ void GVDIC::update_gvd() {
for (auto it = to_erase_gvd.begin(); it != to_erase_gvd.end(); it++) {
gvd.erase_v(*it);
}
// FEDE check if neighbors of erased vertices are on erase_gvd or to_add_gvd
// gvd.min[pos] = local_min_cnd
//recorrer el set generado y hacer esto
gvd.local_min[pos] = is_local_min(p)
//set de cosas
gvd.add_v(to_add_gvd);
update_possible_crit(to_add_gvd, to_erase_gvd);
......
idea: separar cosas a agregar de cosas a updatear
calcular el minimo local a aquellso que puedan cambiar
updates:
- los que se agregan
- los vecinos de los que se agregan
Ej: aparece un vecino nuevo, sigo siendo minimo local? (o puedo ser)
- los que se remueven <-- no pertenece al gvd
- los vecinos de los que se remueven
Ej: si se fue un vecino, puedo ser minimo local? (o sigo siendo)
- vertices que pertenecen y ya pertenecian y cambiaron su disntacia (distance_updated)
----------------
# vertices que deben actualizar su valor de min
for p in to_add_gvd + to_remove_gvd + distance_updated
if p.is_voro
add_to_update_min(p)
for cada vecino n de p
if n.is_voro
add_to_update_min(n)
---------------
set update_min
// actualizar g.is_min
# Remover todo
erase_v(to_remove_gvd)
# Agregar
add_v(to_add_gvd)
# Update
to_update_gvd = update_min - to_add_gvd
g.update_v(to_update_gvd)
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