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