Cleaned up a bit triangle3. Removed some weird interpolation wrappers (that ended to be misused) and updated the rest of the lib to comply with this changes
This commit is contained in:
parent
57cfc71a34
commit
f8eb8a41dd
|
@ -1235,7 +1235,7 @@ private:
|
|||
Triangle3<float> t1(f->P(i), f->P1(i), f->P2(i)), t2(g->P(k), g->P1(k), g->P2(k)),
|
||||
t3(f->P(i), g->P2(k), f->P2(i)), t4(g->P(k), f->P2(i), g->P2(k));
|
||||
|
||||
if ( std::min( t1.QualityFace(), t2.QualityFace() ) < std::min( t3.QualityFace(), t4.QualityFace() ))
|
||||
if ( std::min( QualityFace(t1), QualityFace(t2) ) < std::min( QualityFace(t3), QualityFace(t4) ))
|
||||
{
|
||||
face::FlipEdge<FaceType>( *f, i );
|
||||
++count; ++total;
|
||||
|
|
|
@ -20,108 +20,7 @@
|
|||
* for more details. *
|
||||
* *
|
||||
****************************************************************************/
|
||||
/****************************************************************************
|
||||
History
|
||||
|
||||
$Log: not supported by cvs2svn $
|
||||
Revision 1.27 2006/12/06 12:59:13 pietroni
|
||||
added max distance to rayIterator
|
||||
|
||||
Revision 1.26 2006/11/21 16:06:54 ponchio
|
||||
passing VDistFunct() to functions wanting a reference, not a value
|
||||
(why a reference btw?)
|
||||
|
||||
Revision 1.25 2006/11/13 13:13:49 ponchio
|
||||
Added usual typename.
|
||||
|
||||
Revision 1.24 2006/11/12 02:41:03 pietroni
|
||||
added normalization of normal in DoRay functions
|
||||
|
||||
Revision 1.23 2006/11/10 11:41:49 pietroni
|
||||
added DoRayFuntion that return interpolated normal
|
||||
|
||||
Revision 1.22 2006/09/20 17:18:26 ponchio
|
||||
VDistFunct() at line 292 was passed as a temporary.
|
||||
Invalid under g++. Fixed.
|
||||
|
||||
Revision 1.21 2006/02/09 08:38:04 pietroni
|
||||
sintax error corrected
|
||||
|
||||
Revision 1.20 2006/02/08 17:02:41 pietroni
|
||||
commented one GetClosestFace function ... the code is the same then getClosest that return barycentric coordinates
|
||||
|
||||
Revision 1.19 2006/01/10 13:31:54 pietroni
|
||||
correct pass of variable closest_pt by reference in getclosestFace function
|
||||
|
||||
Revision 1.18 2005/12/02 00:13:34 cignoni
|
||||
Added and removed typenames for gcc compiling.
|
||||
removed also some template arguments specifcation that gcc disliked...
|
||||
commented out GetInSphereFace and SetMesh that are probably never used and i didnt succeed in compile
|
||||
|
||||
Revision 1.17 2005/10/05 17:02:52 pietroni
|
||||
corrected bugs on GEtKClosestVert and GetInSphereVert
|
||||
|
||||
Revision 1.16 2005/10/03 16:19:07 spinelli
|
||||
fixed some bugs
|
||||
|
||||
Revision 1.15 2005/10/03 13:59:39 pietroni
|
||||
added GetInSphere and GetInBox functions
|
||||
rensmed Functions respectively with Face suffix or Vertex suffix for query on vertex or faces
|
||||
|
||||
Revision 1.14 2005/09/30 13:10:37 pietroni
|
||||
used functor defined in face/distance.h for distance point-face
|
||||
used functor defined in intersection3.h for ray-triangle intersection
|
||||
added GetKClosest and DoRay Functions
|
||||
|
||||
Revision 1.13 2005/09/28 08:30:48 cignoni
|
||||
changed name of include, removed use of an undefined type (scalar instead of Scalar)
|
||||
removed unused code portions (the old closest code)
|
||||
|
||||
Revision 1.12 2005/09/21 09:24:30 pietroni
|
||||
Added RayIterators.
|
||||
Added ClosestIterators on Triangles and Vertices.
|
||||
Added Closest Functions on triangles and Vertices.
|
||||
|
||||
Revision 1.11 2005/09/19 13:36:24 pietroni
|
||||
added ray iterator of faces
|
||||
|
||||
Revision 1.10 2005/09/16 11:53:51 cignoni
|
||||
Small gcc compliling issues
|
||||
|
||||
Revision 1.9 2005/09/15 13:16:10 spinelli
|
||||
fixed bugs
|
||||
|
||||
Revision 1.8 2005/09/15 11:15:00 pietroni
|
||||
minor changes
|
||||
|
||||
Revision 1.7 2005/09/14 12:56:47 pietroni
|
||||
used closest function from grid
|
||||
|
||||
Revision 1.6 2005/08/26 09:12:48 cignoni
|
||||
changed typedef A2UGridLink da 'GridStaticPtr<MESH::FaceContainer,double>::Link' a typedef 'GRID::Link'
|
||||
|
||||
Revision 1.5 2005/02/08 17:49:38 pietroni
|
||||
added if (!l->Elem()->IsD()) test on each element
|
||||
|
||||
Revision 1.4 2005/01/28 12:00:33 cignoni
|
||||
small gcc compiling issues for namespaces
|
||||
|
||||
Revision 1.3 2005/01/24 11:47:23 cignoni
|
||||
Now used also by the official Metro
|
||||
Removed using namespace (NEVER IN HEADERS!)
|
||||
Made the computation of barycentric coords only when necessary
|
||||
Renamed Mindistpoint to Closest
|
||||
|
||||
Revision 1.2 2005/01/21 17:13:09 pietroni
|
||||
included distance.h changed Dist to vcg::face::PointDistance
|
||||
|
||||
Revision 1.1 2004/10/04 15:32:16 ganovelli
|
||||
moved from metro core
|
||||
|
||||
Revision 1.6 2004/05/14 00:34:36 ganovelli
|
||||
header added
|
||||
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __VCG_TRIMESH_CLOSEST
|
||||
#define __VCG_TRIMESH_CLOSEST
|
||||
|
@ -211,12 +110,10 @@ namespace vcg {
|
|||
// f=bestf;
|
||||
typename MESH::ScalarType alfa, beta, gamma;
|
||||
//calcolo normale con interpolazione trilineare
|
||||
InterpolationParameters<typename MESH::FaceType,typename MESH::ScalarType>(*bestf,bestf->N(),_closestPt, alfa, beta, gamma);
|
||||
_normf = (bestf->V(0)->cN())*alfa+
|
||||
(bestf->V(1)->cN())*beta+
|
||||
(bestf->V(2)->cN())*gamma ;
|
||||
_ip=Point3x(alfa,beta,gamma);
|
||||
//normf.Normalize(); inutile si assume le normali ai vertici benfatte
|
||||
InterpolationParameters<typename MESH::FaceType,typename MESH::ScalarType>(*bestf,bestf->N(),_closestPt, _ip);
|
||||
_normf = (bestf->V(0)->cN())*_ip[0]+
|
||||
(bestf->V(1)->cN())*_ip[1]+
|
||||
(bestf->V(2)->cN())*_ip[2] ;
|
||||
|
||||
_minDist = fabs(_minDist);
|
||||
return(bestf);
|
||||
|
|
|
@ -721,15 +721,7 @@ static int SingleFaceSubdivisionOld(int sampleNum, const CoordType & v0, const C
|
|||
else SamplePoint=((v0+v1+v2)*(1.0f/3.0f));
|
||||
|
||||
CoordType SampleBary;
|
||||
// int axis;
|
||||
// if(fp->Flags() & FaceType::NORMX ) axis = 0;
|
||||
// else if(fp->Flags() & FaceType::NORMY ) axis = 1;
|
||||
// else {
|
||||
// assert(fp->Flags() & FaceType::NORMZ) ;
|
||||
// axis =2;
|
||||
// }
|
||||
// InterpolationParameters(*fp,axis,SamplePoint,SampleBary);
|
||||
InterpolationParameters(*fp,SamplePoint,SampleBary[0],SampleBary[1],SampleBary[2]);
|
||||
InterpolationParameters(*fp,SamplePoint,SampleBary);
|
||||
ps.AddFace(*fp,SampleBary);
|
||||
return 1;
|
||||
}
|
||||
|
|
|
@ -20,76 +20,7 @@
|
|||
* for more details. *
|
||||
* *
|
||||
****************************************************************************/
|
||||
/****************************************************************************
|
||||
History
|
||||
|
||||
$Log: not supported by cvs2svn $
|
||||
Revision 1.21 2007/12/02 07:39:19 cignoni
|
||||
disambiguated sqrt call
|
||||
|
||||
Revision 1.20 2007/11/26 14:11:38 ponchio
|
||||
Added Mean Ratio metric for triangle quality.
|
||||
|
||||
Revision 1.19 2007/11/19 17:04:05 ponchio
|
||||
QualityRadii values fixed.
|
||||
|
||||
Revision 1.18 2007/11/18 19:12:54 ponchio
|
||||
Typo (missing comma).
|
||||
|
||||
Revision 1.17 2007/11/16 14:22:35 ponchio
|
||||
Added qualityRadii: computes inradius /circumradius.
|
||||
(ok the name is ugly...)
|
||||
|
||||
Revision 1.16 2007/10/10 15:11:30 ponchio
|
||||
Added Circumcenter function.
|
||||
|
||||
Revision 1.15 2007/05/10 09:31:15 cignoni
|
||||
Corrected InterpolationParameters invocation
|
||||
|
||||
Revision 1.14 2007/05/04 16:33:27 ganovelli
|
||||
moved InterpolationParamaters out the class Triangle
|
||||
|
||||
Revision 1.13 2007/04/04 23:23:55 pietroni
|
||||
- corrected and renamed distance to point ( function TrianglePointDistance)
|
||||
|
||||
Revision 1.12 2007/01/13 00:25:23 cignoni
|
||||
Added (Normalized) Normal version templated on three points (instead forcing the creation of a new triangle)
|
||||
|
||||
Revision 1.11 2006/10/17 06:51:33 fiorin
|
||||
In function Barycenter, replaced calls to (the inexistent) cP(i) with P(i)
|
||||
|
||||
Revision 1.10 2006/10/10 09:33:47 cignoni
|
||||
added quality for triangle wrap
|
||||
|
||||
Revision 1.9 2006/09/14 08:44:07 ganovelli
|
||||
changed t.P(*) in t.cP() nella funzione Barycenter
|
||||
|
||||
Revision 1.8 2006/06/01 08:38:58 pietroni
|
||||
added PointDistance function
|
||||
|
||||
Revision 1.7 2006/03/01 15:35:09 pietroni
|
||||
compiled InterspolationParameters function
|
||||
|
||||
Revision 1.6 2006/01/22 10:00:56 cignoni
|
||||
Very Important Change: Area->DoubleArea (and no more Area function)
|
||||
|
||||
Revision 1.5 2005/09/23 14:18:27 ganovelli
|
||||
added constructor
|
||||
|
||||
Revision 1.4 2005/04/14 11:35:09 ponchio
|
||||
*** empty log message ***
|
||||
|
||||
Revision 1.3 2004/07/15 13:22:37 cignoni
|
||||
Added the standard P() access function instead of the shortcut P0()
|
||||
|
||||
Revision 1.2 2004/07/15 10:17:42 pietroni
|
||||
correct access to point funtions call in usage of triangle3 (ex. t.P(0) in t.P0(0))
|
||||
|
||||
Revision 1.1 2004/03/08 01:13:31 cignoni
|
||||
Initial commit
|
||||
|
||||
|
||||
****************************************************************************/
|
||||
#ifndef __VCG_TRIANGLE3
|
||||
#define __VCG_TRIANGLE3
|
||||
|
||||
|
@ -132,42 +63,56 @@ public:
|
|||
inline CoordType & P0( const int j ) { return _v[j];}
|
||||
inline CoordType & P1( const int j ) { return _v[(j+1)%3];}
|
||||
inline CoordType & P2( const int j ) { return _v[(j+2)%3];}
|
||||
inline const CoordType & P( const int j ) const { return _v[j];}
|
||||
inline const CoordType & P0( const int j ) const { return _v[j];}
|
||||
inline const CoordType & P( const int j ) const { return _v[j];}
|
||||
inline const CoordType & cP( const int j ) const { return _v[j];}
|
||||
inline const CoordType & P0( const int j ) const { return _v[j];}
|
||||
inline const CoordType & P1( const int j ) const { return _v[(j+1)%3];}
|
||||
inline const CoordType & P2( const int j ) const { return _v[(j+2)%3];}
|
||||
inline const CoordType & cP0( const int j ) const { return _v[j];}
|
||||
inline const CoordType & cP1( const int j ) const { return _v[(j+1)%3];}
|
||||
inline const CoordType & cP2( const int j ) const { return _v[(j+2)%3];}
|
||||
|
||||
bool InterpolationParameters(const CoordType & bq, ScalarType &a, ScalarType &b, ScalarType &_c ) const{
|
||||
return InterpolationParameters(*this, bq, a, b,_c );
|
||||
}
|
||||
|
||||
/// Return the _q of the face, the return value is in [0,sqrt(3)/2] = [0 - 0.866.. ]
|
||||
ScalarType QualityFace( ) const
|
||||
{
|
||||
return Quality(P(0), P(1), P(2));
|
||||
}
|
||||
|
||||
}; //end Class
|
||||
|
||||
/********************** Normal **********************/
|
||||
|
||||
/// Returns the normal to the plane passing through p0,p1,p2
|
||||
template<class TriangleType>
|
||||
typename TriangleType::ScalarType QualityFace(const TriangleType &t)
|
||||
Point3<typename TriangleType::ScalarType> Normal(const TriangleType &t)
|
||||
{
|
||||
return Quality(t.cP(0), t.cP(1), t.cP(2));
|
||||
return (( t.P(1) - t.P(0)) ^ (t.P(2) - t.P(0)));
|
||||
}
|
||||
template<class Point3Type>
|
||||
Point3Type Normal( Point3Type const &p0, Point3Type const & p1, Point3Type const & p2)
|
||||
{
|
||||
return (( p1 - p0) ^ (p2 - p0));
|
||||
}
|
||||
|
||||
// More robust function to computing barycentric coords of a point inside a triangle.
|
||||
/// Like the above, it returns the normal to the plane passing through p0,p1,p2, but normalized.
|
||||
template<class TriangleType>
|
||||
Point3<typename TriangleType::ScalarType> NormalizedNormal(const TriangleType &t)
|
||||
{
|
||||
return (( t.P(1) - t.P(0)) ^ (t.P(2) - t.P(0))).Normalize();
|
||||
}
|
||||
template<class Point3Type>
|
||||
Point3Type NormalizedNormal( Point3Type const &p0, Point3Type const & p1, Point3Type const & p2)
|
||||
{
|
||||
return (( p1 - p0) ^ (p2 - p0)).Normalize();
|
||||
}
|
||||
|
||||
|
||||
|
||||
/********************** Interpolation **********************/
|
||||
|
||||
// The function to computing barycentric coords of a point inside a triangle.
|
||||
// it requires the knowledge of what is the direction that is more orthogonal to the face plane.
|
||||
// Usually this info can be stored in a bit of the face flags (see updateFlags::FaceProjection(MeshType &m) )
|
||||
// and accessing the field with
|
||||
// if(fp->Flags() & FaceType::NORMX ) axis = 0;
|
||||
// else if(fp->Flags() & FaceType::NORMY ) axis = 1;
|
||||
// else axis =2;
|
||||
// InterpolationParameters(*fp,axis,Point,Bary);
|
||||
// This direction is used to project the triangle in 2D and solve the problem in 2D where it is well defined.
|
||||
// InterpolationParameters(*fp,axis,Point,L);
|
||||
// This normal direction is used to project the triangle in 2D and solve the problem in 2D where it is simpler and often well defined.
|
||||
|
||||
template<class TriangleType, class ScalarType>
|
||||
bool InterpolationParameters(const TriangleType t, const int Axis, const Point3<ScalarType> & P, Point3<ScalarType> & L)
|
||||
|
@ -199,9 +144,7 @@ bool InterpolationParameters(const TriangleType t, const Point3<ScalarType> & N,
|
|||
}
|
||||
}
|
||||
|
||||
// Function that computes the barycentric coords of a 2D triangle. Used by the above function.
|
||||
// Algorithm: simply find a base for the frame of the triangle, assuming v3 as origin (matrix T) invert it and apply to P-v3.
|
||||
|
||||
// Function that computes the barycentric coords of a 2D triangle.
|
||||
template<class ScalarType>
|
||||
bool InterpolationParameters2(const Point2<ScalarType> &V1,
|
||||
const Point2<ScalarType> &V2,
|
||||
|
@ -212,63 +155,17 @@ bool InterpolationParameters2(const Point2<ScalarType> &V1,
|
|||
return (t2.InterpolationParameters(P,L.X(),L.Y(),L.Z() ));
|
||||
}
|
||||
|
||||
//// Function that computes the barycentric coords of a 2D triangle. Used by the above function.
|
||||
//// Algorithm: simply find a base for the frame of the triangle, assuming v3 as origin (matrix T) invert it and apply to P-v3.
|
||||
//
|
||||
//template<class ScalarType>
|
||||
//bool InterpolationParameters2(const Point2<ScalarType> &V1,
|
||||
// const Point2<ScalarType> &V2,
|
||||
// const Point2<ScalarType> &V3,
|
||||
// const Point2<ScalarType> &P, Point3<ScalarType> &L)
|
||||
//{
|
||||
// ScalarType T00 = V1[0]-V3[0]; ScalarType T01 = V2[0]-V3[0];
|
||||
// ScalarType T10 = V1[1]-V3[1]; ScalarType T11 = V2[1]-V3[1];
|
||||
// ScalarType Det = T00 * T11 - T01*T10;
|
||||
// if(fabs(Det) < 0.0000001)
|
||||
// return false;
|
||||
//
|
||||
// ScalarType IT00 = T11/Det; ScalarType IT01 = -T01/Det;
|
||||
// ScalarType IT10 = -T10/Det; ScalarType IT11 = T00/Det;
|
||||
//
|
||||
// Point2<ScalarType> Delta = P-V3;
|
||||
//
|
||||
// L[0] = IT00*Delta[0] + IT01*Delta[1];
|
||||
// L[1] = IT10*Delta[0] + IT11*Delta[1];
|
||||
//
|
||||
// if(L[0]<0) L[0]=0;
|
||||
// if(L[1]<0) L[1]=0;
|
||||
// if(L[0]>1.) L[0]=1;
|
||||
// if(L[1]>1.) L[1]=1;
|
||||
//
|
||||
// L[2] = 1. - L[1] - L[0];
|
||||
// if(L[2]<0) L[2]=0;
|
||||
//
|
||||
// assert(L[2] >= -0.00001);
|
||||
//
|
||||
// return true;
|
||||
//}
|
||||
|
||||
|
||||
/** Calcola i coefficienti della combinazione convessa.
|
||||
@param bq Punto appartenente alla faccia
|
||||
@param a Valore di ritorno per il vertice V(0)
|
||||
@param b Valore di ritorno per il vertice V(1)
|
||||
@param _c Valore di ritorno per il vertice V(2)
|
||||
@return true se bq appartiene alla faccia, false altrimenti
|
||||
*/
|
||||
/// Handy Wrapper of the above one that calculate the normal on the triangle
|
||||
template<class TriangleType, class ScalarType>
|
||||
bool InterpolationParameters(const TriangleType t,const Point3<ScalarType> & N,const Point3<ScalarType> & bq, ScalarType &a, ScalarType &b, ScalarType &c )
|
||||
bool InterpolationParameters(const TriangleType t, const Point3<ScalarType> & P, Point3<ScalarType> & L)
|
||||
{
|
||||
Point3<ScalarType> bary;
|
||||
bool done= InterpolationParameters(t,N,bq,bary);
|
||||
a=bary[0];
|
||||
b=bary[1];
|
||||
c=bary[2];
|
||||
return done;
|
||||
|
||||
vcg::Point3<ScalarType> N=vcg::Normal<TriangleType>(t);
|
||||
return (InterpolationParameters<TriangleType,ScalarType>(t,N,P,L));
|
||||
}
|
||||
|
||||
|
||||
/********************** Quality **********************/
|
||||
|
||||
/// Compute a shape quality measure of the triangle composed by points p0,p1,p2
|
||||
/// It Returns 2*AreaTri/(MaxEdge^2),
|
||||
/// the range is range [0.0, 0.866]
|
||||
|
@ -292,6 +189,12 @@ P3ScalarType Quality( Point3<P3ScalarType> const &p0, Point3<P3ScalarType> const
|
|||
}
|
||||
|
||||
|
||||
/// Return the _q of the face, the return value is in [0,sqrt(3)/2] = [0 - 0.866.. ]
|
||||
template<class TriangleType>
|
||||
typename TriangleType::ScalarType QualityFace(const TriangleType &t)
|
||||
{
|
||||
return Quality(t.cP(0), t.cP(1), t.cP(2));
|
||||
}
|
||||
/// Compute a shape quality measure of the triangle composed by points p0,p1,p2
|
||||
/// It Returns inradius/circumradius
|
||||
/// the range is range [0, 1]
|
||||
|
@ -331,40 +234,8 @@ P3ScalarType QualityMeanRatio(Point3<P3ScalarType> const &p0,
|
|||
return (4.0*sqrt(3.0)*sqrt(area2))/(a*a + b*b + c*c);
|
||||
}
|
||||
|
||||
/// Returns the normal to the plane passing through p0,p1,p2
|
||||
template<class TriangleType>
|
||||
Point3<typename TriangleType::ScalarType> Normal(const TriangleType &t)
|
||||
{
|
||||
return (( t.P(1) - t.P(0)) ^ (t.P(2) - t.P(0)));
|
||||
}
|
||||
template<class Point3Type>
|
||||
Point3Type Normal( Point3Type const &p0, Point3Type const & p1, Point3Type const & p2)
|
||||
{
|
||||
return (( p1 - p0) ^ (p2 - p0));
|
||||
}
|
||||
|
||||
|
||||
/// Like the above, it returns the normal to the plane passing through p0,p1,p2, but normalized.
|
||||
template<class TriangleType>
|
||||
Point3<typename TriangleType::ScalarType> NormalizedNormal(const TriangleType &t)
|
||||
{
|
||||
return (( t.P(1) - t.P(0)) ^ (t.P(2) - t.P(0))).Normalize();
|
||||
}
|
||||
template<class Point3Type>
|
||||
Point3Type NormalizedNormal( Point3Type const &p0, Point3Type const & p1, Point3Type const & p2)
|
||||
{
|
||||
return (( p1 - p0) ^ (p2 - p0)).Normalize();
|
||||
}
|
||||
|
||||
|
||||
/// Handy Wrapper of the above one that calculate the normal on the triangle
|
||||
template<class TriangleType, class ScalarType>
|
||||
bool InterpolationParameters(const TriangleType t, const Point3<ScalarType> & P, Point3<ScalarType> & L)
|
||||
{
|
||||
vcg::Point3<ScalarType> N=vcg::Normal<TriangleType>(t);
|
||||
return (InterpolationParameters<TriangleType,ScalarType>(t,N,P,L));
|
||||
}
|
||||
|
||||
/// Return the Double of area of the triangle
|
||||
// NOTE the old Area function has been removed to intentionally
|
||||
// cause compiling error that will help people to check their code...
|
||||
|
|
Loading…
Reference in New Issue