diff --git a/Apps/Examples/miniTest.cpp b/Apps/Examples/miniTest.cpp index 66d53181d2cc9499ed12f60ed880f2738d04cadd..4c8d0d5f916f4aad4c963cab4542e70256473e25 100644 --- a/Apps/Examples/miniTest.cpp +++ b/Apps/Examples/miniTest.cpp @@ -534,6 +534,58 @@ void MyGlutWin::myKeyboard(unsigned char keycode, int x, int y) break ; } + case 'd': + { + GLint t1 = glutGet(GLUT_ELAPSED_TIME); + + myMap.removeAttribute(normal) ; + myMap.removeAttribute(laplacian) ; + + AttributeHandler newPosition = myMap.addAttribute(FACE_ORBIT, "position") ; + Algo::Geometry::computeCentroidFaces(myMap, position, newPosition) ; + + std::vector attrNames ; + for(unsigned int i = 0; i < NB_ORBITS; ++i) + { + AttributeContainer& cont = myMap.getAttributeContainer(i) ; + std::cout << "container " << i << " (" << cont.getNbAttributes() << ") :" << std::endl ; + cont.getAttributesNames(attrNames) ; + for(unsigned int j = 0; j < attrNames.size(); ++j) + std::cout << " -> " << attrNames[j] << std::endl ; + } + std::cout << std::endl ; + + Algo::Modelisation::computeDual(myMap) ; + + for(unsigned int i = 0; i < NB_ORBITS; ++i) + { + AttributeContainer& cont = myMap.getAttributeContainer(i) ; + std::cout << "container " << i << " (" << cont.getNbAttributes() << ") :" << std::endl ; + cont.getAttributesNames(attrNames) ; + for(unsigned int j = 0; j < attrNames.size(); ++j) + std::cout << " -> " << attrNames[j] << std::endl ; + } + + position = myMap.getAttribute(VERTEX_ORBIT, "position") ; + normal = myMap.addAttribute(VERTEX_ORBIT, "normal") ; + laplacian = myMap.addAttribute(VERTEX_ORBIT, "laplacian") ; + + GLint t2 = glutGet(GLUT_ELAPSED_TIME); + GLfloat seconds = (t2 - t1) / 1000.0f; + std::cout << "dual computation: "<< seconds << "sec" << std::endl; + + t1 = glutGet(GLUT_ELAPSED_TIME); + updateVBOprimitives(Algo::Render::VBO::TRIANGLES | Algo::Render::VBO::LINES | Algo::Render::VBO::POINTS) ; + updateVBOdata(Algo::Render::VBO::POSITIONS | Algo::Render::VBO::NORMALS) ; + topo_render->updateData(myMap, position, 0.9f, 0.9f) ; + t2 = glutGet(GLUT_ELAPSED_TIME); + seconds = (t2 - t1) / 1000.0f; + std::cout << "display update: "<< seconds << "sec" << std::endl; + + glutPostRedisplay() ; + break ; + } + case '3': { CellMarker markVisit(myMap, VERTEX_CELL) ; diff --git a/include/Algo/Import/importMesh.hpp b/include/Algo/Import/importMesh.hpp index 578ad29ec5122d5c76aeeaae3eb3a104e5c62f90..4e919d2812559205f1fc24ca0e551a4b1ffa31de 100644 --- a/include/Algo/Import/importMesh.hpp +++ b/include/Algo/Import/importMesh.hpp @@ -40,7 +40,7 @@ bool importMesh(typename PFP::MAP& map, MeshTablesSurface& mts) { typedef typename PFP::VEC3 VEC3 ; - AutoAttributeHandler< NoMathIONameAttribute< std::vector > > vecDartsPerVertex(map, VERTEX_ORBIT, "incidents"); + AutoAttributeHandler< NoMathIONameAttribute< std::vector > > vecDartsPerVertex(map, VERTEX_ORBIT, "incidents"); unsigned nbf = mts.getNbFaces(); int index = 0; @@ -106,7 +106,6 @@ bool importMesh(typename PFP::MAP& map, MeshTablesSurface& mts) if (good_dart != Dart::nil()) { - Dart aze = map.phi2(good_dart) ; if (good_dart == map.phi2(good_dart)) { map.sewFaces(d, good_dart); diff --git a/include/Algo/Modelisation/subdivision.h b/include/Algo/Modelisation/subdivision.h index 74d7ae6338eb9dedf348225dec8aface2d69c2d6..0e5f8b2c3813d3dc1e41b27b7137e51c837037a4 100644 --- a/include/Algo/Modelisation/subdivision.h +++ b/include/Algo/Modelisation/subdivision.h @@ -95,7 +95,7 @@ void LoopSubdivision(typename PFP::MAP& map, typename PFP::TVEC3& position, cons * Dual mesh computation */ template -void computeDual(typename PFP::MAP& map, typename PFP::TVEC3& position, const FunctorSelect& selected = SelectorTrue()) ; +void computeDual(typename PFP::MAP& map, const FunctorSelect& selected = SelectorTrue()) ; /** * Sqrt(3) subdivision scheme diff --git a/include/Algo/Modelisation/subdivision.hpp b/include/Algo/Modelisation/subdivision.hpp index 36a7261782ba823b5646481a6705e7e8e6cda522..2210a0567a022d73cf7c83c59c54460c1f0f5c11 100644 --- a/include/Algo/Modelisation/subdivision.hpp +++ b/include/Algo/Modelisation/subdivision.hpp @@ -435,32 +435,33 @@ void LoopSubdivision(typename PFP::MAP& map, typename PFP::TVEC3& position, cons } template -void computeDual(typename PFP::MAP& map, typename PFP::TVEC3& position, const FunctorSelect& selected) +void computeDual(typename PFP::MAP& map, const FunctorSelect& selected) { - typedef typename PFP::MAP MAP ; - typedef typename PFP::VEC3 VEC3 ; - typedef typename PFP::REAL REAL ; - AttributeHandler phi1 = map.template getAttribute(DART_ORBIT, "phi1") ; AttributeHandler phi_1 = map.template getAttribute(DART_ORBIT, "phi_1") ; AttributeHandler new_phi1 = map.template addAttribute(DART_ORBIT, "new_phi1") ; + AttributeHandler new_phi_1 = map.template addAttribute(DART_ORBIT, "new_phi_1") ; for(Dart d = map.begin(); d != map.end(); map.next(d)) { Dart dd = map.alpha1(d) ; new_phi1[d] = dd ; - phi_1[dd] = d ; + new_phi_1[dd] = d ; } map.template swapAttributes(phi1, new_phi1) ; + map.template swapAttributes(phi_1, new_phi_1) ; map.template removeAttribute(new_phi1) ; + map.template removeAttribute(new_phi_1) ; + + map.swapEmbeddingContainers(VERTEX_ORBIT, FACE_ORBIT) ; } template void Sqrt3Subdivision(typename PFP::MAP& map, typename PFP::TVEC3& position, const FunctorSelect& selected) { - computeDual(map, position, selected); +// computeDual(map, selected); trianguleFaces(map, position, selected); } diff --git a/include/Algo/Render/topo_vboRender.h b/include/Algo/Render/topo_vboRender.h index 92947a0637686da82b8b276d9521a915eb5237a5..486261b25c47efe9ecac4f26d89d84ab8666847d 100644 --- a/include/Algo/Render/topo_vboRender.h +++ b/include/Algo/Render/topo_vboRender.h @@ -49,7 +49,6 @@ namespace VBO class topo_VBORender { protected: - /** * vbo buffers * 0: vertices darts @@ -78,7 +77,6 @@ protected: */ float m_topo_relation_width; - /** * attribut d'index dans le VBO */ @@ -157,11 +155,9 @@ public: * @param b blue ! */ void overdrawDart(Dart d, float width, float r, float g, float b); - - }; -class topo_VBORenderMapD:public topo_VBORender +class topo_VBORenderMapD : public topo_VBORender { public: /** @@ -176,7 +172,7 @@ public: void updateData(typename PFP::MAP& map, const typename PFP::TVEC3& positions, float ke, float kf, const FunctorSelect& good = SelectorTrue()); }; -class topo_VBORenderGMap: public topo_VBORender +class topo_VBORenderGMap : public topo_VBORender { public: /** diff --git a/include/Algo/Render/topo_vboRender.hpp b/include/Algo/Render/topo_vboRender.hpp index d781d55d6a2d7a70c7e3692584a8e18fcda29193..b385fd5801f6b064b0407a16873e33bfa9b93209 100644 --- a/include/Algo/Render/topo_vboRender.hpp +++ b/include/Algo/Render/topo_vboRender.hpp @@ -78,7 +78,7 @@ void topo_VBORenderMapD::updateData(typename PFP::MAP& map, const typename PFP:: glBufferDataARB(GL_ARRAY_BUFFER, 2*m_nbDarts*sizeof(VEC3), 0, GL_STREAM_DRAW); GLvoid* PositionDartsBuffer = glMapBufferARB(GL_ARRAY_BUFFER, GL_READ_WRITE); VEC3* positionDartBuf = reinterpret_cast(PositionDartsBuffer); - unsigned int posDBI=0; + unsigned int posDBI = 0; DartMarker mf(map); for(std::vector::iterator id = vecDarts.begin(); id!= vecDarts.end(); id++) @@ -176,12 +176,8 @@ void topo_VBORenderMapD::updateData(typename PFP::MAP& map, const typename PFP:: glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER, m_VBOBuffers[2]); glUnmapBufferARB(GL_ELEMENT_ARRAY_BUFFER); - } - - - template void topo_VBORenderGMap::updateData(typename PFP::MAP& map, const typename PFP::TVEC3& positions, float ke, float kf, const FunctorSelect& good) { diff --git a/include/Container/attributeContainer.h b/include/Container/attributeContainer.h index 04260618ad031edac6b43b16fcd0b2165e183cea..e5236e0fb2fb3433a45988cb95971dd1ed9fcd60 100644 --- a/include/Container/attributeContainer.h +++ b/include/Container/attributeContainer.h @@ -71,6 +71,8 @@ protected: */ std::vector m_tableAttribs; + std::vector m_freeIndices; + /** * map de correspondance string / indice pour les attributs */ @@ -246,7 +248,7 @@ public: * @param strings (OUT) tableau des noms d'attributs * @return le nombre d'attributs */ - unsigned int getAttributesStrings(std::vector& strings); + unsigned int getAttributesNames(std::vector& names); /** * get the name of an attribute, given its index in the container @@ -394,11 +396,6 @@ public: */ unsigned int memoryTotalSize() ; - /** - * Nombre d'attributs - */ - unsigned int nbAttributes(); - /** * Nombre de reference d'une ligne */ diff --git a/include/Container/attributeContainer.hpp b/include/Container/attributeContainer.hpp index 968a225e55c0dfaaea1ac2fc5114633bc46bf424..8bcdb0f773292aea2dab841c88983f942ca1a3fe 100644 --- a/include/Container/attributeContainer.hpp +++ b/include/Container/attributeContainer.hpp @@ -1,11 +1,28 @@ - -//#include -//#include -//#include -//#include -//#include - -#include +/******************************************************************************* +* CGoGN: Combinatorial and Geometric modeling with Generic N-dimensional Maps * +* version 0.1 * +* Copyright (C) 2009, IGG Team, LSIIT, University of Strasbourg * +* * +* This library is free software; you can redistribute it and/or modify it * +* under the terms of the GNU Lesser General Public License as published by the * +* Free Software Foundation; either version 2.1 of the License, or (at your * +* option) any later version. * +* * +* This library is distributed in the hope that it will be useful, but WITHOUT * +* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * +* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * +* for more details. * +* * +* You should have received a copy of the GNU Lesser General Public License * +* along with this library; if not, write to the Free Software Foundation, * +* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * +* * +* Web site: https://iggservis.u-strasbg.fr/CGoGN/ * +* Contact information: cgogn@unistra.fr * +* * +*******************************************************************************/ + +#include #include #include "Container/registered.h" #include "Utils/nameTypes.h" @@ -27,16 +44,24 @@ unsigned int AttributeContainer::addAttribute(const std::string& attribName) { MapNameId::iterator it = m_attribNameMap.find(attribName); if (it != m_attribNameMap.end()) - { return UNKNOWN; - } } // new attribut - AttributeMultiVector* ptr = new AttributeMultiVector(attribName, nametype); - unsigned int idxAttrib = m_tableAttribs.size(); - // add it to table of attribut_manager - m_tableAttribs.push_back(ptr); + AttributeMultiVector* amv = new AttributeMultiVector(attribName, nametype); + + unsigned int idxAttrib ; + if(!m_freeIndices.empty()) + { + idxAttrib = m_freeIndices.back() ; + m_freeIndices.pop_back() ; + m_tableAttribs[idxAttrib] = amv ; + } + else + { + idxAttrib = m_tableAttribs.size(); + m_tableAttribs.push_back(amv); + } // add it in the map if (attribName == "") // if no name, generate a fake name @@ -44,6 +69,7 @@ unsigned int AttributeContainer::addAttribute(const std::string& attribName) std::stringstream ss; ss << "unknown" << m_nbUnknown++; m_attribNameMap.insert(std::pair(ss.str(), idxAttrib)); + amv->setName(ss.str()); } else m_attribNameMap.insert(std::pair(attribName, idxAttrib)); @@ -53,7 +79,7 @@ unsigned int AttributeContainer::addAttribute(const std::string& attribName) // resize the new attribute container to have same size than others int nbb = m_holesBlocks.size(); - ptr->setNbBlocks(nbb); + amv->setNbBlocks(nbb); m_nbAttributes++; @@ -68,24 +94,30 @@ unsigned int AttributeContainer::addAttribute(const std::string& attribName, con { MapNameId::iterator it = m_attribNameMap.find(attribName); if (it != m_attribNameMap.end()) - { return UNKNOWN; - } } // new attribut - AttributeMultiVector* ptr = new AttributeMultiVector(attribName, nametype); + AttributeMultiVector* amv = new AttributeMultiVector(attribName, nametype); // add it to table of attribut_manager - m_tableAttribs[idxAttrib] = ptr; + m_tableAttribs[idxAttrib] = amv; // add it in the map - m_attribNameMap.insert(std::pair(attribName, idxAttrib)); + if (attribName == "") // if no name, generate a fake name + { + std::stringstream ss; + ss << "unknown" << m_nbUnknown++; + m_attribNameMap.insert(std::pair(ss.str(), idxAttrib)); + amv->setName(ss.str()); + } + else + m_attribNameMap.insert(std::pair(attribName, idxAttrib)); // maj taille d'une ligne m_lineCost += sizeof(T); // resize the new attribute container to have same size than others int nbb = m_holesBlocks.size(); - ptr->setNbBlocks(nbb); + amv->setNbBlocks(nbb); m_nbAttributes++; @@ -94,7 +126,7 @@ unsigned int AttributeContainer::addAttribute(const std::string& attribName, con inline unsigned int AttributeContainer::getNbAttributes() { - return m_tableAttribs.size(); + return m_nbAttributes; } /////////////////////////// @@ -104,12 +136,12 @@ inline unsigned int AttributeContainer::getNbAttributes() template T& AttributeContainer::getData(unsigned int codeAttrib, unsigned int eltIdx) { - assert(eltIdx < m_maxSize && "Attribut non existant (indice trop grand)"); - assert(m_holesBlocks[eltIdx/_BLOCKSIZE_]->used(eltIdx%_BLOCKSIZE_)&&"Attribut non existant"); - assert((m_tableAttribs[codeAttrib]!=NULL)&&"Attribut detruit"); + assert(eltIdx < m_maxSize || !"Attribut non existant (indice trop grand)"); + assert(m_holesBlocks[eltIdx/_BLOCKSIZE_]->used(eltIdx%_BLOCKSIZE_) || !"Attribut non existant"); + assert((m_tableAttribs[codeAttrib] != NULL) || !"Attribut detruit"); AttributeMultiVector* atm = dynamic_cast< AttributeMultiVector* >(m_tableAttribs[codeAttrib]); - assert((atm!=NULL)&& "type attribut non concordant"); + assert((atm != NULL) || !"type attribut non concordant"); return atm->operator[](eltIdx); } @@ -117,12 +149,12 @@ T& AttributeContainer::getData(unsigned int codeAttrib, unsigned int eltIdx) template const T& AttributeContainer::getData(unsigned int codeAttrib, unsigned int eltIdx) const { - assert(eltIdx < m_maxSize && "Attribut non existant (indice trop grand)"); - assert(m_holesBlocks[eltIdx/_BLOCKSIZE_]->used(eltIdx%_BLOCKSIZE_)&&"Attribut non existant"); - assert((m_tableAttribs[codeAttrib]!=NULL)&&"Attribut detruit"); + assert(eltIdx < m_maxSize || !"Attribut non existant (indice trop grand)"); + assert(m_holesBlocks[eltIdx/_BLOCKSIZE_]->used(eltIdx%_BLOCKSIZE_) || !"Attribut non existant"); + assert((m_tableAttribs[codeAttrib] != NULL) || !"Attribut detruit"); AttributeMultiVector* atm = dynamic_cast< AttributeMultiVector* >(m_tableAttribs[codeAttrib]); - assert((atm!=NULL)&& "type attribut non concordant"); + assert((atm != NULL) || !"type attribut non concordant"); return atm->operator[](eltIdx); } @@ -130,13 +162,12 @@ const T& AttributeContainer::getData(unsigned int codeAttrib, unsigned int eltId template void AttributeContainer::setData(unsigned int codeAttrib, unsigned int eltIdx, const T& data) { - - assert(eltIdx < m_maxSize && "Attribut non existant (indice trop grand)"); - assert(m_holesBlocks[eltIdx/_BLOCKSIZE_]->used(eltIdx%_BLOCKSIZE_)&&"Attribut non existant"); - assert((m_tableAttribs[codeAttrib]!=NULL)&&"Attribut detruit"); + assert(eltIdx < m_maxSize || !"Attribut non existant (indice trop grand)"); + assert(m_holesBlocks[eltIdx/_BLOCKSIZE_]->used(eltIdx%_BLOCKSIZE_) || !"Attribut non existant"); + assert((m_tableAttribs[codeAttrib] != NULL) || !"Attribut detruit"); AttributeMultiVector* atm = dynamic_cast< AttributeMultiVector* >(m_tableAttribs[codeAttrib]); - assert((atm!=NULL)&& "type attribut non concordant"); + assert((atm != NULL) || !"type attribut non concordant"); atm->operator[](eltIdx) = data; } @@ -152,11 +183,11 @@ void AttributeContainer::setData(unsigned int codeAttrib, unsigned int eltIdx, template AttributeMultiVector& AttributeContainer::getDataVector(unsigned int codeAttrib) { - assert((codeAttrib < m_tableAttribs.size()) && "Attribut inexistant"); - assert((m_tableAttribs[codeAttrib] != NULL) && "Attribut detruit"); + assert((codeAttrib < m_tableAttribs.size()) || !"Attribut inexistant"); + assert((m_tableAttribs[codeAttrib] != NULL) || !"Attribut detruit"); AttributeMultiVector* atm = dynamic_cast< AttributeMultiVector* >(m_tableAttribs[codeAttrib]); - assert((atm!=NULL)&& "type attribut non concordant"); + assert((atm != NULL) || !"type attribut non concordant"); return *atm; } @@ -169,11 +200,11 @@ bool AttributeContainer::getAttributesVector(const std::string& attribName, Attr int codeAttrib = it->second; - if (m_tableAttribs[codeAttrib]==NULL) + if (m_tableAttribs[codeAttrib] == NULL) return false; AttributeMultiVector* atm = dynamic_cast< AttributeMultiVector* >(m_tableAttribs[codeAttrib]); - if (atm==NULL) + if (atm == NULL) return false; *ptr = atm; @@ -188,7 +219,7 @@ template unsigned int AttributeContainer::getAddresses(unsigned int attr, std::vector& vect_adr) { AttributeMultiVector* atm = dynamic_cast< AttributeMultiVector* >(m_tableAttribs[attr]); - assert((atm!=NULL)&& "type attribut non concordant"); + assert((atm != NULL) || !"type attribut non concordant"); return atm->getStartAddresses(vect_adr); } diff --git a/include/Container/attributeMultiVector.h b/include/Container/attributeMultiVector.h index b090b6af6b7cddf6b4e27a78ba95472b624b6a52..7f8dde705fd2736b8a6f5051b731c9f15cb90b2d 100644 --- a/include/Container/attributeMultiVector.h +++ b/include/Container/attributeMultiVector.h @@ -99,9 +99,13 @@ public: /** * get name of the type of attribute */ - const std::string& getTypeName() { return m_typeName;} + const std::string& getTypeName() { return m_typeName; } - const std::string& getName() { return m_attName;} + void setTypeName(const std::string& n) { m_typeName = n ; } + + const std::string& getName() { return m_attName; } + + void setName(const std::string& n) { m_attName = n ; } virtual void saveBin(CGoGNostream& fs, unsigned int id)=0; @@ -115,8 +119,6 @@ public: virtual void input(unsigned int i,const std::string& st)=0; - virtual bool swap(AttributeMultiVectorGen& att)=0; - virtual bool merge(const AttributeMultiVectorGen& att)=0; virtual void addBlocksBefore(unsigned int nbb)=0; @@ -162,13 +164,12 @@ public: }; template -class AttributeMultiVector: public AttributeMultiVectorGen +class AttributeMultiVector: public AttributeMultiVectorGen { /** * table of blocks of data ptr: vectors! */ - std::vector< T* > m_tableData; - + std::vector m_tableData; public: @@ -184,8 +185,6 @@ public: AttributeMultiVectorGen* new_obj(); - bool swap(AttributeMultiVectorGen& att); - bool merge(const AttributeMultiVectorGen& att); /** @@ -256,14 +255,12 @@ public: */ void saveBin(CGoGNostream& fs, unsigned int id); - /** * lecture binaire * @param fs filestream */ bool loadBin(CGoGNistream& fs); - // Processing attributes void affect(unsigned int i, unsigned int j); @@ -279,7 +276,7 @@ public: void lerp(unsigned res, unsigned int i, unsigned int j, double alpha); }; -} +} // namespace CGoGN #include "attributeMultiVector.hpp" diff --git a/include/Container/attributeMultiVector.hpp b/include/Container/attributeMultiVector.hpp index 10f1554e4dd3b62372444f079a6f8608a2340fbb..b9cb1d47930dc487cc5a4f38e3449cd714fd8344 100644 --- a/include/Container/attributeMultiVector.hpp +++ b/include/Container/attributeMultiVector.hpp @@ -1,9 +1,32 @@ +/******************************************************************************* +* CGoGN: Combinatorial and Geometric modeling with Generic N-dimensional Maps * +* version 0.1 * +* Copyright (C) 2009, IGG Team, LSIIT, University of Strasbourg * +* * +* This library is free software; you can redistribute it and/or modify it * +* under the terms of the GNU Lesser General Public License as published by the * +* Free Software Foundation; either version 2.1 of the License, or (at your * +* option) any later version. * +* * +* This library is distributed in the hope that it will be useful, but WITHOUT * +* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * +* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * +* for more details. * +* * +* You should have received a copy of the GNU Lesser General Public License * +* along with this library; if not, write to the Free Software Foundation, * +* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * +* * +* Web site: https://iggservis.u-strasbg.fr/CGoGN/ * +* Contact information: cgogn@unistra.fr * +* * +*******************************************************************************/ namespace CGoGN { inline AttributeMultiVectorGen::AttributeMultiVectorGen(const std::string& strName, const std::string& strType): - m_attName(strName), m_typeName(strType), m_toProcess(true) + m_attName(strName), m_typeName(strType), m_toProcess(true) {} inline AttributeMultiVectorGen::AttributeMultiVectorGen(): m_toProcess(true) @@ -70,7 +93,12 @@ bool AttributeMultiVector::copy(const AttributeMultiVectorGen* atmvg) if (atmv == NULL) { - std::cerr<< "copy attribute of different type"<m_typeName != m_typeName) + { + std::cerr << "trying to swap attributes with different type names" << std::endl; return false; } @@ -88,35 +116,40 @@ bool AttributeMultiVector::swap(AttributeMultiVectorGen* atmvg) if (atmv == NULL) { - std::cerr<< "swap attribute of different type"<m_tableData) ; - return true; -} - -template -bool AttributeMultiVector::swap(AttributeMultiVectorGen& att) -{ - AttributeMultiVector* attrib = dynamic_cast< AttributeMultiVector* >(&att); - if (attrib==NULL) - { - std::cerr << "Erreur, swap de container de types differents"<m_typeName != m_typeName) + if (atmv->m_typeName != m_typeName) { - std::cerr << "Erreur, swap de container avec noms de type differents"<m_tableData); - m_typeName.swap(attrib->m_typeName); - + m_tableData.swap(atmv->m_tableData) ; return true; } +//template +//bool AttributeMultiVector::swap(AttributeMultiVectorGen& att) +//{ +// AttributeMultiVector* attrib = dynamic_cast*>(&att); +// if (attrib==NULL) +// { +// std::cerr << "Erreur, swap de container de types differents"<m_typeName != m_typeName) +// { +// std::cerr << "Erreur, swap de container avec noms de type differents"<m_tableData); +// m_typeName.swap(attrib->m_typeName); +// +// return true; +//} + template bool AttributeMultiVector::merge(const AttributeMultiVectorGen& att) { @@ -139,10 +172,16 @@ bool AttributeMultiVector::merge(const AttributeMultiVectorGen& att) } template -T& AttributeMultiVector::operator[](unsigned int i) { return m_tableData[i/_BLOCKSIZE_][i%_BLOCKSIZE_];} +T& AttributeMultiVector::operator[](unsigned int i) +{ + return m_tableData[i/_BLOCKSIZE_][i%_BLOCKSIZE_]; +} template -const T& AttributeMultiVector::operator[](unsigned int i) const { return m_tableData[i/_BLOCKSIZE_][i%_BLOCKSIZE_];} +const T& AttributeMultiVector::operator[](unsigned int i) const +{ + return m_tableData[i/_BLOCKSIZE_][i%_BLOCKSIZE_]; +} template std::string AttributeMultiVector::output(unsigned int i) diff --git a/include/Topology/generic/autoAttributeHandler.h b/include/Topology/generic/autoAttributeHandler.h index fcfb8d9a1632726e1927859df07a4efc790846cc..203e93431bc7d1f5fcb50b8d22b727dd5efc1c54 100644 --- a/include/Topology/generic/autoAttributeHandler.h +++ b/include/Topology/generic/autoAttributeHandler.h @@ -32,9 +32,9 @@ namespace CGoGN { /** - * Class that create an acces-table to an attribute + * Class that creates an access-table to an attribute * that is added especially. The attribute is removed when - * the object is destroyed + * the AutoAttributeHandler object is destroyed */ template class AutoAttributeHandler : public AttributeHandler diff --git a/include/Topology/generic/genericmap.h b/include/Topology/generic/genericmap.h index 76f749dabb25da0c60ea4f09fe749eab1a404980..afebd4b278b0b22e1837088aebbb08e2e748b79d 100644 --- a/include/Topology/generic/genericmap.h +++ b/include/Topology/generic/genericmap.h @@ -256,6 +256,11 @@ public: */ AttributeMultiVector* getEmbeddingAttributeVector(unsigned int orbit); + /** + * + */ + void swapEmbeddingContainers(unsigned int orbit1, unsigned int orbit2); + /** * static function for type registration */ diff --git a/include/Topology/generic/genericmap.hpp b/include/Topology/generic/genericmap.hpp index 1ef11a7a6b7d52a659f2039c01a1acf8ee58bef2..c9e583692462cf1c631e51feb5530537f093fe64 100644 --- a/include/Topology/generic/genericmap.hpp +++ b/include/Topology/generic/genericmap.hpp @@ -244,6 +244,16 @@ inline AttributeMultiVector* GenericMap::getEmbeddingAttributeVect return m_embeddings[orbit] ; } +inline void GenericMap::swapEmbeddingContainers(unsigned int orbit1, unsigned int orbit2) +{ + assert(orbit1 != orbit2 || !"Cannot swap a container with itself") ; + assert((orbit1 != DART_ORBIT && orbit2 != DART_ORBIT) || !"Cannot swap the darts container") ; + m_attribs[orbit1].swap(m_attribs[orbit2]) ; + AttributeMultiVector* e1 = m_embeddings[orbit1] ; + m_embeddings[orbit1] = m_embeddings[orbit2] ; + m_embeddings[orbit2] = e1 ; +} + /**************************************** * MARKERS MANAGEMENT * ****************************************/ diff --git a/src/Container/attributeContainer.cpp b/src/Container/attributeContainer.cpp index 56a39e1efa6305c80fa1530244986688a061fde8..df9dd4f288461f71745c13bc34370e0e4e1b236a 100644 --- a/src/Container/attributeContainer.cpp +++ b/src/Container/attributeContainer.cpp @@ -37,6 +37,7 @@ void AttributeContainer::swap(AttributeContainer& cont) m_holesBlocks.swap(cont.m_holesBlocks); m_tableBlocksWithFree.swap(cont.m_tableBlocksWithFree); m_tableAttribs.swap(cont.m_tableAttribs); + m_freeIndices.swap(cont.m_freeIndices); m_attribNameMap.swap(cont.m_attribNameMap); unsigned int temp = m_nbAttributes; @@ -73,6 +74,11 @@ bool AttributeContainer::removeAttribute(const std::string& attribName) delete (m_tableAttribs[it->second]); m_tableAttribs[it->second] = NULL; + if(it->second == m_tableAttribs.size() - 1) + m_tableAttribs.pop_back() ; + else + m_freeIndices.push_back(it->second); + // remove the attribute from the name map m_attribNameMap.erase(it); @@ -86,17 +92,21 @@ bool AttributeContainer::removeAttribute(unsigned int index) MapNameId::iterator it = m_attribNameMap.begin(); while ((it != m_attribNameMap.end()) && (it->second != index)) ++it; - if (it != m_attribNameMap.end()) - { - // remove the attribute from the name map - m_attribNameMap.erase(it); - } - // else it was an attribute without name // delete the attribute delete (m_tableAttribs[index]); m_tableAttribs[index] = NULL; + if(index == m_tableAttribs.size() - 1) + m_tableAttribs.pop_back() ; + else + m_freeIndices.push_back(index); + + // remove the attribute from the name map + if (it != m_attribNameMap.end()) + m_attribNameMap.erase(it); + // else it was an attribute without name + m_nbAttributes--; return true; @@ -179,7 +189,6 @@ void AttributeContainer::saveXml(xmlTextWriterPtr writer, unsigned int id) rc = xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "BlockSize","%u",_BLOCKSIZE_); rc = xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "size","%u",m_maxSize); - // recuperer le nombre d'attributs unsigned int nbAtt = m_attribNameMap.size(); unsigned int sizeVectAtt = m_tableAttribs.size(); @@ -202,7 +211,6 @@ void AttributeContainer::saveXml(xmlTextWriterPtr writer, unsigned int id) // fin du noeud rc = xmlTextWriterEndElement(writer); - // parcourir le container et sauver les lignes rc = xmlTextWriterStartElement(writer, BAD_CAST "Data_Lines"); // rc = xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "size","%u",m_maxSize); @@ -229,7 +237,6 @@ void AttributeContainer::saveXml(xmlTextWriterPtr writer, unsigned int id) // fin du noeud Container rc = xmlTextWriterEndElement(writer); - } bool AttributeContainer::loadXmlBWF(xmlNodePtr node) @@ -259,7 +266,6 @@ bool AttributeContainer::loadXmlAN(xmlNodePtr node, unsigned int nbb) prop = xmlGetProp(node, BAD_CAST "sv"); // unsigned int sv = atoi((char*)prop); - // Noooooooo!!!! // m_tableAttribs.resize(sv); // for (unsigned int i=0; i< sv; ++i) @@ -316,7 +322,7 @@ bool AttributeContainer::loadXmlDL(xmlNodePtr node) unsigned int nbr = atoi((char*)prop); setRefLine(id,nbr); - if (nbr>0) + if (nbr > 0) { for (MapNameId::iterator it=m_attribNameMap.begin(); it!=m_attribNameMap.end(); ++it) { @@ -336,7 +342,6 @@ bool AttributeContainer::loadXmlDL(xmlNodePtr node) return true; } - unsigned int AttributeContainer::getIdXmlNode(xmlNodePtr node) { xmlChar *prop = xmlGetProp(node, BAD_CAST "id"); @@ -361,7 +366,6 @@ bool AttributeContainer::loadXml(xmlNodePtr node) prop = xmlGetProp(node, BAD_CAST "size"); m_maxSize = atoi((char*)prop); - char* ANnode = (char*)"Attributes_Names"; char* DLnode= (char*)"Data_Lines"; @@ -514,9 +518,7 @@ unsigned int AttributeContainer::getAttribute(const std::string& attribName) { MapNameId::iterator it = m_attribNameMap.find(attribName); if (it == m_attribNameMap.end()) - { return UNKNOWN; - } return it->second; } @@ -534,18 +536,15 @@ bool AttributeContainer::isValidAttribute(unsigned int attr) return false; } -unsigned int AttributeContainer::getAttributesStrings(std::vector& strings) +unsigned int AttributeContainer::getAttributesNames(std::vector& names) { - strings.clear(); - - strings.resize(m_tableAttribs.size()); + names.clear(); + names.reserve(m_nbAttributes); - for (MapNameId::iterator it = m_attribNameMap.begin(); it!= m_attribNameMap.end(); ++it) - { - strings[it->second] = it->first; - } + for (MapNameId::iterator it = m_attribNameMap.begin(); it != m_attribNameMap.end(); ++it) + names.push_back(it->first); - return m_attribNameMap.size(); + return m_nbAttributes; } const std::string& AttributeContainer::getAttributeName(unsigned int attrIndex) @@ -560,11 +559,6 @@ const std::string& AttributeContainer::getAttributeName(unsigned int attrIndex) return m_attribNameMap.begin()->first; // just for compiling } -unsigned int AttributeContainer::nbAttributes() -{ - return m_attribNameMap.size(); -} - /////////////////////////// // GESTION DES LIGNES /////////////////////////// diff --git a/src/Topology/generic/attribmap.cpp b/src/Topology/generic/attribmap.cpp index 279a8fbf5fa835710d66cc40bc06d2218fcebfbc..72a67a83002697408bc3b379e9db4388f2b5229c 100644 --- a/src/Topology/generic/attribmap.cpp +++ b/src/Topology/generic/attribmap.cpp @@ -41,6 +41,8 @@ AttribMap::AttribMap() : GenericMap() void AttribMap::addEmbedding(unsigned int orbit) { + assert(!isOrbitEmbedded(orbit) || !"Invalid parameter: orbit already embedded") ; + std::ostringstream oss; oss << "EMB_" << orbit; diff --git a/src/Topology/generic/genericmap.cpp b/src/Topology/generic/genericmap.cpp index 979433441b793af8f7c9a1654eb8cf2e23e452c2..d57d0a3107c8bd85f23672471f2d158ab1e19fe4 100644 --- a/src/Topology/generic/genericmap.cpp +++ b/src/Topology/generic/genericmap.cpp @@ -160,7 +160,7 @@ void GenericMap::update_m_emb_afterLoad() // get the list of attributes std::vector listeNames; - cont.getAttributesStrings(listeNames); + cont.getAttributesNames(listeNames); // check if there are EMB_X attributes for (unsigned int i = 0; i < listeNames.size(); ++i)