Commit 7b93a4a0 authored by Pierre Kraemer's avatar Pierre Kraemer

update AttributeHandlers management

parent ad2de7a7
......@@ -65,9 +65,9 @@ class MeshTablesSurface
protected:
typename PFP::MAP& m_map;
unsigned m_nbVertices;
unsigned int m_nbVertices;
unsigned m_nbFaces;
unsigned int m_nbFaces;
unsigned int m_lab;
......@@ -138,11 +138,11 @@ class MeshTablesVolume
protected:
typename PFP::MAP& m_map;
unsigned m_nbVertices;
unsigned int m_nbVertices;
unsigned m_nbFaces;
unsigned int m_nbFaces;
unsigned m_nbVolumes;
unsigned int m_nbVolumes;
/**
* number of edges per face
......
......@@ -267,7 +267,7 @@ bool MeshTablesSurface<PFP>::importTrianBinGz(const std::string& filename, std::
template<typename PFP>
bool MeshTablesSurface<PFP>::importOff(const std::string& filename, std::vector<std::string>& attrNames)
{
AttributeHandler<typename PFP::VEC3> positions = m_map.template getAttribute<typename PFP::VEC3>(VERTEX, "position") ;
AttributeHandler<typename PFP::VEC3> positions = m_map.template getAttribute<typename PFP::VEC3>(VERTEX, "position") ;
if (!positions.isValid())
positions = m_map.template addAttribute<typename PFP::VEC3>(VERTEX, "position") ;
......
......@@ -35,7 +35,6 @@ class AttribMap : public GenericMap
{
private:
friend class CellMarkerGen ;
template<typename T> friend class AutoAttributeHandler ;
void init() ;
......
......@@ -44,6 +44,7 @@ inline bool AttribMap::removeAttribute(AttributeHandler<T>& attr)
std::pair<IT, IT> bounds = attributeHandlers.equal_range(attr.getDataVector()) ;
for(IT i = bounds.first; i != bounds.second; ++i)
(*i).second->setInvalid() ;
attributeHandlers.erase(bounds.first, bounds.second) ;
return true ;
}
return false ;
......
......@@ -36,14 +36,16 @@ namespace CGoGN
class AttributeHandlerGen
{
protected:
friend class GenericMap ;
friend class AttribMap ;
// the map that contains the linked attribute
GenericMap* m_map;
GenericMap* m_map ;
// boolean that states the validity of the handler
bool valid ;
public:
AttributeHandlerGen() : m_map(NULL)
{}
AttributeHandlerGen(GenericMap* m) : m_map(m)
AttributeHandlerGen(GenericMap* m, bool v) : m_map(m), valid(v)
{}
GenericMap* map() const
......@@ -51,11 +53,17 @@ public:
return m_map ;
}
bool isValid() const
{
return valid ;
}
protected:
void setInvalid()
{
m_map = NULL ;
valid = false ;
}
};
} ;
/**
* Class that create an access-table to an existing attribute
......@@ -71,6 +79,9 @@ protected:
// the multi-vector that contains attribute data
AttributeMultiVector<T>* m_attrib;
void registerInMap() ;
void unregisterFromMap() ;
public:
typedef T DATA_TYPE ;
......@@ -124,14 +135,6 @@ public:
*/
const std::string& name() const ;
/**
* check if the attribute handler is linked to a valid attribute
* -> MUST BE USED AFTER A CALL TO :
* getAttribute(unsigned int orbit, const std::string& nameAttr)
* addAttribute(unsigned int orbit, const std::string& nameAttr)
*/
bool isValid() const ;
/**
* [] operator with dart parameter
*/
......
......@@ -25,47 +25,73 @@
namespace CGoGN
{
template <typename T>
void AttributeHandler<T>::registerInMap()
{
m_map->attributeHandlers.insert(std::pair<AttributeMultiVectorGen*, AttributeHandlerGen*>(m_attrib, this)) ;
}
template <typename T>
void AttributeHandler<T>::unregisterFromMap()
{
typedef std::multimap<AttributeMultiVectorGen*, AttributeHandlerGen*>::iterator IT ;
std::pair<IT, IT> bounds = m_map->attributeHandlers.equal_range(m_attrib) ;
for(IT i = bounds.first; i != bounds.second; ++i)
{
if((*i).second == this)
{
m_map->attributeHandlers.erase(i) ;
return ;
}
}
assert(false || !"Should not get here") ;
}
// =================================================================
template <typename T>
AttributeHandler<T>::AttributeHandler() :
AttributeHandlerGen(), m_attrib(NULL)
AttributeHandlerGen(NULL, false), m_attrib(NULL)
{}
template <typename T>
AttributeHandler<T>::AttributeHandler(GenericMap* m, AttributeMultiVector<T>* amv) :
AttributeHandlerGen(m), m_attrib(amv)
AttributeHandlerGen(m, false), m_attrib(amv)
{
m->attributeHandlers.insert(std::pair<AttributeMultiVectorGen*, AttributeHandlerGen*>(amv, this)) ;
if(amv != NULL && amv->getIndex() != AttributeContainer::UNKNOWN)
{
valid = true ;
registerInMap() ;
}
else
valid = false ;
}
template <typename T>
AttributeHandler<T>::AttributeHandler(const AttributeHandler<T>& ta) :
AttributeHandlerGen(ta.m_map), m_attrib(ta.m_attrib)
AttributeHandlerGen(ta.m_map, ta.valid), m_attrib(ta.m_attrib)
{
this->m_map->attributeHandlers.insert(std::pair<AttributeMultiVectorGen*, AttributeHandlerGen*>(m_attrib, this)) ;
if(valid)
registerInMap() ;
}
template <typename T>
inline void AttributeHandler<T>::operator=(const AttributeHandler<T>& ta)
{
this->m_map = ta.m_map ;
if(valid)
unregisterFromMap() ;
m_map = ta.m_map ;
m_attrib = ta.m_attrib ;
this->m_map->attributeHandlers.insert(std::pair<AttributeMultiVectorGen*, AttributeHandlerGen*>(m_attrib, this)) ;
valid = ta.valid ;
if(valid)
registerInMap() ;
}
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") ;
if(valid)
unregisterFromMap() ;
}
template <typename T>
......@@ -92,23 +118,15 @@ const std::string& AttributeHandler<T>::name() const
return m_attrib->getName() ;
}
template <typename T>
bool AttributeHandler<T>::isValid() const
{
return !(this->m_map == NULL ||
m_attrib == NULL ||
m_attrib->getIndex() == AttributeContainer::UNKNOWN) ;
}
template <typename T>
inline T& AttributeHandler<T>::operator[](Dart d)
{
assert(isValid() || !"Invalid AttributeHandler") ;
assert(valid || !"Invalid AttributeHandler") ;
unsigned int orbit = m_attrib->getOrbit() ;
unsigned int a = this->m_map->getEmbedding(orbit, d) ;
unsigned int a = m_map->getEmbedding(orbit, d) ;
if (a == EMBNULL)
a = this->m_map->embedNewCell(orbit, d) ;
a = m_map->embedNewCell(orbit, d) ;
return m_attrib->operator[](a) ;
}
......@@ -116,30 +134,30 @@ inline T& AttributeHandler<T>::operator[](Dart d)
template <typename T>
inline const T& AttributeHandler<T>::operator[](Dart d) const
{
assert(isValid() || !"Invalid AttributeHandler") ;
unsigned int a = this->m_map->getEmbedding(m_attrib->getOrbit(), d) ;
assert(valid || !"Invalid AttributeHandler") ;
unsigned int a = m_map->getEmbedding(m_attrib->getOrbit(), d) ;
return m_attrib->operator[](a) ;
}
template <typename T>
inline T& AttributeHandler<T>::operator[](unsigned int a)
{
assert(isValid() || !"Invalid AttributeHandler") ;
assert(valid || !"Invalid AttributeHandler") ;
return m_attrib->operator[](a) ;
}
template <typename T>
inline const T& AttributeHandler<T>::operator[](unsigned int a) const
{
assert(isValid() || !"Invalid AttributeHandler") ;
assert(valid || !"Invalid AttributeHandler") ;
return m_attrib->operator[](a) ;
}
template <typename T>
inline unsigned int AttributeHandler<T>::insert(const T& elt)
{
assert(isValid() || !"Invalid AttributeHandler") ;
unsigned int idx = this->m_map->getAttributeContainer(m_attrib->getOrbit()).insertLine() ;
assert(valid || !"Invalid AttributeHandler") ;
unsigned int idx = m_map->getAttributeContainer(m_attrib->getOrbit()).insertLine() ;
m_attrib->operator[](idx) = elt ;
return idx ;
}
......@@ -147,8 +165,8 @@ inline unsigned int AttributeHandler<T>::insert(const T& elt)
template <typename T>
inline unsigned int AttributeHandler<T>::newElt()
{
assert(isValid() || !"Invalid AttributeHandler") ;
unsigned int idx = this->m_map->getAttributeContainer(m_attrib->getOrbit()).insertLine() ;
assert(valid || !"Invalid AttributeHandler") ;
unsigned int idx = m_map->getAttributeContainer(m_attrib->getOrbit()).insertLine() ;
return idx ;
}
......@@ -162,22 +180,22 @@ inline void AttributeHandler<T>::setAllValues(T& v)
template <typename T>
inline unsigned int AttributeHandler<T>::begin() const
{
assert(isValid() || !"Invalid AttributeHandler") ;
return this->m_map->getAttributeContainer(m_attrib->getOrbit()).begin() ;
assert(valid || !"Invalid AttributeHandler") ;
return m_map->getAttributeContainer(m_attrib->getOrbit()).begin() ;
}
template <typename T>
inline unsigned int AttributeHandler<T>::end() const
{
assert(isValid() || !"Invalid AttributeHandler") ;
return this->m_map->getAttributeContainer(m_attrib->getOrbit()).end() ;
assert(valid || !"Invalid AttributeHandler") ;
return m_map->getAttributeContainer(m_attrib->getOrbit()).end() ;
}
template <typename T>
inline void AttributeHandler<T>::next(unsigned int& iter) const
{
assert(isValid() || !"Invalid AttributeHandler") ;
this->m_map->getAttributeContainer(m_attrib->getOrbit()).next(iter) ;
assert(valid || !"Invalid AttributeHandler") ;
m_map->getAttributeContainer(m_attrib->getOrbit()).next(iter) ;
}
} //namespace CGoGN
......@@ -55,13 +55,15 @@ public:
AttributeContainer& cellCont = this->m_map->m_attribs[orbit] ;
AttributeMultiVector<T>* amv = cellCont.addAttribute<T>(nameAttr) ;
this->m_attrib = amv ;
this->valid = true ;
this->registerInMap() ;
}
~AutoAttributeHandler()
{
reinterpret_cast<AttribMap*>(this->m_map)->removeAttribute<T>(*this) ;
}
};
} ;
} // namespace CGoGN
......
......@@ -117,6 +117,7 @@ void GenericMap::clear(bool removeAttrib)
{
for(std::multimap<AttributeMultiVectorGen*, AttributeHandlerGen*>::iterator it = attributeHandlers.begin(); it != attributeHandlers.end(); ++it)
(*it).second->setInvalid() ;
attributeHandlers.clear() ;
}
}
......
......@@ -30,6 +30,7 @@ namespace CGoGN
namespace Utils
{
#include "shaderSimpleColor.vert"
#include "shaderSimpleColor.frag"
......@@ -49,7 +50,7 @@ namespace Utils
// "FRAG_OUT_DEF;\n"
// "void main()\n"
// "{\n"
// " gl_FragColor=color;\n"
// " gl_FragColor = color;\n"
// "}";
......
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