shape_doc 0.1
/Users/mourrain/Devel/mmx/shape/src/ssi_dsearch_dcurve.cpp
Go to the documentation of this file.
00001 #include <shape/ssi_dsearch.hpp>
00002 
00003 namespace mmx {
00004 
00005 namespace shape_ssi {
00006   
00007   dcurve::dcurve( const point2& l, const point2& r, const point3& i ) 
00008   {
00009     owner = this;
00010     left.push_back(l);
00011     right.push_back(r);
00012     inter.push_back(i);
00013     size = 1;
00014   };
00015   
00016   dcurve::dcurve( const point2& l0, const point2& l1, const point2& r0, const point2& r1, 
00017                   const point3& i0, const point3& i1 )
00018   {
00019     owner = this;
00020     left.push_back(l0);
00021     left.push_back(l1);
00022     right.push_back(r0);
00023     right.push_back(r1);
00024     inter.push_back(i0);
00025     inter.push_back(i1);
00026     size = 2;
00027   };
00028   
00029   
00030   dcurve * curve( pdpoint_t * p )
00031   { 
00032     dcurve * tmp      = p->curve;
00033     while( tmp->owner != tmp ) tmp = tmp->owner;
00034     p->curve->owner   = tmp;
00035     //      p->curve = tmp;
00036     return tmp;
00037   };
00038   
00039   dcurve *  curve( sdpoint_t * p )
00040   { 
00041     dcurve *  tmp      = p->curve;
00042     while( tmp->owner != tmp ) tmp = tmp->owner;
00043     p->curve->owner   = tmp;
00044     //      p->curve = tmp;
00045     return tmp;
00046   };
00047   
00048   
00049   void extremums( sdpoint_t* dst, dcurve* src )
00050   {
00051     dst[0].curve = src;
00052     dst[0].idl   = src->left.begin(); 
00053     dst[0].idr   = src->right.begin();
00054     dst[1].curve = src;
00055     dst[1].idl   = --(src->left.end()); 
00056     dst[1].idr   = --(src->right.end());
00057   };
00058   
00059   void extremums( pdpoint_t * dst, dcurve * c )
00060   {
00061     dst[0].curve = dst[1].curve = dst[2].curve = dst[3].curve  = c; 
00062     dst[0].a = &(dst[1]);  dst[1].a = &(dst[0]);
00063     dst[0].ref   = c->left.begin(); dst[1].ref   = c->right.begin();
00064     dst[2].a = &(dst[3]);  dst[3].a = &(dst[2]);
00065     dst[2].ref   = --(c->left.end()); dst[3].ref   = --(c->right.end());
00066   };
00067   
00068   
00069   void append( dcurve *  a, dcurve   * b ) 
00070   { 
00071     a->left.splice ( a->left.end(),  b->left  );
00072     a->right.splice( a->right.end(), b->right );
00073     a->inter.splice( a->inter.end(), b->inter );
00074     b->owner = a; 
00075     a->size += b->size;
00076   };
00077   
00078   void prepend( dcurve * a, dcurve * b ) 
00079   { 
00080     a->left.splice( a->left.begin(), b->left );  
00081     a->right.splice( a->right.begin(), b->right );
00082     a->inter.splice( a->inter.begin(), b->inter );
00083     b->owner = a; 
00084     a->size += b->size;
00085   };
00086   
00087   void reverse( dcurve * c ) 
00088   { c->left.reverse(); c->right.reverse(); c->inter.reverse(); };
00089 
00090   void link( sdpoint_t* a, sdpoint_t* b){ _link(a,b); };
00091   
00092   void link( pdpoint_t* a, pdpoint_t* b)
00093   {
00094     if ( isright(a) ) swap(curve(a));
00095     if ( isright(b) ) swap(curve(b));
00096     _link(a,b);
00097   };
00098   
00099   void satisfy_links(  curves_links_t::iterator it )
00100   {
00101       std::list< ppair_t > * l = &(it->second);
00102       std::vector< ppair_t > starts;
00103       std::vector< ppair_t > ends;
00104       
00105        starts.reserve(10);
00106        ends.reserve(10);
00107    
00108        for (  std::list< ppair_t >::iterator p = l->begin(); 
00109              p != l->end(); p ++ )
00110          {
00111            if ( isfirst(p->first) ) starts.push_back( *p );
00112            else if ( islast(p->first) ) ends.push_back( *p );
00113          };
00114       
00115        if ( starts.size() == 1 )
00116          {
00117            if ( isextrem( starts[0].first ) && isextrem( starts[0].second ) )
00118             if ( curve(starts[0].first) != curve(starts[0].second))
00119               link( starts[0].first, starts[0].second );
00120          };
00121       
00122        if ( ends.size() == 1 )
00123          {
00124            
00125            if ( isextrem( ends[0].first ) && isextrem( ends[0].second ) )
00126              if ( curve(ends[0].first) != curve(ends[0].second) )
00127                link( ends[0].first, ends[0].second );
00128          };
00129     };
00130   
00131 };
00132 
00133 } //namespace mmx