diff --git a/wrap/miq/MIQ.h b/wrap/miq/MIQ.h index 430f4363..f5185328 100644 --- a/wrap/miq/MIQ.h +++ b/wrap/miq/MIQ.h @@ -1,11 +1,6 @@ #ifndef __MIQ__ #define __MIQ__ - -#define SIZEQUADS 512 -#define V_SIZE 1 -#define SIZEPARA 1024 - #include #include #include "mesh_type.h" @@ -14,24 +9,15 @@ #include "param_stats.h" #include "seams_initializer.h" #include "vertex_indexing.h" - +#include "stiffening.h" +#include #include #include #define USECOMISO -template -ScalarType Gauss(ScalarType &value) -{ - const ScalarType E_NEPER=2.71828; - const ScalarType den=sqrt(2.0*M_PI); - ScalarType exponent=-0.5*pow(value,2); - ScalarType res=((1.0/den)*pow(E_NEPER,exponent)); - return res; -} - -template -class MIQ{ +template +class MIQ_parametrization{ public: typename MeshType::template PerFaceAttributeHandle Handle_Stiffness; @@ -39,20 +25,18 @@ public: // Different stiffening mode enum StiffMode{NO_STIFF = 0,GAUSSIAN = 1,ITERATIVE = 2}; - // Init - MIQ(MeshType &_mesh):mesh(_mesh),PSolver(mesh){}; - - // Parametrize the mesh - void Solve(StiffMode stiffMode, double Stiffness = 5.0, - double GradientSize = 30.0, bool DirectRound = false, - int iter = 5, int localIter = 5, bool DoRound = true) + 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) { + PoissonSolver PSolver(mesh); if (mesh.fn==0)return; - InitDefaultStiffening(); + StiffeningInitializer::InitDefaultStiffening(mesh); if (stiffMode==GAUSSIAN) { - AddGaussStiffening(Stiffness); + StiffeningInitializer::AddGaussStiffening(mesh,Stiffness); PSolver.SolvePoisson(GradientSize,1.f,DirectRound,localIter,DoRound); } else @@ -62,9 +46,7 @@ public: { PSolver.SolvePoisson(GradientSize,1.f,DirectRound,localIter,DoRound); int nflips=NumFlips(mesh); - ScaleGLtoInt(); - bool folded=updateStiffening(GradientSize); - ScaleInttoGL(); + bool folded=StiffeningInitializer::updateStiffeningJacobianDistorsion(mesh,GradientSize); printf("ITERATION %d FLIPS %d \n",i,nflips); if (!folded)break; } @@ -78,203 +60,43 @@ public: printf("**** END OPTIMIZING #FLIPS %d ****\n",nflips); fflush(stdout); SelectFlippedFaces(mesh); - UpdateUVBox(); + } - // Generate a quad mesh starting from the parametrization - void Quadrangulate(PolyMesh &poly,double factor = 1) - { - Quad.Quadrangulate(mesh,poly,factor); - } - - // Bounding box of the param domain - vcg::Box2 UVBox; - - void ScaleGLtoInt() - { - double factor=(double)SIZEPARA/(double)SIZEQUADS; - for (unsigned int i=0;i Quad; - - void colorByStiffening(typename MeshType::ScalarType MaxVal=16) - { - bool hasStiffness = vcg::tri::HasPerFaceAttribute(mesh,std::string("Stiffness")); - assert(hasStiffness); - for (unsigned int i=0;i::AddPerFaceAttribute(mesh,std::string("Stiffness")); - - bool hasSingular = vcg::tri::HasPerVertexAttribute(mesh,std::string("Singular")); - assert(hasSingular); - CMesh::PerVertexAttributeHandle Handle_Singular; - Handle_Singular=vcg::tri::Allocator::GetPerVertexAttribute(mesh,std::string("Singular")); - - std::vector to_stiff; - for(unsigned int i=0;iIsD())continue; - //if (!v->IsSingular())continue; - if (!Handle_Singular[v])continue; - to_stiff.push_back(v); - } - for(unsigned int i=0;iIsD())continue; - if (!f->IsV())continue; - to_stiff.push_back(f->V(0)); - to_stiff.push_back(f->V(1)); - to_stiff.push_back(f->V(2)); - } - std::sort(to_stiff.begin(),to_stiff.end()); - std::vector::iterator new_end=std::unique(to_stiff.begin(),to_stiff.end()); - int dist=distance(to_stiff.begin(),new_end); - to_stiff.resize(dist); - for (unsigned int i=0;i ring; - //mesh.GetConnectedFaces(v,r,ring); - VFExtendedStarVF(v,r,ring); - ///then set stiffening - for (unsigned int k=0;kstiffeningstiffening=stiffVal; - if (Handle_Stiffness[f]::AddPerFaceAttribute(mesh,std::string("Stiffness")); - - bool flipped = NumFlips(mesh)>0; - //if (h == 0.0) - // return flipped; - // - //assert(h != 0.0); - - if (!flipped) - return false; - CMesh::ScalarType maxL=0; - CMesh::ScalarType maxD=0; - if (flipped) - { - const double c = 1.0; - const double d = 5.0; - - for (unsigned int i = 0; i < mesh.face.size(); ++i) - { - CMesh::ScalarType dist=Distortion(mesh.face[i],grad_size); - if (dist>maxD)maxD=dist; - CMesh::ScalarType absLap=fabs(LaplaceDistortion(mesh.face[i], grad_size)); - if (absLap>maxL)maxL=absLap; - CMesh::ScalarType stiffDelta = std::min(c * absLap, d); - //mesh.face[i].stiffening+=stiffDelta; - Handle_Stiffness[i]+=stiffDelta; - } - } - printf("Maximum Distorsion %4.4f \n",maxD); - printf("Maximum Laplacian %4.4f \n",maxL); - return flipped; - } - - void InitDefaultStiffening() - { - bool hasStiffness = vcg::tri::HasPerFaceAttribute(mesh,std::string("Stiffness")); - if(!hasStiffness) - Handle_Stiffness=vcg::tri::Allocator::AddPerFaceAttribute(mesh,std::string("Stiffness")); - - for(unsigned int i=0;istiffening=1; - Handle_Stiffness[f]=1; - } - } - - void AddGaussStiffening(typename MeshType::ScalarType C) - { - int radius=floor(C); - if (C<4)radius=4; - AddStiffening(C,radius); - } public: - // Mesh class - MeshType &mesh; - // Quad mesh class - //CMesh quadmesh; + static bool IsValid(MeshType &mesh) + { + int n_comp=vcg::tri::Clean::CountConnectedComponents(mesh); + int non_manifE=vcg::tri::Clean::CountNonManifoldEdgeFF(mesh); + int non_manifV=vcg::tri::Clean::CountNonManifoldVertexFF(mesh); + return ((n_comp==1)&&(non_manifE==0)&&(non_manifV==0)); + } + static void InitSeamsSing(MeshType &mesh, + bool orient_globally, + bool initMM, + bool initCuts) + { + SeamsInitializer SInit; + SInit.Init(&mesh,orient_globally,initMM,initCuts); + } - ///seams initializer - SeamsInitializer SInit; + 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) + { + VertexIndexing VInd; - // Vertex indexing class used for the solver - VertexIndexing VInd; + VInd.Init(&mesh); + VInd.InitMapping(); + VInd.InitFaceIntegerVal(); + VInd.InitSeamInfo(); + + DoParameterize(mesh,stiffMode,Stiffness,GradientSize,DirectRound,iter,localIter , DoRound); + } - // Poisson solver - PoissonSolver PSolver; };