diff --git a/apps/sample/trimesh_hole/trimesh_hole.cpp b/apps/sample/trimesh_hole/trimesh_hole.cpp index b745a67c..46824f20 100644 --- a/apps/sample/trimesh_hole/trimesh_hole.cpp +++ b/apps/sample/trimesh_hole/trimesh_hole.cpp @@ -73,13 +73,13 @@ int main(int argc,char ** argv){ switch(algorithm) { case 1: - vcg::tri::holeFillingEar >(m,50,false); + vcg::tri::holeFillingEar >(m,50,false); break; case 2: - vcg::tri::holeFillingEar >(m,500,false); + vcg::tri::holeFillingEar >(m,500,false); break; case 3: - vcg::tri::holeFillingIntersection >(m,500,false); + vcg::tri::holeFillingIntersection >(m,500,false); break; case 4: vcg::tri::FillHoleMinimumWeight(m, false); diff --git a/vcg/complex/trimesh/hole.h b/vcg/complex/trimesh/hole.h index 39cbf357..e8a8768b 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.16 2006/11/22 13:43:28 giec +Code refactory and added minimum weight triangolation. + Revision 1.15 2006/11/13 10:11:38 giec Clear some useless code @@ -78,7 +81,7 @@ First Non working Version #include #include -#include +#include #include #define FLT_MAX 3.402823466e+38F /* max float rappresentable */ @@ -89,6 +92,7 @@ di un buco. namespace vcg { namespace tri { + template class HoleInfo { @@ -142,6 +146,19 @@ namespace vcg { }; + //function prototype + template + int GetHoleInfo(MESH &m,bool Selected ,std::vector >& VHI); + + template + void triangulate(std::vector &m,int i, int j, std::vector< std::vector > vi, + std::vector > vv); + + template + void getBoundHole (face::Pos sp,std::vector >&ret); + + + /* Un ear e' identificato da due hedge pos. i vertici dell'ear sono @@ -179,12 +196,12 @@ namespace vcg { e1=e0; e1.NextB(); ComputeQuality(); - computeAngle(); + ComputeAngle(); } void SetAdiacenseRing(std::vector* ar){vf = ar;} - void computeAngle() + void ComputeAngle() { Point3f p1 = e0.VFlip()->P() - e0.v->P(); Point3f p2 = e1.v->P() - e0.v->P(); @@ -322,17 +339,17 @@ namespace vcg { template class MinimumWeightEar : public TrivialEar { public: - ScalarType dihedral; - ScalarType area; + typename MSH_TYPE::ScalarType dihedral; + typename MSH_TYPE::ScalarType area; MinimumWeightEar(){} MinimumWeightEar(const face::Pos & ep) { - e0=ep; - assert(e0.IsBorder()); - e1=e0; - e1.NextB(); - ComputeQuality(); - computeAngle(); + this->e0=ep; + assert(this->e0.IsBorder()); + this->e1=this->e0; + this->e1.NextB(); + this->ComputeQuality(); + this->ComputeAngle(); } virtual inline bool operator < ( const MinimumWeightEar & c ) const @@ -344,17 +361,17 @@ namespace vcg { virtual void ComputeQuality() { //comute quality by (dihedral ancgle, area/sum(edge^2) ) - Point3f n1 = (e0.v->N() + e1.v->N() + e0.VFlip()->N() ) / 3; - face::Pos tmp = e1; + Point3f n1 = (this->e0.v->N() + this->e1.v->N() + this->e0.VFlip()->N() ) / 3; + face::Pos tmp = this->e1; tmp.FlipE();tmp.FlipV(); - Point3f n2=(e1.VFlip()->N() + e1.v->N() + tmp.v->N() ) / 3; - tmp = e0; + Point3f n2=(this->e1.VFlip()->N() + this->e1.v->N() + tmp.v->N() ) / 3; + tmp = this->e0; tmp.FlipE(); tmp.FlipV(); - Point3f n3=(e0.VFlip()->N() + e0.v->N() + tmp.v->N() ) / 3; + Point3f n3=(this->e0.VFlip()->N() + this->e0.v->N() + tmp.v->N() ) / 3; dihedral = std::max(Angle(n1,n2),Angle(n1,n3)); - ScalarType ar; - ar = ( (e0.VFlip()->P() - e0.v->P()) ^ ( e1.v->P() - e0.v->P()) ).Norm() ; + typename MSH_TYPE::ScalarType ar; + ar = ( (this->e0.VFlip()->P() - this->e0.v->P()) ^ ( this->e1.v->P() - this->e0.v->P()) ).Norm() ; area = ar ; } @@ -368,56 +385,56 @@ namespace vcg { SelfIntersectionEar(){} SelfIntersectionEar(const face::Pos & ep) { - e0=ep; - assert(e0.IsBorder()); - e1=e0; - e1.NextB(); - ComputeQuality(); - computeAngle(); + this->e0=ep; + assert(this->e0.IsBorder()); + this->e1=this->e0; + this->e1.NextB(); + this->ComputeQuality(); + this->ComputeAngle(); } virtual bool Close(SelfIntersectionEar &ne0, SelfIntersectionEar &ne1, typename MSH_TYPE::FaceType * f) { // simple topological check - if(e0.f==e1.f) { + if(this->e0.f==this->e1.f) { printf("Avoided bad ear"); return false; } - face::Pos ep=e0; ep.FlipV(); ep.NextB(); ep.FlipV(); // he precedente a e0 - face::Pos en=e1; en.NextB(); // he successivo a e1 + face::Pos ep=this->e0; ep.FlipV(); ep.NextB(); ep.FlipV(); // he precedente a e0 + face::Pos en=this->e1; en.NextB(); // he successivo a e1 //costruisco la faccia e poi testo, o copio o butto via. - (*f).V(0) = e0.VFlip(); - (*f).V(1) = e0.v; - (*f).V(2) = e1.v; + (*f).V(0) = this->e0.VFlip(); + (*f).V(1) = this->e0.v; + (*f).V(2) = this->e1.v; - (*f).FFp(0) = e0.f; - (*f).FFi(0) = e0.z; - (*f).FFp(1) = e1.f; - (*f).FFi(1) = e1.z; + (*f).FFp(0) = this->e0.f; + (*f).FFi(0) = this->e0.z; + (*f).FFp(1) = this->e1.f; + (*f).FFi(1) = this->e1.z; (*f).FFp(2) = f; - (*f).FFi(2) = 2; + (*f).FFi(2) = 2; int a1, a2; - a1=e0.z; - a2=e1.z; + a1= this->e0.z; + a2= this->e1.z; - e0.f->FFp(e0.z)=f; - e0.f->FFi(e0.z)=0; - - e1.f->FFp(e1.z)=f; - e1.f->FFi(e1.z)=1; + this->e0.f->FFp(this->e0.z)=f; + this->e0.f->FFi(this->e0.z)=0; + + this->e1.f->FFp(this->e1.z)=f; + this->e1.f->FFi(this->e1.z)=1; typename std::vector::iterator it; - for(it = (*vf).begin();it!= (*vf).end();++it) + for(it = (* this->vf).begin();it!= (* this->vf).end();++it) { if(!it->IsD()) if( tri::Clean::TestIntersection(&(*f),&(*it))) { - e0.f->FFp(e0.z)=e0.f; - e0.f->FFi(e0.z)=a1; + this->e0.f->FFp(this->e0.z)= this->e0.f; + this->e0.f->FFi(this->e0.z)=a1; - e1.f->FFp(e1.z)=e1.f; - e1.f->FFi(e1.z)=a2; + this->e1.f->FFp(this->e1.z)=this->e1.f; + this->e1.f->FFi(this->e1.z)=a2; return false; } } @@ -443,12 +460,12 @@ namespace vcg { enold.f->FFp(enold.z)=f; enold.f->FFi(enold.z)=2; ne0=SelfIntersectionEar(ep); - ne0.SetAdiacenseRing(vf); + ne0.SetAdiacenseRing(this->vf); ne1=SelfIntersectionEar(en); - ne1.SetAdiacenseRing(vf); + ne1.SetAdiacenseRing(this->vf); } // Caso ear non manifold b - else if(ep.VFlip()==e1.v) + else if(ep.VFlip()==this->e1.v) { printf("Ear Non manif B\n"); face::Pos epold=ep; @@ -458,16 +475,16 @@ namespace vcg { epold.f->FFp(epold.z)=f; epold.f->FFi(epold.z)=2; ne0=SelfIntersectionEar(ep); - ne0.SetAdiacenseRing(vf); + ne0.SetAdiacenseRing(this->vf); ne1=SelfIntersectionEar(en); - ne1.SetAdiacenseRing(vf); + ne1.SetAdiacenseRing(this->vf); } else// Now compute the new ears; { ne0=SelfIntersectionEar(ep); - ne0.SetAdiacenseRing(vf); - ne1=SelfIntersectionEar(face::Pos(f,2,e1.v)); - ne1.SetAdiacenseRing(vf); + ne0.SetAdiacenseRing(this->vf); + ne1=SelfIntersectionEar(face::Pos(f,2,this->e1.v)); + ne1.SetAdiacenseRing(this->vf); } return true; } @@ -578,7 +595,7 @@ namespace vcg { FillHoleEar(m, app,UBIT); } } - MESH::FaceIterator fi; + typename MESH::FaceIterator fi; for(fi = m.face.begin(); fi!=m.face.end(); ++fi) { if(!(*fi).IsD()) @@ -620,7 +637,7 @@ namespace vcg { vf.clear(); } } - MESH::FaceIterator fi; + typename MESH::FaceIterator fi; for(fi = m.face.begin(); fi!=m.face.end(); ++fi) { if(!(*fi).IsD()) @@ -631,7 +648,7 @@ namespace vcg { template int GetHoleInfo(MESH &m,bool Selected ,std::vector >& VHI) { - MESH::FaceIterator fi; + typename MESH::FaceIterator fi; int UBIT = MESH::FaceType::LastBitFlag(); for(fi = m.face.begin(); fi!=m.face.end(); ++fi) @@ -715,9 +732,9 @@ hole/ \ / float ComputeDihedralAngle(typename MESH::VertexPointer v1,typename MESH::VertexPointer v2, typename MESH::VertexPointer v3,typename MESH::VertexPointer v4) { - MESH::CoordType n1 = ((v1->P() - v2->P()) ^ (v3->P() - v1->P()) ).Normalize(); - MESH::CoordType n2 = ((v2->P() - v1->P()) ^ (v4->P() - v2->P()) ).Normalize(); - MESH::ScalarType t = (n1 * n2 ) ; + typename MESH::CoordType n1 = ((v1->P() - v2->P()) ^ (v3->P() - v1->P()) ).Normalize(); + typename MESH::CoordType n2 = ((v2->P() - v1->P()) ^ (v4->P() - v2->P()) ).Normalize(); + typename MESH::ScalarType t = (n1 * n2 ) ; return ( acos(t)* 180.0 / M_PI); } @@ -797,7 +814,7 @@ hole/ \ / angle = std::max(angle , ComputeDihedralAngle(pk.v, pi.v, pj.v,px.v ) ); } - MESH::ScalarType area = ( (pj.v->P() - pi.v->P()) ^ (pk.v->P() - pi.v->P()) ).Norm() * 0.5; + typename MESH::ScalarType area = ( (pj.v->P() - pi.v->P()) ^ (pk.v->P() - pi.v->P()) ).Norm() * 0.5; return Weight(angle, area); } @@ -851,7 +868,7 @@ hole/ \ / //Triangulate int i, j; i=0; j=nv-1; - std::vector vf; + std::vector vf; vf.clear(); @@ -882,12 +899,12 @@ hole/ \ / template void FillHoleMinimumWeight(MESH &m, bool Selected) { - MESH::FaceIterator fi; + typename MESH::FaceIterator fi; std::vector > vvi; std::vector vfp; std::vector > vinfo; - std::vector >::iterator VIT; + typename std::vector >::iterator VIT; int UBIT = GetHoleInfo(m, Selected,vinfo); for(VIT = vinfo.begin(); VIT != vinfo.end();++VIT) @@ -895,14 +912,14 @@ hole/ \ / vvi.push_back(VIT->p); } - std::vector >::iterator ith; - std::vector >::iterator ithn; - std::vector::iterator itf; + typename std::vector >::iterator ith; + typename std::vector >::iterator ithn; + typename std::vector::iterator itf; std::vector > app; face::Pos ps; - std::vector tr; - std::vector vf; + std::vector tr; + std::vector vf; for(ith = vvi.begin(); ith!= vvi.end(); ++ith) { @@ -921,7 +938,7 @@ hole/ \ / if(vf.size() == 0)continue;//non e' stata trovata la triangolazione - MESH::FaceIterator f = tri::Allocator::AddFaces(m, app.size()-2, vfp); + typename MESH::FaceIterator f = tri::Allocator::AddFaces(m, app.size()-2, vfp); for(itf = vf.begin();itf != vf.end(); ) {