grouped documentation, changed typenames and reflection mechanism

This commit is contained in:
Paolo Cignoni 2004-02-24 21:36:42 +00:00
parent 9eda1fa70c
commit f61873646f
2 changed files with 798 additions and 594 deletions

View File

@ -0,0 +1,196 @@
/****************************************************************************
* 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 $
Revision 1.1 2004/02/19 13:11:06 cignoni
Initial commit
****************************************************************************/
namespace vcg {
namespace tri {
template <class AllocateMeshType>
class Allocator
{
public:
typedef AllocateMeshType MeshType;
typedef typename MeshType::VertexPointer VertexPointer;
typedef typename MeshType::VertexIterator VertexIterator;
typedef typename MeshType::FacePointer FacePointer;
typedef typename MeshType::FaceIterator FaceIterator;
/* This class is used to */
template<class SimplexPointerType>
class PointerUpdater
{
public:
void Clear();
void Update(SimplexPointerType &vp);
bool NeedUpdate();
SimplexPointerType oldBase;
SimplexPointerType newBase;
};
/** Function to add n vertices to the mesh. The second parameter hold a vector of
pointers to pointer to elements of the mesh that should be updated after a
possible vector realloc.
@param n Il numero di vertici che si vuole aggiungere alla mesh.
@param local_var Vettore di variabili locali che rappresentano puntatori a vertici.
restituisce l'iteratore al primo elemento aggiunto.
*/
static VertexIterator AddVertices(MeshType &m,int n, PointerUpdater<VertexPointer> &pu)
{
VertexIterator last=m.vert.end();
pu.Clear();
if(m.vert.empty()) pu.oldBase=0; // if the vector is empty we cannot find the last valid element
else pu.oldBase=&*m.vert.begin();
for(int i=0; i<n; ++i)
{
m.vert.push_back(MeshType::VertexType());
m.vert.back().ClearFlags();
}
m.vn+=n;
pu.newBase = &*m.vert.begin();
if(pu.NeedUpdate())
{
FaceIterator fi;
for (fi=m.face.begin(); fi!=m.face.end(); ++fi)
if(!(*fi).IsD())
{
pu.Update((*fi).V(0));
pu.Update((*fi).V(1));
pu.Update((*fi).V(2));
}
// e poiche' lo spazio e' cambiato si ricalcola anche last da zero
if(last!=0)
{
last = m.vert.begin();
advance(last,siz+1);
}
else last=m.vert.begin();
}
return last;// deve restituire l'iteratore alla prima faccia aggiunta;
}
static VertexIterator AddVertices(MeshType &m, int n)
{
PointerUpdater<VertexPointer> pu;
return AddVertices(m, n,pu);
}
/** Function to add n faces to the mesh.
@param n Il numero di facce che si vuole aggiungere alla mesh
*/
static FaceIterator AddFaces(MeshType &m, int n)
{
PointerUpdater<FacePointer> pu;
return AddFaces(m,n,pu);
}
/** Function to add n faces to the mesh.
NOTA: Aggiorna fn;
The second parameter hold a vector of
pointers to pointer to elements of the mesh that should be updated after a
possible vector realloc.
@param n Facce da aggiungere
@param local_var Vettore di variabili locali che rappresentano puntatori a facce, occorre,
perche' questi valori siano consistenti, aggiornarli ogni qual volta venga eseguito un resize
del contenitore delle facce.
*/
static FaceIterator AddFaces(MeshType &m, int n, PointerUpdater<FacePointer> &pu)
{
FaceIterator last=m.vert.end();
pu.Clear();
if(m.face.empty()) pu.oldBase=0; // if the vector is empty we cannot find the last valid element
else pu.oldBase=&*m.face.begin();
unsigned int siz=0; for(int i=0; i<n; ++i)
{
m.face.push_back(MeshType::FaceType());
m.face.back().ClearFlags();
}
m.fn+=n;
pu.newBase = &*m.face.begin();
FaceIterator oldbegin, newbegin;
oldbegin = face.begin();
FaceIterator last=face.end();
if(face.empty()) last=0;
else last--;
unsigned int siz=0;
MFTYPE dum;
dum.Supervisor_Flags()=0;
for(int i=0; i<n; ++i)
face.push_back(dum);
fn+=n;
newbegin = face.begin();
if(newbegin != oldbegin)// se e' cambiato lo spazio (vector abbastanza grande o lista)
{
if(MFTYPE::OBJ_TYPE & MFTYPE::OBJ_TYPE_A)
{
FaceIterator f;
for (f=face.begin(); f!=face.end(); ++f)
for(int k=0; k<(*f).size(); ++k)if(!(*f).IsD())
(*f).F(k) = (*f).F(k)-&*oldbegin+&*newbegin;
}
vector<face_base **>::iterator jit;
for(jit=local_var.begin(); jit!=local_var.end(); ++jit)
if((**jit) !=0 ) **jit = **jit-&*oldbegin+&*newbegin;
// deve restituire l'iteratore alla prima faccia aggiunta;
if(last!=0)
{
last = face.begin();
advance(last,siz+1);
}
else last=face.begin();
}
else //
{ assert(newbegin == oldbegin);
// se non e'cambiato lo spazio (vector abbastanza grande o lista)
if(last==0) last = face.begin(); // se il vettore era vuoto si restituisce begin
else advance(last,1); // altrimenti il primo dopo quello che era in precedenza l'ultimo valido.
}
return last;
}
}; // end class
} // End Namespace TriMesh
} // End Namespace vcg

