From 090e33d1625e6374a5d41239d9231b2b9f571407 Mon Sep 17 00:00:00 2001 From: cnr-isti-vclab Date: Thu, 18 Jan 2007 11:17:43 +0000 Subject: [PATCH] The minimum weight algorithm keep the topology consistent. --- vcg/complex/trimesh/hole.h | 114 +++++++++++++++++++++---------------- 1 file changed, 66 insertions(+), 48 deletions(-) diff --git a/vcg/complex/trimesh/hole.h b/vcg/complex/trimesh/hole.h index 2f60f573..20cc31ba 100644 --- a/vcg/complex/trimesh/hole.h +++ b/vcg/complex/trimesh/hole.h @@ -24,6 +24,9 @@ History $Log: not supported by cvs2svn $ +Revision 1.30 2007/01/10 12:07:54 giec +Bugfixed ComputeDihedralAngle function + Revision 1.29 2006/12/27 15:09:52 giec Bug fix on ComputeDihedralAngle function @@ -362,14 +365,6 @@ namespace vcg { SelfIntersectionEar(){} SelfIntersectionEar(const PosType & ep):MinimumWeightEar(ep){} - //{ - // this->e0=ep; - // assert(this->e0.IsBorder()); - // this->e1=this->e0; - // this->e1.NextB(); - // this->ComputeQuality(); - // this->ComputeAngle(); - //} virtual bool Close(PosType &np0, PosType &np1, FacePointer f) { @@ -493,8 +488,6 @@ public: } }; - - template static void FillHoleEar(MESH &m, Info &h ,int UBIT, std::vector &app,std::vector *vf =0) { @@ -574,10 +567,7 @@ template VertexType::DeleteBitFlag(nmBit); // non manifoldness bit } - - - -template//!!! + template static void EarCuttingFill(MESH &m, int sizeHole,bool Selected = false, CallBackPos *cb=0) { std::vector< Info > vinfo; @@ -608,8 +598,6 @@ template//!!! } } - - template static void EarCuttingIntersectionFill(MESH &m, int sizeHole,bool Selected = false) { @@ -830,14 +818,14 @@ template return Weight(angle, area); } - static std::vector calculateMinimumWeightTriangulation(MESH &m, std::vector vv ) + static void calculateMinimumWeightTriangulation(MESH &m, FaceIterator f,std::vector vv ) { std::vector< std::vector< Weight > > w; //matrice dei pesi minimali di ogni orecchio preso in conzideraione std::vector< std::vector< int > > vi;//memorizza l'indice del terzo vertice del triangolo //hole size int nv = vv.size(); - + w.clear(); w.resize( nv, std::vector( nv, Weight() ) ); @@ -878,17 +866,14 @@ template //Triangulate int i, j; i=0; j=nv-1; - std::vector vf; - - vf.clear(); - - triangulate(vf, i, j, vi, vv); - return vf; + + PosType PF = vv[i]; + triangulate(m,f, i, j, vi, vv,PF); } - static void triangulate(std::vector &m,int i, int j, std::vector< std::vector > vi, - std::vector vv) + static void triangulate(MESH &m, FaceIterator f,int i, int j, + std::vector< std::vector > vi, std::vector vv, PosType &PosFrom) { if(i + 1 == j){return;} if(i==j)return; @@ -897,15 +882,50 @@ template if(k == -1) return; - m.push_back(vv[i].v); - m.push_back(vv[k].v); - m.push_back(vv[j].v); + //Setto i vertici + f->V(0) = vv[i].v; + f->V(1) = vv[k].v; + f->V(2) = vv[j].v; + + if(f->HasFFAdjacency()) + { + + f->FFp(2) = PosFrom.f; + f->FFi(2) = PosFrom.z; + PosFrom.f->FFp(PosFrom.z) = &(*f); + PosFrom.f->FFi(PosFrom.z) = 2; - triangulate(m, i, k, vi, vv); - triangulate(m, k, j, vi, vv); + if(i+1 == k) + { + f->FFp(0) = vv[k].f; + f->FFi(0) = vv[k].z; + vv[k].f->FFp(vv[k].z) = &(*f); + vv[k].f->FFi(vv[k].z) = 0; + } + + if(k+1 == j) + { + f->FFp(1) = vv[j].f; + f->FFi(1) = vv[j].z; + vv[j].f->FFp(vv[j].z) = &(*f); + vv[j].f->FFi(vv[j].z) = 1; + } + } + + PosFrom.f = &(*f); + PosFrom.v=f->V(0); + PosFrom.z=0; + f++; + triangulate(m,f,i,k,vi,vv, PosFrom); + f--; + PosFrom.f = &(*f); + PosFrom.v=f->V(1); + PosFrom.z=1; + f++; + triangulate(m,f,k,j,vi,vv,PosFrom); } - static void MinimumWeightFill(MESH &m, bool Selected) + static void MinimumWeightFill(MESH &m, int holeSize, bool Selected) { FaceIterator fi; std::vector vvi; @@ -936,31 +956,29 @@ template app.clear(); vfp.clear(); - for(ithn = vvi.begin(); ithn!= vvi.end(); ++ithn) - vfp.push_back(&(ithn->f)); - ps = *ith; getBoundHole(ps,app); - vf = calculateMinimumWeightTriangulation(m, app); - - if(vf.size() == 0)continue;//non e' stata trovata la triangolazione - - FaceIterator f = tri::Allocator::AddFaces(m, app.size()-2, vfp); - - for(itf = vf.begin();itf != vf.end(); ) + if(app.size() <= holeSize) { - (*f).V(0) = (*itf++); - (*f).V(1) = (*itf++); - (*f).V(2) = (*itf++); - ++f; - } + std::vector::iterator itP; + std::vector vfp; + for(ithn = vvi.begin(); ithn!= vvi.end(); ++ithn) + vfp.push_back(&(ithn->f)); + + for(itP = app.begin (); itP != app.end ();++itP) + vfp.push_back( &(*itP).f ); + + //aggiungo le facce + FaceIterator f = tri::Allocator::AddFaces(m, (app.size()-2) , vfp); + + calculateMinimumWeightTriangulation(m,f, app); + } } } - static void getBoundHole (PosType sp,std::vector&ret) { PosType fp = sp;