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>
 
  165     for( is=add.begin(); is!=es; ++is )
 
  170       std::vector<Point3df> & vert = omesh.
vertex();
 
  171       std::vector<Point3df> & 
norm = omesh.
normal();
 
  172       std::vector<AimsVector<uint,D> > & poly = omesh.
polygon();
 
  173       const std::vector<Point3df>  & vert2 = imesh.
vertex();
 
  174       const std::vector<Point3df>  & 
norm2 = imesh.
normal();
 
  175       const std::vector<AimsVector<uint,D> >  & poly2 = imesh.
polygon();
 
  176       unsigned i, j, n = vert.size(), m = vert2.size(), p = poly2.size();
 
  179       for ( i=0; i<m; ++i )
 
  180         vert.push_back( vert2[i] );
 
  181       for ( i=0, m=
norm2.size(); i<m; ++i )
 
  185       for ( i=0; i<p; ++i )
 
  188         for ( j=0; j<D; ++j )
 
  189           pol[j] = poly2[i][j] + n;
 
  190         poly.push_back( pol );
 
  197   template<
int D, 
class T>
 
  202     typename std::list<AimsTimeSurface<D,T> >::const_iterator
 
  204     for ( im=src.begin(); im!=em; ++im )
 
  209   template<
int D, 
class T>
 
  216     for( itime=mesh.begin(); itime!=tend; ++itime )
 
  218         typedef std::vector< Point3df > Points;
 
  219         Points& vertex = itime->second.
vertex();
 
  220         Points& normal = itime->second.
normal();
 
  221         unsigned nnorm = normal.size();
 
  222         for( Points::size_type k = 0; k < vertex.size(); ++k )
 
  224             vertex[ k ] = motion.
transform( vertex[ k ] );
 
  229               normal[ k ] = motion.
transform( normal[ k ] ) 
 
  232               norm = normal[k][0] * normal[k][0] + normal[k][1] * normal[k][1] 
 
  233                 + normal[k][2] * normal[k][2];
 
  235               normal[k][0] *= 
norm;
 
  236               normal[k][1] *= 
norm;
 
  237               normal[k][2] *= 
norm;
 
  246   template <
int D, 
typename T>
 
  251                                  std::vector<size_t> ** overtIndex )
 
  257       * overtIndex = 
new std::vector<size_t>;
 
  263     while( jmt != emt || jtt != ett )
 
  270       std::vector<Point3df>  & overt = mh.
vertex();
 
  271       std::vector<Point3df>  & onorm = mh.
normal();
 
  272       std::vector<AimsVector<uint, D> > & opoly = mh.
polygon();
 
  273       const std::vector<Point3df>  & vert = imt->second.
vertex();
 
  274       const std::vector<Point3df>  & 
norm = imt->second.
normal();
 
  275       const std::vector<AimsVector<uint, D> > & poly = imt->second.
polygon();
 
  276       typename std::vector<AimsVector<uint, D> >::const_iterator
 
  280       std::map<uint, uint> vmap;
 
  281       typename std::map<uint, uint>::iterator iv, ev = vmap.end();
 
  283       bool  absmaj, hasdist;
 
  287       for( im=poly.begin(); im != em; ++im )
 
  289         std::map<int16_t, unsigned> vals;
 
  296           g += vert[ (*im)[k] ];
 
  298           unsigned  & x = vals[y];
 
  309         if( vals[ value ] == 
nt )
 
  321               if( vals[ y ] == 
nt )
 
  323                 dist2 = ( vert[ (*im)[k] ] - g ).
norm2();
 
  324                 if( !hasdist || dist2 < dist )
 
  344             iv = vmap.find( (*im)[k] );
 
  347               vmap[ (*im)[k] ] = i;
 
  349               overt.push_back( vert[ (*im)[k] ] );
 
  350               onorm.push_back( 
norm[ (*im)[k] ] );
 
  352                 (** overtIndex).push_back((*im)[k]);
 
  358           opoly.push_back( p );
 
  371   template <
int D, 
typename T>
 
  380     for( is=mesh.begin(); is!=es; ++is )
 
  383       const std::vector<Point3df>            & vert = surf.
vertex();
 
  384       const std::vector<AimsVector<uint,D> > & poly = surf.
polygon();
 
  387       std::vector<float> & tx = (*tex)[ is->first ].data();
 
  388       std::vector<unsigned> counts;
 
  389       tx.reserve( vert.size() );
 
  390       tx.insert( tx.end(), vert.size(), 0. );
 
  391       counts.reserve( vert.size() );
 
  392       counts.insert( counts.end(), vert.size(), 0 );
 
  395       typename std::vector<AimsVector<uint,D> >::const_iterator
 
  396         ip, ep = poly.end(), jp;
 
  399       for( ip=poly.begin(); ip!=ep; ++ip )
 
  405           uint vj = (*ip)[ (i+1) % D ];
 
  406           n = ( vert[ vi ] - vert[ vj ] ).
