First working version!
This commit is contained in:
parent
760a82a416
commit
6ea584884a
|
@ -0,0 +1,284 @@
|
||||||
|
/****************************************************************************
|
||||||
|
* 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 $
|
||||||
|
|
||||||
|
****************************************************************************/
|
||||||
|
#ifndef __VCG_VERTEX_PLUS
|
||||||
|
#define __VCG_VERTEX_PLUS
|
||||||
|
|
||||||
|
#include <vcg/space/point3.h>
|
||||||
|
#include <vcg/space/tcoord2.h>
|
||||||
|
#include <vcg/simplex/vertexplus/component.h>
|
||||||
|
|
||||||
|
namespace vcg {
|
||||||
|
|
||||||
|
class DumET {};
|
||||||
|
class DumFT {};
|
||||||
|
class DumTT {};
|
||||||
|
|
||||||
|
/*------------------------------------------------------------------*/
|
||||||
|
/*
|
||||||
|
The base class of all the recusive definition chain. It is just a container of the typenames of the various simplexes.
|
||||||
|
These typenames must be known form all the derived classes.
|
||||||
|
*/
|
||||||
|
|
||||||
|
template <class BVT, class BET, class BFT, class BTT>
|
||||||
|
class VertexTypeHolder{
|
||||||
|
public:
|
||||||
|
typedef BVT VertType;
|
||||||
|
typedef BET EdgeType;
|
||||||
|
typedef BFT FaceType;
|
||||||
|
typedef BTT TetraType;
|
||||||
|
typedef BVT *VertPointer;
|
||||||
|
typedef BET *EdgePointer;
|
||||||
|
typedef BFT *FacePointer;
|
||||||
|
typedef BTT *TetraPointer;
|
||||||
|
};
|
||||||
|
|
||||||
|
/* 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 BVT, class BET=DumET, class BFT=DumFT, class BTT=DumTT>
|
||||||
|
class VertexBase: public vert::EmptyTexture<
|
||||||
|
vert::EmptyVFAdj<
|
||||||
|
vert::EmptyColor<
|
||||||
|
vert::EmptyQuality<
|
||||||
|
vert::EmptyNormal<
|
||||||
|
vert::EmptyFlag<
|
||||||
|
vert::EmptyCoord<
|
||||||
|
VertexTypeHolder <BVT, BET, BFT, BTT> > > > > > > >{
|
||||||
|
};
|
||||||
|
|
||||||
|
// Metaprogramming Core
|
||||||
|
|
||||||
|
template <class BVT, class BET, class BFT,class BTT,
|
||||||
|
template <typename> class A>
|
||||||
|
class VertexArity1: public A<VertexBase<BVT,BET,BFT,BTT> > {
|
||||||
|
};
|
||||||
|
|
||||||
|
template <class BVT, class BET, typename BFT, class BTT,
|
||||||
|
template <typename> class A, template <typename> class B>
|
||||||
|
class VertexArity2: public B<VertexArity1<BVT,BET,BFT,BTT, A> > {};
|
||||||
|
|
||||||
|
template <class BVT, class BET, typename BFT,class BTT,
|
||||||
|
template <typename> class A, template <typename> class B,
|
||||||
|
template <typename> class C >
|
||||||
|
class VertexArity3: public C<VertexArity2<BVT,BET,BFT,BTT, A, B> > {};
|
||||||
|
|
||||||
|
template <class BVT, class BET, typename BFT,class BTT,
|
||||||
|
template <typename> class A, template <typename> class B,
|
||||||
|
template <typename> class C, template <typename> class D>
|
||||||
|
class VertexArity4: public D<VertexArity3<BVT,BET,BFT,BTT, A, B, C> > {};
|
||||||
|
|
||||||
|
template <class BVT, class BET, typename BFT,class BTT,
|
||||||
|
template <typename> class A, template <typename> class B,
|
||||||
|
template <typename> class C, template <typename> class D,
|
||||||
|
template <typename> class E >
|
||||||
|
class VertexArity5: public E<VertexArity4<BVT,BET,BFT,BTT, A, B, C, D> > {};
|
||||||
|
template <class BVT, class BET, typename BFT,class BTT,
|
||||||
|
template <typename> class A, template <typename> class B,
|
||||||
|
template <typename> class C, template <typename> class D,
|
||||||
|
template <typename> class E, template <typename> class F >
|
||||||
|
class VertexArity6: public F<VertexArity5<BVT,BET,BFT,BTT, A, B, C, D, E> > {};
|
||||||
|
|
||||||
|
/* The Real Big Vertex class;
|
||||||
|
|
||||||
|
The class __VertexArityMax__ is the one that is the Last to be derived,
|
||||||
|
and therefore is the only one to know the real members
|
||||||
|
(after the many overrides) so all the functions with common behaviour
|
||||||
|
using the members defined in the various Empty/nonEmpty component classes
|
||||||
|
MUST be defined here.
|
||||||
|
|
||||||
|
I.e. IsD() that uses the overridden Flags() member must be defined here.
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
template <class BVT, class BET, typename BFT,class BTT,
|
||||||
|
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>
|
||||||
|
class VertexArityMax: public G<VertexArity6<BVT,BET,BFT,BTT, A, B, C, D, E, F> > {
|
||||||
|
|
||||||
|
// ----- Flags stuff -----
|
||||||
|
public:
|
||||||
|
enum {
|
||||||
|
// This bit indicate that the vertex is deleted from the mesh
|
||||||
|
DELETED = 0x0001, // cancellato
|
||||||
|
// This bit indicate that the vertex of the mesh is not readable
|
||||||
|
NOTREAD = 0x0002, // non leggibile (ma forse modificabile)
|
||||||
|
// This bit indicate that the vertex is not modifiable
|
||||||
|
NOTWRITE = 0x0004, // non modificabile (ma forse leggibile)
|
||||||
|
// This bit indicate that the vertex is modified
|
||||||
|
MODIFIED = 0x0008, // modificato
|
||||||
|
// This bit can be used to mark the visited vertex
|
||||||
|
VISITED = 0x0010, // Visited
|
||||||
|
// This bit can be used to select
|
||||||
|
SELECTED = 0x0020, // Selection flag
|
||||||
|
// Border Flag
|
||||||
|
BORDER = 0x0100,
|
||||||
|
// First user bit
|
||||||
|
USER0 = 0x0200 // Fisrt user bit
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
inline int & UberFlags ()
|
||||||
|
{
|
||||||
|
return Flags();
|
||||||
|
}
|
||||||
|
inline const int UberFlags() const
|
||||||
|
{
|
||||||
|
return Flags();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// checks if the vertex is deleted
|
||||||
|
bool IsD() const {return (Flags() & DELETED) != 0;}
|
||||||
|
/// checks if the vertex is readable
|
||||||
|
bool IsR() const {return (Flags() & NOTREAD) == 0;}
|
||||||
|
/// checks if the vertex is modifiable
|
||||||
|
bool IsW() const {return (Flags() & NOTWRITE)== 0;}
|
||||||
|
/// This funcion checks whether the vertex is both readable and modifiable
|
||||||
|
bool IsRW() const {return (Flags() & (NOTREAD | NOTWRITE)) == 0;}
|
||||||
|
/// checks if the vertex is Modified
|
||||||
|
bool IsS() const {return (Flags() & SELECTED) != 0;}
|
||||||
|
/// checks if the vertex is readable
|
||||||
|
bool IsB() const {return (Flags() & BORDER) != 0;}
|
||||||
|
|
||||||
|
/** Set the flag value
|
||||||
|
@param flagp Valore da inserire nel flag
|
||||||
|
*/
|
||||||
|
void SetFlags(int flagp) {Flags()=flagp;}
|
||||||
|
|
||||||
|
/** Set the flag value
|
||||||
|
@param flagp Valore da inserire nel flag
|
||||||
|
*/
|
||||||
|
void ClearFlags() {Flags()=0;}
|
||||||
|
|
||||||
|
/// deletes the vertex from the mesh
|
||||||
|
void SetD() {Flags() |=DELETED;}
|
||||||
|
/// un-delete a vertex
|
||||||
|
void ClearD() {Flags() &=(~DELETED);}
|
||||||
|
/// marks the vertex as readable
|
||||||
|
void SetR() {Flags() &=(~NOTREAD);}
|
||||||
|
/// marks the vertex as not readable
|
||||||
|
void ClearR() {Flags() |=NOTREAD;}
|
||||||
|
/// marks the vertex as writable
|
||||||
|
void ClearW() {Flags() |=NOTWRITE;}
|
||||||
|
/// marks the vertex as not writable
|
||||||
|
void SetW() {Flags() &=(~NOTWRITE);}
|
||||||
|
/// select the vertex
|
||||||
|
void SetS() {Flags() |=SELECTED;}
|
||||||
|
/// Un-select a vertex
|
||||||
|
void ClearS() {Flags() &= ~SELECTED;}
|
||||||
|
void SetB() {Flags() |=BORDER;}
|
||||||
|
void ClearB() {Flags() &=~BORDER;}
|
||||||
|
|
||||||
|
/// Return the first bit that is not still used
|
||||||
|
static int &LastBitFlag()
|
||||||
|
{
|
||||||
|
static int b =USER0;
|
||||||
|
return b;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// allocate a bit among the flags that can be used by user.
|
||||||
|
static inline int NewUserBit()
|
||||||
|
{
|
||||||
|
LastBitFlag()=LastBitFlag()<<1;
|
||||||
|
return LastBitFlag();
|
||||||
|
}
|
||||||
|
// de-allocate a bit among the flags that can be used by user.
|
||||||
|
static inline bool DeleteUserBit(int bitval)
|
||||||
|
{
|
||||||
|
if(LastBitFlag()==bitval) {
|
||||||
|
LastBitFlag()= LastBitFlag()>>1;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
assert(0);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
/// This function checks if the given user bit is true
|
||||||
|
bool IsUserBit(int userBit){return (Flags() & userBit) != 0;}
|
||||||
|
/// This function set the given user bit
|
||||||
|
void SetUserBit(int userBit){Flags() |=userBit;}
|
||||||
|
/// This function clear the given user bit
|
||||||
|
void ClearUserBit(int userBit){Flags() &= (~userBit);}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
template < typename T=int>
|
||||||
|
class DefaultDeriver : public T {};
|
||||||
|
|
||||||
|
/*
|
||||||
|
|
||||||
|
These are the three main classes that are used by the library user to define its own vertexes.
|
||||||
|
The user MUST specify the names of all the type involved in a generic complex.
|
||||||
|
so for example when defining a vertex of a trimesh you must know the name of the type of the edge and of the face.
|
||||||
|
Typical usage example:
|
||||||
|
|
||||||
|
A vertex with coords, flags and normal for use in a standard trimesh:
|
||||||
|
|
||||||
|
class VertexNf : public VertexSimp2< VertexNf, EdgeProto, FaceProto, vert::Coord3d, vert::Flag, vert::Normal3f > {};
|
||||||
|
|
||||||
|
|
||||||
|
A vertex with coords, and normal for use in a tetrahedral mesh AND in a standard trimesh:
|
||||||
|
|
||||||
|
class TetraVertex : public VertexSimp3< TetraVertex, EdgeProto, FaceProto, TetraProto, vert::Coord3d, vert::Normal3f > {};
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
template <class BVT, class BET, class BFT, class BTT,
|
||||||
|
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 >
|
||||||
|
class VertexSimp3: public VertexArityMax<BVT,BET,BFT,BTT, A, B, C, D, E, F, G> {};
|
||||||
|
|
||||||
|
template <class BVT, class BET, class BFT,
|
||||||
|
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 >
|
||||||
|
class VertexSimp2: public VertexArityMax<BVT,BET,BFT,DumTT, A, B, C, D, E, F, G> {};
|
||||||
|
|
||||||
|
template <class BVT, class BET,
|
||||||
|
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 >
|
||||||
|
class VertexSimp1: public VertexArityMax<BVT,BET,DumFT,DumTT, A, B, C, D, E, F, G> {};
|
||||||
|
|
||||||
|
}// end namespace
|
||||||
|
#endif
|
|
@ -0,0 +1,184 @@
|
||||||
|
/****************************************************************************
|
||||||
|
* 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 $
|
||||||
|
|
||||||
|
****************************************************************************/
|
||||||
|
#ifndef __VCG_VERTEX_PLUS_COMPONENT
|
||||||
|
#define __VCG_VERTEX_PLUS_COMPONENT
|
||||||
|
|
||||||
|
namespace vcg {
|
||||||
|
namespace vert {
|
||||||
|
/*
|
||||||
|
Some naming Rules
|
||||||
|
All the Components that can be added to a vertex should be defined in the namespace vert:
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*------------------------- COORD -----------------------------------------*/
|
||||||
|
template <class T> class EmptyCoord: public T {
|
||||||
|
public:
|
||||||
|
typedef vcg::Point3f CoordType;
|
||||||
|
typedef CoordType::ScalarType ScalarType;
|
||||||
|
|
||||||
|
CoordType &P() { static CoordType coord(0, 0, 0); return coord; }
|
||||||
|
CoordType &UberP() { static CoordType coord(0, 0, 0); return coord; }
|
||||||
|
};
|
||||||
|
|
||||||
|
template <class A, class T> class Coord: public T {
|
||||||
|
public:
|
||||||
|
typedef A CoordType;
|
||||||
|
typedef typename CoordType::ScalarType ScalarType;
|
||||||
|
CoordType &P() { return _coord; }
|
||||||
|
CoordType &UberP() { return _coord; }
|
||||||
|
private:
|
||||||
|
CoordType _coord;
|
||||||
|
};
|
||||||
|
template <class T> class Coord3f: public Coord<vcg::Point3f, T> {};
|
||||||
|
template <class T> class Coord3d: public Coord<vcg::Point3d, T> {};
|
||||||
|
|
||||||
|
/*-------------------------- NORMAL ----------------------------------------*/
|
||||||
|
|
||||||
|
template <class T> class EmptyNormal: public T {
|
||||||
|
public:
|
||||||
|
typedef vcg::Point3s NormalType;
|
||||||
|
NormalType &N() { static NormalType dummy_normal(0, 0, 0); return dummy_normal; }
|
||||||
|
};
|
||||||
|
template <class A, class T> class Normal: public T {
|
||||||
|
public:
|
||||||
|
typedef A NormalType;
|
||||||
|
NormalType &N() { return _norm; }
|
||||||
|
private:
|
||||||
|
NormalType _norm;
|
||||||
|
};
|
||||||
|
|
||||||
|
template <class T> class Normal3s: public Normal<vcg::Point3s, T> {};
|
||||||
|
template <class T> class Normal3f: public Normal<vcg::Point3f, T> {};
|
||||||
|
template <class T> class Normal3d: public Normal<vcg::Point3d, T> {};
|
||||||
|
|
||||||
|
/*-------------------------- NORMAL ----------------------------------------*/
|
||||||
|
|
||||||
|
template <class T> class EmptyTexture: public T {
|
||||||
|
public:
|
||||||
|
typedef vcg::TCoord2<float,1> TextureType;
|
||||||
|
TextureType &T() { static TextureType dummy_texture; return dummy_texture; }
|
||||||
|
static bool HasTexture() { return false; }
|
||||||
|
};
|
||||||
|
template <class A, class T> class Texture: public T {
|
||||||
|
public:
|
||||||
|
typedef A TextureType;
|
||||||
|
TextureType &T() { return _t; }
|
||||||
|
static bool HasTexture() { return true; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
TextureType _t;
|
||||||
|
};
|
||||||
|
|
||||||
|
template <class T> class Texture2s: public Texture<TCoord2<short,1>, T> {};
|
||||||
|
template <class T> class Texture2f: public Texture<TCoord2<float,1>, T> {};
|
||||||
|
template <class T> class Texture2d: public Texture<TCoord2<double,1>, T> {};
|
||||||
|
|
||||||
|
/*------------------------- FLAGS -----------------------------------------*/
|
||||||
|
template <class T> class EmptyFlag: 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; }
|
||||||
|
};
|
||||||
|
|
||||||
|
template <class T> class Flag: public T {
|
||||||
|
public:
|
||||||
|
int &Flags() {return _flags; }
|
||||||
|
const int Flags() const {return _flags; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
int _flags;
|
||||||
|
};
|
||||||
|
|
||||||
|
/*-------------------------- COLOR ----------------------------------*/
|
||||||
|
|
||||||
|
template <class T> class EmptyColor: public T {
|
||||||
|
public:
|
||||||
|
typedef vcg::Point3f ColorType;
|
||||||
|
ColorType &C() { static ColorType color(0, 0, 0); return color; }
|
||||||
|
static bool HasColor() { return false; }
|
||||||
|
};
|
||||||
|
template <class A, class T> class Color: public T {
|
||||||
|
public:
|
||||||
|
typedef A ColorType;
|
||||||
|
ColorType &C() { return _color; }
|
||||||
|
static bool HasColor() { return true; }
|
||||||
|
private:
|
||||||
|
ColorType _color;
|
||||||
|
};
|
||||||
|
|
||||||
|
template <class T> class Color3c: public Color<vcg::Point3<char>, T> {};
|
||||||
|
|
||||||
|
/*-------------------------- Quality ----------------------------------*/
|
||||||
|
|
||||||
|
template <class T> class EmptyQuality: public T {
|
||||||
|
public:
|
||||||
|
typedef float QualityType;
|
||||||
|
QualityType &Q() { static QualityType dummyQuality(0); return dummyQuality; }
|
||||||
|
static bool HasQuality() { return false; }
|
||||||
|
};
|
||||||
|
template <class A, class T> class Quality: public T {
|
||||||
|
public:
|
||||||
|
typedef A QualityType;
|
||||||
|
QualityType &Q() { return _quality; }
|
||||||
|
static bool HasQuality() { return true; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
QualityType _quality;
|
||||||
|
};
|
||||||
|
|
||||||
|
template <class T> class Qualitys: public Quality<short, T> {};
|
||||||
|
template <class T> class Qualityf: public Quality<float, T> {};
|
||||||
|
template <class T> class Qualityd: public Quality<double, T> {};
|
||||||
|
|
||||||
|
/*----------------------------- VFADJ ------------------------------*/
|
||||||
|
|
||||||
|
|
||||||
|
template <class T> class EmptyVFAdj: public T {
|
||||||
|
public:
|
||||||
|
typename T::FacePointer &Fp() { static typename T::FacePointer fp=0; return fp; }
|
||||||
|
int &Zp(){static int z=0; return z;};
|
||||||
|
static bool HasVFAdjacency() { return false; }
|
||||||
|
};
|
||||||
|
|
||||||
|
template <class T> class VFAdj: public T {
|
||||||
|
public:
|
||||||
|
//typedef A ColorType;
|
||||||
|
typename T::FacePointer &Fp() {return fp; }
|
||||||
|
typename T::FacePointer &Zp() {return Zp; }
|
||||||
|
static bool HasVFAdjacency() { return true; }
|
||||||
|
private:
|
||||||
|
typename T::FacePointer fp ;
|
||||||
|
int zp ;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // end namespace vert
|
||||||
|
}// end namespace vcg
|
||||||
|
#endif
|
Loading…
Reference in New Issue