First working version

This commit is contained in:
Massimiliano Corsini 2006-02-13 16:17:06 +00:00
parent a148df81a0
commit d937398944
2 changed files with 74 additions and 40 deletions

View File

@ -9,49 +9,48 @@ using namespace std;
#include <vcg/complex/trimesh/update/bounding.h> #include <vcg/complex/trimesh/update/bounding.h>
#include <vcg/complex/trimesh/update/flag.h> #include <vcg/complex/trimesh/update/flag.h>
#include <vcg/complex/trimesh/clean.h> #include <vcg/complex/trimesh/clean.h>
#include <vcg/complex/intersection.h>
#include <vcg/space/index/grid_static_ptr.h>
#include <vcg/simplex/edge/with/ae.h>
#include <vcg/complex/edgemesh/base.h>
#include <vcg/complex/edgemesh/allocate.h>
#include <vcg/complex/edgemesh/update/bounding.h>
// VCG File Format Importer // VCG File Format Importer/Exporter
#include <wrap/io_trimesh/import.h> #include <wrap/io_trimesh/import.h>
#include <wrap/io_trimesh/export.h> #include <wrap/io_edgemesh/export_svg.h>
// VCG Vertex // VCG Vertex
#include <vcg/simplex/vertexplus/base.h> #include <vcg/simplex/vertex/vertex.h>
#include <vcg/simplex/vertexplus/component.h> #include <vcg/simplex/vertex/with/afvn.h>
// VCG Faces // VCG Faces
#include <vcg/simplex/faceplus/base.h> #include <vcg/simplex/face/face.h>
#include <vcg/simplex/faceplus/component.h> #include <vcg/simplex/face/with/afav.h>
#include <vcg/space/index/grid_static_ptr.h>
using namespace vcg; using namespace vcg;
class MyFace; class MyFace;
class MyEdge; class MyEdge;
class MyVertex : public VertexSimp2< MyVertex, MyEdge, MyFace, vert::VFAdj, vert::Coord3f, class MyVertex : public VertexAFVN<float, MyEdge, MyFace> {};
vert::BitFlags, vert::Normal3f > {}; class MyFace : public FaceAFAV< MyVertex, MyEdge, MyFace > {};
class MyFace : public FaceSimp2< MyVertex, MyEdge, MyFace, face::FFAdj, face::VFAdj, class MyEdge : public vcg::EdgeAE<MyEdge, MyVertex> {};
face::VertexRef, face::Normal3f, face::BitFlags, face::Mark > {}; class MyMesh : public vcg::tri::TriMesh< vector<MyVertex>, vector<MyFace> > {};
class MyMesh : public vcg::tri::TriMesh< vector<CVertex>, vector<CFace> > {}; class MyEdgeMesh: public vcg::edge::EdgeMesh< vector<MyVertex>, vector<MyEdge> > {};
typedef MyMesh::VertexPointer VertexPointer;
typedef MyMesh::VertexIterator VertexIterator;
typedef MyMesh::VertexPointer VertexPointer;
typedef MyMesh::VertexIterator VertexIterator;
typedef MyMesh::FaceContainer FaceContainer;
typedef vcg::GridStaticPtr<MyMesh::FaceType, MyMesh::ScalarType> TriMeshGrid;
int main(int argc,char ** argv) int main(int argc,char ** argv)
{ {
if (argc<6) if (argc<6)
{ {
printf("\n");
printf(" Usage: trimesh_intersection <filename> <a> <b> <c> <d>\n\n"); printf(" Usage: trimesh_intersection <filename> <a> <b> <c> <d>\n\n");
printf(" <filename> Mesh model to intersect (PLY format)."); printf(" <filename> Mesh model to intersect (PLY format).\n");
printf(" <a> <b> <c> <d> The coefficients that specifying a plane in the form:\n"); printf(" <a> <b> <c> <d> The coefficients that specifying a plane in the form:\n\n");
printf(" a*x + b*y + c*z + d = 0\n"); printf(" a*x + b*y + c*z + d = 0\n\n\n");
printf(" Example: trimesh_intersection bunny.ply 1.0 0.0 0.0 0.0"); printf(" Example: trimesh_intersection bunny.ply 0.0 1.0 0.0 0.0\n\n");
return 0; return 0;
} }
@ -78,13 +77,41 @@ int main(int argc,char ** argv)
// Compute cross-intersection with the given plane // Compute cross-intersection with the given plane
///////////////////////////////////////////////////////// /////////////////////////////////////////////////////////
double a = atof(arg[2]); MyMesh::ScalarType a = static_cast<MyMesh::ScalarType>(atof(argv[2]));
double b = atof(arg[3]); MyMesh::ScalarType b = static_cast<MyMesh::ScalarType>(atof(argv[3]));
double c = atof(arg[4]); MyMesh::ScalarType c = static_cast<MyMesh::ScalarType>(atof(argv[4]));
double d = atof(arg[5]); MyMesh::ScalarType d = static_cast<MyMesh::ScalarType>(atof(argv[5]));
// export cross-section vcg::Point3<MyMesh::ScalarType> direction(a, b, c);
tri::io::ExporterPLY<MyMesh>::Save(m, "out.ply"); MyMesh::ScalarType distance = -d / direction.Norm();
direction.Normalize();
vcg::Plane3<MyMesh::ScalarType> plane(distance, direction);
printf("%f %f %f %f\n",distance,direction[0],direction[1],direction[2]);
double avg_length; // average length of the edges
MyEdgeMesh edge_mesh; // returned EdgeMesh (i.e. the cross-section)
// Create a static grid (for fast indexing) and fill it
TriMeshGrid static_grid;
static_grid.Set(m.face.begin(), m.face.end());
std::vector<TriMeshGrid::Cell *> intersected_cells;
vcg::Intersection<MyMesh, MyEdgeMesh, MyMesh::ScalarType, TriMeshGrid>(plane,
edge_mesh, avg_length, &static_grid, intersected_cells);
printf("%d", edge_mesh.edges.size());
// Compute bounding box
vcg::edge::UpdateBounding<MyEdgeMesh>::Box(edge_mesh);
// export the cross-section
vcg::edge::io::ExporterSVG<MyEdgeMesh> exporter;
if (exporter.Save(&edge_mesh, "out.svg"))
printf(" The cross-intersection has been successfully saved (OUT.SVG).\n");
else
printf(" The cross-intersection cannot be saved.\n");
return 0; return 0;
} }

View File

@ -0,0 +1,7 @@
TARGET = trimesh_intersection
LIBPATH +=
DEPENDPATH += .
INCLUDEPATH += . ../../..
CONFIG += console stl
TEMPLATE = app
SOURCES += trimesh_intersection.cpp ../../../wrap/ply/plylib.cpp