From b0c8146df4c7cf4fb4bfae280b6b1a3df250aecf Mon Sep 17 00:00:00 2001 From: Paolo Cignoni cignoni Date: Thu, 16 Jun 2011 14:48:23 +0000 Subject: [PATCH] Updated the whole isoparametrization framework to the new local optimization framework by flipping to the new local optimization framework. --- .../dual_coord_optimization.h | 8 +- .../filter_isoparametrization.cpp | 3 +- .../iso_parametrization.h | 18 ++-- .../local_optimization.h | 4 +- .../local_parametrization.h | 31 +++---- .../param_collapse.h | 83 +++++++++++-------- .../filter_isoparametrization/param_flip.h | 16 ++-- .../parametrizator.h | 59 +++++++------ .../texcoord_optimization.h | 3 +- 9 files changed, 118 insertions(+), 107 deletions(-) diff --git a/src/meshlabplugins/filter_isoparametrization/dual_coord_optimization.h b/src/meshlabplugins/filter_isoparametrization/dual_coord_optimization.h index 581d0d937..bb7be5475 100644 --- a/src/meshlabplugins/filter_isoparametrization/dual_coord_optimization.h +++ b/src/meshlabplugins/filter_isoparametrization/dual_coord_optimization.h @@ -267,7 +267,7 @@ public: { inDomain.push_back(test); ///parametrize it - GetUV(father,bary,test->T().U(),test->T().V()); + InterpolateUV(father,bary,test->T().U(),test->T().V()); } } ///create Hres mesh already parametrized @@ -333,7 +333,7 @@ public: { inDomain.push_back(test); ///parametrize it - GetUV(father,bary,test->T().U(),test->T().V()); + InterpolateUV(father,bary,test->T().U(),test->T().V()); } } ///create Hres mesh already parametrized @@ -388,7 +388,7 @@ public: FaceType * father=test->father; assert(father==f0); CoordType bary=test->Bary; - GetUV(father,bary,test->T().U(),test->T().V()); + InterpolateUV(father,bary,test->T().U(),test->T().V()); } ///create Hres mesh already parametrized std::vector OrderedFaces; @@ -659,4 +659,4 @@ public: } } }; -#endif \ No newline at end of file +#endif diff --git a/src/meshlabplugins/filter_isoparametrization/filter_isoparametrization.cpp b/src/meshlabplugins/filter_isoparametrization/filter_isoparametrization.cpp index f107d8bfa..c0e993db5 100644 --- a/src/meshlabplugins/filter_isoparametrization/filter_isoparametrization.cpp +++ b/src/meshlabplugins/filter_isoparametrization/filter_isoparametrization.cpp @@ -295,7 +295,8 @@ bool FilterIsoParametrization::applyFilter(QAction *filter, MeshDocument& md, Ri case 3:Parametrizator.SetParameters(cb,targetAbstractMinFaceNum,tolerance,IsoParametrizator::SM_L2,convergenceSpeed);break; default:Parametrizator.SetParameters(cb,targetAbstractMinFaceNum,tolerance,IsoParametrizator::SM_Euristic,convergenceSpeed);break; } - IsoParametrizator::ReturnCode ret=Parametrizator.Parametrize(mesh,doublestep); + tri::ParamEdgeCollapseParameter pecp; + IsoParametrizator::ReturnCode ret=Parametrizator.Parametrize(mesh,pecp,doublestep); if (ret==IsoParametrizator::Done) { diff --git a/src/meshlabplugins/filter_isoparametrization/iso_parametrization.h b/src/meshlabplugins/filter_isoparametrization/iso_parametrization.h index eeb699c47..2ca09ef8e 100644 --- a/src/meshlabplugins/filter_isoparametrization/iso_parametrization.h +++ b/src/meshlabplugins/filter_isoparametrization/iso_parametrization.h @@ -844,14 +844,10 @@ private: void Clamp(vcg::Point2f &UV) { float eps=0.00001f; - if ((UV.X()-eps)) - UV.X()=0; - if ((UV.X()<1+eps)&&(UV.X()>1-eps)) - UV.X()=1; - if ((UV.Y()-eps)) - UV.Y()=0; - if ((UV.Y()<1+eps)&&(UV.Y()>1-eps)) - UV.Y()=1; + if (UV.X() < eps) UV.X()=0; + if (UV.X()>1-eps) UV.X()=1; + if (UV.Y() < eps) UV.Y()=0; + if (UV.Y()>1-eps) UV.Y()=1; } @@ -1218,7 +1214,7 @@ public: vcg::Point2 UV_interp=bary3D.X()*UVd0+bary3D.Y()*UVd1+bary3D.Z()*UVd2; inv_GE1(EdgeIndex,UV_interp,I,UV); Clamp(UV); - assert((UV.X()>=0)&&(UV.Y()>=0)&&(UV.X()<=1)&&(UV.Y()<=1)&&(UV.X()+UV.Y()<=1+eps)); + //assert((UV.X()>=0)&&(UV.Y()>=0)&&(UV.X()<=1)&&(UV.Y()<=1)&&(UV.X()+UV.Y()<=1+eps)); assert((I==I0)||(I==I1)||(I==I2)); return; } @@ -1351,7 +1347,7 @@ public: if (LocalIndex==-1) return false; - GetUV(&star_domain->face[LocalIndex],bary,UVHstar.X(),UVHstar.Y()); + InterpolateUV(&star_domain->face[LocalIndex],bary,UVHstar.X(),UVHstar.Y()); return true; } @@ -1407,7 +1403,7 @@ public: int LocalIndex=diamond_meshes[DiamIndex].Global2Local(I); if(LocalIndex!=-1) { - GetUV(&diam_domain->face[LocalIndex],bary,UVDiam.X(),UVDiam.Y()); + InterpolateUV(&diam_domain->face[LocalIndex],bary,UVDiam.X(),UVDiam.Y()); return; } ///if ! found seach in the star space diff --git a/src/meshlabplugins/filter_isoparametrization/local_optimization.h b/src/meshlabplugins/filter_isoparametrization/local_optimization.h index f718a4c0d..c33ec2679 100644 --- a/src/meshlabplugins/filter_isoparametrization/local_optimization.h +++ b/src/meshlabplugins/filter_isoparametrization/local_optimization.h @@ -86,7 +86,7 @@ typename MeshType::ScalarType StarDistorsion(typename MeshType::VertexType *v) ///interpolate U V per vertex CoordType bary=test_face->vertices_bary[i].second; ScalarType u,v; - GetUV(parametric_face,bary,u,v); + InterpolateUV(parametric_face,bary,u,v); VertexType* to_parametrize=test_face->vertices_bary[i].first; to_parametrize->T().U()=u; @@ -145,7 +145,7 @@ void OptimizeStar(typename MeshType::VertexType *v,MeshType &domain,int accuracy ///interpolate U V per vertex CoordType bary=test_face->vertices_bary[i].second; ScalarType u,v; - GetUV(parametric_face,bary,u,v); + InterpolateUV(parametric_face,bary,u,v); VertexType* to_parametrize=test_face->vertices_bary[i].first; to_parametrize->T().U()=u; diff --git a/src/meshlabplugins/filter_isoparametrization/local_parametrization.h b/src/meshlabplugins/filter_isoparametrization/local_parametrization.h index 679206ea9..2c66c4e23 100644 --- a/src/meshlabplugins/filter_isoparametrization/local_parametrization.h +++ b/src/meshlabplugins/filter_isoparametrization/local_parametrization.h @@ -763,7 +763,9 @@ bool testBaryCoords(CoordType &bary) template bool NormalizeBaryCoords(CoordType &bary) { - ScalarType EPS=(ScalarType)0.00000001; + typedef typename CoordType::ScalarType ScalarType; + + ScalarType EPS=(ScalarType)0.00000001; bool isOK=testBaryCoords(bary); if (!isOK) return false; @@ -771,20 +773,14 @@ bool NormalizeBaryCoords(CoordType &bary) typedef typename CoordType::ScalarType ScalarType; ///test <0 - if (bary.X()<0) - bary.X()=EPS; - if (bary.Y()<0) - bary.Y()=EPS; - if (bary.Z()<0) - bary.Z()=EPS; + if (bary.X()<0) bary.X()=EPS; + if (bary.Y()<0) bary.Y()=EPS; + if (bary.Z()<0) bary.Z()=EPS; ///test >1 - if (bary.X()>1.0) - bary.X()=EPS; - if (bary.Y()>1.0) - bary.Y()=EPS; - if (bary.Z()>1.0) - bary.Z()=EPS; + if (bary.X()>1.0) bary.X()=1.0-EPS; + if (bary.Y()>1.0) bary.Y()=1.0-EPS; + if (bary.Z()>1.0) bary.Z()=1.0-EPS; ///test sum ScalarType diff=bary.X()+bary.Y()+bary.Z()-1.0; @@ -799,7 +795,7 @@ template void AssingFather(typename MeshType::VertexType &v, typename MeshType::FaceType *father, typename MeshType::CoordType &bary, - MeshType & domain) + MeshType & /*domain*/) { #ifdef _DEBUG const typename MeshType::ScalarType eps=(typename MeshType::ScalarType)0.00001; @@ -818,8 +814,7 @@ void AssingFather(typename MeshType::VertexType &v, template bool testParametrization(MeshType &domain, - MeshType &Hlev, - bool correct=true) + MeshType &Hlev) { typedef typename MeshType::FaceType FaceType; typedef typename MeshType::CoordType CoordType; @@ -1164,7 +1159,7 @@ void ParametrizeLocally(MeshType ¶metrized, template -void GetUV(const typename MeshType::FaceType* f, +void InterpolateUV(const typename MeshType::FaceType* f, const typename MeshType::CoordType &bary, typename MeshType::ScalarType &U, typename MeshType::ScalarType &V) @@ -1430,7 +1425,7 @@ void ParametrizeStarEquilateral(typename MeshType::VertexType *center, { FaceType *father=HresVert[i]->father; CoordType Bary=HresVert[i]->Bary; - GetUV(father,Bary,HresVert[i]->T().U(),HresVert[i]->T().V()); + InterpolateUV(father,Bary,HresVert[i]->T().U(),HresVert[i]->T().V()); } } diff --git a/src/meshlabplugins/filter_isoparametrization/param_collapse.h b/src/meshlabplugins/filter_isoparametrization/param_collapse.h index 53e45c9ff..ef63dc57a 100644 --- a/src/meshlabplugins/filter_isoparametrization/param_collapse.h +++ b/src/meshlabplugins/filter_isoparametrization/param_collapse.h @@ -20,10 +20,28 @@ #include "opt_patch.h" #include "local_optimization.h" -template -class ParamEdgeCollapse: public vcg::tri::TriEdgeCollapse > { +namespace vcg{ +namespace tri{ + +typedef vcg::tri::BasicVertexPair VertexPair; + +class ParamEdgeCollapseParameter : public vcg::BaseParameterClass +{ +private: + EnergyType E; + int _acc; + BaseMesh* mesh; + public: - typedef vcg::tri::TriEdgeCollapse > Super; + int &Accuracy() { return _acc;} + BaseMesh* &HresMesh() { return mesh; } + EnergyType &EType() { return E; } +}; + +template +class ParamEdgeCollapse: public vcg::tri::TriEdgeCollapse > { +public: + typedef vcg::tri::TriEdgeCollapse > Super; typedef typename BaseMesh::VertexType::EdgeType EdgeType; typedef typename BaseMesh::VertexType VertexType; typedef typename BaseMesh::VertexType BaseVertex; @@ -33,13 +51,12 @@ public: typedef typename BaseMesh::CoordType CoordType; typedef BaseMesh TriMeshType; - static EnergyType &EType(){static EnergyType E;return E;}; - - inline ParamEdgeCollapse(const EdgeType &p, int mark) + + inline ParamEdgeCollapse(const VertexPair &p, int mark, BaseParameterClass *pp) { Super::localMark = mark; Super::pos=p; - Super::_priority = ComputePriority(); + Super::_priority = ComputePriority(pp); } inline ScalarType Cost() @@ -59,8 +76,9 @@ public: return (pow(lenght,2)+costArea); } - inline bool IsFeasible(){ - return LinkConditions(Super::pos); + inline bool IsFeasible(const BaseParameterClass *){ +// return LinkConditions(Super::pos); + return EdgeCollapser::LinkConditions(Super::pos); } inline void SetHlevMeshUV(const std::vector &LowFace, @@ -77,7 +95,7 @@ public: { VertexType *brother=test_face->vertices_bary[i].first; CoordType bary=test_face->vertices_bary[i].second; - GetUV(test_face,bary,brother->T().U(),brother->T().V()); + InterpolateUV(test_face,bary,brother->T().U(),brother->T().V()); //printf("%f , %f \n",brother->T().U(),brother->T().V()); assert(brother!=NULL); HiVertex.push_back(brother); @@ -210,7 +228,7 @@ public: ///DISTORSION ///create pos - EdgeType posEdge; + VertexPair posEdge; std::vector vertEdge; FindNotBorderVertices(created,vertEdge); @@ -225,8 +243,8 @@ public: for (unsigned int i=0;i::Do(created, posEdge, newPos); UpdateTopologies(&created); /////parametrize domain @@ -279,7 +297,7 @@ public: return (bestPos); } - inline ScalarType ComputePriority() + inline ScalarType ComputePriority(BaseParameterClass *) { return (Cost()); //return( Distance(pos.V(0)->cP(),pos.V(1)->cP())); @@ -291,7 +309,7 @@ public: return bestPos; } - void UpdateFF(EdgeType &posEdge) + void UpdateFF(VertexPair &posEdge) { std::vector shared; std::vector in_v0; @@ -362,7 +380,7 @@ public: ///create a copy the submesh for a collapse and parameterize it -void CreatePreCollapseSubmesh(EdgeType &pos, +void CreatePreCollapseSubmesh(VertexPair &pos, BaseMesh ¶m, std::vector &orderedVertex, std::vector &orderedFaces) @@ -386,7 +404,7 @@ void CreatePreCollapseSubmesh(EdgeType &pos, ///create a copy the submesh after the collapse that is already parameterized /// only the central vertex has to be set to (0,0) -void CreatePostCollapseSubmesh(EdgeType &pos, +void CreatePostCollapseSubmesh(VertexPair &pos, BaseMesh ¶m_post, std::vector &orderedVertex, std::vector &orderedFaces) @@ -413,7 +431,7 @@ void CreatePostCollapseSubmesh(EdgeType &pos, } -void AphaBetaToUV(EdgeType &pos, +void AphaBetaToUV(VertexPair &pos, std::vector &orderedFaces, BaseMesh ¶m, std::vector &HresVert) @@ -438,7 +456,7 @@ void AphaBetaToUV(EdgeType &pos, ///transform to UV ScalarType u,v; - GetUV(parametric_face,bary,u,v); + InterpolateUV(parametric_face,bary,u,v); ///and assing brother->T().U()=u; brother->T().V()=v; @@ -534,7 +552,7 @@ void UVToAlphaBeta(std::vector &HresVert, brother->Bary=bary1;*/ ///set new parametrization value - GetUV(¶m.face[index],bary1,u,v); + InterpolateUV(¶m.face[index],bary1,u,v); HresVert[i]->T().U()=u; HresVert[i]->T().V()=v; } @@ -573,13 +591,15 @@ void AssignRPos(VertexType* &to_assign, to_assign->RPos=val; } -void Execute(BaseMesh &m) +void Execute(BaseMesh &m, vcg::BaseParameterClass *_pp) { typedef typename BaseMesh::FaceType FaceType; typedef typename BaseMesh::VertexType VertexType; typedef typename BaseMesh::ScalarType ScalarType; typedef typename BaseMesh::CoordType CoordType; - + + ParamEdgeCollapseParameter *pp=(ParamEdgeCollapseParameter *)_pp; + assert(this->pos.V(0)!=this->pos.V(1)); assert(!this->pos.V(0)->IsD()); assert(!this->pos.V(1)->IsD()); @@ -617,7 +637,9 @@ void Execute(BaseMesh &m) ScalarType area0=Area(orderedFaces0); ///do the collapse - DoCollapse(m, this->pos, newPos); // v0 is deleted and v1 take the new position +// DoCollapse(m, this->pos, newPos); // v0 is deleted and v1 take the new position + EdgeCollapser::Do(m, this->pos, newPos); + //vcg::tri::UpdateTopology::TestVertexFace(m); ///TEST //---------------------------/// ///create a parametrized submesh post-collapse #1 @@ -673,24 +695,13 @@ void Execute(BaseMesh &m) this->pos.V(1)->RPos=oldRPos; - /*bool b=*/SmartOptimizeStar(this->pos.V(1),m,Accuracy(),EType()); + /*bool b=*/SmartOptimizeStar(this->pos.V(1),m,pp->Accuracy(),pp->EType()); /*int t1=clock(); time_opt+=(t1-t0);*/ } public: - static int &Accuracy() - { - static int _acc; - return _acc; - } - - static BaseMesh* &HresMesh() - { - static BaseMesh* mesh; - return mesh; - } BaseVertex *getV(int num) { @@ -698,5 +709,7 @@ public: return this->pos.V(num); } }; +}//end namespace tri +}//end namespace vcg #endif diff --git a/src/meshlabplugins/filter_isoparametrization/param_flip.h b/src/meshlabplugins/filter_isoparametrization/param_flip.h index 6b9b8e247..3016207c0 100644 --- a/src/meshlabplugins/filter_isoparametrization/param_flip.h +++ b/src/meshlabplugins/filter_isoparametrization/param_flip.h @@ -3,6 +3,9 @@ #include +namespace vcg{ +namespace tri{ + ///Flip function template class ParamEdgeFlip : public vcg::tri::PlanarEdgeFlip > @@ -19,7 +22,7 @@ class ParamEdgeFlip : public vcg::tri::PlanarEdgeFlippos type */ - inline ParamEdgeFlip(const typename Super::PosType pos, int mark) + inline ParamEdgeFlip(const typename Super::PosType pos, int mark,BaseParameterClass *pp) { this->_pos = pos; this->_localMark = mark; - this->_priority = this->ComputePriority(); + this->_priority = this->ComputePriority(pp); savedomain=false; } @@ -71,7 +74,7 @@ class ParamEdgeFlip : public vcg::tri::PlanarEdgeFlip(father,bary,v->T().U(),v->T().V()); + InterpolateUV(father,bary,v->T().U(),v->T().V()); } ///update VF topology @@ -296,7 +299,7 @@ class ParamEdgeFlip : public vcg::tri::PlanarEdgeFlip_priority=EdgeDiff(); return this->_priority; @@ -317,4 +320,7 @@ class ParamEdgeFlip : public vcg::tri::PlanarEdgeFlip{}; -class MyTriEdgeCollapse: public ParamEdgeCollapse{}; +class MyTriEdgeFlip : public vcg::tri::ParamEdgeFlip{}; +class MyTriEdgeCollapse: public vcg::tri::ParamEdgeCollapse{}; ///THIS CLASS MAINTAINS STRUCTURES WICH ARE USED FOR PARAMETRIZATION ///TOGHETHER WITH METHOD FOR COLORIZATION FOR VISUALIZATION PURPOSES @@ -167,11 +167,9 @@ private: ////initialization for decimation //base_mesh.en=0; InitIMark(); - for (unsigned int i=0;i::VertexClear(base_mesh); + vcg::tri::UpdateFlags::FaceClear(base_mesh); + InitVoronoiArea(); } void InitIMark() @@ -182,14 +180,14 @@ private: } - void ParaDecimate(const int &targetFaces, - const int &interval, - bool execute_flip=false) + void ParaDecimate(vcg::tri::ParamEdgeCollapseParameter &pecp, + const int &targetFaces, + const int &interval, + bool execute_flip=false) { - vcg::LocalOptimization DeciSession(base_mesh); + vcg::LocalOptimization DeciSession(base_mesh,&pecp); DeciSession.Init(); - MyTriEdgeCollapse::Accuracy()=accuracy; - MyTriEdgeCollapse::HresMesh()=&final_mesh; + PatchesOptimizer::HresMesh()=&final_mesh; PatchesOptimizer::BaseMesh()=&base_mesh; @@ -269,7 +267,7 @@ private: if (do_flip) { - FlipStep(); + FlipStep(pecp); vcg::tri::UpdateTopology::FaceFace(base_mesh); vcg::tri::UpdateTopology::VertexFace(base_mesh); InitIMark(); @@ -347,14 +345,12 @@ private: {return (dist>other.dist);} }; - void FinalOptimization() + void FinalOptimization(vcg::tri::ParamEdgeCollapseParameter *pecp) { char ret[200]; sprintf(ret," PERFORM GLOBAL OPTIMIZATION initializing... "); (*cb)(0,ret); - - std::vector ord_vertex; ord_vertex.resize(base_mesh.vn); for (unsigned int i=0;i(ord_vertex[i].v,base_mesh,MyTriEdgeCollapse::Accuracy(),EType); + SmartOptimizeStar(ord_vertex[i].v,base_mesh,pecp->Accuracy(),EType); } } @@ -394,8 +390,12 @@ private: ///INITIALIZATION InitializeStructures(mesh); - ///DECIMATION & PARAMETRIZATION - ParaDecimate(targetFaces,interval,execute_flip); + vcg::tri::ParamEdgeCollapseParameter pecp; + pecp.Accuracy()=accuracy; + pecp.HresMesh()=&final_mesh; + + ///DECIMATION & PARAMETRIZATION + ParaDecimate(pecp, targetFaces,interval,execute_flip); ///SET BEST FIND STOP POINT bool isOK=SetBestStatus(test_interpolation); @@ -407,7 +407,7 @@ private: ///LAST FLIP STEP if (execute_flip) - FlipStep(); + FlipStep(pecp); vcg::tri::UpdateTopology::FaceFace(base_mesh); vcg::tri::UpdateTopology::VertexFace(base_mesh); @@ -427,7 +427,7 @@ private: ///LAST OPTIMIZATION STEP ON STARS if (execute_flip) - FinalOptimization(); + FinalOptimization(&pecp); #ifndef _MESHLAB if (execute_flip) @@ -777,12 +777,12 @@ public: ///PARAMETRIZATION FUNCTIONS ///initialize the mesh template - ReturnCode Parametrize(MeshType *mesh,bool Two_steps=true,EnergyType _EType=EN_EXTMips) + ReturnCode Parametrize(MeshType *mesh,vcg::tri::ParamEdgeCollapseParameter &pecp,bool Two_steps=true,EnergyType _EType=EN_EXTMips) { EType=_EType; - MyTriEdgeCollapse::EType()=EType; - MyTriEdgeFlip::EType()=EType; - +// MyTriEdgeCollapse::EType()=EType; +// MyTriEdgeFlip::EType()=EType; + pecp.EType()=_EType; ///clean unreferenced vertices vcg::tri::Clean::RemoveUnreferencedVertex(*mesh); /*bool done;*/ @@ -829,7 +829,6 @@ public: ExportMeshes(para_mesh1,abs_mesh1); - ///constrauct an ISOPARAM printf("\n STEP 2.5 \n"); IsoParametrization IsoParam1; @@ -893,7 +892,7 @@ public: base_f->vertices_bary.push_back(std::pair(&final_mesh.vert[i],bary)); } InitVoronoiArea(); - FinalOptimization(); + FinalOptimization(&pecp); printf("STEP 3 \n"); } ///finally perform the final optimization step @@ -909,13 +908,13 @@ public: } ///perform one or more flip steps - void FlipStep() + void FlipStep(vcg::tri::ParamEdgeCollapseParameter &pecp) { #ifndef _MESHLAB printf("\n STARTING FLIP SESSION \n"); #endif InitIMark(); - FlipSession=new vcg::LocalOptimization(base_mesh); + FlipSession=new vcg::LocalOptimization(base_mesh,&pecp); FlipSession->Init(); /*bool b=*/FlipSession->DoOptimization(); #ifndef _MESHLAB diff --git a/src/meshlabplugins/filter_isoparametrization/texcoord_optimization.h b/src/meshlabplugins/filter_isoparametrization/texcoord_optimization.h index 0378a4325..eb8bed126 100644 --- a/src/meshlabplugins/filter_isoparametrization/texcoord_optimization.h +++ b/src/meshlabplugins/filter_isoparametrization/texcoord_optimization.h @@ -956,7 +956,8 @@ void SmoothTexCoords(MESH_TYPE &m){ assert(m.HasPerVertexTexCoord()); typedef typename MESH_TYPE::VertexType::TexCoordType::PointType PointType; - + typedef typename MESH_TYPE::VertexType::TexCoordType::ScalarType ScalarType; + SimpleTempData div(m.vert); SimpleTempData sum(m.vert);