34 #ifndef AIMS_DISTANCEMAP_MESHDISTANCE_D_H
35 #define AIMS_DISTANCEMAP_MESHDISTANCE_D_H
44 bool allowUnreached,
float max_dist )
47 const std::vector<Point3df> & vert = mesh.
vertex();
48 const std::vector< AimsVector<uint,3> > & poly = mesh.
polygon();
49 unsigned i, n = vert.size();
56 std::map<unsigned, std::set<unsigned> > neighbours;
59 for( i=0; i<poly.size(); ++i )
67 neighbours[v1].insert( v2 );
68 neighbours[v2].insert( v1 );
73 neighbours[v1].insert( v3 );
74 neighbours[v3].insert( v1 );
79 neighbours[v2].insert( v3 );
80 neighbours[v3].insert( v2 );
88 if( inittex.
item(i) == 0 )
96 std::multimap<float,unsigned> front1, front2;
97 std::multimap<float,unsigned> *cfront = &front1, *nfront = &front2, *tmpf;
98 std::multimap<float,unsigned>::iterator iv, fv;
99 std::set<unsigned> neigh;
100 std::set<unsigned>::iterator in, fn;
107 if( tex.
item(i) == 0 )
108 front1.insert( std::pair<float,unsigned>( 0, i ) );
112 while( cfront->size() > 0 )
117 for( iv=cfront->begin(), fv=cfront->end(); iv!=fv; ++iv )
121 for( in=neighbours[i].begin(), fn=neighbours[i].end(); in!=fn; ++in )
123 d2 = tex.
item( *in );
124 pos = vert[i] - vert[*in];
125 l = sqrt( pos[0] * pos[0] + pos[1] * pos[1] + pos[2] * pos[2] );
127 if( d2 > nd && nd < max_dist )
129 tex.
item( *in ) = nd;
135 for( in=neigh.begin(), fn=neigh.end(); in!=fn; ++in )
136 nfront->insert( std::pair<float,unsigned>( tex.
item( *in ), *in ) );
144 if( !allowUnreached )
146 if( tex.
item(i) == FLT_MAX )
155 namespace meshdistance
158 template <
typename T>
162 static void resize( T & mat,
size_t size1,
size_t size2 = 0 )
167 template <
typename T>
173 static void resize( std::vector<T> & mat,
size_t size1,
179 static void storeLine( std::vector<T> & mat,
size_t line,
180 const std::vector<float> & tex )
183 size_t i, n = tex.size();
191 template <
typename T,
typename U>
195 static void resize( T & mat,
size_t size1,
size_t size2 = 0 )
201 if( value != FLT_MAX )
210 template <
typename T,
typename MapType>
217 const std::vector<Point3df> & vert = mesh.
vertex();
218 const std::vector< AimsVector<uint,3> > & poly = mesh.
polygon();
219 unsigned i, n = vert.size();
220 std::vector<float> tex, ctex( n );
222 bool has_init = ( inittex.
size() != 0 );
228 std::map<unsigned, std::set<unsigned> > neighbours;
231 for( i=0; i<poly.size(); ++i )
239 neighbours[v1].insert( v2 );
240 neighbours[v2].insert( v1 );
245 neighbours[v1].insert( v3 );
246 neighbours[v3].insert( v1 );
251 neighbours[v2].insert( v3 );
252 neighbours[v3].insert( v2 );
267 for( start=0; start<n; ++start )
276 std::multimap<float,unsigned> front1, front2;
277 std::multimap<float,unsigned> *cfront = &front1, *nfront = &front2, *tmpf;
278 std::multimap<float,unsigned>::iterator iv, fv;
279 std::set<unsigned> neigh;
280 std::set<unsigned>::iterator in, fn;
286 front1.insert( std::pair<float,unsigned>( 0., start ) );
290 while( cfront->size() > 0 )
295 for( iv=cfront->begin(), fv=cfront->end(); iv!=fv; ++iv )
299 for( in=neighbours[i].begin(), fn=neighbours[i].end(); in!=fn; ++in )
302 pos = vert[i] - vert[*in];
303 l = sqrt( pos[0] * pos[0] + pos[1] * pos[1] + pos[2] * pos[2] );
305 if( d2 > nd && nd < max_dist )
313 for( in=neigh.begin(), fn=neigh.end(); in!=fn; ++in )
314 nfront->insert( std::pair<float,unsigned>( tex[ *in ], *in ) );
const std::vector< Point3df > & vertex() const
const std::vector< AimsVector< uint, D > > & polygon() const
void reserve(size_t size)
const T & item(int n) const
void push_back(const T &item)
static void storeElement(std::map< T, U > &map, T i, float value)
static void resize(T &mat, size_t size1, size_t size2=0)
static void storeLine(std::vector< T > &mat, size_t line, const std::vector< float > &tex)
static void resize(std::vector< T > &mat, size_t size1, size_t size2=0)
static void resize(T &mat, size_t size1, size_t size2=0)
const short MESHDISTANCE_UNREACHED
void pairwiseDistanceMaps(const AimsSurface< 3, Void > &mesh, MapType &distmaps, const Texture< T > &inittex, float max_dist=FLT_MAX)
Computes a distance matrix over a mesh.
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.
const short MESHDISTANCE_FORBIDDEN
global variable...