Improved documentation of Attribute mechanims

This commit is contained in:
Paolo Cignoni 2012-10-15 08:17:26 +00:00
parent 08458c2652
commit 42252b04b4
1 changed files with 58 additions and 42 deletions

View File

@ -81,14 +81,18 @@ namespace vcg {
} }
/*@{*/ /*@{*/
/// Class to safely add vertexes and faces to a mesh updating all the involved pointers. /*!
/// It provides static memeber to add either vertex or faces to a trimesh. \brief Class to safely add and delete elements in a mesh.
template <class AllocateMeshType>
Adding elements to a mesh, like faces and vertices can involve the reallocation of the vectors of the involved elements.
This class provide the only safe methods to add elements.
It also provide an accessory class vcg::tri::PointerUpdater for updating pointers to mesh elements that are kept by the user.
*/
template <class MeshType>
class Allocator class Allocator
{ {
public: public:
typedef AllocateMeshType MeshType;
typedef typename MeshType::VertexType VertexType; typedef typename MeshType::VertexType VertexType;
typedef typename MeshType::VertexPointer VertexPointer; typedef typename MeshType::VertexPointer VertexPointer;
typedef typename MeshType::VertexIterator VertexIterator; typedef typename MeshType::VertexIterator VertexIterator;
@ -115,7 +119,10 @@ namespace vcg {
typedef typename std::set<PointerToAttribute>::const_iterator AttrConstIterator; typedef typename std::set<PointerToAttribute>::const_iterator AttrConstIterator;
typedef typename std::set<PointerToAttribute >::iterator PAIte; typedef typename std::set<PointerToAttribute >::iterator PAIte;
/** This class is used when allocating new vertexes and faces to update /*!
\brief Accessory class to update pointers after eventual reallocation caused by adding elements.
This class is used when allocating new vertexes and faces to update
the pointers that can be changed when resizing the involved vectors of vertex or faces. the pointers that can be changed when resizing the involved vectors of vertex or faces.
It can also be used to prevent any update of the various mesh fields It can also be used to prevent any update of the various mesh fields
(e.g. in case you are building all the connections by hand as in a importer); (e.g. in case you are building all the connections by hand as in a importer);
@ -148,12 +155,14 @@ namespace vcg {
}; };
/** Function to add n vertices to the mesh. The second parameter hold a vector of /** \brief Add n vertices to the mesh.
pointers to pointer to elements of the mesh that should be updated after a Function to add n vertices to the mesh.
possible vector realloc. The elements are added always to the end of the vector. No attempt of reusing previously deleted element is done.
@param n Il numero di vertici che si vuole aggiungere alla mesh. \sa PointerUpdater
@param local_var Vettore di variabili locali che rappresentano puntatori a vertici. \param m the mesh to be modified
restituisce l'iteratore al primo elemento aggiunto. \param n the number of elements to be added
\param pu a PointerUpdater initialized so that it can be used to update pointers to vertices that could have become invalid after this adding.
\retval the iterator to the first element added.
*/ */
static VertexIterator AddVertices(MeshType &m,int n, PointerUpdater<VertexPointer> &pu) static VertexIterator AddVertices(MeshType &m,int n, PointerUpdater<VertexPointer> &pu)
{ {
@ -209,8 +218,7 @@ namespace vcg {
return last;// deve restituire l'iteratore alla prima faccia aggiunta; return last;// deve restituire l'iteratore alla prima faccia aggiunta;
} }
/** Function to add n vertices to the mesh. /** \brief Wrapper to AddVertices(); no PointerUpdater
First wrapper, with no parameters
*/ */
static VertexIterator AddVertices(MeshType &m, int n) static VertexIterator AddVertices(MeshType &m, int n)
{ {
@ -218,8 +226,7 @@ namespace vcg {
return AddVertices(m, n,pu); return AddVertices(m, n,pu);
} }
/** Function to add n vertices to the mesh. /** \brief Wrapper to AddVertices() no PointerUpdater but a vector of VertexPointer pointers to be updated
Second Wrapper, with a vector of vertex pointers to be updated.
*/ */
static VertexIterator AddVertices(MeshType &m, int n, std::vector<VertexPointer *> &local_vec) static VertexIterator AddVertices(MeshType &m, int n, std::vector<VertexPointer *> &local_vec)
{ {
@ -233,12 +240,14 @@ namespace vcg {
} }
/* ++++++++++ edges +++++++++++++ */ /* ++++++++++ edges +++++++++++++ */
/** Function to add n edges to the mesh. The second parameter hold a vector of /** \brief Add n edges to the mesh.
pointers to pointer to elements of the mesh that should be updated after a Function to add n edges to the mesh.
possible vector realloc. The elements are added always to the end of the vector. No attempt of reusing previously deleted element is done.
@param n number of edges to be added \sa PointerUpdater
@param local_var vector of pointers to pointers to edges to be updated. \param m the mesh to be modified
return an iterator to the first element added \param n the number of elements to be added
\param pu a PointerUpdater initialized so that it can be used to update pointers to edges that could have become invalid after this adding.
\retval the iterator to the first element added.
*/ */
static EdgeIterator AddEdges(MeshType &m,int n, PointerUpdater<EdgePointer> &pu) static EdgeIterator AddEdges(MeshType &m,int n, PointerUpdater<EdgePointer> &pu)
{ {
@ -896,7 +905,8 @@ namespace vcg {
public: public:
/// Per Vertex Attributes /*! \brief Check if an handle to a Per-Vertex Attribute is valid
*/
template <class ATTR_TYPE> template <class ATTR_TYPE>
static static
bool IsValidHandle( MeshType & m, const typename MeshType::template PerVertexAttributeHandle<ATTR_TYPE> & a){ bool IsValidHandle( MeshType & m, const typename MeshType::template PerVertexAttributeHandle<ATTR_TYPE> & a){
@ -906,6 +916,10 @@ public:
return false; return false;
} }
/*! \brief Add a Per-Vertex Attribute of the given ATTR_TYPE with the given name.
No attribute with that name must exists (even of different type)
*/
template <class ATTR_TYPE> template <class ATTR_TYPE>
static static
typename MeshType::template PerVertexAttributeHandle<ATTR_TYPE> typename MeshType::template PerVertexAttributeHandle<ATTR_TYPE>
@ -928,16 +942,18 @@ public:
} }
template <class ATTR_TYPE> template <class ATTR_TYPE>
static static typename MeshType::template PerVertexAttributeHandle<ATTR_TYPE>
typename MeshType::template PerVertexAttributeHandle<ATTR_TYPE>
AddPerVertexAttribute( MeshType & m){ AddPerVertexAttribute( MeshType & m){
return AddPerVertexAttribute<ATTR_TYPE>(m,std::string("")); return AddPerVertexAttribute<ATTR_TYPE>(m,std::string(""));
} }
/*! \brief Try to retrieve an handle to an attribute with a given name and ATTR_TYPE
\returns a invalid handle if no attribute with that name and type exists.
*/
template <class ATTR_TYPE> template <class ATTR_TYPE>
static static typename MeshType::template PerVertexAttributeHandle<ATTR_TYPE>
typename MeshType::template PerVertexAttributeHandle<ATTR_TYPE> GetPerVertexAttribute( MeshType & m, const std::string & name)
GetPerVertexAttribute( MeshType & m, const std::string & name){ {
assert(!name.empty()); assert(!name.empty());
PointerToAttribute h1; h1._name = name; PointerToAttribute h1; h1._name = name;
typename std::set<PointerToAttribute > :: iterator i; typename std::set<PointerToAttribute > :: iterator i;