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()
void Viewer::importMesh(std::string& filename)
{
myMap.clear(true) ;
std::vector<std::string> attrNames ;
if(!Algo::Import::importMesh<PFP>(myMap, filename.c_str(), attrNames))
{
......@@ -191,7 +193,7 @@ 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") ;
......
......@@ -63,7 +63,10 @@ AttributeMultiVector<T>* AttributeContainer::addAttribute(const std::string& att
{
index = getAttributeIndex(attribName) ;
if (index != UNKNOWN)
{
std::cout << "attribute " << attribName << " already found.." << std::endl ;
return NULL ;
}
}
// create the new attribute
......
......@@ -33,14 +33,19 @@ namespace CGoGN
class AttribMap : public GenericMap
{
private:
friend class CellMarkerGen ;
template<typename T> friend class AutoAttributeHandler ;
void init() ;
public:
static const unsigned int UNKNOWN_ATTRIB = AttributeContainer::UNKNOWN ;
AttribMap();
AttribMap() ;
virtual void clear(bool removeAttrib) ;
/****************************************
* ATTRIBUTES MANAGEMENT *
......@@ -50,10 +55,10 @@ public:
* Create an attribute for a given orbit
* @param orbit
* @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>
AttributeHandler<T> addAttribute(unsigned int orbit, const std::string& nameAttr);
AttributeHandler<T> addAttribute(unsigned int orbit, const std::string& nameAttr) ;
/**
* remove an attribute
......@@ -61,16 +66,16 @@ public:
* @return true if remove succeed else false
*/
template <typename T>
bool removeAttribute(AttributeHandler<T>& attr);
bool removeAttribute(AttributeHandler<T>& attr) ;
/**
* search an attribute for a given orbit
* @param orbit
* @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>
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)
......@@ -98,7 +103,7 @@ protected:
* Create the dart attribute to store the embedding of this orbit (for internal use only)
* Also adds a Marker attribute to the container
*/
void addEmbedding(unsigned int orbit);
void addEmbedding(unsigned int orbit) ;
/****************************************
* TOPOLOGICAL ATTRIBUTES MANAGEMENT *
......@@ -108,7 +113,7 @@ protected:
* Add a toological relation in the map
* @param name name of relation
*/
AttributeMultiVector<Dart>* addRelation(const std::string& name);
AttributeMultiVector<Dart>* addRelation(const std::string& name) ;
public:
/****************************************
......
......@@ -33,6 +33,22 @@
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
* Main available operations are:
......@@ -41,13 +57,10 @@ namespace CGoGN
* - begin / end / next to manage indexing
*/
template <typename T>
class AttributeHandler
class AttributeHandler : public AttributeHandlerGen
{
protected:
// we need the map to use dart as index
GenericMap* m_map;
// access to the data
// the multi-vector that contains attribute data
AttributeMultiVector<T>* m_attrib;
public:
......@@ -60,6 +73,10 @@ public:
*/
AttributeHandler(GenericMap* m, AttributeMultiVector<T>* amv) ;
/**
* Default constructor
* Constructs a non-valid AttributeHandler (i.e. not linked to any attribute)
*/
AttributeHandler() ;
/**
......@@ -79,11 +96,6 @@ public:
*/
virtual ~AttributeHandler() ;
/**
* get associated map
*/
GenericMap* map() const ;
/**
* get attribute data vector
*/
......@@ -143,7 +155,7 @@ public:
unsigned int newElt() ;
/**
*
* initialize all the lines of the attribute with the given value
*/
void setAllValues(T& v) ;
......
......@@ -26,24 +26,24 @@ namespace CGoGN
{
template <typename T>
AttributeHandler<T>::AttributeHandler(GenericMap* m, AttributeMultiVector<T>* amv):
m_map(m), m_attrib(amv)
AttributeHandler<T>::AttributeHandler(GenericMap* m, AttributeMultiVector<T>* amv) :
AttributeHandlerGen(m), m_attrib(amv)
{}
template <typename T>
AttributeHandler<T>::AttributeHandler():
m_map(NULL), m_attrib(NULL)
AttributeHandler<T>::AttributeHandler() :
AttributeHandlerGen(NULL), m_attrib(NULL)
{}
template <typename T>
AttributeHandler<T>::AttributeHandler(const AttributeHandler<T>& ta):
m_map(ta.m_map), m_attrib(ta.m_attrib)
AttributeHandler<T>::AttributeHandler(const AttributeHandler<T>& ta) :
AttributeHandlerGen(ta.m_map), m_attrib(ta.m_attrib)
{}
template <typename T>
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 ;
}
......@@ -51,12 +51,6 @@ template <typename T>
AttributeHandler<T>::~AttributeHandler()
{}
template <typename T>
GenericMap* AttributeHandler<T>::map() const
{
return m_map ;
}
template <typename T>
AttributeMultiVector<T>* AttributeHandler<T>::getDataVector() const
{
......@@ -84,7 +78,7 @@ const std::string& AttributeHandler<T>::name() const
template <typename T>
bool AttributeHandler<T>::isValid() const
{
return !(m_map == NULL ||
return !(this->m_map == NULL ||
m_attrib == NULL ||
m_attrib->getIndex() == AttributeContainer::UNKNOWN) ;
}
......@@ -94,19 +88,19 @@ inline T& AttributeHandler<T>::operator[](Dart d)
{
assert(isValid() || !"Invalid AttributeHandler") ;
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)
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>
inline const T& AttributeHandler<T>::operator[](Dart d) const
{
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) ;
}
......@@ -114,31 +108,31 @@ template <typename T>
inline T& AttributeHandler<T>::operator[](unsigned int a)
{
assert(isValid() || !"Invalid AttributeHandler") ;
return m_attrib->operator[](a);
return m_attrib->operator[](a) ;
}
template <typename T>
inline const T& AttributeHandler<T>::operator[](unsigned int a) const
{
assert(isValid() || !"Invalid AttributeHandler") ;
return m_attrib->operator[](a);
return m_attrib->operator[](a) ;
}
template <typename T>
inline unsigned int AttributeHandler<T>::insert(const T& elt)
{
assert(isValid() || !"Invalid AttributeHandler") ;
unsigned int idx = m_map->getAttributeContainer(m_attrib->getOrbit()).insertLine();
m_attrib->operator[](idx) = elt;
return idx;
unsigned int idx = this->m_map->getAttributeContainer(m_attrib->getOrbit()).insertLine() ;
m_attrib->operator[](idx) = elt ;
return idx ;
}
template <typename T>
inline unsigned int AttributeHandler<T>::newElt()
{
assert(isValid() || !"Invalid AttributeHandler") ;
unsigned int idx = m_map->getAttributeContainer(m_attrib->getOrbit()).insertLine();
return idx;
unsigned int idx = this->m_map->getAttributeContainer(m_attrib->getOrbit()).insertLine() ;
return idx ;
}
template <typename T>
......@@ -152,21 +146,21 @@ template <typename T>
inline unsigned int AttributeHandler<T>::begin() const
{
assert(isValid() || !"Invalid AttributeHandler") ;
return m_map->getAttributeContainer(m_attrib->getOrbit()).begin();
return this->m_map->getAttributeContainer(m_attrib->getOrbit()).begin() ;
}
template <typename T>
inline unsigned int AttributeHandler<T>::end() const
{
assert(isValid() || !"Invalid AttributeHandler") ;
return m_map->getAttributeContainer(m_attrib->getOrbit()).end();
return this->m_map->getAttributeContainer(m_attrib->getOrbit()).end() ;
}
template <typename T>
inline void AttributeHandler<T>::next(unsigned int& iter) const
{
assert(isValid() || !"Invalid AttributeHandler") ;
m_map->getAttributeContainer(m_attrib->getOrbit()).next(iter);
this->m_map->getAttributeContainer(m_attrib->getOrbit()).next(iter) ;
}
} //namespace CGoGN
......@@ -49,19 +49,19 @@ protected:
public:
/**
* 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,...
*/
CellMarkerGen(AttribMap& map, unsigned int cell, unsigned int thread = 0) : m_map(map), m_cell(cell), m_thread(thread)
{
if(!map.isOrbitEmbedded(cell))
map.addEmbedding(cell) ;
m_mark = map.getNewMark(cell, thread) ;
m_mark = m_map.m_marksets[m_cell][m_thread].getNewMark() ;
}
virtual ~CellMarkerGen()
{
m_map.releaseMark(m_mark, m_cell, m_thread);
m_map.m_marksets[m_cell][m_thread].releaseMark(m_mark) ;
}
protected:
......
......@@ -98,9 +98,9 @@ public:
class DartMarkerGen
{
protected:
Mark m_mark;
GenericMap& m_map;
unsigned int m_thread;
GenericMap& m_map ;
unsigned int m_thread ;
Mark m_mark ;
public:
/**
......@@ -109,17 +109,17 @@ public:
*/
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)
{
m_mark = map.getNewMark(DART, thread);
m_mark = m_map.m_marksets[DART][m_thread].getNewMark() ;
}
virtual ~DartMarkerGen()
{
m_map.releaseMark(m_mark, DART, m_thread);
m_map.m_marksets[DART][m_thread].releaseMark(m_mark) ;
}
protected:
......
......@@ -71,6 +71,8 @@ public:
virtual void next(Dart& d) = 0;
};
class AttributeHandlerGen ;
class GenericMap : public MapBrowser
{
friend class DartMarkerGen ;
......@@ -99,18 +101,28 @@ protected:
/**
* Direct access to the attributes that store Marks
*/
AttributeMultiVector<Mark>* m_markTables[NB_ORBITS][NB_THREAD];
AttributeMultiVector<Mark>* m_markTables[NB_ORBITS][NB_THREAD] ;
unsigned int m_nbThreads ;
unsigned int m_nbThreads;
// std::multimap<AttributeMultiVectorGen*, AttributeHandlerGen*> attributeHandlers ;
public:
static const unsigned int UNKNOWN_ATTRIB = AttributeContainer::UNKNOWN ;
GenericMap();
GenericMap() ;
~GenericMap();
~GenericMap() ;
virtual std::string mapTypeName() = 0;
virtual std::string mapTypeName() = 0 ;
/**
* Clear the map
* @param removeAttrib
* if false -> data is deleted but all attributes remain (all AttributeHandlers are still valid)
* if true -> data and attributes are deleted (AttributeHandlers are invalid)
*/
virtual void clear(bool removeAttrib) ;
/****************************************
* DARTS MANAGEMENT *
......@@ -119,12 +131,12 @@ protected:
/**
* Add a dart to the map
*/
virtual Dart newDart();
virtual Dart newDart() ;
/**
* Erase a dart of the map
*/
void deleteDart(Dart d);
void deleteDart(Dart d) ;
public:
/**
......@@ -135,7 +147,7 @@ public:
/**
* @return the number of darts in the map
*/
unsigned int getNbDarts();
unsigned int getNbDarts() ;
/****************************************
* EMBEDDING MANAGEMENT *
......@@ -144,29 +156,24 @@ public:
/**
* tell if an orbit is embedded or not
*/
bool isOrbitEmbedded(unsigned int orbit) const;
bool isOrbitEmbedded(unsigned int orbit) const ;
/**
* return the number of embedded orbits (including DART)
*/
unsigned int nbEmbeddings() const;
unsigned int nbEmbeddings() const ;
/**
* get the cell index of the given dimension associated to dart d
* (can go through the whole orbit due to lazy embedding)
* @return EMBNULL if the orbit of d is not attached to any cell
*/
unsigned int getEmbedding(unsigned int orbit, Dart d);
// /**
// * Get the cell index of the given dimension associated to dart d
// */
// unsigned int getDartEmbedding(unsigned int orbit, Dart d);
unsigned int getEmbedding(unsigned int orbit, Dart d) ;
/**
* Set the cell index of the given dimension associated to dart d
*/
void setDartEmbedding(unsigned int orbit, Dart d, unsigned int emb);
void setDartEmbedding(unsigned int orbit, Dart d, unsigned int emb) ;
/**
* Copy the index of the cell associated to a dart over an other dart
......@@ -174,14 +181,14 @@ public:
* @param e the dart to copy (src)
* @param orbit the id of orbit embedding
*/
void copyDartEmbedding(unsigned int orbit, Dart d, Dart e);
void copyDartEmbedding(unsigned int orbit, Dart d, Dart e) ;
/**
* Allocation of some place in attrib table
* @param orbit the orbit of embedding
* @return the index to use as embedding
*/
unsigned int newCell(unsigned int orbit);
unsigned int newCell(unsigned int orbit) ;
/**
* Set the index of the associated cell to all the darts of an orbit
......@@ -189,7 +196,7 @@ public:
* @param d a dart of the topological vertex
* @param em index of attribute to store as embedding
*/
void embedOrbit(unsigned int orbit, Dart d, unsigned int em);
void embedOrbit(unsigned int orbit, Dart d, unsigned int em) ;
/**
* Associate an new embedding to all darts of a vertex
......@@ -197,7 +204,7 @@ public:
* @param d a dart of the topological cell
* @return index of the attribute in table
*/
unsigned int embedNewCell(unsigned int orbit, Dart d);
unsigned int embedNewCell(unsigned int orbit, Dart d) ;
/**
* Copy the cell associated to a dart over an other dart
......@@ -205,7 +212,7 @@ public:
* @param d the dart to overwrite (dest)
* @param e the dart to copy (src)
*/
void copyCell(unsigned int orbit, Dart d, Dart e);
void copyCell(unsigned int orbit, Dart d, Dart e) ;
/**
* Line of attributes i is overwritten with line j
......@@ -213,14 +220,14 @@ public:
* @param i line destination of copy
* @param j line source of copy
*/
void copyCell(unsigned int orbit, unsigned int i, unsigned int j);
void copyCell(unsigned int orbit, unsigned int i, unsigned int j) ;
/**
* Line of attributes i is initialized
* @param orbit attribute orbit to use
* @param i line to init
*/
void initCell(unsigned int orbit, unsigned int i);
void initCell(unsigned int orbit, unsigned int i) ;
/****************************************
* ATTRIBUTES MANAGEMENT *
......@@ -230,24 +237,24 @@ public:
* get the attrib container of a given orbit
* @param orbit the orbit !!! (bilbo the orbit !)
*/
AttributeContainer& getAttributeContainer(unsigned int orbit);
AttributeContainer& getAttributeContainer(unsigned int orbit) ;
/**
* get a multi vector of mark attribute (direct access with [i])
* @param orbit code
*/
AttributeMultiVector<Mark>* getMarkVector(unsigned int orbit, unsigned int thread = 0);
AttributeMultiVector<Mark>* getMarkVector(unsigned int orbit, unsigned int thread = 0) ;
/**
* return a pointer to the Dart attribute vector that store the embedding of the given orbit
* (may be NULL if the orbit is not embedded)
*/
AttributeMultiVector<unsigned int>* getEmbeddingAttributeVector(unsigned int orbit);
AttributeMultiVector<unsigned int>* getEmbeddingAttributeVector(unsigned int orbit) ;
/**
* swap two attribute containers
*/
void swapEmbeddingContainers(unsigned int orbit1, unsigned int orbit2);
void swapEmbeddingContainers(unsigned int orbit1, unsigned int orbit2) ;
/**
* static function for type registration
......@@ -259,25 +266,7 @@ public:
* Traverse the map and embed all orbits of the given dimension with a new cell
* @param realloc if true -> all the orbits are embedded on new cells, if false -> already embedded orbits are not impacted
*/
void initOrbitEmbedding(unsigned int orbit, bool realloc = false);
/****************************************
* MARKERS MANAGEMENT *
****************************************/
protected:
/**
* get a new marker on cell
* \pre the orbit must be already embedded
* @param orbit the orbit of cell to use (xxx_ORBIT)
* @return the marker to use
*/
Mark getNewMark(unsigned int cell, unsigned int thread = 0);
/**
* release a marker of cell.
* @param m the marker to release
*/
void releaseMark(Mark m, unsigned int cell, unsigned int thread = 0);
void initOrbitEmbedding(unsigned int orbit, bool realloc = false) ;
/****************************************
* THREAD MANAGEMENT *
......@@ -288,19 +277,19 @@ public:
* to allow MT
* @param nb thread to add
*/
void addThreadMarker(unsigned int nb);
void addThreadMarker(unsigned int nb) ;
/**
* return allowed threads
* @return the number of threads (including principal)
*/
unsigned int getNbThreadMarkers();
unsigned int getNbThreadMarkers() ;
/**
* Remove some added threads
* @return remaining number of threads (including principal)
*/
void removeThreadMarker(unsigned int nb);
void removeThreadMarker(unsigned int nb) ;
/****************************************
* SAVE & LOAD *
......@@ -312,7 +301,7 @@ public:
* @param name the name
* @ return true if node has the good name
*/
bool chechXmlNode(xmlNodePtr node, const std::string& name);
bool chechXmlNode(xmlNodePtr node, const std::string& name) ;
/**
* update the pointer of embedding vector after loading
......@@ -324,28 +313,28 @@ public:
* @param filename the file name
* @return true if OK
*/
bool saveMapXml(const std::string& filename, bool compress = false);
bool saveMapXml(const std::string& filename, bool compress = false) ;
/**
* Load map from a XML file
* @param filename the file name
* @return true if OK
*/
bool loadMapXml(const std::string& filename, bool compress = false);
bool loadMapXml(const std::string& filename, bool compress = false) ;
/**
* Save map in a binary file
* @param filename the file name
* @return true if OK
*/
bool saveMapBin(const std::string& filename);
bool saveMapBin(const std::string& filename) ;
/**
* Load map from a binary file