35 #ifndef AIMS_DISTANCEMAP_MESHPARCELLATION_D_H
36 #define AIMS_DISTANCEMAP_MESHPARCELLATION_D_H
51 namespace meshdistance
59 const std::set<T> & setBack,
const std::set<T> & setFor,
60 const std::set<std::set<T> > & labelAllowed)
63 const std::vector<Point3df> & vert = mesh.
vertex();
64 const std::vector< AimsVector<uint,3> > & poly = mesh.
polygon();
65 unsigned i, n = vert.size();
67 std::map <unsigned, std::set<T> > labelNeigh;
68 typename std::map <unsigned, std::set<T> >
::iterator il,el;
73 std::map<unsigned, std::set<unsigned> > neighbours;
76 for( i=0; i<poly.size(); ++i )
81 labelNeigh[v1].insert( inittex.
item(v2) );
82 labelNeigh[v2].insert( inittex.
item(v1) );
83 labelNeigh[v1].insert( inittex.
item(v3) );
84 labelNeigh[v3].insert( inittex.
item(v1) );
85 labelNeigh[v3].insert( inittex.
item(v2) );
86 labelNeigh[v2].insert( inittex.
item(v3) );
90 std::set<short> setLabel,setTemp;
125 unsigned interSize,sizeNeigh;
126 typename std::map<unsigned,std::set<T> >::reverse_iterator im,em;
127 std::multimap<unsigned,std::set<T> > matchedLabel;
130 for ( il = labelNeigh.begin(), el = labelNeigh.end(); il!= el; ++il)
133 sizeNeigh = (il->second).size();
162 setLabel = il->second;
163 matchedLabel.clear();
165 typename std::set<T>::iterator i1,i2;
167 for (ia = labelAllowed.begin(),dl = labelAllowed.end(); ia != dl; ++ia)
170 std::insert_iterator<std::set<T> > ii(setTemp, setTemp.begin() );
171 set_intersection(setLabel.begin(),setLabel.end(),ia->begin(),ia->end(),ii );
172 interSize = setTemp.size();
173 if ( interSize >= 2 )
174 matchedLabel.insert(std::pair<
unsigned, std::set<T> >(interSize,*ia) ) ;
177 if (matchedLabel.size() == 1)
179 im = matchedLabel.rbegin();
180 tex.
item(il->first) = im->second;
184 tex.
item(il->first) = setBack;
191 if ( il->second != setFor )
192 tex.
item(il->first) = setBack;
194 tex.
item(il->first) = setFor;
213 const std::vector<Point3df> & vert = mesh.
vertex();
214 unsigned i, n = vert.size();
220 if( skiz.
item( i ) == Back )
228 if( skiz.
item( i ) != Back )
241 const std::set<T> & setBack,
const std::set<T> & setFor )
244 const std::vector<Point3df> & vert = mesh.
vertex();
245 const std::vector< AimsVector<uint,3> > & poly = mesh.
polygon();
246 unsigned i, n = vert.size();
248 std::map <unsigned, std::set<T> > labelNeigh;
249 typename std::map <unsigned, std::set<T> >
::iterator il,el;
254 std::map<unsigned, std::set<unsigned> > neighbours;
257 for( i=0; i<poly.size(); ++i )
262 labelNeigh[v1].insert( inittex.
item(v2) );
263 labelNeigh[v2].insert( inittex.
item(v1) );
264 labelNeigh[v1].insert( inittex.
item(v3) );
265 labelNeigh[v3].insert( inittex.
item(v1) );
266 labelNeigh[v3].insert( inittex.
item(v2) );
267 labelNeigh[v2].insert( inittex.
item(v3) );
272 for ( il = labelNeigh.begin(), el = labelNeigh.end(); il!= el; ++il)
274 sizeNeigh = (il->second).size();
276 tex.
item(il->first) = setBack;
278 tex.
item(il->first) = setFor;
296 const std::set<T> & setBack,
const std::set<T> & setFor)
298 const std::vector<Point3df> & vert = mesh.
vertex();
299 unsigned i, n = vert.size();;
307 labSet.insert( tex.item(i) );
340 if ( tex.item(i).size() > 1 )
341 outtex.
item(i) = newLab[tex.item(i)];
348 template<
class T,
class U>
352 const std::set<T> & setBack,
const std::set<T> & setFor )
357 typename std::set<T>::iterator is,es;
358 const std::vector<Point3df> & vert = mesh.
vertex();
359 unsigned i, n = vert.size();
362 std::map<std::set<U>,
short> lab_set_short;
364 ASSERT( n == vor.nItem() );
369 for (is = vor.item(i).begin(), es = vor.item(i).end();is != es; ++is)
370 setTemp.insert( *is );
372 sTex.
item(i) = setTemp;
373 lab_front_sulci.insert(setTemp);
379 lab_set_short[setBack] = 0;
381 for ( il=lab_front_sulci.begin(), el= lab_front_sulci.end(); il!=el;++il )
382 if (*il != setFor && *il != setBack)
384 lab_set_short[*il] = inc;
397 Tex.
item(i) = lab_set_short[sTex.
item(i)];
410 std::map<T,float> stat;
411 const std::vector<Point3df> & vertex = mesh.
vertex();
412 unsigned i,n = vertex.size();
413 const std::vector< AimsVector<uint,3> > & poly = mesh.
polygon();
415 std::map<T,std::set<unsigned> > labels;
416 typename std::map<T,std::set<unsigned> >
::iterator il,el=labels.end();
419 labels[tex.
item(i)].insert(i);
423 for (il=labels.begin();il != el; ++il)
425 std::set<unsigned> vset = il->second;
427 std::set<unsigned>::iterator evset = vset.end();
429 Point3df zero( 0.0, 0.0, 0.0 ),AB,AC,H,CH;
431 for(
unsigned ii=0, n=poly.size(); ii!=n; ++ii )
432 if( vset.find( poly[ii][0] ) != evset
433 && vset.find( poly[ii][1] ) != evset
434 && vset.find( poly[ii][2] ) != evset )
437 AB = vertex[ pol[ 1 ] ] - vertex[ pol[ 0 ] ];
438 AC = vertex[ pol[ 2 ] ] - vertex[ pol[ 0 ] ];
439 H = vertex[ pol[ 0 ] ] + ( AB.
dot( AC ) /
norm2( AB ) ) * AB;
440 CH = H - vertex[ pol[ 2 ] ];
442 surface +=
norm( CH ) *
norm( AB ) / 2;
460 std::map<T,float> stat;
462 typename std::set<T>::iterator il,el;
465 std::vector<float> vs = vol->getVoxelSize();
466 float voxelVol = vs[0] * vs[1] * vs[2];
470 vol->getStrides(),
true );
471 for( ; !it.
ended(); ++it )
478 for( il = labels.begin(), el = labels.end(); il != el; ++il )
485 stat[*p] += voxelVol;
const std::vector< Point3df > & vertex() const
const std::vector< AimsVector< uint, D > > & polygon() const
T dot(const AimsVector< T, D > &other) const
const T & item(int n) const
void inc_line_ptr(const T *&p) const
Texture< std::set< T > > MeshBorderVoronoi(const AimsSurface< 3, Void > &mesh, const Texture< T > &inittex, const std::set< T > &setBack, const std::set< T > &setFor)
Extract the boundarie of a voronoi diagram i.e.
Texture< short > border2Texture(const Texture< std::set< T > > &tex, const AimsSurface< 3, Void > &mesh, const std::set< T > &setBack, const std::set< T > &setFor)
Convert a multidimensional boundary map to a texture of short.
Texture< T > MeshDilation(const AimsSurface< 3, Void > &mesh, const Texture< T > &inittex, const T &Back, const T &For, const float dist, bool connexity)
std::map< T, float > VolumeParcel(const carto::rc_ptr< carto::Volume< T > > &vol)
Give the surface of labelled parcels defined from volume.
Texture< short > Voronoi2toTexture(const Texture< std::set< T > > &vor, const AimsSurface< 3, Void > &mesh, const std::set< T > &setBack, const std::set< T > &setFor)
Texture< std::set< T > > gyrusSeedDefinition(const AimsSurface< 3, Void > &mesh, const Texture< T > &inittex, const std::set< T > &setBack, const std::set< T > &setFor, const std::set< std::set< T > > &labelAllowed)
Define the gyrus seed from the SKIZ.
Texture< T > gyrusSeedDilationInSKIZ(const AimsSurface< 3, Void > &mesh, const Texture< T > &seed, const Texture< T > &skiz, const T &Back, const T &For)
const short MESHDISTANCE_FORBIDDEN
global variable...
std::map< T, float > SurfaceParcel(const Texture< T > &tex, const AimsSurface< 3, Void > &mesh)
Give the surface of labelled parcels defined from textures.
AIMSDATA_API float norm(const Tensor &thing)
float norm2(const AimsVector< T, D > &v1)