VCG Library
trimesh_resampler.cpp
1 /****************************************************************************
2 * VCGLib o o *
3 * Visual and Computer Graphics Library o o *
4 * _ O _ *
5 * Copyright(C) 2004-2016 \/)\/ *
6 * Visual Computing Lab /\/| *
7 * ISTI - Italian National Research Council | *
8 * \ *
9 * All rights reserved. *
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 * This program is distributed in the hope that it will be useful, *
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
19 * GNU General Public License (http://www.gnu.org/licenses/gpl.txt) *
20 * for more details. *
21 * *
22 ****************************************************************************/
23 #include <vcg/complex/complex.h>
24 #include <vcg/math/perlin_noise.h>
25 #include <vcg/complex/algorithms/create/platonic.h>
26 #include <vcg/complex/algorithms/create/resampler.h>
27 #include <wrap/io_trimesh/export_ply.h>
28 
29 using namespace std;
30 using namespace vcg;
31 
32 typedef float ScalarType;
33 
34 class MyFace;
35 class MyVertex;
36 
37 struct MyUsedTypes : public UsedTypes< Use<MyVertex>::AsVertexType,
38  Use<MyFace> ::AsFaceType>{};
39 
40 class MyVertex : public Vertex< MyUsedTypes, vertex::Coord3f, vertex::Normal3f, vertex::BitFlags>{};
41 class MyFace : public Face< MyUsedTypes, face::VertexRef, face::Normal3f, face::BitFlags> {};
42 
43 class MyMesh : public tri::TriMesh< std::vector< MyVertex>, std::vector< MyFace > > {};
44 
45 int main(int /*argc*/ , char **/*argv*/)
46 {
47  MyMesh base_mesh,resampled_mesh;
48  tri::Torus(base_mesh,10,3);
50  Box3f bb = base_mesh.bbox;
51  float cell_side = bb.Diag()/30.0;
52  bb.Offset(cell_side);
53  Point3i box_size(bb.DimX()/cell_side,bb.DimY()/cell_side,bb.DimZ()/cell_side);
54 
55  tri::Resampler<MyMesh,MyMesh>::Resample(base_mesh,resampled_mesh,bb,box_size,cell_side*5);
56 
57  vcg::tri::io::ExporterPLY<MyMesh>::Save( resampled_mesh, "resampled_torus.ply");
58 
59  printf("OK!\n");
60 };