add vcglib

This commit is contained in:
yuanlin zhong committed 2025-11-03 17:46:44 +08:00
1 parent 6f6c0c8eb7
commit af8100f851
1537 files changed
+634197

No files matched your search

+266
View File
@@ -0,0 +1,266 @@
/****************************************************************************
* 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_TETRA_PLUS
#define __VCG_TETRA_PLUS
#include <vector>
#include <string>
#include <vcg/complex/all_types.h>
#include <vcg/container/derivation_chain.h>
#include "component.h"
namespace vcg {
/*------------------------------------------------------------------*/
// /* The base class form which we start to add our components.
// it has the empty definition for all the standard members (coords, color flags)
// Note:
// in order to avoid both virtual classes and ambiguous definitions all
// the subsequent overrides must be done in a sequence of derivation.
// In other words we cannot derive and add in a single derivation step
// (with multiple ancestor), both the real (non-empty) normal and color but
// we have to build the type a step a time (deriving from a single ancestor at a time).
template <class UserTypes>
class TetraTypeHolder: public UserTypes {
public:
template <class RightT>
void ImportData(const RightT & ){}
static void Name(std::vector<std::string> & /* name */){}
// prot
inline int VN() const { return 4;}
};
/* The base class form which we start to add our components.
it has the empty definition for all the standard members (coords, color flags)
Note:
in order to avoid both virtual classes and ambiguous definitions all
the subsequent overrides must be done in a sequence of derivation.
In other words we cannot derive and add in a single derivation step
(with multiple ancestor), both the real (non-empty) normal and color but
we have to build the type a step a time (deriving from a single ancestor at a time).
*/
template <class UserTypes>
class TetraSimpBase: public
tetrahedron::EmptyCore< TetraTypeHolder <UserTypes> > {
};
template <class UserTypes,
template <typename> class A, template <typename> class B,
template <typename> class C, template <typename> class D,
template <typename> class E, template <typename> class F,
template <typename> class G, template <typename> class H,
template <typename> class I, template <typename> class J,
template <typename> class K, template <typename> class L>
class TetraArityMax: public Arity12<TetraSimpBase<UserTypes>, A, B, C, D, E, F, G, H, I, J, K, L> {
// ----- Flags stuff -----
public:
enum {
DELETED = 0x00000001, // Tet is deleted from the mesh
NOTREAD = 0x00000002, // Tet of the mesh is not readable
NOTWRITE = 0x00000004, // Tet of the mesh is not writable
VISITED = 0x00000010, // Tet has been visited. Usualy this is a per-algorithm used bit.
SELECTED = 0x00000020, // Tet is selected. Algorithms should try to work only on selected face (if explicitly requested)
// Border _flags, it is assumed that BORDERi = BORDER0<<i
BORDER0 = 0x00000040,
BORDER1 = 0x00000080,
BORDER2 = 0x00000100,
BORDER3 = 0x00000200,
BORDER0123 = BORDER0 | BORDER1 | BORDER2 | BORDER3,
// Crease _flags, it is assumed that FEATUREi = FEATURE0<<i
// First user bit
USER0 = 0x00004000
};
/// checks if the Tet is deleted
bool IsD() const {return (this->cFlags() & DELETED) != 0;}
/// checks if the Tet is readable
bool IsR() const {return (this->cFlags() & NOTREAD) == 0;}
/// checks if the Tet is modifiable
bool IsW() const {return (this->cFlags() & NOTWRITE)== 0;}
/// This funcion checks whether the Tet is both readable and modifiable
bool IsRW() const {return (this->cFlags() & (NOTREAD | NOTWRITE)) == 0;}
/// checks if the Tet is Modified
bool IsS() const {return (this->cFlags() & SELECTED) != 0;}
/// checks if the Tet is Modified
bool IsV() const {return (this->cFlags() & VISITED) != 0;}
/** Set the flag value
@param flagp Valore da inserire nel flag
*/
void SetFlags(int flagp) {this->Flags()=flagp;}
/** Set the flag value
@param flagp Valore da inserire nel flag
*/
void ClearFlags() {this->Flags()=0;}
/// deletes the Tet from the mesh
void SetD() {this->Flags() |=DELETED;}
/// un-delete a Tet
void ClearD() {this->Flags() &=(~DELETED);}
/// marks the Tet as readable
void SetR() {this->Flags() &=(~NOTREAD);}
/// marks the Tet as not readable
void ClearR() {this->Flags() |=NOTREAD;}
/// marks the Tet as writable
void SetW() {this->Flags() &=(~NOTWRITE);}
/// marks the Tet as notwritable
void ClearW() {this->Flags() |=NOTWRITE;}
/// select the Tet
void SetS() {this->Flags() |=SELECTED;}
/// Un-select a Tet
void ClearS() {this->Flags() &= ~SELECTED;}
/// select the Tet
void SetV() {this->Flags() |=VISITED;}
/// Un-select a Tet
void ClearV() {this->Flags() &= ~VISITED;}
/// This function checks if the face is border
bool IsB(int i) const {return (this->cFlags() & (BORDER0<<i)) != 0;}
bool IsAnyB() const {return (this->cFlags() & (BORDER0123)) != 0;}
/// This function select the face
void SetB(int i) {this->Flags() |=(BORDER0<<i);}
/// This funcion execute the inverse operation of SetS()
void ClearB(int i) {this->Flags() &= (~(BORDER0<<i));}
/// Return the first bit that is not still used
static int &FirstUnusedBitFlag()
{
static int b =USER0;
return b;
}
/// Allocate a bit among the flags that can be used by user. It updates the FirstUnusedBitFlag.
static inline int NewBitFlag()
{
int bitForTheUser = FirstUnusedBitFlag();
FirstUnusedBitFlag()=FirstUnusedBitFlag()<<1;
return bitForTheUser;
}
/// De-allocate a pre allocated bit. It updates the FirstUnusedBitFlag.
// Note you must deallocate bit in the inverse order of the allocation (as in a stack)
static inline bool DeleteBitFlag(int bitval)
{
if(FirstUnusedBitFlag()>>1==bitval) {
FirstUnusedBitFlag() = FirstUnusedBitFlag()>>1;
return true;
}
assert(0);
return false;
}
/// This function checks if the given user bit is true
bool IsUserBit(int userBit){return (this->Flags() & userBit) != 0;}
/// This function set the given user bit
void SetUserBit(int userBit){this->Flags() |=userBit;}
/// This function clear the given user bit
void ClearUserBit(int userBit){this->Flags() &= (~userBit);}
template<class BoxType>
void GetBBox( BoxType & bb ) const
{
bb.Set(this->cP(0));
bb.Add(this->cP(1));
bb.Add(this->cP(2));
bb.Add(this->cP(3));
}
};
// template < typename T=int>
// class TetraDefaultDeriver : public T {};
/*
These are the three main classes that are used by the library user to define its own Facees.
The user MUST specify the names of all the type involved in a generic complex.
so for example when defining a Face of a trimesh you must know the name of the type of the edge and of the face.
Typical usage example:
A Face with coords, flags and normal for use in a standard trimesh:
class MyFaceNf : public FaceSimp2< VertProto, EdgeProto, MyFaceNf, face::Flag, face::Normal3f > {};
A Face with coords, and normal for use in a tetrahedral mesh AND in a standard trimesh:
class TetraFace : public FaceSimp3< VertProto, EdgeProto, TetraFace, TetraProto, face::Coord3d, face::Normal3f > {};
A summary of the components that can be added to a face (see components.h for details):
VertexRef
Mark //Incremental mark (int)
VTAdj //Topology vertex face adjacency
(pointers to next face in the ring of the vertex
TTAdj //topology: face face adj
pointers to adjacent faces
*/
template <class UserTypes,
template <typename> class A = DefaultDeriver, template <typename> class B = DefaultDeriver,
template <typename> class C = DefaultDeriver, template <typename> class D = DefaultDeriver,
template <typename> class E = DefaultDeriver, template <typename> class F = DefaultDeriver,
template <typename> class G = DefaultDeriver, template <typename> class H = DefaultDeriver,
template <typename> class I = DefaultDeriver, template <typename> class J = DefaultDeriver,
template <typename> class K = DefaultDeriver, template <typename> class L = DefaultDeriver>
class TetraSimp : public TetraArityMax<UserTypes, A, B, C, D, E, F, G, H, I, J, K, L> {
public: typedef AllTypes::ATetraType IAm; typedef UserTypes TypesPool;};
}// end namespace
#endif
+515
View File
@@ -0,0 +1,515 @@
/****************************************************************************
* 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/color4.h>
#include <vcg/space/tetra3.h>
namespace vcg {
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 ) { assert(0); static typename T::VertexType *vp=0; return vp; }
inline const typename T::VertexType * V( const int ) const { assert(0); static typename T::VertexType *vp=0; return vp; }
inline const typename T::VertexType * cV( const int ) const { assert(0); static typename T::VertexType *vp=0; return vp; }
inline typename T::CoordType & P( const int ) { assert(0); static typename T::CoordType coord(0, 0, 0); return coord; }
inline const typename T::CoordType & P( const int ) const { assert(0); static typename T::CoordType coord(0, 0, 0); return coord; }
inline const typename T::CoordType &cP( const int ) 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; }
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; }
inline bool IsQualityEnabled() const { return T::TetraType::HasQuality(); }
inline 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;
inline void InitIMark() { }
inline int & IMark() { assert(0); static int tmp=-1; return tmp;}
inline int cIMark() const {return 0;}
inline bool IsMarkEnabled() const { return T::TetraType::HasMark(); }
static bool HasMark() { return false; }
static bool HasMarkOcc() { return false; }
//Empty Adjacency
typedef int VTAdjType;
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; }
char & VTi( const int ) { static char z=0; assert(0); return z; }
char VTi( const int ) const { static char z=0; assert(0); return z; }
char cVTi( const int ) const { static char z=0; assert(0); return z; }
char & TTi( const int ) { static char z=0; assert(0); return z; }
char cTTi( const int ) 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); }
};
/*-------------------------- 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;
v[3]=0;
/******* vertex and faces indices scheme*********
*
* /2\`
* / \ `
* / \ `
* / \ _ 3`
* / _ \ '
* / _ \ '
* /0___________1\'
*
*/
findices[0][0] = 0; findices[0][1] = 1; findices[0][2] = 2;
findices[1][0] = 0; findices[1][1] = 3; findices[1][2] = 1;
findices[2][0] = 0; findices[2][1] = 2; findices[2][2] = 3;
findices[3][0] = 1; findices[3][1] = 3; findices[3][2] = 2;
}
typedef typename T::VertexType::CoordType CoordType;
typedef typename T::VertexType::ScalarType ScalarType;
inline typename T::VertexType * & V( const int j ) { assert(j>=0 && j<4); return v[j]; }
inline const typename T::VertexType * V( const int j ) const { assert(j>=0 && j<4); return v[j]; }
inline const typename T::VertexType * cV( const int j ) const { assert(j>=0 && j<4); return v[j]; }
inline size_t cFtoVi (const int f, const int j) const { assert(f >= 0 && f < 4); assert(j >= 0 && j < 3); return findices[f][j]; }
// Shortcut for tetra points
inline CoordType & P( const int j ) { assert(j>=0 && j<4); return v[j]->P(); }
inline const CoordType &cP( const int j ) const { assert(j>=0 && j<4); return v[j]->P(); }
/** Return the pointer to the ((j+1)%4)-th vertex of the tetra.
@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);}
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);}
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);}
inline const typename T::VertexType * const & cV3( const int j ) const { return cV((j+3)%4);}
/// Shortcut to get vertex values
inline CoordType &P0 (const int j) { return V(j)->P(); }
inline CoordType &P2 (const int j) { return V((j + 2) % 4)->P(); }
inline CoordType &P3 (const int j) { return V((j + 3) % 4)->P(); }
inline CoordType &P1 (const int j) { return V((j + 1) % 4)->P(); }
inline const CoordType &P0 (const int j) const { return V(j)->P(); }
inline const CoordType &P1 (const int j) const { return V((j + 1) % 4)->P(); }
inline const CoordType &P2 (const int j) const { return V((j + 2) % 4)->P(); }
inline const CoordType &P3 (const int j) const { return V((j + 3) % 4)->P(); }
inline const CoordType &cP0(const int j) const { return cV(j)->P(); }
inline const CoordType &cP1(const int j) const { return cV((j + 1) % 4)->P(); }
inline const CoordType &cP2(const int j) const { return cV((j + 2) % 4)->P(); }
inline const 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>
void ImportData(const RightValueType & rTetra) { T::ImportData(rTetra); }
private:
typename T::VertexType *v[4];
size_t findices[4][3];
};
/*------------------------- 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;}
inline int &Flags() {return _flags; }
inline 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;
};
/*-------------------------- QUALITY ----------------------------------------*/
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 ----------------------------------------*/
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);
}
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;
};
template <class T> class Color4b : public Color<vcg::Color4b, T> {
public: static void Name(std::vector<std::string> & name){name.push_back(std::string("Color4b"));T::Name(name); }
};
/*-------------------------- 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;}
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:
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;
}
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]; }
char & VTi( const int j ) { return _vti[j]; }
char VTi( const int j ) const { return _vti[j]; }
char cVTi( const int j ) const { return _vti[j]; }
static bool HasVTAdjacency() { return true; }
static bool HasVTAdjacencyOcc() { return false; }
static void Name( std::vector< std::string > & name ) { name.push_back( std::string("VTAdj") ); T::Name(name); }
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);}
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);}
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);}
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
+520
View File
@@ -0,0 +1,520 @@
/****************************************************************************
* 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
****************************************************************************/
#ifndef __VCG_TETRA_POS
#define __VCG_TETRA_POS
#include <vector>
#include <algorithm>
#include "component.h"
namespace vcg {
namespace tetra {
/** \addtogroup tetra */
/*@{*/
/** Class VTIterator.
This is a vertex - tetrahedron iterator
@param MTTYPE (Template Parameter) Specifies the type of the tetrahedron.
*/
template < class MTTYPE>
class VTIterator
{
public:
/// The tetrahedron type
typedef MTTYPE TetraType;
typedef typename TetraType::VertexType VertexType;
private:
/// Pointer to a tetrahedron
TetraType *_vt;
/// Index of one vertex
int _vi;
/// Default Constructor
public:
VTIterator() : _vt(0), _vi(-1){}
/// Constructor
VTIterator(TetraType * const tp, int const zp)
{
_vt=tp->V(zp)->VTp();
_vi=tp->V(zp)->VTi();
}
VTIterator(VertexType * const vp)
{
_vt = vp->VTp();
_vi = vp->VTi();
}
~VTIterator(){};
/// Return the tetrahedron stored in the half edge
inline TetraType* & Vt()
{
return _vt;
}
/// Return the index of vertex as seen from the tetrahedron
inline int & Vi()
{
return _vi;
}
/// Return the index of vertex as seen from the tetrahedron
inline const int & Vi() const
{
return _vi;
}
inline bool End(){return (Vt()==nullptr);}
/// move on the next tetrahedron that share the vertex
void operator++()
{
int vi=Vi();
TetraType * tw = Vt();
Vt() = tw->VTp(vi);
Vi() = tw->VTi(vi);
assert((Vt()==nullptr)||((tw->V(vi))==(Vt()->V(Vi()))));
}
};
template <class TetraType>
void VTStarVT( typename TetraType::VertexType* vp,
std::vector<TetraType *> &tetraVec,
std::vector<int> &indexes)
{
tetraVec.clear();
indexes.clear();
tetraVec.reserve(16);
indexes.reserve(16);
tetra::VTIterator<TetraType> vti(vp);
while(!vti.End())
{
tetraVec.push_back(vti.Vt());
indexes.push_back(vti.Vi());
++vti;
}
}
template <class TetraType>
void VVStarVT( typename TetraType::VertexPointer vp, std::vector<typename TetraType::VertexPointer> & starVec)
{
typedef typename TetraType::VertexPointer VertexPointer;
starVec.clear();
starVec.reserve(16);
VTIterator<TetraType> vti(vp);
while (!vti.End())
{
starVec.push_back(vti.Vt()->V1(vti.Vi()));
starVec.push_back(vti.Vt()->V2(vti.Vi()));
starVec.push_back(vti.Vt()->V3(vti.Vi()));
++vti;
}
std::sort(starVec.begin(), starVec.end());
typename std::vector<VertexPointer>::iterator new_end = std::unique(starVec.begin(),starVec.end());
starVec.resize(new_end - starVec.begin());
}
/** Templated over the class tetrahedron, it stores a \em position over a tetrahedron in a mesh.
It contain a pointer to the current tetrahedron,
the index of one face,edge and a edge's incident vertex.
*/
template < class MTTYPE>
class Pos
{
public:
/// The tetrahedron type
typedef MTTYPE TetraType;
/// The vertex type
typedef typename TetraType::VertexType VertexType;
/// The coordinate type
typedef typename TetraType::VertexType::CoordType CoordType;
///The HEdgePos type
typedef Pos<TetraType> BasePosType;
private:
/// Pointer to the tetrahedron of the half-edge
TetraType *_t;
/// Index of the face
char _f;
/// Index of the edge
char _e;
/// Pointer to the vertex
char _v;
public:
/// Default constructor
Pos(){SetNull();};
/// Constructor which associates the half-edge elementet with a face, its edge and its vertex
Pos(TetraType * const tp, char const fap,char const ep,
char const vp){_t=tp;_f=fap;_e=ep;_v=vp;}
~Pos(){};
/// Return the tetrahedron stored in the half edge
inline TetraType* & T()
{
return _t;
}
/// Return the tetrahedron stored in the half edge
inline TetraType* const & T() const
{
return _t;
}
/// Return the index of face as seen from the tetrahedron
inline char & F()
{
return _f;
}
/// Return the index of face as seen from the tetrahedron
inline const char & F() const
{
return _f;
}
/// Return the index of face as seen from the tetrahedron
inline char & E()
{
return _e;
}
/// Return the index of edge as seen from the tetrahedron
inline const char & E() const
{
return _e;
}
/// Return the index of vertex as seen from the tetrahedron
inline char & V()
{
return _v;
}
/// Return the index of vertex as seen from the tetrahedron
inline const char & V() const
{
return _v;
}
/// Operator to compare two half-edge
inline bool operator == ( BasePosType const & p ) const {
return (T()==p.T() && F()==p.F() && E()==p.E() && V()==p.V());
}
/// Operator to compare two half-edge
inline bool operator != ( BasePosType const & p ) const {
return (!((*this)==p));
}
/// Set to null the half-edge
void SetNull(){
T()=0;
F()=-1;
E()=-1;
V()=-1;
}
/// Check if the half-edge is null
bool IsNull() const {
return ((T()==0) || (F()<0) || (E()<0) || (V()<0));
}
/// Changes edge maintaining the same face and the same vertex
void FlipE()
{
//take the absolute index of the tree edges of the faces
char e0=vcg::Tetra::EofF(_f ,0);
char e1=vcg::Tetra::EofF(_f ,1);
char e2=vcg::Tetra::EofF(_f ,2);
//eliminate the same as himself
if (e0==E())
{
e0=e1;
e1=e2;
}
else
if (e1==E())
{
e1=e2;
}
//now choose the one that preserve the same vertex
if ((vcg::Tetra::VofE(e1,0)==V())||(vcg::Tetra::VofE(e1,1)==V()))
E()=e1;
else
E()=e0;
}
/// Changes vertex maintaining the same face and the same edge
void FlipV()
{
// in the same edge choose the one that change
char v0=vcg::Tetra::VofE(E(),0);
char v1=vcg::Tetra::VofE(E(),1);
if (v0!=V())
V()=v0;
else
V()=v1;
}
/// Changes face maintaining the same vertex and the same edge
void FlipF()
{
char f0=vcg::Tetra::FofE(E(),0);
char f1=vcg::Tetra::FofE(E(),1);
if (f0!=F())
F()=f0;
else
F()=f1;
}
/// Changes tetrahedron maintaining the same face edge and vertex'... to finish
void FlipT()
{
//save the two vertices of the old edge
VertexType *v0=T()->V(vcg::Tetra::VofE(E(),0));
VertexType *v1=T()->V(vcg::Tetra::VofE(E(),1));
//get the current vertex
VertexType *vcurr=T()->V(V());
//get new tetrahedron according to tetra to tetra topology
TetraType *nt=T()->TTp(F());
char nfa=T()->TTi(F());
if (nfa!=-1)
{
//find the right edge
char ne0=vcg::Tetra::EofF(nfa,0);
char ne1=vcg::Tetra::EofF(nfa,1);
char ne2=vcg::Tetra::EofF(nfa,2);
//the vertices of new edges
VertexType *vn0=nt->V(vcg::Tetra::VofE(ne0,0));
VertexType *vn1=nt->V(vcg::Tetra::VofE(ne0,1));
//verify that the two vertices of tetrahedron are identical
if (((vn0==v0)&&(vn1==v1))||((vn1==v0)&&(vn0==v1)))
E()=ne0;
else
{
vn0=nt->V(vcg::Tetra::VofE(ne1,0));
vn1=nt->V(vcg::Tetra::VofE(ne1,1));
if (((vn0==v0)&&(vn1==v1))||((vn1==v0)&&(vn0==v1)))
E()=ne1;
else
{
#ifdef _DEBUG
vn0=nt->V(vcg::Tetra::VofE(ne2,0));
vn1=nt->V(vcg::Tetra::VofE(ne2,1));
assert(((vn0==v0)&&(vn1==v1))||((vn1==v0)&&(vn0==v1)));
#endif
E()=ne2;
}
}
//find the right vertex
vn0=nt->V(vcg::Tetra::VofE(E(),0));
#ifdef _DEBUG
vn1=nt->V(vcg::Tetra::VofE(E(),1));
assert((vn0==vcurr)||(vn1==vcurr));
#endif
if (vn0==vcurr)
V()=vcg::Tetra::VofE(E(),0);
else
V()=vcg::Tetra::VofE(E(),1);
T()=nt;
assert(T()->V(V())==vcurr);
F()=nfa;
}
}
///returns the next half edge on the same edge
void NextT( )
{
#ifdef _DEBUG
VertexType *vold=T()->V(V());
#endif
FlipT();
FlipF();
#ifdef _DEBUG
VertexType *vnew=T()->V(V());
assert(vold==vnew);
#endif
}
void Assert()
#ifdef _DEBUG
{
auto ht=*this;
ht.FlipT();
ht.FlipT();
assert(ht==*this);
ht=*this;
ht.FlipF();
ht.FlipF();
assert(ht==*this);
ht=*this;
ht.FlipE();
ht.FlipE();
assert(ht==*this);
ht=*this;
ht.FlipV();
ht.FlipV();
assert(ht==*this);
}
#else
{}
#endif
};
///this pos structure jump on next tetrahedron if find an external face
template < class MTTYPE>
class PosJump:public Pos<MTTYPE>
{
private:
MTTYPE *_t_initial;
short int _back;
public :
typedef MTTYPE TetraType;
PosJump(const TetraType* tp,const int fap,const int ep,
int vp){this->T()=tp;this->F()=fap;this->E()=ep;this->V()=vp;_t_initial=tp;_back=0;}
void NextT()
{
#ifdef _DEBUG
int cont=0;
#endif
MTTYPE *tpred=this->T();
Pos<MTTYPE>::NextT();
//external face
if (tpred==this->T())
{
while (this->T()!=_t_initial)
{
Pos<MTTYPE>::NextT();
#ifdef _DEBUG
cont++;
assert (cont<500);
#endif
}
_back++;
if (_back==1)
{
Pos<MTTYPE>::NextT();
}
}
}
};
///this pos structure jump on next tetrahedron in rotational sense if find an external face
template < class MTTYPE>
class PosLoop:public Pos<MTTYPE>
{
private:
MTTYPE *_t_initial;
bool _jump;
bool _loop;
public :
typedef MTTYPE TetraType;
PosLoop(TetraType* tp,const int fap,const int ep,
int vp){this->T()=tp;this->F()=fap;this->E()=ep;this->V()=vp;_t_initial=tp;_jump=false;_loop=false;}
bool LoopEnd()
{
return (_loop);
}
bool Jump()
{
return(_jump);
}
void Reset()
{
_loop=false;
_jump=false;
}
void NextT()
{
#ifdef _DEBUG
TetraType *t_old=this->T();
#endif
TetraType *tpred=this->T();
Pos<TetraType>::NextT();
_loop=false;
_jump=false;
//external face
if (tpred==this->T())
{
tpred=this->T();
//jump next one
Pos<TetraType>::NextT();
//find the next external face
while (tpred!=this->T())
{
tpred=this->T();
Pos<TetraType>::NextT();
}
////reset right rotation sense
// Pos<TetraType>::NextT();
_jump=true;
}
if (this->T()==_t_initial)
_loop=true;
#ifdef _DEBUG
if (_loop==false)
assert(t_old!=this->T());
#endif
}
};
//@}
}//end namespace tetra
}//end namespace vcg
#endif
@@ -0,0 +1,28 @@
/****************************************************************************
* 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. *
* *
****************************************************************************/
#ifndef __VCGLIB_TETRAHEDRON
#define __VCGLIB_TETRAHEDRON
#define TETRA_TYPE Tetrahedron
// #include <vcg/simplex/tetrahedron/base.h>
#endif
+50
View File
@@ -0,0 +1,50 @@
/****************************************************************************
* 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. *
* *
****************************************************************************/
#ifndef _VCG_TETRA_TOPOLOGY
#define _VCG_TETRA_TOPOLOGY
#include <cassert>
namespace vcg {
namespace tetrahedron {
/** \addtogroup tetrahedron */
/*@{*/
/** Return a boolean that indicate if the j-th face of the tetra is a border.
@param j Index of the face
@return true if j is an face of border, false otherwise
*/
template <class TetraType>
inline bool IsTTBorder(TetraType const & t, const int j )
{
if(TetraType::HasTTAdjacency())
return t.cTTp(j)==&t;
assert(0);
return true;
}
}
}
#endif