polygonmesh_zonohedra.cpp
Go to the documentation of this file.
00001 /****************************************************************************
00002  * VCGLib                                                            o o     *
00003  * Visual and Computer Graphics Library                            o     o   *
00004  *                                                                _   O  _   *
00005  * Copyright(C) 2004                                                \/)\/    *
00006  * Visual Computing Lab                                            /\/|      *
00007  * ISTI - Italian National Research Council                           |      *
00008  *                                                                    \      *
00009  * All rights reserved.                                                      *
00010  *                                                                           *
00011  * This program is free software; you can redistribute it and/or modify      *
00012  * it under the terms of the GNU General Public License as published by      *
00013  * the Free Software Foundation; either version 2 of the License, or         *
00014  * (at your option) any later version.                                       *
00015  *                                                                           *
00016  * This program is distributed in the hope that it will be useful,           *
00017  * but WITHOUT ANY WARRANTY; without even the implied warranty of            *
00018  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the             *
00019  * GNU General Public License (http://www.gnu.org/licenses/gpl.txt)          *
00020  * for more details.                                                         *
00021  *                                                                           *
00022  ****************************************************************************/
00023 
00024 #include <stdio.h>
00025 #include <vcg/complex/complex.h>
00026 #include <vcg/complex/algorithms/create/zonohedron.h>
00027 #include <vcg/complex/algorithms/polygon_support.h>
00028 #include <wrap/io_trimesh/export_off.h>
00029 
00030 
00031 
00032 class MyVertex;
00033 class MyEdge;
00034 class MyFace;
00035 
00036 struct MyUsedTypes: public vcg::UsedTypes<vcg::Use<MyVertex>::AsVertexType,vcg::Use<MyEdge>::AsEdgeType,vcg::Use<MyFace>::AsFaceType>{};
00037 
00038 class MyVertex : public vcg::Vertex< MyUsedTypes,vcg::vertex::Coord3f,vcg::vertex::BitFlags >{};
00039 
00040 class MyEdge : public vcg::Edge< MyUsedTypes > {};
00041 
00042 class MyFace : public vcg::Face< MyUsedTypes,
00043     vcg::face::FFAdj,
00044     vcg::face::VertexRef,
00045   vcg::face::Normal3f,
00046     vcg::face::BitFlags > {};
00047 
00048 // the main mesh class
00049 class MyMesh : public vcg::tri::TriMesh<std::vector<MyVertex>, std::vector<MyFace> > {};
00050 
00051 
00052 
00053 // example 1: build a cube as a Zonohedron
00054 void example1(){
00055 
00056     vcg::tri::Zonohedron<float> z;
00057     z.addVector( 0,0,1 );
00058     z.addVector( 0,1,0 );
00059     z.addVector( 1,0,0 );
00060 
00061     MyMesh m;
00062     z.createMesh(m); // this will be a cube
00063 
00064     vcg::tri::UpdateTopology<MyMesh>::FaceFace(m); // needed by exporter
00065 
00066     int savemask = vcg::tri::io::Mask::IOM_BITPOLYGONAL;
00067     vcg::tri::io::ExporterOFF<MyMesh>::Save(m,"cube.off",savemask);
00068 }
00069 
00070 
00071 // example2: reads input file, builds zonohedra as described there
00072 void example2(){
00073 
00074     FILE* f = fopen("input.txt","rt");
00075     if (!f) return;
00076 
00077     while (1) {
00078 
00079         // read mesh name
00080         char meshFilename[1024], fullMeshFilename[1024];
00081         if (fscanf(f,"%s",meshFilename)!=1) break;
00082         sprintf(fullMeshFilename,"%s.off",meshFilename);
00083 
00084         // build input vector
00085         vcg::tri::Zonohedron<float> z;
00086         while (1) {
00087             float a,b,c;
00088             if (fscanf(f,"%f %f %f",&a, &b, &c)!=3) break;
00089             z.addVector(a,b,c);
00090         }
00091 
00092         printf("Building %s from %d vectors...\n",fullMeshFilename, z.vectors().size() );
00093 
00094         MyMesh m;
00095         z.createMesh(m);
00096 
00097         vcg::tri::UpdateTopology<MyMesh>::FaceFace(m); // needed by exporter
00098 
00099         // normally, faces with more than 4sides are split into parallelograms
00100         // this merges them (optional, try removing it!)
00101         vcg::tri::PolygonSupport<MyMesh,int>::MergeFlatFaces(m);
00102 
00103         int savemask = vcg::tri::io::Mask::IOM_BITPOLYGONAL;
00104         vcg::tri::io::ExporterOFF<MyMesh>::Save(m,fullMeshFilename,savemask);
00105     }
00106 
00107 }
00108 
00109 int main(int argc, char *argv[]){
00110     example1();
00111     example2();
00112     return 0;
00113 }


shape_reconstruction
Author(s): Roberto Martín-Martín
autogenerated on Sat Jun 8 2019 18:34:28