diff --git a/apps/sample/common.pri b/apps/sample/common.pri index 1dfbea12..85c604b2 100644 --- a/apps/sample/common.pri +++ b/apps/sample/common.pri @@ -1,4 +1,4 @@ -DEPENDPATH += . +DEPENDPATH += . ../../.. INCLUDEPATH += . ../../.. CONFIG += console stl TEMPLATE = app diff --git a/apps/sample/sample.pro b/apps/sample/sample.pro index aa4802fd..b2bfe77e 100644 --- a/apps/sample/sample.pro +++ b/apps/sample/sample.pro @@ -1,22 +1,26 @@ TEMPLATE = subdirs SUBDIRS = trimesh_base \ - trimesh_topology \ - trimesh_smooth \ + trimesh_attribute \ + trimesh_ball_pivoting \ + trimesh_closest \ + trimesh_copy \ trimesh_curvature \ - trimesh_normal \ - trimesh_inertia \ - trimesh_refine \ trimesh_clustering \ + trimesh_edge \ + trimesh_ext_mc \ + trimesh_hole \ + trimesh_inertia \ + trimesh_intersection \ trimesh_isosurface \ trimesh_join \ - trimesh_edge \ + trimesh_normal \ trimesh_optional \ - trimesh_intersection \ - trimesh_ball_pivoting \ - trimesh_hole \ + trimesh_ray \ + trimesh_refine \ trimesh_sampling \ + trimesh_smooth \ + trimesh_topology \ polygonmesh_base \ - aabb_binary_tree \ - trimesh_attribute + aabb_binary_tree diff --git a/apps/sample/trimesh_attribute/trimesh_attribute.cpp b/apps/sample/trimesh_attribute/trimesh_attribute.cpp index 9a8b44cf..2a57a186 100644 --- a/apps/sample/trimesh_attribute/trimesh_attribute.cpp +++ b/apps/sample/trimesh_attribute/trimesh_attribute.cpp @@ -34,11 +34,11 @@ Attributes are a simple mechanism to associate user-defined 'attributes' to the class MyEdge; class MyFace; class MyVertex; -struct MyUsedTypes : public UsedTypes< Use ::AsVertexType, - Use ::AsFaceType>{}; +struct MyUsedTypes : public vcg::UsedTypes< vcg::Use ::AsVertexType, + vcg::Use ::AsFaceType>{}; -class MyVertex : public Vertex< MyUsedTypes, vertex::Coord3f,vertex::Normal3f>{}; -class MyFace : public Face< MyUsedTypes, face::VertexRef, face::Normal3f> {}; +class MyVertex : public vcg::Vertex< MyUsedTypes, vcg::vertex::Coord3f,vcg::vertex::Normal3f>{}; +class MyFace : public vcg::Face< MyUsedTypes, vcg::face::VertexRef, vcg::face::Normal3f> {}; class MyMesh : public vcg::tri::TriMesh< std::vector, std::vector > {}; diff --git a/apps/sample/trimesh_base/trimesh_base.cpp b/apps/sample/trimesh_base/trimesh_base.cpp index a4028c3c..64445467 100644 --- a/apps/sample/trimesh_base/trimesh_base.cpp +++ b/apps/sample/trimesh_base/trimesh_base.cpp @@ -44,13 +44,13 @@ This file contain a minimal example of the library class MyEdge; class MyFace; class MyVertex; -struct MyUsedTypes : public UsedTypes< Use ::AsVertexType, - Use ::AsEdgeType, - Use ::AsFaceType>{}; +struct MyUsedTypes : public vcg::UsedTypes< vcg::Use ::AsVertexType, + vcg::Use ::AsEdgeType, + vcg::Use ::AsFaceType>{}; -class MyVertex : public Vertex{}; -class MyFace : public Face< MyUsedTypes, face::FFAdj, face::VertexRef, face::BitFlags > {}; -class MyEdge : public Edge{}; +class MyVertex : public vcg::Vertex{}; +class MyFace : public vcg::Face< MyUsedTypes, vcg::face::FFAdj, vcg::face::VertexRef, vcg::face::BitFlags > {}; +class MyEdge : public vcg::Edge{}; class MyMesh : public vcg::tri::TriMesh< std::vector, std::vector , std::vector > {}; int main( int argc, char **argv ) @@ -63,7 +63,7 @@ int main( int argc, char **argv ) MyMesh m; - if(tri::io::ImporterOFF::Open(m,argv[1])!=tri::io::ImporterOFF::NoError) + if(vcg::tri::io::ImporterOFF::Open(m,argv[1])!=vcg::tri::io::ImporterOFF::NoError) { printf("Error reading file %s\n",argv[1]); exit(0); diff --git a/apps/sample/trimesh_clustering/trimesh_clustering.cpp b/apps/sample/trimesh_clustering/trimesh_clustering.cpp index 5efd61da..db46a01a 100644 --- a/apps/sample/trimesh_clustering/trimesh_clustering.cpp +++ b/apps/sample/trimesh_clustering/trimesh_clustering.cpp @@ -20,6 +20,12 @@ * for more details. * * * ****************************************************************************/ +/*! \file trimesh_clustering.cpp +\ingroup code_sample + +\brief a minimal example of a clustering based simplification + +*/ #include #include @@ -29,61 +35,59 @@ #include // input output -#include -#include +#include +#include class MyFace; class MyVertex; -struct MyUsedTypes : public UsedTypes< Use::AsVertexType, Use::AsFaceType>{}; +struct MyUsedTypes : public vcg::UsedTypes< vcg::Use::AsVertexType, vcg::Use::AsFaceType>{}; -class MyVertex : public Vertex< MyUsedTypes, vertex::Coord3f, vertex::Normal3f, vertex::BitFlags >{}; -class MyFace : public Face < MyUsedTypes, face::VertexRef, face::Normal3f, face::BitFlags > {}; +class MyVertex : public vcg::Vertex< MyUsedTypes, vcg::vertex::Coord3f, vcg::vertex::Normal3f, vcg::vertex::BitFlags >{}; +class MyFace : public vcg::Face < MyUsedTypes, vcg::face::VertexRef, vcg::face::Normal3f, vcg::face::BitFlags > {}; class MyMesh : public vcg::tri::TriMesh< std::vector, std::vector > {}; int main(int argc, char **argv) { - if(argc<3) - { - printf( - "\n trimesh_clustering ("__DATE__")\n" - " Visual Computing Group I.S.T.I. C.N.R.\n" - "Usage: PlyRefine filein.ply fileout.ply [opt] \n" - "options: \n" - "-k cellnum approx number of cluster that should be defined; (default 10e5)\n" - "-s size in absolute units the size of the clustering cell (override the previous param)\n" - "-d enable the duplication of faces for double surfaces\n" - ); - exit(0); - } + if(argc<3) + { + printf( + "Usage: trimesh_clustering filein.ply fileout.ply [opt] \n" + "options: \n" + "-k cellnum approx number of cluster that should be defined; (default 10e5)\n" + "-s size in absolute units the size of the clustering cell (override the previous param)\n" + "-d enable the duplication of faces for double surfaces\n" + ); + exit(0); + } - int i=3; - int CellNum=100000; - float CellSize=0; + int CellNum=100000; + float CellSize=0; bool DupFace=false; - while(i::Open(m,argv[1])!=0) + { + printf("Error reading file %s\n",argv[1]); + exit(0); + } - if(vcg::tri::io::ImporterPLY::Open(m,argv[1])!=0) - { - printf("Error reading file %s\n",argv[1]); - exit(0); - } vcg::tri::UpdateBounding::Box(m); vcg::tri::UpdateNormal::PerFace(m); printf("Input mesh vn:%i fn:%i\n",m.VN(),m.FN()); @@ -95,15 +99,10 @@ int main(int argc, char **argv) printf("Grid of %i x %i x %i cells\n",Grid.Grid.siz[0],Grid.Grid.siz[1],Grid.Grid.siz[2]); printf("with cells size of %.2f x %.2f x %.2f units\n",Grid.Grid.voxel[0],Grid.Grid.voxel[1],Grid.Grid.voxel[2]); - int t0=clock(); Grid.AddMesh(m); - int t1=clock(); Grid.ExtractMesh(m); - int t2=clock(); printf("Output mesh vn:%i fn:%i\n",m.VN(),m.FN()); - printf("Simplified 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; - } + + vcg::tri::io::ExporterPLY::Save(m,argv[2]); + return 0; +} diff --git a/apps/sample/trimesh_curvature/trimesh_curvature.cpp b/apps/sample/trimesh_curvature/trimesh_curvature.cpp index e824c810..6d47b56d 100644 --- a/apps/sample/trimesh_curvature/trimesh_curvature.cpp +++ b/apps/sample/trimesh_curvature/trimesh_curvature.cpp @@ -20,6 +20,14 @@ * for more details. * * * ****************************************************************************/ +/*! \file trimesh_curvature.cpp +\ingroup code_sample + +\brief an example showing the various techniques for computing curvatures + +This file contain a minimal example of the library + +*/ #include #include @@ -31,13 +39,13 @@ class MyEdge; class MyFace; class MyVertex; -struct MyUsedTypes : public UsedTypes< Use ::AsVertexType, - Use ::AsEdgeType, - Use ::AsFaceType>{}; +struct MyUsedTypes : public vcg::UsedTypes< vcg::Use ::AsVertexType, + vcg::Use ::AsEdgeType, + vcg::Use ::AsFaceType>{}; -class MyVertex : public Vertex{}; -class MyFace : public Face< MyUsedTypes, face::FFAdj, face::VertexRef, face::BitFlags > {}; -class MyEdge : public Edge{}; +class MyVertex : public vcg::Vertex{}; +class MyFace : public vcg::Face< MyUsedTypes, vcg::face::FFAdj, vcg::face::VertexRef, vcg::face::BitFlags > {}; +class MyEdge : public vcg::Edge{}; class MyMesh : public vcg::tri::TriMesh< std::vector, std::vector , std::vector > {}; int main( int argc, char **argv ) diff --git a/apps/sample/trimesh_inertia/trimesh_inertia.cpp b/apps/sample/trimesh_inertia/trimesh_inertia.cpp index d1527a54..aa48787a 100644 --- a/apps/sample/trimesh_inertia/trimesh_inertia.cpp +++ b/apps/sample/trimesh_inertia/trimesh_inertia.cpp @@ -20,6 +20,16 @@ * for more details. * * * ****************************************************************************/ +/*! \file trimesh_inertia.cpp +\ingroup code_sample + +\brief An example of computing the inertia properties of meshes + +Two meshes are created a rectangular box and a torus and their mass properties are computed and shown. +The result should match the closed formula for these objects (with a reasonable approximation) + +*/ + #include #include @@ -27,49 +37,86 @@ #include #include -using namespace vcg; -using namespace std; - class MyEdge; class MyFace; class MyVertex; -struct MyUsedTypes : public UsedTypes< Use ::AsVertexType, - Use ::AsEdgeType, - Use ::AsFaceType>{}; +struct MyUsedTypes : public vcg::UsedTypes< vcg::Use ::AsVertexType, + vcg::Use ::AsEdgeType, + vcg::Use ::AsFaceType>{}; -class MyVertex : public Vertex{}; -class MyFace : public Face< MyUsedTypes, face::FFAdj, face::Normal3f, face::VertexRef, face::BitFlags > {}; -class MyEdge : public Edge{}; -class MyMesh : public tri::TriMesh< vector, vector , vector > {}; +class MyVertex : public vcg::Vertex{}; +class MyFace : public vcg::Face< MyUsedTypes, vcg::face::FFAdj, vcg::face::Normal3f, vcg::face::VertexRef, vcg::face::BitFlags > {}; +class MyEdge : public vcg::Edge{}; +class MyMesh : public vcg::tri::TriMesh< std::vector, std::vector , std::vector > {}; int main( int argc, char **argv ) { - MyMesh tet,oct,hex,dod,ico; + MyMesh boxMesh,torusMesh; + vcg::Matrix33f IT; + vcg::Point3f ITv; - tri::Hexahedron(hex); - tri::Tetrahedron(tet); - tri::Octahedron(oct); - tri::Dodecahedron(dod); - tri::Icosahedron(ico); - Matrix44f ScaleM,TransM; - ScaleM.SetScale(1,2,1); - TransM.SetTranslate(1,1,1); -// tri::UpdatePosition::Matrix(hex,ScaleM); - tri::UpdatePosition::Matrix(hex,TransM); + vcg::tri::Hexahedron(boxMesh); + vcg::Matrix44f ScaleM,TransM; + ScaleM.SetScale(1.0f, 2.0f, 5.0f); + TransM.SetTranslate(2.0f,3.0f,4.0f); + vcg::tri::UpdatePosition::Matrix(boxMesh,ScaleM); + vcg::tri::UpdatePosition::Matrix(boxMesh,TransM); + vcg::tri::Inertia Ib(boxMesh); + vcg::Point3f cc = Ib.CenterOfMass(); + Ib.InertiaTensorEigen(IT,ITv); - tri::Inertia I; - I.Compute(hex); - Point3f cc = I.CenterOfMass(); - printf("Mass %f \n",I.Mass()); + printf("Box of size 2,4,10, centered in (2,3,4)\n"); + printf("Volume %f \n",Ib.Mass()); printf("CenterOfMass %f %f %f\n",cc[0],cc[1],cc[2]); - Matrix33f IT; - Point3f ITv; - I.InertiaTensorEigen(IT,ITv); - printf("InertiaTensor %f %f %f\n\n",ITv[0],ITv[1],ITv[2]); + printf("InertiaTensor Values %6.3f %6.3f %6.3f\n",ITv[0],ITv[1],ITv[2]); + printf("InertiaTensor Matrix\n"); - printf("InertiaTensor %f %f %f\n",IT[0][0],IT[0][1],IT[0][2]); - printf("InertiaTensor %f %f %f\n",IT[1][0],IT[1][1],IT[1][2]); - printf("InertiaTensor %f %f %f\n",IT[2][0],IT[2][1],IT[2][2]); + printf(" %6.3f %6.3f %6.3f\n",IT[0][0],IT[0][1],IT[0][2]); + printf(" %6.3f %6.3f %6.3f\n",IT[1][0],IT[1][1],IT[1][2]); + printf(" %6.3f %6.3f %6.3f\n",IT[2][0],IT[2][1],IT[2][2]); + + // Now we have a box with sides (h,w,d) 2,4,10, centered in (2,3,4) + // Volume is 80 + // inertia tensor should be: + // I_h = 1/12 m *(w^2+d^2) = 1/12 * 80 * (16+100) = 773.33 + // I_w = 1/12 m *(h^2+d^2) = 1/12 * 80 * (4+100) = 693.33 + // I_d = 1/12 m *(h^2+w^2) = 1/12 * 80 * (4+16) = 133.33 + + + vcg::tri::Torus(torusMesh,2,1,1024,512); + vcg::tri::Inertia It(torusMesh); + cc = It.CenterOfMass(); + It.InertiaTensorEigen(IT,ITv); + + printf("\nTorus of radius 2,1\n"); + printf("Mass %f \n",It.Mass()); + printf("CenterOfMass %f %f %f\n",cc[0],cc[1],cc[2]); + printf("InertiaTensor Values %6.3f %6.3f %6.3f\n",ITv[0],ITv[1],ITv[2]); + printf("InertiaTensor Matrix\n"); + + printf(" %6.3f %6.3f %6.3f\n",IT[0][0],IT[0][1],IT[0][2]); + printf(" %6.3f %6.3f %6.3f\n",IT[1][0],IT[1][1],IT[1][2]); + printf(" %6.3f %6.3f %6.3f\n",IT[2][0],IT[2][1],IT[2][2]); + + /* + Now we have a torus with c = 2, a = 1 + c = radius of the ring + a = radius of the section + + Volume is: + V= 2 PI^2 * a^2 * c = ~39.478 + + Inertia tensor should be: + + | ( 5/8 a^2 + 1/2 c^2 ) M 0 0 | + | 0 ( 5/8 a^2 + 1/2 c^2 ) M 0 | = + | 0 0 (3/4 a^2 + c^2) M | + + | ( 5/8+2 ) M 0 0 | | 103.630 0 0 | + = | 0 ( 5/8+2 ) M 0 | = | 0 103.630 0 | + | 0 0 (3/4+2) M | | 0 0 187.52 | + + */ return 0; }