trimesh_isosurface.cpp
Go to the documentation of this file.
00001 /****************************************************************************
00002 * VCGLib                                                            o o     *
00003 * Visual and Computer Graphics Library                            o     o   *
00004 *                                                                _   O  _   *
00005 * Copyright(C) 2004-2012                                           \/)\/    *
00006 * Visual Computing Lab                                            /\/|      *
00007 * ISTI - Italian National Research Council                           |      *
00008 *                                                                    \      *
00009 * All rights reserved.                                                      *
00010 *                                                                           *
00011 * This program is free software; you can redistribute it and/or modify      *
00012 * it under the terms of the GNU General Public License as published by      *
00013 * the Free Software Foundation; either version 2 of the License, or         *
00014 * (at your option) any later version.                                       *
00015 *                                                                           *
00016 * This program is distributed in the hope that it will be useful,           *
00017 * but WITHOUT ANY WARRANTY; without even the implied warranty of            *
00018 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the             *
00019 * GNU General Public License (http://www.gnu.org/licenses/gpl.txt)          *
00020 * for more details.                                                         *
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 /*argc*/ , char **/*argv*/)
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   // Simple initialization of the volume with some cool perlin noise
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         // MARCHING CUBES
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 };


shape_reconstruction
Author(s): Roberto Martín-Martín
autogenerated on Sat Jun 8 2019 18:38:20