cleaning up polygonal vcg samples

This commit is contained in:
Paolo Cignoni 2014-02-18 09:17:18 +00:00
parent b84e06c14e
commit 5f68ac2d07
2 changed files with 40 additions and 48 deletions

View File

@ -21,18 +21,10 @@
* * * *
****************************************************************************/ ****************************************************************************/
#include <vector>
#include <stdio.h> #include <stdio.h>
#include <vcg/simplex/vertex/base.h>
#include <vcg/simplex/face/base.h>
#include <vcg/simplex/edge/base.h>
#include <vcg/complex/complex.h> #include <vcg/complex/complex.h>
#include <vcg/complex/algorithms/create/zonohedron.h> #include <vcg/complex/algorithms/create/zonohedron.h>
#include <vcg/complex/algorithms/polygon_support.h> #include <vcg/complex/algorithms/polygon_support.h>
#include <wrap/io_trimesh/export_off.h> #include <wrap/io_trimesh/export_off.h>
@ -48,10 +40,10 @@ class MyVertex : public vcg::Vertex< MyUsedTypes,vcg::vertex::Coord3f,vcg::verte
class MyEdge : public vcg::Edge< MyUsedTypes > {}; class MyEdge : public vcg::Edge< MyUsedTypes > {};
class MyFace : public vcg::Face< MyUsedTypes, class MyFace : public vcg::Face< MyUsedTypes,
vcg::face::FFAdj, vcg::face::FFAdj,
vcg::face::VertexRef, vcg::face::VertexRef,
vcg::face::Normal3f, vcg::face::Normal3f,
vcg::face::BitFlags > {}; vcg::face::BitFlags > {};
// the main mesh class // the main mesh class
class MyMesh : public vcg::tri::TriMesh<std::vector<MyVertex>, std::vector<MyFace> > {}; class MyMesh : public vcg::tri::TriMesh<std::vector<MyVertex>, std::vector<MyFace> > {};
@ -61,61 +53,61 @@ class MyMesh : public vcg::tri::TriMesh<std::vector<MyVertex>, std::vector<MyFac
// example 1: build a cube as a Zonohedron // example 1: build a cube as a Zonohedron
void example1(){ void example1(){
vcg::tri::Zonohedron<float> z; vcg::tri::Zonohedron<float> z;
z.addVector( 0,0,1 ); z.addVector( 0,0,1 );
z.addVector( 0,1,0 ); z.addVector( 0,1,0 );
z.addVector( 1,0,0 ); z.addVector( 1,0,0 );
MyMesh m; MyMesh m;
z.createMesh(m); // this will be a cube z.createMesh(m); // this will be a cube
vcg::tri::UpdateTopology<MyMesh>::FaceFace(m); // needed by exporter vcg::tri::UpdateTopology<MyMesh>::FaceFace(m); // needed by exporter
int savemask = vcg::tri::io::Mask::IOM_BITPOLYGONAL; int savemask = vcg::tri::io::Mask::IOM_BITPOLYGONAL;
vcg::tri::io::ExporterOFF<MyMesh>::Save(m,"cube.off",savemask); vcg::tri::io::ExporterOFF<MyMesh>::Save(m,"cube.off",savemask);
} }
// example2: reads input file, builds zonohedra as described there // example2: reads input file, builds zonohedra as described there
void example2(){ void example2(){
FILE* f = fopen("input.txt","rt"); FILE* f = fopen("input.txt","rt");
if (!f) return; if (!f) return;
while (1) { while (1) {
// read mesh name // read mesh name
char meshFilename[1024], fullMeshFilename[1024]; char meshFilename[1024], fullMeshFilename[1024];
if (fscanf(f,"%s",meshFilename)!=1) break; if (fscanf(f,"%s",meshFilename)!=1) break;
sprintf(fullMeshFilename,"%s.off",meshFilename); sprintf(fullMeshFilename,"%s.off",meshFilename);
// build input vector // build input vector
vcg::tri::Zonohedron<float> z; vcg::tri::Zonohedron<float> z;
while (1) { while (1) {
float a,b,c; float a,b,c;
if (fscanf(f,"%f %f %f",&a, &b, &c)!=3) break; if (fscanf(f,"%f %f %f",&a, &b, &c)!=3) break;
z.addVector(a,b,c); z.addVector(a,b,c);
} }
printf("Building %s from %d vectors...\n",fullMeshFilename, z.vectors().size() ); printf("Building %s from %d vectors...\n",fullMeshFilename, z.vectors().size() );
MyMesh m; MyMesh m;
z.createMesh(m); z.createMesh(m);
vcg::tri::UpdateTopology<MyMesh>::FaceFace(m); // needed by exporter vcg::tri::UpdateTopology<MyMesh>::FaceFace(m); // needed by exporter
// normally, faces with more than 4sides are split into parallelograms // normally, faces with more than 4sides are split into parallelograms
// this merges them (optional, try removing it!) // this merges them (optional, try removing it!)
vcg::tri::PolygonSupport<MyMesh,int>::MergeFlatFaces(m); vcg::tri::PolygonSupport<MyMesh,int>::MergeFlatFaces(m);
int savemask = vcg::tri::io::Mask::IOM_BITPOLYGONAL; int savemask = vcg::tri::io::Mask::IOM_BITPOLYGONAL;
vcg::tri::io::ExporterOFF<MyMesh>::Save(m,fullMeshFilename,savemask); vcg::tri::io::ExporterOFF<MyMesh>::Save(m,fullMeshFilename,savemask);
} }
} }
int main(int argc, char *argv[]){ int main(int argc, char *argv[]){
example1(); example1();
example2(); example2();
return 0; return 0;
} }

View File

@ -1,4 +1,4 @@
include(../common.pri) include(../common.pri)
TARGET = polygonmesh_zonohedra TARGET = polygonmesh_zonohedra
SOURCES += polygonmesh_zonohedra.cpp SOURCES += polygonmesh_zonohedra.cpp
SOURCES += $$VCGLIBDIR/wrap/ply/plylib.cpp SOURCES += ../../../wrap/ply/plylib.cpp