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:
......
This diff is collapsed.
......@@ -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 *
****************************************/
......
......@@ -41,6 +41,8 @@ class GMap0 : public AttribMap
protected:
AttributeMultiVector<Dart>* m_beta0 ;
void init() ;
public:
GMap0();
......@@ -48,6 +50,8 @@ public:
virtual unsigned int dimension();
virtual void clear(bool removeAttrib);
/*! @name Basic Topological Operators
* Access and Modification
*************************************************************************/
......
......@@ -27,11 +27,16 @@ namespace CGoGN
/// INLINE FUNCTIONS
inline GMap0::GMap0() : AttribMap()
inline void GMap0::init()
{
m_beta0 = addRelation("beta0") ;
}
inline GMap0::GMap0() : AttribMap()
{
init() ;
}
inline std::string GMap0::mapTypeName()
{
return "GMap0";
......@@ -42,6 +47,12 @@ inline unsigned int GMap0::dimension()
return 0;
}
inline void GMap0::clear(bool removeAttrib)
{
AttribMap::clear(removeAttrib) ;
init() ;
}
/*! @name Basic Topological Operators
* Access and Modification
*************************************************************************/
......
......@@ -38,6 +38,8 @@ class GMap1 : public GMap0
protected:
AttributeMultiVector<Dart>* m_beta1 ;
void init() ;
public:
GMap1();
......@@ -45,6 +47,8 @@ public:
virtual unsigned int dimension();
virtual void clear(bool removeAttrib);
virtual int getDartsPerTriangle();
/*! @name Basic Topological Operators
......
......@@ -25,11 +25,16 @@
namespace CGoGN
{
inline GMap1::GMap1() : GMap0()
inline void GMap1::init()
{
m_beta1 = addRelation("beta1") ;
}
inline GMap1::GMap1() : GMap0()
{
init() ;
}
inline std::string GMap1::mapTypeName()
{
return "GMap1";
......@@ -40,6 +45,12 @@ inline unsigned int GMap1::dimension()
return 1;
}
inline void GMap1::clear(bool removeAttrib)
{
GMap0::clear(removeAttrib) ;
init() ;
}
inline int GMap1::getDartsPerTriangle()
{
return 6 ;
......
......@@ -38,6 +38,8 @@ class GMap2 : public GMap1
protected:
AttributeMultiVector<Dart>* m_beta2 ;
void init() ;
public:
GMap2();
......@@ -45,6 +47,8 @@ public:
virtual unsigned int dimension();
virtual void clear(bool removeAttrib);
virtual int getDartsPerTriangle();
/*! @name Basic Topological Operators
......
......@@ -25,11 +25,16 @@
namespace CGoGN
{
inline GMap2::GMap2() : GMap1()
inline void GMap2::init()
{
m_beta2 = addRelation("beta2") ;
}
inline GMap2::GMap2() : GMap1()
{
init() ;
}
inline std::string GMap2::mapTypeName()
{
return "GMap2";
......@@ -40,6 +45,12 @@ inline unsigned int GMap2::dimension()
return 2;
}
inline void GMap2::clear(bool removeAttrib)
{
GMap1::clear(removeAttrib) ;
init() ;
}
inline int GMap2::getDartsPerTriangle()
{
return 6;
......
......@@ -38,6 +38,8 @@ class GMap3 : public GMap2
protected:
AttributeMultiVector<Dart>* m_beta3 ;
void init() ;
public:
GMap3();
......@@ -45,6 +47,8 @@ public:
virtual unsigned int dimension();
virtual void clear(bool removeAttrib);
/*! @name Basic Topological Operators
* Access and Modification
*************************************************************************/
......
......@@ -25,10 +25,14 @@
namespace CGoGN
{
inline void GMap3::init()
{
m_beta3 = addRelation("beta3") ;
}
inline GMap3::GMap3() : GMap2()
{
m_beta3 = addRelation("beta3") ;
init() ;
}
inline std::string GMap3::mapTypeName()
......@@ -41,6 +45,11 @@ inline unsigned int GMap3::dimension()
return 3;
}
inline void GMap3::clear(bool removeAttrib)
{
GMap2::clear(removeAttrib) ;
init() ;
}
/*! @name Basic Topological Operators
* Access and Modification
......
......@@ -36,7 +36,7 @@ namespace CGoGN
* - A dual 1-map is made of darts linked by the phi1 permutation.
* - In this class darts are interpreted as oriented edges.
* - The phi1 relation defines cycles of darts or (oriented) faces.
* - Faces may have abitrary size.
* - Faces may have arbitrary size.
* - Faces with only one edge (sometime called loops) are accepted.
* - Degenerated faces with only two edges are accepted.
* @param DART the type of dart used in the class
......@@ -47,6 +47,8 @@ protected:
AttributeMultiVector<Dart>* m_phi1 ;
AttributeMultiVector<Dart>* m_phi_1 ;
void init() ;
public:
Map1();
......@@ -54,6 +56,8 @@ public:
virtual unsigned int dimension();
virtual void clear(bool removeAttrib);
/*! @name Basic Topological Operators
* Access and Modification
*************************************************************************/
......
......@@ -27,20 +27,31 @@ namespace CGoGN
/// INLINE FUNCTIONS
inline Map1::Map1() : AttribMap()
inline void Map1::init()
{
m_phi1 = addRelation("phi1") ;
m_phi_1 = addRelation("phi_1") ;
}
inline Map1::Map1() : AttribMap()
{
init() ;
}
inline std::string Map1::mapTypeName()
{
return "Map1";
return "Map1" ;
}
inline unsigned int Map1::dimension()
{
return 1;
return 1 ;
}
inline void Map1::clear(bool removeAttrib)
{
AttribMap::clear(removeAttrib) ;
init() ;
}
/*! @name Basic Topological Operators
......
......@@ -50,6 +50,8 @@ class Map2 : public Map1
protected:
AttributeMultiVector<Dart>* m_phi2 ;
void init() ;
public:
typedef Map1 ParentMap;
......@@ -59,6 +61,8 @@ public:
virtual unsigned int dimension();
virtual void clear(bool removeAttrib);
/*! @name Basic Topological Operators
* Access and Modification
*************************************************************************/
......
......@@ -27,11 +27,16 @@ namespace CGoGN
/// INLINE FUNCTIONS
inline Map2::Map2() : Map1()
inline void Map2::init()
{
m_phi2 = addRelation("phi2") ;
}
inline Map2::Map2() : Map1()
{
init() ;
}
inline std::string Map2::mapTypeName()
{
return "Map2" ;
......@@ -42,6 +47,12 @@ inline unsigned int Map2::dimension()
return 2 ;
}
inline void Map2::clear(bool removeAttrib)
{
Map1::clear(removeAttrib) ;
init() ;
}
/*! @name Basic Topological Operators
* Access and Modification
*************************************************************************/
......
......@@ -52,6 +52,8 @@ class Map3 : public Map2
protected:
AttributeMultiVector<Dart>* m_phi3 ;
void init() ;
public:
typedef Map2 ParentMap;
......@@ -61,6 +63,8 @@ public:
virtual unsigned int dimension();
virtual void clear(bool removeAttrib);
/*! @name Basic Topological Operators
* Access and Modification
*************************************************************************/
......
......@@ -32,11 +32,16 @@ namespace CGoGN
/// INLINE FUNCTIONS
inline Map3::Map3() : Map2()
inline void Map3::init()
{
m_phi3 = addRelation("phi3") ;
}
inline Map3::Map3() : Map2()
{
init() ;
}
inline std::string Map3::mapTypeName()
{