diff --git a/apps/sample/edgemesh_sampling/edgemesh_sampling.cpp b/apps/sample/edgemesh_sampling/edgemesh_sampling.cpp new file mode 100644 index 00000000..6a8bb037 --- /dev/null +++ b/apps/sample/edgemesh_sampling/edgemesh_sampling.cpp @@ -0,0 +1,96 @@ +/**************************************************************************** +* VCGLib o o * +* Visual and Computer Graphics Library o o * +* _ O _ * +* Copyright(C) 2004-2012 \/)\/ * +* Visual Computing Lab /\/| * +* ISTI - Italian National Research Council | * +* \ * +* All rights reserved. * +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU General Public License as published by * +* the Free Software Foundation; either version 2 of the License, or * +* (at your option) any later version. * +* * +* This program is distributed in the hope that it will be useful, * +* but WITHOUT ANY WARRANTY; without even the implied warranty of * +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +* GNU General Public License (http://www.gnu.org/licenses/gpl.txt) * +* for more details. * +* * +****************************************************************************/ +#include + +#include +#include +#include + +#include +#include + +using namespace vcg; +using namespace std; + +class MyEdge; +class MyFace; +class MyVertex; +struct MyUsedTypes : public UsedTypes< Use ::AsVertexType, + Use ::AsEdgeType, + Use ::AsFaceType>{}; + +class MyVertex : public Vertex{}; +class MyFace : public Face< MyUsedTypes, face::FFAdj, face::Normal3f, face::VertexRef, face::BitFlags > {}; +class MyEdge : public Edge{}; +class MyMesh : public tri::TriMesh< vector, vector , vector > {}; + + + + +int main( int argc, char **argv ) +{ + if(argc<2) + { + printf("Usage trimesh_base radius\n"); + return -1; + } + + MyMesh m,e; + + if(tri::io::ImporterOFF::Open(m,argv[1])!=0) + { + printf("Error reading file %s\n",argv[1]); + exit(0); + } + + printf("Input mesh has %i vert %i faces\n",m.vn,m.fn); + + + tri::UpdateTopology::FaceFace(m); + tri::UpdateNormal::PerVertexNormalizedPerFaceNormalized(m); + + tri::UpdateFlags::FaceFauxSignedCrease(m,math::ToRad(-40.f),math::ToRad(40.f ),false); + assert(tri::Clean::IsFaceFauxConsistent(m)); + tri::BuildFromNonFaux(m,e); + printf("Out mesh has %i vert %i edges\n",e.vn,e.en); + + tri::UpdateTopology::VertexEdge(e); + tri::Clean::SelectNonManifoldVertexOnEdgeMesh(e); + printf("Selected vertices %i\n",tri::UpdateSelection::VertexCount(e)); + tri::Clean::SplitSelectedVertexOnEdgeMesh(e); + printf("Out mesh has %i vert %i edges\n",e.vn,e.en); + tri::Clean::SelectCreaseVertexOnEdgeMesh(e,math::ToRad(30.f)); + printf("Selected vertices %i\n",tri::UpdateSelection::VertexCount(e)); + tri::Clean::SplitSelectedVertexOnEdgeMesh(e); + printf("Out mesh has %i vert %i edges\n",e.vn,e.en); + + tri::io::ExporterPLY::Save(e,"out.ply", tri::io::Mask::IOM_EDGEINDEX); + + std::vector sampleVec; + tri::TrivialSampler ps(sampleVec); + tri::SurfaceSampling::EdgeMeshUniform(e,ps,m.bbox.Diag()/90.0f); + MyMesh sampleMesh; + tri::Build(sampleMesh,sampleVec); + tri::io::ExporterPLY::Save(sampleMesh,"sampleMesh.ply"); + return 0; +} diff --git a/apps/sample/edgemesh_sampling/edgemesh_sampling.pro b/apps/sample/edgemesh_sampling/edgemesh_sampling.pro new file mode 100644 index 00000000..e15014a1 --- /dev/null +++ b/apps/sample/edgemesh_sampling/edgemesh_sampling.pro @@ -0,0 +1,3 @@ +include(../common.pri) +TARGET = edgemesh_sampling +SOURCES += edgemesh_sampling.cpp ../../../wrap/ply/plylib.cpp