Cleaning up the quadrangulator application

This commit is contained in:
Paolo Cignoni 2012-10-18 16:03:57 +00:00
parent 51534fc79a
commit 5ba6675838
2 changed files with 134 additions and 108 deletions

View File

@ -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 . ; "
}

View File

@ -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 <vcg/complex/complex.h>
#include <vcg/complex/algorithms/update/topology.h>
#include <vcg/complex/algorithms/parametrization/tangent_field_operators.h>
#include <wrap/io_trimesh/import.h>
#include <wrap/io_trimesh/export.h>
#include <wrap/miq/MIQ.h>
#include <wrap/miq/quadrangulator.h>
#include <wrap/io_trimesh/import_ply.h>
#include <wrap/io_trimesh/import_off.h>
#include <wrap/io_trimesh/import_obj.h>
using namespace vcg;
class CFace;
class CVertex;
struct MyUsedTypes : public UsedTypes< Use<CVertex>::AsVertexType, Use<CFace>::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<CVertex>, std::vector<CFace> >{};
class MyPolyFace;
class MyPolyVertex;
struct PolyUsedTypes: public UsedTypes<Use<MyPolyVertex> ::AsVertexType,
Use<MyPolyFace> ::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<MyPolyVertex>,
std::vector<MyPolyFace > >{};
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<CMesh>::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<CMesh>::LoadMask(PathMesh.c_str(),mask);
if (!readed)return false;
int err=vcg::tri::io::ImporterOBJ<CMesh>::Open(trimesh,PathMesh.c_str(),mask);
return (err==vcg::tri::io::ImporterOBJ<CMesh>::E_NOERROR);
}
position=PathMesh.find(".off");
assert(position!=-1);
int mask;
bool readed=vcg::tri::io::ImporterOFF<CMesh>::LoadMask(PathMesh.c_str(),mask);
if (!readed)return false;
int err=vcg::tri::io::ImporterOFF<CMesh>::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<CMesh>::Box(trimesh);
vcg::tri::UpdateNormal<CMesh>::PerVertexNormalizedPerFace(trimesh);
vcg::tri::UpdateNormal<CMesh>::PerFaceNormalized(trimesh);
vcg::tri::UpdateTopology<CMesh>::FaceFace(trimesh);
vcg::tri::UpdateTopology<CMesh>::VertexFace(trimesh);
vcg::tri::UpdateFlags<CMesh>::FaceBorderFromFF(trimesh);
vcg::tri::UpdateFlags<CMesh>::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<CMesh>::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<CMesh>::Open(trimesh, meshFilename)!=0)
{
printf("error output mesh file \n");
printf("error loading mesh file %s\n",meshFilename);
exit(0);
}
bool isvalid=MIQ_parametrization<CMesh>::IsValid(trimesh);
if (!isvalid)
tri::UpdateBounding<CMesh>::Box(trimesh);
tri::UpdateNormal<CMesh>::PerVertexNormalizedPerFaceNormalized(trimesh);
tri::UpdateTopology<CMesh>::FaceFace(trimesh);
tri::UpdateTopology<CMesh>::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<CMesh>::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<CMesh>::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<CMesh>::InitSeamsSing(trimesh,true,true,true);
MIQ_parametrization<CMesh>::Parametrize(trimesh,MIQ_parametrization<CMesh>::ITERATIVE,Stiffness,GradientSize,(bool)DirectRound,iter,localIter,true);
MIQ_parametrization<CMesh>::Parametrize(trimesh,MIQ_parametrization<CMesh>::ITERATIVE,Stiffness,GradientSize,(bool)DirectRounding,iterationNum,localIterationNum,true);
Quadrangulator<CMesh,MyPolyMesh> Quad;
Quad.TestIsProper(trimesh);
Quad.Quadrangulate(trimesh,polymesh);
vcg::tri::io::ExporterOBJ<MyPolyMesh>::Save(polymesh,out.c_str(),0);
fclose(f);
tri::io::Exporter<MyPolyMesh>::Save(polymesh,outFilename);
}