From de84cc10816b2c82da0a24907bf2ba309e8cdef2 Mon Sep 17 00:00:00 2001 From: mtarini Date: Wed, 18 Jul 2012 22:10:11 +0000 Subject: [PATCH] --- apps/sample/polygonmesh_zonohedra/input.txt | 42 ++++++ .../polygonmesh_zonohedra.cpp | 121 ++++++++++++++++++ 2 files changed, 163 insertions(+) create mode 100644 apps/sample/polygonmesh_zonohedra/input.txt create mode 100644 apps/sample/polygonmesh_zonohedra/polygonmesh_zonohedra.cpp diff --git a/apps/sample/polygonmesh_zonohedra/input.txt b/apps/sample/polygonmesh_zonohedra/input.txt new file mode 100644 index 00000000..6d3d149a --- /dev/null +++ b/apps/sample/polygonmesh_zonohedra/input.txt @@ -0,0 +1,42 @@ +cube +0 0 1 +0 1 0 +1 0 0 + +funny +0 0 4 +0 4 0 +4 0 0 +0 1 1 +1 1 0 +1 0 1 +0 1 -1 +1 -1 0 +-1 0 1 + +prism8 +0 3 0 +1 0 0 +0 0 1 +1 0 1 +1 0 -1 + +prismCoolEnd +0 6 0 +3 0 0 +0 0 3 +1 0 1 +1 0 -1 +1 1 1 +-1 1 1 +1 1 -1 +-1 1 -1 + +strangeDie +0 0 3 +0 3 0 +3 0 0 +1 -1 1 +1 1 -1 +1 -1 -1 +1 1 1 diff --git a/apps/sample/polygonmesh_zonohedra/polygonmesh_zonohedra.cpp b/apps/sample/polygonmesh_zonohedra/polygonmesh_zonohedra.cpp new file mode 100644 index 00000000..78308e48 --- /dev/null +++ b/apps/sample/polygonmesh_zonohedra/polygonmesh_zonohedra.cpp @@ -0,0 +1,121 @@ +/**************************************************************************** + * VCGLib o o * + * Visual and Computer Graphics Library o o * + * _ O _ * + * Copyright(C) 2004 \/)\/ * + * 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 + +#include + + + +class MyVertex; +class MyEdge; +class MyFace; + +struct MyUsedTypes: public vcg::UsedTypes::AsVertexType,vcg::Use::AsEdgeType,vcg::Use::AsFaceType>{}; + +class MyVertex : public vcg::Vertex< MyUsedTypes,vcg::vertex::Coord3f,vcg::vertex::BitFlags >{}; + +class MyEdge : public vcg::Edge< MyUsedTypes > {}; + +class MyFace : public vcg::Face< MyUsedTypes, + vcg::face::FFAdj, + vcg::face::VertexRef, + vcg::face::Normal3f, + vcg::face::BitFlags > {}; + +// the main mesh class +class MyMesh : public vcg::tri::TriMesh, std::vector > {}; + + + +// example 1: build a cube as a Zonohedron +void example1(){ + + vcg::tri::Zonohedron z; + z.addVector( 0,0,1 ); + z.addVector( 0,1,0 ); + z.addVector( 1,0,0 ); + + MyMesh m; + z.createMesh(m); // this will be a cube + + vcg::tri::UpdateTopology::FaceFace(m); // needed by exporter + + int savemask = vcg::tri::io::Mask::IOM_BITPOLYGONAL; + vcg::tri::io::ExporterOFF::Save(m,"cube.off",savemask); +} + + +// example2: reads input file, builds zonohedra as described there +void example2(){ + + FILE* f = fopen("input.txt","rt"); + if (!f) return; + + while (1) { + + // read mesh name + char meshFilename[1024], fullMeshFilename[1024]; + if (fscanf(f,"%s",meshFilename)!=1) break; + sprintf(fullMeshFilename,"%s.off",meshFilename); + + // build input vector + vcg::tri::Zonohedron z; + while (1) { + float a,b,c; + if (fscanf(f,"%f %f %f",&a, &b, &c)!=3) break; + z.addVector(a,b,c); + } + + printf("Building %s from %d vectors...\n",fullMeshFilename, z.vectors().size() ); + + MyMesh m; + z.createMesh(m); + + vcg::tri::UpdateTopology::FaceFace(m); // needed by exporter + + // normally, faces with more than 4sides are split into parallelograms + // this merges them (optional, try removing it!) + vcg::tri::PolygonSupport::MergeFlatFaces(m); + + int savemask = vcg::tri::io::Mask::IOM_BITPOLYGONAL; + vcg::tri::io::ExporterOFF::Save(m,fullMeshFilename,savemask); + } + +} + +int main(int argc, char *argv[]){ + example1(); + example2(); + return 0; +}