quadrangulator.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-2012                                           \/)\/    *
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 #include <vcg/complex/complex.h>
00024 #include <vcg/complex/algorithms/update/topology.h>
00025 #include <vcg/complex/algorithms/parametrization/tangent_field_operators.h>
00026 #include <wrap/io_trimesh/import.h>
00027 #include <wrap/io_trimesh/export.h>
00028 #include <wrap/miq/MIQ.h>
00029 #include <wrap/miq/quadrangulator.h>
00030 
00031 
00032 using namespace vcg;
00033 
00034 class CFace;
00035 class CVertex;
00036 
00037 struct MyUsedTypes : public UsedTypes<  Use<CVertex>::AsVertexType, Use<CFace>::AsFaceType >{};
00038 
00039 class CVertex : public Vertex< MyUsedTypes,
00040         vertex::Coord3d,     vertex::Normal3d,
00041         vertex::BitFlags,    vertex::VFAdj,
00042         vertex::TexCoord2d,  vertex::Qualityd>{};
00043 
00044 class CFace   : public Face<  MyUsedTypes, face::VertexRef,
00045         face::VFAdj,            face::FFAdj,      face::Normal3d,
00046         face::WedgeTexCoord2d,  face::BitFlags,   face::CurvatureDird,
00047         face::Qualityd,         face::Color4b,    face::Mark>{};
00048 
00049 class CMesh   : public tri::TriMesh< std::vector<CVertex>, std::vector<CFace> >{};
00050 
00051 
00052 class MyPolyFace;
00053 class MyPolyVertex;
00054 struct PolyUsedTypes: public UsedTypes<Use<MyPolyVertex>        ::AsVertexType,
00055                                             Use<MyPolyFace>     ::AsFaceType
00056                                             >{};
00057 
00058 class MyPolyVertex:public Vertex<       PolyUsedTypes,
00059                                         vertex::Coord3f,
00060                                         vertex::Normal3f,
00061                                         vertex::BitFlags>{} ;
00062 
00063 class MyPolyFace:public Face<   PolyUsedTypes,
00064     face::PolyInfo, // this is necessary  if you use component in vcg/simplex/face/component_polygon.h
00065     face::PFVAdj,        // Pointer to the vertices (just like FVAdj )
00066     face::BitFlags, // bit flags
00067     face::Normal3f // normal
00068 > {};
00069 
00070 class MyPolyMesh: public
00071     tri::TriMesh<     std::vector<MyPolyVertex>,
00072                            std::vector<MyPolyFace >       >{};
00073 
00074 
00075 using namespace std;
00076 
00077 int main(int argc, const char * argv[])
00078 {
00079     const char* configfile;
00080 
00081     if (argc != 2)
00082     {
00083         cout << "Not enough parameters;\nUsage:\n\n./quadrangulator configfile" << endl;
00084         exit(EXIT_FAILURE);
00085     }
00086 
00087     configfile = argv[1];
00088     printf("configuration file %s",configfile);
00089     fflush(stdout);
00090 
00091     //  ********* Read parameters from config File *********
00092     FILE *fp= fopen(configfile,"r");
00093     if (fp==NULL)
00094     {
00095         printf("Cannot open config file %s\n",configfile);
00096         return -1;
00097     }
00098 
00099     char  meshFilename[200];      fscanf(fp,"mesh=%s\n", meshFilename);
00100     char  fieldFilename[200];     fscanf(fp,"field=%s\n", fieldFilename);
00101     int   scalegradient;          fscanf(fp,"scalegradient=%d\n", &scalegradient);
00102     float GradientSize;           fscanf(fp,"gradient=%f\n", &GradientSize);
00103     int   DirectRounding;         fscanf(fp,"directround=%d\n", &DirectRounding);
00104     char  outFilename[200];       fscanf(fp,"out=%s\n", outFilename);
00105 
00106     fclose(fp);
00107 
00108     // other parameters not in the config file...
00109     float Stiffness=4;
00110     int iterationNum=10;
00111     int localIterationNum=5;
00112 
00113     // ********* Start the processing *********
00114     // 1) Load, Prepare and Validate the mesh and field
00115 
00116     CMesh trimesh;
00117     if (tri::io::Importer<CMesh>::Open(trimesh, meshFilename)!=0)
00118     {
00119         printf("error loading mesh file %s\n",meshFilename);
00120         exit(0);
00121     }
00122 
00123     tri::UpdateBounding<CMesh>::Box(trimesh);
00124     tri::UpdateNormal<CMesh>::PerVertexNormalizedPerFaceNormalized(trimesh);
00125     tri::UpdateTopology<CMesh>::FaceFace(trimesh);
00126     tri::UpdateTopology<CMesh>::VertexFace(trimesh);
00127 
00128     if (std::string(fieldFilename).find(".ffield")==-1)
00129     {
00130         printf("error loading field file %s\n",fieldFilename);
00131         exit(0);
00132     }
00133     bool field_loaded=tri::io::ImporterFIELD<CMesh>::LoadFFIELD(trimesh,fieldFilename);
00134     if (!field_loaded) return false;
00135 
00136     if (scalegradient!=0) // If the gradient has not been specified try an educated guess
00137       GradientSize*=1.0/trimesh.bbox.Diag();
00138 
00139     if (! MIQ_parametrization<CMesh>::IsValid(trimesh) )
00140     {
00141         printf("Mesh not valid for quadrangulation: \n"
00142                "It must be a 2-manifold single connected component \n");
00143         exit(0);
00144     }
00145 
00146     // 2) Do the actual Quadrangulation and save the result
00147 
00148     MyPolyMesh polymesh;
00149     MIQ_parametrization<CMesh>::InitSeamsSing(trimesh,true,true,true);
00150     MIQ_parametrization<CMesh>::Parametrize(trimesh,MIQ_parametrization<CMesh>::ITERATIVE,Stiffness,GradientSize,(bool)DirectRounding,iterationNum,localIterationNum,true);
00151 
00152     Quadrangulator<CMesh,MyPolyMesh> Quad;
00153     Quad.TestIsProper(trimesh);
00154     Quad.Quadrangulate(trimesh,polymesh);
00155 
00156     tri::io::Exporter<MyPolyMesh>::Save(polymesh,outFilename);
00157 
00158 }
00159 


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