norm();
 
  416       std::vector<float>::iterator          it, et = tx.end();
 
  417       std::vector<unsigned>::const_iterator itc;
 
  419         for( it=tx.begin(), itc=counts.begin(); it!=et; ++it, ++itc )
 
  421             *it /= float( *itc );
 
  425         for( it=tx.begin(), itc=counts.begin(); it!=et; ++it, ++itc )
 
  426           *it = float( *itc ) / *it;
 
  433   template <
int D, 
typename T>
 
  441       ids, eds = denommesh.end();
 
  444     for( is=nummesh.begin(), ids=denommesh.begin(); is!=es && ids!=eds;
 
  448       const std::vector<Point3df>            & vert = surf.
vertex();
 
  449       const std::vector<AimsVector<uint,D> > & poly = surf.
polygon();
 
  450       const std::vector<Point3df>            & dvert = ids->second.vertex();
 
  453       std::vector<float> & tx = (*tex)[ is->first ].data();
 
  454       std::vector<unsigned> counts;
 
  455       tx.reserve( vert.size() );
 
  456       tx.insert( tx.end(), vert.size(), 0. );
 
  457       counts.reserve( vert.size() );
 
  458       counts.insert( counts.end(), vert.size(), 0 );
 
  461       typename std::vector<AimsVector<uint,D> >::const_iterator
 
  462         ip, ep = poly.end(), jp;
 
  465       for( ip=poly.begin(); ip!=ep; ++ip )
 
  471           uint vj = (*ip)[ (i+1) % D ];
 
  472           n = ( vert[ vi ] - vert[ vj ] ).
norm();
 
  473           dn = ( dvert[ vi ] - dvert[ vj ] ).
norm();
 
  478           tx[ vi ] = std::max( tx[ vi ], n );
 
  479           tx[ vj ] = std::max( tx[ vj ], n );
 
  505       std::map<std::pair<uint,uint>, 
uint> & segments,
 
  507       const std::vector<Point3df> & vert,
 
  508       std::vector<Point3df> & overt )
 
  510       std::pair<uint,uint> seg = std::make_pair( i, j );
 
  511       std::map<std::pair<uint,uint>, 
uint>::const_iterator
 
  512         iseg = segments.find( seg );
 
  514       if( iseg == segments.end() )
 
  516         Point3df p = ( vert[i] + vert[j] ) / 2;
 
  518         overt.push_back( p );
 
  519         segments[ seg ] = iout;
 
  529   template <
typename T>
 
  534     const std::vector<Point3df> & vert = mesh.
vertex();
 
  535     const std::vector<AimsVector<uint,3> > & poly = mesh.
polygon();
 
  537     std::map<std::pair<uint,uint>, 
uint> segments;
 
  538     std::vector<AimsVector<uint,3> >::const_iterator ip, ep = poly.end();
 
  541     std::vector<Point3df> & overt = outmesh->
vertex();
 
  542     std::vector<AimsVector<uint,2> > & opoly = outmesh->
polygon();
 
  544     for( ip=poly.begin(); ip!=ep; ++ip )
 
  570         if( tex[i] == region )
 
  574         if( tex[j] == region )
 
  578         if( tex[k] == region )
 
  585         if( tex[i] != tex[j] && tex[i] != tex[k] && tex[j] != tex[k] )
 
  588           Point3df center = ( vert[i] + vert[j] + vert[k] ) / 3.;
 
  590           overt.push_back( center );
 
  605           if( tex[i] == tex[j] )
 
  609           if( tex[i] == tex[k] )
 
  616       if( !done && ( ii != jj || ii != kk ) )
 
  618         std::vector<uint> ipts;
 
  635   template <
typename T>
 
  640     AimsSurfaceTriangle::const_iterator imesh, jmesh, emesh = mesh.end();
 
  641     imesh = mesh.begin();
 
  646       itex = tex.begin(), jtex=itex, etex = tex.end();
 
  650     while( imesh != emesh && itex != etex )
 
  652       unsigned mtimestep = imesh->first;
 
  653       unsigned ttimestep = itex->first;
 
  657       (*outmesh)[ std::max( mtimestep, ttimestep ) ] = *tmesh;
 
  659       if( jmesh == emesh && jtex == etex )
 
  661       if( jmesh != emesh && ( jtex == etex || jmesh->first < jtex->first ) )
 
  666       else if( jtex != etex
 
  667                && ( jmesh == emesh || jmesh->first > jtex->first ) )
 
  690   template <
int D, 
typename T>
 
  695     const std::vector<Point3df> & vert = mesh[timestep].
vertex();
 
  696     std::vector<AimsVector<uint, D> > & poly = mesh[timestep].
