Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include <vcg/complex/complex.h>
00024 #include <vcg/math/perlin_noise.h>
00025 #include <vcg/complex/algorithms/create/marching_cubes.h>
00026 #include <vcg/complex/algorithms/create/extended_marching_cubes.h>
00027 #include <vcg/complex/algorithms/create/mc_trivial_walker.h>
00028 #include <wrap/io_trimesh/export_ply.h>
00029
00030 using namespace std;
00031 using namespace vcg;
00032
00033 typedef float ScalarType;
00034
00035 class MyFace;
00036 class MyVertex;
00037
00038 struct MyUsedTypes : public UsedTypes< Use<MyVertex> ::AsVertexType,
00039 Use<MyFace> ::AsFaceType>{};
00040
00041 class MyVertex : public Vertex< MyUsedTypes, vertex::Coord3f, vertex::Normal3f, vertex::BitFlags>{};
00042 class MyFace : public Face< MyUsedTypes, face::VertexRef, face::BitFlags> {};
00043
00044 class MyMesh : public vcg::tri::TriMesh< std::vector< MyVertex>, std::vector< MyFace > > {};
00045
00046
00047
00048 typedef SimpleVolume<SimpleVoxel<float> > MyVolume;
00049
00050 int main(int , char **)
00051 {
00052 MyVolume volume;
00053
00054 typedef vcg::tri::TrivialWalker<MyMesh,MyVolume> MyWalker;
00055 typedef vcg::tri::MarchingCubes<MyMesh, MyWalker> MyMarchingCubes;
00056 MyWalker walker;
00057
00058
00059
00060 vcg::Box3f bb(vcg::Point3f(-1,-1,-1),vcg::Point3f(1,1,1));
00061 volume.Init(Point3i(64,64,64),bb);
00062 for(int i=0;i<64;i++)
00063 for(int j=0;j<64;j++)
00064 for(int k=0;k<64;k++)
00065 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);
00066
00067
00068
00069 MyMesh mc_mesh;
00070 printf("[MARCHING CUBES] Building mesh...");
00071 MyMarchingCubes mc(mc_mesh, walker);
00072 walker.BuildMesh<MyMarchingCubes>(mc_mesh, volume, mc, 20*20);
00073 vcg::tri::io::ExporterPLY<MyMesh>::Save( mc_mesh, "marching_cubes.ply");
00074
00075 printf("OK!\n");
00076 };