diff --git a/include/Algo/Import/import2tables.h b/include/Algo/Import/import2tables.h index 6cabedb56dacc168b6fc58de62709760338addea..69988c1034244ec2a7d43657e60017f645c8c6fb 100644 --- a/include/Algo/Import/import2tables.h +++ b/include/Algo/Import/import2tables.h @@ -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 diff --git a/include/Algo/Import/import2tablesSurface.hpp b/include/Algo/Import/import2tablesSurface.hpp index 2b30ab658896bfca81d95398c4ac3d438bee0ff1..e61754906af4eb5fdc2b1f87a3ffd1dd3ae583a3 100644 --- a/include/Algo/Import/import2tablesSurface.hpp +++ b/include/Algo/Import/import2tablesSurface.hpp @@ -267,7 +267,7 @@ bool MeshTablesSurface::importTrianBinGz(const std::string& filename, std:: template bool MeshTablesSurface::importOff(const std::string& filename, std::vector& attrNames) { - AttributeHandler positions = m_map.template getAttribute(VERTEX, "position") ; + AttributeHandler positions = m_map.template getAttribute(VERTEX, "position") ; if (!positions.isValid()) positions = m_map.template addAttribute(VERTEX, "position") ; diff --git a/include/Topology/generic/attribmap.h b/include/Topology/generic/attribmap.h index ce8d6690f0900237abe40dc89292ccf4d4795c05..a8d52f9208fa50c86109c5e26ee7544d932754be 100644 --- a/include/Topology/generic/attribmap.h +++ b/include/Topology/generic/attribmap.h @@ -35,7 +35,6 @@ class AttribMap : public GenericMap { private: friend class CellMarkerGen ; - template friend class AutoAttributeHandler ; void init() ; diff --git a/include/Topology/generic/attribmap.hpp b/include/Topology/generic/attribmap.hpp index a6e6dfe81143daa894c849daeb5bd479448151e0..9283e30ee86724f20810cdbd41b4821bc6163316 100644 --- a/include/Topology/generic/attribmap.hpp +++ b/include/Topology/generic/attribmap.hpp @@ -44,6 +44,7 @@ inline bool AttribMap::removeAttribute(AttributeHandler& attr) std::pair 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 ; diff --git a/include/Topology/generic/attributeHandler.h b/include/Topology/generic/attributeHandler.h index f762780789cd1fc9a733b1d423a3beafa9d80ca5..565bd75423e985c8d391abd6f0a508f5285c71c5 100644 --- a/include/Topology/generic/attributeHandler.h +++ b/include/Topology/generic/attributeHandler.h @@ -36,14 +36,16 @@ namespace CGoGN class AttributeHandlerGen { protected: + friend class GenericMap ; + friend class AttribMap ; + // the map that contains the linked attribute - GenericMap* m_map; + GenericMap* m_map ; + // boolean that states the validity of the handler + bool valid ; public: - AttributeHandlerGen() : m_map(NULL) - {} - - AttributeHandlerGen(GenericMap* m) : m_map(m) + AttributeHandlerGen(GenericMap* m, bool v) : m_map(m), valid(v) {} GenericMap* map() const @@ -51,11 +53,17 @@ public: return m_map ; } + bool isValid() const + { + return valid ; + } + +protected: void setInvalid() { - m_map = NULL ; + valid = false ; } -}; +} ; /** * Class that create an access-table to an existing attribute @@ -71,6 +79,9 @@ protected: // the multi-vector that contains attribute data AttributeMultiVector* m_attrib; + void registerInMap() ; + void unregisterFromMap() ; + public: typedef T DATA_TYPE ; @@ -124,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 */ diff --git a/include/Topology/generic/attributeHandler.hpp b/include/Topology/generic/attributeHandler.hpp index f92e8048a3bdb55be5b939edfe7850873fc3f3a3..9fa1961241685e627ea3680e0ba65103a8984457 100644 --- a/include/Topology/generic/attributeHandler.hpp +++ b/include/Topology/generic/attributeHandler.hpp @@ -25,47 +25,73 @@ namespace CGoGN { +template +void AttributeHandler::registerInMap() +{ + m_map->attributeHandlers.insert(std::pair(m_attrib, this)) ; +} + +template +void AttributeHandler::unregisterFromMap() +{ + typedef std::multimap::iterator IT ; + std::pair 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 AttributeHandler::AttributeHandler() : - AttributeHandlerGen(), m_attrib(NULL) + AttributeHandlerGen(NULL, false), m_attrib(NULL) {} template AttributeHandler::AttributeHandler(GenericMap* m, AttributeMultiVector* amv) : - AttributeHandlerGen(m), m_attrib(amv) + AttributeHandlerGen(m, false), m_attrib(amv) { - m->attributeHandlers.insert(std::pair(amv, this)) ; + if(amv != NULL && amv->getIndex() != AttributeContainer::UNKNOWN) + { + valid = true ; + registerInMap() ; + } + else + valid = false ; } template AttributeHandler::AttributeHandler(const AttributeHandler& ta) : - AttributeHandlerGen(ta.m_map), m_attrib(ta.m_attrib) + AttributeHandlerGen(ta.m_map, ta.valid), m_attrib(ta.m_attrib) { - this->m_map->attributeHandlers.insert(std::pair(m_attrib, this)) ; + if(valid) + registerInMap() ; } template inline void AttributeHandler::operator=(const AttributeHandler& ta) { - this->m_map = ta.m_map ; + if(valid) + unregisterFromMap() ; + m_map = ta.m_map ; m_attrib = ta.m_attrib ; - this->m_map->attributeHandlers.insert(std::pair(m_attrib, this)) ; + valid = ta.valid ; + if(valid) + registerInMap() ; } template AttributeHandler::~AttributeHandler() { - typedef std::multimap::iterator IT ; - std::pair bounds = this->m_map->attributeHandlers.equal_range(m_attrib) ; - for(IT i = bounds.first; i != bounds.second; ++i) - { - if((*i).second == this) - { - this->m_map->attributeHandlers.erase(i) ; - return ; - } - } - assert(false || !"Should not get here") ; + if(valid) + unregisterFromMap() ; } template @@ -92,23 +118,15 @@ const std::string& AttributeHandler::name() const return m_attrib->getName() ; } -template -bool AttributeHandler::isValid() const -{ - return !(this->m_map == NULL || - m_attrib == NULL || - m_attrib->getIndex() == AttributeContainer::UNKNOWN) ; -} - template inline T& AttributeHandler::operator[](Dart d) { - assert(isValid() || !"Invalid AttributeHandler") ; + assert(valid || !"Invalid AttributeHandler") ; unsigned int orbit = m_attrib->getOrbit() ; - unsigned int a = this->m_map->getEmbedding(orbit, d) ; + unsigned int a = m_map->getEmbedding(orbit, d) ; if (a == EMBNULL) - a = this->m_map->embedNewCell(orbit, d) ; + a = m_map->embedNewCell(orbit, d) ; return m_attrib->operator[](a) ; } @@ -116,30 +134,30 @@ inline T& AttributeHandler::operator[](Dart d) template inline const T& AttributeHandler::operator[](Dart d) const { - assert(isValid() || !"Invalid AttributeHandler") ; - unsigned int a = this->m_map->getEmbedding(m_attrib->getOrbit(), d) ; + assert(valid || !"Invalid AttributeHandler") ; + unsigned int a = m_map->getEmbedding(m_attrib->getOrbit(), d) ; return m_attrib->operator[](a) ; } template inline T& AttributeHandler::operator[](unsigned int a) { - assert(isValid() || !"Invalid AttributeHandler") ; + assert(valid || !"Invalid AttributeHandler") ; return m_attrib->operator[](a) ; } template inline const T& AttributeHandler::operator[](unsigned int a) const { - assert(isValid() || !"Invalid AttributeHandler") ; + assert(valid || !"Invalid AttributeHandler") ; return m_attrib->operator[](a) ; } template inline unsigned int AttributeHandler::insert(const T& elt) { - assert(isValid() || !"Invalid AttributeHandler") ; - unsigned int idx = this->m_map->getAttributeContainer(m_attrib->getOrbit()).insertLine() ; + assert(valid || !"Invalid AttributeHandler") ; + unsigned int idx = m_map->getAttributeContainer(m_attrib->getOrbit()).insertLine() ; m_attrib->operator[](idx) = elt ; return idx ; } @@ -147,8 +165,8 @@ inline unsigned int AttributeHandler::insert(const T& elt) template inline unsigned int AttributeHandler::newElt() { - assert(isValid() || !"Invalid AttributeHandler") ; - unsigned int idx = this->m_map->getAttributeContainer(m_attrib->getOrbit()).insertLine() ; + assert(valid || !"Invalid AttributeHandler") ; + unsigned int idx = m_map->getAttributeContainer(m_attrib->getOrbit()).insertLine() ; return idx ; } @@ -162,22 +180,22 @@ inline void AttributeHandler::setAllValues(T& v) template inline unsigned int AttributeHandler::begin() const { - assert(isValid() || !"Invalid AttributeHandler") ; - return this->m_map->getAttributeContainer(m_attrib->getOrbit()).begin() ; + assert(valid || !"Invalid AttributeHandler") ; + return m_map->getAttributeContainer(m_attrib->getOrbit()).begin() ; } template inline unsigned int AttributeHandler::end() const { - assert(isValid() || !"Invalid AttributeHandler") ; - return this->m_map->getAttributeContainer(m_attrib->getOrbit()).end() ; + assert(valid || !"Invalid AttributeHandler") ; + return m_map->getAttributeContainer(m_attrib->getOrbit()).end() ; } template inline void AttributeHandler::next(unsigned int& iter) const { - assert(isValid() || !"Invalid AttributeHandler") ; - this->m_map->getAttributeContainer(m_attrib->getOrbit()).next(iter) ; + assert(valid || !"Invalid AttributeHandler") ; + m_map->getAttributeContainer(m_attrib->getOrbit()).next(iter) ; } } //namespace CGoGN diff --git a/include/Topology/generic/autoAttributeHandler.h b/include/Topology/generic/autoAttributeHandler.h index c0f73386cbbe00ad5f8946ccd6fd6b6deeccc385..23c17a26b628c43c6f610adc0a39534e3143a0c0 100644 --- a/include/Topology/generic/autoAttributeHandler.h +++ b/include/Topology/generic/autoAttributeHandler.h @@ -55,13 +55,15 @@ public: AttributeContainer& cellCont = this->m_map->m_attribs[orbit] ; AttributeMultiVector* amv = cellCont.addAttribute(nameAttr) ; this->m_attrib = amv ; + this->valid = true ; + this->registerInMap() ; } ~AutoAttributeHandler() { reinterpret_cast(this->m_map)->removeAttribute(*this) ; } -}; +} ; } // namespace CGoGN diff --git a/src/Topology/generic/genericmap.cpp b/src/Topology/generic/genericmap.cpp index 7694d0d26104599ad17cf7480b77d75b58d2c795..83d053f373f6b1a4f6b624cabc076a17137959f3 100644 --- a/src/Topology/generic/genericmap.cpp +++ b/src/Topology/generic/genericmap.cpp @@ -117,6 +117,7 @@ void GenericMap::clear(bool removeAttrib) { for(std::multimap::iterator it = attributeHandlers.begin(); it != attributeHandlers.end(); ++it) (*it).second->setInvalid() ; + attributeHandlers.clear() ; } } diff --git a/src/Utils/Shaders/shaderSimpleColor.cpp b/src/Utils/Shaders/shaderSimpleColor.cpp index 49f5c2b3b89f59b03153740624b3a95486414023..babdae6f3b33a182475f3146b14038cd7e65036d 100644 --- a/src/Utils/Shaders/shaderSimpleColor.cpp +++ b/src/Utils/Shaders/shaderSimpleColor.cpp @@ -30,6 +30,7 @@ namespace CGoGN namespace Utils { + #include "shaderSimpleColor.vert" #include "shaderSimpleColor.frag" @@ -49,7 +50,7 @@ namespace Utils // "FRAG_OUT_DEF;\n" // "void main()\n" // "{\n" -// " gl_FragColor=color;\n" +// " gl_FragColor = color;\n" // "}";