shape_doc 0.1
|
00001 # include <shape/ssi_dsearch.hpp> 00002 //#include <shape/ssi/chrono.h> 00003 #include <fstream> 00004 #define ParametricSurface shape::surface_parametric<double> 00005 00006 namespace mmx { 00007 namespace shape_ssi { 00008 00009 00010 dsearch::dsearch( const ParametricSurface * s , unsigned w, unsigned h, bool cnf ) : qsegment(s, w, h ) 00011 { 00012 m_cnf = cnf; 00013 // _st = time(); 00014 unsigned i,j; 00015 conflict_count = 0; 00016 nbpoints = 0; 00017 _branches = new std::list< dcurve * > *[this->regions.size()*this->regions.size()]; 00018 memset(_branches,0,sizeof( std::list< dcurve * > * )* 00019 this->regions.size()*this->regions.size() ); 00020 00021 for ( i = 0; i < this->regions.size() ; i++ ) 00022 for ( j = i+1; j < this->regions.size() ; j++ ) 00023 { 00024 #define VOISINS_AUSSI 00025 #ifndef VOISINS_AUSSI 00026 if ( !this->grp->neighbors(i,j) ) 00027 #endif 00028 { 00029 //cout << i << " " << j << endl; 00030 search(i,j); 00031 find_branches(i,j); 00032 }; 00033 }; 00034 00035 // cout << "search: ok\n"; 00036 std::vector< dcurve * > * tmp = new std::vector<dcurve*>(); 00037 00038 for ( i = 0; i < this->regions.size(); i++ ) 00039 for ( j = i+1; j < this->regions.size(); j++ ) 00040 { 00041 if ( branches(i,j) ) 00042 { 00043 for ( std::list<dcurve*>::iterator it = branches(i,j)->begin(); it != branches(i,j)->end(); it ++ ) 00044 { 00045 tmp->push_back( *it ); 00046 }; 00047 delete branches(i,j); 00048 } 00049 }; 00050 00051 result = reduce2( tmp ); 00052 delete tmp; 00053 nbcurves = 0; 00054 lefts = rights = 0; 00055 sizes = 0; 00056 if ( result ) 00057 { 00058 nbpoints = 0; 00059 std::list<dcurve *>::iterator it; 00060 nbcurves = result->size(); 00061 00062 sizes = new unsigned[nbcurves]; 00063 00064 for ( i = 0, it = result->begin(); it != result->end(); it++ , i++ ) 00065 { 00066 sizes[i] = (*it)->left.size(); 00067 nbpoints+= sizes[i]; 00068 }; 00069 00070 lefts = new point2*[nbcurves]; 00071 rights = new point2*[nbcurves]; 00072 unsigned c_n = 0; 00073 unsigned k; 00074 for ( it = result->begin(); it != result->end(); it ++, c_n++ ) 00075 { 00076 lefts[c_n] = new point2[sizes[c_n]]; 00077 rights[c_n] = new point2[sizes[c_n]]; 00078 list2_t::iterator itcr, itcl; 00079 for ( k = 0, itcl = (*it)->left.begin(), itcr = (*it)->right.begin(); 00080 itcl != (*it)->left.end(); 00081 itcl++ , itcr++, k++ ) 00082 { 00083 00084 lefts[c_n][k] = *itcl; 00085 rights[c_n][k] = *itcr; 00086 }; 00087 }; 00088 00089 for ( std::list<dcurve*>::iterator it = result->begin(); it!= result->end(); it++ ) 00090 { 00091 delete *it; 00092 }; 00093 delete result; 00094 }; 00095 delete[] _branches; 00096 00097 //std::cout << "d = " << (time()-_st) << std::endl; 00098 // std::cout << nbcurves << std::endl; 00099 00100 // GnuPlotOutput("dsearch.gmv"); 00101 }; 00102 00103 dsearch::~dsearch() 00104 { 00105 if ( sizes ) delete[] sizes; 00106 if ( lefts ) 00107 { 00108 for ( unsigned i = 0; i < nbcurves; i++ ) 00109 delete[] lefts[i]; 00110 delete[] lefts; 00111 }; 00112 if ( rights ) 00113 { 00114 for ( unsigned i = 0; i < nbcurves; i++ ) 00115 delete[] rights[i]; 00116 delete[] rights; 00117 }; 00118 00119 }; 00120 00121 void dsearch::GnuPlotOutput( char * name ) 00122 { 00123 /* 00124 gmv::stream out(name); 00125 00126 std::vector< vector3 > v; 00127 for ( unsigned i = 0; i < nbcurves; i++ ) 00128 { 00129 for ( unsigned k = 0; k < sizes[i]; k++ ) 00130 { 00131 v.push_back(vector3()); 00132 v.back()[0] = lefts[i][k][0]; 00133 v.back()[1] = lefts[i][k][1]; 00134 v.back()[2] = 0; 00135 v.push_back(vector3()); 00136 v.back()[0] = rights[i][k][0]; 00137 v.back()[1] = rights[i][k][1]; 00138 v.back()[2] = 0; 00139 }; 00140 }; 00141 out.points(&(v[0][0]),v.size()); 00142 */ 00143 } 00144 00145 00146 } 00147 } //namespace mmx 00148 00149 # undef ParametricSurface