View File

@ -24,6 +24,9 @@
History History
$Log: not supported by cvs2svn $ $Log: not supported by cvs2svn $
Revision 1.2 2004/02/13 02:09:39 cignoni
First working release, with doxygen comment structure
Revision 1.1 2004/02/10 01:11:28 cignoni Revision 1.1 2004/02/10 01:11:28 cignoni
Edited Comments and GPL license Edited Comments and GPL license
@ -42,7 +45,9 @@ class DUMMYFACETYPE;
namespace vcg { namespace vcg {
/** @name Vertex /**
\ingroup vertex
@name Vertex
Class Vertex. Class Vertex.
This is the base class for definition of a vertex of the mesh. This is the base class for definition of a vertex of the mesh.
@param FLTYPE (Template Parameter) Specifies the scalar field of the vertex coordinate type. @param FLTYPE (Template Parameter) Specifies the scalar field of the vertex coordinate type.
@ -59,7 +64,7 @@ public:
/// The type base of the vertex, useful for recovering the original typename after user subclassing /// The type base of the vertex, useful for recovering the original typename after user subclassing
typedef VERTEX_TYPE BaseVertexType; typedef VERTEX_TYPE BaseVertexType;
/// The type base of the vertex, useful for recovering the original typename after user subclassing /// The type base of the vertex, useful for recovering the original typename after user subclassing
typedef VFTYPE face_type; typedef VFTYPE FaceType;
/***********************************************/ /***********************************************/
@ -114,13 +119,17 @@ public:
/***********************************************/ /***********************************************/
/** @name Vertex Flags /** @name Vertex Flags
blah For each vertex we store a set of boolean values packed in a int.
blah The default value for each flag is 0. Most commonly used flags are the \a deleted and the \a selected ones.
Users can ask and dispose for a bit for their own purposes with the vcg::VertexFull::NewUserBit() and vcg::VertexFull::DeleteUserBit() functions.
The value returned by these functions has to be passed to the
vcg::VertexFull::SetUserBit() vcg::VertexFull::ClearUserBit() and vcg::VertexFull::IsUserBit() functions to check and modify the obtained bit flag.
**/ **/
//@{ //@{
protected: protected:
/// This are the _flags of vertex, the default value is 0 /// This are the flags of vertex, the default (reasonable) value is 0
int _flags; int _flags;
public: public:
@ -141,6 +150,80 @@ public:
{ {
return _flags; 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);}
//@} //@}
@ -420,43 +503,51 @@ public:
} }
//@} //@}
/***********************************************/
/** @name Reflection Functions
Static functions that give information about the current vertex type.
Reflection is a mechanism making it possible to investigate yourself. Reflection is used to investigate format of objects at runtime, invoke methods and access fields of these objects. Here we provide static const functions that are resolved at compile time and they give information about the data (normal, color etc.) supported by the current vertex type.
**/
//@{
static bool HasNormal() {
enum {
OBJ_TYPE_N = 0x0001,
OBJ_TYPE_M = 0x0002,
OBJ_TYPE_A = 0x0004,
OBJ_TYPE_AS = 0x0008,
OBJ_TYPE_C = 0x0010,
OBJ_TYPE_T = 0x0020,
OBJ_TYPE_Q = 0x0040,
};
enum {
OBJ_TYPE =
#ifdef __VCGLIB_VERTEX_N #ifdef __VCGLIB_VERTEX_N
OBJ_TYPE_N | return true
#endif #else
#ifdef __VCGLIB_VERTEX_M return false
OBJ_TYPE_M |
#endif
#ifdef __VCGLIB_VERTEX_A
OBJ_TYPE_A |
#endif
#ifdef __VCGLIB_VERTEX_AS
OBJ_TYPE_AS |
#endif #endif
}
static bool HasColor() {
#ifdef __VCGLIB_VERTEX_C #ifdef __VCGLIB_VERTEX_C
OBJ_TYPE_C | return true
#else
return false
#endif #endif
#ifdef __VCGLIB_VERTEX_T }
OBJ_TYPE_T | static bool HasMark() {
#ifdef __VCGLIB_VERTEX_M
return true
#else
return false
#endif #endif
}
static bool HasQuality() {
#ifdef __VCGLIB_VERTEX_Q #ifdef __VCGLIB_VERTEX_Q
OBJ_TYPE_Q | return true
#else
return false
#endif #endif
0 }
}; static bool HasTexture() {
#ifdef __VCGLIB_VERTEX_T
return true
#else
return false
#endif
}
//@}
enum { enum {
@ -478,29 +569,6 @@ public:
USER0 = 0x0200 // Fisrt user bit USER0 = 0x0200 // Fisrt user bit
}; };
/*
Queste funzioni servono per ottenere a runtime un bit per i flag
*/
static int &LastBitFlag()
{
static int b =USER0;
return b;
}
static inline int NewBitFlag()
{
LastBitFlag()=LastBitFlag()<<1;
return LastBitFlag();
}
static inline bool DeleteBitFlag(int bitval)
{
if(LastBitFlag()==bitval) {
LastBitFlag()= LastBitFlag()>>1;
return true;
}
assert(0);
return false;
}
/** Return the i-th spatial value of the vertex coordinate. /** Return the i-th spatial value of the vertex coordinate.
@param i Index of the spatial vertex coordinate (x=0 y=1 z=2). @param i Index of the spatial vertex coordinate (x=0 y=1 z=2).
@ -526,66 +594,6 @@ static inline bool DeleteBitFlag(int bitval)
#endif #endif
}; };
/// This function checks if the vertex is deleted
bool IsD() const {return (_flags & DELETED) != 0;}
/// This function checks if the vertex is readable
bool IsR() const {return (_flags & NOTREAD) == 0;}
/// This function 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;}
/// This function checks if the vertex is Modified
bool IsM() const {return (_flags & MODIFIED)!= 0;}
/// This function checks if the vertex is marked as visited
bool IsV() const {return (_flags & VISITED) != 0;}
/// This function checks if the vertex is selected
bool IsS() const {return (_flags & SELECTED) != 0;}
/// This function checks if the vertex is readable
bool IsB() const {return (_flags & BORDER) != 0;}
// bool IsMF() const {return (_flags & NOTMANIFOLD) == 0;}
/// This function checks if the vertex is deleted from the mesh
bool IsDeleted() const {return IsD();}
/// This function checks if the vertex is readable
bool IsReadable() const {return IsR();}
/** Set the flag value
@param flagp Valore da inserire nel flag
*/
void SetFlags(int flagp) {_flags=flagp;}
/// This function deletes the vertex from the mesh
void SetD() {_flags |=DELETED;}
/// This funcion execute the inverse operation of SetD()
void ClearD() {_flags &=(~DELETED);}
/// This function marks the vertex as modified. It's necessary to mark all modified vertex to have a consistent mesh
void SetM() {_flags |=MODIFIED;}
/// This function marks the vertex as not modified
void ClearM() {_flags &=(~MODIFIED);}
/// This function marks the vertex as readable
void SetR() {_flags &=(~NOTREAD);}
/// This function marks the vertex as not readable
void ClearR() {_flags |=NOTREAD;}
/// This function marks the vertex as writable
void ClearW() {_flags |=NOTWRITE;}
/// This function marks the vertex as not writable
void SetW() {_flags &=(~NOTWRITE);}
/// This funcion marks the vertex as visited
void SetV() {_flags |=VISITED;}
/// This function marks the vertex as not visited. This flag, initially, is setted to random value, therefore, to the beginnig of every function it is necessary to clean up the flag
void ClearV() {_flags &=(~VISITED);}
/// This function select the vertex
void SetS() {_flags |=SELECTED;}
/// This funcion execute the inverse operation of SetS()
void ClearS() {_flags &= ~SELECTED;}
void SetB() {_flags |=BORDER;}
void ClearB() {_flags &=~BORDER;}
/// 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);}
}; };