From b95684e6e5f7496c9ff1567c51f4f147c8289e96 Mon Sep 17 00:00:00 2001 From: Paolo Cignoni Date: Thu, 29 Nov 2018 00:35:22 +0100 Subject: [PATCH] Corrected some of the polygonal samples and created a collective sample_poly.pro --- apps/sample/polygonmesh_base/polygonmesh.cpp | 10 +- .../polygonmesh_dual/polygonmesh_dual.cpp | 10 +- .../polygonmesh_smooth/polygonmesh_smooth.cpp | 132 ++++++++++++++++++ .../polygonmesh_smooth/polygonmesh_smooth.pro | 3 + .../polygonmesh_zonohedra.cpp | 2 +- apps/sample/sample_poly.pro | 10 ++ 6 files changed, 154 insertions(+), 13 deletions(-) create mode 100644 apps/sample/polygonmesh_smooth/polygonmesh_smooth.cpp create mode 100644 apps/sample/polygonmesh_smooth/polygonmesh_smooth.pro create mode 100644 apps/sample/sample_poly.pro diff --git a/apps/sample/polygonmesh_base/polygonmesh.cpp b/apps/sample/polygonmesh_base/polygonmesh.cpp index c9dda8d4..69fba553 100644 --- a/apps/sample/polygonmesh_base/polygonmesh.cpp +++ b/apps/sample/polygonmesh_base/polygonmesh.cpp @@ -36,16 +36,11 @@ using namespace vcg; using namespace std; -// forward declarations class TFace; class TVertex; struct TUsedTypes: public vcg::UsedTypes< vcg::Use::AsVertexType, vcg::Use::AsFaceType >{}; - - -/* Definition of a mesh of triangles -*/ class TVertex : public Vertex< TUsedTypes, vertex::BitFlags, vertex::Coord3f, @@ -201,9 +196,8 @@ else 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); + vcg::tri::io::ExporterPLY::Save(tm1,"converted_tri.ply",false); + vcg::tri::io::ExporterPLY::Save(pm,"converted_poly.ply",false); } diff --git a/apps/sample/polygonmesh_dual/polygonmesh_dual.cpp b/apps/sample/polygonmesh_dual/polygonmesh_dual.cpp index be16defc..d01b5d5c 100644 --- a/apps/sample/polygonmesh_dual/polygonmesh_dual.cpp +++ b/apps/sample/polygonmesh_dual/polygonmesh_dual.cpp @@ -74,10 +74,11 @@ struct PUsedTypes: public vcg::UsedTypes ::AsVertexType, vcg::Use ::AsFaceType>{}; class PVertex:public vcg::Vertex< PUsedTypes, - vcg::vertex::Coord3f, - vcg::vertex::Normal3f, - vcg::vertex::Mark, - vcg::vertex::BitFlags>{} ; + vcg::vertex::Coord3f, + vcg::vertex::Normal3f, + vcg::vertex::Mark, + vcg::vertex::Qualityf, + vcg::vertex::BitFlags>{} ; class PFace:public vcg::Face< PUsedTypes @@ -88,6 +89,7 @@ class PFace:public vcg::Face< ,vcg::face::PFVAdj ,vcg::face::PFFAdj // Pointer to edge-adjacent face (just like FFAdj ) ,vcg::face::BitFlags // bit flags + ,vcg::face::Qualityf // quality ,vcg::face::Normal3f // normal > {}; diff --git a/apps/sample/polygonmesh_smooth/polygonmesh_smooth.cpp b/apps/sample/polygonmesh_smooth/polygonmesh_smooth.cpp new file mode 100644 index 00000000..07301709 --- /dev/null +++ b/apps/sample/polygonmesh_smooth/polygonmesh_smooth.cpp @@ -0,0 +1,132 @@ +/**************************************************************************** +* VCGLib o o * +* Visual and Computer Graphics Library o o * +* _ O _ * +* Copyright(C) 2004-2016 \/)\/ * +* 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 + +#include +#include +#include +#include + +using namespace vcg; +using namespace std; + +// forward declarations +class TFace; +class TVertex; + +struct TUsedTypes: public vcg::UsedTypes< vcg::Use::AsVertexType, vcg::Use::AsFaceType >{}; + +/* Definition of a mesh of triangles +*/ +class TVertex : public Vertex< TUsedTypes, + vertex::BitFlags, + vertex::Coord3f, + vertex::Normal3f, + vertex::Mark >{}; + +class TFace : public Face< TUsedTypes, + face::VertexRef, // three pointers to vertices + face::Normal3f, // normal + face::BitFlags, // flags + face::Mark, // incremental mark + face::FFAdj // three pointers to adjacent faces +> {}; + +/* 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 PFace; +class PVertex; + +struct PUsedTypes: public vcg::UsedTypes ::AsVertexType, + vcg::Use ::AsFaceType>{}; + +class PVertex:public vcg::Vertex< PUsedTypes, + vcg::vertex::Coord3f, + vcg::vertex::Normal3f, + vcg::vertex::Mark, + vcg::vertex::Qualityf, + vcg::vertex::Mark, + vcg::vertex::BitFlags>{} ; + +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::BitFlags // bit flags + ,vcg::face::Qualityf // quality + ,vcg::face::Mark // incremental mark + ,vcg::face::Normal3f // normal +> {}; + +class PMesh: public + vcg::tri::TriMesh< + std::vector, // the vector of vertices + std::vector // the vector of faces + >{}; + +using namespace vcg; + +int main(int, char **) +{ + TMesh tm; + PMesh pm; + math::MarsenneTwisterRNG RndGen; + tri::io::ImporterOFF::Open(pm,"../../meshes/fertility_quad.off"); + tri::UpdateBounding::Box(pm); + tri::UpdateSelection::VertexClear(pm); + // randomly displace half of the vertices + float randScale = pm.bbox.Diag()/200.0f; + ForEachVertex(pm,[&](PVertex &v){ + if(v.P()[0] < pm.bbox.Center()[0]) + v.P() += math::GeneratePointInUnitBallUniform(RndGen)*randScale; + }); + + // Select half of the vertices + ForEachVertex(pm,[&](PVertex &v){ + if(v.P()[2] < pm.bbox.Center()[2]) + v.SetS(); + }); + printf("Input quad mesh has %i %i (sel %i)\n",pm.VN(), pm.FN(), tri::UpdateSelection::VertexCount(pm) ); + + tri::io::ImporterPLY::Open(tm,"../../meshes/fertility_tri.ply"); + tri::UpdateNormal::PerVertexNormalizedPerFaceNormalized(tm); + printf("Input tri mesh has %i %i\n",tm.VN(), tm.FN()); + tri::io::ExporterOFF::Save(pm,"./smooth.off"); + PolygonalAlgorithm::LaplacianReproject(pm,tm,100,0.6,0.3,true); + tri::io::ExporterOFF::Save(pm,"./smooth2.off"); +} + + diff --git a/apps/sample/polygonmesh_smooth/polygonmesh_smooth.pro b/apps/sample/polygonmesh_smooth/polygonmesh_smooth.pro new file mode 100644 index 00000000..439aca55 --- /dev/null +++ b/apps/sample/polygonmesh_smooth/polygonmesh_smooth.pro @@ -0,0 +1,3 @@ +include(../common.pri) +TARGET = polygonmesh_smooth +SOURCES += polygonmesh_smooth.cpp ../../../wrap/ply/plylib.cpp diff --git a/apps/sample/polygonmesh_zonohedra/polygonmesh_zonohedra.cpp b/apps/sample/polygonmesh_zonohedra/polygonmesh_zonohedra.cpp index 995bad0a..809b4496 100644 --- a/apps/sample/polygonmesh_zonohedra/polygonmesh_zonohedra.cpp +++ b/apps/sample/polygonmesh_zonohedra/polygonmesh_zonohedra.cpp @@ -42,7 +42,7 @@ class MyEdge : public vcg::Edge< MyUsedTypes > {}; class MyFace : public vcg::Face< MyUsedTypes, vcg::face::FFAdj, vcg::face::VertexRef, - vcg::face::Normal3f, + vcg::face::Normal3f, vcg::face::BitFlags > {}; // the main mesh class diff --git a/apps/sample/sample_poly.pro b/apps/sample/sample_poly.pro new file mode 100644 index 00000000..249d29b4 --- /dev/null +++ b/apps/sample/sample_poly.pro @@ -0,0 +1,10 @@ + +TEMPLATE = subdirs +SUBDIRS = polygonmesh_base \ + polygonmesh_dual \ + polygonmesh_optimize \ +# polygonmesh_quadsimpl \ + polygonmesh_smooth \ + polygonmesh_zonohedra + +