Updated a number of sample app for the vcg lib
This commit is contained in:
parent
a437952298
commit
2bb91ac57a
|
@ -45,13 +45,11 @@ class MyEdge : public Edge<MyUsedTypes,edge::VertexRef, edge::VEAdj, edge::EE
|
|||
class MyMesh : public tri::TriMesh< vector<MyVertex>, vector<MyFace> , vector<MyEdge> > {};
|
||||
|
||||
|
||||
|
||||
|
||||
int main( int argc, char **argv )
|
||||
{
|
||||
if(argc<2)
|
||||
{
|
||||
printf("Usage trimesh_base <meshfilename.obj> radius\n");
|
||||
printf("Usage edgemesh_sampling <meshfilename.off> radius\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -90,7 +88,7 @@ int main( int argc, char **argv )
|
|||
tri::TrivialSampler<MyMesh> ps(sampleVec);
|
||||
tri::SurfaceSampling<MyMesh>::EdgeMeshUniform(e,ps,m.bbox.Diag()/90.0f);
|
||||
MyMesh sampleMesh;
|
||||
tri::Build(sampleMesh,sampleVec);
|
||||
tri::BuildMeshFromCoordVector(sampleMesh,sampleVec);
|
||||
tri::io::ExporterPLY<MyMesh>::Save(sampleMesh,"sampleMesh.ply");
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -28,17 +28,14 @@
|
|||
#include <vcg/complex/algorithms/update/bounding.h>
|
||||
#include <vcg/complex/algorithms/update/normal.h>
|
||||
|
||||
/*include the algorithms for mesh fixing */
|
||||
#include <vcg/complex/algorithms/clean.h>
|
||||
#include <vcg/complex/algorithms/create/platonic.h>
|
||||
|
||||
#include <wrap/io_trimesh/import.h>
|
||||
#include <wrap/io_trimesh/export_ply.h>
|
||||
|
||||
/* include the support for polygon meshes (function to convert from/to trimesh)*/
|
||||
#include <vcg/complex/algorithms/polygon_support.h>
|
||||
|
||||
/* include the support for polygon meshes (the component for the face )*/
|
||||
#include <vcg/simplex/face/component_polygon.h>
|
||||
//#include <vcg/complex/algorithms/polygon_support.h>
|
||||
|
||||
/* include the support for half edges */
|
||||
#include <vcg/complex/algorithms/update/halfedge_indexed.h>
|
||||
|
@ -48,25 +45,22 @@ using namespace vcg;
|
|||
using namespace std;
|
||||
|
||||
// forward declarations
|
||||
class CFace;
|
||||
class CVertex;
|
||||
class CHEdge;
|
||||
class CEdge;
|
||||
class MyPolyVertex;
|
||||
class TFace;
|
||||
class TVertex;
|
||||
|
||||
struct CUsedTypes: public vcg::UsedTypes< vcg::Use<CVertex>::AsVertexType, vcg::Use<CFace>::AsFaceType >{};
|
||||
struct TUsedTypes: public vcg::UsedTypes< vcg::Use<TVertex>::AsVertexType, vcg::Use<TFace>::AsFaceType >{};
|
||||
|
||||
|
||||
|
||||
/* Definition of a mesh of triangles
|
||||
*/
|
||||
class CVertex : public Vertex< CUsedTypes,
|
||||
class TVertex : public Vertex< TUsedTypes,
|
||||
vertex::BitFlags,
|
||||
vertex::Coord3f,
|
||||
vertex::Normal3f,
|
||||
vertex::Mark >{};
|
||||
|
||||
class CFace : public Face< CUsedTypes,
|
||||
class TFace : public Face< TUsedTypes,
|
||||
face::VertexRef, // three pointers to vertices
|
||||
face::Normal3f, // normal
|
||||
face::BitFlags, // flags
|
||||
|
@ -74,29 +68,32 @@ class CFace : public Face< CUsedTypes,
|
|||
> {};
|
||||
|
||||
/* the mesh is a container of vertices and a container of faces */
|
||||
class CMesh : public vcg::tri::TriMesh< vector<CVertex>, vector<CFace> > {};
|
||||
class TMesh : public vcg::tri::TriMesh< vector<TVertex>, vector<TFace> > {};
|
||||
|
||||
|
||||
/* Definition of a mesh of polygons that also supports half-edges
|
||||
*/
|
||||
class MyPolyFace;
|
||||
class MyPolyVertex;
|
||||
struct PolyUsedTypes: public vcg::UsedTypes<vcg::Use<MyPolyVertex> ::AsVertexType,
|
||||
vcg::Use<CEdge> ::AsEdgeType,
|
||||
vcg::Use<CHEdge> ::AsHEdgeType,
|
||||
vcg::Use<MyPolyFace> ::AsFaceType
|
||||
class PFace;
|
||||
class PVertex;
|
||||
class PHEdge;
|
||||
class PEdge;
|
||||
|
||||
struct PUsedTypes: public vcg::UsedTypes<vcg::Use<PVertex> ::AsVertexType,
|
||||
vcg::Use<PEdge> ::AsEdgeType,
|
||||
vcg::Use<PHEdge>::AsHEdgeType,
|
||||
vcg::Use<PFace> ::AsFaceType
|
||||
>{};
|
||||
|
||||
//class DummyEdge: public vcg::Edge<PolyUsedTypes>{};
|
||||
class MyPolyVertex:public vcg::Vertex< PolyUsedTypes,
|
||||
class PVertex:public vcg::Vertex< PUsedTypes,
|
||||
vcg::vertex::Coord3f,
|
||||
vcg::vertex::Normal3f,
|
||||
vcg::vertex::Mark,
|
||||
vcg::vertex::BitFlags,
|
||||
vcg::vertex::VHAdj>{} ;
|
||||
|
||||
class CEdge : public Edge<PolyUsedTypes>{};
|
||||
class CHEdge : public HEdge< PolyUsedTypes, hedge::BitFlags,
|
||||
class PEdge : public Edge<PUsedTypes>{};
|
||||
class PHEdge : public HEdge< PUsedTypes, hedge::BitFlags,
|
||||
//hedge::HFAdj, // pointer to the face
|
||||
//hedge::HOppAdj, // pointer to the opposite edge
|
||||
//hedge::HVAdj, // pointer to the vertex
|
||||
|
@ -105,8 +102,8 @@ class CHEdge : public HEdge< PolyUsedTypes, hedge::BitFlags,
|
|||
//,hedge::HPrevAdj // pointer to the previous halfedge
|
||||
>{};
|
||||
|
||||
class MyPolyFace:public vcg::Face<
|
||||
PolyUsedTypes
|
||||
class PFace:public vcg::Face<
|
||||
PUsedTypes
|
||||
,vcg::face::PolyInfo // this is necessary if you use component in vcg/simplex/face/component_polygon.h
|
||||
// It says "this class is a polygon and the memory for its components (e.g. pointer to its vertices
|
||||
// will be allocated dynamically")
|
||||
|
@ -118,28 +115,21 @@ class MyPolyFace:public vcg::Face<
|
|||
,vcg::face::Normal3f // normal
|
||||
> {};
|
||||
|
||||
class MyPolyMesh: public
|
||||
class PMesh: public
|
||||
vcg::tri::TriMesh<
|
||||
std::vector<MyPolyVertex>, // the vector of vertices
|
||||
std::vector<MyPolyFace >, // the vector of faces
|
||||
std::vector<CHEdge> , // the vector of edges
|
||||
std::vector<CEdge> // the vector of edges
|
||||
std::vector<PVertex>, // the vector of vertices
|
||||
std::vector<PFace >, // the vector of faces
|
||||
std::vector<PHEdge> , // the vector of edges
|
||||
std::vector<PEdge> // the vector of edges
|
||||
>{};
|
||||
|
||||
MyPolyMesh pm;
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
// Globals: the mesh, the OpenGL wrapper to draw the mesh and the trackball.
|
||||
CMesh mesh,mesh1;
|
||||
PMesh pm;
|
||||
TMesh tm0;
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
|
||||
int loadmask;
|
||||
|
||||
vcg::tri::io::PlyInfo pi;
|
||||
|
||||
// pm.hedge.reserve(100000);
|
||||
if(true){
|
||||
/*
|
||||
first way:
|
||||
|
@ -149,40 +139,39 @@ if(true){
|
|||
3) import the tagged triangle mesh in a polygon mesh
|
||||
*/
|
||||
// vcg::tri::io::ImporterOBJ<CMesh>::Open(mesh,argv[1],loadmask);
|
||||
vcg::tri::io::ImporterOFF<CMesh>::Open(mesh,argv[1],loadmask);
|
||||
|
||||
vcg::tri::Clean<CMesh>::RemoveUnreferencedVertex(mesh);
|
||||
vcg::tri::Clean<CMesh>::RemoveZeroAreaFace(mesh);
|
||||
vcg::tri::UpdateTopology<CMesh>::FaceFace(mesh);
|
||||
vcg::tri::Clean<CMesh>::RemoveNonManifoldFace(mesh);
|
||||
vcg::tri::UpdateTopology<CMesh>::FaceFace(mesh);
|
||||
assert(vcg::tri::Clean<CMesh>::CountNonManifoldEdgeFF(mesh)==0);
|
||||
assert(vcg::tri::Clean<CMesh>::CountNonManifoldVertexFF(mesh)==0);
|
||||
// vcg::tri::io::ImporterOFF<TMesh>::Open(tm0,argv[1],loadmask);
|
||||
vcg::tri::Hexahedron(tm0);
|
||||
vcg::tri::Clean<TMesh>::RemoveUnreferencedVertex(tm0);
|
||||
vcg::tri::Clean<TMesh>::RemoveZeroAreaFace(tm0);
|
||||
vcg::tri::UpdateTopology<TMesh>::FaceFace(tm0);
|
||||
vcg::tri::Clean<TMesh>::RemoveNonManifoldFace(tm0);
|
||||
vcg::tri::UpdateTopology<TMesh>::FaceFace(tm0);
|
||||
assert(vcg::tri::Clean<TMesh>::CountNonManifoldEdgeFF(tm0)==0);
|
||||
assert(vcg::tri::Clean<TMesh>::CountNonManifoldVertexFF(tm0)==0);
|
||||
|
||||
// create a polygon meshe from a trimesh with tagged faces
|
||||
vcg::tri::PolygonSupport<CMesh,MyPolyMesh>::ImportFromTriMesh(pm,mesh);
|
||||
vcg::tri::PolygonSupport<TMesh,PMesh>::ImportFromTriMesh(pm,tm0);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* second way:
|
||||
Load into a polygon mesh straight away.
|
||||
*/
|
||||
vcg::tri::io::ImporterOBJ<MyPolyMesh>::Open(pm,argv[1],loadmask);
|
||||
vcg::tri::UpdateTopology<MyPolyMesh>::FaceFace(pm);
|
||||
vcg::tri::Clean<MyPolyMesh>::RemoveNonManifoldFace(pm);
|
||||
vcg::tri::UpdateTopology<MyPolyMesh>::FaceFace(pm);
|
||||
assert(vcg::tri::Clean<MyPolyMesh>::CountNonManifoldEdgeFF(pm));
|
||||
|
||||
vcg::tri::io::ImporterOBJ<PMesh>::Open(pm,argv[1],loadmask);
|
||||
vcg::tri::UpdateTopology<PMesh>::FaceFace(pm);
|
||||
vcg::tri::Clean<PMesh>::RemoveNonManifoldFace(pm);
|
||||
vcg::tri::UpdateTopology<PMesh>::FaceFace(pm);
|
||||
assert(vcg::tri::Clean<PMesh>::CountNonManifoldEdgeFF(pm));
|
||||
}
|
||||
|
||||
|
||||
// compute the half edges because I'm a half-edge programmer
|
||||
vcg::tri::UpdateHalfEdges<MyPolyMesh>::FromIndexed(pm);
|
||||
vcg::tri::UpdateHalfEdges<PMesh>::FromIndexed(pm);
|
||||
|
||||
// .... my half edge based code ......
|
||||
|
||||
// check for consistency
|
||||
assert(vcg::tri::UpdateHalfEdges<MyPolyMesh>::CheckConsistency(pm));
|
||||
assert(vcg::tri::UpdateHalfEdges<PMesh>::CheckConsistency(pm));
|
||||
|
||||
int size = pm.face.size();
|
||||
|
||||
|
@ -191,12 +180,12 @@ else
|
|||
for(int i = 0; i < size; ++i)
|
||||
if(!(pm.face[i].IsD()))
|
||||
if(pm.face[i].VN()>3){
|
||||
MyPolyMesh::HEdgePointer ef = pm.face[i].FHp();
|
||||
MyPolyMesh::HEdgePointer ef1 = ef -> HNp();
|
||||
PMesh::HEdgePointer ef = pm.face[i].FHp();
|
||||
PMesh::HEdgePointer ef1 = ef -> HNp();
|
||||
ef1 = ef1->HNp();
|
||||
vcg::tri::UpdateHalfEdges<MyPolyMesh>::AddHEdge(pm, ef, ef1 );
|
||||
vcg::tri::UpdateHalfEdges<PMesh>::AddHEdge(pm, ef, ef1 );
|
||||
}
|
||||
assert(vcg::tri::UpdateHalfEdges<MyPolyMesh>::CheckConsistency(pm));
|
||||
assert(vcg::tri::UpdateHalfEdges<PMesh>::CheckConsistency(pm));
|
||||
size = pm.face.size();
|
||||
|
||||
// remove an edge for each face
|
||||
|
@ -204,23 +193,25 @@ else
|
|||
for(int i = 0; i < size; ++i)
|
||||
if(!(pm.face[i].IsD() ))
|
||||
{
|
||||
MyPolyMesh::HEdgePointer ef = pm.face[i].FHp();
|
||||
PMesh::HEdgePointer ef = pm.face[i].FHp();
|
||||
if( ef->HOp()->HFp() !=NULL){
|
||||
vcg::tri::UpdateHalfEdges<MyPolyMesh>::RemoveHEdge(pm,ef);
|
||||
vcg::tri::UpdateHalfEdges<PMesh>::RemoveHEdge(pm,ef);
|
||||
}
|
||||
}
|
||||
|
||||
// check for consistency
|
||||
assert(vcg::tri::UpdateHalfEdges<MyPolyMesh>::CheckConsistency(pm));
|
||||
assert(vcg::tri::UpdateHalfEdges<PMesh>::CheckConsistency(pm));
|
||||
|
||||
// recompute indexed data structure from the half edge data structure
|
||||
vcg::tri::UpdateIndexed<MyPolyMesh>::FromHalfEdges(pm );
|
||||
// vcg::tri::UpdateIndexed<PMesh>::FromHalfEdges(pm );
|
||||
|
||||
// create a triangle mesh from a polygon mesh
|
||||
vcg::tri::PolygonSupport<CMesh,MyPolyMesh>::ImportFromPolyMesh(mesh1,pm);
|
||||
TMesh tm1;
|
||||
vcg::tri::PolygonSupport<TMesh,PMesh>::ImportFromPolyMesh(tm1,pm);
|
||||
|
||||
// write out the triangle mesh
|
||||
vcg::tri::io::ExporterPLY<CMesh>::Save(mesh1,"converted_out.ply",true,pi);
|
||||
vcg::tri::io::PlyInfo pi;
|
||||
vcg::tri::io::ExporterPLY<TMesh>::Save(tm1,"converted_tri.ply",false,pi);
|
||||
vcg::tri::io::ExporterPLY<PMesh>::Save(pm,"converted_poly.ply",false,pi);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -55,8 +55,6 @@ int main(int argc, char **argv)
|
|||
if(argc<3)
|
||||
{
|
||||
printf(
|
||||
"\n trimesh_ball_pivoting ("__DATE__")\n"
|
||||
" Visual Computing Group I.S.T.I. C.N.R.\n"
|
||||
"Usage: trimesh_ball_pivoting filein.ply fileout.ply [opt]\n"
|
||||
"options: \n"
|
||||
"-r <val> radius of the rolling ball\n"
|
||||
|
|
|
@ -68,14 +68,6 @@ class OcfMesh : public vcg::tri::TriMesh< vcg::vertex::vector_ocf<OcfVertex>,
|
|||
void Usage()
|
||||
{
|
||||
printf(
|
||||
"---------------------------------\n"
|
||||
" TriMeshCopy V.1.0 \n"
|
||||
" http://vcg.isti.cnr.it\n"
|
||||
" http://vcg.sourceforge.net\n"
|
||||
" release date: "__DATE__"\n"
|
||||
"---------------------------------\n\n"
|
||||
"TriMeshCopy 1.0 \n"__DATE__"\n"
|
||||
"Copyright 2003-2012 Visual Computing Lab I.S.T.I. C.N.R.\n"
|
||||
"\nUsage: "\
|
||||
"trimeshcopy fileIn -(n|o) [fileOut]\n"\
|
||||
"trimeshcopy test vcg::MeshCopy efficiency.\nIt imports a fileIn file into a user defined mesh and test how long vcg::MeshCopy needs to copy the imported mesh in a second one.The copy time is expressed in milliseconds.\nIf the -n flag is used a non-optional attributes mesh will be tested, defining -o, instead, the target mesh will be an ocf one.\nA fileOut file can be passed to the tool in order to check if the mesh was successfully copied.\nThe file will be exported in PLY file format.\n"
|
||||
|
|
|
@ -22,9 +22,12 @@
|
|||
****************************************************************************/
|
||||
#include<vcg/complex/complex.h>
|
||||
|
||||
#include<wrap/io_trimesh/import_off.h>
|
||||
#include<wrap/io_trimesh/import_ply.h>
|
||||
#include<wrap/io_trimesh/export_ply.h>
|
||||
|
||||
#include<vcg/complex/algorithms/point_sampling.h>
|
||||
#include<vcg/complex/algorithms/geodesic.h>
|
||||
#include<vcg/complex/algorithms/update/color.h>
|
||||
|
||||
using namespace vcg;
|
||||
using namespace std;
|
||||
|
@ -36,8 +39,8 @@ struct MyUsedTypes : public UsedTypes< Use<MyVertex> ::AsVertexType,
|
|||
Use<MyEdge> ::AsEdgeType,
|
||||
Use<MyFace> ::AsFaceType>{};
|
||||
|
||||
class MyVertex : public Vertex<MyUsedTypes, vertex::Coord3f, vertex::Normal3f, vertex::BitFlags >{};
|
||||
class MyFace : public Face< MyUsedTypes, face::FFAdj, face::VertexRef, face::BitFlags > {};
|
||||
class MyVertex : public Vertex<MyUsedTypes, vertex::Coord3f, vertex::Normal3f, vertex::Mark, vertex::VFAdj, vertex::Color4b, vertex::Qualityf, vertex::BitFlags >{};
|
||||
class MyFace : public Face< MyUsedTypes, face::VFAdj, face::VertexRef, face::Normal3f, face::BitFlags > {};
|
||||
class MyEdge : public Edge<MyUsedTypes>{};
|
||||
class MyMesh : public tri::TriMesh< vector<MyVertex>, vector<MyFace> , vector<MyEdge> > {};
|
||||
|
||||
|
@ -45,20 +48,47 @@ int main( int argc, char **argv )
|
|||
{
|
||||
if(argc<2)
|
||||
{
|
||||
printf("Usage trimesh_base <meshfilename.obj>\n");
|
||||
return -1;
|
||||
printf("Usage trimesh_geodesic <meshfilename.obj>\n");
|
||||
// return -1;
|
||||
}
|
||||
|
||||
MyMesh m;
|
||||
|
||||
if(tri::io::ImporterOFF<MyMesh>::Open(m,argv[1])!=0)
|
||||
// if(tri::io::ImporterPLY<MyMesh>::Open(m,"../../meshes/disk_irregular_1k.ply")!=0)
|
||||
if(tri::io::ImporterPLY<MyMesh>::Open(m,"../../meshes/disk_irregular_650k.ply")!=0)
|
||||
{
|
||||
printf("Error reading file %s\n",argv[1]);
|
||||
exit(0);
|
||||
}
|
||||
vector<Point3f> pointVec;
|
||||
float radius;
|
||||
tri::PoissonSampling<MyMesh>(m,pointVec,1000,radius);
|
||||
|
||||
Point3f c=m.bbox.Center();
|
||||
MyVertex*closest=&*m.vert.begin();
|
||||
float minDist = Distance(closest->P(),c);
|
||||
for(MyMesh::VertexIterator vi=m.vert.begin();vi!=m.vert.end(); ++vi)
|
||||
{
|
||||
if(Distance(vi->P(),c)<minDist)
|
||||
{
|
||||
minDist = Distance(vi->P(),c);
|
||||
closest = &*vi;
|
||||
}
|
||||
}
|
||||
vector<MyVertex*> seedVec;
|
||||
seedVec.push_back(closest);
|
||||
tri::EuclideanDistance<MyMesh> ed;
|
||||
tri::Clean<MyMesh>::RemoveUnreferencedVertex(m);
|
||||
tri::Allocator<MyMesh>::CompactEveryVector(m);
|
||||
tri::UpdateTopology<MyMesh>::VertexFace(m);
|
||||
tri::Geodesic<MyMesh>::Compute(m,seedVec,ed);
|
||||
pair<float,float> minmax = tri::Stat<MyMesh>::ComputePerVertexQualityMinMax(m);
|
||||
tri::UpdateColor<MyMesh>::PerVertexQualityRamp(m);
|
||||
printf("min %f max %f\n",minmax.first,minmax.second);
|
||||
tri::io::ExporterPLY<MyMesh>::Save(m,"base.ply",tri::io::Mask::IOM_VERTCOLOR | tri::io::Mask::IOM_VERTQUALITY);
|
||||
int t0=clock();
|
||||
tri::Geodesic<MyMesh>::PerVertexDijsktraCompute(m,seedVec,ed);
|
||||
int t1=clock();
|
||||
printf("Geodesic dijkstra %6.3f\n",float(t1-t0)/CLOCKS_PER_SEC);
|
||||
tri::UpdateColor<MyMesh>::PerVertexQualityRamp(m);
|
||||
tri::io::ExporterPLY<MyMesh>::Save(m,"base_d.ply",tri::io::Mask::IOM_VERTCOLOR | tri::io::Mask::IOM_VERTQUALITY);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
include(../common.pri)
|
||||
TARGET = trimesh_geodesic
|
||||
SOURCES += trimesh_geodesic.cpp
|
||||
SOURCES += trimesh_geodesic.cpp ../../../wrap/ply/plylib.cpp
|
||||
|
|
|
@ -73,13 +73,13 @@ bool NormalTest(typename face::Pos<typename MESH::FaceType> pos)
|
|||
{
|
||||
//giro intorno al vertice e controllo le normali
|
||||
typename MESH::ScalarType thr = 0.0f;
|
||||
typename MESH::CoordType NdP = vcg::Normal<typename MESH::FaceType>(*pos.f);
|
||||
typename MESH::CoordType NdP = vcg::TriangleNormal<typename MESH::FaceType>(*pos.f);
|
||||
typename MESH::CoordType tmp, oop, soglia = typename MESH::CoordType(thr,thr,thr);
|
||||
face::Pos<typename MESH::FaceType> aux=pos;
|
||||
do{
|
||||
aux.FlipF();
|
||||
aux.FlipE();
|
||||
oop = Abs(tmp - ::vcg::Normal<typename MESH::FaceType>(*pos.f));
|
||||
oop = Abs(tmp - ::vcg::TriangleNormal<typename MESH::FaceType>(*pos.f));
|
||||
if(oop < soglia )return false;
|
||||
}while(aux != pos && !aux.IsBorder());
|
||||
|
||||
|
|
|
@ -52,9 +52,7 @@ int main(int argc,char **argv )
|
|||
{
|
||||
if(argc<2)
|
||||
{
|
||||
printf( "\n trimesh_join ("__DATE__")\n"
|
||||
"Visual Computing Group I.S.T.I. C.N.R.\n"
|
||||
"Usage: trimesh_join [opt] filename.ply [filename.ply | *] \n"
|
||||
printf( "Usage: trimesh_join [opt] filename.ply [filename.ply | *] \n"
|
||||
"where opt can be:\n"
|
||||
" -b xmin ymin zmin xmax ymax zmax : \n"
|
||||
" Returns only mesh composed by faces inside specified bbox\n"
|
||||
|
|
|
@ -23,9 +23,9 @@
|
|||
/*! \file trimesh_kdtree.cpp
|
||||
\ingroup code_sample
|
||||
|
||||
\brief An example about using the kdtree and meshes
|
||||
\brief An example about using a kdtree to spatially index the vertexes of a mesh
|
||||
|
||||
KdTree are one of the Spatial indexing data structure available.
|
||||
KdTree are one of the Spatial indexing data structures available.
|
||||
They are tailored for storing point-based structures and performing k-neighbours queries.
|
||||
In this simple example we simply compute the average distance of a vertex from its neighbours.
|
||||
\ref spatial_indexing for more Details
|
||||
|
|
|
@ -61,17 +61,18 @@ int main( int argc, char **argv )
|
|||
tri::SurfaceSampling<MyMesh,tri::TrivialSampler<MyMesh> >::SamplingRandomGenerator().initialize(time(0));
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// Basic Sample,
|
||||
// Basic Sample of a mesh surface
|
||||
// Build a point cloud with points with a plain poisson disk distribution
|
||||
|
||||
int t0=clock();
|
||||
vector<Point3f> pointVec;
|
||||
float rad;
|
||||
float rad=0;
|
||||
if(argc>2) rad=atof(argv[2]);
|
||||
int sampleNum=rad?0:1000;
|
||||
tri::PoissonSampling<MyMesh>(m,pointVec,sampleNum,rad);
|
||||
int t1=clock();
|
||||
MyMesh BasicPoissonMesh;
|
||||
tri::Build(BasicPoissonMesh,pointVec);
|
||||
tri::BuildMeshFromCoordVector(BasicPoissonMesh,pointVec);
|
||||
|
||||
tri::io::ExporterOFF<MyMesh>::Save(BasicPoissonMesh,"BasicPoissonMesh.off");
|
||||
printf("Computed a basic poisson disk distribution of %i vertices radius is %6.3f in %5.2f sec\n",BasicPoissonMesh.VN(),rad,float(t1-t0)/CLOCKS_PER_SEC);
|
||||
|
@ -90,32 +91,32 @@ int main( int argc, char **argv )
|
|||
tri::UpdateNormal<MyMesh>::PerFace(m);
|
||||
tri::UpdateFlags<MyMesh>::FaceFauxCrease(m,math::ToRad(40.0f));
|
||||
tri::SurfaceSampling<MyMesh,tri::TrivialSampler<MyMesh> >::EdgeMontecarlo(m,mps,10000,false);
|
||||
tri::Build(MontecarloEdgeMesh,sampleVec);
|
||||
tri::BuildMeshFromCoordVector(MontecarloEdgeMesh,sampleVec);
|
||||
tri::io::ExporterOFF<MyMesh>::Save(MontecarloEdgeMesh,"MontecarloEdgeMesh.off");
|
||||
|
||||
sampleVec.clear();
|
||||
tri::SurfaceSampling<MyMesh,tri::TrivialSampler<MyMesh> >::VertexCrease(m, mps);
|
||||
tri::Build(PoissonEdgeMesh,sampleVec);
|
||||
tri::io::ExporterOFF<MyMesh>::Save(PoissonEdgeMesh,"CreaseMesh.off");
|
||||
tri::BuildMeshFromCoordVector(PoissonEdgeMesh,sampleVec);
|
||||
tri::io::ExporterOFF<MyMesh>::Save(PoissonEdgeMesh,"VertexCreaseMesh.off");
|
||||
|
||||
tri::SurfaceSampling<MyMesh,tri::TrivialSampler<MyMesh> >::PoissonDiskParam pp;
|
||||
pp.preGenMesh = &PoissonEdgeMesh;
|
||||
pp.preGenFlag=true;
|
||||
sampleVec.clear();
|
||||
tri::SurfaceSampling<MyMesh,tri::TrivialSampler<MyMesh> >::PoissonDiskPruning(mps, MontecarloEdgeMesh, rad, pp);
|
||||
tri::Build(PoissonEdgeMesh,sampleVec);
|
||||
tri::BuildMeshFromCoordVector(PoissonEdgeMesh,sampleVec);
|
||||
tri::io::ExporterOFF<MyMesh>::Save(PoissonEdgeMesh,"PoissonEdgeMesh.off");
|
||||
|
||||
sampleVec.clear();
|
||||
tri::SurfaceSampling<MyMesh,tri::TrivialSampler<MyMesh> >::Montecarlo(m,mps,50000);
|
||||
tri::Build(MontecarloSurfaceMesh,sampleVec);
|
||||
tri::BuildMeshFromCoordVector(MontecarloSurfaceMesh,sampleVec);
|
||||
tri::io::ExporterOFF<MyMesh>::Save(MontecarloSurfaceMesh,"MontecarloSurfaceMesh.off");
|
||||
|
||||
pp.preGenMesh = &PoissonEdgeMesh;
|
||||
pp.preGenFlag=true;
|
||||
sampleVec.clear();
|
||||
tri::SurfaceSampling<MyMesh,tri::TrivialSampler<MyMesh> >::PoissonDiskPruning(mps, MontecarloSurfaceMesh, rad, pp);
|
||||
tri::Build(PoissonMesh,sampleVec);
|
||||
tri::BuildMeshFromCoordVector(PoissonMesh,sampleVec);
|
||||
tri::io::ExporterOFF<MyMesh>::Save(PoissonMesh,"PoissonMesh.off");
|
||||
printf("Computed a feature aware poisson disk distribution of %i vertices radius is %6.3f\n",PoissonMesh.VN(),rad);
|
||||
|
||||
|
|
|
@ -73,7 +73,7 @@ int main(int ,char ** )
|
|||
std::vector<std::pair<int,MyMesh::FacePointer> > fpVec;
|
||||
tri::UpdateTopology<MyMesh>::FaceFace(tm);
|
||||
tri::Clean<MyMesh>::ConnectedComponents(tm,fpVec);
|
||||
printf("Mesh has %i texture components\n",fpVec.size());
|
||||
printf("Mesh has %lu texture components\n",fpVec.size());
|
||||
tri::io::ExporterPLY<MyMesh>::Save(tm,"out.ply");
|
||||
std::vector< std::vector<Point2f> > outline2Vec;
|
||||
|
||||
|
@ -99,13 +99,13 @@ int main(int ,char ** )
|
|||
outline2Vec.push_back(compOutline2Vec[largestInd]);
|
||||
}
|
||||
|
||||
printf("Mesh has %i texture components\n",outline2Vec.size());
|
||||
printf("Mesh has %lu texture components\n",outline2Vec.size());
|
||||
|
||||
Outline2Dumper::Param pp;
|
||||
Similarity2f sim;
|
||||
sim.sca=1024.0f;
|
||||
std::vector<Similarity2f> trVec(outline2Vec.size(),sim);
|
||||
printf("Mesh has %i texture components\n",outline2Vec.size());
|
||||
printf("Mesh has %lu texture components\n",outline2Vec.size());
|
||||
Outline2Dumper::dumpOutline2VecPNG("PrePack.png",outline2Vec,trVec,pp);
|
||||
|
||||
const Point2i containerSize(1024,1024);
|
||||
|
|
|
@ -39,7 +39,7 @@ struct MyUsedTypes : public UsedTypes< Use<MyVertex> ::AsVertexType,
|
|||
Use<MyFace> ::AsFaceType>{};
|
||||
|
||||
class MyVertex : public Vertex<MyUsedTypes, vertex::InfoOcf, vertex::Coord3f, vertex::Normal3f, vertex::TexCoord2f, vertex::VFAdj , vertex::Qualityf, vertex::Color4b, vertex::BitFlags >{};
|
||||
class MyFace : public Face< MyUsedTypes, face::InfoOcf, face::VertexRef, face::BitFlags, face::FFAdjOcf ,face::VFAdj , face::WedgeTexCoord2f> {};
|
||||
class MyFace : public Face< MyUsedTypes, face::InfoOcf, face::VertexRef, face::CurvatureDirf, face::BitFlags, face::FFAdjOcf ,face::VFAdj , face::WedgeTexCoord2f> {};
|
||||
class MyEdge : public Edge< MyUsedTypes>{};
|
||||
class MyMesh : public tri::TriMesh< vertex::vector_ocf<MyVertex>, face::vector_ocf<MyFace> , vector<MyEdge> > {};
|
||||
|
||||
|
|
|
@ -54,9 +54,9 @@ int main( int argc, char **argv )
|
|||
printf("Usage trimesh_voronoiclustering mesh region_num iterNum\n");
|
||||
return -1;
|
||||
}
|
||||
int seed = atoi(argv[2]);
|
||||
int seedNum = atoi(argv[2]);
|
||||
int iterNum = atoi(argv[3]);
|
||||
printf("Reading %s and sampling %i \n",argv[1],seed);
|
||||
printf("Reading %s and sampling %i \n",argv[1],seedNum);
|
||||
int ret= tri::io::ImporterPLY<MyMesh>::Open(baseMesh,argv[1]);
|
||||
if(ret!=0)
|
||||
{
|
||||
|
@ -66,15 +66,14 @@ int main( int argc, char **argv )
|
|||
|
||||
int randSeed=time(0);
|
||||
tri::UpdateTopology<MyMesh>::VertexFace(baseMesh);
|
||||
std::vector<MyVertex *> seedVec;
|
||||
tri::ClusteringSampler<MyMesh> cs(seedVec);
|
||||
tri::SurfaceSampling<MyMesh, vcg::tri::ClusteringSampler<MyMesh> >::SamplingRandomGenerator().initialize(randSeed);
|
||||
tri::SurfaceSampling<MyMesh, vcg::tri::ClusteringSampler<MyMesh> >::VertexUniform(baseMesh,cs,seed);
|
||||
tri::TrivialPointerSampler<MyMesh> cs;
|
||||
tri::SurfaceSampling<MyMesh, tri::TrivialPointerSampler<MyMesh> >::SamplingRandomGenerator().initialize(randSeed);
|
||||
tri::SurfaceSampling<MyMesh, tri::TrivialPointerSampler<MyMesh> >::VertexUniform(baseMesh,cs,seedNum);
|
||||
tri::VoronoiProcessingParameter vpp;
|
||||
tri::EuclideanDistance<MyMesh> df;
|
||||
tri::VoronoiProcessing<MyMesh>::VoronoiRelaxing(baseMesh, seedVec, iterNum, df, vpp);
|
||||
tri::VoronoiProcessing<MyMesh>::TopologicalVertexColoring(baseMesh, seedVec);
|
||||
tri::VoronoiProcessing<MyMesh>::ConvertDelaunayTriangulationToMesh(baseMesh,clusteredMesh,seedVec);
|
||||
tri::VoronoiProcessing<MyMesh>::VoronoiRelaxing(baseMesh, cs.sampleVec, iterNum, df, vpp);
|
||||
tri::VoronoiProcessing<MyMesh>::TopologicalVertexColoring(baseMesh, cs.sampleVec);
|
||||
tri::VoronoiProcessing<MyMesh>::ConvertDelaunayTriangulationToMesh(baseMesh,clusteredMesh,cs.sampleVec);
|
||||
|
||||
tri::io::ExporterPLY<MyMesh>::Save(baseMesh,"base.ply",tri::io::Mask::IOM_VERTCOLOR );
|
||||
tri::io::ExporterPLY<MyMesh>::Save(clusteredMesh,"clustered.ply");
|
||||
|
|
|
@ -70,7 +70,8 @@ int main( int argc, char **argv )
|
|||
int sampleNum = atoi(argv[2]);
|
||||
int iterNum = atoi(argv[3]);
|
||||
|
||||
bool fixCornerFlag=false;
|
||||
bool fixCornerFlag=true;
|
||||
bool uniformEdgeSamplingFlag = true;
|
||||
|
||||
printf("Reading %s and sampling %i points with %i iteration\n",argv[1],sampleNum,iterNum);
|
||||
int ret= tri::io::ImporterPLY<MyMesh>::Open(baseMesh,argv[1]);
|
||||
|
@ -91,21 +92,30 @@ int main( int argc, char **argv )
|
|||
tri::VoronoiProcessing<MyMesh>::PreprocessForVoronoi(baseMesh,radius,vpp);
|
||||
|
||||
tri::UpdateFlags<MyMesh>::FaceBorderFromVF(baseMesh);
|
||||
tri::UpdateFlags<MyMesh>::VertexBorderFromFace(baseMesh);
|
||||
tri::UpdateFlags<MyMesh>::VertexBorderFromFaceBorder(baseMesh);
|
||||
|
||||
|
||||
// -- Build a sampling with just corners (Poisson filtered)
|
||||
MyMesh poissonCornerMesh;
|
||||
std::vector<Point3f> sampleVec;
|
||||
tri::TrivialSampler<MyMesh> mps(sampleVec);
|
||||
if(fixCornerFlag)
|
||||
{
|
||||
tri::SurfaceSampling<MyMesh,tri::TrivialSampler<MyMesh> >::VertexBorderCorner(baseMesh,mps,math::ToRad(150.f));
|
||||
tri::Build(poissonCornerMesh,sampleVec);
|
||||
tri::BuildMeshFromCoordVector(poissonCornerMesh,sampleVec);
|
||||
tri::io::ExporterPLY<MyMesh>::Save(poissonCornerMesh,"cornerMesh.ply");
|
||||
sampleVec.clear();
|
||||
MyMesh borderMesh,poissonBorderMesh;
|
||||
|
||||
|
||||
if(uniformEdgeSamplingFlag)
|
||||
{
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
if(fixCornerFlag)
|
||||
{
|
||||
tri::SurfaceSampling<MyMesh,tri::TrivialSampler<MyMesh> >::PoissonDiskPruning(mps, poissonCornerMesh, radius, pp);
|
||||
tri::Build(poissonCornerMesh,sampleVec);
|
||||
tri::BuildMeshFromCoordVector(poissonCornerMesh,sampleVec);
|
||||
tri::io::ExporterPLY<MyMesh>::Save(poissonCornerMesh,"poissonCornerMesh.ply");
|
||||
// Now save the corner as Fixed Seeds for later...
|
||||
std::vector<MyVertex *> fixedSeedVec;
|
||||
|
@ -115,10 +125,9 @@ int main( int argc, char **argv )
|
|||
}
|
||||
|
||||
// -- Build a sampling with points on the border
|
||||
MyMesh borderMesh,poissonBorderMesh;
|
||||
sampleVec.clear();
|
||||
tri::SurfaceSampling<MyMesh,tri::TrivialSampler<MyMesh> >::VertexBorder(baseMesh,mps);
|
||||
tri::Build(borderMesh,sampleVec);
|
||||
tri::BuildMeshFromCoordVector(borderMesh,sampleVec);
|
||||
tri::io::ExporterPLY<MyMesh>::Save(borderMesh,"borderMesh.ply");
|
||||
|
||||
// -- and then prune the border sampling with poisson strategy using the precomputed corner vertexes.
|
||||
|
@ -126,14 +135,16 @@ int main( int argc, char **argv )
|
|||
pp.preGenFlag=true;
|
||||
sampleVec.clear();
|
||||
tri::SurfaceSampling<MyMesh,tri::TrivialSampler<MyMesh> >::PoissonDiskPruning(mps, borderMesh, radius*0.8f, pp);
|
||||
tri::Build(poissonBorderMesh,sampleVec);
|
||||
tri::BuildMeshFromCoordVector(poissonBorderMesh,sampleVec);
|
||||
}
|
||||
|
||||
tri::io::ExporterPLY<MyMesh>::Save(poissonBorderMesh,"PoissonEdgeMesh.ply");
|
||||
|
||||
// -- Build the montercarlo sampling of the surface
|
||||
MyMesh MontecarloSurfaceMesh;
|
||||
sampleVec.clear();
|
||||
tri::SurfaceSampling<MyMesh,tri::TrivialSampler<MyMesh> >::Montecarlo(baseMesh,mps,50000);
|
||||
tri::Build(MontecarloSurfaceMesh,sampleVec);
|
||||
tri::BuildMeshFromCoordVector(MontecarloSurfaceMesh,sampleVec);
|
||||
tri::io::ExporterPLY<MyMesh>::Save(MontecarloSurfaceMesh,"MontecarloSurfaceMesh.ply");
|
||||
|
||||
// -- Prune the montecarlo sampling with poisson strategy using the precomputed vertexes on the border.
|
||||
|
@ -141,7 +152,7 @@ int main( int argc, char **argv )
|
|||
sampleVec.clear();
|
||||
tri::SurfaceSampling<MyMesh,tri::TrivialSampler<MyMesh> >::PoissonDiskPruning(mps, MontecarloSurfaceMesh, radius, pp);
|
||||
MyMesh PoissonMesh;
|
||||
tri::Build(PoissonMesh,sampleVec);
|
||||
tri::BuildMeshFromCoordVector(PoissonMesh,sampleVec);
|
||||
tri::io::ExporterPLY<MyMesh>::Save(PoissonMesh,"PoissonMesh.ply");
|
||||
|
||||
std::vector<MyVertex *> seedVec;
|
||||
|
|
Loading…
Reference in New Issue