updated the slicing/capping/edgemesh sample
This commit is contained in:
parent
2239cbd747
commit
8d77ac39e3
|
@ -20,6 +20,7 @@
|
||||||
* for more details. *
|
* for more details. *
|
||||||
* *
|
* *
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
#include <QtOpenGL/qgl.h>
|
||||||
|
|
||||||
#include<vcg/simplex/vertex/base.h>
|
#include<vcg/simplex/vertex/base.h>
|
||||||
#include<vcg/simplex/vertex/component.h>
|
#include<vcg/simplex/vertex/component.h>
|
||||||
|
@ -31,6 +32,7 @@
|
||||||
|
|
||||||
#include<vcg/simplex/face/topology.h>
|
#include<vcg/simplex/face/topology.h>
|
||||||
#include<vcg/complex/complex.h>
|
#include<vcg/complex/complex.h>
|
||||||
|
#include<vcg/complex/append.h>
|
||||||
|
|
||||||
// input output
|
// input output
|
||||||
#include<wrap/io_trimesh/import.h>
|
#include<wrap/io_trimesh/import.h>
|
||||||
|
@ -38,10 +40,12 @@
|
||||||
|
|
||||||
// topology computation
|
// topology computation
|
||||||
#include<vcg/complex/algorithms/update/topology.h>
|
#include<vcg/complex/algorithms/update/topology.h>
|
||||||
|
#include<vcg/complex/algorithms/update/bounding.h>
|
||||||
|
|
||||||
// normals
|
// normals
|
||||||
#include<vcg/complex/algorithms/update/normal.h>
|
#include<vcg/complex/algorithms/update/normal.h>
|
||||||
#include <vcg/complex/algorithms/intersection.h>
|
#include <vcg/complex/algorithms/intersection.h>
|
||||||
|
#include <wrap/gl/glu_tessellator_cap.h>
|
||||||
|
|
||||||
using namespace vcg;
|
using namespace vcg;
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
@ -66,7 +70,7 @@ int main( int argc, char **argv )
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
MyMesh m,em;
|
MyMesh m,em,cm,full;
|
||||||
|
|
||||||
if(tri::io::ImporterPLY<MyMesh>::Open(m,argv[1])!=0)
|
if(tri::io::ImporterPLY<MyMesh>::Open(m,argv[1])!=0)
|
||||||
{
|
{
|
||||||
|
@ -76,53 +80,35 @@ int main( int argc, char **argv )
|
||||||
|
|
||||||
tri::UpdateFlags<MyMesh>::FaceBorderFromFF(m);
|
tri::UpdateFlags<MyMesh>::FaceBorderFromFF(m);
|
||||||
tri::UpdateNormals<MyMesh>::PerVertexNormalized(m);
|
tri::UpdateNormals<MyMesh>::PerVertexNormalized(m);
|
||||||
|
tri::UpdateBounding<MyMesh>::Box(m);
|
||||||
|
|
||||||
printf("Input mesh vn:%i fn:%i\n",m.vn,m.fn);
|
printf("Input mesh vn:%i fn:%i\n",m.vn,m.fn);
|
||||||
printf( "Mesh has %i vert and %i faces\n", m.vn, m.fn );
|
printf( "Mesh has %i vert and %i faces\n", m.vn, m.fn );
|
||||||
|
srand(time(0));
|
||||||
Plane3f slicingPlane;
|
Plane3f slicingPlane;
|
||||||
Point3f planeCenter = m.bbox.Center();
|
Point3f planeCenter = m.bbox.Center();
|
||||||
slicingPlane.Init(planeCenter,Point3f(0,0,1));
|
|
||||||
|
|
||||||
vcg::IntersectionPlaneMesh<MyMesh, MyMesh, float>(m, slicingPlane, em );
|
for(int i=0;i<10;++i)
|
||||||
tri::Clean<MyMesh>::RemoveDuplicateVertex(em);
|
|
||||||
std::vector< std::vector<Point3f> > outlines;
|
|
||||||
std::vector<Point3f> outline;
|
|
||||||
vcg::tri::UpdateFlags<MyMesh>::EdgeClearV(em);
|
|
||||||
int nv=0;
|
|
||||||
|
|
||||||
tri::UpdateTopology<MyMesh>::EdgeEdge(em);
|
|
||||||
|
|
||||||
for(size_t i=0;i<em.edge.size();i++)
|
|
||||||
{
|
{
|
||||||
if (!em.edge[i].IsV())
|
cm.Clear();
|
||||||
{
|
em.Clear();
|
||||||
printf("Edge %i (%i %i) ee0=%i ee1=%i\n",i,tri::Index(em,em.edge[i].V(0)),tri::Index(em,em.edge[i].V(1)),
|
Point3f planeDir = Point3f(-0.5f+float(rand())/RAND_MAX,-0.5f+float(rand())/RAND_MAX,-0.5f+float(rand())/RAND_MAX);
|
||||||
tri::Index(em,em.edge[i].EEp(0)),tri::Index(em,em.edge[i].EEp(1)));
|
planeDir.Normalize();
|
||||||
MyEdge* startE=&(em.edge[i]);
|
printf("slicing dir %5.2f %5.2f %5.2f\n",planeDir[0],planeDir[1],planeDir[2]);
|
||||||
int startI = 0;
|
|
||||||
int curI = startI;
|
|
||||||
MyEdge* curE = startE;
|
|
||||||
MyEdge* nextE; int nextI;
|
|
||||||
do
|
|
||||||
{
|
|
||||||
curE->SetV();
|
|
||||||
outline.push_back(curE->V(curI)->P());
|
|
||||||
nextE=curE->EEp((curI+1)%2);
|
|
||||||
nextI=curE->EEi((curI+1)%2);
|
|
||||||
curE=nextE;
|
|
||||||
curI=nextI;
|
|
||||||
nv++;
|
|
||||||
}
|
|
||||||
while(curE != startE);
|
|
||||||
|
|
||||||
outlines.push_back(outline);
|
slicingPlane.Init(planeCenter+planeDir*0.3f*m.bbox.Diag()*float(rand())/RAND_MAX,planeDir);
|
||||||
printf("Found one outline of %i vertices\n\n",outline.size());
|
|
||||||
|
|
||||||
outline.clear();
|
vcg::IntersectionPlaneMesh<MyMesh, MyMesh, float>(m, slicingPlane, em );
|
||||||
}
|
tri::Clean<MyMesh>::RemoveDuplicateVertex(em);
|
||||||
|
vcg::tri::CapEdgeMesh(em,cm);
|
||||||
|
|
||||||
|
printf(" edge mesh vn %5i en %5i fn %5i\n",em.vn,em.en,em.fn);
|
||||||
|
printf("sliced mesh vn %5i en %5i fn %5i\n",cm.vn,cm.en,cm.fn);
|
||||||
|
|
||||||
|
tri::Append<MyMesh,MyMesh>::Mesh(full,cm);
|
||||||
}
|
}
|
||||||
printf("Found %i outlines for a total of %i vertices",outlines.size(),nv);
|
|
||||||
|
tri::io::ExporterPLY<MyMesh>::Save(full,"out.ply",false);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,9 +5,10 @@
|
||||||
TARGET = trimesh_edge
|
TARGET = trimesh_edge
|
||||||
DEPENDPATH += .
|
DEPENDPATH += .
|
||||||
INCLUDEPATH += . ../../..
|
INCLUDEPATH += . ../../..
|
||||||
CONFIG += console stl
|
CONFIG += console stl opengl
|
||||||
TEMPLATE = app
|
TEMPLATE = app
|
||||||
SOURCES += trimesh_edge.cpp ../../../wrap/ply/plylib.cpp
|
SOURCES += trimesh_edge.cpp ../../../wrap/ply/plylib.cpp
|
||||||
HEADERS += ../../../vcg/complex/algorithms/update/topology.h
|
HEADERS += ../../../vcg/complex/algorithms/update/topology.h
|
||||||
|
HEADERS += ../../../wrap/gl/glu_tessellator_cap.h
|
||||||
# Mac specific Config required to avoid to make application bundles
|
# Mac specific Config required to avoid to make application bundles
|
||||||
CONFIG -= app_bundle
|
CONFIG -= app_bundle
|
||||||
|
|
Loading…
Reference in New Issue