VCG Library
trimesh_cylinder_clipping.cpp
1 #include <math.h>
2 #include <stdio.h>
3 #include <vcg/complex/algorithms/update/color.h>
4 #include <vcg/complex/algorithms/create/platonic.h>
5 #include <wrap/io_trimesh/import_ply.h>
6 #include <wrap/io_trimesh/export_ply.h>
7 #include <vcg/complex/algorithms/cylinder_clipping.h>
8 
9 using namespace vcg;
10 using namespace std;
11 
12 class MyEdge;
13 class MyFace;
14 class MyVertex;
15 struct MyUsedTypes : public UsedTypes< Use<MyVertex> ::AsVertexType,
16  Use<MyEdge> ::AsEdgeType,
17  Use<MyFace> ::AsFaceType >{};
18 
19 class MyVertex : public Vertex<MyUsedTypes, vertex::Normal3f, vertex::Coord3f, vertex::BitFlags, vertex::Color4b >{};
20 class MyFace : public Face<MyUsedTypes, face::Mark, face::Normal3f, face::FFAdj, face::BitFlags, face::VertexRef, face::Color4b > {};
21 class MyEdge : public Edge<MyUsedTypes, edge::BitFlags>{};
22 class MyMesh : public tri::TriMesh< vector<MyVertex>, vector<MyFace> , vector<MyEdge> > {};
23 
24 int main()
25 {
26  MyMesh m;
27  tri::Hexahedron(m);
32 
33  Point3f origin(0.8f,-0.4,0);
34  Point3f end= origin+Point3f(0,1,0);
35  float radius = 0.5f;
36  MyMesh cm;
37  tri::OrientedCylinder(cm,origin,end,radius,64,4);
38  tri::io::ExporterPLY<MyMesh>::Save(cm,"cyl.ply");
39 
40  tri::CylinderClipping<MyMesh>::Apply(m,origin,end,radius);
41  tri::CylinderClipping<MyMesh>::Apply(m,origin,end,radius/2.0f);
42 
43  tri::io::ExporterPLY<MyMesh>::Save(m,"cube.ply");
44  return 0;
45 }