VCG Library
trimesh_intersection_mesh.cpp
Go to the documentation of this file.
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 ****************************************************************************/
30 #include <vcg/complex/complex.h>
31 #include <vcg/complex/algorithms/clean.h>
32 #include <vcg/complex/algorithms/intersection.h>
33 #include <vcg/complex/algorithms/refine.h>
34 #include <vcg/complex/algorithms/update/color.h>
35 #include <vcg/complex/algorithms/create/platonic.h>
36 #include<vcg/complex/algorithms/isotropic_remeshing.h>
37 
38 #include <wrap/io_trimesh/export_off.h>
39 
40 using namespace std;
41 using namespace vcg;
42 
43 class MyFace;
44 class MyVertex;
45 
46 struct MyUsedTypes : public UsedTypes<
47  Use<MyVertex>::AsVertexType,
48  Use<MyFace> ::AsFaceType>{};
49 
50 
51 class MyVertex : public Vertex< MyUsedTypes, vertex::Coord3f, vertex::VFAdj, vertex::BitFlags, vertex::Normal3f, vertex::Qualityf, vertex::Mark>{};
52 class MyFace : public Face < MyUsedTypes, face::VertexRef, face::VFAdj, face::FFAdj, face::Color4b, face::BitFlags, face::Mark, face::Normal3f> {};
53 
54 class MyMesh: public tri::TriMesh< vector<MyVertex>, vector<MyFace > >{};
55 
56 int main(int ,char **)
57 {
58  MyMesh m1, m2;
59  Sphere(m1);
60  Hexahedron(m2);
61  printf("Created a sphere mesh of %i vertices %i edges\n",m1.VN(),m1.FN());
62  printf("Created a cube mesh of %i vertices %i edges\n",m2.VN(),m2.FN());
63 
64  math::MarsenneTwisterRNG rnd(clock());
65  Point3f direction = vcg::math::GeneratePointOnUnitSphereUniform<float,math::MarsenneTwisterRNG>(rnd);
67  for(int i=0;i<6;++i)
68  {
73  IsotropicRemeshing<MyMesh>::Params params;
74 
75  float len = (tri::Stat<MyMesh>::ComputeFaceEdgeLengthAverage(m1,true) + tri::Stat<MyMesh>::ComputeFaceEdgeLengthAverage(m1,true));
76  params.SetTargetLen(len*0.8f);
77  params.SetFeatureAngleDeg(10);
78  params.iter=1; // just one iteration to avoid overtessellating.
79  params.selectedOnly=true;
80  printf(" Input mesh %8i v %8i f\n",m1.VN(),m1.FN());
81  IsotropicRemeshing<MyMesh>::Do(m1, params);
82  IsotropicRemeshing<MyMesh>::Do(m2, params);
83  printf(" Input mesh %8i v %8i f\n",m1.VN(),m1.FN());
84  }
87  int selCnt= tri::UpdateColor<MyMesh>::PerFaceConstant(m1,Color4b::Red,true);
88  printf("Intersected %i faces on sphere\n",selCnt);
89  selCnt= tri::UpdateColor<MyMesh>::PerFaceConstant(m2,Color4b::Red,true);
90  printf("Intersected %i faces on cube\n",selCnt);
91 
92  tri::io::ExporterOFF<MyMesh>::Save(m1,"sphere.off",tri::io::Mask::IOM_FACECOLOR);
93  tri::io::ExporterOFF<MyMesh>::Save(m2,"cube.off",tri::io::Mask::IOM_FACECOLOR);
94 
95  return 0;
96 }
97