From c40a6c3d97029be366e8f1788ed68a08359a48e6 Mon Sep 17 00:00:00 2001 From: ganovelli Date: Mon, 15 Mar 2010 10:42:52 +0000 Subject: [PATCH] [ Changes in definition of TriMesh: PART I ] Note for the developers: the change to make to existing projects is very little but strictly necessary to compile. This change IS NOT backward compliant. ==== OLD ==== way to define a TriMesh: // forward declarations class MyVertex; class MyEdge; class MyFace; class MyVertex: public VertexSimp2 < MyVertex, MyEdge, MyFace, vertex::Coord3f,...other components>{}; class MyFace: public FaceSimp2 < MyVertex, MyEdge, MyFace, face::VertexRef,...other components>{}; class MyMesh: public TriMesh,vector >{}; ==== NEW ==== way to define a TriMesh: // forward declarations class MyVertex; class MyEdge; class MyFace; // declaration of which types is used as VertexType, which type is used as FaceType and so on... class MyUsedTypes: public vcg::UsedType < vcg::Use::AsVertexType, vcg::Use::AsFaceType>{}; class MyVertex: public Vertex < MyUsedTypes, vertex::Coord3f,...other components>{}; class MyFace: public Face < MyUsedTypes, face::VertexRef,...other components>{}; class MyMesh: public TriMesh,vector >{}; ===== classes introduced [vcg::UsedType] : it is a class containing all the types that must be passed to the definition of Vertex, Face, Edge... This class replaces the list of typenames to pass as first templates and the need to specify the maximal simplicial. So ::AsVertexType, vcg::Use::AsEdgeType, vcg::Use::AsFaceType>{}; is the same as: class MyUsedTypes: public vcg::UsedType ::AsFaceType, vcg::Use::AsEdgeType, vcg::Use::AsVertexType>{}; Note 3: you only need to specify the type you use. If you do not have edges you do not need to include vcg::Use::AsEdgeType in the template list of UsedTypes. ==== the Part II will be a tiny change to the class TriMesh it self. --- vcg/complex/trimesh/base.h | 26 +++++--- vcg/simplex/edge/base.h | 45 +++----------- vcg/simplex/edge/component.h | 2 +- vcg/simplex/face/base.h | 35 +++-------- vcg/simplex/face/component_ocf.h | 2 +- vcg/simplex/face/component_polygon.h | 2 +- vcg/simplex/vertex/base.h | 66 ++++++++------------ vcg/simplex/vertex/component.h | 92 +++++++++++++++------------- vcg/simplex/vertex/component_ocf.h | 10 +-- 9 files changed, 115 insertions(+), 165 deletions(-) diff --git a/vcg/complex/trimesh/base.h b/vcg/complex/trimesh/base.h index df0422d6..d022fb89 100644 --- a/vcg/complex/trimesh/base.h +++ b/vcg/complex/trimesh/base.h @@ -142,6 +142,8 @@ Initial commit #include #include +#include + /* People should subclass his vertex class from these one... */ @@ -175,18 +177,24 @@ class TriMeshEdgeHolder{ }; // a dummy class is used to provide the interface of a stl container - class DummyClass:public std::vector{}; + class DummyClass:public std::vector{ + }; // If the DummyClass is passed it provides the interfaces to compile -template < class VertContainerType, class FaceContainerType > -class TriMeshEdgeHolder{ - public: - class EdgeType: public EdgeSimp2< typename VertContainerType::value_type,EdgeType,typename FaceContainerType::value_type >{}; - typedef typename FaceContainerType::value_type::EdgeType EdgeTypeExternal; - struct EdgePointer {}; - struct ConstEdgePointer {}; + template < class VertContainerType, class FaceContainerType > + class TriMeshEdgeHolder{ + public: + + struct OthersTypes : public UsedTypes< Use::template AsVertexType, + Use::template AsFaceType + >{}; + + class EdgeType: public Edge< OthersTypes >{}; + + struct EdgePointer {}; + struct ConstEdgePointer {}; typedef std::vector< EdgeType > EdgeContainerType; typedef typename std::vector< EdgeType > EdgeContainer; -}; + }; diff --git a/vcg/simplex/edge/base.h b/vcg/simplex/edge/base.h index 233b86d2..e706e014 100644 --- a/vcg/simplex/edge/base.h +++ b/vcg/simplex/edge/base.h @@ -38,19 +38,10 @@ The base class of all the recusive definition chain. It is just a container of t These typenames must be known form all the derived classes. */ -template -class EdgeTypeHolder{ +template + class EdgeTypeHolder: public UserTypes{ public: - typedef BVT VertexType; - typedef typename VertexType::CoordType CoordType; - typedef typename VertexType::ScalarType ScalarType; - typedef BET EdgeType; - typedef BFT FaceType; - typedef BTT TetraType; - typedef BVT *VertexPointer; - typedef BET *EdgePointer; - typedef BFT *FacePointer; - typedef BTT *TetraPointer; + template < class LeftV> void ImportLocal(const LeftV & /* left */ ) { } static void Name(std::vector & name){} @@ -69,12 +60,12 @@ we have to build the type a step a time (deriving from a single ancestor at a ti */ -template +template class EdgeBase: public edge::EmptyEVAdj< edge::EmptyEEAdj< edge::EmptyHEdgeData< edge::EmptyBitFlags< - EdgeTypeHolder > > > > { + EdgeTypeHolder < UserTypes> > > > > { }; @@ -90,14 +81,14 @@ I.e. IsD() that uses the overridden Flags() member must be defined here. */ -template class A, template class B, template class C, template class D, template class E, template class F, template class G, template class H, template class I, template class J, template class K> -class EdgeArityMax: public K > { +class EdgeArityMax: public K, A, B, C, D, E, F, G, H, I, J> > { // ----- Flags stuff ----- public: @@ -218,32 +209,14 @@ Qualitys, Qualityf, Qualityd VFAdj //topology (vertex->face adjacency) */ -template class A = DefaultDeriver, template class B = DefaultDeriver, template class C = DefaultDeriver, template class D = DefaultDeriver, template class E = DefaultDeriver, template class F = DefaultDeriver, template class G = DefaultDeriver, template class H = DefaultDeriver, template class I = DefaultDeriver, template class J = DefaultDeriver, template class K = DefaultDeriver> - class EdgeSimp3: public EdgeArityMax {}; - -template class A = DefaultDeriver, template class B = DefaultDeriver, - template class C = DefaultDeriver, template class D = DefaultDeriver, - template class E = DefaultDeriver, template class F = DefaultDeriver, - template class G = DefaultDeriver, template class H = DefaultDeriver, - template class I = DefaultDeriver, template class J = DefaultDeriver, - template class K = DefaultDeriver> - class EdgeSimp2: public EdgeArityMax {}; - -template class A = DefaultDeriver, template class B = DefaultDeriver, - template class C = DefaultDeriver, template class D = DefaultDeriver, - template class E = DefaultDeriver, template class F = DefaultDeriver, - template class G = DefaultDeriver, template class H = DefaultDeriver, - template class I = DefaultDeriver, template class J = DefaultDeriver, - template class K = DefaultDeriver> - class EdgeSimp1: public EdgeArityMax {}; + class Edge: public EdgeArityMax {}; }// end namespace #endif diff --git a/vcg/simplex/edge/component.h b/vcg/simplex/edge/component.h index 6ddfdcaf..008c72c2 100644 --- a/vcg/simplex/edge/component.h +++ b/vcg/simplex/edge/component.h @@ -24,7 +24,7 @@ #ifndef __VCG_EDGE_PLUS_COMPONENT #define __VCG_EDGE_PLUS_COMPONENT //#include -//#include +#include //#include //#include #include diff --git a/vcg/simplex/face/base.h b/vcg/simplex/face/base.h index 3fd48cb2..4579a5f6 100644 --- a/vcg/simplex/face/base.h +++ b/vcg/simplex/face/base.h @@ -89,19 +89,10 @@ The base class of all the recusive definition chain. It is just a container of t These typenames must be known form all the derived classes. */ -template -class FaceTypeHolder{ +template + class FaceTypeHolder: public UserTypes { public: - typedef BVT VertexType; - typedef typename VertexType::CoordType CoordType; - typedef typename VertexType::ScalarType ScalarType; - typedef BET EdgeType; - typedef BFT FaceType; - typedef BTT TetraType; - typedef BVT *VertPointer; - typedef BET *EdgePointer; - typedef BFT *FacePointer; - typedef BTT *TetraPointer; + template void ImportLocal(const LeftF & ){} static void Name(std::vector & /* name */){} @@ -127,7 +118,7 @@ we have to build the type a step a time (deriving from a single ancestor at a ti */ -template +template class FaceBase: public face::EmptyPolyInfo< face::EmptyVertexRef< face::EmptyAdj< @@ -135,7 +126,7 @@ class FaceBase: public face::EmptyPolyInfo< face::EmptyNormal< face::EmptyBitFlags< face::EmptyWedgeTexCoord< - FaceTypeHolder > > > > > > > { + FaceTypeHolder > > > > > > > { }; @@ -152,13 +143,13 @@ I.e. IsD() that uses the overridden Flags() member must be defined here. */ -template class A, template class B, template class C, template class D, template class E, template class F, template class G, template class H, template class I, template class J > - class FaceArityMax: public I > { + class FaceArityMax: public J, A, B, C, D, E, F, G, H, I> > { // ----- Flags stuff ----- public: @@ -346,21 +337,13 @@ FFAdj //topology: face face adj */ -template class A = FaceDefaultDeriver, template class B = FaceDefaultDeriver, template class C = FaceDefaultDeriver, template class D = FaceDefaultDeriver, template class E = FaceDefaultDeriver, template class F = FaceDefaultDeriver, template class G = FaceDefaultDeriver, template class H = FaceDefaultDeriver, template class I = FaceDefaultDeriver, template class J = FaceDefaultDeriver > - class FaceSimp3: public FaceArityMax {}; -class DumTT; -template class A = FaceDefaultDeriver, template class B = FaceDefaultDeriver, - template class C = FaceDefaultDeriver, template class D = FaceDefaultDeriver, - template class E = FaceDefaultDeriver, template class F = FaceDefaultDeriver, - template class G = FaceDefaultDeriver, template class H = FaceDefaultDeriver, - template class I = FaceDefaultDeriver, template class J = FaceDefaultDeriver > - class FaceSimp2: public FaceArityMax {}; + class Face: public FaceArityMax {}; }// end namespace diff --git a/vcg/simplex/face/component_ocf.h b/vcg/simplex/face/component_ocf.h index b6037a71..0346c99f 100644 --- a/vcg/simplex/face/component_ocf.h +++ b/vcg/simplex/face/component_ocf.h @@ -519,7 +519,7 @@ public: assert((*this).Base().FFAdjacencyEnabled); return (*this).Base().AF[(*this).Index()]._zp[j]; } - const char cFFi(const int j) const { + char cFFi(const int j) const { assert((*this).Base().FFAdjacencyEnabled); return (*this).Base().AF[(*this).Index()]._zp[j]; } diff --git a/vcg/simplex/face/component_polygon.h b/vcg/simplex/face/component_polygon.h index b62b481c..c8b5765a 100644 --- a/vcg/simplex/face/component_polygon.h +++ b/vcg/simplex/face/component_polygon.h @@ -147,7 +147,7 @@ public: static void Name(std::vector & name){name.push_back(std::string("PFVAdj"));T::Name(name);} private: - typename T::VertPointer *_vpoly; + typename T::VertexPointer *_vpoly; }; /*----------------------------- PVFADJ ------------------------------*/ diff --git a/vcg/simplex/vertex/base.h b/vcg/simplex/vertex/base.h index 7bbf0f07..8e03c5eb 100644 --- a/vcg/simplex/vertex/base.h +++ b/vcg/simplex/vertex/base.h @@ -81,23 +81,23 @@ namespace vcg { The base class of all the recusive definition chain. It is just a container of the typenames of the various simplexes. These typenames must be known form all the derived classes. */ - -template -class VertexTypeHolder{ - public: - typedef BVT VertType; - typedef BET EdgeType; - typedef BFT FaceType; - typedef BTT TetraType; - typedef BVT *VertPointer; - typedef BET *EdgePointer; - typedef BFT *FacePointer; - typedef BTT *TetraPointer; - template < class LeftV> - void ImportLocal(const LeftV & /* left */ ) { } - static void Name(std::vector & /* name */){} - -}; +// +//template +//class VertexTypeHolder{ +// public: +// typedef BVT VertType; +// typedef BET EdgeType; +// typedef BFT FaceType; +// typedef BTT TetraType; +// typedef BVT *VertPointer; +// typedef BET *EdgePointer; +// typedef BFT *FacePointer; +// typedef BTT *TetraPointer; +// template < class LeftV> +// void ImportLocal(const LeftV & /* left */ ) { } +// static void Name(std::vector & /* name */){} +// +//}; /* The base class form which we start to add our components. it has the empty definition for all the standard members (coords, color flags) @@ -111,9 +111,9 @@ we have to build the type a step a time (deriving from a single ancestor at a ti */ -template -class VertexBase: public vertex::EmptyCore< VertexTypeHolder >{ -}; +//template +//class VertexBase: public vertex::EmptyCore< UserUsedTypes >{ +//}; /* The Real Big Vertex class; @@ -128,14 +128,14 @@ I.e. IsD() that uses the overridden Flags() member must be defined here. */ -template class A, template class B, template class C, template class D, template class E, template class F, template class G, template class H, template class I, template class J, template class K, template class L> -class VertexArityMax: public Arity12 { +class VertexArityMax: public Arity12, A, B, C, D, E, F, G, H, I, J, K, L> { // ----- Flags stuff ----- public: @@ -253,32 +253,14 @@ Qualitys, Qualityf, Qualityd VFAdj //topology (vertex->face adjacency) */ -template class A = DefaultDeriver, template class B = DefaultDeriver, template class C = DefaultDeriver, template class D = DefaultDeriver, template class E = DefaultDeriver, template class F = DefaultDeriver, template class G = DefaultDeriver, template class H = DefaultDeriver, template class I = DefaultDeriver, template class J = DefaultDeriver, template class K = DefaultDeriver, template class L = DefaultDeriver> - class VertexSimp3: public VertexArityMax {}; - -template class A = DefaultDeriver, template class B = DefaultDeriver, - template class C = DefaultDeriver, template class D = DefaultDeriver, - template class E = DefaultDeriver, template class F = DefaultDeriver, - template class G = DefaultDeriver, template class H = DefaultDeriver, - template class I = DefaultDeriver, template class J = DefaultDeriver, - template class K = DefaultDeriver, template class L = DefaultDeriver> - class VertexSimp2: public VertexArityMax {}; - -template class A = DefaultDeriver, template class B = DefaultDeriver, - template class C = DefaultDeriver, template class D = DefaultDeriver, - template class E = DefaultDeriver, template class F = DefaultDeriver, - template class G = DefaultDeriver, template class H = DefaultDeriver, - template class I = DefaultDeriver, template class J = DefaultDeriver, - template class K = DefaultDeriver, template class L = DefaultDeriver> - class VertexSimp1: public VertexArityMax {}; + class Vertex: public VertexArityMax {}; }// end namespace #endif diff --git a/vcg/simplex/vertex/component.h b/vcg/simplex/vertex/component.h index f26ea169..b83f7295 100644 --- a/vcg/simplex/vertex/component.h +++ b/vcg/simplex/vertex/component.h @@ -36,6 +36,42 @@ All the Components that can be added to a vertex should be defined in the namesp */ + /*-------------------------- Curvature ----------------------------------*/ + + template + struct CurvatureDirBaseType{ + typedef Point3 VecType; + typedef S ScalarType; + CurvatureDirBaseType () {} + Point3max_dir,min_dir; // max and min curvature direction + S k1,k2;// max and min curvature values + }; + + template class Curvature: public TT { + public: + typedef Point2 CurvatureType; + typedef typename CurvatureType::ScalarType ScalarType; + ScalarType &Kh(){ return _hk[0];} + ScalarType &Kg(){ return _hk[1];} + const ScalarType &cKh() const { return _hk[0];} + const ScalarType &cKg() const { return _hk[1];} + + static bool HasCurvature() { return true; } + static bool IsCurvatureEnabled(typename TT::VertexType *) { return true; } + static void Name(std::vector & name){name.push_back(std::string("Curvature"));TT::Name(name);} + + private: + Point2 _hk; + }; + + + template class Curvaturef: public Curvature< float, T> { + public: static void Name(std::vector & name){name.push_back(std::string("Curvaturef"));T::Name(name);} + }; + template class Curvatured: public Curvature { + public: static void Name(std::vector & name){name.push_back(std::string("Curvatured"));T::Name(name);} + }; + /*------------------------- EMPTY CORE COMPONENTS -----------------------------------------*/ template class EmptyCore: public TT { @@ -63,14 +99,14 @@ public: const QualityType &cQ() const { static QualityType dummyQuality(0); assert(0); return dummyQuality; } static bool HasQuality() { return false; } static bool HasQualityOcf() { return false; } - static bool IsQualityEnabled(const typename TT::VertType *) { return false; } + static bool IsQualityEnabled(const typename TT::VertexType *) { return false; } typedef vcg::Color4b ColorType; ColorType &C() { static ColorType dumcolor(vcg::Color4b::White); assert(0); return dumcolor; } const ColorType &cC() const { static ColorType dumcolor(vcg::Color4b::White); assert(0); return dumcolor; } static bool HasColor() { return false; } static bool HasColorOcf() { return false; } - static bool IsColorEnabled(const typename TT::VertType *) { return false; } + static bool IsColorEnabled(const typename TT::VertexType *) { return false; } inline void InitIMark() { } inline const int & cIMark() const { assert(0); static int tmp=-1; return tmp;} @@ -78,20 +114,20 @@ public: inline int IMark() const {return 0;} static bool HasMark() { return false; } static bool HasMarkOcf() { return false; } - static bool IsMarkEnabled(const typename TT::VertType *) { return false; } + static bool IsMarkEnabled(const typename TT::VertexType *) { return false; } typedef ScalarType RadiusType; RadiusType &R(){ static ScalarType v = 0.0; assert(0 && "the radius component is not available"); return v; } const RadiusType &cR() const { static const ScalarType v = 0.0; assert(0 && "the radius component is not available"); return v; } static bool HasRadius() { return false; } static bool HasRadiusOcf() { return false; } - static bool IsRadiusEnabled(const typename TT::VertType *) { return false; } + static bool IsRadiusEnabled(const typename TT::VertexType *) { return false; } typedef vcg::TexCoord2 TexCoordType; TexCoordType &T() { static TexCoordType dummy_texcoord; assert(0); return dummy_texcoord; } const TexCoordType &cT() const { static TexCoordType dummy_texcoord; assert(0); return dummy_texcoord; } static bool HasTexCoord() { return false; } - static bool IsTexCoordEnabled(const typename TT::VertType *) { return false; } + static bool IsTexCoordEnabled(const typename TT::VertexType *) { return false; } typename TT::TetraPointer &VTp() { static typename TT::TetraPointer tp = 0; assert(0); return tp; } typename TT::TetraPointer cVTp() { static typename TT::TetraPointer tp = 0; assert(0); return tp; } @@ -109,12 +145,15 @@ public: int &VEi(){static int z=0; return z;}; static bool HasVEAdjacency() { return false; } + typedef Point3f VecType; - float &Kh() { static float dummy = 0.f; assert(0);return dummy;} + typedef Point2f CurvatureType; + float &Kh() { static float dummy = 0.f; assert(0);return dummy;} float &Kg() { static float dummy = 0.f; assert(0);return dummy;} const float &cKh() const { static float dummy = 0.f; assert(0); return dummy;} const float &cKg() const { static float dummy = 0.f; assert(0); return dummy;} + typedef CurvatureDirBaseType CurvatureDirType; VecType &PD1(){static VecType v(0,0,0); assert(0);return v;} VecType &PD2(){static VecType v(0,0,0); assert(0);return v;} const VecType &cPD1() const {static VecType v(0,0,0); assert(0);return v;} @@ -126,9 +165,9 @@ public: const ScalarType &cK2()const {static ScalarType v = 0.0;assert(0);return v;} static bool HasCurvature() { return false; } - static bool IsCurvatureEnabled(const typename TT::VertType *) { return false; } + static bool IsCurvatureEnabled(const typename TT::VertexType *) { return false; } static bool HasCurvatureDir() { return false; } - static bool IsCurvatureDirEnabled(const typename TT::VertType *) { return false; } + static bool IsCurvatureDirEnabled(const typename TT::VertexType *) { return false; } template < class LeftV> @@ -269,7 +308,7 @@ public: template < class LeftV> void ImportLocal(const LeftV & left ) { if(LeftV::HasColor()) C() = left.cC(); T::ImportLocal( left); } static bool HasColor() { return true; } - static bool IsColorEnabled(typename T::VertType *) { return true; } + static bool IsColorEnabled(typename T::VertexType *) { return true; } static void Name(std::vector & name){name.push_back(std::string("Color"));T::Name(name);} private: @@ -307,41 +346,6 @@ public: static void Name(std::vector & name){name.push_back(std::st }; - -template -struct CurvatureDirBaseType{ - typedef Point3 VecType; - typedef S ScalarType; - CurvatureDirBaseType () {} - Point3max_dir,min_dir; // max and min curvature direction - S k1,k2;// max and min curvature values -}; - -template class Curvature: public TT { -public: - typedef Point2 CurvatureType; - typedef typename CurvatureType::ScalarType ScalarType; - ScalarType &Kh(){ return _hk[0];} - ScalarType &Kg(){ return _hk[1];} - const ScalarType &cKh() const { return _hk[0];} - const ScalarType &cKg() const { return _hk[1];} - - static bool HasCurvature() { return true; } - static bool IsCurvatureEnabled(typename TT::VertType *) { return true; } - static void Name(std::vector & name){name.push_back(std::string("Curvature"));TT::Name(name);} - -private: - Point2 _hk; -}; - - -template class Curvaturef: public Curvature< float, T> { -public: static void Name(std::vector & name){name.push_back(std::string("Curvaturef"));T::Name(name);} -}; -template class Curvatured: public Curvature { -public: static void Name(std::vector & name){name.push_back(std::string("Curvatured"));T::Name(name);} -}; - /*-------------------------- Curvature Direction ----------------------------------*/ diff --git a/vcg/simplex/vertex/component_ocf.h b/vcg/simplex/vertex/component_ocf.h index 222ba2cc..09c8b455 100644 --- a/vcg/simplex/vertex/component_ocf.h +++ b/vcg/simplex/vertex/component_ocf.h @@ -404,7 +404,7 @@ public: static bool HasVFAdjacency() { return true; } static bool HasVFAdjacencyOcf() { return true; } - static bool IsVFAdjacencyEnabled(const typename T::VertType *vp) {return vp->Base().VFAdjacencyEnabled;} + static bool IsVFAdjacencyEnabled(const typename T::VertexType *vp) {return vp->Base().VFAdjacencyEnabled;} private: }; @@ -558,7 +558,7 @@ public: } static bool HasCurvature() { return true; } - static bool IsCurvatureEnabled(const typename TT::VertType *v) { return v->Base().CurvatureEnabled; } + static bool IsCurvatureEnabled(const typename TT::VertexType *v) { return v->Base().CurvatureEnabled; } static bool HasCurvatureOcf() { return true; } static void Name(std::vector & name){name.push_back(std::string("CurvatureOcf"));TT::Name(name);} @@ -666,15 +666,15 @@ public: assert(0); return *this; } - vector_ocf &Base() const { return *_ovp;} + vector_ocf &Base() const { return *_ovp;} inline int Index() const { - typename T::VertType const *tp=static_cast(this); + typename T::VertexType const *tp=static_cast(this); int tt2=tp- &*(_ovp->begin()); return tt2; } public: - vector_ocf *_ovp; + vector_ocf *_ovp; static bool HasQualityOcf() { return false; } static bool HasTexCoordOcf() { return false; }