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