From cd3af281cc4c8ff495fd9038cb446ab37f760d7c Mon Sep 17 00:00:00 2001 From: cignoni Date: Fri, 12 Oct 2012 06:07:06 +0000 Subject: [PATCH] Added a few more samples (normals, inertia, sampling) --- apps/sample/sample.pro | 1 + .../trimesh_inertia/trimesh_inertia.cpp | 75 ++++++++++++++++++ .../trimesh_inertia/trimesh_inertia.pro | 3 + apps/sample/trimesh_normal/trimesh_normal.cpp | 79 +++++++++++++++++++ apps/sample/trimesh_normal/trimesh_normal.pro | 3 + .../trimesh_sampling/trimesh_sampling.cpp | 64 +++++++++++++++ .../trimesh_sampling/trimesh_sampling.pro | 3 + 7 files changed, 228 insertions(+) create mode 100644 apps/sample/trimesh_inertia/trimesh_inertia.cpp create mode 100644 apps/sample/trimesh_inertia/trimesh_inertia.pro create mode 100644 apps/sample/trimesh_normal/trimesh_normal.cpp create mode 100644 apps/sample/trimesh_normal/trimesh_normal.pro create mode 100644 apps/sample/trimesh_sampling/trimesh_sampling.cpp create mode 100644 apps/sample/trimesh_sampling/trimesh_sampling.pro diff --git a/apps/sample/sample.pro b/apps/sample/sample.pro index 07e6859b..aa4802fd 100644 --- a/apps/sample/sample.pro +++ b/apps/sample/sample.pro @@ -15,6 +15,7 @@ SUBDIRS = trimesh_base \ trimesh_intersection \ trimesh_ball_pivoting \ trimesh_hole \ + trimesh_sampling \ polygonmesh_base \ aabb_binary_tree \ trimesh_attribute diff --git a/apps/sample/trimesh_inertia/trimesh_inertia.cpp b/apps/sample/trimesh_inertia/trimesh_inertia.cpp new file mode 100644 index 00000000..d1527a54 --- /dev/null +++ b/apps/sample/trimesh_inertia/trimesh_inertia.cpp @@ -0,0 +1,75 @@ +/**************************************************************************** +* VCGLib o o * +* Visual and Computer Graphics Library o o * +* _ O _ * +* Copyright(C) 2004-2012 \/)\/ * +* Visual Computing Lab /\/| * +* ISTI - Italian National Research Council | * +* \ * +* All rights reserved. * +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU General Public License as published by * +* the Free Software Foundation; either version 2 of the License, or * +* (at your option) any later version. * +* * +* This program is distributed in the hope that it will be useful, * +* but WITHOUT ANY WARRANTY; without even the implied warranty of * +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +* GNU General Public License (http://www.gnu.org/licenses/gpl.txt) * +* for more details. * +* * +****************************************************************************/ +#include + +#include + +#include +#include + +using namespace vcg; +using namespace std; + +class MyEdge; +class MyFace; +class MyVertex; +struct MyUsedTypes : public UsedTypes< Use ::AsVertexType, + Use ::AsEdgeType, + 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 > {}; + +int main( int argc, char **argv ) +{ + MyMesh tet,oct,hex,dod,ico; + + 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); + + tri::Inertia I; + I.Compute(hex); + Point3f cc = I.CenterOfMass(); + printf("Mass %f \n",I.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 %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]); + + return 0; +} diff --git a/apps/sample/trimesh_inertia/trimesh_inertia.pro b/apps/sample/trimesh_inertia/trimesh_inertia.pro new file mode 100644 index 00000000..61382570 --- /dev/null +++ b/apps/sample/trimesh_inertia/trimesh_inertia.pro @@ -0,0 +1,3 @@ +include(../common.pri) +TARGET = trimesh_inertia +SOURCES += trimesh_inertia.cpp diff --git a/apps/sample/trimesh_normal/trimesh_normal.cpp b/apps/sample/trimesh_normal/trimesh_normal.cpp new file mode 100644 index 00000000..f7485e7e --- /dev/null +++ b/apps/sample/trimesh_normal/trimesh_normal.cpp @@ -0,0 +1,79 @@ +/**************************************************************************** +* VCGLib o o * +* Visual and Computer Graphics Library o o * +* _ O _ * +* Copyright(C) 2004-2012 \/)\/ * +* Visual Computing Lab /\/| * +* ISTI - Italian National Research Council | * +* \ * +* All rights reserved. * +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU General Public License as published by * +* the Free Software Foundation; either version 2 of the License, or * +* (at your option) any later version. * +* * +* This program is distributed in the hope that it will be useful, * +* but WITHOUT ANY WARRANTY; without even the implied warranty of * +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +* GNU General Public License (http://www.gnu.org/licenses/gpl.txt) * +* for more details. * +* * +****************************************************************************/ +#include + +#include + +#include +#include + +using namespace vcg; +using namespace std; + +class MyEdge; +class MyFace; +class MyVertex; +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 MyEdge : public Edge{}; +class MyMesh : public tri::TriMesh< vector, vector , vector > {}; + +int main( int argc, char **argv ) +{ + if(argc<2) + { + printf("Usage trimesh_base \n"); + return -1; + } + + MyMesh m; + + if(tri::io::ImporterOFF::Open(m,argv[1])!=0) + { + printf("Error reading file %s\n",argv[1]); + exit(0); + } + + Matrix44f m44 = Matrix44f::Identity(); + + tri::UpdateNormal::PerVertexClear(m); + tri::UpdateNormal::PerVertex(m); + tri::UpdateNormal::PerVertexAngleWeighted(m); + tri::UpdateNormal::PerVertexNelsonMaxWeighted(m); + tri::UpdateNormal::PerFace(m); + tri::UpdateNormal::PerVertexFromCurrentFaceNormal(m); + tri::UpdateNormal::PerFaceFromCurrentVertexNormal(m); + tri::UpdateNormal::NormalizePerVertex(m); + tri::UpdateNormal::NormalizePerFace(m); + tri::UpdateNormal::NormalizePerFaceByArea(m); + tri::UpdateNormal::PerBitQuadFaceNormalized(m); + tri::UpdateNormal::PerVertexMatrix(m,m44); + tri::UpdateNormal::PerFaceMatrix(m,m44); + tri::UpdateNormal::PerWedgeCrease(m, math::ToRad(45.0f)); + + return 0; +} diff --git a/apps/sample/trimesh_normal/trimesh_normal.pro b/apps/sample/trimesh_normal/trimesh_normal.pro new file mode 100644 index 00000000..977523a0 --- /dev/null +++ b/apps/sample/trimesh_normal/trimesh_normal.pro @@ -0,0 +1,3 @@ +include(../common.pri) +TARGET = trimesh_normal +SOURCES += trimesh_normal.cpp diff --git a/apps/sample/trimesh_sampling/trimesh_sampling.cpp b/apps/sample/trimesh_sampling/trimesh_sampling.cpp new file mode 100644 index 00000000..8df5c2fb --- /dev/null +++ b/apps/sample/trimesh_sampling/trimesh_sampling.cpp @@ -0,0 +1,64 @@ +/**************************************************************************** +* VCGLib o o * +* Visual and Computer Graphics Library o o * +* _ O _ * +* Copyright(C) 2004-2012 \/)\/ * +* Visual Computing Lab /\/| * +* ISTI - Italian National Research Council | * +* \ * +* All rights reserved. * +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU General Public License as published by * +* the Free Software Foundation; either version 2 of the License, or * +* (at your option) any later version. * +* * +* This program is distributed in the hope that it will be useful, * +* but WITHOUT ANY WARRANTY; without even the implied warranty of * +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +* GNU General Public License (http://www.gnu.org/licenses/gpl.txt) * +* for more details. * +* * +****************************************************************************/ +#include + +#include + +#include + +using namespace vcg; +using namespace std; + +class MyEdge; +class MyFace; +class MyVertex; +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 MyEdge : public Edge{}; +class MyMesh : public tri::TriMesh< vector, vector , vector > {}; + +int main( int argc, char **argv ) +{ + if(argc<2) + { + printf("Usage trimesh_base \n"); + return -1; + } + + MyMesh m; + + if(tri::io::ImporterOFF::Open(m,argv[1])!=0) + { + printf("Error reading file %s\n",argv[1]); + exit(0); + } + vector pointVec; + float radius; + tri::PoissonSampling(m,pointVec,1000,radius); + + return 0; +} diff --git a/apps/sample/trimesh_sampling/trimesh_sampling.pro b/apps/sample/trimesh_sampling/trimesh_sampling.pro new file mode 100644 index 00000000..e112f066 --- /dev/null +++ b/apps/sample/trimesh_sampling/trimesh_sampling.pro @@ -0,0 +1,3 @@ +include(../common.pri) +TARGET = trimesh_sampling +SOURCES += trimesh_sampling.cpp