2004-04-22 15:19:12 +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. *
|
|
|
|
* *
|
|
|
|
****************************************************************************/
|
|
|
|
/****************************************************************************
|
|
|
|
History
|
|
|
|
|
|
|
|
$Log: not supported by cvs2svn $
|
2004-07-09 12:08:21 +02:00
|
|
|
Revision 1.6 2004/06/25 18:17:03 ganovelli
|
|
|
|
minor changes
|
|
|
|
|
2004-06-25 20:17:03 +02:00
|
|
|
Revision 1.5 2004/05/13 12:51:00 turini
|
|
|
|
Changed SolidAngle : table EV in table EofV
|
|
|
|
Changed DiedralAngle : tables FE and FV in tables FofE and FofV
|
|
|
|
|
2004-05-13 14:51:00 +02:00
|
|
|
Revision 1.4 2004/05/13 08:42:36 pietroni
|
|
|
|
the relation between entities functions are in tetra class (don't neeed template argoument)
|
|
|
|
|
2004-05-13 10:42:36 +02:00
|
|
|
Revision 1.3 2004/04/28 16:31:17 turini
|
|
|
|
Changed :
|
|
|
|
in SolidAngle(vind) :
|
|
|
|
double da0=DiedralAngle(EV(vind,0));
|
|
|
|
double da1=DiedralAngle(EV(vind,1));
|
|
|
|
double da2=DiedralAngle(EV(vind,2));
|
|
|
|
in
|
|
|
|
double da0=DiedralAngle(EofV(vind,0));
|
|
|
|
double da1=DiedralAngle(EofV(vind,1));
|
|
|
|
double da2=DiedralAngle(EofV(vind,2));
|
|
|
|
|
|
|
|
Changed :
|
|
|
|
in DiedralAngle(edgeind) :
|
|
|
|
int f1=FE(edgeind,0);
|
|
|
|
int f2=FE(edgeind,1);
|
|
|
|
in
|
|
|
|
int f1=FofE(edgeind,0);
|
|
|
|
int f2=FofE(edgeind,1);
|
|
|
|
|
|
|
|
Changed :
|
|
|
|
in DiedralAngle(edgeind) :
|
|
|
|
Point3d p0=FV(f1,0)->P();
|
|
|
|
Point3d p1=FV(f1,1)->P();
|
|
|
|
Point3d p2=FV(f1,2)->P();
|
|
|
|
in
|
|
|
|
Point3d p0=_v[FofV(f1,0)];
|
|
|
|
Point3d p1=_v[FofV(f1,1)];
|
|
|
|
Point3d p2=_v[FofV(f1,2)];
|
|
|
|
|
|
|
|
Changed :
|
|
|
|
in DiedralAngle(edgeind) :
|
|
|
|
p0=FV(f2,0)->P();
|
|
|
|
p1=FV(f2,1)->P();
|
|
|
|
p2=FV(f2,2)->P();
|
|
|
|
in
|
|
|
|
p0=_v[FofV(f2,0)];
|
|
|
|
p1=_v[FofV(f2,1)];
|
|
|
|
p2=_v[FofV(f2,2)];
|
|
|
|
|
Changed :
in SolidAngle(vind) :
double da0=DiedralAngle(EV(vind,0));
double da1=DiedralAngle(EV(vind,1));
double da2=DiedralAngle(EV(vind,2));
in
double da0=DiedralAngle(EofV(vind,0));
double da1=DiedralAngle(EofV(vind,1));
double da2=DiedralAngle(EofV(vind,2));
Changed :
in DiedralAngle(edgeind) :
int f1=FE(edgeind,0);
int f2=FE(edgeind,1);
in
int f1=FofE(edgeind,0);
int f2=FofE(edgeind,1);
Changed :
in DiedralAngle(edgeind) :
Point3d p0=FV(f1,0)->P();
Point3d p1=FV(f1,1)->P();
Point3d p2=FV(f1,2)->P();
in
Point3d p0=_v[FofV(f1,0)];
Point3d p1=_v[FofV(f1,1)];
Point3d p2=_v[FofV(f1,2)];
Changed :
in DiedralAngle(edgeind) :
p0=FV(f2,0)->P();
p1=FV(f2,1)->P();
p2=FV(f2,2)->P();
in
p0=_v[FofV(f2,0)];
p1=_v[FofV(f2,1)];
p2=_v[FofV(f2,2)];
2004-04-28 18:31:17 +02:00
|
|
|
Revision 1.2 2004/04/28 11:37:15 pietroni
|
|
|
|
*** empty log message ***
|
|
|
|
|
2004-04-28 13:37:15 +02:00
|
|
|
Revision 1.1 2004/04/22 13:19:12 ganovelli
|
|
|
|
first version
|
|
|
|
|
2004-04-22 15:19:12 +02:00
|
|
|
Revision 1.2 2004/04/20 16:26:48 pietroni
|
|
|
|
*** empty log message ***
|
|
|
|
|
|
|
|
Revision 1.1 2004/04/15 08:54:20 pietroni
|
|
|
|
*** empty log message ***
|
|
|
|
|
|
|
|
Revision 1.1 2004/04/08 01:13:31 pietroni
|
|
|
|
Initial commit
|
|
|
|
|
|
|
|
|
|
|
|
****************************************************************************/
|
|
|
|
#ifndef __VCG_TETRA3
|
|
|
|
#define __VCG_TETRA3
|
|
|
|
|
2004-06-25 20:17:03 +02:00
|
|
|
#include <vcg/space/point3.h>
|
|
|
|
|
2004-04-22 15:19:12 +02:00
|
|
|
namespace vcg {
|
|
|
|
/** \addtogroup space */
|
|
|
|
/*@{*/
|
|
|
|
/**
|
2004-05-13 10:42:36 +02:00
|
|
|
Templated class for storing a generic tetrahedron
|
2004-04-22 15:19:12 +02:00
|
|
|
|
|
|
|
|
2004-05-13 10:42:36 +02:00
|
|
|
*/
|
|
|
|
class Tetra
|
|
|
|
{
|
2004-04-22 15:19:12 +02:00
|
|
|
public:
|
|
|
|
|
2004-05-13 10:42:36 +02:00
|
|
|
|
2004-04-22 15:19:12 +02:00
|
|
|
//Tatrahedron Functions to retrieve information about relation between faces of tetrahedron(faces,adges,vertices).
|
|
|
|
|
|
|
|
static int VofE(const int &indexE,const int &indexV)
|
|
|
|
{ assert ((indexE<6)&&(indexV<2));
|
2004-05-13 10:42:36 +02:00
|
|
|
static int edgevert[6][2] ={{0,1},
|
2004-04-22 15:19:12 +02:00
|
|
|
{0,2},
|
|
|
|
{0,3},
|
|
|
|
{1,2},
|
|
|
|
{1,3},
|
|
|
|
{2,3}};
|
|
|
|
return (edgevert[indexE][indexV]);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int VofF(const int &indexF,const int &indexV)
|
|
|
|
{ assert ((indexF<4)&&(indexV<3));
|
|
|
|
static int facevert[4][3]={{0,1,2},
|
|
|
|
{0,3,1},
|
|
|
|
{0,2,3},
|
|
|
|
{1,3,2}};
|
|
|
|
return (facevert[indexF][indexV]);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int EofV(const int &indexV,const int &indexE)
|
|
|
|
{
|
|
|
|
assert ((indexE<3)&&(indexV<4));
|
|
|
|
static int vertedge[4][3]={{0,1,2},
|
|
|
|
{0,3,4},
|
|
|
|
{5,1,3},
|
|
|
|
{4,5,2}};
|
|
|
|
return vertedge[indexV][indexE];
|
|
|
|
}
|
|
|
|
|
|
|
|
static int EofF(const int &indexF,const int &indexE)
|
2004-05-13 10:42:36 +02:00
|
|
|
{ assert ((indexF<4)&&(indexE<3));
|
2004-04-22 15:19:12 +02:00
|
|
|
static int faceedge[4][3]={{0,3,1},
|
|
|
|
{2,4,0},
|
|
|
|
{1,5,2},
|
|
|
|
{4,5,3}
|
|
|
|
};
|
2004-05-13 10:42:36 +02:00
|
|
|
return faceedge [indexF][indexE];
|
2004-04-22 15:19:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static int FofV(const int &indexV,const int &indexF)
|
|
|
|
{
|
|
|
|
assert ((indexV<4)&&(indexF<3));
|
|
|
|
static int vertface[4][3]={{0,1,2},
|
|
|
|
{0,3,1},
|
|
|
|
{0,2,3},
|
|
|
|
{1,3,2}};
|
|
|
|
return vertface[indexV][indexF];
|
|
|
|
}
|
|
|
|
|
2004-04-28 13:37:15 +02:00
|
|
|
static int FofE(const int &indexE,const int &indexSide)
|
|
|
|
{ assert ((indexE<6)&&(indexSide<2));
|
2004-04-22 15:19:12 +02:00
|
|
|
static int edgeface[6][2]={{0,1},
|
|
|
|
{0,2},
|
|
|
|
{1,2},
|
|
|
|
{0,3},
|
|
|
|
{1,3},
|
|
|
|
{2,3}};
|
|
|
|
return edgeface [indexE][indexSide];
|
|
|
|
}
|
|
|
|
|
|
|
|
static int VofEE(const int &indexE0,const int &indexE1)
|
|
|
|
{
|
|
|
|
assert ((indexE0<6)&&(indexE0>=0));
|
|
|
|
assert ((indexE1<6)&&(indexE1>=0));
|
|
|
|
static int edgesvert[6][6]={{-1,0,0,1,1,-1},
|
|
|
|
{0,-1,0,2,-1,2},
|
|
|
|
{0,0,-1,-1,3,3},
|
|
|
|
{1,2,-1,-1,1,2},
|
|
|
|
{1,-1,3,1,-1,3},
|
|
|
|
{-1,2,3,2,3,-1}};
|
|
|
|
return (edgesvert[indexE0][indexE1]);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int VofFFF(const int &indexF0,const int &indexF1,const int &indexF2)
|
|
|
|
{
|
|
|
|
assert ((indexF0<4)&&(indexF0>=0));
|
|
|
|
assert ((indexF1<4)&&(indexF1>=0));
|
|
|
|
assert ((indexF2<4)&&(indexF2>=0));
|
|
|
|
static int facesvert[4][4][4]={
|
|
|
|
{//0
|
|
|
|
{-1,-1,-1,-1},{-1,-1,0,1},{-1,0,-1,2},{-1,1,2,-1}
|
|
|
|
},
|
|
|
|
{//1
|
|
|
|
{-1,-1,0,1},{-1,-1,-1,-1},{0,-1,-1,3},{1,-1,3,-1}
|
|
|
|
},
|
|
|
|
{//2
|
|
|
|
{-1,0,-1,2},{0,-1,-1,3},{-1,-1,-1,-1},{2,3,-1,-1}
|
|
|
|
},
|
|
|
|
{//3
|
|
|
|
{-1,1,2,-1},{1,-1,3,-1},{2,3,-1,-1},{-1,-1,-1,-1}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
return facesvert[indexF0][indexF1][indexF2];
|
|
|
|
}
|
|
|
|
|
|
|
|
static int EofFF(const int &indexF0,const int &indexF1)
|
|
|
|
{
|
|
|
|
assert ((indexF0<4)&&(indexF0>=0));
|
|
|
|
assert ((indexF1<4)&&(indexF1>=0));
|
|
|
|
static int facesedge[4][4]={{-1, 0, 1, 3},
|
|
|
|
{ 0, -1, 2, 4},
|
|
|
|
{ 1, 2, -1, 5},
|
|
|
|
{ 3, 4, 5, -1}};
|
|
|
|
return (facesedge[indexF0][indexF1]);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int EofVV(const int &indexV0,const int &indexV1)
|
|
|
|
{
|
|
|
|
assert ((indexV0<4)&&(indexV0>=0));
|
|
|
|
assert ((indexV1<4)&&(indexV1>=0));
|
|
|
|
static int verticesedge[4][4]={{-1, 0, 1, 2},
|
|
|
|
{ 0, -1, 3, 4},
|
|
|
|
{ 1, 3, -1, 5},
|
|
|
|
{ 2, 4, 5, -1}};
|
|
|
|
|
|
|
|
return verticesedge[indexV0][indexV1];
|
|
|
|
}
|
|
|
|
|
2004-06-25 20:17:03 +02:00
|
|
|
static int FofVVV(const int &indexV0,const int &indexV1,const int &indexV2)
|
2004-04-22 15:19:12 +02:00
|
|
|
{
|
|
|
|
|
|
|
|
assert ((indexV0<4)&&(indexV0>=0));
|
|
|
|
assert ((indexV1<4)&&(indexV1>=0));
|
|
|
|
assert ((indexV2<4)&&(indexV2>=0));
|
|
|
|
|
|
|
|
static int verticesface[4][4][4]={
|
|
|
|
{//0
|
|
|
|
{-1,-1,-1,-1},{-1,-1,0,1},{-1,0,-1,2},{-1,1,2,-1}
|
|
|
|
},
|
|
|
|
{//1
|
|
|
|
{-1,-1,0,1},{-1,-1,-1,-1},{0,-1,-1,3},{1,-1,3,-1}
|
|
|
|
},
|
|
|
|
{//2
|
|
|
|
{-1,0,-1,2},{0,-1,-1,3},{-1,-1,-1,-1},{2,3,-1,-1}
|
|
|
|
},
|
|
|
|
{//3
|
|
|
|
{-1,1,2,-1},{1,-1,3,-1},{2,3,-1,-1},{-1,-1,-1,-1}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
return verticesface[indexV0][indexV1][indexV2];
|
|
|
|
}
|
|
|
|
|
|
|
|
static int FofEE(const int &indexE0,const int &indexE1)
|
|
|
|
{
|
|
|
|
assert ((indexE0<6)&&(indexE0>=0));
|
|
|
|
assert ((indexE1<6)&&(indexE1>=0));
|
|
|
|
static int edgesface[6][6]={{-1,0,1,0,1,-1},
|
|
|
|
{0,-1,2,0,-1,2},
|
|
|
|
{1,2,-1,-1,1,2},
|
|
|
|
{0,0,-1,-1,3,3},
|
|
|
|
{1,-1,1,3,-1,3},
|
|
|
|
{-1,2,2,3,3,-1}};
|
|
|
|
|
|
|
|
return edgesface[indexE0][indexE1];
|
|
|
|
}
|
2004-05-13 10:42:36 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
/** \addtogroup space */
|
|
|
|
/*@{*/
|
|
|
|
/**
|
|
|
|
Templated class for storing a generic tetrahedron in a 3D space.
|
|
|
|
Note the relation with the Face class of TetraMesh complex, both classes provide the P(i) access functions to their points and therefore they share the algorithms on it (e.g. area, normal etc...)
|
|
|
|
*/
|
2004-07-09 12:08:21 +02:00
|
|
|
template <class ScalarType>
|
|
|
|
class Tetra3:public Tetra
|
2004-05-13 10:42:36 +02:00
|
|
|
{
|
|
|
|
public:
|
2004-07-09 12:08:21 +02:00
|
|
|
typedef Point3< ScalarType > CoordType;
|
|
|
|
typedef ScalarType ScalarType;
|
2004-05-13 10:42:36 +02:00
|
|
|
|
|
|
|
/*********************************************
|
|
|
|
|
|
|
|
**/
|
|
|
|
|
|
|
|
private:
|
|
|
|
/// Vector of the 4 points that defines the tetrahedron
|
|
|
|
CoordType _v[4];
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
/// Shortcut per accedere ai punti delle facce
|
2004-07-09 12:08:21 +02:00
|
|
|
inline CoordType & P( const int j ) { return _v[j];}
|
|
|
|
inline CoordType const & cP( const int j )const { return _v[j];}
|
|
|
|
|
2004-05-13 10:42:36 +02:00
|
|
|
inline CoordType & P0( const int j ) { return _v[j];}
|
|
|
|
inline CoordType & P1( const int j ) { return _v[(j+1)%4];}
|
|
|
|
inline CoordType & P2( const int j ) { return _v[(j+2)%4];}
|
|
|
|
inline CoordType & P3( const int j ) { return _v[(j+3)%4];}
|
|
|
|
|
|
|
|
inline const CoordType & P0( const int j ) const { return _v[j];}
|
|
|
|
inline const CoordType & P1( const int j ) const { return _v[(j+1)%4];}
|
|
|
|
inline const CoordType & P2( const int j ) const { return _v[(j+2)%4];}
|
|
|
|
inline const CoordType & P3( const int j ) const { return _v[(j+3)%4];}
|
|
|
|
|
|
|
|
inline const CoordType & cP0( const int j ) const { return _v[j];}
|
|
|
|
inline const CoordType & cP1( const int j ) const { return _v[(j+1)%4];}
|
|
|
|
inline const CoordType & cP2( const int j ) const { return _v[(j+2)%4];}
|
|
|
|
inline const CoordType & cP3( const int j ) const { return _v[(j+3)%4];}
|
|
|
|
|
|
|
|
/// compute and return the barycenter of a tetrahedron
|
|
|
|
CoordType ComputeBarycenter()
|
|
|
|
{
|
|
|
|
return((_v[0] + _v[1] + _v[2]+ _v[3])/4);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// compute and return the solid angle on a vertex
|
|
|
|
double SolidAngle(int vind)
|
|
|
|
{
|
2004-05-13 14:51:00 +02:00
|
|
|
double da0=DiedralAngle(EofV(vind,0));
|
|
|
|
double da1=DiedralAngle(EofV(vind,1));
|
|
|
|
double da2=DiedralAngle(EofV(vind,2));
|
2004-05-13 10:42:36 +02:00
|
|
|
|
|
|
|
return((da0 + da1 + da2)- M_PI);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// compute and return the diadedral angle on an edge
|
|
|
|
double DiedralAngle(int edgeind)
|
|
|
|
{
|
2004-05-13 14:51:00 +02:00
|
|
|
int f1=FofE(edgeind,0);
|
|
|
|
int f2=FofE(edgeind,1);
|
2004-07-09 12:08:21 +02:00
|
|
|
CoordType p0=_v[FofV(f1,0)];
|
|
|
|
CoordType p1=_v[FofV(f1,1)];
|
|
|
|
CoordType p2=_v[FofV(f1,2)];
|
|
|
|
CoordType norm1=((p1-p0)^(p2-p0));
|
2004-05-13 14:51:00 +02:00
|
|
|
p0=_v[FofV(f2,0)];
|
|
|
|
p1=_v[FofV(f2,1)];
|
|
|
|
p2=_v[FofV(f2,2)];
|
2004-07-09 12:08:21 +02:00
|
|
|
CoordType norm2=((p1-p0)^(p2-p0));
|
2004-05-13 10:42:36 +02:00
|
|
|
norm1.Normalize();
|
|
|
|
norm2.Normalize();
|
|
|
|
return (M_PI-acos(double(norm1*norm2)));
|
|
|
|
}
|
|
|
|
|
|
|
|
/// compute and return the aspect ratio of the tetrahedron
|
2004-07-09 12:08:21 +02:00
|
|
|
ScalarType ComputeAspectRatio()
|
2004-05-13 10:42:36 +02:00
|
|
|
{
|
|
|
|
double a0=SolidAngle(0);
|
|
|
|
double a1=SolidAngle(1);
|
|
|
|
double a2=SolidAngle(2);
|
|
|
|
double a3=SolidAngle(3);
|
|
|
|
return (min(a0,min(a1,min(a2,a3))));
|
|
|
|
}
|
|
|
|
|
2004-04-22 15:19:12 +02:00
|
|
|
|
|
|
|
}; //end Class
|
|
|
|
|
2004-07-09 12:08:21 +02:00
|
|
|
// compute and return the volume of a tetrahedron
|
|
|
|
template<class TetraType>
|
|
|
|
typename TetraType::ScalarType ComputeVolume( const TetraType & t){
|
|
|
|
return (( t.cP(2)-t.cP(0))^(t.cP(1)-t.cP(0) ))*(t.cP(3)-t.cP(0))/6.0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Returns the normal to the face face of the tetrahedron t
|
2004-05-13 10:42:36 +02:00
|
|
|
template<class TetraType>
|
2004-07-09 12:08:21 +02:00
|
|
|
Point3<typename TetraType::ScalarType> Normal( const TetraType &t,const int &face)
|
2004-05-13 10:42:36 +02:00
|
|
|
{
|
2004-07-09 12:08:21 +02:00
|
|
|
return(((t.cP(Tetra::VofF(face,1))-t.cP(Tetra::VofF(face,0)))^(t.cP(Tetra::VofF(face,2))-t.cP(Tetra::VofF(face,0)))).Normalize());
|
2004-05-13 10:42:36 +02:00
|
|
|
}
|
2004-04-22 15:19:12 +02:00
|
|
|
|
|
|
|
} // end namespace
|
|
|
|
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|