diff --git a/apps/miq_commandline/MIQ.pro b/apps/miq_commandline/MIQ.pro index c085cf0b..be5dfaa8 100644 --- a/apps/miq_commandline/MIQ.pro +++ b/apps/miq_commandline/MIQ.pro @@ -1,10 +1,13 @@ -include (./predefinitions.pro) +# 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 @@ -13,19 +16,20 @@ 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/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/glUtils.h HEADERS += $$VCGLIBDIR/wrap/miq/core/seams_initializer.h HEADERS += $$VCGLIBDIR/wrap/miq/core/stiffening.h -#SOURCES += $$VCGLIBDIR/wrap/miq/MIQ.cpp # VCG HEADERS += $$VCGLIBDIR/vcg/complex/algorithms/parametrization/tangent_field_operators.h @@ -35,17 +39,22 @@ HEADERS += $$VCGLIBDIR/wrap/io_trimesh/export_field.h SOURCES += $$VCGLIBDIR/wrap/ply/plylib.cpp SOURCES += main.cpp -# Awful problem with windows.. win32{ +# Awful problem with windows.. DEFINES += NOMINMAX } mac{ -# Mac specific Config required to avoid to make application bundles CONFIG += console +# Mac specific Config required to avoid to make application bundles CONFIG -= app_bundle - LIBS += -framework OpenGL 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 . ; " +} diff --git a/apps/miq_commandline/main.cpp b/apps/miq_commandline/main.cpp index 7f685e15..36c4febc 100644 --- a/apps/miq_commandline/main.cpp +++ b/apps/miq_commandline/main.cpp @@ -1,40 +1,78 @@ -#include "mesh_type.h" +/**************************************************************************** +* 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 -#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; -CMesh trimesh; -MyPolyMesh polymesh; - -bool OpenTriMesh(std::string PathMesh) -{ - int position; - position=PathMesh.find(".ply"); - if (position!=-1) - { - int err=vcg::tri::io::ImporterPLY::Open(trimesh,PathMesh.c_str()); - return (err==vcg::ply::E_NOERROR); - } - position=PathMesh.find(".obj"); - if (position!=-1) - { - int mask; - bool readed=vcg::tri::io::ImporterOBJ::LoadMask(PathMesh.c_str(),mask); - if (!readed)return false; - int err=vcg::tri::io::ImporterOBJ::Open(trimesh,PathMesh.c_str(),mask); - return (err==vcg::tri::io::ImporterOBJ::E_NOERROR); - } - position=PathMesh.find(".off"); - assert(position!=-1); - int mask; - bool readed=vcg::tri::io::ImporterOFF::LoadMask(PathMesh.c_str(),mask); - if (!readed)return false; - int err=vcg::tri::io::ImporterOFF::Open(trimesh,PathMesh.c_str(),mask); - return (err==0); -} int main(int argc, const char * argv[]) { @@ -50,93 +88,72 @@ int main(int argc, const char * argv[]) printf("configuration file %s",configfile); fflush(stdout); - // Read Config File - FILE *f= fopen(configfile,"r"); - if (f==NULL) + // ********* Read parameters from config File ********* + FILE *fp= fopen(configfile,"r"); + if (fp==NULL) { - printf("Cannot open config file\n"); + printf("Cannot open config file %s\n",configfile); return -1; } - char buff[200]; - // Mesh name - fscanf(f,"mesh=%s\n",&buff[0]); - std::string filename = std::string(buff); - printf("FILENAME %s",filename.c_str()); - fflush(stdout); - bool opened=OpenTriMesh(filename); - if (!opened) - { - printf("error loading mesh file \n"); - exit(0); - } + 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); - vcg::tri::UpdateBounding::Box(trimesh); - vcg::tri::UpdateNormal::PerVertexNormalizedPerFace(trimesh); - vcg::tri::UpdateNormal::PerFaceNormalized(trimesh); - vcg::tri::UpdateTopology::FaceFace(trimesh); - vcg::tri::UpdateTopology::VertexFace(trimesh); - vcg::tri::UpdateFlags::FaceBorderFromFF(trimesh); - vcg::tri::UpdateFlags::VertexBorderFromFace(trimesh); + fclose(fp); - // Field name - fscanf(f,"field=%s\n",&buff[0]); - std::string fieldname = std::string(buff); - int position=fieldname.find(".ffield"); - if (position==-1) - { - printf("error loading mesh file \n"); - exit(0); - } - bool field_loaded=vcg::tri::io::ImporterFIELD::LoadFFIELD(trimesh,fieldname.c_str()); - if (!field_loaded)return false; - - int scalegradient; - fscanf(f,"scalegradient=%d\n",&scalegradient); - - // Gradient Size - float GradientSize; - fscanf(f,"gradient=%f\n",&GradientSize); - if (scalegradient!=0) - GradientSize*=1.0/trimesh.bbox.Diag(); - - // Stiffness + // other parameters not in the config file... float Stiffness=4; + int iterationNum=10; + int localIterationNum=5; - // DirectRounding - int DirectRound; - fscanf(f,"directround=%d\n",&DirectRound); + // ********* Start the processing ********* + // 1) Load, Prepare and Validate the mesh and field - // Number of iterations - int iter=10; - - // Number of local iterations - int localIter=5; - - // Output name - fscanf(f,"out=%s\n",&buff[0]); - std::string out = std::string(buff); - position=out.find(".obj"); - if (position==-1) + CMesh trimesh; + if (tri::io::Importer::Open(trimesh, meshFilename)!=0) { - printf("error output mesh file \n"); + printf("error loading mesh file %s\n",meshFilename); exit(0); } - bool isvalid=MIQ_parametrization::IsValid(trimesh); - if (!isvalid) + tri::UpdateBounding::Box(trimesh); + tri::UpdateNormal::PerVertexNormalizedPerFaceNormalized(trimesh); + tri::UpdateTopology::FaceFace(trimesh); + tri::UpdateTopology::VertexFace(trimesh); + + if (std::string(fieldFilename).find(".ffield")==-1) { - printf("mesh not valid for parametrization \n"); + 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)DirectRound,iter,localIter,true); + MIQ_parametrization::Parametrize(trimesh,MIQ_parametrization::ITERATIVE,Stiffness,GradientSize,(bool)DirectRounding,iterationNum,localIterationNum,true); Quadrangulator Quad; Quad.TestIsProper(trimesh); Quad.Quadrangulate(trimesh,polymesh); - vcg::tri::io::ExporterOBJ::Save(polymesh,out.c_str(),0); - fclose(f); + tri::io::Exporter::Save(polymesh,outFilename); + }