[ 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<MyVertex>,vector<MyFace> >{};


==== 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<MyVertex>::AsVertexType,
                                          vcg::Use<MyFace>::AsFaceType>{};

class MyVertex: public Vertex < MyUsedTypes, vertex::Coord3f,...other components>{};
class MyFace: public Face < MyUsedTypes, face::VertexRef,...other components>{};
class MyMesh: public TriMesh<vector<MyVertex>,vector<MyFace> >{};

                                 
===== 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 

<MyVertex, MyEdge, MyFace  becomes <MyUsedTypes<

and 

VertexSimp2 becomes Vertex

[vcg::Use] : an auxiliary class to give a simple way to specify the role of a type

Note 2: the order of templates parameters to vcg::UsedTypes is unimportant, e.g:

class MyUsedTypes: public vcg::UsedType <vcg::Use<MyVertex>::AsVertexType,
                                         vcg::Use<MyEdge>::AsEdgeType,
                                         vcg::Use<MyFace>::AsFaceType>{};

is the same as:
class MyUsedTypes: public vcg::UsedType <vcg::Use<MyFace>::AsFaceType,
                                         vcg::Use<MyEdge>::AsEdgeType,
                                         vcg::Use<MyVertex>::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<MyEdge>::AsEdgeType in the template list of UsedTypes.
==== the Part II will be a tiny change to the class TriMesh it self.
This commit is contained in:
ganovelli 2010-03-15 10:42:03 +00:00
parent 54ca153009
commit cdfed059d3
1 changed files with 9 additions and 2 deletions

View File

@ -9,14 +9,21 @@
#include <vcg/complex/edgemesh/allocate.h>
#include <vcg/complex/edgemesh/update/bounding.h>
#include <vcg/complex/edgemesh/closest.h>
#include <vcg/complex/trimesh/closest.h>
#include <vcg/complex/used_types.h>
//
//using namespace std;
//
class MyFace;
class MyEdge;
class MyVertex : public vcg::VertexSimp2<MyVertex,MyEdge, MyFace,vcg::vertex::BitFlags,vcg::vertex::Coord3f> {};
class MyEdge : public vcg::EdgeSimp2<MyVertex,MyEdge, MyVertex,vcg::edge::Mark,vcg::edge::VertexRef,vcg::edge::BitFlags> {};
class MyVertex;
struct MyUsedTypes : public vcg::UsedTypes< vcg::Use<MyVertex> ::AsVertexType,
vcg::Use<MyEdge> ::AsEdgeType,
vcg::Use<MyFace> ::AsFaceType>{};
class MyVertex : public vcg::Vertex<MyUsedTypes,vcg::vertex::BitFlags,vcg::vertex::Coord3f> {};
class MyEdge : public vcg::Edge<MyUsedTypes,vcg::edge::Mark,vcg::edge::VertexRef,vcg::edge::BitFlags> {};
class MyEdgeMesh: public vcg::edg::EdgeMesh< std::vector<MyVertex>, std::vector<MyEdge> > {};
typedef vcg::GridStaticPtr<MyEdge, MyEdge::ScalarType> EdgeMeshGrid;