diff --git a/apps/quadrangulator/quadrangulator.cpp b/apps/quadrangulator/quadrangulator.cpp new file mode 100644 index 00000000..36c4febc --- /dev/null +++ b/apps/quadrangulator/quadrangulator.cpp @@ -0,0 +1,159 @@ +/**************************************************************************** +* VCGLib o o * +* Visual and Computer Graphics Library o o * +* _ O _ * +* Copyright(C) 2004-2012 \/)\/ * +* 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 + + +using namespace vcg; + +class CFace; +class CVertex; + +struct MyUsedTypes : public UsedTypes< Use::AsVertexType, Use::AsFaceType >{}; + +class CVertex : public Vertex< MyUsedTypes, + vertex::Coord3d, vertex::Normal3d, + vertex::BitFlags, vertex::VFAdj, + vertex::TexCoord2d, vertex::Qualityd>{}; + +class CFace : public Face< MyUsedTypes, face::VertexRef, + face::VFAdj, face::FFAdj, face::Normal3d, + face::WedgeTexCoord2d, face::BitFlags, face::CurvatureDird, + face::Qualityd, face::Color4b, face::Mark>{}; + +class CMesh : public tri::TriMesh< std::vector, std::vector >{}; + + +class MyPolyFace; +class MyPolyVertex; +struct PolyUsedTypes: public UsedTypes ::AsVertexType, + Use ::AsFaceType + >{}; + +class MyPolyVertex:public Vertex< PolyUsedTypes, + vertex::Coord3f, + vertex::Normal3f, + vertex::BitFlags>{} ; + +class MyPolyFace:public Face< PolyUsedTypes, + face::PolyInfo, // this is necessary if you use component in vcg/simplex/face/component_polygon.h + face::PFVAdj, // Pointer to the vertices (just like FVAdj ) + face::BitFlags, // bit flags + face::Normal3f // normal +> {}; + +class MyPolyMesh: public + tri::TriMesh< std::vector, + std::vector >{}; + + +using namespace std; + +int main(int argc, const char * argv[]) +{ + const char* configfile; + + if (argc != 2) + { + cout << "Not enough parameters: ./MIQ configfile" << endl; + exit(EXIT_FAILURE); + } + + configfile = argv[1]; + printf("configuration file %s",configfile); + fflush(stdout); + + // ********* Read parameters from config File ********* + FILE *fp= fopen(configfile,"r"); + if (fp==NULL) + { + printf("Cannot open config file %s\n",configfile); + return -1; + } + + char meshFilename[200]; fscanf(fp,"mesh=%s\n", meshFilename); + char fieldFilename[200]; fscanf(fp,"field=%s\n", fieldFilename); + int scalegradient; fscanf(fp,"scalegradient=%d\n", &scalegradient); + float GradientSize; fscanf(fp,"gradient=%f\n", &GradientSize); + int DirectRounding; fscanf(fp,"directround=%d\n", &DirectRounding); + char outFilename[200]; fscanf(fp,"out=%s\n", outFilename); + + fclose(fp); + + // other parameters not in the config file... + float Stiffness=4; + int iterationNum=10; + int localIterationNum=5; + + // ********* Start the processing ********* + // 1) Load, Prepare and Validate the mesh and field + + CMesh trimesh; + if (tri::io::Importer::Open(trimesh, meshFilename)!=0) + { + printf("error loading mesh file %s\n",meshFilename); + exit(0); + } + + tri::UpdateBounding::Box(trimesh); + tri::UpdateNormal::PerVertexNormalizedPerFaceNormalized(trimesh); + tri::UpdateTopology::FaceFace(trimesh); + tri::UpdateTopology::VertexFace(trimesh); + + if (std::string(fieldFilename).find(".ffield")==-1) + { + printf("error loading field file %s\n",fieldFilename); + exit(0); + } + bool field_loaded=tri::io::ImporterFIELD::LoadFFIELD(trimesh,fieldFilename); + if (!field_loaded) return false; + + if (scalegradient!=0) // If the gradient has not been specified try an educated guess + GradientSize*=1.0/trimesh.bbox.Diag(); + + if (! MIQ_parametrization::IsValid(trimesh) ) + { + printf("Mesh not valid for quadrangulation: \n" + "It must be a 2-manifold single connected component \n"); + exit(0); + } + + // 2) Do the actual Quadrangulation and save the result + + MyPolyMesh polymesh; + MIQ_parametrization::InitSeamsSing(trimesh,true,true,true); + MIQ_parametrization::Parametrize(trimesh,MIQ_parametrization::ITERATIVE,Stiffness,GradientSize,(bool)DirectRounding,iterationNum,localIterationNum,true); + + Quadrangulator Quad; + Quad.TestIsProper(trimesh); + Quad.Quadrangulate(trimesh,polymesh); + + tri::io::Exporter::Save(polymesh,outFilename); + +} + diff --git a/apps/quadrangulator/quadrangulator.pro b/apps/quadrangulator/quadrangulator.pro new file mode 100644 index 00000000..be5dfaa8 --- /dev/null +++ b/apps/quadrangulator/quadrangulator.pro @@ -0,0 +1,60 @@ +# IMPORTANT +# We assume that you have unzipped and compiled somewhere the COMISO solver +# put here that path and and the name of the build dir. +COMISODIR = ../../../code/lib/CoMISo +COMISOBUILDDIR = $$COMISODIR/buildMACOSX + + +QT += core +QT -= gui +TARGET = miq +TEMPLATE = app + +# This is needed by CoMISo +DEFINES += INCLUDE_TEMPLATES +INCLUDEPATH += $$COMISODIR/include +INCLUDEPATH += $$COMISODIR/Solver +INCLUDEPATH += $$COMISODIR/.. + +# just a shortcut +VCGLIBDIR = ../../../vcglib + +# include of vcg library +INCLUDEPATH += $$VCGLIBDIR + +# CORE +HEADERS += $$VCGLIBDIR/wrap/miq/core/vertex_indexing.h +HEADERS += $$VCGLIBDIR/wrap/miq/core/poisson_solver.h +HEADERS += $$VCGLIBDIR/wrap/miq/quadrangulator.h +HEADERS += $$VCGLIBDIR/wrap/miq/core/param_stats.h +HEADERS += $$VCGLIBDIR/wrap/miq/MIQ.h +HEADERS += $$VCGLIBDIR/wrap/miq/core/seams_initializer.h +HEADERS += $$VCGLIBDIR/wrap/miq/core/stiffening.h + +# VCG +HEADERS += $$VCGLIBDIR/vcg/complex/algorithms/parametrization/tangent_field_operators.h +HEADERS += $$VCGLIBDIR/vcg/complex/algorithms/parametrization/distortion.h +HEADERS += $$VCGLIBDIR/wrap/io_trimesh/import_field.h +HEADERS += $$VCGLIBDIR/wrap/io_trimesh/export_field.h +SOURCES += $$VCGLIBDIR/wrap/ply/plylib.cpp +SOURCES += main.cpp + +win32{ +# Awful problem with windows.. + DEFINES += NOMINMAX +} + +mac{ + CONFIG += console +# Mac specific Config required to avoid to make application bundles + CONFIG -= app_bundle + LIBS += -L/opt/local/lib -lamd -lcamd -lccolamd -lcholmod -lcolamd -lcxsparse -lblas -framework accelerate +} + +#Comiso +mac{ +LIBS += -L $$COMISOBUILDDIR/Build/lib/CoMISo/ -lCoMISo + QMAKE_POST_LINK +="install_name_tool -change @executable_path/../lib/CoMISo/libCoMISo.dylib @executable_path/libCoMISo.dylib $$TARGET ; " + QMAKE_POST_LINK +="cp -P $$COMISOBUILDDIR/Build/lib/CoMISo/libCoMISo.dylib . ; " +} +