diff --git a/Apps/Examples/miniTest.cpp b/Apps/Examples/miniTest.cpp index 040554f9b656884971caeea0c4eb0fa29702c160..86a754e4ee88f148dfb1b9978d9558ba2d167e21 100644 --- a/Apps/Examples/miniTest.cpp +++ b/Apps/Examples/miniTest.cpp @@ -536,11 +536,10 @@ void MyGlutWin::myKeyboard(unsigned char keycode, int x, int y) case 'd': { - myMap.removeAttribute(normal) ; - myMap.removeAttribute(laplacian) ; - - AttributeHandler newPosition = myMap.addAttribute(FACE_ORBIT, "position") ; - Algo::Geometry::computeCentroidFaces(myMap, position, newPosition) ; + AttributeHandler positionF = myMap.getAttribute(FACE_ORBIT, "position") ; + if(!positionF.isValid()) + positionF = myMap.addAttribute(FACE_ORBIT, "position") ; + Algo::Geometry::computeCentroidFaces(myMap, position, positionF) ; GLint t1 = glutGet(GLUT_ELAPSED_TIME); @@ -550,12 +549,14 @@ void MyGlutWin::myKeyboard(unsigned char keycode, int x, int y) GLfloat seconds = (t2 - t1) / 1000.0f; std::cout << "dual computation: "<< seconds << "sec" << std::endl; - newPosition = myMap.getAttribute(FACE_ORBIT, "position") ; - myMap.removeAttribute(newPosition) ; - position = myMap.getAttribute(VERTEX_ORBIT, "position") ; - normal = myMap.addAttribute(VERTEX_ORBIT, "normal") ; - laplacian = myMap.addAttribute(VERTEX_ORBIT, "laplacian") ; + + normal = myMap.getAttribute(VERTEX_ORBIT, "normal") ; + if(!normal.isValid()) + normal = myMap.addAttribute(VERTEX_ORBIT, "normal") ; + laplacian = myMap.getAttribute(VERTEX_ORBIT, "laplacian") ; + if(!laplacian.isValid()) + laplacian = myMap.addAttribute(VERTEX_ORBIT, "laplacian") ; t1 = glutGet(GLUT_ELAPSED_TIME); updateVBOprimitives(Algo::Render::VBO::TRIANGLES | Algo::Render::VBO::LINES | Algo::Render::VBO::POINTS) ; diff --git a/include/Algo/ImplicitHierarchicalMesh/ihm.hpp b/include/Algo/ImplicitHierarchicalMesh/ihm.hpp index 215709f95bc2b6c150135a2b396e8bfee58e63a2..4f8e26ef557116a197fc6661cbfa62329dd64d56 100644 --- a/include/Algo/ImplicitHierarchicalMesh/ihm.hpp +++ b/include/Algo/ImplicitHierarchicalMesh/ihm.hpp @@ -343,7 +343,7 @@ T& AttributeHandler_IHM::operator[](Dart d) assert(m->m_dartLevel[d] <= m->m_curLevel || !"Access to a dart introduced after current level") ; assert(m->vertexInsertionLevel(d) <= m->m_curLevel || !"Access to the embedding of a vertex inserted after current level") ; - unsigned int orbit = this->m_orbit ; + unsigned int orbit = this->getOrbit() ; unsigned int nbSteps = m->m_curLevel - m->vertexInsertionLevel(d) ; unsigned int index = m->getEmbedding(d, orbit) ; @@ -380,7 +380,7 @@ const T& AttributeHandler_IHM::operator[](Dart d) const assert(m->m_dartLevel[d] <= m->m_curLevel || !"Access to a dart introduced after current level") ; assert(m->vertexInsertionLevel(d) <= m->m_curLevel || !"Access to the embedding of a vertex inserted after current level") ; - unsigned int orbit = this->m_orbit ; + unsigned int orbit = this->getOrbit() ; unsigned int nbSteps = m->m_curLevel - m->vertexInsertionLevel(d) ; unsigned int index = m->getEmbedding(d, orbit) ; diff --git a/include/Algo/Modelisation/subdivision.h b/include/Algo/Modelisation/subdivision.h index 0e5f8b2c3813d3dc1e41b27b7137e51c837037a4..00f6ca518e129108c6af2a269bbd163232c8791a 100644 --- a/include/Algo/Modelisation/subdivision.h +++ b/include/Algo/Modelisation/subdivision.h @@ -91,6 +91,12 @@ void LoopSubdivision(typename PFP::MAP& map, EMBV& attributs, const FunctorSelec template void LoopSubdivision(typename PFP::MAP& map, typename PFP::TVEC3& position, const FunctorSelect& selected = SelectorTrue()) ; +/** + * Reverse the orientation of the map + */ +template +void reverseOrientation(typename PFP::MAP& map) ; + /** * Dual mesh computation */ diff --git a/include/Algo/Modelisation/subdivision.hpp b/include/Algo/Modelisation/subdivision.hpp index 2a2fa4aef22c3d4519516d4244ef0638fb6fb8fc..a209f355cc69238be82478993904751b74072302 100644 --- a/include/Algo/Modelisation/subdivision.hpp +++ b/include/Algo/Modelisation/subdivision.hpp @@ -434,6 +434,24 @@ void LoopSubdivision(typename PFP::MAP& map, typename PFP::TVEC3& position, cons LoopSubdivision(map, position, selected) ; } +template +void reverseOrientation(typename PFP::MAP& map) +{ + AttributeHandler emb0(&map, map.getEmbeddingAttributeVector(VERTEX_ORBIT)) ; + if(emb0.isValid()) + { + AttributeHandler new_emb0 = map.template addAttribute(DART_ORBIT, "new_EMB_0") ; + for(Dart d = map.begin(); d != map.end(); map.next(d)) + new_emb0[d] = emb0[map.phi1(d)] ; + map.template swapAttributes(emb0, new_emb0) ; + map.template removeAttribute(new_emb0) ; + } + + AttributeHandler phi1 = map.template getAttribute(DART_ORBIT, "phi1") ; + AttributeHandler phi_1 = map.template getAttribute(DART_ORBIT, "phi_1") ; + map.template swapAttributes(phi1, phi_1) ; +} + template void computeDual(typename PFP::MAP& map, const FunctorSelect& selected) { @@ -456,12 +474,14 @@ void computeDual(typename PFP::MAP& map, const FunctorSelect& selected) map.template removeAttribute(new_phi_1) ; map.swapEmbeddingContainers(VERTEX_ORBIT, FACE_ORBIT) ; + + reverseOrientation(map) ; } template void Sqrt3Subdivision(typename PFP::MAP& map, typename PFP::TVEC3& position, const FunctorSelect& selected) { -// computeDual(map, selected); + computeDual(map, selected); trianguleFaces(map, position, selected); } diff --git a/include/Container/attributeContainer.hpp b/include/Container/attributeContainer.hpp index c19bde2221911899d354fa6f719fee139fb78b4a..3e2424c11ab3da1f178dff0276ced9a76e4f428a 100644 --- a/include/Container/attributeContainer.hpp +++ b/include/Container/attributeContainer.hpp @@ -292,8 +292,10 @@ AttributeMultiVector* AttributeContainer::getDataVector(const std::string& at inline AttributeMultiVectorGen* AttributeContainer::getVirtualDataVector(const std::string& attribName) { unsigned int index = getAttributeIndex(attribName) ; - assert(index != UNKNOWN) ; - return m_tableAttribs[index]; + if(index == UNKNOWN) + return NULL ; + else + return m_tableAttribs[index]; } template diff --git a/include/Topology/generic/attribmap.hpp b/include/Topology/generic/attribmap.hpp index db04634fb59443144de857453c69a973580144ae..b7fdd788d78e6ed5afefd1d083688a5dea1f096c 100644 --- a/include/Topology/generic/attribmap.hpp +++ b/include/Topology/generic/attribmap.hpp @@ -44,7 +44,6 @@ inline bool AttribMap::removeAttribute(AttributeHandler& attr) template inline AttributeHandler AttribMap::getAttribute(unsigned int orbit, const std::string& nameAttr) { - assert(isOrbitEmbedded(orbit) || !"Invalid parameter: orbit not embedded"); AttributeMultiVector* amv = m_attribs[orbit].getDataVector(nameAttr) ; return AttributeHandler(this, amv) ; } @@ -77,7 +76,6 @@ inline bool AttribMap::copyAttribute(AttributeHandler& dst, AttributeHandler< inline unsigned int AttribMap::getNbCells(unsigned int orbit) { - assert(isOrbitEmbedded(orbit) || !"Invalid parameter: orbit not embedded"); return this->m_attribs[orbit].size() ; } @@ -88,7 +86,6 @@ inline unsigned int AttribMap::getNbCells(unsigned int orbit) inline AttributeMultiVector* AttribMap::addRelation(const std::string& name) { AttributeContainer& cont = m_attribs[DART_ORBIT] ; - AttributeMultiVector* amv = cont.addAttribute(name) ; // set new relation to fix point for all the darts of the map diff --git a/include/Topology/generic/attributeHandler.h b/include/Topology/generic/attributeHandler.h index 7673a9a16989bef9c21df29be54117cacaf49056..1d7f59e0ffb3330ab26d0f79c56a6710f42f3701 100644 --- a/include/Topology/generic/attributeHandler.h +++ b/include/Topology/generic/attributeHandler.h @@ -43,8 +43,6 @@ namespace CGoGN template class AttributeHandler { - friend class AttribMap ; - protected: // we need the map to use dart as index GenericMap* m_map; @@ -52,19 +50,17 @@ protected: // access to the data AttributeMultiVector* m_attrib; -protected: +public: + typedef T DATA_TYPE ; + /** * Constructor * @param m the map which belong attribute - * @param orbit orbit of attribute - * @param orbit index of attribute + * @param amv a pointer to the AttributeMultiVector */ AttributeHandler(GenericMap* m, AttributeMultiVector* amv) ; -public: - typedef T DATA_TYPE ; - - AttributeHandler() : m_map(NULL), m_attrib(NULL) {} + AttributeHandler() ; /** * Copy constructor diff --git a/include/Topology/generic/attributeHandler.hpp b/include/Topology/generic/attributeHandler.hpp index f659befff568483e595468934057a491a0bb7d3c..db1139f2ff004723f306d0a9834cbaf1c1d31938 100644 --- a/include/Topology/generic/attributeHandler.hpp +++ b/include/Topology/generic/attributeHandler.hpp @@ -30,6 +30,11 @@ AttributeHandler::AttributeHandler(GenericMap* m, AttributeMultiVector* am m_map(m), m_attrib(amv) {} +template +AttributeHandler::AttributeHandler(): + m_map(NULL), m_attrib(NULL) +{} + template AttributeHandler::AttributeHandler(const AttributeHandler& ta): m_map(ta.m_map), m_attrib(ta.m_attrib) @@ -79,9 +84,9 @@ const std::string& AttributeHandler::name() const template bool AttributeHandler::isValid() const { - return (m_map != NULL && - m_attrib != NULL && - m_attrib->getIndex() != AttributeContainer::UNKNOWN) ; + return !(m_map == NULL || + m_attrib == NULL || + m_attrib->getIndex() == AttributeContainer::UNKNOWN) ; } template diff --git a/include/Topology/generic/genericmap.h b/include/Topology/generic/genericmap.h index a2d1d079c2ab74cfd80fc512d848e60f5d1b775d..f672d3056a7ae7e155b509c6d84f28da8cb9a97c 100644 --- a/include/Topology/generic/genericmap.h +++ b/include/Topology/generic/genericmap.h @@ -84,7 +84,7 @@ protected: */ AttributeContainer m_attribs[NB_ORBITS] ; - static std::map< std::string, RegisteredBaseAttribute* >* m_attributes_registry_map ; + static std::map* m_attributes_registry_map ; /** * Direct access to the Dart attributes that store the orbits embeddings @@ -272,17 +272,16 @@ protected: * @param orbit the orbit of cell to use (xxx_ORBIT) * @return the marker to use */ - Marker getNewMarker(unsigned int cell = DART_ORBIT, unsigned int thread=0); + Marker getNewMarker(unsigned int cell = DART_ORBIT, unsigned int thread = 0); /** * release a marker of cell. * @param m the marker to release */ - void releaseMarker(Marker m, unsigned int thread=0); - + void releaseMarker(Marker m, unsigned int thread = 0); /**************************************** - * THREAD MANAGEMENT * + * THREAD MANAGEMENT * ****************************************/ public: /** @@ -304,7 +303,6 @@ public: */ void removeThreadMarker(unsigned int nb); - /**************************************** * SAVE & LOAD * ****************************************/ @@ -384,13 +382,13 @@ public: * @param d a dart of the orbit * @param f a functor obj */ - bool foreach_dart_of_orbit(unsigned int orbit, Dart d, FunctorType& f, unsigned int thread=0); + bool foreach_dart_of_orbit(unsigned int orbit, Dart d, FunctorType& f, unsigned int thread = 0); - virtual bool foreach_dart_of_vertex(Dart d, FunctorType& f, unsigned int thread=0) = 0; - virtual bool foreach_dart_of_edge(Dart d, FunctorType& f, unsigned int thread=0) = 0; - virtual bool foreach_dart_of_face(Dart d, FunctorType& f, unsigned int thread=0) = 0; - virtual bool foreach_dart_of_volume(Dart d, FunctorType& f, unsigned int thread=0) = 0; - virtual bool foreach_dart_of_cc(Dart d, FunctorType& f, unsigned int thread=0) = 0; + virtual bool foreach_dart_of_vertex(Dart d, FunctorType& f, unsigned int thread = 0) = 0; + virtual bool foreach_dart_of_edge(Dart d, FunctorType& f, unsigned int thread = 0) = 0; + virtual bool foreach_dart_of_face(Dart d, FunctorType& f, unsigned int thread = 0) = 0; + virtual bool foreach_dart_of_volume(Dart d, FunctorType& f, unsigned int thread = 0) = 0; + virtual bool foreach_dart_of_cc(Dart d, FunctorType& f, unsigned int thread = 0) = 0; /** * execute functor for each orbit @@ -398,7 +396,7 @@ public: * @param f the functor * @param good the selector of darts */ - bool foreach_orbit(unsigned int orbit, FunctorType& f, const FunctorSelect& good = SelectorTrue(),unsigned int thread=0); + bool foreach_orbit(unsigned int orbit, FunctorType& f, const FunctorSelect& good = SelectorTrue(), unsigned int thread = 0); //! Count the number of orbits of dimension dim in the map /*! @param dim the dimension of the orbit diff --git a/include/Topology/generic/genericmap.hpp b/include/Topology/generic/genericmap.hpp index bfd6f5d88bbb345be271c745110ddb46c696a3f9..421025fd91885926c341d213076e746826f88cdf 100644 --- a/include/Topology/generic/genericmap.hpp +++ b/include/Topology/generic/genericmap.hpp @@ -242,9 +242,7 @@ inline void GenericMap::swapEmbeddingContainers(unsigned int orbit1, unsigned in m_attribs[orbit1].setOrbit(orbit1) ; // to update the orbit information m_attribs[orbit2].setOrbit(orbit2) ; // in the contained AttributeMultiVectors - AttributeMultiVector* e = m_embeddings[orbit1] ; - m_embeddings[orbit1] = m_embeddings[orbit2] ; - m_embeddings[orbit2] = e ; + m_embeddings[orbit1]->swap(m_embeddings[orbit2]) ; for(unsigned int t = 0; t < m_nbThreads; ++t) { diff --git a/include/Topology/map/map2.h b/include/Topology/map/map2.h index eb7df4cf73dba8cb48af1f528b901f3f964f9c9b..20cffa05740f4a67d6ebf9cfcf91d9c2297a4720 100644 --- a/include/Topology/map/map2.h +++ b/include/Topology/map/map2.h @@ -235,13 +235,6 @@ public: * @param marker */ void closeMap(DartMarker& marker); - - // TODO a mettre en algo - /** - * Reverse orientation of map (reverse orientation of all faces) - * no dart created, each dart keeps its embedding, only changing phi1 and phi2 - */ - void reverseOrientation(); //@} /*! @name Topological Queries diff --git a/src/Container/attributeContainer.cpp b/src/Container/attributeContainer.cpp index 3afbce3904ec750eb42b2030b485e4555f248150..c0c3dd192a8a860d3d2221d73485440cb6571607 100644 --- a/src/Container/attributeContainer.cpp +++ b/src/Container/attributeContainer.cpp @@ -125,8 +125,7 @@ const std::string& AttributeContainer::getAttributeName(unsigned int index) assert(index < m_tableAttribs.size() || !"getAttributeName: attribute index out of bounds"); assert(m_tableAttribs[index] != NULL || !"getAttributeName: attribute does not exist"); - if(m_tableAttribs[index] != NULL) - return m_tableAttribs[index]->getName() ; + return m_tableAttribs[index]->getName() ; } template diff --git a/src/Topology/generic/attribmap.cpp b/src/Topology/generic/attribmap.cpp index f6e4a6b04de8fc5b4d2d21aa0cec4e472fc3fa91..ed6b6d9d4dcd04ec2156d8d964b2f93809559fc7 100644 --- a/src/Topology/generic/attribmap.cpp +++ b/src/Topology/generic/attribmap.cpp @@ -56,7 +56,9 @@ void AttribMap::addEmbedding(unsigned int orbit) AttributeContainer& cellCont = m_attribs[orbit]; for (unsigned int t = 0; t < m_nbThreads; ++t) { - AttributeMultiVector* amvMark = cellCont.addAttribute("Mark") ; + std::stringstream ss ; + ss << "Mark_"<< t ; + AttributeMultiVector* amvMark = cellCont.addAttribute(ss.str()) ; m_markerTables[orbit][t] = amvMark ; } } diff --git a/src/Topology/generic/genericmap.cpp b/src/Topology/generic/genericmap.cpp index b722768b119da63985382debaa4bc0e30ef201ff..5ed1c2c94b29103056098163308b011e2d039141 100644 --- a/src/Topology/generic/genericmap.cpp +++ b/src/Topology/generic/genericmap.cpp @@ -33,8 +33,7 @@ namespace CGoGN std::map* GenericMap::m_attributes_registry_map = NULL ; -GenericMap::GenericMap() -:m_nbThreads(1) +GenericMap::GenericMap() : m_nbThreads(1) { if(m_attributes_registry_map == NULL) m_attributes_registry_map = new std::map ; @@ -114,7 +113,6 @@ void GenericMap::setDartEmbedding(unsigned int orbit, Dart d, unsigned int emb) (*m_embeddings[orbit])[d.index] = emb ; } - /**************************************** * ATTRIBUTES MANAGEMENT * ****************************************/ @@ -150,6 +148,58 @@ bool GenericMap::registerAttribute(const std::string &nameType) return true; } +/**************************************** + * THREAD MANAGEMENT * + ****************************************/ + +void GenericMap::addThreadMarker(unsigned int nb) +{ + unsigned int th ; + + for (unsigned int j = 0; j < nb; ++j) + { + th = m_nbThreads ; + m_nbThreads++ ; + + for (unsigned int i = 0; i < NB_ORBITS; ++i) + { + if (isOrbitEmbedded(i)) + { + std::stringstream ss ; + ss << "Mark_"<< th ; + AttributeContainer& cellCont = m_attribs[i] ; + AttributeMultiVector* amvMark = cellCont.addAttribute(ss.str()) ; + m_markerTables[i][th] = amvMark ; + } + } + } +} + +unsigned int GenericMap::getNbThreadMarkers() +{ + return m_nbThreads; +} + +void GenericMap::removeThreadMarker(unsigned int nb) +{ + unsigned int th = 0; + while ((m_nbThreads > 1) && (nb > 0)) + { + th = --m_nbThreads ; + --nb; + for (unsigned int i = 0; i < NB_ORBITS; ++i) + { + if (isOrbitEmbedded(i)) + { + std::stringstream ss ; + ss << "Mark_"<< th ; + AttributeContainer& cellCont = m_attribs[i] ; + cellCont.removeAttribute(ss.str()) ; + m_markerTables[i][th] = NULL ; + } + } + } +} /**************************************** * SAVE & LOAD * @@ -464,7 +514,6 @@ bool GenericMap::loadMapBin(const std::string& filename) return true; } - /**************************************** * DARTS TRAVERSALS * ****************************************/ @@ -524,55 +573,4 @@ unsigned int GenericMap::getNbOrbits(unsigned int orbit, const FunctorSelect& go return fcount.getNb(); } -void GenericMap::addThreadMarker(unsigned int nb) -{ - unsigned int th ; - - for (unsigned int j = 0; j < nb; ++j) - { - th = m_nbThreads ; - m_nbThreads++ ; - - for (unsigned int i = 0; i < NB_ORBITS; ++i) - { - if (isOrbitEmbedded(i)) - { - AttributeContainer& cellCont = m_attribs[i] ; - std::stringstream ss ; - ss << "Mark_"<< th ; - AttributeMultiVector* amvMark = cellCont.addAttribute(ss.str()) ; - m_markerTables[i][th] = amvMark ; - } - } - } -} - -unsigned int GenericMap::getNbThreadMarkers() -{ - return m_nbThreads; -} - -void GenericMap::removeThreadMarker(unsigned int nb) -{ - unsigned int th = 0; - while ((m_nbThreads > 1) && (nb > 0)) - { - th = --m_nbThreads ; - --nb; - for (unsigned int i = 0; i < NB_ORBITS; ++i) - { - if (isOrbitEmbedded(i)) - { - AttributeContainer& cellCont = m_attribs[i] ; - std::stringstream ss ; - ss << "Mark_"<< th ; - cellCont.removeAttribute(ss.str()) ; - m_markerTables[i][th] = NULL ; - } - } - } -} - - - } // namespace CGoGN diff --git a/src/Topology/map/map2.cpp b/src/Topology/map/map2.cpp index 324f47fc270bd8c626ce22d5c6731506946c36eb..a99546240de47482d5d0bf89b89f97189b729dbd 100644 --- a/src/Topology/map/map2.cpp +++ b/src/Topology/map/map2.cpp @@ -353,46 +353,6 @@ void Map2::closeMap(DartMarker& marker) } } -void Map2::reverseOrientation() -{ - DartMarkerNoUnmark mf(*this); - - // reverse all faces (only phi1 is modified) - for (Dart d = begin(); d != end(); next(d)) - { - if (!mf.isMarked(d)) - { - reverseFace(d); - mf.markOrbit(FACE_ORBIT, d); - } - } - - // store all new phi2 - std::vector vd; - vd.reserve(getNbDarts()); - for (Dart d = begin(); d != end(); next(d)) - { - Dart e = phi_1(phi2(phi1(d))); - vd.push_back(e); - } - - // apply the phi2sew with stored phi2 on all darts - std::vector::iterator id = vd.begin(); - for (Dart d = begin(); d != end(); next(d),++id) - { - if (mf.isMarked(d)) - { - mf.unmark(d); // unmark the two darts - mf.unmark(*id); - if (phi2(d) != d) - phi2unsew(d); // unsew the two darts if necessary - if (phi2(*id) != *id) - phi2unsew(*id); - phi2sew(d, *id); // sew the darts - } - } -} - /*! @name Topological Queries * Return or set various topological information *************************************************************************/