Now compiles on gcc under linux.

This commit is contained in:
Paolo Cignoni 2006-11-24 10:42:39 +00:00
parent 2a84b52bc8
commit 2954c88fef
2 changed files with 91 additions and 74 deletions

View File

@ -73,13 +73,13 @@ int main(int argc,char ** argv){
switch(algorithm) switch(algorithm)
{ {
case 1: case 1:
vcg::tri::holeFillingEar<MyMesh, typename vcg::tri::TrivialEar<MyMesh> >(m,50,false); vcg::tri::holeFillingEar<MyMesh, vcg::tri::TrivialEar<MyMesh> >(m,50,false);
break; break;
case 2: case 2:
vcg::tri::holeFillingEar<MyMesh, typename vcg::tri::MinimumWeightEar<MyMesh> >(m,500,false); vcg::tri::holeFillingEar<MyMesh, vcg::tri::MinimumWeightEar< MyMesh> >(m,500,false);
break; break;
case 3: case 3:
vcg::tri::holeFillingIntersection<MyMesh, typename vcg::tri::SelfIntersectionEar<MyMesh> >(m,500,false); vcg::tri::holeFillingIntersection<MyMesh, vcg::tri::SelfIntersectionEar< MyMesh> >(m,500,false);
break; break;
case 4: case 4:
vcg::tri::FillHoleMinimumWeight<MyMesh>(m, false); vcg::tri::FillHoleMinimumWeight<MyMesh>(m, false);

View File

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