shape_doc 0.1
/Users/mourrain/Devel/mmx/shape/src/ssi_dsearch_search.cpp
Go to the documentation of this file.
00001 
00002 #include <shape/ssi_dsearch.hpp>
00003 
00004 namespace mmx {
00005 namespace  shape_ssi {
00006 
00007 // search specialisation s is known to be a leaf
00008 void dsearch::search_f(  qtree f, qtree const s )
00009 {
00010 
00011   if (intersectp(f->box,s->box))
00012     {
00013       f->split(this);
00014       if ( leaf(f) ){ push_f(f,s); return; };
00015       search_f(f->l,s);
00016       search_f(f->r,s);
00017     };
00018 };
00019 
00020 // same thing here f is a leaf
00021 void dsearch::search_s(   qtree const f, qtree s )
00022 {
00023 
00024   if ( intersectp( f->box, s->box ) )
00025     {
00026       s->split(this);
00027       if ( leaf(s) ) { push_s(f,s); return; };
00028       search_s(f,s->l);
00029       search_s(f,s->r);
00030     };
00031 };
00032 
00033 // search generic case: both f and s are root node
00034 void dsearch::search(  qtree f, qtree s )
00035 {
00036 
00037 
00038   // if there bounding boxes intersect
00039   if ( intersectp(f->box,s->box) )
00040     {
00041       // compute if needed the next level in the hierarchy
00042       f->split(this);
00043       s->split(this);
00044       // if f and s are root node
00045       if ( !(f->leaf()) && !(s->leaf()) )
00046         {
00047           // check all the possible intersection between  sons
00048           search(f->l,s->l), search(f->l,s->r);
00049           search(f->r,s->l), search(f->r,s->r);
00050           return;
00051         };
00052       
00053       // s is leaf (not f) switch to specialized case
00054       if ( !leaf(f) ) 
00055           {
00056             search_f(f->l,s);
00057             search_f(f->r,s);
00058             return;
00059           };
00060         // same thing with f
00061       if ( !leaf(s) ) 
00062         {
00063           search_s(f,s->l);
00064           search_s(f,s->r);
00065           return;
00066         };
00067         // two unit quad had been reached push the conflict
00068       // the function push( qtree, qtree ) compute the intersection on the fly if any
00069       push(f,s);
00070     };
00071   };
00072 
00073 // launch the search for region i vs region j
00074 void dsearch::search( rid_t i, rid_t j )
00075 {
00076   curr_config = new std::vector< dcurve* >();
00077   search( this->trees[i], this->trees[j] ); 
00078 };
00079 
00080 }
00081 
00082 } //namespace mmx
00083