vcglib/vcg/simplex/tetrahedron/component.h

485 lines
21 KiB
C
Raw Normal View History

/****************************************************************************
* VCGLib o o *
* Visual and Computer Graphics Library o o *
* _ O _ *
* Copyright(C) 2004-2016 \/)\/ *
* 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 $
Revision 1.1 2007/05/09 10:31:53 ganovelli
added
****************************************************************************/
#ifndef __VCG_TETRAHEDRON_PLUS_COMPONENT
#define __VCG_TETRAHEDRON_PLUS_COMPONENT
#include <vector>
#include <vcg/space/tetra3.h>
namespace vcg {
2018-05-03 15:05:42 +02:00
namespace tetrahedron {
/*
Some naming Rules
All the Components that can be added to a tetra should be defined in the namespace tetra:
*/
template <class T> class EmptyCore : public T {
public:
//Empty vertexref
inline typename T::VertexType * & V( const int j ) { assert(0); static typename T::VertexType *vp=0; return vp; }
inline typename T::VertexType * const & V( const int j ) const { assert(0); static typename T::VertexType *vp=0; return vp; }
inline typename T::VertexType * const cV( const int j ) const { assert(0); static typename T::VertexType *vp=0; return vp; }
inline typename T::CoordType & P( const int j ) { assert(0); static typename T::CoordType coord(0, 0, 0); return coord; }
inline const typename T::CoordType & P( const int j ) const { assert(0); static typename T::CoordType coord(0, 0, 0); return coord; }
inline const typename T::CoordType &cP( const int j ) const { assert(0); static typename T::CoordType coord(0, 0, 0); return coord; }
static bool HasVertexRef() { return false; }
static bool HasTVAdjacency() { return false; }
//Empty normals
typedef typename T::VertexType::NormalType NormalType;
NormalType &N(const int & ){ static NormalType dummynormal(0, 0, 0); assert(0); return dummynormal; }
const NormalType cN(const int & ) const { static NormalType dummynormal(0, 0, 0); assert(0); return dummynormal; }
static bool HasFaceNormal() { return false; }
static bool HasFaceNormalOcc() { return false; }
//Empty color
typedef vcg::Color4b ColorType;
ColorType &C() { static ColorType dummycolor(vcg::Color4b::White); assert(0); return dummycolor; }
ColorType cC() const { static ColorType dummycolor(vcg::Color4b::White); assert(0); return dummycolor; }
2018-05-03 15:05:42 +02:00
static bool HasColor() { return false; }
static bool IsColorEnabled() { return T::TetraType::HasColor(); }
//Empty Quality
typedef float QualityType;
typedef vcg::Point3f Quality3Type;
QualityType &Q() { static QualityType dummyquality(0); assert(0); return dummyquality; }
QualityType cQ() const { static QualityType dummyquality(0); assert(0); return dummyquality; }
Quality3Type &Q3() { static Quality3Type dummyQuality3(0,0,0); assert(0); return dummyQuality3; }
Quality3Type cQ3() const { static Quality3Type dummyQuality3(0,0,0); assert(0); return dummyQuality3; }
static bool HasQuality() { return false; }
static bool HasQuality3() { return false; }
2018-05-03 15:05:42 +02:00
bool IsQualityEnabled() const { return T::TetraType::HasQuality(); }
bool IsQuality3Enabled() const { return T::TetraType::HasQuality3(); }
//Empty flags
int &Flags() { static int dummyflags(0); assert(0); return dummyflags; }
int cFlags() const { return 0; }
static bool HasFlags() { return false; }
static bool HasFlagsOcc() { return false; }
//Empty IMark
typedef int MarkType;
2018-05-03 15:05:42 +02:00
inline void InitIMark() { }
inline int & IMark() { assert(0); static int tmp=-1; return tmp;}
inline int cIMark() const {return 0;}
2018-05-03 15:05:42 +02:00
static bool HasMark() { return false; }
static bool HasMarkOcc() { return false; }
//Empty Adjacency
typedef int VFAdjType;
typename T::TetraPointer & VTp( const int ) { static typename T::TetraPointer tp=0; assert(0); return tp; }
typename T::TetraPointer const cVTp( const int ) const { static typename T::TetraPointer const tp=0; assert(0); return tp; }
typename T::TetraPointer & TTp( const int ) { static typename T::TetraPointer tp=0; assert(0); return tp; }
typename T::TetraPointer const cTTp( const int ) const { static typename T::TetraPointer const tp=0; assert(0); return tp; }
2018-05-03 15:05:42 +02:00
char & VTi( const int j ) { static char z=0; assert(0); return z; }
char cVTi( const int j ) const { static char z=0; assert(0); return z; }
char & TTi( const int j ) { static char z=0; assert(0); return z; }
char cTTi( const int j ) const { static char z=0; assert(0); return z; }
bool IsVTInitialized(const int j) const {return static_cast<const typename T::TetraType *>(this)->cVTi(j)!=-1;}
void VTClear(int j) {
if(IsVTInitialized(j)) {
static_cast<typename T::TetraPointer>(this)->VTp(j)=0;
static_cast<typename T::TetraPointer>(this)->VTi(j)=-1;
}
}
static bool HasVTAdjacency() { return false; }
static bool HasTTAdjacency() { return false; }
static bool HasTTAdjacencyOcc() { return false; }
static bool HasVTAdjacencyOcc() { return false; }
template <class RightValuteType>
void ImportData(const RightValuteType & ) {}
static void Name(std::vector<std::string> & name) { T::Name(name); }
2018-05-03 15:05:42 +02:00
};
/*-------------------------- VERTEX ----------------------------------------*/
// template <class T> class EmptyVertexRef: public T {
// public:
// // typedef typename T::VertexType VertexType;
// // typedef typename T::CoordType CoordType;
// inline typename T::VertexType * & V( const int j ) { assert(0); static typename T::VertexType *vp=0; return vp; }
// inline typename T::VertexType * const & V( const int j ) const { assert(0); static typename T::VertexType *vp=0; return vp; }
// inline typename T::VertexType * const cV( const int j ) const { assert(0); static typename T::VertexType *vp=0; return vp; }
// inline typename T::CoordType & P( const int j ) { assert(0); static typename T::CoordType coord(0, 0, 0); return coord; }
// inline const typename T::CoordType & P( const int j ) const { assert(0); static typename T::CoordType coord(0, 0, 0); return coord; }
// inline const typename T::CoordType &cP( const int j ) const { assert(0); static typename T::CoordType coord(0, 0, 0); return coord; }
// static bool HasVertexRef() { return false; }
// };
template <class T> class VertexRef: public T {
public:
VertexRef(){
v[0]=0;
v[1]=0;
v[2]=0;
2018-05-01 17:02:47 +02:00
v[3]=0;
}
2018-05-03 15:05:42 +02:00
typedef typename T::VertexType::CoordType CoordType;
typedef typename T::VertexType::ScalarType ScalarType;
2018-05-03 15:05:42 +02:00
inline typename T::VertexType * & V( const int j ) { assert(j>=0 && j<4); return v[j]; }
inline typename T::VertexType * const & V( const int j ) const { assert(j>=0 && j<4); return v[j]; }
inline typename T::VertexType * const cV( const int j ) const { assert(j>=0 && j<4); return v[j]; }
// Shortcut per accedere ai punti delle facce
2018-05-03 15:05:42 +02:00
inline typename CoordType & P( const int j ) { assert(j>=0 && j<4); return v[j]->P(); }
inline const typename CoordType & P( const int j ) const { assert(j>=0 && j<4); return v[j]->cP(); }
inline const typename CoordType &cP( const int j ) const { assert(j>=0 && j<4); return v[j]->cP(); }
/** Return the pointer to the ((j+1)%3)-th vertex of the face.
@param j Index of the face vertex.
*/
inline typename T::VertexType * & V0( const int j ) { return V(j);}
inline typename T::VertexType * & V1( const int j ) { return V((j+1)%4);}
inline typename T::VertexType * & V2( const int j ) { return V((j+2)%4);}
2018-05-01 17:02:47 +02:00
inline typename T::VertexType * & V3( const int j ) { return V((j+3)%4);}
inline const typename T::VertexType * const & V0( const int j ) const { return V(j);}
inline const typename T::VertexType * const & V1( const int j ) const { return V((j+1)%4);}
inline const typename T::VertexType * const & V2( const int j ) const { return V((j+2)%4);}
2018-05-01 17:02:47 +02:00
inline const typename T::VertexType * const & V3( const int j ) const { return V((j+3)%4);}
inline const typename T::VertexType * const & cV0( const int j ) const { return cV(j);}
inline const typename T::VertexType * const & cV1( const int j ) const { return cV((j+1)%4);}
inline const typename T::VertexType * const & cV2( const int j ) const { return cV((j+2)%4);}
2018-05-01 17:02:47 +02:00
inline const typename T::VertexType * const & cV3( const int j ) const { return cV((j+3)%4);}
/// Shortcut to get vertex values
2018-05-03 15:05:42 +02:00
inline typename CoordType & P0( const int j ) { return V(j)->P();}
inline typename CoordType & P1( const int j ) { return V((j+1)%4)->P();}
inline typename CoordType & P2( const int j ) { return V((j+2)%4)->P();}
inline typename CoordType & P3( const int j ) { return V((j+3)%4)->P();}
inline const typename CoordType & P0( const int j ) const { return V(j)->P();}
inline const typename CoordType & P1( const int j ) const { return V((j+1)%4)->P();}
inline const typename CoordType & P2( const int j ) const { return V((j+2)%4)->P();}
inline const typename CoordType & P3( const int j ) const { return V((j+3)%4)->P();}
inline const typename CoordType & cP0( const int j ) const { return cV(j)->P();}
inline const typename CoordType & cP1( const int j ) const { return cV((j+1)%4)->P();}
inline const typename CoordType & cP2( const int j ) const { return cV((j+2)%4)->P();}
inline const typename CoordType & cP3( const int j ) const { return cV((j+3)%4)->P();}
static bool HasVertexRef() { return true; }
static bool HasTVAdjacency() { return true; }
static void Name(std::vector<std::string> & name){name.push_back(std::string("VertexRef"));T::Name(name);}
template <class RightValueType>
2018-05-03 15:05:42 +02:00
void ImportData(const RightValueType & rTetra) { T::ImportData(rTetra); }
private:
typename T::VertexType *v[4];
};
/*------------------------- FACE NORMAL -----------------------------------------*/
// template <class A, class T> class EmptyFaceNormal: public T {
// public:
// typedef ::vcg::Point3<A> NormalType;
// /// Return the vector of Flags(), senza effettuare controlli sui bit
// NormalType N(const int & ){ static int dummynormal(0); return dummynormal; }
// const NormalType cN(const int & ) const { return 0; }
// static bool HasFaceNormal() { return false; }
// static bool HasFaceNormalOcc() { return false; }
// static void Name(std::vector<std::string> & name){T::Name(name);}
// };
template <class A, class T> class FaceNormal: public T {
public:
typedef A NormalType;
inline NormalType N(const int & i){ assert((i>=0)&&(i < 4)); return _facenormals[i]; }
inline NormalType cN(const int & i) const { assert((i>=0)&&(i < 4)); return _facenormals[i]; }
static bool HasFaceNormals() { return true; }
static bool HasFaceNormalOcc() { return false; }
template <class RightValueType>
void ImportData(const RightValueType & rightT)
{
if(rightT.IsNormalEnabled()) N().Import(rightT.cN());
T::ImportData(rightT);
}
static void Name(std::vector<std::string> & name){name.push_back(std::string("FaceNormal"));T::Name(name);}
private:
NormalType _facenormals[4];
};
template <class T> class FaceNormal3f: public FaceNormal<vcg::Point3f, T>{
public:static void Name(std::vector<std::string> & name){name.push_back(std::string("FaceNormal3f"));T::Name(name);} };
template <class T> class FaceNormal3d: public FaceNormal<vcg::Point3d, T>{
public:static void Name(std::vector<std::string> & name){name.push_back(std::string("FaceNormal3d"));T::Name(name);} };
/*------------------------- FLAGS -----------------------------------------*/
// template <class T> class EmptyBitFlags: public T {
// public:
// /// Return the vector of Flags(), senza effettuare controlli sui bit
// int &Flags() { static int dummyflags(0); return dummyflags; }
// const int Flags() const { return 0; }
// static bool HasFlags() { return false; }
// static bool HasFlagsOcc() { return false; }
// static void Name(std::vector<std::string> & name){T::Name(name);}
// };
template <class T> class BitFlags: public T {
public:
typedef int FlagType;
BitFlags(){_flags=0;}
int &Flags() {return _flags; }
2018-05-03 15:05:42 +02:00
int cFlags() const {return _flags; }
template <class RightValueType>
void ImportData(const RightValueType & rightT){
if(RightValueType::HasFlags())
Flags() = rightT.cFlags();
T::ImportData(rightT);
}
static bool HasFlags() { return true; }
static void Name(std::vector<std::string> & name){name.push_back(std::string("BitFlags"));T::Name(name);}
private:
int _flags;
};
2018-05-02 20:23:48 +02:00
/*-------------------------- QUALITY ----------------------------------------*/
2018-05-02 20:23:48 +02:00
template <class A, class T> class Quality: public T {
public:
typedef A QualityType;
Quality():_quality(0) {}
QualityType &Q() { return _quality; }
QualityType cQ() const { return _quality; }
template <class RightValueType>
void ImportData(const RightValueType & rightT){
if(rightT.IsQualityEnabled())
Q() = rightT.cQ();
T::ImportData(rightT);
}
static bool HasQuality() { return true; }
static void Name(std::vector<std::string> & name){name.push_back(std::string("Quality"));T::Name(name);}
private:
QualityType _quality;
};
template <class T> class Qualityf: public Quality<float, T> {
public: static void Name(std::vector<std::string> & name){name.push_back(std::string("Qualityf"));T::Name(name);}
};
template <class T> class Qualityd: public Quality<double, T> {
public: static void Name(std::vector<std::string> & name){name.push_back(std::string("Qualityd"));T::Name(name);}
};
/*-------------------------- Quality3 ----------------------------------*/
template <class A, class T> class Quality3: public T {
public:
typedef vcg::Point3<A> Quality3Type;
Quality3Type &Q3() { return _quality; }
Quality3Type cQ3() const { return _quality; }
template <class RightValueType>
void ImportData(const RightValueType & rightT){
if(rightT.IsQuality3Enabled()) Q3() = rightT.cQ3();
T::ImportData(rightT);
}
static bool HasQuality3() { return true; }
static void Name(std::vector<std::string> & name){name.push_back(std::string("Quality3"));T::Name(name);}
private:
Quality3Type _quality;
};
template <class T> class Quality3f: public Quality3<float, T> {
public: static void Name(std::vector<std::string> & name){name.push_back(std::string("Quality3f"));T::Name(name);}
};
template <class T> class Quality3d: public Quality3<double, T> {
public: static void Name(std::vector<std::string> & name){name.push_back(std::string("Quality3d"));T::Name(name);}
};
/*-------------------------- COLOR ----------------------------------------*/
2018-05-02 20:23:48 +02:00
template <class A, class T> class Color: public T {
public:
typedef A ColorType;
Color():_color(vcg::Color4b::White) {}
ColorType &C() { return _color; }
ColorType cC() const { return _color; }
template <class RightValueType>
void ImportData(const RightValueType & rightT){
if(rightT.IsColorEnabled()) C() = rightT.cC();
T::ImportData(rightT);
}
2018-05-02 20:23:48 +02:00
static bool HasColor() { return true; }
static void Name(std::vector<std::string> & name){name.push_back(std::string("Color"));T::Name(name);}
private:
ColorType _color;
};
/*-------------------------- INCREMENTAL MARK ----------------------------------------*/
// template <class T> class EmptyMark: public T {
// public:
// typedef int MarkType;
// static bool HasMark() { return false; }
// static bool HasMarkOcc() { return false; }
// inline void InitIMark() { }
// inline int & IMark() { assert(0); static int tmp=-1; return tmp;}
// inline const int IMark() const {return 0;}
// static void Name(std::vector<std::string> & name){T::Name(name);}
// };
template <class T> class Mark: public T {
public:
static bool HasMark() { return true; }
static bool HasMarkOcc() { return false; }
inline void InitIMark() { _imark = 0; }
inline int & IMark() { return _imark;}
2018-05-03 15:05:42 +02:00
inline int cIMark() const {return _imark;}
template <class RightValueType>
void ImportData(const RightValueType & rightT){
if(rightT.IsMarkEnabled()) IMark() = rightT.cIMark();
T::ImportData(rightT);
}
static void Name(std::vector<std::string> & name){name.push_back(std::string("Mark"));T::Name(name);}
private:
int _imark;
};
/*----------------------------- VTADJ ------------------------------*/
// template <class T> class EmptyAdj: public T {
// public:
// typedef int VFAdjType;
// typename T::TetraPointer & VTp( const int ) { static typename T::TetraPointer tp=0; return tp; }
// typename T::TetraPointer const cVTp( const int ) const { static typename T::TetraPointer const tp=0; return tp; }
// typename T::TetraPointer & TTp( const int ) { static typename T::TetraPointer tp=0; return tp; }
// typename T::TetraPointer const cTTp( const int ) const { static typename T::TetraPointer const tp=0; return tp; }
// char & VTi( const int j ) { static char z=0; return z; }
// char & TTi( const int j ) { static char z=0; return z; }
// static bool HasVTAdjacency() { return false; }
// static bool HasTTAdjacency() { return false; }
// static bool HasTTAdjacencyOcc() { return false; }
// static bool HasVTAdjacencyOcc() { return false; }
// static void Name( std::vector< std::string > & name ){ T::Name(name); }
// };
template <class T> class VTAdj: public T {
public:
2018-05-03 15:05:42 +02:00
VTAdj() {
_vtp[0]=0;
_vtp[1]=0;
_vtp[2]=0;
_vtp[3]=0;
_vti[0]=-1;
_vti[1]=-1;
_vti[2]=-1;
_vti[3]=-1;
}
2018-05-01 17:02:47 +02:00
typename T::TetraPointer & VTp( const int j ) { assert( j >= 0 && j < 4 ); return _vtp[j]; }
typename T::TetraPointer const VTp( const int j ) const { assert( j >= 0 && j < 4 ); return _vtp[j]; }
typename T::TetraPointer const cVTp( const int j ) const { assert( j >= 0 && j < 4 ); return _vtp[j]; }
2018-05-01 17:02:47 +02:00
char & VTi( const int j ) { return _vti[j]; }
const char & cVTi( const int j ) const { return _vti[j]; }
2018-05-01 17:02:47 +02:00
static bool HasVTAdjacency() { return true; }
static bool HasVTAdjacencyOcc() { return false; }
2018-05-01 17:02:47 +02:00
static void Name( std::vector< std::string > & name ) { name.push_back( std::string("VTAdj") ); T::Name(name); }
2018-05-03 15:05:42 +02:00
template <class RightValueType>
void ImportData(const RightValueType & rightT){T::ImportData(rightT);}
private:
typename T::TetraPointer _vtp[4];
char _vti[4];
};
/*----------------------------- TTADJ ------------------------------*/
template <class T> class TTAdj: public T {
public:
TTAdj(){
_ttp[0]=0;
_ttp[1]=0;
_ttp[2]=0;
_ttp[3]=0;
}
typename T::TetraPointer &TTp(const int j) { assert(j>=0 && j<4); return _ttp[j]; }
typename T::TetraPointer const TTp(const int j) const { assert(j>=0 && j<4); return _ttp[j]; }
typename T::TetraPointer const cTTp(const int j) const { assert(j>=0 && j<4); return _ttp[j]; }
char &TTi(const int j) { return _tti[j]; }
const char &cTTi(const int j) const { return _tti[j]; }
typename T::TetraPointer &TTp1( const int j ) { return TTp((j+1)%4);}
typename T::TetraPointer &TTp2( const int j ) { return TTp((j+2)%4);}
2018-05-01 17:02:47 +02:00
typename T::TetraPointer &TTp3( const int j ) { return TTp((j+3)%4);}
typename T::TetraPointer const TTp1( const int j ) const { return TTp((j+1)%4);}
typename T::TetraPointer const TTp2( const int j ) const { return TTp((j+2)%4);}
2018-05-01 17:02:47 +02:00
typename T::TetraPointer const TTp3( const int j ) const { return TTp((j+3)%4);}
bool IsBorderF(const int & i) const { assert( (i>=0) && (i < 4)); { return TTp(i) == this;}}
static bool HasTTAdjacency() { return true; }
static bool HasTTAdjacencyOcc() { return false; }
static void Name(std::vector<std::string> & name){name.push_back(std::string("TTAdj"));T::Name(name);}
2018-05-03 15:05:42 +02:00
template <class RightValueType>
void ImportData(const RightValueType & rightT){T::ImportData(rightT);}
private:
typename T::TetraPointer _ttp[4] ;
char _tti[4] ;
};
} // end namespace vert
}// end namespace vcg
#endif