Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include <vcg/complex/complex.h>
00025 #include <vcg/complex/algorithms/update/topology.h>
00026 #include <vcg/complex/algorithms/update/bounding.h>
00027 #include <vcg/complex/algorithms/update/flag.h>
00028 #include <vcg/complex/algorithms/clean.h>
00029 #include <vcg/complex/algorithms/intersection.h>
00030 #include <vcg/space/index/grid_static_ptr.h>
00031
00032
00033 #include <wrap/io_trimesh/import.h>
00034 #include <wrap/io_edgemesh/export_svg.h>
00035 #include <wrap/io_edgemesh/export_dxf.h>
00036
00037 using namespace std;
00038 using namespace vcg;
00039
00040 class MyFace;
00041 class MyEdge;
00042 class MyVertex;
00043
00044 struct MyUsedTypes : public UsedTypes< Use<MyVertex> ::AsVertexType,
00045 Use<MyEdge> ::AsEdgeType,
00046 Use<MyFace> ::AsFaceType>{};
00047
00048
00049 class MyVertex : public Vertex< MyUsedTypes, vertex::Coord3f, vertex::BitFlags, vertex::Normal3f, vertex::Mark>{};
00050 class MyEdge : public Edge< MyUsedTypes, edge::VertexRef, edge::EVAdj> {};
00051 class MyFace : public Face <MyUsedTypes, face::VertexRef,face::FFAdj, face::BitFlags, face::Normal3f> {};
00052
00053 class MyEdgeMesh: public tri::TriMesh< vector<MyVertex>, vector<MyEdge> > {};
00054 class MyMesh : public tri::TriMesh< vector<MyVertex>, vector<MyFace > >{};
00055
00056
00057 typedef vcg::GridStaticPtr<MyMesh::FaceType, MyMesh::ScalarType> TriMeshGrid;
00058
00059 int main(int argc,char ** argv)
00060 {
00061 if (argc<6)
00062 {
00063 printf("\n");
00064 printf(" Usage: trimesh_intersection <filename> <a> <b> <c> <d>\n\n");
00065 printf(" <filename> Mesh model to intersect (PLY format).\n");
00066 printf(" <a> <b> <c> <d> The coefficients that specifying a plane in the form:\n\n");
00067 printf(" a*x + b*y + c*z + d = 0\n\n\n");
00068
00069 printf(" Example: trimesh_intersection bunny.ply 0.0 1.0 0.0 0.0\n\n");
00070
00071 return 0;
00072 }
00073
00074 MyMesh m;
00075
00076
00077 int err = tri::io::Importer<MyMesh>::Open(m,argv[1]);
00078 if(err)
00079 {
00080 printf("Error in reading %s: '%s'\n",argv[1],tri::io::Importer<MyMesh>::ErrorMsg(err));
00081 exit(-1);
00082 }
00083
00084
00085 int dup = tri::Clean<MyMesh>::RemoveDuplicateVertex(m);
00086 int unref = tri::Clean<MyMesh>::RemoveUnreferencedVertex(m);
00087
00088 if (dup > 0 || unref > 0)
00089 printf("Removed %i duplicate and %i unreferenced vertices from mesh %s\n",dup,unref,argv[1]);
00090
00091
00093
00094 MyMesh::ScalarType a = static_cast<MyMesh::ScalarType>(atof(argv[2]));
00095 MyMesh::ScalarType b = static_cast<MyMesh::ScalarType>(atof(argv[3]));
00096 MyMesh::ScalarType c = static_cast<MyMesh::ScalarType>(atof(argv[4]));
00097 MyMesh::ScalarType d = static_cast<MyMesh::ScalarType>(atof(argv[5]));
00098
00099 vcg::Point3<MyMesh::ScalarType> direction(a, b, c);
00100 MyMesh::ScalarType distance = -d / direction.Norm();
00101 direction.Normalize();
00102
00103 vcg::Plane3<MyMesh::ScalarType> plane(distance, direction);
00104
00105 MyEdgeMesh edge_mesh;
00106
00107 vcg::IntersectionPlaneMesh<MyMesh, MyEdgeMesh, MyMesh::ScalarType>(m, plane, edge_mesh);
00108
00109
00110 vcg::tri::UpdateBounding<MyEdgeMesh>::Box(edge_mesh);
00111
00112
00113 tri::io::SVGProperties pro;
00114 if (tri::io::ExporterSVG<MyEdgeMesh>::Save(edge_mesh, "out.svg",pro))
00115 printf(" The cross-intersection has been successfully saved (OUT.SVG).\n");
00116 else
00117 printf(" The cross-intersection cannot be saved.\n");
00118
00119
00120 return 0;
00121 }
00122