From b619a09508e0abfe9357681002ed70beb0014561 Mon Sep 17 00:00:00 2001 From: Paolo Cignoni Date: Wed, 8 May 2019 11:28:54 +0200 Subject: [PATCH] Simple example for mesh uniform resampling class --- .../trimesh_resampler/trimesh_resampler.cpp | 60 +++++++++++++++++++ .../trimesh_resampler/trimesh_resampler.pro | 3 + 2 files changed, 63 insertions(+) create mode 100644 apps/sample/trimesh_resampler/trimesh_resampler.cpp create mode 100644 apps/sample/trimesh_resampler/trimesh_resampler.pro diff --git a/apps/sample/trimesh_resampler/trimesh_resampler.cpp b/apps/sample/trimesh_resampler/trimesh_resampler.cpp new file mode 100644 index 00000000..cb60cf8e --- /dev/null +++ b/apps/sample/trimesh_resampler/trimesh_resampler.cpp @@ -0,0 +1,60 @@ +/**************************************************************************** +* VCGLib o o * +* Visual and Computer Graphics Library o o * +* _ O _ * +* Copyright(C) 2004-2016 \/)\/ * +* 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 + +using namespace std; +using namespace vcg; + +typedef float ScalarType; + +class MyFace; +class MyVertex; + +struct MyUsedTypes : public UsedTypes< Use::AsVertexType, + Use ::AsFaceType>{}; + +class MyVertex : public Vertex< MyUsedTypes, vertex::Coord3f, vertex::Normal3f, vertex::BitFlags>{}; +class MyFace : public Face< MyUsedTypes, face::VertexRef, face::Normal3f, face::BitFlags> {}; + +class MyMesh : public tri::TriMesh< std::vector< MyVertex>, std::vector< MyFace > > {}; + +int main(int /*argc*/ , char **/*argv*/) +{ + MyMesh base_mesh,resampled_mesh; + tri::Torus(base_mesh,10,3); + vcg::tri::UpdateBounding::Box(base_mesh); + Box3f bb = base_mesh.bbox; + float cell_side = bb.Diag()/30.0; + bb.Offset(cell_side); + Point3i box_size(bb.DimX()/cell_side,bb.DimY()/cell_side,bb.DimZ()/cell_side); + + tri::Resampler::Resample(base_mesh,resampled_mesh,bb,box_size,cell_side*5); + + vcg::tri::io::ExporterPLY::Save( resampled_mesh, "resampled_torus.ply"); + + printf("OK!\n"); +}; diff --git a/apps/sample/trimesh_resampler/trimesh_resampler.pro b/apps/sample/trimesh_resampler/trimesh_resampler.pro new file mode 100644 index 00000000..f83391ce --- /dev/null +++ b/apps/sample/trimesh_resampler/trimesh_resampler.pro @@ -0,0 +1,3 @@ +include(../common.pri) +TARGET = trimesh_resampler +SOURCES += trimesh_resampler.cpp ../../../wrap/ply/plylib.cpp