polygon();
 
  697     std::multimap<float, AimsVector<uint, D> > sorted;
 
  698     typename std::vector<AimsVector<uint, D> >::iterator
 
  700     typename std::multimap<float, AimsVector<uint, D> >::iterator
 
  701       im, em = sorted.end();
 
  706     for( ip=poly.begin(); ip!=ep; ++ip )
 
  708       center = vert[(*ip)[0]];
 
  710         center += vert[(*ip)[d]];
 
  711       sorted.insert( std::make_pair( center.
dot( direction ), *ip ) );
 
  715     for( im=sorted.begin(), ip=poly.begin(); im!=em; ++im, ++ip )
 
  720   template <
int D, 
typename T>
 
  721   std::pair<carto::rc_ptr< AimsTimeSurface<D, Void> >,
 
  730     for( im=texmesh.begin(); im!=em; ++im )
 
  740     mesh->header().copyProperties(
 
  742     tex->header().copyProperties(
 
  745     return std::make_pair( mesh, tex );
 
  749   template <
int D, 
typename T>
 
  760     std::set<int> timesteps;
 
  761     for( im=mesh.begin(); im!=em; ++im )
 
  762       timesteps.insert( im->first );
 
  763     for( it=texture.begin(); it!=et; ++it )
 
  764       timesteps.insert( it->first );
 
  765     std::set<int>::iterator is, es = timesteps.end();
 
  767     for( is=timesteps.begin(); is!=es; ++is )
 
  769       im = mesh.lower_bound( *is );
 
  772       it = texture.lower_bound( *is );
 
  779         m.
texture() = it->second.data();
 
  782     texmesh->header().copyProperties(
 
  784     texmesh->header().copyProperties(
 
The template class to manage a mesh.
const std::vector< Point3df > & normal() const
Get a const reference to the vector of normals.
const std::vector< Point3df > & vertex() const
Get a const reference to the vector of vertices.
const std::vector< T > & texture() const
Get a const reference to the vector of textures.
const std::vector< AimsVector< uint, D > > & polygon() const
Get a const reference to the vector of polygons.
The template class to manage a mesh with time if needed.
void erase()
Clear all the meshes.
const std::vector< AimsVector< uint, D > > & polygon() const
Get a const reference to the vector of polygons of the 0 surface.
const std::vector< T > & texture() const
Get a const reference to the vector of textures of the 0 surface.
std::map< int, AimsSurface< D, T > >::iterator iterator
const aims::PythonHeader & header() const
Get the header.
std::map< int, AimsSurface< D, T > >::const_iterator const_iterator
const std::vector< Point3df > & normal() const
Get a const reference to the vector of normals of the 0 surface.
const std::vector< Point3df > & vertex() const
Get a const reference to the vector of verteces of the surface of index 0.
T dot(const AimsVector< T, D > &other) const
const std::vector< T > & data() const
const aims::PythonHeader & header() const
Get the header.
std::map< int, Texture< T > >::const_iterator const_iterator
static void sortPolygonsAlongDirection(AimsTimeSurface< D, T > &mesh, int timestep, const Point3df &direction)
Sort polygons along a given direction.
static AimsTimeSurface< D, T > * meshExtract(const AimsTimeSurface< D, T > &mesh, const TimeTexture< int16_t > &tex, int16_t value, std::vector< size_t > **overtIndex=0)
Extracts a sub-mesh region from a label texture.
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 std::vector< std::map< uint, float > > surfaceNeighbourDistance(const AimsTimeSurface< D, T > &surf)
static void meshTransform(AimsTimeSurface< D, T > &mesh, const Motion &trans)
Applies a transformation to a mesh.
static void meshMerge(AimsTimeSurface< D, T > &dst, const AimsTimeSurface< D, T > &add)
concatenates 2 meshes into one (adds the second to the first one)
static std::pair< carto::rc_ptr< AimsTimeSurface< D, Void > >, carto::rc_ptr< TimeTexture< T > > > splitTexturedMesh(const AimsTimeSurface< D, T > &texmesh)
Split a textured mesh into a mesh and a texture.
static carto::rc_ptr< AimsTimeSurface< D, T > > joinTexturedMesh(const AimsTimeSurface< D, Void > &mesh, const TimeTexture< T > &texture)
Join a mesh and a texture into a textured mesh.
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,...
static std::vector< std::set< uint > > surfaceNeighbours(const AimsSurface< D, T > &surf)
static std::vector< std::set< uint > > surfaceNeighbours2ndOrder(const AimsTimeSurface< D, T > &surf)
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.
virtual void copyProperties(Object source)
Object reference(Object &value)
virtual void setProperty(const std::string &, Object)
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 class for EcatSino data write operation.
AIMSDATA_API AimsTimeSurface< 3, Void > AimsSurfaceTriangle
AIMSDATA_API float norm(const Tensor &thing)
float norm2(const AimsVector< T, D > &v1)