trimesh_sampling.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 
00025 #include<wrap/io_trimesh/import_off.h>
00026 #include<wrap/io_trimesh/export_off.h>
00027 
00028 #include<vcg/complex/algorithms/point_sampling.h>
00029 #include<vcg/complex/algorithms/create/platonic.h>
00030 
00031 using namespace vcg;
00032 using namespace std;
00033 
00034 class MyEdge;
00035 class MyFace;
00036 class MyVertex;
00037 struct MyUsedTypes : public UsedTypes<  Use<MyVertex>   ::AsVertexType,
00038                                         Use<MyEdge>     ::AsEdgeType,
00039                                         Use<MyFace>     ::AsFaceType>{};
00040 
00041 class MyVertex  : public Vertex<MyUsedTypes, vertex::Coord3f, vertex::Normal3f, vertex::BitFlags  >{};
00042 class MyFace    : public Face< MyUsedTypes, face::FFAdj,  face::Normal3f, face::VertexRef, face::BitFlags > {};
00043 class MyEdge    : public Edge<MyUsedTypes>{};
00044 class MyMesh    : public tri::TriMesh< vector<MyVertex>, vector<MyFace> , vector<MyEdge>  > {};
00045 
00046 int main( int argc, char **argv )
00047 {
00048   if(argc<2)
00049   {
00050     printf("Usage trimesh_base <meshfilename.obj> radius\n");
00051     return -1;
00052   }
00053 
00054   MyMesh m;
00055 
00056   if(tri::io::ImporterOFF<MyMesh>::Open(m,argv[1])!=0)
00057   {
00058     printf("Error reading file  %s\n",argv[1]);
00059     exit(0);
00060   }
00061   tri::SurfaceSampling<MyMesh,tri::TrivialSampler<MyMesh> >::SamplingRandomGenerator().initialize(time(0));
00062 
00063   //----------------------------------------------------------------------
00064   // Basic Sample of a mesh surface
00065   // Build a point cloud with points with a plain poisson disk distribution
00066 
00067   int t0=clock();
00068   vector<Point3f> pointVec;
00069   float rad=0;
00070   if(argc>2) rad=atof(argv[2]);
00071   int sampleNum=rad?0:1000;
00072   tri::PoissonSampling<MyMesh>(m,pointVec,sampleNum,rad);
00073   int t1=clock();
00074   MyMesh BasicPoissonMesh;
00075   tri::BuildMeshFromCoordVector(BasicPoissonMesh,pointVec);
00076 
00077   tri::io::ExporterOFF<MyMesh>::Save(BasicPoissonMesh,"BasicPoissonMesh.off");
00078   printf("Computed a basic poisson disk distribution of %i vertices radius is %6.3f in %5.2f sec\n",BasicPoissonMesh.VN(),rad,float(t1-t0)/CLOCKS_PER_SEC);
00079 
00080   //----------------------------------------------------------------------
00081   // Advanced Sample
00082   // Make a feature dependent Poisson Disk sampling
00083   MyMesh MontecarloSurfaceMesh;
00084   MyMesh MontecarloEdgeMesh;
00085   MyMesh PoissonEdgeMesh;
00086   MyMesh PoissonMesh;
00087 
00088   std::vector<Point3f> sampleVec;
00089   tri::TrivialSampler<MyMesh> mps(sampleVec);
00090   tri::UpdateTopology<MyMesh>::FaceFace(m);
00091   tri::UpdateNormal<MyMesh>::PerFace(m);
00092   tri::UpdateFlags<MyMesh>::FaceFauxCrease(m,math::ToRad(40.0f));
00093   tri::SurfaceSampling<MyMesh,tri::TrivialSampler<MyMesh> >::EdgeMontecarlo(m,mps,10000,false);
00094   tri::BuildMeshFromCoordVector(MontecarloEdgeMesh,sampleVec);
00095   tri::io::ExporterOFF<MyMesh>::Save(MontecarloEdgeMesh,"MontecarloEdgeMesh.off");
00096 
00097   sampleVec.clear();
00098   tri::SurfaceSampling<MyMesh,tri::TrivialSampler<MyMesh> >::VertexCrease(m, mps);
00099   tri::BuildMeshFromCoordVector(PoissonEdgeMesh,sampleVec);
00100   tri::io::ExporterOFF<MyMesh>::Save(PoissonEdgeMesh,"VertexCreaseMesh.off");
00101 
00102   tri::SurfaceSampling<MyMesh,tri::TrivialSampler<MyMesh> >::PoissonDiskParam pp;
00103   pp.preGenMesh = &PoissonEdgeMesh;
00104   pp.preGenFlag=true;
00105   sampleVec.clear();
00106   tri::SurfaceSampling<MyMesh,tri::TrivialSampler<MyMesh> >::PoissonDiskPruning(mps, MontecarloEdgeMesh, rad, pp);
00107   tri::BuildMeshFromCoordVector(PoissonEdgeMesh,sampleVec);
00108   tri::io::ExporterOFF<MyMesh>::Save(PoissonEdgeMesh,"PoissonEdgeMesh.off");
00109 
00110   sampleVec.clear();
00111   tri::SurfaceSampling<MyMesh,tri::TrivialSampler<MyMesh> >::Montecarlo(m,mps,50000);
00112   tri::BuildMeshFromCoordVector(MontecarloSurfaceMesh,sampleVec);
00113   tri::io::ExporterOFF<MyMesh>::Save(MontecarloSurfaceMesh,"MontecarloSurfaceMesh.off");
00114 
00115   pp.preGenMesh = &PoissonEdgeMesh;
00116   pp.preGenFlag=true;
00117   sampleVec.clear();
00118   tri::SurfaceSampling<MyMesh,tri::TrivialSampler<MyMesh> >::PoissonDiskPruning(mps, MontecarloSurfaceMesh, rad, pp);
00119   tri::BuildMeshFromCoordVector(PoissonMesh,sampleVec);
00120   tri::io::ExporterOFF<MyMesh>::Save(PoissonMesh,"PoissonMesh.off");
00121   printf("Computed a feature aware poisson disk distribution of %i vertices radius is %6.3f\n",PoissonMesh.VN(),rad);
00122 
00123   return 0;
00124 }


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