51 const Texture<T> & inittex, T threshold,
int mode,
int verbose )
54 const std::vector<Point3df> & vert = mesh.
vertex();
55 const std::vector< AimsVector<uint,3> > & poly = mesh.
polygon();
56 unsigned i, n = vert.size();
63 std::map<unsigned, std::set<unsigned> > neighbours;
69 std::cout <<
"Thresholding: " << threshold << std::endl;
97 std::cerr <<
"AimsMeshLabelConnectedComponent : thresholding mode unknown" << std::endl;
101 std::cout << nnode <<
"/" << n << std::endl;
105 for( i=0; i<poly.size(); ++i )
113 neighbours[v1].insert( v2 );
114 neighbours[v2].insert( v1 );
119 neighbours[v1].insert( v3 );
120 neighbours[v3].insert( v1 );
125 neighbours[v2].insert( v3 );
126 neighbours[v3].insert( v2 );
132 std::stack<unsigned> current;
133 std::set<unsigned>::iterator in, fn;
136 printf(
"Computing connected component\n");
146 while(!current.empty())
148 point = current.top();
150 tex.
item(point)=label;
151 for( in=neighbours[point].begin(), fn=neighbours[point].end(); in!=fn; ++in )
153 if(tex.
item(*in)==0) current.push(*in);
159 std::cout <<
"nb cc: " << label << std::endl;
171 const std::vector<Point3df> & vert = mesh.
vertex();
172 const std::vector< AimsVector<uint,3> > & poly = mesh.
polygon();
173 unsigned i, n = vert.size();
180 if (inittex.
item(i) == lab)
186 std::map<unsigned, std::set<unsigned> > neighbours;
188 for( i=0; i<poly.size(); ++i )
195 && inittex.
item(v1) == inittex.
item(v2) )
198 neighbours[v1].insert( v2 );
199 neighbours[v2].insert( v1 );
203 && inittex.
item(v1) == inittex.
item(v3) )
205 neighbours[v1].insert( v3 );
206 neighbours[v3].insert( v1 );
210 && inittex.
item(v2) == inittex.
item(v3) )
212 neighbours[v2].insert( v3 );
213 neighbours[v3].insert( v2 );
220 std::stack<unsigned> current;
221 std::set<unsigned>::iterator in, fn;
231 while(!current.empty())
233 point = current.top();
235 tex.
item(point)=label;
236 for( in=neighbours[point].begin(), fn=neighbours[point].end(); in!=fn; ++in )
238 if(tex.
item(*in)==0) current.push(*in);
256 const std::vector<Point3df> & vert = mesh.
vertex();
257 const std::vector< AimsVector<uint,3> > & poly = mesh.
polygon();
258 unsigned i, n = vert.size();
261 std::map<T,std::set<unsigned> > labels;
262 std::multimap<unsigned, T> nbLabels;
270 std::map<unsigned, std::set<unsigned> > neighbours;
277 if(inittex.
item(i) < threshold)
290 for( i=0; i<poly.size(); ++i )
297 && inittex.
item(v1) == inittex.
item(v2) )
300 neighbours[v1].insert( v2 );
301 neighbours[v2].insert( v1 );
305 && inittex.
item(v1) == inittex.
item(v3) )
307 neighbours[v1].insert( v3 );
308 neighbours[v3].insert( v1 );
312 && inittex.
item(v2) == inittex.
item(v3) )
314 neighbours[v2].insert( v3 );
315 neighbours[v3].insert( v2 );
321 std::stack<unsigned> current;
322 std::set<unsigned>::iterator in, fn;
329 while(!current.empty())
331 point = current.top();
333 tex.
item(point)=label;
334 labels[label].insert(point);
335 for( in=neighbours[point].begin(), fn=neighbours[point].end(); in!=fn; ++in )
337 if(tex.
item(*in)==0) current.push(*in);
340 nbLabels.insert( std::pair<unsigned, T> ( labels[label].size(), label ) );
343 std::cout <<
"Nb of cc : "<< label << std::endl;
345 typename std::multimap<unsigned,T>::reverse_iterator rit;
346 std::map<T, T> nbLabels_ord;
348 for (rit=nbLabels.rbegin(); rit!=nbLabels.rend(); ++rit)
350 nbLabels_ord[rit->second] = ++lab;
351 std::cout <<
"The " << lab <<
"th cc has " << rit->first <<
" points" << std::endl;
354 typename std::map<T, T>::iterator it;
360 for (it=nbLabels_ord.begin(); it!=nbLabels_ord.end(); ++it)
362 if (tex.
item(i) == it->first)
364 tex_ord.
item(i) = it->second;
376 const T & background,
unsigned long ncomp,
unsigned long min_npts,
381 const std::vector<Point3df> & vert = mesh.
vertex();
382 const std::vector< AimsVector<uint,3> > & poly = mesh.
polygon();
383 unsigned i, n = vert.size();
385 std::map<long, std::set<unsigned> > labels;
386 std::multimap<unsigned, long> nbLabels;
387 std::map<long, float> areaLabels;
395 std::map<unsigned, std::set<unsigned> > neighbours;
397 std::vector<float> areas( inittex.
nItem(), 0. );
404 if( inittex.
item(i) != cc_label )
411 for( i=0; i<poly.size(); ++i )
418 surf = ( vert[v2] - vert[v1] ).dot( vert[v3] - vert[v1] ) / 6;
427 neighbours[v1].insert( v2 );
428 neighbours[v2].insert( v1 );
433 neighbours[v1].insert( v3 );
434 neighbours[v3].insert( v1 );
439 neighbours[v2].insert( v3 );
440 neighbours[v3].insert( v2 );
446 std::stack<unsigned> current;
447 std::set<unsigned>::iterator in, fn;
455 while(!current.empty())
457 point = current.top();
459 tex.
item(point)=label;
460 labels[label].insert(point);
461 areaLabels[label] += areas[point];
462 for( in=neighbours[point].begin(), fn=neighbours[point].end(); in!=fn;
469 nbLabels.insert( std::make_pair( labels[label].size(), label) );
470 std::cout <<
"The " << label <<
" th cc (" << cc_label <<
") has "
471 << labels[label].size() <<
" points, area: " << areaLabels[label]
472 <<
" mm2" << std::endl;
475 std::cout <<
"Nb of cc : "<< label << std::endl;
477 std::multimap<unsigned, long>::reverse_iterator il, el=nbLabels.rend();
478 std::set<long> allowed_labels;
482 for( il=nbLabels.rbegin(), c=0; il!=el; ++il, ++c )
484 if( ncomp != 0 && c >= ncomp )
486 if( min_npts != 0 && il->first < min_npts )
488 if( min_surf != 0. && areaLabels[il->second] < min_surf )
490 allowed_labels.insert( il->second );
492 std::cout <<
"keeping " << allowed_labels.size() <<
" components"
500 if( allowed_labels.find( tex.
item(i) ) != allowed_labels.end() )
void reserve(size_t size)
const T & item(int n) const
void push_back(const T &item)
Texture< T > AimsMeshLabelConnectedComponent(const AimsSurface< 3, Void > &mesh, const Texture< T > &inittex, T threshold, int mode, int verbose)
Texture< T > AimsMeshFilterConnectedComponent(const AimsSurface< 3, Void > &mesh, const Texture< T > &inittex, T cc_label, const T &background, unsigned long ncomp, unsigned long min_npts, float min_surf)
Split label "label" into connected components, then filter smaller ones out.