diff --git a/ksimplex.cpp b/ksimplex.cpp index 1754373..eb3cb27 100644 --- a/ksimplex.cpp +++ b/ksimplex.cpp @@ -25,8 +25,8 @@ KSimplex::~KSimplex(){ bool KSimplex::find_neighbor(KSimplex *kSimplex){ if(!kSimplex) return false; - int k = kSimplex->k; - for(auto &it : neighbors->elements[k]) + int k1 = kSimplex->k; + for(auto &it : neighbors->elements[k1]) if(it == kSimplex) return true; return false; @@ -37,6 +37,7 @@ bool KSimplex::find_neighbor(KSimplex *kSimplex){ // Whenever a neighbor is added to current one, // current one is also added to neighbor. void KSimplex::add_neighbor(KSimplex *kSimplex){ + int k2; if(!kSimplex) return; int k1 = kSimplex->k; // extract dimension @@ -48,17 +49,27 @@ void KSimplex::add_neighbor(KSimplex *kSimplex){ log_report(LOG_ERROR, "You have tried to connect two simplices of the same level as neighbors! This is wrong and should never happen, skipping. Fix your code."); return; } - if(!find_neighbor(kSimplex)){ // if doesn't exist already + if(!find_neighbor(kSimplex)){ // if kSimplex is not already my neighbor neighbors->elements[k1].push_back(kSimplex); // add it as a neighbor } - if(!kSimplex->find_neighbor(this)) // add me as a neigbhor to it as well - kSimplex->neighbors->elements[k].push_back(this); - if(k1){ // recursivelly add neighbors at k-1,..0: - for(auto &it : kSimplex->neighbors->elements[k1 - 1]) - add_neighbor(it); + if(!kSimplex->find_neighbor(this)){ // if I am not already his neighbor + kSimplex->neighbors->elements[k].push_back(this); // add me as his neigbhor as well + } + if(k1 && k>k1){ // if kSimplex is my subsimplex (k>k1) and is not a vertex (k1!=0), then add all his neighbor subsimplices (k1-1,...,0) as my neighbors: + for (k2=0 ; k2neighbors->elements[k2]) + add_neighbor(it); + } + } + if(k && kelements[k2]) + kSimplex->add_neighbor(it); + } } } + // Collects neighboring vertices into a set: void KSimplex::collect_vertices(set &s){ // If this k-simplex is a vertex, return it: diff --git a/main.cpp b/main.cpp index bbd324b..7955301 100644 --- a/main.cpp +++ b/main.cpp @@ -10,14 +10,12 @@ int main(){ cout << "############ BEGINNING OF THE MAIN FUNCTION ###########" << endl; cout << "#######################################################" << endl << endl; - SimpComp *g1 = seed_sphere(3,"obicna 3-sfera"); + SimpComp *g1 = seed_sphere(3,"obicna 2-sfera"); UniqueIDColor::colorize_entire_complex(g1); - // g1->print_detailed(); + g1->print_detailed(); - KSimplex *s1 = g1->elements[2][0]; - KSimplex *s2 = g1->elements[2][1]; - s1->add_neighbor(s1); - s1->add_neighbor(s2); + // KSimplex *s1 = g1->elements[2][0]; + // KSimplex *s2 = g1->elements[2][1];