diff --git a/apps/sample/edgemesh_sampling/edgemesh_sampling.cpp b/apps/sample/edgemesh_sampling/edgemesh_sampling.cpp index 6a8bb037..5765c8a8 100644 --- a/apps/sample/edgemesh_sampling/edgemesh_sampling.cpp +++ b/apps/sample/edgemesh_sampling/edgemesh_sampling.cpp @@ -45,13 +45,11 @@ class MyEdge : public Edge, vector , vector > {}; - - int main( int argc, char **argv ) { if(argc<2) { - printf("Usage trimesh_base radius\n"); + printf("Usage edgemesh_sampling radius\n"); return -1; } @@ -90,7 +88,7 @@ int main( int argc, char **argv ) tri::TrivialSampler ps(sampleVec); tri::SurfaceSampling::EdgeMeshUniform(e,ps,m.bbox.Diag()/90.0f); MyMesh sampleMesh; - tri::Build(sampleMesh,sampleVec); + tri::BuildMeshFromCoordVector(sampleMesh,sampleVec); tri::io::ExporterPLY::Save(sampleMesh,"sampleMesh.ply"); return 0; } diff --git a/apps/sample/polygonmesh_base/polygonmesh.cpp b/apps/sample/polygonmesh_base/polygonmesh.cpp index 99191dc0..920b5280 100644 --- a/apps/sample/polygonmesh_base/polygonmesh.cpp +++ b/apps/sample/polygonmesh_base/polygonmesh.cpp @@ -28,17 +28,14 @@ #include #include -/*include the algorithms for mesh fixing */ #include +#include #include #include /* include the support for polygon meshes (function to convert from/to trimesh)*/ -#include - -/* include the support for polygon meshes (the component for the face )*/ -#include +//#include /* include the support for half edges */ #include @@ -48,179 +45,173 @@ 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::AsVertexType, vcg::Use::AsFaceType >{}; +struct TUsedTypes: public vcg::UsedTypes< vcg::Use::AsVertexType, vcg::Use::AsFaceType >{}; /* Definition of a mesh of triangles */ -class CVertex : public Vertex< CUsedTypes, - vertex::BitFlags, - vertex::Coord3f, - vertex::Normal3f, - vertex::Mark >{}; +class TVertex : public Vertex< TUsedTypes, + vertex::BitFlags, + vertex::Coord3f, + vertex::Normal3f, + vertex::Mark >{}; -class CFace : public Face< CUsedTypes, - face::VertexRef, // three pointers to vertices - face::Normal3f, // normal - face::BitFlags, // flags - face::FFAdj // three pointers to adjacent faces +class TFace : public Face< TUsedTypes, + face::VertexRef, // three pointers to vertices + face::Normal3f, // normal + face::BitFlags, // flags + face::FFAdj // three pointers to adjacent faces > {}; -/* the mesh is a container of vertices and a container of faces */ -class CMesh : public vcg::tri::TriMesh< vector, vector > {}; +/* the mesh is a container of vertices and a container of faces */ +class TMesh : public vcg::tri::TriMesh< vector, vector > {}; /* Definition of a mesh of polygons that also supports half-edges */ -class MyPolyFace; -class MyPolyVertex; -struct PolyUsedTypes: public vcg::UsedTypes ::AsVertexType, - vcg::Use ::AsEdgeType, - vcg::Use ::AsHEdgeType, - vcg::Use ::AsFaceType - >{}; +class PFace; +class PVertex; +class PHEdge; +class PEdge; + +struct PUsedTypes: public vcg::UsedTypes ::AsVertexType, + vcg::Use ::AsEdgeType, + vcg::Use::AsHEdgeType, + vcg::Use ::AsFaceType + >{}; //class DummyEdge: public vcg::Edge{}; -class MyPolyVertex:public vcg::Vertex< PolyUsedTypes, - vcg::vertex::Coord3f, - vcg::vertex::Normal3f, - vcg::vertex::Mark, - vcg::vertex::BitFlags, - vcg::vertex::VHAdj>{} ; +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{}; -class CHEdge : public HEdge< PolyUsedTypes, hedge::BitFlags, - //hedge::HFAdj, // pointer to the face - //hedge::HOppAdj, // pointer to the opposite edge - //hedge::HVAdj, // pointer to the vertex - //hedge::HNextAdj, // pointer to the next halfedge - hedge::HEdgeData // the previous 4 components (just more handy, you can comment this and uncomment the previous four lines) - //,hedge::HPrevAdj // pointer to the previous halfedge +class PEdge : public Edge{}; +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 + //hedge::HNextAdj, // pointer to the next halfedge + hedge::HEdgeData // the previous 4 components (just more handy, you can comment this and uncomment the previous four lines) + //,hedge::HPrevAdj // pointer to the previous halfedge >{}; -class MyPolyFace:public vcg::Face< - PolyUsedTypes - ,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") - ,vcg::face::PFVAdj // Pointer to the vertices (just like FVAdj ) - ,vcg::face::PFVAdj - ,vcg::face::PFFAdj // Pointer to edge-adjacent face (just like FFAdj ) - ,vcg::face::PFHAdj // Pointer its half -edges ( you may need this if you use half edges) - ,vcg::face::BitFlags // bit flags - ,vcg::face::Normal3f // normal +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") + ,vcg::face::PFVAdj // Pointer to the vertices (just like FVAdj ) + ,vcg::face::PFVAdj + ,vcg::face::PFFAdj // Pointer to edge-adjacent face (just like FFAdj ) + ,vcg::face::PFHAdj // Pointer its half -edges ( you may need this if you use half edges) + ,vcg::face::BitFlags // bit flags + ,vcg::face::Normal3f // normal > {}; -class MyPolyMesh: public - vcg::tri::TriMesh< - std::vector, // the vector of vertices - std::vector, // the vector of faces - std::vector , // the vector of edges - std::vector // the vector of edges - >{}; +class PMesh: public + vcg::tri::TriMesh< + std::vector, // the vector of vertices + std::vector, // the vector of faces + std::vector , // the vector of edges + std::vector // the vector of edges + >{}; -MyPolyMesh pm; +PMesh pm; +TMesh tm0; +int main(int argc, char *argv[]) { -//////////////////////////////////////////////////////////////////////////// -// Globals: the mesh, the OpenGL wrapper to draw the mesh and the trackball. -CMesh mesh,mesh1; + int loadmask; -int main(int argc, char *argv[]) { - - int loadmask; - - vcg::tri::io::PlyInfo pi; - -// pm.hedge.reserve(100000); if(true){ - /* - first way: - 1) read a polygon mesh that will be automatically converted in a triangle mesh tagging - the internal edges (i.e. the edges that have been added for triangulating the polygons) + /* + first way: + 1) read a polygon mesh that will be automatically converted in a triangle mesh tagging + the internal edges (i.e. the edges that have been added for triangulating the polygons) 2) make some cleaning - 3) import the tagged triangle mesh in a polygon mesh - */ + 3) import the tagged triangle mesh in a polygon mesh + */ // vcg::tri::io::ImporterOBJ::Open(mesh,argv[1],loadmask); - vcg::tri::io::ImporterOFF::Open(mesh,argv[1],loadmask); +// vcg::tri::io::ImporterOFF::Open(tm0,argv[1],loadmask); + vcg::tri::Hexahedron(tm0); + vcg::tri::Clean::RemoveUnreferencedVertex(tm0); + vcg::tri::Clean::RemoveZeroAreaFace(tm0); + vcg::tri::UpdateTopology::FaceFace(tm0); + vcg::tri::Clean::RemoveNonManifoldFace(tm0); + vcg::tri::UpdateTopology::FaceFace(tm0); + assert(vcg::tri::Clean::CountNonManifoldEdgeFF(tm0)==0); + assert(vcg::tri::Clean::CountNonManifoldVertexFF(tm0)==0); - vcg::tri::Clean::RemoveUnreferencedVertex(mesh); - vcg::tri::Clean::RemoveZeroAreaFace(mesh); - vcg::tri::UpdateTopology::FaceFace(mesh); - vcg::tri::Clean::RemoveNonManifoldFace(mesh); - vcg::tri::UpdateTopology::FaceFace(mesh); - assert(vcg::tri::Clean::CountNonManifoldEdgeFF(mesh)==0); - assert(vcg::tri::Clean::CountNonManifoldVertexFF(mesh)==0); - - // create a polygon meshe from a trimesh with tagged faces - vcg::tri::PolygonSupport::ImportFromTriMesh(pm,mesh); + // create a polygon meshe from a trimesh with tagged faces + vcg::tri::PolygonSupport::ImportFromTriMesh(pm,tm0); } else { - /* second way: - Load into a polygon mesh straight away. - */ - vcg::tri::io::ImporterOBJ::Open(pm,argv[1],loadmask); - vcg::tri::UpdateTopology::FaceFace(pm); - vcg::tri::Clean::RemoveNonManifoldFace(pm); - vcg::tri::UpdateTopology::FaceFace(pm); - assert(vcg::tri::Clean::CountNonManifoldEdgeFF(pm)); - + /* second way: + Load into a polygon mesh straight away. + */ + vcg::tri::io::ImporterOBJ::Open(pm,argv[1],loadmask); + vcg::tri::UpdateTopology::FaceFace(pm); + vcg::tri::Clean::RemoveNonManifoldFace(pm); + vcg::tri::UpdateTopology::FaceFace(pm); + assert(vcg::tri::Clean::CountNonManifoldEdgeFF(pm)); } - // compute the half edges because I'm a half-edge programmer - vcg::tri::UpdateHalfEdges::FromIndexed(pm); + // compute the half edges because I'm a half-edge programmer + vcg::tri::UpdateHalfEdges::FromIndexed(pm); - // .... my half edge based code ...... + // .... my half edge based code ...... - // check for consistency - assert(vcg::tri::UpdateHalfEdges::CheckConsistency(pm)); + // check for consistency + assert(vcg::tri::UpdateHalfEdges::CheckConsistency(pm)); - int size = pm.face.size(); + int size = pm.face.size(); - // add a face to each face with more than 3 vertices ( just one pass) - - 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(); - ef1 = ef1->HNp(); - vcg::tri::UpdateHalfEdges::AddHEdge(pm, ef, ef1 ); - } - assert(vcg::tri::UpdateHalfEdges::CheckConsistency(pm)); - size = pm.face.size(); + // add a face to each face with more than 3 vertices ( just one pass) - // remove an edge for each face - - for(int i = 0; i < size; ++i) - if(!(pm.face[i].IsD() )) - { - MyPolyMesh::HEdgePointer ef = pm.face[i].FHp(); - if( ef->HOp()->HFp() !=NULL){ - vcg::tri::UpdateHalfEdges::RemoveHEdge(pm,ef); - } - } + for(int i = 0; i < size; ++i) + if(!(pm.face[i].IsD())) + if(pm.face[i].VN()>3){ + PMesh::HEdgePointer ef = pm.face[i].FHp(); + PMesh::HEdgePointer ef1 = ef -> HNp(); + ef1 = ef1->HNp(); + vcg::tri::UpdateHalfEdges::AddHEdge(pm, ef, ef1 ); + } + assert(vcg::tri::UpdateHalfEdges::CheckConsistency(pm)); + size = pm.face.size(); - // check for consistency - assert(vcg::tri::UpdateHalfEdges::CheckConsistency(pm)); + // remove an edge for each face - // recompute indexed data structure from the half edge data structure - vcg::tri::UpdateIndexed::FromHalfEdges(pm ); - - // create a triangle mesh from a polygon mesh - vcg::tri::PolygonSupport::ImportFromPolyMesh(mesh1,pm); + for(int i = 0; i < size; ++i) + if(!(pm.face[i].IsD() )) + { + PMesh::HEdgePointer ef = pm.face[i].FHp(); + if( ef->HOp()->HFp() !=NULL){ + vcg::tri::UpdateHalfEdges::RemoveHEdge(pm,ef); + } + } - // write out the triangle mesh - vcg::tri::io::ExporterPLY::Save(mesh1,"converted_out.ply",true,pi); + // check for consistency + assert(vcg::tri::UpdateHalfEdges::CheckConsistency(pm)); + + // recompute indexed data structure from the half edge data structure +// vcg::tri::UpdateIndexed::FromHalfEdges(pm ); + + // create a triangle mesh from a polygon mesh + TMesh tm1; + vcg::tri::PolygonSupport::ImportFromPolyMesh(tm1,pm); + + vcg::tri::io::PlyInfo pi; + vcg::tri::io::ExporterPLY::Save(tm1,"converted_tri.ply",false,pi); + vcg::tri::io::ExporterPLY::Save(pm,"converted_poly.ply",false,pi); } diff --git a/apps/sample/trimesh_ball_pivoting/trimesh_ball_pivoting.cpp b/apps/sample/trimesh_ball_pivoting/trimesh_ball_pivoting.cpp index 4cc9d4e6..8505d431 100644 --- a/apps/sample/trimesh_ball_pivoting/trimesh_ball_pivoting.cpp +++ b/apps/sample/trimesh_ball_pivoting/trimesh_ball_pivoting.cpp @@ -39,7 +39,7 @@ class MyFace; class MyVertex; struct MyUsedTypes : public UsedTypes< Use ::AsVertexType, - Use ::AsFaceType>{}; + Use ::AsFaceType>{}; class MyVertex : public Vertex< MyUsedTypes, vertex::Coord3f, vertex::Normal3f, vertex::BitFlags, vertex::Mark>{}; class MyFace : public Face < MyUsedTypes, face::VertexRef, face::Normal3f, face::BitFlags > {}; @@ -53,51 +53,49 @@ bool callback(int percent, const char *str) { 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" + { + printf( "Usage: trimesh_ball_pivoting filein.ply fileout.ply [opt]\n" "options: \n" "-r radius of the rolling ball\n" "-c clustering radius (as fraction of radius) default: 0.05\n" - ); - exit(0); - } + ); + exit(0); + } float radius = 0.0f; float clustering = 0.05; int i = 3; - while(i::Open(m,argv[1])!=0) - { + default : {printf("Error unable to parse option '%s'\n",argv[i]); exit(0);} + } + ++i; + } + if(radius == 0) + printf("Autodetecting ball radius...\n"); + + MyMesh m; + + if(vcg::tri::io::ImporterPLY::Open(m,argv[1])!=0) + { printf("Error reading file %s\n",argv[1]); - exit(0); - } + exit(0); + } vcg::tri::UpdateBounding::Box(m); vcg::tri::UpdateNormal::PerFace(m); printf("Input mesh vn:%i fn:%i\n",m.VN(),m.FN()); int t0=clock(); // Initialization - tri::BallPivoting pivot(m, radius, clustering); + tri::BallPivoting pivot(m, radius, clustering); printf("Ball radius: %f\nClustering points withing %f radii\n", pivot.radius, clustering); int t1=clock(); @@ -108,7 +106,7 @@ int main(int argc, char **argv) printf("Output mesh vn:%i fn:%i\n",m.VN(),m.FN()); printf("Created in :%i msec (%i+%i)\n",t2-t0,t1-t0,t2-t1); - + vcg::tri::io::PlyInfo pi; vcg::tri::io::ExporterPLY::Save(m,argv[2],pi.mask); return 0; diff --git a/apps/sample/trimesh_copy/trimesh_copy.cpp b/apps/sample/trimesh_copy/trimesh_copy.cpp index e31572df..302f7861 100644 --- a/apps/sample/trimesh_copy/trimesh_copy.cpp +++ b/apps/sample/trimesh_copy/trimesh_copy.cpp @@ -26,9 +26,9 @@ class MyVertex : public vcg::Vertex< MyUsedTypes,vcg::vertex::VFAdj,vcg::vertex class MyEdge : public vcg::Edge< MyUsedTypes> {}; class MyFace : public vcg::Face< MyUsedTypes, - vcg::face::VFAdj, - vcg::face::VertexRef, - vcg::face::BitFlags > {}; + vcg::face::VFAdj, + vcg::face::VertexRef, + vcg::face::BitFlags > {}; // the main mesh class class MyMesh : public vcg::tri::TriMesh, std::vector > {}; @@ -39,8 +39,8 @@ class OcfFace; // Declaration of the semantic of the used types class OcfUsedTypes: public vcg::UsedTypes < vcg::Use::AsVertexType, - vcg::Use::AsEdgeType, - vcg::Use::AsFaceType >{}; + vcg::Use::AsEdgeType, + vcg::Use::AsFaceType >{}; // The Main Vertex Class @@ -61,26 +61,18 @@ class OcfEdge : public vcg::Edge // Each face needs 32 byte, on 32bit arch. and 48 byte on 64bit arch. class OcfFace : public vcg::Face< OcfUsedTypes,vcg::face::InfoOcf,vcg::face::VertexRef,vcg::face::BitFlags,vcg::face::VFAdjOcf> {}; -class OcfMesh : public vcg::tri::TriMesh< vcg::vertex::vector_ocf, vcg::face::vector_ocf > +class OcfMesh : public vcg::tri::TriMesh< vcg::vertex::vector_ocf, vcg::face::vector_ocf > { }; 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" - ); - exit(-1); + printf( + "\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" + ); + exit(-1); } template @@ -117,7 +109,7 @@ bool UnitTest_Append(const char *filename1, const char *filename2) int main(int /*argc*/ ,char**argv) { - UnitTest_Append(argv[1],"out.ply"); - UnitTest_Append(argv[1],"out.ply"); - return 0; + UnitTest_Append(argv[1],"out.ply"); + UnitTest_Append(argv[1],"out.ply"); + return 0; } diff --git a/apps/sample/trimesh_geodesic/trimesh_geodesic.cpp b/apps/sample/trimesh_geodesic/trimesh_geodesic.cpp index f62394f5..1b035780 100644 --- a/apps/sample/trimesh_geodesic/trimesh_geodesic.cpp +++ b/apps/sample/trimesh_geodesic/trimesh_geodesic.cpp @@ -22,9 +22,12 @@ ****************************************************************************/ #include -#include +#include +#include +#include #include +#include using namespace vcg; using namespace std; @@ -36,8 +39,8 @@ struct MyUsedTypes : public UsedTypes< Use ::AsVertexType, Use ::AsEdgeType, Use ::AsFaceType>{}; -class MyVertex : public Vertex{}; -class MyFace : public Face< MyUsedTypes, face::FFAdj, face::VertexRef, face::BitFlags > {}; +class MyVertex : public Vertex{}; +class MyFace : public Face< MyUsedTypes, face::VFAdj, face::VertexRef, face::Normal3f, face::BitFlags > {}; class MyEdge : public Edge{}; class MyMesh : public tri::TriMesh< vector, vector , vector > {}; @@ -45,20 +48,47 @@ int main( int argc, char **argv ) { if(argc<2) { - printf("Usage trimesh_base \n"); - return -1; + printf("Usage trimesh_geodesic \n"); +// return -1; } MyMesh m; - if(tri::io::ImporterOFF::Open(m,argv[1])!=0) +// if(tri::io::ImporterPLY::Open(m,"../../meshes/disk_irregular_1k.ply")!=0) + if(tri::io::ImporterPLY::Open(m,"../../meshes/disk_irregular_650k.ply")!=0) { printf("Error reading file %s\n",argv[1]); exit(0); } - vector pointVec; - float radius; - tri::PoissonSampling(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)P(),c); + closest = &*vi; + } + } + vector seedVec; + seedVec.push_back(closest); + tri::EuclideanDistance ed; + tri::Clean::RemoveUnreferencedVertex(m); + tri::Allocator::CompactEveryVector(m); + tri::UpdateTopology::VertexFace(m); + tri::Geodesic::Compute(m,seedVec,ed); + pair minmax = tri::Stat::ComputePerVertexQualityMinMax(m); + tri::UpdateColor::PerVertexQualityRamp(m); + printf("min %f max %f\n",minmax.first,minmax.second); + tri::io::ExporterPLY::Save(m,"base.ply",tri::io::Mask::IOM_VERTCOLOR | tri::io::Mask::IOM_VERTQUALITY); + int t0=clock(); + tri::Geodesic::PerVertexDijsktraCompute(m,seedVec,ed); + int t1=clock(); + printf("Geodesic dijkstra %6.3f\n",float(t1-t0)/CLOCKS_PER_SEC); + tri::UpdateColor::PerVertexQualityRamp(m); + tri::io::ExporterPLY::Save(m,"base_d.ply",tri::io::Mask::IOM_VERTCOLOR | tri::io::Mask::IOM_VERTQUALITY); return 0; } diff --git a/apps/sample/trimesh_geodesic/trimesh_geodesic.pro b/apps/sample/trimesh_geodesic/trimesh_geodesic.pro index 31d41730..2bce06e6 100644 --- a/apps/sample/trimesh_geodesic/trimesh_geodesic.pro +++ b/apps/sample/trimesh_geodesic/trimesh_geodesic.pro @@ -1,3 +1,3 @@ include(../common.pri) TARGET = trimesh_geodesic -SOURCES += trimesh_geodesic.cpp +SOURCES += trimesh_geodesic.cpp ../../../wrap/ply/plylib.cpp diff --git a/apps/sample/trimesh_hole/trimesh_hole.cpp b/apps/sample/trimesh_hole/trimesh_hole.cpp index 0a84f08a..93886b44 100644 --- a/apps/sample/trimesh_hole/trimesh_hole.cpp +++ b/apps/sample/trimesh_hole/trimesh_hole.cpp @@ -73,13 +73,13 @@ bool NormalTest(typename face::Pos pos) { //giro intorno al vertice e controllo le normali typename MESH::ScalarType thr = 0.0f; - typename MESH::CoordType NdP = vcg::Normal(*pos.f); + typename MESH::CoordType NdP = vcg::TriangleNormal(*pos.f); typename MESH::CoordType tmp, oop, soglia = typename MESH::CoordType(thr,thr,thr); face::Pos aux=pos; do{ aux.FlipF(); aux.FlipE(); - oop = Abs(tmp - ::vcg::Normal(*pos.f)); + oop = Abs(tmp - ::vcg::TriangleNormal(*pos.f)); if(oop < soglia )return false; }while(aux != pos && !aux.IsBorder()); @@ -91,7 +91,7 @@ int main(int argc,char ** argv){ if(argc<5) { printf( - "\n HoleFilling ("__DATE__")\n" + "\n HoleFilling (" __DATE__ ")\n" "Visual Computing Group I.S.T.I. C.N.R.\n" "Usage: trimesh_hole #algorithm #size filein.ply fileout.ply \n" "#algorithm: \n" diff --git a/apps/sample/trimesh_join/trimesh_join.cpp b/apps/sample/trimesh_join/trimesh_join.cpp index 8ebe3fbe..99509559 100644 --- a/apps/sample/trimesh_join/trimesh_join.cpp +++ b/apps/sample/trimesh_join/trimesh_join.cpp @@ -40,7 +40,7 @@ class MyFace; class MyVertex; struct MyUsedTypes : public UsedTypes< Use ::AsVertexType, - Use ::AsFaceType>{}; + Use ::AsFaceType>{}; class MyVertex : public Vertex {}; class MyFace : public Face < MyUsedTypes, face::VertexRef, face::BitFlags > {}; @@ -51,31 +51,29 @@ class MyMesh : public vcg::tri::TriMesh< vector, vector > { 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" " -t Just scan all the input files computing the total bbox\n" - ); - exit(0); - } + ); + exit(0); + } MyMesh ml,mr; Box3f ClipBB,TotBB; bool ClipFlag=false,MergeFlag=true; - int i=1; + int i=1; // Parsing option loop while(argv[i][0]=='-') { switch(argv[i][1]) { - case 'b': { + case 'b': { if(argc::Open(mr,argv[i])!=0) - { + while(i::Open(mr,argv[i])!=0) + { printf("Error reading file %s\n",argv[1]); - exit(0); - } + exit(0); + } printf("Input mesh %3i vn:%9i fn:%9i\n",i, mr.VN(), mr.FN()); - if(ClipFlag) - { + if(ClipFlag) + { tri::GenericVertexInterpolator interp(mr); tri::TriMeshClipper::Box(ClipBB,interp,mr); printf(" clipped to vn:%9i fn:%9i\n", mr.VN(), mr.FN()); } tri::UpdateBounding::Box(mr); TotBB.Add(mr.bbox); - + if(MergeFlag) tri::Append::Mesh(ml,mr); // append mesh mr to ml - ++i; - } - + ++i; + } + printf("Output mesh vn:%i fn:%i\n",ml.VN(),ml.FN()); - + tri::io::ExporterPLY::Save(ml,"joined.ply"); - int dv=tri::Clean::RemoveDuplicateVertex(ml); + int dv=tri::Clean::RemoveDuplicateVertex(ml); printf("Removed %i duplicated vertices\n",dv); tri::io::ExporterPLY::Save(ml,"joined_unif.ply"); printf("Final BBox of mesh :\n (%7.4f %7.4f %7.4f) - (%7.4f %7.4f %7.4f)\n", TotBB.min[0],TotBB.min[1],TotBB.min[2], TotBB.max[0],TotBB.max[1],TotBB.max[2]); - + } diff --git a/apps/sample/trimesh_kdtree/trimesh_kdtree.cpp b/apps/sample/trimesh_kdtree/trimesh_kdtree.cpp index 1be2ed23..f034260d 100644 --- a/apps/sample/trimesh_kdtree/trimesh_kdtree.cpp +++ b/apps/sample/trimesh_kdtree/trimesh_kdtree.cpp @@ -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 @@ -69,13 +69,13 @@ int main( int argc, char **argv ) KdTree tree(ww); KdTree::PriorityQueue queue; - + for (int j = 0; j < m.VN(); j++) { tree.doQueryK(m.vert[j].cP(), 3, queue); - int neighbours = queue.getNofElements(); + int neighbours = queue.getNofElements(); float avgDist=0; for (int i = 0; i < neighbours; i++) { - int neightId = queue.getIndex(i); + int neightId = queue.getIndex(i); avgDist += Distance(m.vert[j].cP(),m.vert[neightId].cP()); } m.vert[j].Q() = avgDist/=neighbours; diff --git a/apps/sample/trimesh_refine/trimesh_refine.cpp b/apps/sample/trimesh_refine/trimesh_refine.cpp index 0bd80836..348b180d 100644 --- a/apps/sample/trimesh_refine/trimesh_refine.cpp +++ b/apps/sample/trimesh_refine/trimesh_refine.cpp @@ -40,7 +40,7 @@ int main(int argc, char **argv) if(argc<4) { printf( - "\n PlyRefine ("__DATE__")\n" + "\n PlyRefine (" __DATE__ ")\n" " Visual Computing Group I.S.T.I. C.N.R.\n" "Usage: PlyRefine filein.ply fileout.[ply|off|obj|...] ref_step [opt] \n" "Commands: \n" diff --git a/apps/sample/trimesh_sampling/trimesh_sampling.cpp b/apps/sample/trimesh_sampling/trimesh_sampling.cpp index 679762b2..0bd4c820 100644 --- a/apps/sample/trimesh_sampling/trimesh_sampling.cpp +++ b/apps/sample/trimesh_sampling/trimesh_sampling.cpp @@ -61,17 +61,18 @@ int main( int argc, char **argv ) tri::SurfaceSampling >::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 pointVec; - float rad; + float rad=0; if(argc>2) rad=atof(argv[2]); int sampleNum=rad?0:1000; tri::PoissonSampling(m,pointVec,sampleNum,rad); int t1=clock(); MyMesh BasicPoissonMesh; - tri::Build(BasicPoissonMesh,pointVec); + tri::BuildMeshFromCoordVector(BasicPoissonMesh,pointVec); tri::io::ExporterOFF::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::PerFace(m); tri::UpdateFlags::FaceFauxCrease(m,math::ToRad(40.0f)); tri::SurfaceSampling >::EdgeMontecarlo(m,mps,10000,false); - tri::Build(MontecarloEdgeMesh,sampleVec); + tri::BuildMeshFromCoordVector(MontecarloEdgeMesh,sampleVec); tri::io::ExporterOFF::Save(MontecarloEdgeMesh,"MontecarloEdgeMesh.off"); sampleVec.clear(); tri::SurfaceSampling >::VertexCrease(m, mps); - tri::Build(PoissonEdgeMesh,sampleVec); - tri::io::ExporterOFF::Save(PoissonEdgeMesh,"CreaseMesh.off"); + tri::BuildMeshFromCoordVector(PoissonEdgeMesh,sampleVec); + tri::io::ExporterOFF::Save(PoissonEdgeMesh,"VertexCreaseMesh.off"); tri::SurfaceSampling >::PoissonDiskParam pp; pp.preGenMesh = &PoissonEdgeMesh; pp.preGenFlag=true; sampleVec.clear(); tri::SurfaceSampling >::PoissonDiskPruning(mps, MontecarloEdgeMesh, rad, pp); - tri::Build(PoissonEdgeMesh,sampleVec); + tri::BuildMeshFromCoordVector(PoissonEdgeMesh,sampleVec); tri::io::ExporterOFF::Save(PoissonEdgeMesh,"PoissonEdgeMesh.off"); sampleVec.clear(); tri::SurfaceSampling >::Montecarlo(m,mps,50000); - tri::Build(MontecarloSurfaceMesh,sampleVec); + tri::BuildMeshFromCoordVector(MontecarloSurfaceMesh,sampleVec); tri::io::ExporterOFF::Save(MontecarloSurfaceMesh,"MontecarloSurfaceMesh.off"); pp.preGenMesh = &PoissonEdgeMesh; pp.preGenFlag=true; sampleVec.clear(); tri::SurfaceSampling >::PoissonDiskPruning(mps, MontecarloSurfaceMesh, rad, pp); - tri::Build(PoissonMesh,sampleVec); + tri::BuildMeshFromCoordVector(PoissonMesh,sampleVec); tri::io::ExporterOFF::Save(PoissonMesh,"PoissonMesh.off"); printf("Computed a feature aware poisson disk distribution of %i vertices radius is %6.3f\n",PoissonMesh.VN(),rad); diff --git a/apps/sample/trimesh_texture/trimesh_texture.cpp b/apps/sample/trimesh_texture/trimesh_texture.cpp index 3a6b2df6..64971049 100644 --- a/apps/sample/trimesh_texture/trimesh_texture.cpp +++ b/apps/sample/trimesh_texture/trimesh_texture.cpp @@ -73,7 +73,7 @@ int main(int ,char ** ) std::vector > fpVec; tri::UpdateTopology::FaceFace(tm); tri::Clean::ConnectedComponents(tm,fpVec); - printf("Mesh has %i texture components\n",fpVec.size()); + printf("Mesh has %lu texture components\n",fpVec.size()); tri::io::ExporterPLY::Save(tm,"out.ply"); std::vector< std::vector > 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 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); diff --git a/apps/sample/trimesh_voronoiatlas/trimesh_voronoiatlas.cpp b/apps/sample/trimesh_voronoiatlas/trimesh_voronoiatlas.cpp index d9387167..442d4818 100644 --- a/apps/sample/trimesh_voronoiatlas/trimesh_voronoiatlas.cpp +++ b/apps/sample/trimesh_voronoiatlas/trimesh_voronoiatlas.cpp @@ -39,7 +39,7 @@ struct MyUsedTypes : public UsedTypes< Use ::AsVertexType, Use ::AsFaceType>{}; class MyVertex : public Vertex{}; -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, face::vector_ocf , vector > {}; diff --git a/apps/sample/trimesh_voronoiclustering/trimesh_voronoiclustering.cpp b/apps/sample/trimesh_voronoiclustering/trimesh_voronoiclustering.cpp index fc967c9a..5da04638 100644 --- a/apps/sample/trimesh_voronoiclustering/trimesh_voronoiclustering.cpp +++ b/apps/sample/trimesh_voronoiclustering/trimesh_voronoiclustering.cpp @@ -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::Open(baseMesh,argv[1]); if(ret!=0) { @@ -66,15 +66,14 @@ int main( int argc, char **argv ) int randSeed=time(0); tri::UpdateTopology::VertexFace(baseMesh); - std::vector seedVec; - tri::ClusteringSampler cs(seedVec); - tri::SurfaceSampling >::SamplingRandomGenerator().initialize(randSeed); - tri::SurfaceSampling >::VertexUniform(baseMesh,cs,seed); + tri::TrivialPointerSampler cs; + tri::SurfaceSampling >::SamplingRandomGenerator().initialize(randSeed); + tri::SurfaceSampling >::VertexUniform(baseMesh,cs,seedNum); tri::VoronoiProcessingParameter vpp; tri::EuclideanDistance df; - tri::VoronoiProcessing::VoronoiRelaxing(baseMesh, seedVec, iterNum, df, vpp); - tri::VoronoiProcessing::TopologicalVertexColoring(baseMesh, seedVec); - tri::VoronoiProcessing::ConvertDelaunayTriangulationToMesh(baseMesh,clusteredMesh,seedVec); + tri::VoronoiProcessing::VoronoiRelaxing(baseMesh, cs.sampleVec, iterNum, df, vpp); + tri::VoronoiProcessing::TopologicalVertexColoring(baseMesh, cs.sampleVec); + tri::VoronoiProcessing::ConvertDelaunayTriangulationToMesh(baseMesh,clusteredMesh,cs.sampleVec); tri::io::ExporterPLY::Save(baseMesh,"base.ply",tri::io::Mask::IOM_VERTCOLOR ); tri::io::ExporterPLY::Save(clusteredMesh,"clustered.ply"); diff --git a/apps/sample/trimesh_voronoisampling/trimesh_voronoisampling.cpp b/apps/sample/trimesh_voronoisampling/trimesh_voronoisampling.cpp index 99334734..42a819a5 100644 --- a/apps/sample/trimesh_voronoisampling/trimesh_voronoisampling.cpp +++ b/apps/sample/trimesh_voronoisampling/trimesh_voronoisampling.cpp @@ -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::Open(baseMesh,argv[1]); @@ -91,34 +92,42 @@ int main( int argc, char **argv ) tri::VoronoiProcessing::PreprocessForVoronoi(baseMesh,radius,vpp); tri::UpdateFlags::FaceBorderFromVF(baseMesh); - tri::UpdateFlags::VertexBorderFromFace(baseMesh); + tri::UpdateFlags::VertexBorderFromFaceBorder(baseMesh); // -- Build a sampling with just corners (Poisson filtered) MyMesh poissonCornerMesh; std::vector sampleVec; tri::TrivialSampler mps(sampleVec); - if(fixCornerFlag) + tri::SurfaceSampling >::VertexBorderCorner(baseMesh,mps,math::ToRad(150.f)); + tri::BuildMeshFromCoordVector(poissonCornerMesh,sampleVec); + tri::io::ExporterPLY::Save(poissonCornerMesh,"cornerMesh.ply"); + sampleVec.clear(); + MyMesh borderMesh,poissonBorderMesh; + + + if(uniformEdgeSamplingFlag) { - tri::SurfaceSampling >::VertexBorderCorner(baseMesh,mps,math::ToRad(150.f)); - tri::Build(poissonCornerMesh,sampleVec); - tri::io::ExporterPLY::Save(poissonCornerMesh,"cornerMesh.ply"); - sampleVec.clear(); - tri::SurfaceSampling >::PoissonDiskPruning(mps, poissonCornerMesh, radius, pp); - tri::Build(poissonCornerMesh,sampleVec); - tri::io::ExporterPLY::Save(poissonCornerMesh,"poissonCornerMesh.ply"); - // Now save the corner as Fixed Seeds for later... - std::vector fixedSeedVec; - tri::VoronoiProcessing::SeedToVertexConversion(baseMesh,sampleVec,fixedSeedVec); - tri::VoronoiProcessing >::FixVertexVector(baseMesh,fixedSeedVec); - vpp.preserveFixedSeed=true; + } + else + { + if(fixCornerFlag) + { + tri::SurfaceSampling >::PoissonDiskPruning(mps, poissonCornerMesh, radius, pp); + tri::BuildMeshFromCoordVector(poissonCornerMesh,sampleVec); + tri::io::ExporterPLY::Save(poissonCornerMesh,"poissonCornerMesh.ply"); + // Now save the corner as Fixed Seeds for later... + std::vector fixedSeedVec; + tri::VoronoiProcessing::SeedToVertexConversion(baseMesh,sampleVec,fixedSeedVec); + tri::VoronoiProcessing >::FixVertexVector(baseMesh,fixedSeedVec); + vpp.preserveFixedSeed=true; + } // -- Build a sampling with points on the border - MyMesh borderMesh,poissonBorderMesh; sampleVec.clear(); tri::SurfaceSampling >::VertexBorder(baseMesh,mps); - tri::Build(borderMesh,sampleVec); + tri::BuildMeshFromCoordVector(borderMesh,sampleVec); tri::io::ExporterPLY::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 >::PoissonDiskPruning(mps, borderMesh, radius*0.8f, pp); - tri::Build(poissonBorderMesh,sampleVec); + tri::BuildMeshFromCoordVector(poissonBorderMesh,sampleVec); + } + tri::io::ExporterPLY::Save(poissonBorderMesh,"PoissonEdgeMesh.ply"); // -- Build the montercarlo sampling of the surface MyMesh MontecarloSurfaceMesh; sampleVec.clear(); tri::SurfaceSampling >::Montecarlo(baseMesh,mps,50000); - tri::Build(MontecarloSurfaceMesh,sampleVec); + tri::BuildMeshFromCoordVector(MontecarloSurfaceMesh,sampleVec); tri::io::ExporterPLY::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 >::PoissonDiskPruning(mps, MontecarloSurfaceMesh, radius, pp); MyMesh PoissonMesh; - tri::Build(PoissonMesh,sampleVec); + tri::BuildMeshFromCoordVector(PoissonMesh,sampleVec); tri::io::ExporterPLY::Save(PoissonMesh,"PoissonMesh.ply"); std::vector seedVec;