2006-09-25 11:17:44 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* VCGLib o o *
|
|
|
|
* Visual and Computer Graphics Library o o *
|
|
|
|
* _ O _ *
|
|
|
|
* Copyright(C) 2004 \/)\/ *
|
|
|
|
* Visual Computing Lab /\/| *
|
|
|
|
* ISTI - Italian National Research Council | *
|
|
|
|
* \ *
|
|
|
|
* All rights reserved. *
|
|
|
|
* *
|
|
|
|
* This program is free software; you can redistribute it and/or modify *
|
|
|
|
* it under the terms of the GNU General Public License as published by *
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or *
|
|
|
|
* (at your option) any later version. *
|
|
|
|
* *
|
|
|
|
* This program is distributed in the hope that it will be useful, *
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
|
|
* GNU General Public License (http://www.gnu.org/licenses/gpl.txt) *
|
|
|
|
* for more details. *
|
|
|
|
* *
|
|
|
|
****************************************************************************/
|
|
|
|
/****************************************************************************
|
2006-10-06 17:28:14 +02:00
|
|
|
History
|
2006-09-25 11:17:44 +02:00
|
|
|
|
|
|
|
$Log: not supported by cvs2svn $
|
2007-11-06 00:46:43 +01:00
|
|
|
Revision 1.34 2007/01/31 15:25:49 giec
|
|
|
|
Remove some usless code in Minimum Weight Triangulation.
|
|
|
|
|
2007-01-31 16:25:49 +01:00
|
|
|
Revision 1.33 2007/01/31 11:46:12 giec
|
|
|
|
Bug fix
|
|
|
|
|
2007-01-31 12:46:12 +01:00
|
|
|
Revision 1.32 2007/01/18 18:15:14 cignoni
|
|
|
|
added missing typenames
|
|
|
|
|
2007-01-18 19:15:14 +01:00
|
|
|
Revision 1.31 2007/01/18 11:17:43 giec
|
|
|
|
The minimum weight algorithm keep the topology consistent.
|
|
|
|
|
2007-01-18 12:17:43 +01:00
|
|
|
Revision 1.30 2007/01/10 12:07:54 giec
|
|
|
|
Bugfixed ComputeDihedralAngle function
|
|
|
|
|
2007-01-10 13:07:54 +01:00
|
|
|
Revision 1.29 2006/12/27 15:09:52 giec
|
|
|
|
Bug fix on ComputeDihedralAngle function
|
|
|
|
|
2006-12-27 16:09:52 +01:00
|
|
|
Revision 1.28 2006/12/12 11:14:51 cignoni
|
|
|
|
Commented some variant of the quality measure of weighted ears
|
|
|
|
|
2006-12-12 12:14:51 +01:00
|
|
|
Revision 1.27 2006/12/07 00:40:18 cignoni
|
|
|
|
Added many this-> for gcc compiling
|
|
|
|
|
2006-12-07 01:40:18 +01:00
|
|
|
Revision 1.26 2006/12/06 13:03:59 cignoni
|
|
|
|
Corrected bugs on selfintersection
|
|
|
|
|
2006-12-06 14:03:59 +01:00
|
|
|
Revision 1.25 2006/12/06 00:12:53 cignoni
|
|
|
|
Heavily restructured and corrected. Now a single Close ear function
|
|
|
|
Corrected Hole search function, and management of double non manifold vertex in a hole
|
|
|
|
Changed priority strategy in the heap, now a mix of quality and dihedral angle.
|
|
|
|
Changed but still untested IntersectionEar
|
|
|
|
|
2006-12-06 01:12:53 +01:00
|
|
|
Revision 1.24 2006/12/01 21:24:16 cignoni
|
|
|
|
Corrected bug in the search of holes. Removed output prints
|
|
|
|
|
2006-12-01 22:24:16 +01:00
|
|
|
Revision 1.23 2006/12/01 08:53:55 cignoni
|
|
|
|
Corrected pop_heap vs pop_back issue in heap usage
|
|
|
|
|
2006-12-01 09:53:55 +01:00
|
|
|
Revision 1.22 2006/12/01 00:11:17 cignoni
|
|
|
|
Added Callback, Corrected some spelling errors (adiacense -> adjacency).
|
|
|
|
Added Validity Check function for hole loops
|
|
|
|
|
2006-12-01 01:11:17 +01:00
|
|
|
Revision 1.21 2006/11/30 11:49:20 cignoni
|
|
|
|
small gcc compiling issues
|
|
|
|
|
2006-11-30 12:49:20 +01:00
|
|
|
Revision 1.20 2006/11/29 16:21:45 cignoni
|
|
|
|
Made static exposed funtions of the class
|
|
|
|
|
2006-11-29 17:21:45 +01:00
|
|
|
Revision 1.19 2006/11/29 15:25:22 giec
|
|
|
|
Removed limit.
|
|
|
|
|
2006-11-29 16:25:22 +01:00
|
|
|
Revision 1.18 2006/11/29 15:18:49 giec
|
|
|
|
Code refactory and bugfix.
|
|
|
|
|
2006-11-29 16:18:49 +01:00
|
|
|
Revision 1.17 2006/11/24 10:42:39 mariolatronico
|
|
|
|
Now compiles on gcc under linux.
|
|
|
|
|
2006-11-24 11:42:39 +01:00
|
|
|
Revision 1.16 2006/11/22 13:43:28 giec
|
|
|
|
Code refactory and added minimum weight triangolation.
|
|
|
|
|
2006-11-22 14:43:28 +01:00
|
|
|
Revision 1.15 2006/11/13 10:11:38 giec
|
|
|
|
Clear some useless code
|
|
|
|
|
2006-11-13 11:11:38 +01:00
|
|
|
Revision 1.14 2006/11/07 15:13:56 zifnab1974
|
|
|
|
Necessary changes for compilation with gcc 3.4.6. Especially the hash function is a problem
|
|
|
|
|
2006-11-07 16:13:57 +01:00
|
|
|
Revision 1.13 2006/11/07 11:47:11 cignoni
|
|
|
|
gcc compiling issues
|
|
|
|
|
2006-11-07 12:47:14 +01:00
|
|
|
Revision 1.12 2006/11/07 07:56:43 cignoni
|
|
|
|
Added missing std::
|
|
|
|
|
2006-11-07 08:56:43 +01:00
|
|
|
Revision 1.11 2006/11/06 16:12:29 giec
|
|
|
|
Leipa ear now compute max dihedral angle.
|
|
|
|
|
2006-11-06 17:12:29 +01:00
|
|
|
Revision 1.10 2006/10/31 11:30:41 ganovelli
|
|
|
|
changed access throught iterator with static call to comply 2005 compiler
|
|
|
|
|
2006-10-31 12:30:41 +01:00
|
|
|
Revision 1.9 2006/10/20 07:44:45 cignoni
|
|
|
|
Added missing std::
|
|
|
|
|
2006-10-20 09:44:45 +02:00
|
|
|
Revision 1.8 2006/10/18 15:06:47 giec
|
|
|
|
New policy for compute quality in TrivialEar.
|
|
|
|
Bugfixed LeipaEar.
|
|
|
|
Added new algorithm "selfintersection" with test for self intersection.
|
|
|
|
|
2006-10-18 17:06:47 +02:00
|
|
|
Revision 1.7 2006/10/10 09:12:02 giec
|
|
|
|
Bugfix and added a new type of ear (Liepa like)
|
|
|
|
|
2006-10-10 11:12:02 +02:00
|
|
|
Revision 1.6 2006/10/09 10:07:07 giec
|
|
|
|
Optimized version of "EAR HOLE FILLING", the Ear is selected according to its dihedral angle.
|
|
|
|
|
2006-10-09 12:07:07 +02:00
|
|
|
Revision 1.5 2006/10/06 15:28:14 giec
|
|
|
|
first working implementationof "EAR HOLE FILLING".
|
|
|
|
|
2006-10-06 17:28:14 +02:00
|
|
|
Revision 1.4 2006/10/02 12:06:40 giec
|
|
|
|
BugFix
|
|
|
|
|
2006-10-02 14:06:40 +02:00
|
|
|
Revision 1.3 2006/09/27 15:33:32 giec
|
|
|
|
It close one simple hole . . .
|
|
|
|
|
2006-09-27 17:33:32 +02:00
|
|
|
Revision 1.2 2006/09/27 09:29:53 giec
|
|
|
|
Frist working release whit a few bugs.
|
|
|
|
It almost fills the hole ...
|
|
|
|
|
2006-09-27 11:29:53 +02:00
|
|
|
Revision 1.1 2006/09/25 09:17:44 cignoni
|
|
|
|
First Non working Version
|
|
|
|
|
2006-09-25 11:17:44 +02:00
|
|
|
****************************************************************************/
|
|
|
|
#ifndef __VCG_TRI_UPDATE_HOLE
|
|
|
|
#define __VCG_TRI_UPDATE_HOLE
|
|
|
|
|
2006-12-01 01:11:17 +01:00
|
|
|
#include <wrap/callback.h>
|
2006-10-18 17:06:47 +02:00
|
|
|
#include <vcg/math/base.h>
|
2006-11-22 14:43:28 +01:00
|
|
|
#include <vcg/complex/trimesh/clean.h>
|
2006-11-24 11:42:39 +01:00
|
|
|
#include <vcg/space/point3.h>
|
2006-11-22 14:43:28 +01:00
|
|
|
#include <vector>
|
2006-11-29 16:18:49 +01:00
|
|
|
#include <float.h>
|
2006-10-18 17:06:47 +02:00
|
|
|
|
2006-09-25 11:17:44 +02:00
|
|
|
namespace vcg {
|
2006-10-06 17:28:14 +02:00
|
|
|
namespace tri {
|
2006-09-27 11:29:53 +02:00
|
|
|
|
2006-10-06 17:28:14 +02:00
|
|
|
/*
|
|
|
|
Un ear e' identificato da due hedge pos.
|
|
|
|
i vertici dell'ear sono
|
2006-12-06 01:12:53 +01:00
|
|
|
e0.VFlip().v
|
2006-10-06 17:28:14 +02:00
|
|
|
e0.v
|
|
|
|
e1.v
|
|
|
|
Vale che e1== e0.NextB();
|
|
|
|
e che e1.FlipV() == e0;
|
|
|
|
Situazioni ear non manifold, e degeneri (buco triangolare)
|
2006-09-25 11:17:44 +02:00
|
|
|
|
2006-11-29 16:18:49 +01:00
|
|
|
T XXXXXXXXXXXXX A /XXXXX B en/XXXXX
|
2006-10-06 17:28:14 +02:00
|
|
|
/XXXXXXXXXXXXXXX /XXXXXX /XXXXXX
|
|
|
|
XXXXXXep==en XXX ep\ /en XXXX /e1 XXXX
|
|
|
|
XXXXXX ----/| XX ------ ----/| XX ------ ----/|XXX
|
|
|
|
XXXXXX| /e1 XX XXXXXX| /e1 XX XXXXXX| o/e0 XX
|
|
|
|
XXXXXX| /XXXXXX XXXXXX| /XXXXXX XXXXXX| /XXXXXX
|
|
|
|
XXX e0|o/XXXXXXX XXX e0|o/XXXXXXX XXX ep| /XXXXXXX
|
|
|
|
XXX \|/XXXXXXXX XXX \|/XXXXXXXX XXX \|/XXXXXXXX
|
|
|
|
XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX
|
|
|
|
*/
|
2006-11-29 16:18:49 +01:00
|
|
|
template<class MESH> class TrivialEar
|
2006-10-06 17:28:14 +02:00
|
|
|
{
|
|
|
|
public:
|
2006-12-06 01:12:53 +01:00
|
|
|
typedef typename MESH::FaceType FaceType;
|
2006-12-06 14:03:59 +01:00
|
|
|
typedef typename MESH::FacePointer FacePointer;
|
2006-12-06 01:12:53 +01:00
|
|
|
typedef typename face::Pos<FaceType> PosType;
|
|
|
|
typedef typename MESH::ScalarType ScalarType;
|
|
|
|
typedef typename MESH::CoordType CoordType;
|
|
|
|
|
|
|
|
PosType e0;
|
|
|
|
PosType e1;
|
|
|
|
CoordType n; // the normal of the face defined by the ear
|
|
|
|
const char * Dump() {return 0;}
|
|
|
|
const CoordType &cP(int i) const {return P(i);}
|
|
|
|
const CoordType &P(int i) const {
|
|
|
|
switch(i) {
|
|
|
|
case 0 : return e0.v->cP();
|
|
|
|
case 1 : return e1.v->cP();
|
|
|
|
case 2 : return e0.VFlip()->cP();
|
|
|
|
default: assert(0);
|
|
|
|
}
|
|
|
|
return e0.v->cP();
|
|
|
|
}
|
|
|
|
|
2006-10-18 17:06:47 +02:00
|
|
|
ScalarType quality;
|
|
|
|
ScalarType angle;
|
2006-12-06 01:12:53 +01:00
|
|
|
//std::vector<typename MESH::FaceType>* vf;
|
|
|
|
TrivialEar(){}
|
|
|
|
TrivialEar(const PosType & ep)
|
2006-10-06 17:28:14 +02:00
|
|
|
{
|
|
|
|
e0=ep;
|
|
|
|
assert(e0.IsBorder());
|
|
|
|
e1=e0;
|
|
|
|
e1.NextB();
|
2006-12-06 01:12:53 +01:00
|
|
|
n=Normal<TrivialEar>(*this);
|
2006-10-06 17:28:14 +02:00
|
|
|
ComputeQuality();
|
2006-11-24 11:42:39 +01:00
|
|
|
ComputeAngle();
|
2006-10-06 17:28:14 +02:00
|
|
|
}
|
|
|
|
|
2006-12-06 01:12:53 +01:00
|
|
|
/// Compute the angle of the two edges of the ear.
|
2006-12-01 01:11:17 +01:00
|
|
|
// it tries to make the computation in a precision safe way.
|
|
|
|
// the angle computation takes into account the case of reversed ears
|
2006-11-24 11:42:39 +01:00
|
|
|
void ComputeAngle()
|
2006-12-06 01:12:53 +01:00
|
|
|
{
|
|
|
|
angle=Angle(cP(2)-cP(0), cP(1)-cP(0));
|
|
|
|
ScalarType flipAngle = n * e0.v->N();
|
|
|
|
if(flipAngle<0) angle = (2.0 *(float)M_PI) - angle;
|
|
|
|
}
|
2006-10-18 17:06:47 +02:00
|
|
|
|
2006-11-22 14:43:28 +01:00
|
|
|
virtual inline bool operator < ( const TrivialEar & c ) const { return quality < c.quality; }
|
2006-10-06 17:28:14 +02:00
|
|
|
|
|
|
|
bool IsNull(){return e0.IsNull() || e1.IsNull();}
|
|
|
|
void SetNull(){e0.SetNull();e1.SetNull();}
|
2006-12-06 01:12:53 +01:00
|
|
|
virtual void ComputeQuality() { quality = QualityFace(*this) ; };
|
2006-11-29 16:18:49 +01:00
|
|
|
bool IsUpToDate() {return ( e0.IsBorder() && e1.IsBorder());};
|
2006-12-06 01:12:53 +01:00
|
|
|
// An ear is degenerated if both of its two endpoints are non manifold.
|
|
|
|
bool IsDegen(const int nonManifoldBit)
|
|
|
|
{
|
|
|
|
if(e0.VFlip()->IsUserBit(nonManifoldBit) && e1.V()->IsUserBit(nonManifoldBit))
|
|
|
|
return true;
|
|
|
|
else return false;
|
|
|
|
}
|
|
|
|
bool IsConcave() const {return(angle > (float)M_PI);}
|
2006-09-25 11:17:44 +02:00
|
|
|
|
2006-12-06 01:12:53 +01:00
|
|
|
virtual bool Close(PosType &np0, PosType &np1, FaceType * f)
|
2006-10-06 17:28:14 +02:00
|
|
|
{
|
|
|
|
// simple topological check
|
|
|
|
if(e0.f==e1.f) {
|
2006-12-01 22:24:16 +01:00
|
|
|
//printf("Avoided bad ear");
|
2006-10-06 17:28:14 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
//usato per generare una delle due nuove orecchie.
|
2006-12-06 01:12:53 +01:00
|
|
|
PosType ep=e0; ep.FlipV(); ep.NextB(); ep.FlipV(); // he precedente a e0
|
|
|
|
PosType en=e1; en.NextB(); // he successivo a e1
|
|
|
|
|
2006-10-06 17:28:14 +02:00
|
|
|
(*f).V(0) = e0.VFlip();
|
|
|
|
(*f).V(1) = e0.v;
|
|
|
|
(*f).V(2) = e1.v;
|
2006-12-06 01:12:53 +01:00
|
|
|
ComputeNormal(*f);
|
2006-10-06 17:28:14 +02:00
|
|
|
|
|
|
|
(*f).FFp(0) = e0.f;
|
|
|
|
(*f).FFi(0) = e0.z;
|
|
|
|
(*f).FFp(1) = e1.f;
|
|
|
|
(*f).FFi(1) = e1.z;
|
|
|
|
(*f).FFp(2) = f;
|
|
|
|
(*f).FFi(2) = 2;
|
|
|
|
|
|
|
|
e0.f->FFp(e0.z)=f;
|
|
|
|
e0.f->FFi(e0.z)=0;
|
|
|
|
|
|
|
|
e1.f->FFp(e1.z)=f;
|
|
|
|
e1.f->FFi(e1.z)=1;
|
|
|
|
|
|
|
|
// caso ear degenere per buco triangolare
|
|
|
|
if(ep==en)
|
|
|
|
{
|
2006-12-01 22:24:16 +01:00
|
|
|
//printf("Closing the last triangle");
|
2006-10-06 17:28:14 +02:00
|
|
|
f->FFp(2)=en.f;
|
|
|
|
f->FFi(2)=en.z;
|
|
|
|
en.f->FFp(en.z)=f;
|
|
|
|
en.f->FFi(en.z)=2;
|
2006-12-06 01:12:53 +01:00
|
|
|
np0.SetNull();
|
|
|
|
np1.SetNull();
|
2006-10-06 17:28:14 +02:00
|
|
|
}
|
|
|
|
// Caso ear non manifold a
|
|
|
|
else if(ep.v==en.v)
|
|
|
|
{
|
2006-12-01 22:24:16 +01:00
|
|
|
//printf("Ear Non manif A\n");
|
2006-12-06 01:12:53 +01:00
|
|
|
PosType enold=en;
|
2006-10-06 17:28:14 +02:00
|
|
|
en.NextB();
|
|
|
|
f->FFp(2)=enold.f;
|
|
|
|
f->FFi(2)=enold.z;
|
|
|
|
enold.f->FFp(enold.z)=f;
|
|
|
|
enold.f->FFi(enold.z)=2;
|
2006-12-06 01:12:53 +01:00
|
|
|
np0=ep;
|
|
|
|
np1=en;
|
2006-10-06 17:28:14 +02:00
|
|
|
}
|
|
|
|
// Caso ear non manifold b
|
|
|
|
else if(ep.VFlip()==e1.v)
|
|
|
|
{
|
2006-12-01 22:24:16 +01:00
|
|
|
//printf("Ear Non manif B\n");
|
2006-12-06 01:12:53 +01:00
|
|
|
PosType epold=ep;
|
2006-10-06 17:28:14 +02:00
|
|
|
ep.FlipV(); ep.NextB(); ep.FlipV();
|
|
|
|
f->FFp(2)=epold.f;
|
|
|
|
f->FFi(2)=epold.z;
|
|
|
|
epold.f->FFp(epold.z)=f;
|
|
|
|
epold.f->FFi(epold.z)=2;
|
2006-12-06 01:12:53 +01:00
|
|
|
np0=ep; // assign the two new
|
|
|
|
np1=en; // pos that denote the ears
|
2006-10-06 17:28:14 +02:00
|
|
|
}
|
2006-11-29 16:18:49 +01:00
|
|
|
else // caso standard // Now compute the new ears;
|
2006-10-06 17:28:14 +02:00
|
|
|
{
|
2006-12-06 01:12:53 +01:00
|
|
|
np0=ep;
|
|
|
|
np1=PosType(f,2,e1.v);
|
2006-10-06 17:28:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2006-11-22 14:43:28 +01:00
|
|
|
//Ear with FillHoleMinimumWeight's quality policy
|
2006-11-29 16:18:49 +01:00
|
|
|
template<class MESH> class MinimumWeightEar : public TrivialEar<MESH>
|
2006-10-10 11:12:02 +02:00
|
|
|
{
|
|
|
|
public:
|
2006-12-12 12:14:51 +01:00
|
|
|
static float &DiedralWeight() { static float _dw=1.0; return _dw;}
|
2006-12-07 01:40:18 +01:00
|
|
|
typedef TrivialEar<MESH> TE;
|
2006-12-06 01:12:53 +01:00
|
|
|
typename MESH::ScalarType dihedralRad;
|
|
|
|
typename MESH::ScalarType aspectRatio;
|
|
|
|
const char * Dump() {
|
|
|
|
static char buf[200];
|
2006-12-12 12:14:51 +01:00
|
|
|
if(this->IsConcave()) sprintf(buf,"Dihedral -(deg) %6.2f Quality %6.2f\n",math::ToDeg(dihedralRad),aspectRatio);
|
|
|
|
else sprintf(buf,"Dihedral (deg) %6.2f Quality %6.2f\n",math::ToDeg(dihedralRad),aspectRatio);
|
2006-12-06 01:12:53 +01:00
|
|
|
return buf;
|
|
|
|
}
|
|
|
|
|
2006-11-22 14:43:28 +01:00
|
|
|
MinimumWeightEar(){}
|
2006-12-07 01:40:18 +01:00
|
|
|
//MinimumWeightEar(const PosType & ep) : TrivialEar<MESH>(ep)
|
|
|
|
MinimumWeightEar(const typename face::Pos<typename MESH::FaceType>& ep) : TrivialEar<MESH>(ep)
|
2006-10-10 11:12:02 +02:00
|
|
|
{
|
2006-12-06 01:12:53 +01:00
|
|
|
ComputeQuality();
|
2006-10-10 11:12:02 +02:00
|
|
|
}
|
|
|
|
|
2006-12-12 12:14:51 +01:00
|
|
|
// In the heap, by default, we retrieve the LARGEST value,
|
2006-12-06 01:12:53 +01:00
|
|
|
// so if we need the ear with minimal dihedral angle, we must reverse the sign of the comparison.
|
2006-12-12 12:14:51 +01:00
|
|
|
// The concave elements must be all in the end of the heap, sorted accordingly,
|
|
|
|
// So if only one of the two ear is Concave that one is always the minimum one.
|
|
|
|
// the pow function is here just to give a way to play with different weighting schemas, balancing in a different way
|
2006-12-06 01:12:53 +01:00
|
|
|
|
|
|
|
virtual inline bool operator < ( const MinimumWeightEar & c ) const
|
2006-10-10 11:12:02 +02:00
|
|
|
{
|
2006-12-07 01:40:18 +01:00
|
|
|
if(TE::IsConcave() == c.IsConcave())
|
2006-12-06 01:12:53 +01:00
|
|
|
{
|
2006-12-12 12:14:51 +01:00
|
|
|
return (pow(dihedralRad,DiedralWeight())/aspectRatio) > (pow(c.dihedralRad,DiedralWeight())/c.aspectRatio);
|
2006-12-06 01:12:53 +01:00
|
|
|
}
|
2006-12-07 01:40:18 +01:00
|
|
|
if(TE::IsConcave()) return true;
|
2006-12-12 12:14:51 +01:00
|
|
|
// assert(c.IsConcave());
|
|
|
|
return false;
|
2006-10-10 11:12:02 +02:00
|
|
|
}
|
|
|
|
|
2006-12-12 12:14:51 +01:00
|
|
|
// the real core of the whole hole filling strategy.
|
2006-11-22 14:43:28 +01:00
|
|
|
virtual void ComputeQuality()
|
2006-12-06 01:12:53 +01:00
|
|
|
{
|
|
|
|
//compute quality by (dihedral ancgle, area/sum(edge^2) )
|
2006-12-07 01:40:18 +01:00
|
|
|
Point3f n1=TE::e0.FFlip()->cN();
|
|
|
|
Point3f n2=TE::e1.FFlip()->cN();
|
2006-12-12 12:14:51 +01:00
|
|
|
|
2006-12-07 01:40:18 +01:00
|
|
|
dihedralRad = std::max(Angle(TE::n,n1),Angle(TE::n,n2));
|
2006-12-12 12:14:51 +01:00
|
|
|
aspectRatio = QualityFace(*this);
|
2006-10-10 11:12:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
};
|
2006-10-18 17:06:47 +02:00
|
|
|
//Ear for selfintersection algorithm
|
2006-12-06 14:03:59 +01:00
|
|
|
template<class MESH> class SelfIntersectionEar : public MinimumWeightEar<MESH>
|
2006-10-18 17:06:47 +02:00
|
|
|
{
|
|
|
|
public:
|
2006-12-07 01:40:18 +01:00
|
|
|
typedef typename MESH::FaceType FaceType;
|
|
|
|
typedef typename MESH::FacePointer FacePointer;
|
|
|
|
typedef typename face::Pos<FaceType> PosType;
|
|
|
|
typedef typename MESH::ScalarType ScalarType;
|
|
|
|
typedef typename MESH::CoordType CoordType;
|
|
|
|
|
2006-12-06 14:03:59 +01:00
|
|
|
static std::vector<FacePointer> &AdjacencyRing()
|
2006-12-06 01:12:53 +01:00
|
|
|
{
|
2006-12-06 14:03:59 +01:00
|
|
|
static std::vector<FacePointer> ar;
|
2006-12-06 01:12:53 +01:00
|
|
|
return ar;
|
|
|
|
}
|
2006-11-22 14:43:28 +01:00
|
|
|
|
|
|
|
SelfIntersectionEar(){}
|
2006-12-06 14:03:59 +01:00
|
|
|
SelfIntersectionEar(const PosType & ep):MinimumWeightEar<MESH>(ep){}
|
|
|
|
|
|
|
|
virtual bool Close(PosType &np0, PosType &np1, FacePointer f)
|
2006-10-18 17:06:47 +02:00
|
|
|
{
|
2006-12-07 01:40:18 +01:00
|
|
|
PosType ep=this->e0; ep.FlipV(); ep.NextB(); ep.FlipV(); // he precedente a e0
|
|
|
|
PosType en=this->e1; en.NextB(); // he successivo a e1
|
2006-10-18 17:06:47 +02:00
|
|
|
//costruisco la faccia e poi testo, o copio o butto via.
|
2006-12-07 01:40:18 +01:00
|
|
|
(*f).V(0) = this->e0.VFlip();
|
|
|
|
(*f).V(1) = this->e0.v;
|
|
|
|
(*f).V(2) = this->e1.v;
|
|
|
|
|
|
|
|
(*f).FFp(0) = this->e0.f;
|
|
|
|
(*f).FFi(0) = this->e0.z;
|
|
|
|
(*f).FFp(1) = this->e1.f;
|
|
|
|
(*f).FFi(1) = this->e1.z;
|
2006-10-18 17:06:47 +02:00
|
|
|
(*f).FFp(2) = f;
|
2006-11-24 11:42:39 +01:00
|
|
|
(*f).FFi(2) = 2;
|
2006-10-18 17:06:47 +02:00
|
|
|
|
|
|
|
int a1, a2;
|
2006-12-07 01:40:18 +01:00
|
|
|
a1= this->e0.z;
|
|
|
|
a2= this->e1.z;
|
2006-11-24 11:42:39 +01:00
|
|
|
|
2006-12-07 01:40:18 +01:00
|
|
|
this->e0.f->FFp(this->e0.z)=f;
|
|
|
|
this->e0.f->FFi(this->e0.z)=0;
|
2006-11-29 16:18:49 +01:00
|
|
|
|
2006-12-07 01:40:18 +01:00
|
|
|
this->e1.f->FFp(this->e1.z)=f;
|
|
|
|
this->e1.f->FFi(this->e1.z)=1;
|
|
|
|
typename std::vector< FacePointer >::iterator it;
|
|
|
|
for(it = this->AdjacencyRing().begin();it!= this->AdjacencyRing().end();++it)
|
2006-10-18 17:06:47 +02:00
|
|
|
{
|
2006-12-06 14:03:59 +01:00
|
|
|
if(!(*it)->IsD())
|
|
|
|
if( tri::Clean<MESH>::TestIntersection(&(*f),*it))
|
2006-10-18 17:06:47 +02:00
|
|
|
{
|
2006-12-07 01:40:18 +01:00
|
|
|
this->e0.f->FFp(this->e0.z)= this->e0.f;
|
|
|
|
this->e0.f->FFi(this->e0.z)=a1;
|
2006-10-18 17:06:47 +02:00
|
|
|
|
2006-12-07 01:40:18 +01:00
|
|
|
this->e1.f->FFp(this->e1.z)= this->e1.f;
|
|
|
|
this->e1.f->FFi(this->e1.z)=a2;
|
2006-10-18 17:06:47 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2006-12-06 14:03:59 +01:00
|
|
|
//return ((TrivialEar<MESH> *)this)->Close(np0,np1,f);
|
2006-12-07 01:40:18 +01:00
|
|
|
this->e0.f->FFp(this->e0.z)= this->e0.f;
|
|
|
|
this->e0.f->FFi(this->e0.z)=a1;
|
2006-12-06 14:03:59 +01:00
|
|
|
|
2006-12-07 01:40:18 +01:00
|
|
|
this->e1.f->FFp(this->e1.z)=this->e1.f;
|
|
|
|
this->e1.f->FFi(this->e1.z)=a2;
|
2006-12-06 14:03:59 +01:00
|
|
|
|
|
|
|
bool ret=TrivialEar<MESH>::Close(np0,np1,f);
|
|
|
|
if(ret) AdjacencyRing().push_back(f);
|
|
|
|
return ret;
|
|
|
|
}
|
2006-10-18 17:06:47 +02:00
|
|
|
};
|
|
|
|
|
2006-10-06 17:28:14 +02:00
|
|
|
// Funzione principale per chiudier un buco in maniera topologicamente corretta.
|
|
|
|
// Gestisce situazioni non manifold ragionevoli
|
|
|
|
// (tutte eccetto quelle piu' di 2 facce per 1 edge).
|
|
|
|
// Controlla che non si generino nuove situazioni non manifold chiudendo orecchie
|
|
|
|
// che sottendono un edge che gia'esiste.
|
2006-09-25 11:17:44 +02:00
|
|
|
|
2006-11-29 16:18:49 +01:00
|
|
|
template <class MESH>
|
|
|
|
class Hole
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
typedef typename MESH::VertexType VertexType;
|
|
|
|
typedef typename MESH::VertexPointer VertexPointer;
|
|
|
|
typedef typename MESH::ScalarType ScalarType;
|
|
|
|
typedef typename MESH::FaceType FaceType;
|
|
|
|
typedef typename MESH::FacePointer FacePointer;
|
|
|
|
typedef typename MESH::FaceIterator FaceIterator;
|
|
|
|
typedef typename MESH::CoordType CoordType;
|
|
|
|
typedef typename vcg::Box3<ScalarType> Box3Type;
|
|
|
|
typedef typename face::Pos<FaceType> PosType;
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
class Info
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
Info(){}
|
|
|
|
Info(PosType const &pHole, int const pHoleSize, Box3<ScalarType> &pHoleBB)
|
|
|
|
{
|
|
|
|
p=pHole;
|
|
|
|
size=pHoleSize;
|
|
|
|
bb=pHoleBB;
|
|
|
|
}
|
|
|
|
|
|
|
|
PosType p;
|
|
|
|
int size;
|
|
|
|
Box3Type bb;
|
|
|
|
|
|
|
|
bool operator < (const Info & hh) const {return size < hh.size;}
|
|
|
|
|
|
|
|
ScalarType Perimeter()
|
|
|
|
{
|
|
|
|
ScalarType sum=0;
|
|
|
|
PosType ip = p;
|
|
|
|
do
|
|
|
|
{
|
|
|
|
sum+=Distance(ip.v->cP(),ip.VFlip()->cP());
|
|
|
|
ip.NextB();
|
|
|
|
}
|
|
|
|
while (ip != p);
|
|
|
|
return sum;
|
|
|
|
}
|
|
|
|
|
2006-12-01 01:11:17 +01:00
|
|
|
// Support function to test the validity of a single hole loop
|
|
|
|
// for now it test only that all the edges are border;
|
|
|
|
// The real test should check if all non manifold vertices
|
|
|
|
// are touched only by edges belonging to this hole loop.
|
|
|
|
bool CheckValidity()
|
|
|
|
{
|
|
|
|
if(!p.IsBorder())
|
|
|
|
return false;
|
2006-12-01 22:24:16 +01:00
|
|
|
PosType ip=p;ip.NextB();
|
2006-12-01 01:11:17 +01:00
|
|
|
for(;ip!=p;ip.NextB())
|
|
|
|
{
|
|
|
|
if(!ip.IsBorder())
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2006-11-29 16:18:49 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
template<class EAR>
|
2006-11-29 17:21:45 +01:00
|
|
|
static void FillHoleEar(MESH &m, Info &h ,int UBIT, std::vector<FacePointer *> &app,std::vector<FaceType > *vf =0)
|
2006-09-25 11:17:44 +02:00
|
|
|
{
|
2006-12-01 09:53:55 +01:00
|
|
|
//Aggiungo le facce e aggiorno il puntatore alla faccia!
|
2006-11-29 16:18:49 +01:00
|
|
|
FaceIterator f = tri::Allocator<MESH>::AddFaces(m, h.size-2, app);
|
|
|
|
assert(h.p.f >= &*m.face.begin());
|
2007-11-06 00:46:43 +01:00
|
|
|
assert(h.p.f <= &m.face.back());
|
2006-12-01 09:53:55 +01:00
|
|
|
assert(h.p.IsBorder());//test fondamentale altrimenti qualcosa s'e' rotto!
|
2006-12-06 01:12:53 +01:00
|
|
|
std::vector< EAR > H;
|
2006-10-06 17:28:14 +02:00
|
|
|
H.reserve(h.size);
|
2006-12-06 01:12:53 +01:00
|
|
|
int nmBit= VertexType::NewBitFlag(); // non manifoldness bit
|
|
|
|
|
|
|
|
//First loops around the hole to mark non manifold vertices.
|
|
|
|
PosType ip = h.p; // Pos iterator
|
|
|
|
do{
|
|
|
|
ip.V()->ClearUserBit(nmBit);
|
|
|
|
ip.V()->ClearV();
|
|
|
|
ip.NextB();
|
|
|
|
} while(ip!=h.p);
|
|
|
|
|
|
|
|
ip = h.p; // Re init the pos iterator for another loop (useless if everithing is ok!!)
|
|
|
|
do{
|
|
|
|
if(!ip.V()->IsV())
|
|
|
|
ip.V()->SetV(); // All the vertexes that are visited more than once are non manifold
|
|
|
|
else ip.V()->SetUserBit(nmBit);
|
|
|
|
ip.NextB();
|
|
|
|
} while(ip!=h.p);
|
2006-10-06 17:28:14 +02:00
|
|
|
|
2006-11-29 16:18:49 +01:00
|
|
|
PosType fp = h.p;
|
2006-11-22 14:43:28 +01:00
|
|
|
do{
|
|
|
|
EAR app = EAR(fp);
|
|
|
|
H.push_back( app );
|
2007-01-10 13:07:54 +01:00
|
|
|
//printf("Adding ear %s ",app.Dump());
|
2006-12-06 01:12:53 +01:00
|
|
|
fp.NextB();
|
2006-11-22 14:43:28 +01:00
|
|
|
assert(fp.IsBorder());
|
2006-12-06 01:12:53 +01:00
|
|
|
}while(fp!=h.p);
|
2006-10-06 17:28:14 +02:00
|
|
|
|
|
|
|
int cnt=h.size;
|
2006-12-06 01:12:53 +01:00
|
|
|
|
2006-10-09 12:07:07 +02:00
|
|
|
make_heap(H.begin(), H.end());
|
2006-12-06 01:12:53 +01:00
|
|
|
|
2006-11-22 14:43:28 +01:00
|
|
|
//finche' il buco non e' chiuso o non ci sono piu' orecchie da analizzare.
|
|
|
|
while( cnt > 2 && !H.empty() )
|
2006-12-06 01:12:53 +01:00
|
|
|
{
|
2007-01-10 13:07:54 +01:00
|
|
|
//printf("Front of the heap is %s", H.front().Dump());
|
2006-12-06 01:12:53 +01:00
|
|
|
pop_heap(H.begin(), H.end()); // retrieve the MAXIMUM value and put in the back;
|
|
|
|
PosType ep0,ep1;
|
2006-12-01 09:53:55 +01:00
|
|
|
EAR BestEar=H.back();
|
|
|
|
H.pop_back();
|
2006-12-06 01:12:53 +01:00
|
|
|
if(BestEar.IsUpToDate() && !BestEar.IsDegen(nmBit))
|
|
|
|
{
|
|
|
|
if(BestEar.Close(ep0,ep1,&*f))
|
2006-09-27 17:33:32 +02:00
|
|
|
{
|
2006-12-06 01:12:53 +01:00
|
|
|
if(!ep0.IsNull()){
|
|
|
|
H.push_back(EAR(ep0));
|
2006-10-09 12:07:07 +02:00
|
|
|
push_heap( H.begin(), H.end());
|
2006-10-06 17:28:14 +02:00
|
|
|
}
|
2006-12-06 01:12:53 +01:00
|
|
|
if(!ep1.IsNull()){
|
|
|
|
H.push_back(EAR(ep1));
|
2006-10-09 12:07:07 +02:00
|
|
|
push_heap( H.begin(), H.end());
|
|
|
|
}
|
2006-10-06 17:28:14 +02:00
|
|
|
--cnt;
|
2006-10-09 12:07:07 +02:00
|
|
|
f->SetUserBit(UBIT);
|
2006-11-22 14:43:28 +01:00
|
|
|
if(vf != 0) (*vf).push_back(*f);
|
2006-10-06 17:28:14 +02:00
|
|
|
++f;
|
2006-10-09 12:07:07 +02:00
|
|
|
}
|
2006-12-06 01:12:53 +01:00
|
|
|
}//is update()
|
2006-11-22 14:43:28 +01:00
|
|
|
}//fine del while principale.
|
|
|
|
//tolgo le facce non utilizzate.
|
2006-10-06 17:28:14 +02:00
|
|
|
while(f!=m.face.end())
|
|
|
|
{
|
|
|
|
(*f).SetD();
|
|
|
|
++f;
|
|
|
|
m.fn--;
|
|
|
|
}
|
2006-12-06 01:12:53 +01:00
|
|
|
|
|
|
|
VertexType::DeleteBitFlag(nmBit); // non manifoldness bit
|
|
|
|
}
|
|
|
|
|
2007-01-18 12:17:43 +01:00
|
|
|
template<class EAR>
|
2006-12-01 01:11:17 +01:00
|
|
|
static void EarCuttingFill(MESH &m, int sizeHole,bool Selected = false, CallBackPos *cb=0)
|
2006-09-27 17:33:32 +02:00
|
|
|
{
|
2006-11-29 16:18:49 +01:00
|
|
|
std::vector< Info > vinfo;
|
|
|
|
int UBIT = GetInfo(m, Selected,vinfo);
|
|
|
|
|
2006-11-30 12:49:20 +01:00
|
|
|
typename std::vector<Info >::iterator ith;
|
2006-11-29 16:18:49 +01:00
|
|
|
//Info app;
|
|
|
|
int ind=0;
|
2006-11-22 14:43:28 +01:00
|
|
|
|
2006-11-29 16:18:49 +01:00
|
|
|
std::vector<FacePointer *> vfp;
|
|
|
|
for(ith = vinfo.begin(); ith!= vinfo.end(); ++ith)
|
|
|
|
vfp.push_back( &(*ith).p.f );
|
|
|
|
|
2006-11-22 14:43:28 +01:00
|
|
|
for(ith = vinfo.begin(); ith!= vinfo.end(); ++ith)
|
|
|
|
{
|
2006-11-29 16:18:49 +01:00
|
|
|
ind++;
|
2006-12-01 01:11:17 +01:00
|
|
|
if(cb) (*cb)(ind*100/vinfo.size(),"Closing Holes");
|
2006-12-01 22:24:16 +01:00
|
|
|
if((*ith).size < sizeHole){
|
2006-11-29 16:18:49 +01:00
|
|
|
FillHoleEar< EAR >(m, *ith,UBIT,vfp);
|
2006-11-22 14:43:28 +01:00
|
|
|
}
|
|
|
|
}
|
2006-11-29 16:18:49 +01:00
|
|
|
|
|
|
|
FaceIterator fi;
|
2006-11-22 14:43:28 +01:00
|
|
|
for(fi = m.face.begin(); fi!=m.face.end(); ++fi)
|
|
|
|
{
|
|
|
|
if(!(*fi).IsD())
|
|
|
|
(*fi).ClearUserBit(UBIT);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-11-29 17:21:45 +01:00
|
|
|
template<class EAR>
|
|
|
|
static void EarCuttingIntersectionFill(MESH &m, int sizeHole,bool Selected = false)
|
2006-11-22 14:43:28 +01:00
|
|
|
{
|
2006-11-29 16:18:49 +01:00
|
|
|
std::vector<Info > vinfo;
|
|
|
|
int UBIT = GetInfo(m, Selected,vinfo);
|
|
|
|
std::vector<FaceType > vf;
|
|
|
|
PosType sp;
|
|
|
|
PosType ap;
|
2006-11-30 12:49:20 +01:00
|
|
|
typename std::vector<Info >::iterator ith;
|
2006-12-06 14:03:59 +01:00
|
|
|
|
2006-12-06 01:12:53 +01:00
|
|
|
// collect the face pointer that has to be updated by the various addfaces
|
2006-12-06 14:03:59 +01:00
|
|
|
std::vector<FacePointer *> vfpOrig;
|
2006-11-22 14:43:28 +01:00
|
|
|
for(ith = vinfo.begin(); ith!= vinfo.end(); ++ith)
|
2006-12-06 14:03:59 +01:00
|
|
|
vfpOrig.push_back( &(*ith).p.f );
|
2006-12-06 01:12:53 +01:00
|
|
|
|
2006-12-06 14:03:59 +01:00
|
|
|
|
2006-11-29 16:18:49 +01:00
|
|
|
for(ith = vinfo.begin(); ith!= vinfo.end(); ++ith)
|
|
|
|
{
|
2006-12-06 01:12:53 +01:00
|
|
|
if((*ith).size < sizeHole){
|
2006-12-06 14:03:59 +01:00
|
|
|
std::vector<FacePointer *> vfp;
|
|
|
|
|
|
|
|
vfp=vfpOrig;
|
|
|
|
EAR::AdjacencyRing().clear();
|
2006-12-06 01:12:53 +01:00
|
|
|
//Loops around the hole to collect the races .
|
|
|
|
PosType ip = (*ith).p;
|
2006-11-22 14:43:28 +01:00
|
|
|
do
|
|
|
|
{
|
2006-12-06 01:12:53 +01:00
|
|
|
PosType inp = ip;
|
2006-11-22 14:43:28 +01:00
|
|
|
do
|
|
|
|
{
|
2006-12-06 01:12:53 +01:00
|
|
|
inp.FlipE();
|
|
|
|
inp.FlipF();
|
2006-12-06 14:03:59 +01:00
|
|
|
EAR::AdjacencyRing().push_back(inp.f);
|
2006-12-06 01:12:53 +01:00
|
|
|
} while(!inp.IsBorder());
|
|
|
|
ip.NextB();
|
2006-12-06 14:03:59 +01:00
|
|
|
}while(ip != (*ith).p);
|
2006-11-22 14:43:28 +01:00
|
|
|
|
2006-12-07 01:40:18 +01:00
|
|
|
typename std::vector<FacePointer>::iterator fpi;
|
2006-12-06 14:03:59 +01:00
|
|
|
for(fpi=EAR::AdjacencyRing().begin();fpi!=EAR::AdjacencyRing().end();++fpi)
|
|
|
|
vfp.push_back( &*fpi );
|
|
|
|
|
|
|
|
FillHoleEar<EAR >(m, *ith,UBIT,vfp,&vf);
|
2006-12-06 01:12:53 +01:00
|
|
|
EAR::AdjacencyRing().clear();
|
2006-11-22 14:43:28 +01:00
|
|
|
}
|
|
|
|
}
|
2006-11-29 16:18:49 +01:00
|
|
|
FaceIterator fi;
|
2006-11-22 14:43:28 +01:00
|
|
|
for(fi = m.face.begin(); fi!=m.face.end(); ++fi)
|
|
|
|
{
|
|
|
|
if(!(*fi).IsD())
|
|
|
|
(*fi).ClearUserBit(UBIT);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-11-29 16:18:49 +01:00
|
|
|
|
|
|
|
|
2006-11-29 17:21:45 +01:00
|
|
|
static int GetInfo(MESH &m,bool Selected ,std::vector<Info >& VHI)
|
2006-11-22 14:43:28 +01:00
|
|
|
{
|
2006-11-29 16:18:49 +01:00
|
|
|
FaceIterator fi;
|
|
|
|
int UBIT = FaceType::LastBitFlag();
|
2006-10-06 17:28:14 +02:00
|
|
|
|
|
|
|
for(fi = m.face.begin(); fi!=m.face.end(); ++fi)
|
|
|
|
{
|
|
|
|
if(!(*fi).IsD())
|
2006-09-27 17:33:32 +02:00
|
|
|
{
|
2006-10-06 17:28:14 +02:00
|
|
|
if(Selected && !(*fi).IsS())
|
|
|
|
{
|
|
|
|
//se devo considerare solo i triangoli selezionati e
|
|
|
|
//quello che sto considerando non lo e' lo marchio e vado avanti
|
|
|
|
(*fi).SetUserBit(UBIT);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for(int j =0; j<3 ; ++j)
|
|
|
|
{
|
2006-12-01 22:24:16 +01:00
|
|
|
if( face::IsBorder(*fi,j) && !(*fi).IsUserBit(UBIT) )
|
2006-10-06 17:28:14 +02:00
|
|
|
{//Trovato una faccia di bordo non ancora visitata.
|
2006-12-01 22:24:16 +01:00
|
|
|
(*fi).SetUserBit(UBIT);
|
|
|
|
PosType sp(&*fi, j, (*fi).V(j));
|
2006-11-29 16:18:49 +01:00
|
|
|
PosType fp=sp;
|
2006-11-22 14:43:28 +01:00
|
|
|
int holesize=0;
|
|
|
|
|
2006-11-29 16:18:49 +01:00
|
|
|
Box3Type hbox;
|
2006-11-22 14:43:28 +01:00
|
|
|
hbox.Add(sp.v->cP());
|
2006-12-01 22:24:16 +01:00
|
|
|
//printf("Looping %i : (face %i edge %i) \n", VHI.size(),sp.f-&*m.face.begin(),sp.z);
|
|
|
|
sp.f->SetUserBit(UBIT);
|
2006-11-22 14:43:28 +01:00
|
|
|
do
|
|
|
|
{
|
|
|
|
sp.f->SetUserBit(UBIT);
|
|
|
|
hbox.Add(sp.v->cP());
|
|
|
|
++holesize;
|
|
|
|
sp.NextB();
|
2006-12-01 22:24:16 +01:00
|
|
|
sp.f->SetUserBit(UBIT);
|
2006-11-22 14:43:28 +01:00
|
|
|
assert(sp.IsBorder());
|
|
|
|
}while(sp != fp);
|
|
|
|
|
2006-10-06 17:28:14 +02:00
|
|
|
//ho recuperato l'inofrmazione su tutto il buco
|
2006-11-29 16:18:49 +01:00
|
|
|
VHI.push_back( Info(sp,holesize,hbox) );
|
2006-10-06 17:28:14 +02:00
|
|
|
}
|
|
|
|
}//for sugli edge del triangolo
|
|
|
|
}//S & !S
|
|
|
|
}//!IsD()
|
|
|
|
}//for principale!!!
|
2006-11-22 14:43:28 +01:00
|
|
|
return UBIT;
|
|
|
|
}
|
2006-10-06 17:28:14 +02:00
|
|
|
|
2006-11-22 14:43:28 +01:00
|
|
|
//Minimum Weight Algorithm
|
|
|
|
class Weight
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
Weight() { ang = 180; ar = FLT_MAX ;}
|
|
|
|
Weight( float An, float Ar ) { ang=An ; ar= Ar;}
|
|
|
|
~Weight() {}
|
|
|
|
|
|
|
|
float angle() const { return ang; }
|
|
|
|
float area() const { return ar; }
|
|
|
|
|
|
|
|
Weight operator+( const Weight & other ) const {return Weight( std::max( angle(), other.angle() ), area() + other.area());}
|
|
|
|
bool operator<( const Weight & rhs ) const {return ( angle() < rhs.angle() ||(angle() == rhs.angle() && area() < rhs.area())); }
|
|
|
|
|
|
|
|
private:
|
|
|
|
float ang;
|
|
|
|
float ar;
|
|
|
|
};
|
2006-11-29 16:18:49 +01:00
|
|
|
|
2006-11-22 14:43:28 +01:00
|
|
|
/*
|
2006-11-29 16:18:49 +01:00
|
|
|
\ / \/
|
|
|
|
v1*---------*v4
|
|
|
|
/ \ /
|
|
|
|
/ \ /
|
|
|
|
/ \ /
|
|
|
|
/ear \ /
|
|
|
|
*---------*-
|
|
|
|
| v3 v2\
|
|
|
|
*/
|
|
|
|
|
2006-11-29 17:21:45 +01:00
|
|
|
static float ComputeDihedralAngle(CoordType p1,CoordType p2,CoordType p3,CoordType p4)
|
2006-11-22 14:43:28 +01:00
|
|
|
{
|
2007-01-10 13:07:54 +01:00
|
|
|
CoordType n1 = NormalizedNormal(p1,p3,p2);
|
|
|
|
CoordType n2 = NormalizedNormal(p1,p2,p4);
|
|
|
|
return math::ToDeg(AngleN(n1,n2));
|
2006-11-22 14:43:28 +01:00
|
|
|
}
|
|
|
|
|
2006-11-29 17:21:45 +01:00
|
|
|
static bool existEdge(PosType pi,PosType pf)
|
2006-11-22 14:43:28 +01:00
|
|
|
{
|
2006-11-29 16:18:49 +01:00
|
|
|
PosType app = pi;
|
|
|
|
PosType appF = pi;
|
|
|
|
PosType tmp;
|
2006-11-22 14:43:28 +01:00
|
|
|
assert(pi.IsBorder());
|
|
|
|
appF.NextB();
|
|
|
|
appF.FlipV();
|
|
|
|
do
|
2006-10-06 17:28:14 +02:00
|
|
|
{
|
2006-11-22 14:43:28 +01:00
|
|
|
tmp = app;
|
|
|
|
tmp.FlipV();
|
|
|
|
if(tmp.v == pf.v)
|
|
|
|
return true;
|
|
|
|
app.FlipE();
|
|
|
|
app.FlipF();
|
|
|
|
|
|
|
|
if(app == pi)return false;
|
|
|
|
}while(app != appF);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2006-11-29 17:21:45 +01:00
|
|
|
static Weight computeWeight( int i, int j, int k,
|
2006-11-29 16:18:49 +01:00
|
|
|
std::vector<PosType > pv,
|
2006-11-22 14:43:28 +01:00
|
|
|
std::vector< std::vector< int > > v)
|
|
|
|
{
|
2006-11-29 16:18:49 +01:00
|
|
|
PosType pi = pv[i];
|
|
|
|
PosType pj = pv[j];
|
|
|
|
PosType pk = pv[k];
|
2006-11-22 14:43:28 +01:00
|
|
|
|
|
|
|
//test complex edge
|
2006-11-29 16:18:49 +01:00
|
|
|
if(existEdge(pi,pj) || existEdge(pj,pk)|| existEdge(pk,pi) )
|
2006-11-22 14:43:28 +01:00
|
|
|
{
|
|
|
|
return Weight();
|
|
|
|
}
|
|
|
|
// Return an infinite weight, if one of the neighboring patches
|
|
|
|
// could not be created.
|
|
|
|
if(v[i][j] == -1){return Weight();}
|
|
|
|
if(v[j][k] == -1){return Weight();}
|
|
|
|
|
|
|
|
//calcolo il massimo angolo diedrale, se esiste.
|
|
|
|
float angle = 0.0f;
|
2006-11-29 16:18:49 +01:00
|
|
|
PosType px;
|
2006-11-22 14:43:28 +01:00
|
|
|
if(i + 1 == j)
|
|
|
|
{
|
|
|
|
px = pj;
|
|
|
|
px.FlipE(); px.FlipV();
|
2006-11-29 16:18:49 +01:00
|
|
|
angle = std::max<float>(angle , ComputeDihedralAngle(pi.v->P(), pj.v->P(), pk.v->P(), px.v->P()) );
|
2006-11-22 14:43:28 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2006-11-29 16:18:49 +01:00
|
|
|
angle = std::max<float>( angle, ComputeDihedralAngle(pi.v->P(),pj.v->P(), pk.v->P(), pv[ v[i][j] ].v->P()));
|
2006-10-06 17:28:14 +02:00
|
|
|
}
|
|
|
|
|
2006-11-22 14:43:28 +01:00
|
|
|
if(j + 1 == k)
|
2006-10-06 17:28:14 +02:00
|
|
|
{
|
2006-11-22 14:43:28 +01:00
|
|
|
px = pk;
|
|
|
|
px.FlipE(); px.FlipV();
|
2006-11-29 16:18:49 +01:00
|
|
|
angle = std::max<float>(angle , ComputeDihedralAngle(pj.v->P(), pk.v->P(), pi.v->P(), px.v->P()) );
|
2006-10-06 17:28:14 +02:00
|
|
|
}
|
2006-11-22 14:43:28 +01:00
|
|
|
else
|
|
|
|
{
|
2006-11-29 16:18:49 +01:00
|
|
|
angle = std::max<float>( angle, ComputeDihedralAngle(pj.v->P(),pk.v->P(), pi.v->P(), pv[ v[j][k] ].v->P()));
|
2006-11-22 14:43:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if( i == 0 && k == (int)v.size() - 1)
|
|
|
|
{
|
|
|
|
px = pi;
|
|
|
|
px.FlipE(); px.FlipV();
|
2006-11-29 16:18:49 +01:00
|
|
|
angle = std::max<float>(angle , ComputeDihedralAngle(pk.v->P(), pi.v->P(), pj.v->P(),px.v->P() ) );
|
2006-11-22 14:43:28 +01:00
|
|
|
}
|
|
|
|
|
2006-11-30 12:49:20 +01:00
|
|
|
ScalarType area = ( (pj.v->P() - pi.v->P()) ^ (pk.v->P() - pi.v->P()) ).Norm() * 0.5;
|
2006-11-22 14:43:28 +01:00
|
|
|
|
|
|
|
return Weight(angle, area);
|
2006-09-25 11:17:44 +02:00
|
|
|
}
|
2006-09-27 17:33:32 +02:00
|
|
|
|
2007-01-18 12:17:43 +01:00
|
|
|
static void calculateMinimumWeightTriangulation(MESH &m, FaceIterator f,std::vector<PosType > vv )
|
2006-10-18 17:06:47 +02:00
|
|
|
{
|
2006-11-22 14:43:28 +01:00
|
|
|
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
|
2006-10-18 17:06:47 +02:00
|
|
|
|
2006-11-22 14:43:28 +01:00
|
|
|
//hole size
|
|
|
|
int nv = vv.size();
|
2007-01-18 12:17:43 +01:00
|
|
|
|
2006-11-22 14:43:28 +01:00
|
|
|
w.clear();
|
|
|
|
w.resize( nv, std::vector<Weight>( nv, Weight() ) );
|
2006-10-18 17:06:47 +02:00
|
|
|
|
2006-11-22 14:43:28 +01:00
|
|
|
vi.resize( nv, std::vector<int>( nv, 0 ) );
|
|
|
|
|
|
|
|
//inizializzo tutti i pesi possibili del buco
|
|
|
|
for ( int i = 0; i < nv-1; ++i )
|
|
|
|
w[i][i+1] = Weight( 0, 0 );
|
|
|
|
|
|
|
|
//doppio ciclo for per calcolare di tutti i possibili triangoli i loro pesi.
|
|
|
|
for ( int j = 2; j < nv; ++j )
|
2006-10-18 17:06:47 +02:00
|
|
|
{
|
2006-11-22 14:43:28 +01:00
|
|
|
for ( int i = 0; i + j < nv; ++i )
|
2006-10-18 17:06:47 +02:00
|
|
|
{
|
2006-11-22 14:43:28 +01:00
|
|
|
//per ogni triangolazione mi mantengo il minimo valore del peso tra i triangoli possibili
|
|
|
|
Weight minval;
|
|
|
|
|
|
|
|
//indice del vertice che da il peso minimo nella triangolazione corrente
|
|
|
|
int minIndex = -1;
|
|
|
|
|
|
|
|
//ciclo tra i vertici in mezzo a i due prefissati
|
|
|
|
for ( int m = i + 1; m < i + j; ++m )
|
2006-10-18 17:06:47 +02:00
|
|
|
{
|
2006-11-22 14:43:28 +01:00
|
|
|
Weight a = w[i][m];
|
|
|
|
Weight b = w[m][i+j];
|
2006-11-29 16:18:49 +01:00
|
|
|
Weight newval = a + b + computeWeight( i, m, i+j, vv, vi);
|
2006-11-22 14:43:28 +01:00
|
|
|
if ( newval < minval )
|
2006-10-18 17:06:47 +02:00
|
|
|
{
|
2006-11-22 14:43:28 +01:00
|
|
|
minval = newval;
|
|
|
|
minIndex = m;
|
2006-10-18 17:06:47 +02:00
|
|
|
}
|
|
|
|
}
|
2006-11-22 14:43:28 +01:00
|
|
|
w[i][i+j] = minval;
|
|
|
|
vi[i][i+j] = minIndex;
|
|
|
|
}
|
2006-10-18 17:06:47 +02:00
|
|
|
}
|
|
|
|
|
2006-11-22 14:43:28 +01:00
|
|
|
//Triangulate
|
|
|
|
int i, j;
|
|
|
|
i=0; j=nv-1;
|
2007-01-18 12:17:43 +01:00
|
|
|
|
2007-01-31 16:25:49 +01:00
|
|
|
triangulate(m,f, i, j, vi, vv);
|
2007-01-31 12:46:12 +01:00
|
|
|
|
|
|
|
while(f!=m.face.end())
|
|
|
|
{
|
|
|
|
(*f).SetD();
|
|
|
|
++f;
|
|
|
|
m.fn--;
|
|
|
|
}
|
2006-10-18 17:06:47 +02:00
|
|
|
}
|
|
|
|
|
2006-11-29 16:18:49 +01:00
|
|
|
|
2007-01-31 12:46:12 +01:00
|
|
|
static void triangulate(MESH &m, FaceIterator &f,int i, int j,
|
2007-01-31 16:25:49 +01:00
|
|
|
std::vector< std::vector<int> > vi, std::vector<PosType > vv)
|
2006-10-18 17:06:47 +02:00
|
|
|
{
|
2006-11-22 14:43:28 +01:00
|
|
|
if(i + 1 == j){return;}
|
|
|
|
if(i==j)return;
|
|
|
|
|
|
|
|
int k = vi[i][j];
|
|
|
|
|
|
|
|
if(k == -1) return;
|
|
|
|
|
2007-01-18 12:17:43 +01:00
|
|
|
//Setto i vertici
|
|
|
|
f->V(0) = vv[i].v;
|
|
|
|
f->V(1) = vv[k].v;
|
|
|
|
f->V(2) = vv[j].v;
|
|
|
|
|
|
|
|
f++;
|
2007-01-31 16:25:49 +01:00
|
|
|
triangulate(m,f,i,k,vi,vv);
|
|
|
|
triangulate(m,f,k,j,vi,vv);
|
2006-11-22 14:43:28 +01:00
|
|
|
}
|
|
|
|
|
2007-01-18 12:17:43 +01:00
|
|
|
static void MinimumWeightFill(MESH &m, int holeSize, bool Selected)
|
2006-11-22 14:43:28 +01:00
|
|
|
{
|
2006-11-29 16:18:49 +01:00
|
|
|
FaceIterator fi;
|
|
|
|
std::vector<PosType > vvi;
|
|
|
|
std::vector<FacePointer * > vfp;
|
2006-11-22 14:43:28 +01:00
|
|
|
|
2006-11-29 16:18:49 +01:00
|
|
|
std::vector<Info > vinfo;
|
|
|
|
typename std::vector<Info >::iterator VIT;
|
|
|
|
int UBIT = GetInfo(m, Selected,vinfo);
|
2006-10-18 17:06:47 +02:00
|
|
|
|
2006-11-22 14:43:28 +01:00
|
|
|
for(VIT = vinfo.begin(); VIT != vinfo.end();++VIT)
|
2006-10-18 17:06:47 +02:00
|
|
|
{
|
2006-11-22 14:43:28 +01:00
|
|
|
vvi.push_back(VIT->p);
|
|
|
|
}
|
2006-10-18 17:06:47 +02:00
|
|
|
|
2006-11-29 16:18:49 +01:00
|
|
|
typename std::vector<PosType >::iterator ith;
|
|
|
|
typename std::vector<PosType >::iterator ithn;
|
|
|
|
typename std::vector<VertexPointer >::iterator itf;
|
2006-10-18 17:06:47 +02:00
|
|
|
|
2006-11-29 16:18:49 +01:00
|
|
|
std::vector<PosType > app;
|
|
|
|
PosType ps;
|
|
|
|
std::vector<FaceType > tr;
|
|
|
|
std::vector<VertexPointer > vf;
|
2006-11-22 14:43:28 +01:00
|
|
|
|
|
|
|
for(ith = vvi.begin(); ith!= vvi.end(); ++ith)
|
2006-10-18 17:06:47 +02:00
|
|
|
{
|
2006-11-22 14:43:28 +01:00
|
|
|
tr.clear();
|
|
|
|
vf.clear();
|
|
|
|
app.clear();
|
|
|
|
vfp.clear();
|
2006-10-18 17:06:47 +02:00
|
|
|
|
2006-11-22 14:43:28 +01:00
|
|
|
ps = *ith;
|
2006-11-29 16:18:49 +01:00
|
|
|
getBoundHole(ps,app);
|
|
|
|
|
2007-01-18 12:17:43 +01:00
|
|
|
if(app.size() <= holeSize)
|
|
|
|
{
|
2007-01-18 19:15:14 +01:00
|
|
|
typename std::vector<PosType >::iterator itP;
|
2007-01-18 12:17:43 +01:00
|
|
|
std::vector<FacePointer *> vfp;
|
2006-11-22 14:43:28 +01:00
|
|
|
|
2007-01-18 12:17:43 +01:00
|
|
|
for(ithn = vvi.begin(); ithn!= vvi.end(); ++ithn)
|
|
|
|
vfp.push_back(&(ithn->f));
|
2006-11-22 14:43:28 +01:00
|
|
|
|
2007-01-18 12:17:43 +01:00
|
|
|
for(itP = app.begin (); itP != app.end ();++itP)
|
|
|
|
vfp.push_back( &(*itP).f );
|
2006-11-22 14:43:28 +01:00
|
|
|
|
2007-01-18 12:17:43 +01:00
|
|
|
//aggiungo le facce
|
|
|
|
FaceIterator f = tri::Allocator<MESH>::AddFaces(m, (app.size()-2) , vfp);
|
2006-11-29 16:18:49 +01:00
|
|
|
|
2007-01-18 12:17:43 +01:00
|
|
|
calculateMinimumWeightTriangulation(m,f, app);
|
|
|
|
}
|
2006-11-22 14:43:28 +01:00
|
|
|
}
|
2006-11-29 16:18:49 +01:00
|
|
|
|
2006-11-22 14:43:28 +01:00
|
|
|
}
|
|
|
|
|
2006-11-29 17:21:45 +01:00
|
|
|
static void getBoundHole (PosType sp,std::vector<PosType >&ret)
|
2006-11-22 14:43:28 +01:00
|
|
|
{
|
2006-11-29 16:18:49 +01:00
|
|
|
PosType fp = sp;
|
2006-11-22 14:43:28 +01:00
|
|
|
//take vertex around the hole
|
|
|
|
do
|
2006-10-18 17:06:47 +02:00
|
|
|
{
|
2006-11-22 14:43:28 +01:00
|
|
|
assert(fp.IsBorder());
|
|
|
|
ret.push_back(fp);
|
|
|
|
fp.NextB();
|
|
|
|
}while(sp != fp);
|
2006-10-18 17:06:47 +02:00
|
|
|
}
|
2006-11-22 14:43:28 +01:00
|
|
|
|
2006-11-29 16:18:49 +01:00
|
|
|
};//close class Hole
|
|
|
|
|
2006-10-06 17:28:14 +02:00
|
|
|
} // end namespace
|
2006-09-27 11:29:53 +02:00
|
|
|
}
|
2006-11-07 12:47:14 +01:00
|
|
|
#endif
|