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) ...@@ -193,7 +193,6 @@ void Viewer::importMesh(std::string& filename)
normalBaseSize = bb.diagSize() / 100.0f ; normalBaseSize = bb.diagSize() / 100.0f ;
// vertexBaseSize = normalBaseSize /5.0f ; // vertexBaseSize = normalBaseSize /5.0f ;
normal = myMap.getAttribute<PFP::VEC3>(VERTEX, "normal") ;
if(!normal.isValid()) if(!normal.isValid())
normal = myMap.addAttribute<PFP::VEC3>(VERTEX, "normal") ; normal = myMap.addAttribute<PFP::VEC3>(VERTEX, "normal") ;
......
...@@ -38,7 +38,15 @@ template <typename T> ...@@ -38,7 +38,15 @@ template <typename T>
inline bool AttribMap::removeAttribute(AttributeHandler<T>& attr) inline bool AttribMap::removeAttribute(AttributeHandler<T>& attr)
{ {
assert(attr.isValid() || !"Invalid attribute handler") ; 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> template <typename T>
......
...@@ -40,6 +40,9 @@ protected: ...@@ -40,6 +40,9 @@ protected:
GenericMap* m_map; GenericMap* m_map;
public: public:
AttributeHandlerGen() : m_map(NULL)
{}
AttributeHandlerGen(GenericMap* m) : m_map(m) AttributeHandlerGen(GenericMap* m) : m_map(m)
{} {}
...@@ -47,6 +50,11 @@ public: ...@@ -47,6 +50,11 @@ public:
{ {
return m_map ; return m_map ;
} }
void setInvalid()
{
m_map = NULL ;
}
}; };
/** /**
...@@ -66,6 +74,12 @@ protected: ...@@ -66,6 +74,12 @@ protected:
public: public:
typedef T DATA_TYPE ; typedef T DATA_TYPE ;
/**
* Default constructor
* Constructs a non-valid AttributeHandler (i.e. not linked to any attribute)
*/
AttributeHandler() ;
/** /**
* Constructor * Constructor
* @param m the map which belong attribute * @param m the map which belong attribute
...@@ -73,12 +87,6 @@ public: ...@@ -73,12 +87,6 @@ public:
*/ */
AttributeHandler(GenericMap* m, AttributeMultiVector<T>* amv) ; AttributeHandler(GenericMap* m, AttributeMultiVector<T>* amv) ;
/**
* Default constructor
* Constructs a non-valid AttributeHandler (i.e. not linked to any attribute)
*/
AttributeHandler() ;
/** /**
* Copy constructor * Copy constructor
* @param ta the table attribute * @param ta the table attribute
......
...@@ -26,30 +26,47 @@ namespace CGoGN ...@@ -26,30 +26,47 @@ namespace CGoGN
{ {
template <typename T> template <typename T>
AttributeHandler<T>::AttributeHandler(GenericMap* m, AttributeMultiVector<T>* amv) : AttributeHandler<T>::AttributeHandler() :
AttributeHandlerGen(m), m_attrib(amv) AttributeHandlerGen(), m_attrib(NULL)
{} {}
template <typename T> template <typename T>
AttributeHandler<T>::AttributeHandler() : AttributeHandler<T>::AttributeHandler(GenericMap* m, AttributeMultiVector<T>* amv) :
AttributeHandlerGen(NULL), m_attrib(NULL) AttributeHandlerGen(m), m_attrib(amv)
{} {
m->attributeHandlers.insert(std::pair<AttributeMultiVectorGen*, AttributeHandlerGen*>(amv, this)) ;
}
template <typename T> template <typename T>
AttributeHandler<T>::AttributeHandler(const AttributeHandler<T>& ta) : AttributeHandler<T>::AttributeHandler(const AttributeHandler<T>& ta) :
AttributeHandlerGen(ta.m_map), m_attrib(ta.m_attrib) AttributeHandlerGen(ta.m_map), m_attrib(ta.m_attrib)
{} {
this->m_map->attributeHandlers.insert(std::pair<AttributeMultiVectorGen*, AttributeHandlerGen*>(m_attrib, this)) ;
}
template <typename T> template <typename T>
inline void AttributeHandler<T>::operator=(const AttributeHandler<T>& ta) inline void AttributeHandler<T>::operator=(const AttributeHandler<T>& ta)
{ {
this->m_map = ta.m_map ; this->m_map = ta.m_map ;
m_attrib = ta.m_attrib ; m_attrib = ta.m_attrib ;
this->m_map->attributeHandlers.insert(std::pair<AttributeMultiVectorGen*, AttributeHandlerGen*>(m_attrib, this)) ;
} }
template <typename T> template <typename T>
AttributeHandler<T>::~AttributeHandler() 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> template <typename T>
AttributeMultiVector<T>* AttributeHandler<T>::getDataVector() const AttributeMultiVector<T>* AttributeHandler<T>::getDataVector() const
......
...@@ -77,6 +77,7 @@ class GenericMap : public MapBrowser ...@@ -77,6 +77,7 @@ class GenericMap : public MapBrowser
{ {
friend class DartMarkerGen ; friend class DartMarkerGen ;
template<typename T> friend class AttributeHandler ;
template<typename T> friend class AutoAttributeHandler ; template<typename T> friend class AutoAttributeHandler ;
protected: protected:
...@@ -105,7 +106,7 @@ protected: ...@@ -105,7 +106,7 @@ protected:
unsigned int m_nbThreads ; unsigned int m_nbThreads ;
// std::multimap<AttributeMultiVectorGen*, AttributeHandlerGen*> attributeHandlers ; std::multimap<AttributeMultiVectorGen*, AttributeHandlerGen*> attributeHandlers ;
public: public:
static const unsigned int UNKNOWN_ATTRIB = AttributeContainer::UNKNOWN ; static const unsigned int UNKNOWN_ATTRIB = AttributeContainer::UNKNOWN ;
......
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
*******************************************************************************/ *******************************************************************************/
#include "Topology/generic/genericmap.h" #include "Topology/generic/genericmap.h"
#include "Topology/generic/attributeHandler.h"
#include "Topology/generic/dartmarker.h" #include "Topology/generic/dartmarker.h"
#include "Geometry/vector_gen.h" #include "Geometry/vector_gen.h"
#include "Geometry/matrix.h" #include "Geometry/matrix.h"
...@@ -111,6 +112,12 @@ void GenericMap::clear(bool removeAttrib) ...@@ -111,6 +112,12 @@ void GenericMap::clear(bool removeAttrib)
m_markTables[i][j] = NULL ; 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