2012-10-15 03:15:04 +02:00
|
|
|
#ifndef __MIQ__
|
|
|
|
#define __MIQ__
|
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
#include "quadrangulator.h"
|
2012-10-17 14:34:26 +02:00
|
|
|
#include "core/poisson_solver.h"
|
|
|
|
#include "core/param_stats.h"
|
|
|
|
#include "core/seams_initializer.h"
|
|
|
|
#include "core/vertex_indexing.h"
|
|
|
|
#include "core/stiffening.h"
|
2012-10-16 17:28:15 +02:00
|
|
|
#include <vcg/complex/algorithms/clean.h>
|
2012-10-15 03:15:04 +02:00
|
|
|
|
|
|
|
#define USECOMISO
|
|
|
|
|
2012-10-16 17:28:15 +02:00
|
|
|
template <class MeshType>
|
|
|
|
class MIQ_parametrization{
|
2012-10-15 03:15:04 +02:00
|
|
|
|
|
|
|
public:
|
|
|
|
typename MeshType::template PerFaceAttributeHandle<float> Handle_Stiffness;
|
|
|
|
|
|
|
|
// Different stiffening mode
|
|
|
|
enum StiffMode{NO_STIFF = 0,GAUSSIAN = 1,ITERATIVE = 2};
|
|
|
|
|
|
|
|
// Parametrize the mesh
|
2012-10-16 17:28:15 +02:00
|
|
|
static void DoParameterize(MeshType &mesh,StiffMode stiffMode,
|
|
|
|
double Stiffness = 5.0,double GradientSize = 30.0,
|
|
|
|
bool DirectRound = false,int iter = 5,
|
|
|
|
int localIter = 5, bool DoRound = true)
|
2012-10-15 03:15:04 +02:00
|
|
|
{
|
2012-10-16 17:28:15 +02:00
|
|
|
PoissonSolver<MeshType> PSolver(mesh);
|
2012-10-15 03:15:04 +02:00
|
|
|
if (mesh.fn==0)return;
|
2012-10-16 17:28:15 +02:00
|
|
|
StiffeningInitializer<MeshType>::InitDefaultStiffening(mesh);
|
2012-10-15 03:15:04 +02:00
|
|
|
if (stiffMode==GAUSSIAN)
|
|
|
|
{
|
2012-10-16 17:28:15 +02:00
|
|
|
StiffeningInitializer<MeshType>::AddGaussStiffening(mesh,Stiffness);
|
2012-10-15 03:15:04 +02:00
|
|
|
PSolver.SolvePoisson(GradientSize,1.f,DirectRound,localIter,DoRound);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
if (stiffMode==ITERATIVE)
|
|
|
|
{
|
|
|
|
for (int i=0;i<iter;i++)
|
|
|
|
{
|
|
|
|
PSolver.SolvePoisson(GradientSize,1.f,DirectRound,localIter,DoRound);
|
|
|
|
int nflips=NumFlips(mesh);
|
2012-10-16 17:28:15 +02:00
|
|
|
bool folded=StiffeningInitializer<MeshType>::updateStiffeningJacobianDistorsion(mesh,GradientSize);
|
2012-10-15 03:15:04 +02:00
|
|
|
printf("ITERATION %d FLIPS %d \n",i,nflips);
|
|
|
|
if (!folded)break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
if (stiffMode==NO_STIFF)
|
|
|
|
{
|
|
|
|
PSolver.SolvePoisson(GradientSize,1.f,DirectRound,localIter,DoRound);
|
|
|
|
}
|
|
|
|
int nflips=NumFlips(mesh);
|
|
|
|
printf("**** END OPTIMIZING #FLIPS %d ****\n",nflips);
|
|
|
|
fflush(stdout);
|
|
|
|
SelectFlippedFaces(mesh);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2012-10-16 17:28:15 +02:00
|
|
|
public:
|
2012-10-15 03:15:04 +02:00
|
|
|
|
2012-10-16 17:28:15 +02:00
|
|
|
static bool IsValid(MeshType &mesh)
|
2012-10-15 03:15:04 +02:00
|
|
|
{
|
2012-10-16 17:28:15 +02:00
|
|
|
int n_comp=vcg::tri::Clean<MeshType>::CountConnectedComponents(mesh);
|
|
|
|
int non_manifE=vcg::tri::Clean<MeshType>::CountNonManifoldEdgeFF(mesh);
|
|
|
|
int non_manifV=vcg::tri::Clean<MeshType>::CountNonManifoldVertexFF(mesh);
|
|
|
|
return ((n_comp==1)&&(non_manifE==0)&&(non_manifV==0));
|
2012-10-15 03:15:04 +02:00
|
|
|
}
|
2012-10-16 17:28:15 +02:00
|
|
|
static void InitSeamsSing(MeshType &mesh,
|
|
|
|
bool orient_globally,
|
|
|
|
bool initMM,
|
|
|
|
bool initCuts)
|
2012-10-15 03:15:04 +02:00
|
|
|
{
|
2012-10-16 17:28:15 +02:00
|
|
|
SeamsInitializer<MeshType> SInit;
|
|
|
|
SInit.Init(&mesh,orient_globally,initMM,initCuts);
|
2012-10-15 03:15:04 +02:00
|
|
|
}
|
|
|
|
|
2012-10-16 17:28:15 +02:00
|
|
|
static void Parametrize(MeshType &mesh,StiffMode stiffMode,
|
|
|
|
double Stiffness = 5.0,
|
|
|
|
double GradientSize = 30.0,
|
|
|
|
bool DirectRound = false,int iter = 5,
|
|
|
|
int localIter = 5, bool DoRound = true)
|
2012-10-15 03:15:04 +02:00
|
|
|
{
|
2012-10-16 17:28:15 +02:00
|
|
|
VertexIndexing<MeshType> VInd;
|
2012-10-15 03:15:04 +02:00
|
|
|
|
2012-10-16 17:28:15 +02:00
|
|
|
VInd.Init(&mesh);
|
|
|
|
VInd.InitMapping();
|
|
|
|
VInd.InitFaceIntegerVal();
|
|
|
|
VInd.InitSeamInfo();
|
2012-10-15 03:15:04 +02:00
|
|
|
|
2012-10-16 17:28:15 +02:00
|
|
|
DoParameterize(mesh,stiffMode,Stiffness,GradientSize,DirectRound,iter,localIter , DoRound);
|
2012-10-15 03:15:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|