Commit 8fb58c43 authored by Sylvain Thery's avatar Sylvain Thery

Merge branch 'master' of cgogn:~cgogn/CGoGN

parents a8449583 7b93a4a0
......@@ -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,6 @@ void Viewer::importMesh(std::string& filename)
normalBaseSize = bb.diagSize() / 100.0f ;
// vertexBaseSize = normalBaseSize /5.0f ;
if(!normal.isValid())
normal = myMap.addAttribute<PFP::VEC3>(VERTEX, "normal") ;
......
......@@ -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") ;
......
......@@ -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,18 @@ 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 +54,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 +65,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 +102,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 +112,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:
/****************************************
......
......@@ -38,7 +38,16 @@ template <typename T>
inline bool AttribMap::removeAttribute(AttributeHandler<T>& attr)
{
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() ;
attributeHandlers.erase(bounds.first, bounds.second) ;
return true ;
}
return false ;
}
template <typename T>
......
......@@ -33,6 +33,38 @@
namespace CGoGN
{
class AttributeHandlerGen
{
protected:
friend class GenericMap ;
friend class AttribMap ;
// the map that contains the linked attribute
GenericMap* m_map ;
// boolean that states the validity of the handler
bool valid ;
public:
AttributeHandlerGen(GenericMap* m, bool v) : m_map(m), valid(v)
{}
GenericMap* map() const
{
return m_map ;
}
bool isValid() const
{
return valid ;
}
protected:
void setInvalid()
{
valid = false ;
}
} ;
/**
* Class that create an access-table to an existing attribute
* Main available operations are:
......@@ -41,18 +73,24 @@ 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;
void registerInMap() ;
void unregisterFromMap() ;
public:
typedef T DATA_TYPE ;
/**
* Default constructor
* Constructs a non-valid AttributeHandler (i.e. not linked to any attribute)
*/
AttributeHandler() ;
/**
* Constructor
* @param m the map which belong attribute
......@@ -60,8 +98,6 @@ public:
*/
AttributeHandler(GenericMap* m, AttributeMultiVector<T>* amv) ;
AttributeHandler() ;
/**
* Copy constructor
* @param ta the table attribute
......@@ -79,11 +115,6 @@ public:
*/
virtual ~AttributeHandler() ;
/**
* get associated map
*/
GenericMap* map() const ;
/**
* get attribute data vector
*/
......@@ -104,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
*/
......@@ -143,7 +166,7 @@ public:
unsigned int newElt() ;
/**
*
* initialize all the lines of the attribute with the given value
*/
void setAllValues(T& v) ;
......
......@@ -26,35 +26,72 @@ namespace CGoGN
{
template <typename T>
AttributeHandler<T>::AttributeHandler(GenericMap* m, AttributeMultiVector<T>* amv):
m_map(m), m_attrib(amv)
{}
void AttributeHandler<T>::registerInMap()
{
m_map->attributeHandlers.insert(std::pair<AttributeMultiVectorGen*, AttributeHandlerGen*>(m_attrib, this)) ;
}
template <typename T>
AttributeHandler<T>::AttributeHandler():
m_map(NULL), m_attrib(NULL)
{}
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(const AttributeHandler<T>& ta):
m_map(ta.m_map), m_attrib(ta.m_attrib)
AttributeHandler<T>::AttributeHandler() :
AttributeHandlerGen(NULL, false), m_attrib(NULL)
{}
template <typename T>
AttributeHandler<T>::AttributeHandler(GenericMap* m, AttributeMultiVector<T>* amv) :
AttributeHandlerGen(m, false), m_attrib(amv)
{
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, ta.valid), m_attrib(ta.m_attrib)
{
if(valid)
registerInMap() ;
}
template <typename T>
inline void AttributeHandler<T>::operator=(const AttributeHandler<T>& ta)
{
if(valid)
unregisterFromMap() ;
m_map = ta.m_map ;
m_attrib = ta.m_attrib ;
valid = ta.valid ;
if(valid)
registerInMap() ;
}
template <typename T>
AttributeHandler<T>::~AttributeHandler()
{}
template <typename T>
GenericMap* AttributeHandler<T>::map() const
{
return m_map ;
if(valid)
unregisterFromMap() ;
}
template <typename T>
......@@ -81,31 +118,23 @@ const std::string& AttributeHandler<T>::name() const
return m_attrib->getName() ;
}
template <typename T>
bool AttributeHandler<T>::isValid() const
{
return !(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 = m_map->getEmbedding(orbit, d) ;
if (a == EMBNULL)
a = m_map->embedNewCell(orbit, d);
a = 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") ;
assert(valid || !"Invalid AttributeHandler") ;
unsigned int a = m_map->getEmbedding(m_attrib->getOrbit(), d) ;
return m_attrib->operator[](a) ;
}
......@@ -113,32 +142,32 @@ inline const T& AttributeHandler<T>::operator[](Dart d) const
template <typename T>
inline T& AttributeHandler<T>::operator[](unsigned int a)
{
assert(isValid() || !"Invalid AttributeHandler") ;
return m_attrib->operator[](a);
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") ;
return m_attrib->operator[](a);
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 = m_map->getAttributeContainer(m_attrib->getOrbit()).insertLine();
m_attrib->operator[](idx) = elt;
return idx;
assert(valid || !"Invalid AttributeHandler") ;
unsigned int idx = 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;
assert(valid || !"Invalid AttributeHandler") ;
unsigned int idx = m_map->getAttributeContainer(m_attrib->getOrbit()).insertLine() ;
return idx ;
}
template <typename T>
......@@ -151,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 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 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") ;
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
......
......@@ -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();