diff --git a/apps/sample/trimesh_intersection/trimesh_intersection.cpp b/apps/sample/trimesh_intersection/trimesh_intersection.cpp new file mode 100644 index 00000000..814a5f12 --- /dev/null +++ b/apps/sample/trimesh_intersection/trimesh_intersection.cpp @@ -0,0 +1,91 @@ +#include + +using namespace std; + +// VCG headers for triangular mesh processing +#include +#include +#include +#include +#include +#include + +// VCG File Format Importer +#include +#include + +// VCG Vertex +#include +#include + +// VCG Faces +#include +#include + +#include + +using namespace vcg; + +class MyFace; +class MyEdge; +class MyVertex : public VertexSimp2< MyVertex, MyEdge, MyFace, vert::VFAdj, vert::Coord3f, + vert::BitFlags, vert::Normal3f > {}; +class MyFace : public FaceSimp2< MyVertex, MyEdge, MyFace, face::FFAdj, face::VFAdj, + face::VertexRef, face::Normal3f, face::BitFlags, face::Mark > {}; +class MyMesh : public vcg::tri::TriMesh< vector, vector > {}; + +typedef MyMesh::VertexPointer VertexPointer; +typedef MyMesh::VertexIterator VertexIterator; + +typedef MyMesh::VertexPointer VertexPointer; +typedef MyMesh::VertexIterator VertexIterator; +typedef MyMesh::FaceContainer FaceContainer; + + +int main(int argc,char ** argv) +{ + if (argc<6) + { + printf("Usage: trimesh_intersection \n\n"); + printf(" Mesh model to intersect (PLY format)."); + printf(" The coefficients that specifying a plane in the form:\n"); + printf(" a*x + b*y + c*z + d = 0\n"); + + printf(" Example: trimesh_intersection bunny.ply 1.0 0.0 0.0 0.0"); + + return 0; + } + + MyMesh m; + + // open a mesh + int err = tri::io::Importer::Open(m,argv[1]); + if(err) + { + printf("Error in reading %s: '%s'\n",argv[1],tri::io::Importer::ErrorMsg(err)); + exit(-1); + } + + // some cleaning to get rid of bad file formats like stl that duplicate vertexes.. + int dup = tri::Clean::RemoveDuplicateVertex(m); + int unref = tri::Clean::RemoveUnreferencedVertex(m); + + if (dup > 0 || unref > 0) + printf("Removed %i duplicate and %i unreferenced vertices from mesh %s\n",dup,unref,argv[1]); + + printf(""); + + // Compute cross-intersection with the given plane + ///////////////////////////////////////////////////////// + + double a = atof(arg[2]); + double b = atof(arg[3]); + double c = atof(arg[4]); + double d = atof(arg[5]); + + // export cross-section + tri::io::ExporterPLY::Save(m, "out.ply"); + + return 0; +} +