Commit ad2de7a7 authored by Pierre Kraemer's avatar Pierre Kraemer

map now manages the validity of AttributeHandlers

parent b7003005
......@@ -193,7 +193,6 @@ void Viewer::importMesh(std::string& filename)
normalBaseSize = bb.diagSize() / 100.0f ;
// vertexBaseSize = normalBaseSize /5.0f ;
normal = myMap.getAttribute<PFP::VEC3>(VERTEX, "normal") ;
if(!normal.isValid())
normal = myMap.addAttribute<PFP::VEC3>(VERTEX, "normal") ;
......
......@@ -38,7 +38,15 @@ template <typename T>
inline bool AttribMap::removeAttribute(AttributeHandler<T>& attr)
{
assert(attr.isValid() || !"Invalid attribute handler") ;
return m_attribs[attr.getOrbit()].removeAttribute<T>(attr.getIndex()) ;
if(m_attribs[attr.getOrbit()].removeAttribute<T>(attr.getIndex()))
{
typedef std::multimap<AttributeMultiVectorGen*, AttributeHandlerGen*>::iterator IT ;
std::pair<IT, IT> bounds = attributeHandlers.equal_range(attr.getDataVector()) ;
for(IT i = bounds.first; i != bounds.second; ++i)
(*i).second->setInvalid() ;
return true ;
}
return false ;
}
template <typename T>
......
......@@ -40,6 +40,9 @@ protected:
GenericMap* m_map;
public:
AttributeHandlerGen() : m_map(NULL)
{}
AttributeHandlerGen(GenericMap* m) : m_map(m)
{}
......@@ -47,6 +50,11 @@ public:
{
return m_map ;
}
void setInvalid()
{
m_map = NULL ;
}
};
/**
......@@ -66,6 +74,12 @@ protected:
public:
typedef T DATA_TYPE ;
/**
* Default constructor
* Constructs a non-valid AttributeHandler (i.e. not linked to any attribute)
*/
AttributeHandler() ;
/**
* Constructor
* @param m the map which belong attribute
......@@ -73,12 +87,6 @@ public:
*/
AttributeHandler(GenericMap* m, AttributeMultiVector<T>* amv) ;
/**
* Default constructor
* Constructs a non-valid AttributeHandler (i.e. not linked to any attribute)
*/
AttributeHandler() ;
/**
* Copy constructor
* @param ta the table attribute
......
......@@ -26,30 +26,47 @@ namespace CGoGN
{
template <typename T>
AttributeHandler<T>::AttributeHandler(GenericMap* m, AttributeMultiVector<T>* amv) :
AttributeHandlerGen(m), m_attrib(amv)
AttributeHandler<T>::AttributeHandler() :
AttributeHandlerGen(), m_attrib(NULL)
{}
template <typename T>
AttributeHandler<T>::AttributeHandler() :
AttributeHandlerGen(NULL), m_attrib(NULL)
{}
AttributeHandler<T>::AttributeHandler(GenericMap* m, AttributeMultiVector<T>* amv) :
AttributeHandlerGen(m), m_attrib(amv)
{
m->attributeHandlers.insert(std::pair<AttributeMultiVectorGen*, AttributeHandlerGen*>(amv, this)) ;
}
template <typename T>
AttributeHandler<T>::AttributeHandler(const AttributeHandler<T>& ta) :
AttributeHandlerGen(ta.m_map), m_attrib(ta.m_attrib)
{}
{
this->m_map->attributeHandlers.insert(std::pair<AttributeMultiVectorGen*, AttributeHandlerGen*>(m_attrib, this)) ;
}
template <typename T>
inline void AttributeHandler<T>::operator=(const AttributeHandler<T>& ta)
{
this->m_map = ta.m_map ;
m_attrib = ta.m_attrib ;
this->m_map->attributeHandlers.insert(std::pair<AttributeMultiVectorGen*, AttributeHandlerGen*>(m_attrib, this)) ;
}
template <typename T>
AttributeHandler<T>::~AttributeHandler()
{}
{
typedef std::multimap<AttributeMultiVectorGen*, AttributeHandlerGen*>::iterator IT ;
std::pair<IT, IT> bounds = this->m_map->attributeHandlers.equal_range(m_attrib) ;
for(IT i = bounds.first; i != bounds.second; ++i)
{
if((*i).second == this)
{
this->m_map->attributeHandlers.erase(i) ;
return ;
}
}
assert(false || !"Should not get here") ;
}
template <typename T>
AttributeMultiVector<T>* AttributeHandler<T>::getDataVector() const
......
......@@ -77,6 +77,7 @@ class GenericMap : public MapBrowser
{
friend class DartMarkerGen ;
template<typename T> friend class AttributeHandler ;
template<typename T> friend class AutoAttributeHandler ;
protected:
......@@ -105,7 +106,7 @@ protected:
unsigned int m_nbThreads ;
// std::multimap<AttributeMultiVectorGen*, AttributeHandlerGen*> attributeHandlers ;
std::multimap<AttributeMultiVectorGen*, AttributeHandlerGen*> attributeHandlers ;
public:
static const unsigned int UNKNOWN_ATTRIB = AttributeContainer::UNKNOWN ;
......
......@@ -23,6 +23,7 @@
*******************************************************************************/
#include "Topology/generic/genericmap.h"
#include "Topology/generic/attributeHandler.h"
#include "Topology/generic/dartmarker.h"
#include "Geometry/vector_gen.h"
#include "Geometry/matrix.h"
......@@ -111,6 +112,12 @@ void GenericMap::clear(bool removeAttrib)
m_markTables[i][j] = NULL ;
}
}
if(removeAttrib)
{
for(std::multimap<AttributeMultiVectorGen*, AttributeHandlerGen*>::iterator it = attributeHandlers.begin(); it != attributeHandlers.end(); ++it)
(*it).second->setInvalid() ;
}
}
/****************************************
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment