2008-10-28 10:18:52 +01:00
|
|
|
|
2008-12-19 11:43:36 +01:00
|
|
|
#include<vcg/simplex/vertex/base.h>
|
|
|
|
#include<vcg/simplex/vertex/component.h>
|
|
|
|
#include<vcg/simplex/face/base.h>
|
|
|
|
#include<vcg/simplex/face/component.h>
|
2008-10-28 10:18:52 +01:00
|
|
|
#include<vcg/complex/trimesh/base.h>
|
|
|
|
#include<vcg/complex/trimesh/allocate.h>
|
|
|
|
|
[ 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.
2010-03-15 11:44:40 +01:00
|
|
|
|
|
|
|
class MyEdge;
|
2008-10-28 10:18:52 +01:00
|
|
|
class MyFace;
|
|
|
|
class MyVertex;
|
[ 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.
2010-03-15 11:44:40 +01:00
|
|
|
struct MyUsedTypes : public vcg::UsedTypes< vcg::Use<MyVertex> ::AsVertexType,
|
|
|
|
vcg::Use<MyFace> ::AsFaceType>{};
|
|
|
|
|
|
|
|
class MyVertex : public vcg::Vertex< MyUsedTypes, vcg::vertex::Coord3f,vcg::vertex::Normal3f>{};
|
|
|
|
class MyFace : public vcg::Face< MyUsedTypes, vcg::face::VertexRef, vcg::face::Normal3f> {};
|
2008-10-28 10:18:52 +01:00
|
|
|
|
|
|
|
class MyMesh : public vcg::tri::TriMesh< std::vector<MyVertex>, std::vector<MyFace> > {};
|
2009-03-20 11:24:13 +01:00
|
|
|
|
|
|
|
|
|
|
|
float Irradiance(MyMesh::VertexType v){
|
|
|
|
// .....
|
|
|
|
return 1.0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int main()
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
MyMesh m;
|
|
|
|
//...here m is filled
|
|
|
|
|
|
|
|
// add a per-vertex attribute with type float named "Irradiance"
|
|
|
|
MyMesh::PerVertexAttributeHandle<float> ih = vcg::tri::Allocator<MyMesh>::AddPerVertexAttribute<float> (m,std::string("Irradiance"));
|
|
|
|
|
|
|
|
// add a per-vertex attribute with type float named "Radiosity"
|
|
|
|
vcg::tri::Allocator<MyMesh>::AddPerVertexAttribute<float> (m,std::string("Radiosity"));
|
|
|
|
|
|
|
|
// add a per-vertex attribute with type bool and no name specified
|
|
|
|
MyMesh::PerVertexAttributeHandle<bool> blocked_h = vcg::tri::Allocator<MyMesh>::AddPerVertexAttribute<bool> (m);
|
|
|
|
|
|
|
|
// add a per-vertex attribute with type bool and no name specified
|
|
|
|
MyMesh::PerFaceAttributeHandle<bool> blocked_hf = vcg::tri::Allocator<MyMesh>::AddPerFaceAttribute<bool> (m);
|
|
|
|
|
|
|
|
MyMesh::VertexIterator vi; int i = 0;
|
|
|
|
for(vi = m.vert.begin(); vi != m.vert.end(); ++vi,++i){
|
|
|
|
ih[vi] = Irradiance(*vi); // [] operator takes a iterator
|
|
|
|
ih[*vi] = Irradiance(*vi); // or a MyMesh::VertexType object
|
|
|
|
ih[&*vi]= Irradiance(*vi); // or a pointer to it
|
|
|
|
ih[i] = Irradiance(*vi); // or an integer index
|
|
|
|
}
|
|
|
|
|
|
|
|
// Once created with AddPerVertexAttribute, an handle to the attribute can be obtained as follows
|
|
|
|
MyMesh::PerVertexAttributeHandle<float> rh = vcg::tri::Allocator<MyMesh>::GetPerVertexAttribute<float>(m,"Radiosity");
|
|
|
|
|
|
|
|
// you can query if an attribute is present or not
|
|
|
|
bool hasRadiosity = vcg::tri::HasPerVertexAttribute(m,"Radiosity");
|
|
|
|
|
|
|
|
// you can delete an attibute by name
|
|
|
|
vcg::tri::Allocator<MyMesh>::DeletePerVertexAttribute(m,"Radiosity");
|
|
|
|
|
|
|
|
// you can delete an attibute by handle
|
|
|
|
vcg::tri::Allocator<MyMesh>::DeletePerVertexAttribute(m,blocked_h);
|
|
|
|
|
|
|
|
bool res ;
|
|
|
|
|
|
|
|
res = vcg::tri::Allocator<MyMesh>::IsValidHandle(m,ih);printf("%d\n",res);
|
|
|
|
res = vcg::tri::Allocator<MyMesh>::IsValidHandle(m,blocked_hf);printf("%d\n",res);
|
|
|
|
vcg::tri::Allocator<MyMesh>::DeletePerVertexAttribute(m,ih);
|
|
|
|
vcg::tri::Allocator<MyMesh>::DeletePerFaceAttribute(m,blocked_hf);
|
|
|
|
res = vcg::tri::Allocator<MyMesh>::IsValidHandle(m,ih);printf("%d\n",res);
|
|
|
|
res = vcg::tri::Allocator<MyMesh>::IsValidHandle(m,blocked_hf);printf("%d\n",res);
|
|
|
|
|
|
|
|
|
|
|
|
}
|