Still improving the documentation of the samples
This commit is contained in:
parent
ac9b6b16f2
commit
9ae5490a8b
apps/sample
|
@ -1,4 +1,4 @@
|
|||
DEPENDPATH += .
|
||||
DEPENDPATH += . ../../..
|
||||
INCLUDEPATH += . ../../..
|
||||
CONFIG += console stl
|
||||
TEMPLATE = app
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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<MyVertex> ::AsVertexType,
|
||||
Use<MyFace> ::AsFaceType>{};
|
||||
struct MyUsedTypes : public vcg::UsedTypes< vcg::Use<MyVertex> ::AsVertexType,
|
||||
vcg::Use<MyFace> ::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<MyVertex>, std::vector<MyFace> > {};
|
||||
|
||||
|
|
|
@ -44,13 +44,13 @@ This file contain a minimal example of the library
|
|||
class MyEdge;
|
||||
class MyFace;
|
||||
class MyVertex;
|
||||
struct MyUsedTypes : public UsedTypes< Use<MyVertex> ::AsVertexType,
|
||||
Use<MyEdge> ::AsEdgeType,
|
||||
Use<MyFace> ::AsFaceType>{};
|
||||
struct MyUsedTypes : public vcg::UsedTypes< vcg::Use<MyVertex> ::AsVertexType,
|
||||
vcg::Use<MyEdge> ::AsEdgeType,
|
||||
vcg::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 MyEdge : public Edge<MyUsedTypes>{};
|
||||
class MyVertex : public vcg::Vertex<MyUsedTypes, vcg::vertex::Coord3f, vcg::vertex::Normal3f, vcg::vertex::BitFlags >{};
|
||||
class MyFace : public vcg::Face< MyUsedTypes, vcg::face::FFAdj, vcg::face::VertexRef, vcg::face::BitFlags > {};
|
||||
class MyEdge : public vcg::Edge<MyUsedTypes>{};
|
||||
class MyMesh : public vcg::tri::TriMesh< std::vector<MyVertex>, std::vector<MyFace> , std::vector<MyEdge> > {};
|
||||
|
||||
int main( int argc, char **argv )
|
||||
|
@ -63,7 +63,7 @@ int main( int argc, char **argv )
|
|||
|
||||
MyMesh m;
|
||||
|
||||
if(tri::io::ImporterOFF<MyMesh>::Open(m,argv[1])!=tri::io::ImporterOFF<MyMesh>::NoError)
|
||||
if(vcg::tri::io::ImporterOFF<MyMesh>::Open(m,argv[1])!=vcg::tri::io::ImporterOFF<MyMesh>::NoError)
|
||||
{
|
||||
printf("Error reading file %s\n",argv[1]);
|
||||
exit(0);
|
||||
|
|
|
@ -20,6 +20,12 @@
|
|||
* for more details. *
|
||||
* *
|
||||
****************************************************************************/
|
||||
/*! \file trimesh_clustering.cpp
|
||||
\ingroup code_sample
|
||||
|
||||
\brief a minimal example of a clustering based simplification
|
||||
|
||||
*/
|
||||
#include<vcg/complex/complex.h>
|
||||
|
||||
#include <vcg/complex/algorithms/update/bounding.h>
|
||||
|
@ -29,61 +35,59 @@
|
|||
#include <vcg/complex/algorithms/clustering.h>
|
||||
|
||||
// input output
|
||||
#include <wrap/io_trimesh/import_ply.h>
|
||||
#include <wrap/io_trimesh/export_ply.h>
|
||||
#include <wrap/io_trimesh/import.h>
|
||||
#include <wrap/io_trimesh/export.h>
|
||||
|
||||
class MyFace;
|
||||
class MyVertex;
|
||||
|
||||
struct MyUsedTypes : public UsedTypes< Use<MyVertex>::AsVertexType, Use<MyFace>::AsFaceType>{};
|
||||
struct MyUsedTypes : public vcg::UsedTypes< vcg::Use<MyVertex>::AsVertexType, vcg::Use<MyFace>::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<MyVertex>, std::vector<MyFace> > {};
|
||||
|
||||
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<argc)
|
||||
{
|
||||
if(argv[i][0]!='-')
|
||||
{printf("Error unable to parse option '%s'\n",argv[i]); exit(0);}
|
||||
switch(argv[i][1])
|
||||
{
|
||||
case 'k' : CellNum=atoi(argv[i+1]); ++i; printf("Using %i clustering cells\n",CellNum); break;
|
||||
case 's' : CellSize=atof(argv[i+1]); ++i; printf("Using %5f as clustering cell size\n",CellSize); break;
|
||||
case 'd' : DupFace=true; printf("Enabling the duplication of faces for double surfaces\n"); break;
|
||||
int i=3;
|
||||
while(i<argc)
|
||||
{
|
||||
if(argv[i][0]!='-')
|
||||
{ printf("Error unable to parse option '%s'\n",argv[i]); exit(0); }
|
||||
switch(argv[i][1])
|
||||
{
|
||||
case 'k' : CellNum=atoi(argv[i+1]); ++i; printf("Using %i clustering cells\n",CellNum); break;
|
||||
case 's' : CellSize=atof(argv[i+1]); ++i; printf("Using %5f as clustering cell size\n",CellSize); break;
|
||||
case 'd' : DupFace=true; printf("Enabling the duplication of faces for double surfaces\n"); break;
|
||||
|
||||
default : {printf("Error unable to parse option '%s'\n",argv[i]); exit(0);}
|
||||
}
|
||||
++i;
|
||||
}
|
||||
default : {printf("Error unable to parse option '%s'\n",argv[i]); exit(0);}
|
||||
}
|
||||
++i;
|
||||
}
|
||||
|
||||
MyMesh m;
|
||||
MyMesh m;
|
||||
if(vcg::tri::io::ImporterPLY<MyMesh>::Open(m,argv[1])!=0)
|
||||
{
|
||||
printf("Error reading file %s\n",argv[1]);
|
||||
exit(0);
|
||||
}
|
||||
|
||||
if(vcg::tri::io::ImporterPLY<MyMesh>::Open(m,argv[1])!=0)
|
||||
{
|
||||
printf("Error reading file %s\n",argv[1]);
|
||||
exit(0);
|
||||
}
|
||||
vcg::tri::UpdateBounding<MyMesh>::Box(m);
|
||||
vcg::tri::UpdateNormal<MyMesh>::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<MyMesh>::Save(m,argv[2],pi.mask);
|
||||
return 0;
|
||||
}
|
||||
|
||||
vcg::tri::io::ExporterPLY<MyMesh>::Save(m,argv[2]);
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -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<vcg/complex/complex.h>
|
||||
|
||||
#include<wrap/io_trimesh/export_off.h>
|
||||
|
@ -31,13 +39,13 @@
|
|||
class MyEdge;
|
||||
class MyFace;
|
||||
class MyVertex;
|
||||
struct MyUsedTypes : public UsedTypes< Use<MyVertex> ::AsVertexType,
|
||||
Use<MyEdge> ::AsEdgeType,
|
||||
Use<MyFace> ::AsFaceType>{};
|
||||
struct MyUsedTypes : public vcg::UsedTypes< vcg::Use<MyVertex> ::AsVertexType,
|
||||
vcg::Use<MyEdge> ::AsEdgeType,
|
||||
vcg::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 MyEdge : public Edge<MyUsedTypes>{};
|
||||
class MyVertex : public vcg::Vertex<MyUsedTypes, vcg::vertex::Coord3f, vcg::vertex::Normal3f, vcg::vertex::BitFlags >{};
|
||||
class MyFace : public vcg::Face< MyUsedTypes, vcg::face::FFAdj, vcg::face::VertexRef, vcg::face::BitFlags > {};
|
||||
class MyEdge : public vcg::Edge<MyUsedTypes>{};
|
||||
class MyMesh : public vcg::tri::TriMesh< std::vector<MyVertex>, std::vector<MyFace> , std::vector<MyEdge> > {};
|
||||
|
||||
int main( int argc, char **argv )
|
||||
|
|
|
@ -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<vcg/complex/complex.h>
|
||||
|
||||
#include<wrap/io_trimesh/import_off.h>
|
||||
|
@ -27,49 +37,86 @@
|
|||
#include<vcg/complex/algorithms/inertia.h>
|
||||
#include<vcg/complex/algorithms/create/platonic.h>
|
||||
|
||||
using namespace vcg;
|
||||
using namespace std;
|
||||
|
||||
class MyEdge;
|
||||
class MyFace;
|
||||
class MyVertex;
|
||||
struct MyUsedTypes : public UsedTypes< Use<MyVertex> ::AsVertexType,
|
||||
Use<MyEdge> ::AsEdgeType,
|
||||
Use<MyFace> ::AsFaceType>{};
|
||||
struct MyUsedTypes : public vcg::UsedTypes< vcg::Use<MyVertex> ::AsVertexType,
|
||||
vcg::Use<MyEdge> ::AsEdgeType,
|
||||
vcg::Use<MyFace> ::AsFaceType>{};
|
||||
|
||||
class MyVertex : public Vertex<MyUsedTypes, vertex::Coord3f, vertex::Normal3f, vertex::BitFlags >{};
|
||||
class MyFace : public Face< MyUsedTypes, face::FFAdj, face::Normal3f, face::VertexRef, face::BitFlags > {};
|
||||
class MyEdge : public Edge<MyUsedTypes>{};
|
||||
class MyMesh : public tri::TriMesh< vector<MyVertex>, vector<MyFace> , vector<MyEdge> > {};
|
||||
class MyVertex : public vcg::Vertex<MyUsedTypes, vcg::vertex::Coord3f, vcg::vertex::Normal3f, vcg::vertex::BitFlags >{};
|
||||
class MyFace : public vcg::Face< MyUsedTypes, vcg::face::FFAdj, vcg::face::Normal3f, vcg::face::VertexRef, vcg::face::BitFlags > {};
|
||||
class MyEdge : public vcg::Edge<MyUsedTypes>{};
|
||||
class MyMesh : public vcg::tri::TriMesh< std::vector<MyVertex>, std::vector<MyFace> , std::vector<MyEdge> > {};
|
||||
|
||||
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<MyMesh>::Matrix(hex,ScaleM);
|
||||
tri::UpdatePosition<MyMesh>::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<MyMesh>::Matrix(boxMesh,ScaleM);
|
||||
vcg::tri::UpdatePosition<MyMesh>::Matrix(boxMesh,TransM);
|
||||
vcg::tri::Inertia<MyMesh> Ib(boxMesh);
|
||||
vcg::Point3f cc = Ib.CenterOfMass();
|
||||
Ib.InertiaTensorEigen(IT,ITv);
|
||||
|
||||
tri::Inertia<MyMesh> 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<MyMesh> 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;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue