35 #ifndef AIMS_DISTANCEMAP_MESHMORPHOMAT_D_H
36 #define AIMS_DISTANCEMAP_MESHMORPHOMAT_D_H
47 namespace meshdistance
54 const T & Back,
const T & For,
55 unsigned &
min,
unsigned &
max,
unsigned nbDil)
60 bool allowUnreached =
false;
61 const std::vector<Point3df> & vert = mesh.
vertex();
62 unsigned n = vert.size(),imax,i,j,jmax,nbpt=0;
65 std::vector<unsigned> nodeMax;
66 const std::vector< AimsVector<uint,3> > & poly = mesh.
polygon();
73 if (inittex.
item(i) == label)
82 if (nbpt == 0 || nbpt == 1)
84 std::cout <<
"The label " << label <<
" has only one node ! \n";
92 std::map<unsigned, std::set<unsigned> > neighbours;
95 for( i=0; i<poly.size(); ++i )
101 && tex.
item(v2)!=For)
103 neighbours[v1].insert( v2 );
104 neighbours[v2].insert( v1 );
107 && tex.
item(v3)!=For)
109 neighbours[v1].insert( v3 );
110 neighbours[v3].insert( v1 );
113 && tex.
item(v3)!=For)
115 neighbours[v2].insert( v3 );
116 neighbours[v3].insert( v2 );
122 while (tex.
item(i) == For)
126 dist = MeshDistance<T>(mesh, tex, allowUnreached);
130 if (distance[0].item(i) >= distMax)
132 distMax = distance[0].
item(i);
136 nodeMax.push_back(imax);
144 if (inittex.
item(i) > 0)
150 dist = MeshDistance<T>(mesh, tex, allowUnreached);
153 if (dist.
item(i) > distMax )
155 distMax = dist.
item(i);
158 nodeMax.push_back(imax);
162 std::set<unsigned>::iterator in,en;
164 min = imax = nodeMax[4];
165 max = jmax = nodeMax[3];
166 std::stack<unsigned> line;
172 for (in = neighbours[i].begin(), en = neighbours[i].end(); in !=en ; ++in)
173 if (dist.
item(*in) < dmin)
176 dmin = dist.
item(*in);
178 sulci.
item(i) = label;
181 unsigned inc = 0, l = line.size();
183 std::cout <<
"Size of the line: " << l <<
" nbDil: " << nbDil << std::endl;
185 while (!line.empty())
190 if (inc <= nbDil || inc >= l - nbDil)
191 sulci.
item(i) = Back;
196 if (inittex.
item(i) != label)
213 const T & Back,
const T & For ,
215 const unsigned min,
const unsigned max)
219 const std::vector<Point3df> & vert = mesh.
vertex();
220 unsigned ncc, n = vert.size(),i;
222 const std::vector< AimsVector<uint,3> > & poly = mesh.
polygon();
229 std::set<unsigned> neighbours;
231 std::set<unsigned>::iterator is,es;
237 neighbours.insert(v1);
238 neighbours.insert(v2);
239 neighbours.insert(v3);
244 neighbours.insert(v1);
245 neighbours.insert(v2);
246 neighbours.insert(v3);
247 neighbours.insert(
min);
248 neighbours.insert(
max);
252 if (inittex.
item(i) == label)
253 dilat.item(i) = label;
255 dilat.item(i) = Back;
260 for (is=neighbours.begin(), es=neighbours.end();is != es; ++is)
262 dilat.item(*is) = For;
265 dilat = MeshDilation<T>(mesh,dilat,Back,For,1,
true);
268 split.item(i) = dilat.item(i);
272 if (inittex.
item(i) == label || dilat.item(i) == For )
273 split.item(i) = Back;
277 std::cout <<
"ncc: " << ncc << std::endl;
290 float nbDilMax,
bool connexity,
291 const T & Back,
const T & For,
292 const std::vector<std::list<unsigned> > & neigho)
295 const std::vector<Point3df> & vert = mesh.
vertex();
296 unsigned inc=0,nbLabel,i,n = vert.size();
302 std::set<T> cc_sulci_labels;
303 typename std::set<T>::iterator ilab,elab;
309 cc_sulci_labels.insert(sulctex.
item(i));
313 cc_sulci_labels.erase(Back);
314 cc_sulci_labels.erase(For);
315 nbLabel = cc_sulci_labels.size();
316 std::cout <<
"\nNb of labels: " << nbLabel << std::endl;
319 for ( ilab = cc_sulci_labels.begin(), elab=cc_sulci_labels.end(); ilab!=elab; ++ilab)
324 std::cout << inc <<
"/" << nbLabel << std::endl;
327 if (sulctex.
item(i) == label)
328 ccsulcus.
item(i) = label;
330 ccsulcus.
item(i) = Back;
333 std::cout <<
"Nb initial of cc: " << ncc << std::endl;
337 hole =
HasHole(ccsulcus,mesh,label);
340 std::cout <<
"With hole(s) \n";
342 std::cout <<
"Without hole \n";
345 unsigned NB_PT_MAX = 10,nbpt;
348 while ( (ncc != 1 || hole) && nbd <= nbDilMax)
350 sulctemp = MeshDilation<T>( mesh, ccsulcus,Back,For,nbd,connexity);
352 std::cout <<
"After Dilation (" << nbd <<
") : cc: " << ncc << std::endl ;
355 hole =
HasHole(sulctemp,mesh,label);
357 std::cout <<
"With hole(s) \n";
359 std::cout <<
"Without hole \n";
365 std::cerr <<
"Not able to close the projected connnected component, but I continue.\n";
368 ccsulcus = MeshDilation<T>( mesh, ccsulcus,Back,For,1,connexity);
369 std::cout <<
"Skeletonization" << std::endl;
372 if ( nbpt > NB_PT_MAX)
375 std::cout <<
"Not enough point for the ebarbulage ( " << nbpt <<
" < " << NB_PT_MAX <<
")" << std::endl;
377 std::cout <<
"ncc: " << ncc << std::endl ;
378 hole =
HasHole(ccsulcus,mesh,label);
380 std::cout <<
"With hole(s) \n";
382 std::cout <<
"Without hole \n";
403 if (ccsulcus.
item(i) == label)
405 if (sulctex.
item(i)==label || sulctex.
item(i) == Back )
408 std::cout <<
"The point " << i <<
" cannot change its label \n";
413 if (tex.
item(i) == label)
415 if (ccsulcus.
item(i) == label)
431 float nbDilMax,
bool connexity,
432 const T & Back,
const T & For,
433 const std::vector<std::list<unsigned> > & neigho,
434 const std::set<T> & label_forbidden)
437 const std::vector<Point3df> & vert = mesh.
vertex();
438 unsigned inc=0,nbLabel,i,n = vert.size();
444 std::set<T> cc_sulci_labels;
445 typename std::set<T>::iterator ilab,elab;
451 cc_sulci_labels.insert(sulctex.
item(i));
455 cc_sulci_labels.erase(Back);
456 cc_sulci_labels.erase(For);
457 nbLabel = cc_sulci_labels.size();
458 std::cout <<
"\nNb of labels: " << nbLabel << std::endl;
460 typename std::set<T>::iterator lfe = label_forbidden.end();
462 for ( ilab = cc_sulci_labels.begin(), elab=cc_sulci_labels.end(); ilab!=elab; ++ilab)
467 std::cout << inc <<
"/" << nbLabel << std::endl;
470 if (sulctex.
item(i) == label)
471 ccsulcus.
item(i) = label;
473 ccsulcus.
item(i) = Back;
476 std::cout <<
"Nb initial of cc: " << ncc << std::endl;
480 hole =
HasHole(ccsulcus,mesh,label);
483 std::cout <<
"With hole(s) \n";
485 std::cout <<
"Without hole \n";
488 unsigned NB_PT_MAX = 10,nbpt;
491 while ( (ncc != 1 || hole) && nbd <= nbDilMax)
493 sulctemp = MeshDilation<T>( mesh, ccsulcus,Back,For,nbd,connexity);
495 std::cout <<
"After Dilation (" << nbd <<
") : cc: " << ncc << std::endl ;
498 hole =
HasHole(sulctemp,mesh,label);
500 std::cout <<
"With hole(s) \n";
502 std::cout <<
"Without hole \n";
508 std::cerr <<
"Not able to close the projected connnected component, but I continue.\n";
511 ccsulcus = MeshDilation<T>( mesh, ccsulcus,Back,For,1,connexity);
512 std::cout <<
"Skeletonization" << std::endl;
514 if (label_forbidden.find(*ilab) == lfe)
518 if ( nbpt > NB_PT_MAX)
521 std::cout <<
"Not enough point for the ebarbulage ( " << nbpt <<
" < " << NB_PT_MAX <<
")" << std::endl;
523 std::cout <<
"ncc: " << ncc << std::endl ;
524 hole =
HasHole(ccsulcus,mesh,label);
526 std::cout <<
"With hole(s) \n";
528 std::cout <<
"Without hole \n";
531 std::cout <<
"No thinning for the INSULA\n";
552 if (ccsulcus.
item(i) == label)
554 if (sulctex.
item(i)==label || sulctex.
item(i) == Back )
557 std::cout <<
"The point " << i <<
" cannot change its label \n";
562 if (tex.
item(i) == label)
564 if (ccsulcus.
item(i) == label)
579 template<
class T>
inline
581 const std::list<unsigned> & neigho)
584 std::list<unsigned>::const_iterator il=neigho.begin(), el=neigho.end();
585 short l=tex.
item(*il);
590 if (tex.
item(*il) != l)
597 return(nb == 1 || nb == 2);
602 template<
class T>
inline
607 const std::vector<Point3df> & vert = mesh.
vertex();
608 const std::vector< AimsVector<uint,3> > & poly = mesh.
polygon();
609 unsigned i, n = vert.size();
610 unsigned S=0,A=0,F=0;
616 std::set<std::set<unsigned> > neighbours;
617 std::set<unsigned> temp;
620 for( i=0; i<poly.size(); ++i )
626 if(tex.
item(v1)==label && tex.
item(v2)==label)
631 neighbours.insert(temp);
634 if(tex.
item(v1)==label && tex.
item(v3)==label)
639 neighbours.insert(temp);
642 if(tex.
item(v3)==label && tex.
item(v2)==label)
647 neighbours.insert(temp);
650 if(tex.
item(v3)==label && tex.
item(v2)==label && tex.
item(v1)==label)
656 if (tex.
item(i) == label)
660 A = neighbours.size();
663 return( (S - A + F != 1) );
671 template<
class T>
inline
673 const std::list<unsigned> & neigho )
676 std::list<unsigned>::const_iterator il=neigho.begin(), el=neigho.end();
677 short l=tex.
item(*il);
682 if (tex.
item(*il) != l)
690 if (tex.
item(*il) != l)
693 return(nb > 2 || nb ==1 );
700 template<
class T>
inline
704 for (
unsigned i=0; i < tex.
nItem(); ++i)
705 if (tex.
item(i) == label)
717 const std::vector<std::list<unsigned> > & neigho )
720 unsigned i,n = mesh.
vertex().size();
724 std::list<unsigned>::const_iterator il,el;
727 if (inittex.
item(i) == label)
735 if ( skelet.item(i) == 1 && ImmortalPoint(skelet,neigho[i]) )
736 immortal.
item(i) = 1;
739 if (skelet.item(i) == 1)
745 std::multimap<float,unsigned> dfront;
746 std::multimap<float,unsigned>::iterator id,ed;
752 if (skelet.item(i) == 1 && immortal.
item(i) == 0)
753 for (il=neigho[i].begin(), el=neigho[i].end();il!=el;++il)
754 if (skelet.item(*il) == 0 )
755 dfront.insert( std::pair<float,unsigned>(dist.
item(i),i) );
758 while (dfront.size()>0)
761 for (
id=dfront.begin(), ed=dfront.end();
id != ed; ++
id)
762 if ( immortal.
item(id->second) == 0 )
764 skelet.item(id->second) = 0;
766 for (il=neigho[id->second].begin(), el=neigho[id->second].end();il!=el;++il)
767 if ( skelet.item(*il) == 1 && ImmortalPoint(skelet,neigho[*il]) )
768 immortal.
item(*il) = 1;
775 if (skelet.item(i) == 1 && immortal.
item(i) == 0)
776 for (il=neigho[i].begin(), el=neigho[i].end();il!=el;++il)
777 if (skelet.item(*il) == 0 )
778 dfront.insert( std::pair<float,unsigned>(dist.
item(i),i) );
782 if ( skelet.item(i) == 1)
794 const T & Back,
const T & For,
795 const float dist,
bool connexity )
799 tex = MeshVoronoiT<T>( mesh, inittex, Back, For, dist, connexity,
true );
807 const T & Back,
const T & For,
808 const float dist,
bool connexity )
812 tex = MeshVoronoiT<T>( mesh, inittex, Back,For,dist, connexity,
false );
const std::vector< Point3df > & vertex() const
const std::vector< AimsVector< uint, D > > & polygon() const
const T & item(int n) const
const T & item(int n) const
unsigned AimsMeshLabelNbConnectedComponent(const AimsSurface< 3, Void > &mesh, const Texture< T > &inittex, const T lab)
Texture< T > SplitSulci(const AimsSurface< 3, Void > &mesh, const Texture< T > &inittex, const T &Back, const T &For, const T label, const unsigned min, const unsigned max)
Texture< T > MeshErosion(const AimsSurface< 3, Void > &mesh, const Texture< T > &inittex, const T &Back, const T &For, const float dist, bool connexity)
Texture< T > MeshDilation(const AimsSurface< 3, Void > &mesh, const Texture< T > &inittex, const T &Back, const T &For, const float dist, bool connexity)
float min(float x, float y)
Texture< T > CloseSulci(const AimsSurface< 3, Void > &mesh, const Texture< T > &sulctex, float nbDilMax, bool connexity, const T &Back, const T &For, const std::vector< std::list< unsigned > > &neigho, const std::set< T > &label_forbidden)
Close the sulcus map (dilation and skeletization).
float max(float x, float y)
bool HasHole(const Texture< T > &tex, const AimsSurface< 3, Void > &mesh, const T label)
Texture< T > LineariseSulci(const AimsSurface< 3, Void > &mesh, const Texture< T > &inittex, const T &label, const T &Back, const T &For, unsigned &min, unsigned &max, unsigned nbDil)
Texture< T > MeshSkeletization(const AimsSurface< 3, Void > &mesh, const Texture< T > &inittex, T label, T Back, const std::vector< std::list< unsigned > > &neigho)
Skeletization of the components of the innitex with label label.
unsigned NbOfPoint(const Texture< T > tex, const T label)
Texture< float > MeshDistance(const AimsSurface< 3, Void > &mesh, const Texture< T > &inittex, bool allowUnreached, float max_dist=FLT_MAX)
Computes a distance texture over a mesh.
std::vector< std::string > split(const std::string &text, const std::string &sep)