2005-09-21 12:29:33 +02:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <vcg/space/point3.h>
|
|
|
|
#include <vcg/space/box3.h>
|
|
|
|
#include <vcg/math/perlin_noise.h>
|
2008-12-19 11:43:36 +01:00
|
|
|
#include <vcg/simplex/vertex/base.h>
|
|
|
|
#include <vcg/simplex/face/base.h>
|
2007-01-18 02:35:31 +01:00
|
|
|
#include <vcg/complex/trimesh/base.h>
|
|
|
|
#include <vcg/complex/trimesh/allocate.h>
|
2005-09-21 12:29:33 +02:00
|
|
|
#include <vcg/complex/trimesh/create/marching_cubes.h>
|
|
|
|
#include <vcg/complex/trimesh/create/extended_marching_cubes.h>
|
2009-05-18 16:19:12 +02:00
|
|
|
#include <vcg/complex/trimesh/create/mc_trivial_walker.h>
|
2009-03-30 22:58:18 +02:00
|
|
|
#include <wrap/io_trimesh/export_ply.h>
|
2005-09-21 12:29:33 +02:00
|
|
|
|
2007-12-13 01:21:55 +01:00
|
|
|
|
|
|
|
|
2005-09-21 12:29:33 +02:00
|
|
|
using namespace std;
|
|
|
|
using namespace vcg;
|
|
|
|
|
|
|
|
|
|
|
|
typedef float ScalarType;
|
|
|
|
|
|
|
|
class MyFace;
|
[ 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 MyVertex;
|
2006-10-13 15:17:23 +02:00
|
|
|
|
[ 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 UsedTypes< Use<MyVertex> ::AsVertexType,
|
|
|
|
Use<MyFace> ::AsFaceType>{};
|
|
|
|
|
|
|
|
class MyVertex : public Vertex< MyUsedTypes, vertex::Coord3f>{};
|
|
|
|
class MyFace : public Face< MyUsedTypes, face::VertexRef, face::BitFlags> {};
|
2006-10-13 15:17:23 +02:00
|
|
|
|
|
|
|
//class MyVertex : public vcg::Vertex< ScalarType, MyEdge, MyFace > {};
|
|
|
|
//class MyFace : public vcg::Face< MyVertex, MyEdge, MyFace> {};
|
|
|
|
|
2005-09-21 12:29:33 +02:00
|
|
|
class MyMesh : public vcg::tri::TriMesh< std::vector< MyVertex>, std::vector< MyFace > > {};
|
|
|
|
|
|
|
|
|
|
|
|
|
2007-12-13 01:21:55 +01:00
|
|
|
typedef SimpleVolume<SimpleVoxel> MyVolume;
|
2005-09-21 12:29:33 +02:00
|
|
|
|
2006-10-13 15:17:23 +02:00
|
|
|
int main(int /*argc*/ , char /**argv[]*/)
|
2005-09-21 12:29:33 +02:00
|
|
|
{
|
|
|
|
MyVolume volume;
|
|
|
|
|
|
|
|
typedef vcg::tri::TrivialWalker<MyMesh,MyVolume> MyWalker;
|
|
|
|
typedef vcg::tri::MarchingCubes<MyMesh, MyWalker> MyMarchingCubes;
|
|
|
|
MyWalker walker;
|
|
|
|
|
|
|
|
|
|
|
|
// Simple initialization of the volume with some cool perlin noise
|
|
|
|
volume.Init(Point3i(64,64,64));
|
|
|
|
for(int i=0;i<64;i++)
|
|
|
|
for(int j=0;j<64;j++)
|
|
|
|
for(int k=0;k<64;k++)
|
2006-10-13 15:17:23 +02:00
|
|
|
volume.Val(i,j,k)=(j-32)*(j-32)+(k-32)*(k-32) + i*10*(float)math::Perlin::Noise(i*.2,j*.2,k*.2);
|
2005-09-21 12:29:33 +02:00
|
|
|
|
|
|
|
|
|
|
|
// MARCHING CUBES
|
|
|
|
MyMesh mc_mesh;
|
|
|
|
printf("[MARCHING CUBES] Building mesh...");
|
|
|
|
MyMarchingCubes mc(mc_mesh, walker);
|
|
|
|
walker.BuildMesh<MyMarchingCubes>(mc_mesh, volume, mc, 20*20);
|
|
|
|
vcg::tri::io::ExporterPLY<MyMesh>::Save( mc_mesh, "marching_cubes.ply");
|
|
|
|
|
|
|
|
printf("OK!\n");
|
2009-03-30 22:58:18 +02:00
|
|
|
};
|