1 /****************************************************************************
2 * VCGLib                                                            o o     *
3 * Visual and Computer Graphics Library                            o     o   *
4 *                                                                _   O  _   *
5 * Copyright(C) 2004-2016                                           \/)\/    *
6 * Visual Computing Lab                                            /\/|      *
7 * ISTI - Italian National Research Council                           |      *
8 *                                                                    \      *
9 * All rights reserved.                                                      *
10 *                                                                           *
11 * This program is free software; you can redistribute it and/or modify      *
12 * it under the terms of the GNU General Public License as published by      *
13 * the Free Software Foundation; either version 2 of the License, or         *
14 * (at your option) any later version.                                       *
15 *                                                                           *
16 * This program is distributed in the hope that it will be useful,           *
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of            *
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the             *
19 * GNU General Public License (http://www.gnu.org/licenses/gpl.txt)          *
20 * for more details.                                                         *
21 *                                                                           *
22 ****************************************************************************/
23 #ifndef __VCG_MESH
24 #error "This file should not be included alone. It is automatically included by complex.h"
25 #endif
26 #ifndef __VCG_COMPLEX_BASE
27 #define __VCG_COMPLEX_BASE
28 
29 namespace vcg {
30 
31 class PointerToAttribute
32 {
33 public:
34     SimpleTempDataBase * _handle;		// pointer to the SimpleTempData that stores the attribute
35     std::string _name;					// name of the attribute
36     int _sizeof;						// size of the attribute type (used only with VMI loading)
37     int _padding;						// padding 	(used only with VMI loading)
38 
39     int n_attr;							// unique ID of the attribute
40 
Resize(size_t sz)41     void Resize(size_t sz){((SimpleTempDataBase *)_handle)->Resize(sz);}
Reorder(std::vector<size_t> & newVertIndex)42     void Reorder(std::vector<size_t> & newVertIndex){((SimpleTempDataBase *)_handle)->Reorder(newVertIndex);}
43     bool operator<(const  PointerToAttribute    b) const {	return(_name.empty()&&b._name.empty())?(_handle < b._handle):( _name < b._name);}
44 };
45 
46 
47 namespace tri {
48 /** \addtogroup trimesh */
49 /*@{*/
50 
51 
52  /* MeshTypeHolder is a class which is used to define the types in the mesh
53 */
54 
55         template <class TYPESPOOL>
56         struct BaseMeshTypeHolder{
57 
58                 typedef bool ScalarType;
59                 typedef std::vector< typename TYPESPOOL::VertexType  >	CONTV;
60                 typedef std::vector< typename TYPESPOOL::EdgeType  >		CONTE;
61                 typedef std::vector< typename TYPESPOOL::FaceType >		CONTF;
62                 typedef std::vector< typename TYPESPOOL::HEdgeType  >		CONTH;
63 
64                 typedef CONTV									VertContainer;
65                 typedef _Vertex 								VertexType;
66                 typedef typename TYPESPOOL::VertexPointer		VertexPointer;
67                 typedef const typename TYPESPOOL::VertexPointer ConstVertexPointer;
68                 typedef bool									CoordType;
69                 typedef typename CONTV::iterator				VertexIterator;
70                 typedef typename CONTV::const_iterator	ConstVertexIterator;
71 
72                 typedef CONTE										EdgeContainer;
73                 typedef typename CONTE::value_type					EdgeType;
74                 typedef typename  TYPESPOOL::EdgePointer	EdgePointer;
75                 typedef typename CONTE::iterator				EdgeIterator;
76                 typedef typename CONTE::const_iterator	ConstEdgeIterator;
77 
78                 typedef CONTF														FaceContainer;
79                 typedef typename CONTF::value_type					FaceType;
80                 typedef typename CONTF::const_iterator				ConstFaceIterator;
81                 typedef typename CONTF::iterator					FaceIterator;
82                 typedef typename TYPESPOOL::FacePointer	FacePointer;
83                 typedef const typename TYPESPOOL::FacePointer		ConstFacePointer;
84 
85                 typedef CONTH														HEdgeContainer;
86                 typedef typename CONTH::value_type			HEdgeType;
87                 typedef typename TYPESPOOL::HEdgePointer					HEdgePointer;
88                 typedef typename CONTH::iterator				HEdgeIterator;
89                 typedef typename CONTH::const_iterator	ConstHEdgeIterator;
90 
91 
92         };
93 
94 
95 
96         template <class T, typename CONT, class TRAIT >
97                         struct MeshTypeHolder: public T {};
98 
99         template <class T, typename CONT>
100                         struct MeshTypeHolder<T, CONT, AllTypes::AVertexType>: public T {
101                                 typedef CONT VertContainer;
102                                 typedef typename VertContainer::value_type VertexType;
103                                 typedef VertexType * VertexPointer;
104                                 typedef const VertexType * ConstVertexPointer;
105                                 typedef typename VertexType::ScalarType ScalarType;
106                                 typedef typename VertexType::CoordType CoordType;
107                                 typedef typename VertContainer::iterator VertexIterator;
108                                 typedef typename VertContainer::const_iterator ConstVertexIterator;
109         };
110 
111 
112     template <typename T, class CONT>
113                     struct MeshTypeHolder< T, CONT, AllTypes::AEdgeType>: public T{
114                                 typedef CONT EdgeContainer;
115                                 typedef typename EdgeContainer::value_type EdgeType;
116                                 typedef typename EdgeContainer::value_type *  EdgePointer;
117                                 typedef typename EdgeContainer::iterator EdgeIterator;
118                                 typedef typename EdgeContainer::const_iterator ConstEdgeIterator;
119 };
120 
121     template <typename T, class CONT>
122                     struct MeshTypeHolder< T, CONT,  AllTypes::AFaceType>:public T {
123                                 typedef CONT FaceContainer;
124                                 typedef typename FaceContainer::value_type FaceType;
125                                 typedef typename FaceContainer::const_iterator ConstFaceIterator;
126                                 typedef typename FaceContainer::iterator FaceIterator;
127                                 typedef FaceType * FacePointer;
128                                 typedef const FaceType * ConstFacePointer;
129                 };
130 
131     template <typename T, class CONT>
132                     struct MeshTypeHolder< T, CONT, AllTypes::AHEdgeType>: public T{
133                                 typedef CONT HEdgeContainer;
134                                 typedef typename HEdgeContainer::value_type			HEdgeType;
135                                 typedef typename HEdgeContainer::value_type *		HEdgePointer;
136                                 typedef typename HEdgeContainer::iterator				HEdgeIterator;
137                                 typedef typename HEdgeContainer::const_iterator ConstHEdgeIterator;
138 };
139 
140 template <typename T, typename CONT> struct Der: public MeshTypeHolder<T,CONT, typename CONT::value_type::IAm>{};
141 struct DummyContainer{struct value_type{ typedef int IAm;}; };
142 /** \brief The official \b mesh class
143 
144 As explained in \ref basic_concepts, this class is templated over a list of container of simplexes (like vertex, face, edges)
145  */
146 
147 template < class Container0 = DummyContainer, class Container1 = DummyContainer, class Container2 = DummyContainer, class Container3 = DummyContainer >
148 class TriMesh
149     : public  MArity4<   BaseMeshTypeHolder<typename Container0::value_type::TypesPool>, Container0, Der ,Container1, Der, Container2, Der, Container3, Der>{
150     public:
151 
152         typedef typename TriMesh::ScalarType		ScalarType;
153         typedef typename TriMesh::VertContainer VertContainer;
154         typedef typename TriMesh::EdgeContainer EdgeContainer;
155         typedef typename TriMesh::FaceContainer FaceContainer;
156 
157         // types for vertex
158         typedef typename TriMesh::VertexType						VertexType;
159         typedef typename TriMesh::VertexPointer					VertexPointer;
160         typedef typename TriMesh::ConstVertexPointer		ConstVertexPointer;
161         typedef typename TriMesh::CoordType							CoordType;
162         typedef typename TriMesh::VertexIterator				VertexIterator;
163         typedef typename TriMesh::ConstVertexIterator		ConstVertexIterator;
164 
165         // types for edge
166         typedef typename TriMesh::EdgeType							EdgeType;
167         typedef typename TriMesh::EdgePointer						EdgePointer;
168         typedef typename TriMesh::EdgeIterator					EdgeIterator;
169         typedef typename TriMesh::ConstEdgeIterator			ConstEdgeIterator;
170 
171         //types for face
172         typedef typename TriMesh::FaceType							FaceType;
173         typedef typename TriMesh::ConstFaceIterator			ConstFaceIterator;
174         typedef typename TriMesh::FaceIterator					FaceIterator;
175         typedef typename TriMesh::FacePointer						FacePointer;
176         typedef typename TriMesh::ConstFacePointer			ConstFacePointer;
177 
178         // types for hedge
179         typedef typename TriMesh::HEdgeType							HEdgeType;
180         typedef typename TriMesh::HEdgePointer					HEdgePointer;
181         typedef typename TriMesh::HEdgeIterator					HEdgeIterator;
182         typedef typename TriMesh::HEdgeContainer				HEdgeContainer;
183         typedef typename TriMesh::ConstHEdgeIterator		ConstHEdgeIterator;
184 
185         typedef vcg::PointerToAttribute PointerToAttribute;
186 
187     typedef TriMesh<Container0, Container1,Container2,Container3> MeshType;
188 
189     typedef Box3<ScalarType> BoxType;
190 
191     /// Container of vertices, usually a vector.
192     VertContainer vert;
193     /// Current number of vertices; this member is for internal use only. You should always use the VN() member
194     int vn;
195     /// Current number of vertices
196     inline int VN() const { return vn; }
197 
198     /// Container of edges, usually a vector.
199     EdgeContainer edge;
200     /// Current number of edges; this member is for internal use only. You should always use the EN() member
201     int en;
202     /// Current number of edges
203     inline int EN() const { return en; }
204 
205     /// Container of faces, usually a vector.
206     FaceContainer face;
207     /// Current number of faces; this member is for internal use only. You should always use the FN() member
208     int fn;
209     /// Current number of faces
210     inline int FN() const { return fn; }
211 
212     /// Container of half edges, usually a vector.
213     HEdgeContainer hedge;
214     /// Current number of halfedges; this member is for internal use only. You should always use the HN() member
215     int hn;
216     /// Current number of halfedges;
217     inline int HN() const { return hn; }
218 
219     /// Bounding box of the mesh
220     Box3<typename TriMesh::VertexType::CoordType::ScalarType> bbox;
221 
222   /// Nomi di textures
223     //
224   std::vector<std::string> textures;
225     //
226   std::vector<std::string> normalmaps;
227 
228     int attrn;	// total numer of attribute created
229 
230 
231     std::set< PointerToAttribute > vert_attr;
232     std::set< PointerToAttribute > edge_attr;
233     std::set< PointerToAttribute > face_attr;
234     std::set< PointerToAttribute > mesh_attr;
235 
236 
237 
238     template <class ATTR_TYPE, class CONT>
239     class AttributeHandle{
240     public:
241         AttributeHandle(){_handle=(SimpleTempData<CONT,ATTR_TYPE> *)NULL;}
242         AttributeHandle( void *ah,const int & n):_handle ( (SimpleTempData<CONT,ATTR_TYPE> *)ah ),n_attr(n){}
243                 AttributeHandle operator = ( const PointerToAttribute & pva){
244             _handle = (SimpleTempData<CONT,ATTR_TYPE> *)pva._handle;
245             n_attr = pva.n_attr;
246             return (*this);
247         }
248 
249         //pointer to the SimpleTempData that stores the attribute
250         SimpleTempData<CONT,ATTR_TYPE> * _handle;
251 
252         // its attribute number
253         int n_attr;
254 
255         // access function
256         template <class RefType>
257         ATTR_TYPE & operator [](const RefType  & i){return (*_handle)[i];}
258         void resize(size_t /*size*/) { };
259     };
260 
261     template <class ATTR_TYPE>
262     class PerVertexAttributeHandle: public AttributeHandle<ATTR_TYPE,VertContainer>{
263     public:
264         PerVertexAttributeHandle():AttributeHandle<ATTR_TYPE,VertContainer>(){}
265                 PerVertexAttributeHandle( void *ah,const int & n):AttributeHandle<ATTR_TYPE,VertContainer>(ah,n){}
266     };
267 
268 
269     template <class ATTR_TYPE>
270     class PerFaceAttributeHandle: public AttributeHandle<ATTR_TYPE,FaceContainer>{
271     public:
272         PerFaceAttributeHandle():AttributeHandle<ATTR_TYPE,FaceContainer>(){}
273                 PerFaceAttributeHandle( void *ah,const int & n):AttributeHandle<ATTR_TYPE,FaceContainer>(ah,n){}
274     };
275 
276     template <class ATTR_TYPE>
277     class PerEdgeAttributeHandle:  public AttributeHandle<ATTR_TYPE,EdgeContainer>{
278     public:
279         PerEdgeAttributeHandle():AttributeHandle<ATTR_TYPE,EdgeContainer>(){}
280                 PerEdgeAttributeHandle( void *ah,const int & n):AttributeHandle<ATTR_TYPE,EdgeContainer>(ah,n){}
281     };
282 
283     template <class ATTR_TYPE>
284     class PerMeshAttributeHandle{
285     public:
286         PerMeshAttributeHandle(){_handle=NULL;}
287         PerMeshAttributeHandle(void *ah,const int & n):_handle ( (Attribute<ATTR_TYPE> *)ah ),n_attr(n){}
288         PerMeshAttributeHandle operator = ( const PerMeshAttributeHandle & pva){
289             _handle = (Attribute<ATTR_TYPE> *)pva._handle;
290             n_attr = pva.n_attr;
291             return (*this);
292         }
293 
294         Attribute<ATTR_TYPE> * _handle;
295         int n_attr;
296         ATTR_TYPE & operator ()(){ return *((Attribute<ATTR_TYPE> *)_handle)->attribute;}
297     };
298 
299     // Some common Handle typedefs to simplify use
300     typedef typename MeshType::template PerVertexAttributeHandle<ScalarType> PerVertexScalarHandle;
301     typedef typename MeshType::template PerVertexAttributeHandle<int>        PerVertexIntHandle;
302     typedef typename MeshType::template PerVertexAttributeHandle<bool>       PerVertexBoolHandle;
303     typedef typename MeshType::template PerVertexAttributeHandle<CoordType>  PerVertexCoordHandle;
304 
305     typedef typename MeshType::template PerFaceAttributeHandle<ScalarType> PerFaceScalarHandle;
306     typedef typename MeshType::template PerFaceAttributeHandle<int>        PerFaceIntHandle;
307     typedef typename MeshType::template PerFaceAttributeHandle<bool>       PerFaceBoolHandle;
308     typedef typename MeshType::template PerFaceAttributeHandle<CoordType>  PerFaceCoordHandle;
309 
310 
311     // the camera member (that should keep the intrinsics) is no more needed since 2006, when intrisncs moved into the Shot structure
312     //Camera<ScalarType> camera; // intrinsic
313     Shot<ScalarType> shot;		// intrinsic && extrinsic
314 
315 private:
316     /// The per-mesh color. Not very useful and meaningful...
317     Color4b c;
318 public:
319 
320     inline const Color4b &C() const	{ return c; }
321     inline       Color4b &C()       { return c;  }
322     inline       Color4b cC() const { return c;  }
323 
324     /// Default constructor
325     TriMesh()
326     {
327       Clear();
328     }
329 
330     /// destructor
331     ~TriMesh()
332     {
333       Clear();
334     }
335 
336      int Mem(const int & nv, const int & nf) const  {
337         typename std::set< PointerToAttribute>::const_iterator i;
338         int size = 0;
339         size += sizeof(TriMesh)+sizeof(VertexType)*nv+sizeof(FaceType)*nf;
340 
341         for( i = vert_attr.begin(); i != vert_attr.end(); ++i)
342             size += ((SimpleTempDataBase*)(*i)._handle)->SizeOf()*nv;
343         for( i = edge_attr.begin(); i != edge_attr.end(); ++i)
344             size += ((SimpleTempDataBase*)(*i)._handle)->SizeOf()*en;
345         for( i = face_attr.begin(); i != face_attr.end(); ++i)
346             size +=  ((SimpleTempDataBase*)(*i)._handle)->SizeOf()*nf;
347         for( i = mesh_attr.begin(); i != mesh_attr.end(); ++i)
348             size +=  ((SimpleTempDataBase*)(*i)._handle)->SizeOf();
349 
350         return size;
351     }
352     int MemUsed() const  {return Mem(vert.size(),face.size());}
353     inline int MemNeeded() const {return Mem(vn,fn);}
354 
355 
356 
357   /// Function to destroy the mesh
358   void Clear()
359   {
360     for(FaceIterator fi = face.begin(); fi != face.end(); ++fi)
361       (*fi).Dealloc();
362     vert.clear();
363     face.clear();
364     edge.clear();
365 //    textures.clear();
366 //    normalmaps.clear();
367     vn = 0;
368     en = 0;
369     fn = 0;
370     hn = 0;
371     imark = 0;
372     C()=Color4b::Gray;
373   }
374 
375 
376   void ClearAttributes()
377   {
378 	  // Clear attributes
379 	  typename std::set< PointerToAttribute>::iterator i;
380 	  for (i = vert_attr.begin(); i != vert_attr.end(); ++i)
381 		  delete ((SimpleTempDataBase*)(*i)._handle);
382 	  vert_attr.clear();
383 
384 	  for (i = edge_attr.begin(); i != edge_attr.end(); ++i)
385 		  delete ((SimpleTempDataBase*)(*i)._handle);
386 	  edge_attr.clear();
387 
388 	  for (i = face_attr.begin(); i != face_attr.end(); ++i)
389 		  delete ((SimpleTempDataBase*)(*i)._handle);
390 	  face_attr.clear();
391 
392 	  for (i = mesh_attr.begin(); i != mesh_attr.end(); ++i)
393 		  delete ((SimpleTempDataBase*)(*i)._handle);
394 	  mesh_attr.clear();
395     attrn = 0;
396   }
397 
398   bool IsEmpty() const
399   {
400     return vert.empty() && edge.empty() && face.empty();
401   }
402 
403   int & SimplexNumber(){ return fn;}
404   int & VertexNumber(){ return vn;}
405 
406   /// The incremental mark
407   int imark;
408 
409 private:
410     // TriMesh cannot be copied. Use Append (see vcg/complex/append.h)
411   TriMesh operator =(const TriMesh &  /*m*/){assert(0);return TriMesh();}
412   TriMesh(const TriMesh & ){}
413 
414 };	// end class Mesh
415 
416 /// Initialize the imark-system of the faces
417 template <class MeshType> inline  void InitFaceIMark(MeshType & m)
418 {
419     typename MeshType::FaceIterator f;
420 
421     for(f=m.face.begin();f!=m.face.end();++f)
422         if( !(*f).IsD() && (*f).IsR() && (*f).IsW() )
423             (*f).InitIMark();
424 }
425 
426 /// Initialize the imark-system of the vertices
427 template <class MeshType> inline  void InitVertexIMark(MeshType & m)
428 {
429     typename MeshType::VertexIterator vi;
430 
431     for(vi=m.vert.begin();vi!=m.vert.end();++vi)
432         if( !(*vi).IsD() && (*vi).IsRW() )
433             (*vi).InitIMark();
434 }
435 /** \brief Access function to the incremental mark.
436   You should not use this member directly. In most of the case just use IsMarked() and Mark()
437 */
438 template <class MeshType> inline int & IMark(MeshType & m){return m.imark;}
439 
440 /** \brief Check if the vertex incremental mark matches the one of the mesh.
441     @param m the mesh containing the element
442     @param v Vertex pointer */
443 template <class MeshType> inline bool IsMarked(MeshType & m, typename MeshType::ConstVertexPointer  v )  { return v->cIMark() == m.imark; }
444 
445 /** \brief Check if the face incremental mark matches the one of the mesh.
446     @param m the mesh containing the element
447     @param f Face pointer */
448 template <class MeshType> inline bool IsMarked( MeshType & m,typename MeshType::ConstFacePointer f )  { return f->cIMark() == m.imark; }
449 
450 /** \brief Set the vertex incremental mark of the vertex to the one of the mesh.
451     @param m the mesh containing the element
452     @param v Vertex pointer */
453 template <class MeshType> inline void Mark(MeshType & m, typename MeshType::VertexPointer v )  { v->IMark() = m.imark; }
454 
455 /** \brief Set the face incremental mark of the vertex to the one of the mesh.
456     @param m the mesh containing the element
457     @param f Vertex pointer */
458 template <class MeshType> inline void Mark(MeshType & m, typename MeshType::FacePointer f )  { f->IMark() = m.imark; }
459 
460 
461 /** \brief Unmark, in constant time, all the elements (face and vertices) of a mesh.
462     @param m the mesh containing the element
463 
464     In practice this function just increment the internal counter that stores the value for which an element is considered marked;
465     therefore all the mesh elements become immediately un-mmarked.
466     */
467 template <class MeshType> inline void UnMarkAll(MeshType & m)
468 {
469   ++m.imark;
470 }
471 
472 
473 //template < class CType0, class CType1 , class CType2, class CType3>
474 //bool HasPerVertexVEAdjacency (const TriMesh < CType0, CType1, CType2, CType3> & /*m*/) {return TriMesh < CType0 , CType1, CType2, CType3>::VertContainer::value_type::HasVEAdjacency();}
475 //template < class  CType0, class CType1, class CType2 , class CType3>
476 //bool HasPerEdgeVEAdjacency   (const TriMesh < CType0, CType1, CType2, CType3> & /*m*/) {return TriMesh < CType0 , CType1, CType2, CType3>::EdgeContainer::value_type::HasVEAdjacency();}
477 
478 template < class VertexType> bool VertexVectorHasVFAdjacency     (const std::vector<VertexType> &) {  return VertexType::HasVFAdjacency(); }
479 template < class VertexType> bool VertexVectorHasVEAdjacency     (const std::vector<VertexType> &) {  return VertexType::HasVEAdjacency(); }
480 template < class EdgeType  > bool   EdgeVectorHasVEAdjacency     (const std::vector<EdgeType  > &) {  return EdgeType::HasVEAdjacency(); }
481 template < class EdgeType  > bool   EdgeVectorHasEEAdjacency     (const std::vector<EdgeType> &) {  return EdgeType::HasEEAdjacency(); }
482 template < class FaceType  > bool   FaceVectorHasVFAdjacency     (const std::vector<FaceType  > &) {  return FaceType::HasVFAdjacency(); }
483 
484 template < class TriMeshType> bool HasPerVertexVFAdjacency     (const TriMeshType &m) { return tri::VertexVectorHasVFAdjacency(m.vert); }
485 template < class TriMeshType> bool HasPerVertexVEAdjacency     (const TriMeshType &m) { return tri::VertexVectorHasVEAdjacency(m.vert); }
486 template < class TriMeshType> bool   HasPerEdgeVEAdjacency     (const TriMeshType &m) { return tri::EdgeVectorHasVEAdjacency  (m.edge); }
487 template < class TriMeshType> bool   HasPerFaceVFAdjacency     (const TriMeshType &m) { return tri::FaceVectorHasVFAdjacency  (m.face); }
488 
489 
490 template < class VertexType> bool VertexVectorHasPerVertexQuality     (const std::vector<VertexType> &) {  return VertexType::HasQuality     (); }
491 template < class VertexType> bool VertexVectorHasPerVertexNormal      (const std::vector<VertexType> &) {  return VertexType::HasNormal      (); }
492 template < class VertexType> bool VertexVectorHasPerVertexColor       (const std::vector<VertexType> &) {  return VertexType::HasColor       (); }
493 template < class VertexType> bool VertexVectorHasPerVertexMark        (const std::vector<VertexType> &) {  return VertexType::HasMark        (); }
494 template < class VertexType> bool VertexVectorHasPerVertexFlags       (const std::vector<VertexType> &) {  return VertexType::HasFlags       (); }
495 template < class VertexType> bool VertexVectorHasPerVertexRadius      (const std::vector<VertexType> &) {  return VertexType::HasRadius      (); }
496 template < class VertexType> bool VertexVectorHasPerVertexCurvature   (const std::vector<VertexType> &) {  return VertexType::HasCurvature   (); }
497 template < class VertexType> bool VertexVectorHasPerVertexCurvatureDir(const std::vector<VertexType> &) {  return VertexType::HasCurvatureDir(); }
498 template < class VertexType> bool VertexVectorHasPerVertexTexCoord    (const std::vector<VertexType> &) {  return VertexType::HasTexCoord    (); }
499 
500 template < class TriMeshType> bool HasPerVertexQuality     (const TriMeshType &m) { return tri::VertexVectorHasPerVertexQuality     (m.vert); }
501 template < class TriMeshType> bool HasPerVertexNormal      (const TriMeshType &m) { return tri::VertexVectorHasPerVertexNormal      (m.vert); }
502 template < class TriMeshType> bool HasPerVertexColor       (const TriMeshType &m) { return tri::VertexVectorHasPerVertexColor       (m.vert); }
503 template < class TriMeshType> bool HasPerVertexMark        (const TriMeshType &m) { return tri::VertexVectorHasPerVertexMark        (m.vert); }
504 template < class TriMeshType> bool HasPerVertexFlags       (const TriMeshType &m) { return tri::VertexVectorHasPerVertexFlags       (m.vert); }
505 template < class TriMeshType> bool HasPerVertexRadius      (const TriMeshType &m) { return tri::VertexVectorHasPerVertexRadius      (m.vert); }
506 template < class TriMeshType> bool HasPerVertexCurvature   (const TriMeshType &m) { return tri::VertexVectorHasPerVertexCurvature   (m.vert); }
507 template < class TriMeshType> bool HasPerVertexCurvatureDir(const TriMeshType &m) { return tri::VertexVectorHasPerVertexCurvatureDir(m.vert); }
508 template < class TriMeshType> bool HasPerVertexTexCoord    (const TriMeshType &m) { return tri::VertexVectorHasPerVertexTexCoord    (m.vert); }
509 
510 template < class EdgeType> bool EdgeVectorHasPerEdgeQuality     (const std::vector<EdgeType> &) {  return EdgeType::HasQuality     (); }
511 template < class EdgeType> bool EdgeVectorHasPerEdgeNormal      (const std::vector<EdgeType> &) {  return EdgeType::HasNormal      (); }
512 template < class EdgeType> bool EdgeVectorHasPerEdgeColor       (const std::vector<EdgeType> &) {  return EdgeType::HasColor       (); }
513 template < class EdgeType> bool EdgeVectorHasPerEdgeMark        (const std::vector<EdgeType> &) {  return EdgeType::HasMark        (); }
514 template < class EdgeType> bool EdgeVectorHasPerEdgeFlags       (const std::vector<EdgeType> &) {  return EdgeType::HasFlags       (); }
515 
516 template < class TriMeshType> bool HasPerEdgeQuality     (const TriMeshType &m) { return tri::EdgeVectorHasPerEdgeQuality     (m.edge); }
517 template < class TriMeshType> bool HasPerEdgeNormal      (const TriMeshType &m) { return tri::EdgeVectorHasPerEdgeNormal      (m.edge); }
518 template < class TriMeshType> bool HasPerEdgeColor       (const TriMeshType &m) { return tri::EdgeVectorHasPerEdgeColor       (m.edge); }
519 template < class TriMeshType> bool HasPerEdgeMark        (const TriMeshType &m) { return tri::EdgeVectorHasPerEdgeMark        (m.edge); }
520 template < class TriMeshType> bool HasPerEdgeFlags       (const TriMeshType &m) { return tri::EdgeVectorHasPerEdgeFlags       (m.edge); }
521 
522 
523 template < class FaceType>    bool FaceVectorHasPerWedgeColor   (const std::vector<FaceType> &) {  return FaceType::HasWedgeColor   (); }
524 template < class FaceType>    bool FaceVectorHasPerWedgeNormal  (const std::vector<FaceType> &) {  return FaceType::HasWedgeNormal  (); }
525 template < class FaceType>    bool FaceVectorHasPerWedgeTexCoord(const std::vector<FaceType> &) {  return FaceType::HasWedgeTexCoord(); }
526 
527 template < class TriMeshType> bool HasPerWedgeColor   (const TriMeshType &m) { return tri::FaceVectorHasPerWedgeColor   (m.face); }
528 template < class TriMeshType> bool HasPerWedgeNormal  (const TriMeshType &m) { return tri::FaceVectorHasPerWedgeNormal  (m.face); }
529 template < class TriMeshType> bool HasPerWedgeTexCoord(const TriMeshType &m) { return tri::FaceVectorHasPerWedgeTexCoord(m.face); }
530 
531 template < class  CType0, class CType1, class CType2 , class CType3>
532 bool HasPolyInfo (const TriMesh < CType0, CType1, CType2, CType3> & /*m*/) {return TriMesh < CType0 , CType1, CType2, CType3>::FaceContainer::value_type::HasPolyInfo();}
533 
534 template < class FaceType>    bool FaceVectorHasPerFaceFlags  (const std::vector<FaceType> &) {  return FaceType::HasFlags  (); }
535 template < class FaceType>    bool FaceVectorHasPerFaceNormal (const std::vector<FaceType> &) {  return FaceType::HasNormal (); }
536 template < class FaceType>    bool FaceVectorHasPerFaceColor  (const std::vector<FaceType> &) {  return FaceType::HasColor  (); }
537 template < class FaceType>    bool FaceVectorHasPerFaceMark   (const std::vector<FaceType> &) {  return FaceType::HasMark   (); }
538 template < class FaceType>    bool FaceVectorHasPerFaceQuality(const std::vector<FaceType> &) {  return FaceType::HasQuality(); }
539 template < class FaceType>    bool FaceVectorHasFFAdjacency   (const std::vector<FaceType> &) {  return FaceType::HasFFAdjacency(); }
540 template < class FaceType>    bool FaceVectorHasFEAdjacency   (const std::vector<FaceType> &) {  return FaceType::HasFEAdjacency(); }
541 template < class FaceType>    bool FaceVectorHasFVAdjacency   (const std::vector<FaceType> &) {  return FaceType::HasFVAdjacency(); }
542 template < class FaceType>    bool FaceVectorHasPerFaceCurvatureDir   (const std::vector<FaceType> &) {  return FaceType::HasCurvatureDir(); }
543 
544 template < class TriMeshType> bool HasPerFaceFlags       (const TriMeshType &m) { return tri::FaceVectorHasPerFaceFlags       (m.face); }
545 template < class TriMeshType> bool HasPerFaceNormal      (const TriMeshType &m) { return tri::FaceVectorHasPerFaceNormal      (m.face); }
546 template < class TriMeshType> bool HasPerFaceColor       (const TriMeshType &m) { return tri::FaceVectorHasPerFaceColor       (m.face); }
547 template < class TriMeshType> bool HasPerFaceMark        (const TriMeshType &m) { return tri::FaceVectorHasPerFaceMark        (m.face); }
548 template < class TriMeshType> bool HasPerFaceQuality     (const TriMeshType &m) { return tri::FaceVectorHasPerFaceQuality     (m.face); }
549 template < class TriMeshType> bool HasPerFaceCurvatureDir(const TriMeshType &m) { return tri::FaceVectorHasPerFaceCurvatureDir(m.face); }
550 template < class TriMeshType> bool HasFFAdjacency   (const TriMeshType &m) { return tri::FaceVectorHasFFAdjacency   (m.face); }
551 template < class TriMeshType> bool HasEEAdjacency   (const TriMeshType &m) { return tri::EdgeVectorHasEEAdjacency   (m.edge); }
552 template < class TriMeshType> bool HasFEAdjacency   (const TriMeshType &m) { return tri::FaceVectorHasFEAdjacency   (m.face); }
553 template < class TriMeshType> bool HasFVAdjacency   (const TriMeshType &m) { return tri::FaceVectorHasFVAdjacency   (m.face); }
554 
555 template < class TriMeshType> bool HasVFAdjacency   (const TriMeshType &m) { return tri::FaceVectorHasVFAdjacency   (m.face) && tri::VertexVectorHasVFAdjacency(m.vert);  }
556 template < class TriMeshType> bool HasVEAdjacency   (const TriMeshType &m) { return tri::EdgeVectorHasVEAdjacency   (m.edge) && tri::VertexVectorHasVEAdjacency(m.vert);  }
557 
558 
559 
560 //template < class  CType0, class CType1, class CType2 , class CType3>
561 //bool HasVEAdjacency (const TriMesh < CType0, CType1, CType2, CType3> & /*m*/) {return TriMesh < CType0 , CType1, CType2, CType3>::VertContainer::value_type::HasVEAdjacency();}
562 
563 template < class  CType0, class CType1, class CType2 , class CType3>
564 bool HasVHAdjacency (const TriMesh < CType0, CType1, CType2, CType3> & /*m*/) {return TriMesh < CType0 , CType1, CType2, CType3>::VertContainer::value_type::HasVHAdjacency();}
565 
566 template < class  CType0, class CType1, class CType2 , class CType3>
567 bool HasEVAdjacency (const TriMesh < CType0, CType1, CType2, CType3> & /*m*/) {return TriMesh < CType0 , CType1, CType2, CType3>::EdgeType::HasEVAdjacency();}
568 
569 //template < class  CType0, class CType1, class CType2 , class CType3>
570 //bool HasEEAdjacency (const TriMesh < CType0, CType1, CType2, CType3> & /*m*/) {return TriMesh < CType0 , CType1, CType2, CType3>::EdgeType::HasEEAdjacency();}
571 
572 template < class  CType0, class CType1, class CType2 , class CType3>
573 bool HasEFAdjacency (const TriMesh < CType0, CType1, CType2, CType3> & /*m*/) {return TriMesh < CType0 , CType1, CType2, CType3>::EdgeType::HasEFAdjacency();}
574 
575 template < class  CType0, class CType1, class CType2 , class CType3>
576 bool HasEHAdjacency (const TriMesh < CType0, CType1, CType2, CType3> & /*m*/) {return TriMesh < CType0 , CType1, CType2, CType3>::EdgeType::HasEHAdjacency();}
577 
578 template < class  CType0, class CType1, class CType2 , class CType3>
579 bool HasFHAdjacency (const TriMesh < CType0, CType1, CType2, CType3> & /*m*/) {return TriMesh < CType0 , CType1, CType2, CType3>::FaceType::HasFHAdjacency();}
580 
581 template < class  CType0, class CType1, class CType2 , class CType3>
582 bool HasHVAdjacency (const TriMesh < CType0, CType1, CType2, CType3> & /*m*/) {return TriMesh < CType0 , CType1, CType2, CType3>::HEdgeType::HasHVAdjacency();}
583 
584 template < class  CType0, class CType1, class CType2 , class CType3>
585 bool HasHEAdjacency (const TriMesh < CType0, CType1, CType2, CType3> & /*m*/) {return TriMesh < CType0 , CType1, CType2, CType3>::HEdgeType::HasHEAdjacency();}
586 
587 template < class  CType0, class CType1, class CType2 , class CType3>
588 bool HasHFAdjacency (const TriMesh < CType0, CType1, CType2, CType3> & /*m*/) {return TriMesh < CType0 , CType1, CType2, CType3>::HEdgeType::HasHFAdjacency();}
589 
590 template < class  CType0, class CType1, class CType2 , class CType3>
591 bool HasHNextAdjacency (const TriMesh < CType0, CType1, CType2, CType3> & /*m*/) {return TriMesh< CType0,   CType1,   CType2 ,  CType3>::HEdgeType::HasHNextAdjacency();}
592 
593 template < class  CType0, class CType1, class CType2 , class CType3>
594 bool HasHPrevAdjacency (const TriMesh < CType0, CType1, CType2, CType3> & /*m*/) {return TriMesh< CType0,   CType1,   CType2 , CType3>::HEdgeType::HasHPrevAdjacency();}
595 
596 template < class  CType0, class CType1, class CType2 , class CType3>
597 bool HasHOppAdjacency (const TriMesh < CType0, CType1, CType2, CType3> & /*m*/)  {return TriMesh< CType0,   CType1,   CType2 ,  CType3>::HEdgeType::HasHOppAdjacency();}
598 
599 //template < class CType0, class CType1 , class CType2, class CType3>
600 //bool HasVFAdjacency (const TriMesh < CType0 , CType1,   CType2, CType3> &  m ) {
601 //		// gcc 4.4: if the expressions assigned to a1 and a2 are replaced in the assert we get a compilation error
602 //		// for the macro assert
603 //		bool a1 =  TriMesh < CType0 , CType1,   CType2, CType3>::FaceContainer::value_type::HasVFAdjacency();
604 //		bool a2 =  TriMesh < CType0 , CType1,   CType2, CType3>::VertContainer::value_type::HasVFAdjacency();
605 //		// a1 and a2 are still evaluated but not referenced, this causes a warning
606 //		(void)a1;
607 //		(void)a2;
608 //		assert(a1==a2);
609 //
610 //		return   vcg::tri::HasPerVertexVFAdjacency<   CType0,   CType1 ,   CType2,   CType3>(m) &&
611 //						 vcg::tri::HasPerFaceVFAdjacency<   CType0,   CType1 ,   CType2,   CType3>(m) ;
612 //}
613 
614 template <class MeshType>
615 bool HasPerVertexAttribute(const MeshType &m,   std::string   name){
616         typename std::set< typename MeshType::PointerToAttribute>::const_iterator ai;
617         typename MeshType::PointerToAttribute h;
618         h._name = name;
619         ai = m.vert_attr.find(h);
620         return (ai!= m.vert_attr.end() ) ;
621 }
622 template <class MeshType>
623 bool HasPerFaceAttribute(const MeshType &m,   std::string   name){
624         typename std::set< typename MeshType::PointerToAttribute>::const_iterator ai;
625         typename MeshType::PointerToAttribute h;
626         h._name = name;
627         ai = m.face_attr.find(h);
628         return (ai!= m.face_attr.end() ) ;
629 }
630 
631 template <class MeshType>
632 bool HasPerMeshAttribute(const MeshType &m,   std::string   name){
633         typename std::set< typename MeshType::PointerToAttribute>::const_iterator ai;
634         typename MeshType::PointerToAttribute h;
635         h._name = name;
636         ai = m.mesh_attr.find(h);
637         return (ai!= m.mesh_attr.end() ) ;
638 }
639 
640 template <class MeshType> void RequireCompactness    (MeshType &m) {
641   if(m.vert.size()!=size_t(m.vn)) throw vcg::MissingCompactnessException("Vertex Vector Contains deleted elements");
642   if(m.edge.size()!=size_t(m.en)) throw vcg::MissingCompactnessException("Edge Vector Contains deleted elements");
643   if(m.face.size()!=size_t(m.fn)) throw vcg::MissingCompactnessException("Face Vector Contains deleted elements");
644 }
645 
646 template <class MeshType> void RequireTriangularMesh (MeshType &m ) { if( tri::HasPolyInfo( m ) ) throw vcg::MissingTriangularRequirementException("");}
647 template <class MeshType> void RequirePolygonalMesh (MeshType &m )  { if(!tri::HasPolyInfo( m ) ) throw vcg::MissingPolygonalRequirementException("");}
648 
649 template <class MeshType> void RequireVFAdjacency    (MeshType &m) { if(!tri::HasVFAdjacency   (m)) throw vcg::MissingComponentException("VFAdjacency"); }
650 template <class MeshType> void RequireVEAdjacency    (MeshType &m) { if(!tri::HasVEAdjacency   (m)) throw vcg::MissingComponentException("VEAdjacency"); }
651 template <class MeshType> void RequireFFAdjacency    (MeshType &m) { if(!tri::HasFFAdjacency   (m)) throw vcg::MissingComponentException("FFAdjacency"); }
652 template <class MeshType> void RequireEEAdjacency    (MeshType &m) { if(!tri::HasEEAdjacency   (m)) throw vcg::MissingComponentException("EEAdjacency"); }
653 template <class MeshType> void RequireFEAdjacency    (MeshType &m) { if(!tri::HasFEAdjacency   (m)) throw vcg::MissingComponentException("FEAdjacency"); }
654 template <class MeshType> void RequireFHAdjacency    (MeshType &m) { if(!tri::HasFHAdjacency   (m)) throw vcg::MissingComponentException("FHAdjacency"); }
655 
656 template <class MeshType> void RequirePerVertexQuality     (MeshType &m) { if(!tri::HasPerVertexQuality     (m)) throw vcg::MissingComponentException("PerVertexQuality     "); }
657 template <class MeshType> void RequirePerVertexNormal      (MeshType &m) { if(!tri::HasPerVertexNormal      (m)) throw vcg::MissingComponentException("PerVertexNormal      "); }
658 template <class MeshType> void RequirePerVertexColor       (MeshType &m) { if(!tri::HasPerVertexColor       (m)) throw vcg::MissingComponentException("PerVertexColor       "); }
659 template <class MeshType> void RequirePerVertexMark        (MeshType &m) { if(!tri::HasPerVertexMark        (m)) throw vcg::MissingComponentException("PerVertexMark        "); }
660 template <class MeshType> void RequirePerVertexFlags       (MeshType &m) { if(!tri::HasPerVertexFlags       (m)) throw vcg::MissingComponentException("PerVertexFlags       "); }
661 template <class MeshType> void RequirePerVertexRadius      (MeshType &m) { if(!tri::HasPerVertexRadius      (m)) throw vcg::MissingComponentException("PerVertexRadius      "); }
662 template <class MeshType> void RequirePerVertexCurvature   (MeshType &m) { if(!tri::HasPerVertexCurvature   (m)) throw vcg::MissingComponentException("PerVertexCurvature   "); }
663 template <class MeshType> void RequirePerVertexCurvatureDir(MeshType &m) { if(!tri::HasPerVertexCurvatureDir(m)) throw vcg::MissingComponentException("PerVertexCurvatureDir"); }
664 template <class MeshType> void RequirePerVertexTexCoord    (MeshType &m) { if(!tri::HasPerVertexTexCoord    (m)) throw vcg::MissingComponentException("PerVertexTexCoord    "); }
665 
666 template <class MeshType> void RequirePerEdgeQuality (MeshType &m) { if(!tri::HasPerEdgeQuality (m)) throw vcg::MissingComponentException("PerEdgeQuality "); }
667 template <class MeshType> void RequirePerEdgeNormal  (MeshType &m) { if(!tri::HasPerEdgeNormal  (m)) throw vcg::MissingComponentException("PerEdgeNormal  "); }
668 template <class MeshType> void RequirePerEdgeColor   (MeshType &m) { if(!tri::HasPerEdgeColor   (m)) throw vcg::MissingComponentException("PerEdgeColor   "); }
669 template <class MeshType> void RequirePerEdgeMark    (MeshType &m) { if(!tri::HasPerEdgeMark    (m)) throw vcg::MissingComponentException("PerEdgeMark    "); }
670 template <class MeshType> void RequirePerEdgeFlags   (MeshType &m) { if(!tri::HasPerEdgeFlags   (m)) throw vcg::MissingComponentException("PerEdgeFlags   "); }
671 
672 template <class MeshType> void RequirePerFaceFlags       (MeshType &m) { if(!tri::HasPerFaceFlags       (m)) throw vcg::MissingComponentException("PerFaceFlags       "); }
673 template <class MeshType> void RequirePerFaceNormal      (MeshType &m) { if(!tri::HasPerFaceNormal      (m)) throw vcg::MissingComponentException("PerFaceNormal      "); }
674 template <class MeshType> void RequirePerFaceColor       (MeshType &m) { if(!tri::HasPerFaceColor       (m)) throw vcg::MissingComponentException("PerFaceColor       "); }
675 template <class MeshType> void RequirePerFaceMark        (MeshType &m) { if(!tri::HasPerFaceMark        (m)) throw vcg::MissingComponentException("PerFaceMark        "); }
676 template <class MeshType> void RequirePerFaceQuality     (MeshType &m) { if(!tri::HasPerFaceQuality     (m)) throw vcg::MissingComponentException("PerFaceQuality     "); }
677 template <class MeshType> void RequirePerFaceCurvatureDir(MeshType &m) { if(!tri::HasPerFaceCurvatureDir(m)) throw vcg::MissingComponentException("PerFaceCurvatureDir"); }
678 
679 template <class MeshType> void RequirePerFaceWedgeColor   (MeshType &m) { if(!tri::HasPerWedgeColor   (m)) throw vcg::MissingComponentException("PerFaceWedgeColor   "); }
680 template <class MeshType> void RequirePerFaceWedgeNormal  (MeshType &m) { if(!tri::HasPerWedgeNormal  (m)) throw vcg::MissingComponentException("PerFaceWedgeNormal  "); }
681 template <class MeshType> void RequirePerFaceWedgeTexCoord(MeshType &m) { if(!tri::HasPerWedgeTexCoord(m)) throw vcg::MissingComponentException("PerFaceWedgeTexCoord"); }
682 
683 template <class MeshType> void RequirePerVertexAttribute(MeshType &m, const char *name) { if(!HasPerVertexAttribute(m,name)) throw vcg::MissingComponentException("PerVertex attribute"); }
684 template <class MeshType> void RequirePerEdgeAttribute(MeshType &m, const char *name)   { if(!HasPerEdgeAttribute(m,name))   throw vcg::MissingComponentException("PerEdge attribute"); }
685 template <class MeshType> void RequirePerFaceAttribute(MeshType &m, const char *name)   { if(!HasPerFaceAttribute(m,name))   throw vcg::MissingComponentException("PerFace attribute"); }
686 template <class MeshType> void RequirePerMeshAttribute(MeshType &m, const char *name)   { if(!HasPerMeshAttribute(m,name))   throw vcg::MissingComponentException("PerMesh attribute"); }
687 
688 /*@}*/
689 /*@}*/
690 }	 // end namespace
691 }	 // end namespace
692 
693 
694 
695 
696 #endif // BASE_H
697