34 #ifndef AIMS_SURFACE_SURFACEOPERATION_D_H 35 #define AIMS_SURFACE_SURFACEOPERATION_D_H 44 template<
int D,
class T> std::vector<std::set<uint> >
47 const std::vector< AimsVector<uint,D> > & poly = surf.
polygon();
49 std::vector<std::set<uint> > neigh( surf.
vertex().size() );
51 for (
uint i=0; i<n; ++i )
52 for (
uint j=0; j<D; ++j )
53 for (
uint k=0; k<D; ++k )
55 neigh[poly[i][j]].insert( poly[i][k] );
60 template<
int D,
class T> std::vector<std::set<uint> >
63 const std::vector< AimsVector<uint,D> > & poly = surf.
polygon();
65 std::vector<std::set<uint> > neigh( surf.
vertex().size() );
67 for (
uint i=0; i<n; ++i )
68 for (
uint j=0; j<D; ++j )
69 for (
uint k=0; k<D; ++k )
71 neigh[poly[i][j]].insert( poly[i][k] );
76 template<
int D,
class T> std::vector<std::set<uint> >
79 const std::vector< AimsVector<uint,D> > & poly = surf.
polygon();
81 std::vector<std::set<uint> > neigh( surf.
vertex().size() );
82 std::vector<std::set<uint> > neigh_final( surf.
vertex().size() );
84 for (
uint i=0; i<n; ++i )
85 for (
uint j=0; j<D; ++j )
86 for (
uint k=0; k<D; ++k )
88 neigh[poly[i][j]].insert( poly[i][k] );
90 for (
uint i=0; i<neigh.size() ; ++i)
92 std::set<uint> voisin=neigh[i];
93 std::set<uint> voisin_final=neigh[i];
94 std::set<uint>::iterator voisin_pt=voisin.begin();
95 for ( ; voisin_pt!=voisin.end(); ++voisin_pt)
98 std::set<uint> vois2=neigh[j];
99 std::set<uint>::iterator v_pt=vois2.begin();
100 for ( ; v_pt!=vois2.end(); ++v_pt)
101 voisin_final.insert(*v_pt);
103 neigh_final[i]=voisin_final;
110 template<
int D,
class T> std::vector<std::map<uint, float> >
113 const std::vector< AimsVector<uint,D> > & poly = surf.
polygon();
114 uint n = poly.size();
115 const std::vector<Point3df> & vert = surf.
vertex();
116 std::vector<std::map<uint, float> > neighDist(surf.
vertex().size());
120 for (
uint i=0; i<n; ++i )
121 for (
uint j=0; j<D; ++j )
122 for (
uint k=0; k<D; ++k )
125 diff=vert[poly[i][j]] - vert[poly[i][k]];
127 neighDist[poly[i][j]][poly[i][k]] = dist;
133 template<
int D,
class T>
137 typename std::vector< AimsVector<uint,D> >::iterator ip, fp;
139 for ( is=surface.begin(); is!=fs; ++is )
142 std::vector< AimsVector<uint,D> > & poly = surf.
polygon();
144 for ( ip=poly.begin(), fp=poly.end(); ip!=fp; ++ip )
147 for (
uint i=0; i<n; ++i )
158 template<
int D,
class T>
163 for( is=add.begin(); is!=es; ++is )
168 std::vector<Point3df> & vert = omesh.
vertex();
169 std::vector<Point3df> &
norm = omesh.
normal();
170 std::vector<AimsVector<uint,D> > & poly = omesh.
polygon();
171 const std::vector<Point3df> & vert2 = imesh.
vertex();
172 const std::vector<Point3df> &
norm2 = imesh.
normal();
173 const std::vector<AimsVector<uint,D> > & poly2 = imesh.
polygon();
174 unsigned i, j, n = vert.size(), m = vert2.size(), p = poly2.size();
177 for ( i=0; i<m; ++i )
178 vert.push_back( vert2[i] );
179 for ( i=0, m=norm2.size(); i<m; ++i )
180 norm.push_back( norm2[i] );
183 for ( i=0; i<p; ++i )
186 for ( j=0; j<D; ++j )
187 pol[j] = poly2[i][j] + n;
188 poly.push_back( pol );
195 template<
int D,
class T>
200 typename std::list<AimsTimeSurface<D,T> >::const_iterator
202 for ( im=src.begin(); im!=em; ++im )
207 template<
int D,
class T>
214 for( itime=mesh.begin(); itime!=tend; ++itime )
216 typedef std::vector< Point3df > Points;
217 Points& vertex = itime->second.
vertex();
218 Points& normal = itime->second.
normal();
219 unsigned nnorm = normal.size();
220 for( Points::size_type k = 0; k < vertex.size(); ++k )
222 vertex[ k ] = motion.
transform( vertex[ k ] );
227 normal[ k ] = motion.
transform( normal[ k ] )
230 norm = normal[k][0] * normal[k][0] + normal[k][1] * normal[k][1]
231 + normal[k][2] * normal[k][2];
232 norm = 1. / sqrt( norm );
233 normal[k][0] *=
norm;
234 normal[k][1] *=
norm;
235 normal[k][2] *=
norm;
244 template <
int D,
typename T>
249 std::vector<size_t> ** overtIndex )
255 * overtIndex =
new std::vector<size_t>;
261 while( jmt != emt || jtt != ett )
268 std::vector<Point3df> & overt = mh.
vertex();
269 std::vector<Point3df> & onorm = mh.
normal();
270 std::vector<AimsVector<uint, D> > & opoly = mh.
polygon();
271 const std::vector<Point3df> & vert = imt->second.
vertex();
272 const std::vector<Point3df> &
norm = imt->second.
normal();
273 const std::vector<AimsVector<uint, D> > & poly = imt->second.
polygon();
274 typename std::vector<AimsVector<uint, D> >::const_iterator
278 std::map<uint, uint> vmap;
279 typename std::map<uint, uint>::iterator iv, ev = vmap.end();
281 bool absmaj, hasdist;
285 for( im=poly.begin(); im != em; ++im )
287 std::map<int16_t, unsigned> vals;
294 g += vert[ (*im)[k] ];
296 unsigned & x = vals[y];
307 if( vals[ value ] == nt )
319 if( vals[ y ] == nt )
321 dist2 = ( vert[ (*im)[k] ] - g ).
norm2();
322 if( !hasdist || dist2 < dist )
342 iv = vmap.find( (*im)[k] );
345 vmap[ (*im)[k] ] = i;
347 overt.push_back( vert[ (*im)[k] ] );
348 onorm.push_back( norm[ (*im)[k] ] );
350 (** overtIndex).push_back((*im)[k]);
356 opoly.push_back( p );
369 template <
int D,
typename T>
378 for( is=mesh.begin(); is!=es; ++is )
381 const std::vector<Point3df> & vert = surf.
vertex();
382 const std::vector<AimsVector<uint,D> > & poly = surf.
polygon();
385 std::vector<float> & tx = (*tex)[ is->first ].data();
386 std::vector<unsigned> counts;
387 tx.reserve( vert.size() );
388 tx.insert( tx.end(), vert.size(), 0. );
389 counts.reserve( vert.size() );
390 counts.insert( counts.end(), vert.size(), 0 );
393 typename std::vector<AimsVector<uint,D> >::const_iterator
394 ip, ep = poly.end(), jp;
397 for( ip=poly.begin(); ip!=ep; ++ip )
403 uint vj = (*ip)[ (i+1) % D ];
404 n = ( vert[ vi ] - vert[ vj ] ).
norm();
414 std::vector<float>::iterator it, et = tx.end();
415 std::vector<unsigned>::const_iterator itc;
417 for( it=tx.begin(), itc=counts.begin(); it!=et; ++it, ++itc )
419 *it /= float( *itc );
423 for( it=tx.begin(), itc=counts.begin(); it!=et; ++it, ++itc )
424 *it =
float( *itc ) / *it;
431 template <
int D,
typename T>
439 ids, eds = denommesh.end();
442 for( is=nummesh.begin(), ids=denommesh.begin(); is!=es && ids!=eds;
446 const std::vector<Point3df> & vert = surf.
vertex();
447 const std::vector<AimsVector<uint,D> > & poly = surf.
polygon();
448 const std::vector<Point3df> & dvert = ids->second.vertex();
451 std::vector<float> & tx = (*tex)[ is->first ].data();
452 std::vector<unsigned> counts;
453 tx.reserve( vert.size() );
454 tx.insert( tx.end(), vert.size(), 0. );
455 counts.reserve( vert.size() );
456 counts.insert( counts.end(), vert.size(), 0 );
459 typename std::vector<AimsVector<uint,D> >::const_iterator
460 ip, ep = poly.end(), jp;
463 for( ip=poly.begin(); ip!=ep; ++ip )
469 uint vj = (*ip)[ (i+1) % D ];
470 n = ( vert[ vi ] - vert[ vj ] ).
norm();
471 dn = ( dvert[ vi ] - dvert[ vj ] ).
norm();
476 tx[ vi ] = std::max( tx[ vi ], n );
477 tx[ vj ] = std::max( tx[ vj ], n );
503 std::map<std::pair<uint,uint>,
uint> & segments,
505 const std::vector<Point3df> & vert,
506 std::vector<Point3df> & overt )
508 std::pair<uint,uint> seg = std::make_pair( i, j );
509 std::map<std::pair<uint,uint>,
uint>::const_iterator
510 iseg = segments.find( seg );
512 if( iseg == segments.end() )
514 Point3df p = ( vert[i] + vert[j] ) / 2;
516 overt.push_back( p );
517 segments[ seg ] = iout;
527 template <
typename T>
532 const std::vector<Point3df> & vert = mesh.
vertex();
533 const std::vector<AimsVector<uint,3> > & poly = mesh.
polygon();
535 std::map<std::pair<uint,uint>,
uint> segments;
536 std::vector<AimsVector<uint,3> >::const_iterator ip, ep = poly.end();
539 std::vector<Point3df> & overt = outmesh->
vertex();
540 std::vector<AimsVector<uint,2> > & opoly = outmesh->
polygon();
542 for( ip=poly.begin(); ip!=ep; ++ip )
568 if( tex[i] == region )
572 if( tex[j] == region )
576 if( tex[k] == region )
583 if( tex[i] != tex[j] && tex[i] != tex[k] && tex[j] != tex[k] )
586 Point3df center = ( vert[i] + vert[j] + vert[k] ) / 3.;
587 uint iop = overt.size();
588 overt.push_back( center );
603 if( tex[i] == tex[j] )
607 if( tex[i] == tex[k] )
614 if( !done && ( ii != jj || ii != kk ) )
616 std::vector<uint> ipts;
633 template <
typename T>
638 AimsSurfaceTriangle::const_iterator imesh, jmesh, emesh = mesh.end();
639 imesh = mesh.begin();
644 itex = tex.begin(), jtex=itex, etex = tex.end();
648 while( imesh != emesh && itex != etex )
650 unsigned mtimestep = imesh->first;
651 unsigned ttimestep = itex->first;
655 (*outmesh)[ std::max( mtimestep, ttimestep ) ] = *tmesh;
657 if( jmesh == emesh && jtex == etex )
659 if( jmesh != emesh && ( jtex == etex || jmesh->first < jtex->first ) )
664 else if( jtex != etex
665 && ( jmesh == emesh || jmesh->first > jtex->first ) )
688 template <
int D,
typename T>
693 const std::vector<Point3df> & vert = mesh[timestep].
vertex();
694 std::vector<AimsVector<uint, D> > & poly = mesh[timestep].
polygon();
695 std::multimap<float, AimsVector<uint, D> > sorted;
696 typename std::vector<AimsVector<uint, D> >::iterator
698 typename std::multimap<float, AimsVector<uint, D> >::iterator
699 im, em = sorted.end();
704 for( ip=poly.begin(); ip!=ep; ++ip )
706 center = vert[(*ip)[0]];
708 center += vert[(*ip)[d]];
709 sorted.insert( std::make_pair( center.
dot( direction ), *ip ) );
713 for( im=sorted.begin(), ip=poly.begin(); im!=em; ++im, ++ip )
static std::vector< std::set< uint > > surfaceNeighbours2ndOrder(const AimsTimeSurface< D, T > &surf)
static void invertSurfacePolygons(AimsTimeSurface< D, T > &surface)
static TimeTexture< float > * meshEdgeLengthRatioTexture(const AimsTimeSurface< D, T > &nummesh, const AimsTimeSurface< D, T > &denommesh)
Calculate an edge length ratio in edges of two meshes with the same topology.
static TimeTexture< float > * meshDensity(const AimsTimeSurface< D, T > &mesh, bool asDistance=false)
Calculate a mesh density: inverse of the average edges distance If asDistance is true, then the average distance is returned instead of the density.
std::map< int, Texture< T > >::const_iterator const_iterator
AIMSDATA_API AimsTimeSurface< 3, Void > AimsSurfaceTriangle
static void meshTransform(AimsTimeSurface< D, T > &mesh, const Motion &trans)
Applies a transformation to a mesh.
float norm2(const AimsVector< T, D > &v1)
The class for EcatSino data write operation.
static AimsTimeSurface< D, T > * meshExtract(const AimsTimeSurface< D, T > &mesh, const TimeTexture< int16_t > &tex, int16_t value, std::vector< size_t > **overtIndex=0)
const std::vector< Point3df > & vertex() const
Get a const reference to the vector of vertices.
std::map< int, AimsSurface< D, T > >::iterator iterator
The template class to manage a mesh with time if needed.
static std::vector< std::set< uint > > surfaceNeighbours(const AimsSurface< D, T > &surf)
const std::vector< AimsVector< uint, D > > & polygon() const
Get a const reference to the vector of polygons of the 0 surface.
static void sortPolygonsAlongDirection(AimsTimeSurface< D, T > &mesh, int timestep, const Point3df &direction)
Sort polygons along a given direction.
const std::vector< Point3df > & normal() const
Get a const reference to the vector of normals of the 0 surface.
const std::vector< AimsVector< uint, D > > & polygon() const
Get a const reference to the vector of polygons.
T dot(const AimsVector< T, D > &other) const
uint take_mid_point_and_insert(std::map< std::pair< uint, uint >, uint > &segments, uint i, uint j, const std::vector< Point3df > &vert, std::vector< Point3df > &overt)
The template class to manage a mesh.
static std::vector< std::map< uint, float > > surfaceNeighbourDistance(const AimsTimeSurface< D, T > &surf)
static void meshMerge(AimsTimeSurface< D, T > &dst, const AimsTimeSurface< D, T > &add)
concatenates 2 meshes into one (adds the second to the first one)
const std::vector< Point3df > & vertex() const
Get a const reference to the vector of verteces of the surface of index 0.
virtual void setProperty(const std::string &, Object)
AIMSDATA_API float norm(const Tensor &thing)
static AimsSurface< 2, Void > * meshTextureBoundary(const AimsSurface< 3, Void > &mesh, const Texture< T > &tex, T region)
Extracts the boundary of region of value <region> of the input texture, on the mesh.
std::map< int, AimsSurface< D, T > >::const_iterator const_iterator
void erase()
Clear all the meshes.
const aims::PythonHeader & header() const
Get the header.
const std::vector< Point3df > & normal() const
Get a const reference to the vector of normals.