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() ...@@ -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,6 @@ void Viewer::importMesh(std::string& filename) ...@@ -191,7 +193,6 @@ void Viewer::importMesh(std::string& filename)
normalBaseSize = bb.diagSize() / 100.0f ; normalBaseSize = bb.diagSize() / 100.0f ;
// vertexBaseSize = normalBaseSize /5.0f ; // vertexBaseSize = normalBaseSize /5.0f ;
if(!normal.isValid()) if(!normal.isValid())
normal = myMap.addAttribute<PFP::VEC3>(VERTEX, "normal") ; normal = myMap.addAttribute<PFP::VEC3>(VERTEX, "normal") ;
......
...@@ -65,9 +65,9 @@ class MeshTablesSurface ...@@ -65,9 +65,9 @@ class MeshTablesSurface
protected: protected:
typename PFP::MAP& m_map; typename PFP::MAP& m_map;
unsigned m_nbVertices; unsigned int m_nbVertices;
unsigned m_nbFaces; unsigned int m_nbFaces;
unsigned int m_lab; unsigned int m_lab;
...@@ -138,11 +138,11 @@ class MeshTablesVolume ...@@ -138,11 +138,11 @@ class MeshTablesVolume
protected: protected:
typename PFP::MAP& m_map; 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 * number of edges per face
......
...@@ -267,7 +267,7 @@ bool MeshTablesSurface<PFP>::importTrianBinGz(const std::string& filename, std:: ...@@ -267,7 +267,7 @@ bool MeshTablesSurface<PFP>::importTrianBinGz(const std::string& filename, std::
template<typename PFP> template<typename PFP>
bool MeshTablesSurface<PFP>::importOff(const std::string& filename, std::vector<std::string>& attrNames) 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()) if (!positions.isValid())
positions = m_map.template addAttribute<typename PFP::VEC3>(VERTEX, "position") ; positions = m_map.template addAttribute<typename PFP::VEC3>(VERTEX, "position") ;
......
...@@ -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,18 @@ namespace CGoGN ...@@ -33,14 +33,18 @@ 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 +54,10 @@ public: ...@@ -50,10 +54,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 +65,16 @@ public: ...@@ -61,16 +65,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 +102,7 @@ protected: ...@@ -98,7 +102,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 +112,7 @@ protected: ...@@ -108,7 +112,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:
/**************************************** /****************************************
......
...@@ -38,7 +38,16 @@ template <typename T> ...@@ -38,7 +38,16 @@ template <typename T>
inline bool AttribMap::removeAttribute(AttributeHandler<T>& attr) inline bool AttribMap::removeAttribute(AttributeHandler<T>& attr)
{ {
assert(attr.isValid() || !"Invalid attribute handler") ; 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> template <typename T>
......
...@@ -33,6 +33,38 @@ ...@@ -33,6 +33,38 @@
namespace CGoGN 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 * Class that create an access-table to an existing attribute
* Main available operations are: * Main available operations are:
...@@ -41,18 +73,24 @@ namespace CGoGN ...@@ -41,18 +73,24 @@ 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;
void registerInMap() ;
void unregisterFromMap() ;
public: public:
typedef T DATA_TYPE ; typedef T DATA_TYPE ;
/**
* Default constructor
* Constructs a non-valid AttributeHandler (i.e. not linked to any attribute)
*/
AttributeHandler() ;
/** /**
* Constructor * Constructor
* @param m the map which belong attribute * @param m the map which belong attribute
...@@ -60,8 +98,6 @@ public: ...@@ -60,8 +98,6 @@ public:
*/ */
AttributeHandler(GenericMap* m, AttributeMultiVector<T>* amv) ; AttributeHandler(GenericMap* m, AttributeMultiVector<T>* amv) ;
AttributeHandler() ;
/** /**
* Copy constructor * Copy constructor
* @param ta the table attribute * @param ta the table attribute
...@@ -79,11 +115,6 @@ public: ...@@ -79,11 +115,6 @@ public:
*/ */
virtual ~AttributeHandler() ; virtual ~AttributeHandler() ;
/**
* get associated map
*/
GenericMap* map() const ;
/** /**
* get attribute data vector * get attribute data vector
*/ */
...@@ -104,14 +135,6 @@ public: ...@@ -104,14 +135,6 @@ public:
*/ */
const std::string& name() const ; 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 * [] operator with dart parameter
*/ */
...@@ -143,7 +166,7 @@ public: ...@@ -143,7 +166,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,35 +26,72 @@ namespace CGoGN ...@@ -26,35 +26,72 @@ namespace CGoGN
{ {
template <typename T> template <typename T>
AttributeHandler<T>::AttributeHandler(GenericMap* m, AttributeMultiVector<T>* amv): void AttributeHandler<T>::registerInMap()
m_map(m), m_attrib(amv) {
{} m_map->attributeHandlers.insert(std::pair<AttributeMultiVectorGen*, AttributeHandlerGen*>(m_attrib, this)) ;
}
template <typename T> template <typename T>
AttributeHandler<T>::AttributeHandler(): void AttributeHandler<T>::unregisterFromMap()
m_map(NULL), m_attrib(NULL) {
{} 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> template <typename T>
AttributeHandler<T>::AttributeHandler(const AttributeHandler<T>& ta): AttributeHandler<T>::AttributeHandler() :
m_map(ta.m_map), m_attrib(ta.m_attrib) 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> template <typename T>
inline void AttributeHandler<T>::operator=(const AttributeHandler<T>& ta) inline void AttributeHandler<T>::operator=(const AttributeHandler<T>& ta)
{ {
if(valid)
unregisterFromMap() ;
m_map = ta.m_map ; m_map = ta.m_map ;
m_attrib = ta.m_attrib ; m_attrib = ta.m_attrib ;
valid = ta.valid ;
if(valid)
registerInMap() ;
} }
template <typename T> template <typename T>
AttributeHandler<T>::~AttributeHandler() AttributeHandler<T>::~AttributeHandler()
{}
template <typename T>
GenericMap* AttributeHandler<T>::map() const
{ {
return m_map ; if(valid)
unregisterFromMap() ;
} }
template <typename T> template <typename T>
...@@ -81,31 +118,23 @@ const std::string& AttributeHandler<T>::name() const ...@@ -81,31 +118,23 @@ const std::string& AttributeHandler<T>::name() const
return m_attrib->getName() ; 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> template <typename T>
inline T& AttributeHandler<T>::operator[](Dart d) inline T& AttributeHandler<T>::operator[](Dart d)
{ {
assert(isValid() || !"Invalid AttributeHandler") ; assert(valid || !"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 = m_map->getEmbedding(orbit, d) ;
if (a == EMBNULL) 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> 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(valid || !"Invalid AttributeHandler") ;
unsigned int a = m_map->getEmbedding(m_attrib->getOrbit(), d) ; unsigned int a = m_map->getEmbedding(m_attrib->getOrbit(), d) ;
return m_attrib->operator[](a) ; return m_attrib->operator[](a) ;
} }
...@@ -113,32 +142,32 @@ inline const T& AttributeHandler<T>::operator[](Dart d) const ...@@ -113,32 +142,32 @@ inline const T& AttributeHandler<T>::operator[](Dart d) const
template <typename T> template <typename T>
inline T& AttributeHandler<T>::operator[](unsigned int a) inline T& AttributeHandler<T>::operator[](unsigned int a)
{ {
assert(isValid() || !"Invalid AttributeHandler") ; assert(valid || !"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(valid || !"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(valid || !"Invalid AttributeHandler") ;
unsigned int idx = m_map->getAttributeContainer(m_attrib->getOrbit()).insertLine(); unsigned int idx = 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(valid || !"Invalid AttributeHandler") ;
unsigned int idx = m_map->getAttributeContainer(m_attrib->getOrbit()).insertLine(); unsigned int idx = m_map->getAttributeContainer(m_attrib->getOrbit()).insertLine() ;
return idx; return idx ;
} }
template <typename T> template <typename T>
...@@ -151,22 +180,22 @@ inline void AttributeHandler<T>::setAllValues(T& v) ...@@ -151,22 +180,22 @@ inline void AttributeHandler<T>::setAllValues(T& v)
template <typename T> template <typename T>
inline unsigned int AttributeHandler<T>::begin() const inline unsigned int AttributeHandler<T>::begin() const
{ {
assert(isValid() || !"Invalid AttributeHandler") ; assert(valid || !"Invalid AttributeHandler") ;
return m_map->getAttributeContainer(m_attrib->getOrbit()).begin(); return 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(valid || !"Invalid AttributeHandler") ;
return m_map->getAttributeContainer(m_attrib->getOrbit()).end(); return 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(valid || !"Invalid AttributeHandler") ;
m_map->getAttributeContainer(m_attrib->getOrbit()).next(iter); m_map->getAttributeContainer(m_attrib->getOrbit()).next(iter) ;
} }
} //namespace CGoGN } //namespace CGoGN
...@@ -55,13 +55,15 @@ public: ...@@ -55,13 +55,15 @@ public:
AttributeContainer& cellCont = this->m_map->m_attribs[orbit] ; AttributeContainer& cellCont = this->m_map->m_attribs[orbit] ;