Commit b7003005 authored by Pierre Kraemer's avatar Pierre Kraemer

add clear function to reset the map

parent 69cbf02a
...@@ -175,6 +175,8 @@ void Viewer::cb_Open() ...@@ -175,6 +175,8 @@ void Viewer::cb_Open()
void Viewer::importMesh(std::string& filename) void Viewer::importMesh(std::string& filename)
{ {
myMap.clear(true) ;
std::vector<std::string> attrNames ; std::vector<std::string> attrNames ;
if(!Algo::Import::importMesh<PFP>(myMap, filename.c_str(), attrNames)) if(!Algo::Import::importMesh<PFP>(myMap, filename.c_str(), attrNames))
{ {
...@@ -191,7 +193,7 @@ void Viewer::importMesh(std::string& filename) ...@@ -191,7 +193,7 @@ 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") ;
......
...@@ -63,7 +63,10 @@ AttributeMultiVector<T>* AttributeContainer::addAttribute(const std::string& att ...@@ -63,7 +63,10 @@ AttributeMultiVector<T>* AttributeContainer::addAttribute(const std::string& att
{ {
index = getAttributeIndex(attribName) ; index = getAttributeIndex(attribName) ;
if (index != UNKNOWN) if (index != UNKNOWN)
{
std::cout << "attribute " << attribName << " already found.." << std::endl ;
return NULL ; return NULL ;
}
} }
// create the new attribute // create the new attribute
......
...@@ -33,14 +33,19 @@ namespace CGoGN ...@@ -33,14 +33,19 @@ namespace CGoGN
class AttribMap : public GenericMap class AttribMap : public GenericMap
{ {
private:
friend class CellMarkerGen ; friend class CellMarkerGen ;
template<typename T> friend class AutoAttributeHandler ; template<typename T> friend class AutoAttributeHandler ;
void init() ;
public: public:
static const unsigned int UNKNOWN_ATTRIB = AttributeContainer::UNKNOWN ; static const unsigned int UNKNOWN_ATTRIB = AttributeContainer::UNKNOWN ;
AttribMap(); AttribMap() ;
virtual void clear(bool removeAttrib) ;
/**************************************** /****************************************
* ATTRIBUTES MANAGEMENT * * ATTRIBUTES MANAGEMENT *
...@@ -50,10 +55,10 @@ public: ...@@ -50,10 +55,10 @@ public:
* Create an attribute for a given orbit * Create an attribute for a given orbit
* @param orbit * @param orbit
* @param nameAttr attribute name * @param nameAttr attribute name
* @return a "code orbit" : 8 bits for orbit & 24 bits for index of attribute in container * @return an AttributeHandler
*/ */
template <typename T> template <typename T>
AttributeHandler<T> addAttribute(unsigned int orbit, const std::string& nameAttr); AttributeHandler<T> addAttribute(unsigned int orbit, const std::string& nameAttr) ;
/** /**
* remove an attribute * remove an attribute
...@@ -61,16 +66,16 @@ public: ...@@ -61,16 +66,16 @@ public:
* @return true if remove succeed else false * @return true if remove succeed else false
*/ */
template <typename T> template <typename T>
bool removeAttribute(AttributeHandler<T>& attr); bool removeAttribute(AttributeHandler<T>& attr) ;
/** /**
* search an attribute for a given orbit * search an attribute for a given orbit
* @param orbit * @param orbit
* @param nameAttr attribute name * @param nameAttr attribute name
* @return id of attribute : 8 bits for orbit & 24 bits for index of attribute in container * @return an AttributeHandler
*/ */
template <typename T> template <typename T>
AttributeHandler<T> getAttribute(unsigned int orbit, const std::string& nameAttr); AttributeHandler<T> getAttribute(unsigned int orbit, const std::string& nameAttr) ;
/** /**
* swap the content of two attributes (efficient, only swap pointers) * swap the content of two attributes (efficient, only swap pointers)
...@@ -98,7 +103,7 @@ protected: ...@@ -98,7 +103,7 @@ protected:
* Create the dart attribute to store the embedding of this orbit (for internal use only) * Create the dart attribute to store the embedding of this orbit (for internal use only)
* Also adds a Marker attribute to the container * Also adds a Marker attribute to the container
*/ */
void addEmbedding(unsigned int orbit); void addEmbedding(unsigned int orbit) ;
/**************************************** /****************************************
* TOPOLOGICAL ATTRIBUTES MANAGEMENT * * TOPOLOGICAL ATTRIBUTES MANAGEMENT *
...@@ -108,7 +113,7 @@ protected: ...@@ -108,7 +113,7 @@ protected:
* Add a toological relation in the map * Add a toological relation in the map
* @param name name of relation * @param name name of relation
*/ */
AttributeMultiVector<Dart>* addRelation(const std::string& name); AttributeMultiVector<Dart>* addRelation(const std::string& name) ;
public: public:
/**************************************** /****************************************
......
...@@ -33,6 +33,22 @@ ...@@ -33,6 +33,22 @@
namespace CGoGN namespace CGoGN
{ {
class AttributeHandlerGen
{
protected:
// the map that contains the linked attribute
GenericMap* m_map;
public:
AttributeHandlerGen(GenericMap* m) : m_map(m)
{}
GenericMap* map() const
{
return m_map ;
}
};
/** /**
* Class that create an access-table to an existing attribute * Class that create an access-table to an existing attribute
* Main available operations are: * Main available operations are:
...@@ -41,13 +57,10 @@ namespace CGoGN ...@@ -41,13 +57,10 @@ namespace CGoGN
* - begin / end / next to manage indexing * - begin / end / next to manage indexing
*/ */
template <typename T> template <typename T>
class AttributeHandler class AttributeHandler : public AttributeHandlerGen
{ {
protected: protected:
// we need the map to use dart as index // the multi-vector that contains attribute data
GenericMap* m_map;
// access to the data
AttributeMultiVector<T>* m_attrib; AttributeMultiVector<T>* m_attrib;
public: public:
...@@ -60,6 +73,10 @@ public: ...@@ -60,6 +73,10 @@ 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() ; AttributeHandler() ;
/** /**
...@@ -79,11 +96,6 @@ public: ...@@ -79,11 +96,6 @@ public:
*/ */
virtual ~AttributeHandler() ; virtual ~AttributeHandler() ;
/**
* get associated map
*/
GenericMap* map() const ;
/** /**
* get attribute data vector * get attribute data vector
*/ */
...@@ -143,7 +155,7 @@ public: ...@@ -143,7 +155,7 @@ public:
unsigned int newElt() ; unsigned int newElt() ;
/** /**
* * initialize all the lines of the attribute with the given value
*/ */
void setAllValues(T& v) ; void setAllValues(T& v) ;
......
...@@ -26,24 +26,24 @@ namespace CGoGN ...@@ -26,24 +26,24 @@ namespace CGoGN
{ {
template <typename T> template <typename T>
AttributeHandler<T>::AttributeHandler(GenericMap* m, AttributeMultiVector<T>* amv): AttributeHandler<T>::AttributeHandler(GenericMap* m, AttributeMultiVector<T>* amv) :
m_map(m), m_attrib(amv) AttributeHandlerGen(m), m_attrib(amv)
{} {}
template <typename T> template <typename T>
AttributeHandler<T>::AttributeHandler(): AttributeHandler<T>::AttributeHandler() :
m_map(NULL), m_attrib(NULL) AttributeHandlerGen(NULL), m_attrib(NULL)
{} {}
template <typename T> template <typename T>
AttributeHandler<T>::AttributeHandler(const AttributeHandler<T>& ta): AttributeHandler<T>::AttributeHandler(const AttributeHandler<T>& ta) :
m_map(ta.m_map), m_attrib(ta.m_attrib) AttributeHandlerGen(ta.m_map), m_attrib(ta.m_attrib)
{} {}
template <typename T> template <typename T>
inline void AttributeHandler<T>::operator=(const AttributeHandler<T>& ta) inline void AttributeHandler<T>::operator=(const AttributeHandler<T>& ta)
{ {
m_map = ta.m_map ; this->m_map = ta.m_map ;
m_attrib = ta.m_attrib ; m_attrib = ta.m_attrib ;
} }
...@@ -51,12 +51,6 @@ template <typename T> ...@@ -51,12 +51,6 @@ template <typename T>
AttributeHandler<T>::~AttributeHandler() AttributeHandler<T>::~AttributeHandler()
{} {}
template <typename T>
GenericMap* AttributeHandler<T>::map() const
{
return m_map ;
}
template <typename T> template <typename T>
AttributeMultiVector<T>* AttributeHandler<T>::getDataVector() const AttributeMultiVector<T>* AttributeHandler<T>::getDataVector() const
{ {
...@@ -84,7 +78,7 @@ const std::string& AttributeHandler<T>::name() const ...@@ -84,7 +78,7 @@ const std::string& AttributeHandler<T>::name() const
template <typename T> template <typename T>
bool AttributeHandler<T>::isValid() const bool AttributeHandler<T>::isValid() const
{ {
return !(m_map == NULL || return !(this->m_map == NULL ||
m_attrib == NULL || m_attrib == NULL ||
m_attrib->getIndex() == AttributeContainer::UNKNOWN) ; m_attrib->getIndex() == AttributeContainer::UNKNOWN) ;
} }
...@@ -94,19 +88,19 @@ inline T& AttributeHandler<T>::operator[](Dart d) ...@@ -94,19 +88,19 @@ inline T& AttributeHandler<T>::operator[](Dart d)
{ {
assert(isValid() || !"Invalid AttributeHandler") ; assert(isValid() || !"Invalid AttributeHandler") ;
unsigned int orbit = m_attrib->getOrbit() ; unsigned int orbit = m_attrib->getOrbit() ;
unsigned int a = m_map->getEmbedding(orbit, d) ; unsigned int a = this->m_map->getEmbedding(orbit, d) ;
if (a == EMBNULL) if (a == EMBNULL)
a = m_map->embedNewCell(orbit, d); a = this->m_map->embedNewCell(orbit, d) ;
return m_attrib->operator[](a); return m_attrib->operator[](a) ;
} }
template <typename T> template <typename T>
inline const T& AttributeHandler<T>::operator[](Dart d) const inline const T& AttributeHandler<T>::operator[](Dart d) const
{ {
assert(isValid() || !"Invalid AttributeHandler") ; assert(isValid() || !"Invalid AttributeHandler") ;
unsigned int a = m_map->getEmbedding(m_attrib->getOrbit(), d) ; unsigned int a = this->m_map->getEmbedding(m_attrib->getOrbit(), d) ;
return m_attrib->operator[](a) ; return m_attrib->operator[](a) ;
} }
...@@ -114,31 +108,31 @@ template <typename T> ...@@ -114,31 +108,31 @@ template <typename T>
inline T& AttributeHandler<T>::operator[](unsigned int a) inline T& AttributeHandler<T>::operator[](unsigned int a)
{ {
assert(isValid() || !"Invalid AttributeHandler") ; assert(isValid() || !"Invalid AttributeHandler") ;
return m_attrib->operator[](a); return m_attrib->operator[](a) ;
} }
template <typename T> template <typename T>
inline const T& AttributeHandler<T>::operator[](unsigned int a) const inline const T& AttributeHandler<T>::operator[](unsigned int a) const
{ {
assert(isValid() || !"Invalid AttributeHandler") ; assert(isValid() || !"Invalid AttributeHandler") ;
return m_attrib->operator[](a); return m_attrib->operator[](a) ;
} }
template <typename T> template <typename T>
inline unsigned int AttributeHandler<T>::insert(const T& elt) inline unsigned int AttributeHandler<T>::insert(const T& elt)
{ {
assert(isValid() || !"Invalid AttributeHandler") ; assert(isValid() || !"Invalid AttributeHandler") ;
unsigned int idx = m_map->getAttributeContainer(m_attrib->getOrbit()).insertLine(); unsigned int idx = this->m_map->getAttributeContainer(m_attrib->getOrbit()).insertLine() ;
m_attrib->operator[](idx) = elt; m_attrib->operator[](idx) = elt ;
return idx; return idx ;
} }
template <typename T> template <typename T>
inline unsigned int AttributeHandler<T>::newElt() inline unsigned int AttributeHandler<T>::newElt()
{ {
assert(isValid() || !"Invalid AttributeHandler") ; assert(isValid() || !"Invalid AttributeHandler") ;
unsigned int idx = m_map->getAttributeContainer(m_attrib->getOrbit()).insertLine(); unsigned int idx = this->m_map->getAttributeContainer(m_attrib->getOrbit()).insertLine() ;
return idx; return idx ;
} }
template <typename T> template <typename T>
...@@ -152,21 +146,21 @@ template <typename T> ...@@ -152,21 +146,21 @@ template <typename T>
inline unsigned int AttributeHandler<T>::begin() const inline unsigned int AttributeHandler<T>::begin() const
{ {
assert(isValid() || !"Invalid AttributeHandler") ; assert(isValid() || !"Invalid AttributeHandler") ;
return m_map->getAttributeContainer(m_attrib->getOrbit()).begin(); return this->m_map->getAttributeContainer(m_attrib->getOrbit()).begin() ;
} }
template <typename T> template <typename T>
inline unsigned int AttributeHandler<T>::end() const inline unsigned int AttributeHandler<T>::end() const
{ {
assert(isValid() || !"Invalid AttributeHandler") ; assert(isValid() || !"Invalid AttributeHandler") ;
return m_map->getAttributeContainer(m_attrib->getOrbit()).end(); return this->m_map->getAttributeContainer(m_attrib->getOrbit()).end() ;
} }
template <typename T> template <typename T>
inline void AttributeHandler<T>::next(unsigned int& iter) const inline void AttributeHandler<T>::next(unsigned int& iter) const
{ {
assert(isValid() || !"Invalid AttributeHandler") ; assert(isValid() || !"Invalid AttributeHandler") ;
m_map->getAttributeContainer(m_attrib->getOrbit()).next(iter); this->m_map->getAttributeContainer(m_attrib->getOrbit()).next(iter) ;
} }
} //namespace CGoGN } //namespace CGoGN
...@@ -49,19 +49,19 @@ protected: ...@@ -49,19 +49,19 @@ protected:
public: public:
/** /**
* constructor * constructor
* @param map the map on which we work (not stored use to get table of markers and new marker. * @param map the map on which we work
* @param cell the type of cell we want to mark VERTEX, EDGE,... * @param cell the type of cell we want to mark VERTEX, EDGE,...
*/ */
CellMarkerGen(AttribMap& map, unsigned int cell, unsigned int thread = 0) : m_map(map), m_cell(cell), m_thread(thread) CellMarkerGen(AttribMap& map, unsigned int cell, unsigned int thread = 0) : m_map(map), m_cell(cell), m_thread(thread)
{ {
if(!map.isOrbitEmbedded(cell)) if(!map.isOrbitEmbedded(cell))
map.addEmbedding(cell) ; map.addEmbedding(cell) ;
m_mark = map.getNewMark(cell, thread) ; m_mark = m_map.m_marksets[m_cell][m_thread].getNewMark() ;
} }
virtual ~CellMarkerGen() virtual ~CellMarkerGen()
{ {
m_map.releaseMark(m_mark, m_cell, m_thread); m_map.m_marksets[m_cell][m_thread].releaseMark(m_mark) ;
} }
protected: protected:
......
...@@ -98,9 +98,9 @@ public: ...@@ -98,9 +98,9 @@ public:
class DartMarkerGen class DartMarkerGen
{ {
protected: protected:
Mark m_mark; GenericMap& m_map ;
GenericMap& m_map; unsigned int m_thread ;
unsigned int m_thread; Mark m_mark ;
public: public:
/** /**
...@@ -109,17 +109,17 @@ public: ...@@ -109,17 +109,17 @@ public:
*/ */
DartMarkerGen(GenericMap& map): m_map(map), m_thread(0) DartMarkerGen(GenericMap& map): m_map(map), m_thread(0)
{ {
m_mark = map.getNewMark(DART); m_mark = m_map.m_marksets[DART][m_thread].getNewMark() ;
} }
DartMarkerGen(GenericMap& map, unsigned int thread): m_map(map), m_thread(thread) DartMarkerGen(GenericMap& map, unsigned int thread): m_map(map), m_thread(thread)
{ {
m_mark = map.getNewMark(DART, thread); m_mark = m_map.m_marksets[DART][m_thread].getNewMark() ;
} }
virtual ~DartMarkerGen() virtual ~DartMarkerGen()
{ {
m_map.releaseMark(m_mark, DART, m_thread); m_map.m_marksets[DART][m_thread].releaseMark(m_mark) ;
} }
protected: protected:
......
This diff is collapsed.
...@@ -199,22 +199,6 @@ inline void GenericMap::swapEmbeddingContainers(unsigned int orbit1, unsigned in ...@@ -199,22 +199,6 @@ inline void GenericMap::swapEmbeddingContainers(unsigned int orbit1, unsigned in
} }
} }
/****************************************
* MARKERS MANAGEMENT *
****************************************/
inline Mark GenericMap::getNewMark(unsigned int cell, unsigned int thread)
{
assert(isOrbitEmbedded(cell) || !"Try to get a marker on non embedded cell! ") ;
return m_marksets[cell][thread].getNewMark() ;
}
inline void GenericMap::releaseMark(Mark m, unsigned int cell, unsigned int thread)
{
assert(isOrbitEmbedded(cell) || !"Try to release a marker on non embedded cell! ") ;
m_marksets[cell][thread].releaseMark(m) ;
}
/**************************************** /****************************************
* DARTS TRAVERSALS * * DARTS TRAVERSALS *
****************************************/ ****************************************/
......
...@@ -41,6 +41,8 @@ class GMap0 : public AttribMap ...@@ -41,6 +41,8 @@ class GMap0 : public AttribMap
protected: protected:
AttributeMultiVector<Dart>* m_beta0 ; AttributeMultiVector<Dart>* m_beta0 ;
void init() ;
public: public:
GMap0(); GMap0();
...@@ -48,6 +50,8 @@ public: ...@@ -48,6 +50,8 @@ public:
virtual unsigned int dimension(); virtual unsigned int dimension();
virtual void clear(bool removeAttrib);
/*! @name Basic Topological Operators /*! @name Basic Topological Operators
* Access and Modification * Access and Modification
*************************************************************************/ *************************************************************************/
......
...@@ -27,11 +27,16 @@ namespace CGoGN ...@@ -27,11 +27,16 @@ namespace CGoGN
/// INLINE FUNCTIONS /// INLINE FUNCTIONS
inline GMap0::GMap0() : AttribMap() inline void GMap0::init()
{ {
m_beta0 = addRelation("beta0") ; m_beta0 = addRelation("beta0") ;
} }
inline GMap0::GMap0() : AttribMap()
{
init() ;
}
inline std::string GMap0::mapTypeName() inline std::string GMap0::mapTypeName()
{ {
return "GMap0"; return "GMap0";
...@@ -42,6 +47,12 @@ inline unsigned int GMap0::dimension() ...@@ -42,6 +47,12 @@ inline unsigned int GMap0::dimension()
return 0; return 0;
} }
inline void GMap0::clear(bool