From b50afe0333b3a9a0e3e0f53010ec412db4fd6998 Mon Sep 17 00:00:00 2001 From: Sylvain Thery Date: Tue, 13 May 2014 18:36:14 +0200 Subject: [PATCH] bugfix in copyFrom & copy constructors of maps in protected --- Apps/Tuto/Modelling/basics.cpp | 76 --------------------- Apps/Tuto/tuto_subdivision.cpp | 38 ++++++++--- include/Container/attributeContainer.h | 4 +- include/Topology/generic/genericmap.h | 3 + include/Topology/generic/mapCommon.h | 9 +++ include/Topology/generic/mapImpl/mapMono.h | 3 + include/Topology/generic/mapImpl/mapMulti.h | 3 + include/Topology/gmap/embeddedGMap2.h | 3 + include/Topology/gmap/embeddedGMap3.h | 3 + include/Topology/gmap/gmap0.h | 3 + include/Topology/gmap/gmap1.h | 3 + include/Topology/gmap/gmap2.h | 3 + include/Topology/gmap/gmap3.h | 3 + include/Topology/map/embeddedMap2.h | 4 ++ include/Topology/map/embeddedMap3.h | 4 ++ include/Topology/map/map1.h | 3 + include/Topology/map/map2.h | 3 + include/Topology/map/map3.h | 3 + src/Container/attributeContainer.cpp | 40 +++++++---- src/Topology/generic/genericmap.cpp | 8 +-- 20 files changed, 113 insertions(+), 106 deletions(-) diff --git a/Apps/Tuto/Modelling/basics.cpp b/Apps/Tuto/Modelling/basics.cpp index 79354f45..98c10514 100644 --- a/Apps/Tuto/Modelling/basics.cpp +++ b/Apps/Tuto/Modelling/basics.cpp @@ -47,81 +47,6 @@ typedef PFP::MAP::IMPL MAP_IMPL ; // map implementation typedef PFP::VEC3 VEC3 ; // type of R³ vector - -// example of cell marking with CellMarker for a simple traversal -template -void simpleTraversal(MAP& map) // NEVER COPY THE MAP, ALWAYS USE REFERENCE !! -{ - CellMarker cm(map); - for (Dart d = map.begin(); d != map.end(); map.next(d)) - { - if (!cm.isMarked(d)) // is the cell (of dart d) not marked ? - { - std::cout << orbitName(ORBIT)<< " of dart "<< d << std::endl; - cm.mark(d); // mark the cell - } - } - std::cout << std::endl; - - // all cells are unmarked automatically during the destruction of the CellMarker -} - - - -// example of cell marking with CellMarkerNoUnmark for a double traversal -template -void doubleTraversal(MAP& map) // NEVER COPY THE MAP, ALWAYS USE REFERENCE !! -{ - CellMarkerNoUnmark cm(map); - for (Dart d = map.begin(); d != map.end(); map.next(d)) - { - if (!cm.isMarked(d)) // is the cell (of dart d) not marked ? - { - std::cout << "First Pass" << orbitName(ORBIT)<< " of dart "<< d << std::endl; - cm.mark(d); // mark the cell - } - } - std::cout << std::endl; - - for (Dart d = map.begin(); d != map.end(); map.next(d)) - { - if (cm.isMarked(d)) // is the cell (of dart d) marked ? - { - std::cout << "second Pass" << orbitName(ORBIT)<< " of dart "<< d << std::endl; - cm.unmark(d); // unmark the cell - } - } - std::cout << std::endl; - - // destructor does not clean the markers - // user MUST ensure that he has unmark all he has marked -} - - - - -// example of usage of CellMarkerStore -void negativePositions(MAP& map, VertexAttribute& position) // NEVER COPY THE MAP, ALWAYS USE REFERENCE !! -{ - // if user knows that small numbers of cell will be marked - // it is more efficient to store them instead of traverse - // all darts for cleanning. CellMarkerStore do it for you. - - CellMarkerStore cms(map); - - for (Dart d = map.begin(); d != map.end(); map.next(d)) - { - if (!cms.isMarked(d) && (position[d][0]<= 0.0) && (position[d][1]<= 0.0)) - { - std::cout << "position["<(f2.dart)] = VEC3(0, -2, 0); position[myMap.phi_1(f2.dart)] = VEC3(2, -2, 0); - return 0; } diff --git a/Apps/Tuto/tuto_subdivision.cpp b/Apps/Tuto/tuto_subdivision.cpp index 89b1f10b..02788c3b 100644 --- a/Apps/Tuto/tuto_subdivision.cpp +++ b/Apps/Tuto/tuto_subdivision.cpp @@ -50,19 +50,20 @@ typedef PFP::MAP MAP ; typedef PFP::MAP::IMPL MAP_IMPL ; typedef PFP::VEC3 VEC3 ; +void pipo(PFP::MAP& m) +{ + std::cout << m.getNbDarts()<< std::endl; +} + + int main(int argc, char **argv) { if(argc != 3) { - CGoGNout << "Usage : " << argv[0] << " filename nbSteps" << CGoGNendl; - return 0; + CGoGNerr << "Usage : " << argv[0] << " filename nbSteps" << CGoGNendl; + return 1; } - - std::string filename(argv[1]); - - unsigned int nbSteps; - std::istringstream iss(argv[2]); - iss >> nbSteps; + unsigned int nbSteps = atoi(argv[2]); // declaration of the map MAP myMap; @@ -70,13 +71,30 @@ int main(int argc, char **argv) std::vector attrNames ; Algo::Surface::Import::importMesh(myMap, argv[1], attrNames); - // get a handler to the 3D vector attribute created by the import + // get a handler to the 3D vector attribute created by the import (position always the first) VertexAttribute position = myMap.getAttribute(attrNames[0]); + // a second map + MAP myMap2; + // for copying the initial mesh + myMap2.copyFrom(myMap); + // AttributeHandler are linked to the map, need a new one + VertexAttribute position2 = myMap2.getAttribute(attrNames[0]); + + // subdivide first map with Loop algo for(unsigned int i = 0; i < nbSteps; ++i) Algo::Surface::Modelisation::LoopSubdivision(myMap, position); - Algo::Surface::Export::exportOFF(myMap, position, "result.off"); + // and export to file + Algo::Surface::Export::exportOFF(myMap, position, "resultLoop.off"); + + // subdivide second map with CatmullClark (using map2/position2) + for(unsigned int i = 0; i < nbSteps; ++i) + Algo::Surface::Modelisation::CatmullClarkSubdivision(myMap2, position2); + + // and export to file (using map2/position2) + Algo::Surface::Export::exportOFF(myMap2, position2, "resultCC.off"); + return 0; } diff --git a/include/Container/attributeContainer.h b/include/Container/attributeContainer.h index acbd605c..0b6b1f93 100644 --- a/include/Container/attributeContainer.h +++ b/include/Container/attributeContainer.h @@ -273,7 +273,7 @@ public: /** * get the name of an attribute, given its index in the container */ - const std::string& getAttributeName(unsigned int attrIndex); + const std::string& getAttributeName(unsigned int attrIndex) const; /** * fill a vector with pointers to the blocks of the given attribute @@ -290,7 +290,7 @@ public: * @param names vector of names * @return number of attributes */ - unsigned int getAttributesNames(std::vector& names); + unsigned int getAttributesNames(std::vector& names) const; /** * fill a vector with attribute type names diff --git a/include/Topology/generic/genericmap.h b/include/Topology/generic/genericmap.h index 049424f4..ef2bf6ff 100644 --- a/include/Topology/generic/genericmap.h +++ b/include/Topology/generic/genericmap.h @@ -87,6 +87,9 @@ class GenericMap template friend class CellMarkerBase ; protected: + // protected copy constructor to prevent the copy of map + GenericMap(const GenericMap& ) {} + /** * Attributes Containers */ diff --git a/include/Topology/generic/mapCommon.h b/include/Topology/generic/mapCommon.h index 3801c3ec..4294c7f4 100644 --- a/include/Topology/generic/mapCommon.h +++ b/include/Topology/generic/mapCommon.h @@ -36,6 +36,12 @@ class MapCommon : public MAP_IMPL { typedef MAP_IMPL IMPL; +protected: + // protected copy constructor to prevent the copy of map + MapCommon(const MapCommon& m) : MAP_IMPL(m) {} +public: + MapCommon() {} + /**************************************** * DARTS TRAVERSALS * ****************************************/ @@ -127,7 +133,10 @@ public: /**************************************** * BOUNDARY MANAGEMENT * ****************************************/ + protected: + + /** * mark a dart as belonging to boundary */ diff --git a/include/Topology/generic/mapImpl/mapMono.h b/include/Topology/generic/mapImpl/mapMono.h index 296392bb..ee810094 100644 --- a/include/Topology/generic/mapImpl/mapMono.h +++ b/include/Topology/generic/mapImpl/mapMono.h @@ -42,6 +42,9 @@ public: inline virtual void clear(bool removeAttrib); protected: + // protected copy constructor to prevent the copy of map + MapMono(const MapMono& m): GenericMap(m){} + std::vector*> m_involution; std::vector*> m_permutation; std::vector*> m_permutation_inv; diff --git a/include/Topology/generic/mapImpl/mapMulti.h b/include/Topology/generic/mapImpl/mapMulti.h index 7cf970e8..4f483133 100644 --- a/include/Topology/generic/mapImpl/mapMulti.h +++ b/include/Topology/generic/mapImpl/mapMulti.h @@ -44,6 +44,9 @@ public: inline virtual void clear(bool removeAttrib); protected: + // protected copy constructor to prevent the copy of map + MapMulti(const MapMulti& m): GenericMap(m) {} + std::vector*> m_involution; std::vector*> m_permutation; std::vector*> m_permutation_inv; diff --git a/include/Topology/gmap/embeddedGMap2.h b/include/Topology/gmap/embeddedGMap2.h index 4ce00269..723f104e 100644 --- a/include/Topology/gmap/embeddedGMap2.h +++ b/include/Topology/gmap/embeddedGMap2.h @@ -37,12 +37,15 @@ namespace CGoGN */ class EmbeddedGMap2 : public GMap2 { + EmbeddedGMap2(const EmbeddedGMap2& m):GMap2(m) {} public: typedef MapMono IMPL; typedef GMap2 TOPO_MAP; static const unsigned int DIMENSION = TOPO_MAP::DIMENSION ; + EmbeddedGMap2() {} + /** * create a new face with managed embeddings */ diff --git a/include/Topology/gmap/embeddedGMap3.h b/include/Topology/gmap/embeddedGMap3.h index 209be4fa..49380744 100644 --- a/include/Topology/gmap/embeddedGMap3.h +++ b/include/Topology/gmap/embeddedGMap3.h @@ -37,12 +37,15 @@ namespace CGoGN */ class EmbeddedGMap3 : public GMap3 { + EmbeddedGMap3(const EmbeddedGMap3& m):GMap3(m) {} public: typedef MapMono IMPL; typedef GMap3 TOPO_MAP; static const unsigned int DIMENSION = TOPO_MAP::DIMENSION ; + EmbeddedGMap3() {} + /*! * */ diff --git a/include/Topology/gmap/gmap0.h b/include/Topology/gmap/gmap0.h index 73d2f68d..f83a99e6 100644 --- a/include/Topology/gmap/gmap0.h +++ b/include/Topology/gmap/gmap0.h @@ -40,6 +40,9 @@ template class GMap0 : public MapCommon { protected: + // protected copy constructor to prevent the copy of map + GMap0(const GMap0& m):MapCommon(m) {} + void init() ; public: diff --git a/include/Topology/gmap/gmap1.h b/include/Topology/gmap/gmap1.h index 889aaf3f..971e9e0d 100644 --- a/include/Topology/gmap/gmap1.h +++ b/include/Topology/gmap/gmap1.h @@ -37,6 +37,9 @@ template class GMap1 : public GMap0 { protected: + // protected copy constructor to prevent the copy of map + GMap1(const GMap1& m):GMap0(m) {} + void init() ; public: diff --git a/include/Topology/gmap/gmap2.h b/include/Topology/gmap/gmap2.h index 1214ce09..a73910d7 100644 --- a/include/Topology/gmap/gmap2.h +++ b/include/Topology/gmap/gmap2.h @@ -37,6 +37,9 @@ template class GMap2 : public GMap1 { protected: + // protected copy constructor to prevent the copy of map + GMap2(const GMap2& m):GMap1(m) {} + void init() ; public: diff --git a/include/Topology/gmap/gmap3.h b/include/Topology/gmap/gmap3.h index 78c449b8..21ce52e7 100644 --- a/include/Topology/gmap/gmap3.h +++ b/include/Topology/gmap/gmap3.h @@ -37,6 +37,9 @@ template class GMap3 : public GMap2 { protected: + // protected copy constructor to prevent the copy of map + GMap3(const GMap3& m):GMap2(m) {} + void init() ; public: diff --git a/include/Topology/map/embeddedMap2.h b/include/Topology/map/embeddedMap2.h index 9a0f73c2..5f7a6cb9 100644 --- a/include/Topology/map/embeddedMap2.h +++ b/include/Topology/map/embeddedMap2.h @@ -37,12 +37,16 @@ namespace CGoGN */ class EmbeddedMap2 : public Map2 { + + EmbeddedMap2(const EmbeddedMap2& m):Map2(m) {} public: typedef MapMono IMPL; typedef Map2 TOPO_MAP; static const unsigned int DIMENSION = TOPO_MAP::DIMENSION ; + EmbeddedMap2() {} + /* */ Dart newPolyLine(unsigned int nbEdges) ; diff --git a/include/Topology/map/embeddedMap3.h b/include/Topology/map/embeddedMap3.h index b82abb85..f04c9209 100644 --- a/include/Topology/map/embeddedMap3.h +++ b/include/Topology/map/embeddedMap3.h @@ -35,12 +35,16 @@ namespace CGoGN */ class EmbeddedMap3 : public Map3 { + EmbeddedMap3(const EmbeddedMap3& m):Map3(m) {} public: typedef MapMono IMPL; typedef Map3 TOPO_MAP; static const unsigned int DIMENSION = TOPO_MAP::DIMENSION ; + + EmbeddedMap3() {} + //! /*! * diff --git a/include/Topology/map/map1.h b/include/Topology/map/map1.h index b404c354..4773d816 100644 --- a/include/Topology/map/map1.h +++ b/include/Topology/map/map1.h @@ -44,6 +44,9 @@ template class Map1 : public MapCommon { protected: + // protected copy constructor to prevent the copy of map + Map1(const Map1& m):MapCommon(m) {} + void init() ; public: diff --git a/include/Topology/map/map2.h b/include/Topology/map/map2.h index 221b0a47..0a9a98de 100644 --- a/include/Topology/map/map2.h +++ b/include/Topology/map/map2.h @@ -49,6 +49,9 @@ template class Map2 : public Map1 { protected: + // protected copy constructor to prevent the copy of map + Map2(const Map2& m):Map1(m) {} + void init() ; public: diff --git a/include/Topology/map/map3.h b/include/Topology/map/map3.h index 099696ef..3f0a4b9b 100644 --- a/include/Topology/map/map3.h +++ b/include/Topology/map/map3.h @@ -51,6 +51,9 @@ template class Map3 : public Map2 { protected: + // protected copy constructor to prevent the copy of map + Map3(const Map3& m):Map2(m) {} + void init() ; public: diff --git a/src/Container/attributeContainer.cpp b/src/Container/attributeContainer.cpp index 402139dc..cf4c5c13 100644 --- a/src/Container/attributeContainer.cpp +++ b/src/Container/attributeContainer.cpp @@ -83,7 +83,7 @@ unsigned int AttributeContainer::getAttributeIndex(const std::string& attribName return index - 1 ; } -const std::string& AttributeContainer::getAttributeName(unsigned int index) +const std::string& AttributeContainer::getAttributeName(unsigned int index) const { assert(index < m_tableAttribs.size() || !"getAttributeName: attribute index out of bounds"); assert(m_tableAttribs[index] != NULL || !"getAttributeName: attribute does not exist"); @@ -102,7 +102,7 @@ unsigned int AttributeContainer::getAttributeBlocksPointers(unsigned int attrInd return atm->getBlocksPointers(vect_ptr, byteBlockSize); } -unsigned int AttributeContainer::getAttributesNames(std::vector& names) +unsigned int AttributeContainer::getAttributesNames(std::vector& names) const { names.clear() ; names.reserve(m_nbAttributes) ; @@ -752,7 +752,6 @@ bool AttributeContainer::loadBin(CGoGNistream& fs) { RegisteredBaseAttribute* ra = itAtt->second; AttributeMultiVectorGen* amvg = ra->addAttribute(*this, nameAtt); -// CGoGNout << "loading attribute " << nameAtt << " : " << typeAtt << CGoGNendl; amvg->loadBin(fs); } } @@ -790,6 +789,12 @@ void AttributeContainer::copyFrom(const AttributeContainer& cont) for (unsigned int i = 0; i < sz; ++i) m_holesBlocks[i] = new HoleBlockRef(*(cont.m_holesBlocks[i])); + // free indices + sz = cont.m_freeIndices.size(); + m_freeIndices.resize(sz); + for (unsigned int i = 0; i < sz; ++i) + m_freeIndices[i] = cont.m_freeIndices[i]; + // blocks with free sz = cont.m_tableBlocksWithFree.size(); m_tableBlocksWithFree.resize(sz); @@ -809,17 +814,24 @@ void AttributeContainer::copyFrom(const AttributeContainer& cont) { if (cont.m_tableAttribs[i] != NULL) { - AttributeMultiVectorGen* ptr = cont.m_tableAttribs[i]->new_obj(); - ptr->setName(cont.m_tableAttribs[i]->getName()); - ptr->setOrbit(cont.m_tableAttribs[i]->getOrbit()); - ptr->setIndex(m_tableAttribs.size()); - ptr->setNbBlocks(cont.m_tableAttribs[i]->getNbBlocks()); - ptr->copy(cont.m_tableAttribs[i]); - // if (cont.m_tableAttribs[i]->toProcess()) - // ptr->toggleProcess(); - // else - // ptr->toggleNoProcess(); - m_tableAttribs.push_back(ptr); + std::string sub = cont.m_tableAttribs[i]->getName().substr(0, 5); + if (sub != "Mark_") // Mark leaved by + { + AttributeMultiVectorGen* ptr = cont.m_tableAttribs[i]->new_obj(); + ptr->setName(cont.m_tableAttribs[i]->getName()); + ptr->setOrbit(cont.m_tableAttribs[i]->getOrbit()); + ptr->setIndex(m_tableAttribs.size()); + ptr->setNbBlocks(cont.m_tableAttribs[i]->getNbBlocks()); + ptr->copy(cont.m_tableAttribs[i]); + m_tableAttribs.push_back(ptr); + } + else + { + // Mark always the first ! + AttributeMultiVectorGen* ptr = m_tableAttribs[i]; + ptr->setNbBlocks(cont.m_tableAttribs[i]->getNbBlocks()); + ptr->copy(cont.m_tableAttribs[i]); + } } } } diff --git a/src/Topology/generic/genericmap.cpp b/src/Topology/generic/genericmap.cpp index a4a777dd..c7b746fd 100644 --- a/src/Topology/generic/genericmap.cpp +++ b/src/Topology/generic/genericmap.cpp @@ -405,13 +405,13 @@ void GenericMap::restore_shortcuts() { // clear all marks expect boundary marks Mark m(m_boundaryMarkers[0] + m_boundaryMarkers[1]); m.invert(); - for (unsigned int i = cont.begin(); i != cont.end(); cont.next(i)) - amvMark->operator[](i).unsetMark(m); + for (unsigned int k = cont.begin(); k != cont.end(); cont.next(k)) + amvMark->operator[](k).unsetMark(m); } else // for others clear all { - for (unsigned int i = cont.begin(); i != cont.end(); cont.next(i)) - amvMark->operator[](i).clear(); + for (unsigned int k = cont.begin(); k != cont.end(); cont.next(k)) + amvMark->operator[](k).clear(); } } } -- GitLab