diff --git a/include/Algo/Import/importMRDAT.h b/include/Algo/Import/importMRDAT.h index 7b64a0d3abd011a52d7a49002c4c6af8279c6b8d..ed72b880fd583b2924db73e97ae9461c82f3ee90 100644 --- a/include/Algo/Import/importMRDAT.h +++ b/include/Algo/Import/importMRDAT.h @@ -104,7 +104,7 @@ public: // if(oldEmb == EMBNULL) // { //std::cout << "oldEmb == NULL"<< std::endl; - map.template setOrbitEmbedding(dd, newEmb) ; + Algo::Topo::setOrbitEmbedding(map,dd,newEmb); //needed because the darts are duplicated at each level //and the vertex orbits are initialized at the creation of each level with wrong embedding indices @@ -114,7 +114,8 @@ public: for(unsigned int i = map.getCurrentLevel() + 1; i <= map.getMaxLevel(); ++i) { map.setCurrentLevel(i) ; - map.template setOrbitEmbedding(dd, newEmb) ; + Algo::Topo::setOrbitEmbedding(map,dd,newEmb); + } //map.popLevel() ; map.setCurrentLevel(cur); diff --git a/include/Algo/Import/importMRDAT.hpp b/include/Algo/Import/importMRDAT.hpp index 46a6c6042d358a6097521c09e5c42222225a65c4..e9878a1cb8201431870dd179bb8fea95e55a99ea 100644 --- a/include/Algo/Import/importMRDAT.hpp +++ b/include/Algo/Import/importMRDAT.hpp @@ -44,9 +44,9 @@ inline void nextNonEmptyLine(std::ifstream& fp, std::string& line) template bool importMRDAT(typename PFP::MAP& map, const std::string& filename, std::vector& attrNames, QuadTree& qt) { - VertexAttribute position = map.template getAttribute("position") ; + VertexAttribute position = map.template getAttribute("position") ; if (!position.isValid()) - position = map.template addAttribute("position") ; + position = map.template addAttribute("position") ; attrNames.push_back(position.name()) ; @@ -197,7 +197,6 @@ bool importMRDAT(typename PFP::MAP& map, const std::string& filename, std::vecto DartMarkerNoUnmark m(map) ; unsigned int vemb = EMBNULL; - auto fsetemb = [&] (Dart d) { map.template setDartEmbedding(d, vemb); }; unsigned nbf = qt.roots.size() ; @@ -211,7 +210,7 @@ bool importMRDAT(typename PFP::MAP& map, const std::string& filename, std::vecto unsigned int idx = qt.roots[i]->indices[j] ; vemb = qt.verticesID[idx] ; - map.template foreach_dart_of_orbit(d, fsetemb) ; + map.template foreach_dart_of_orbit(d, [&] (Dart dd) { map.template initDartEmbedding(dd, vemb); }); m.mark(d) ; // mark on the fly to unmark on second loop vecDartsPerVertex[vemb].push_back(d) ; // store incident darts for fast adjacency reconstruction diff --git a/include/Algo/Modelisation/subdivision.hpp b/include/Algo/Modelisation/subdivision.hpp index f99ada42d9e27a3b04e2dda38cd322a07f54c84d..80b7134a90ed02c289f83c6f0e7bbe6124de6b62 100644 --- a/include/Algo/Modelisation/subdivision.hpp +++ b/include/Algo/Modelisation/subdivision.hpp @@ -582,8 +582,8 @@ void DooSabin(typename PFP::MAP& map, EMBV& position) // take care of edge embedding if(map.template isOrbitEmbedded()) { - map.template setOrbitEmbedding(nf, map.template getEmbedding(e)); - map.template setOrbitEmbedding(map.template phi<11>(nf), map.template getEmbedding(e2)); + Algo::Topo::setOrbitEmbedding(map, nf, map.template getEmbedding(e)); + Algo::Topo::setOrbitEmbedding(map, map.template phi<11>(nf), map.template getEmbedding(e2)); } dm.markOrbit(nf); @@ -608,7 +608,8 @@ void DooSabin(typename PFP::MAP& map, EMBV& position) Dart d = df; do { - map.template setOrbitEmbedding(d,map.template getEmbedding(map.phi2(d))); +// map.template setOrbitEmbedding(d,map.template getEmbedding(map.phi2(d))); + Algo::Topo::setOrbitEmbedding(map, d, map.template getEmbedding(map.phi2(d))); d = map.phi1(d); } while (d != df); } @@ -646,7 +647,8 @@ void DooSabin(typename PFP::MAP& map, EMBV& position) P+= c2*buffer[j]; } } - map.template setOrbitEmbeddingOnNewCell(e); +// map.template setOrbitEmbeddingOnNewCell(e); + Algo::Topo::setOrbitEmbeddingOnNewCell(map,e); position[e] = P; e = map.phi1(e); } @@ -730,9 +732,9 @@ void computeDual(typename PFP::MAP& map, VertexAttribute after dual new Vertex Attribute - FaceAttribute positionF = map.template getAttribute("position") ; + FaceAttribute positionF = map.template getAttribute("position") ; if(!positionF.isValid()) - positionF = map.template addAttribute("position") ; + positionF = map.template addAttribute("position") ; // Compute Centroid for the faces Algo::Surface::Geometry::computeCentroidFaces(map, position, positionF) ; @@ -752,9 +754,9 @@ void computeBoundaryConstraintDual(typename PFP::MAP& map, VertexAttribute after dual new Vertex Attribute - FaceAttribute positionF = map.template getAttribute("position") ; + FaceAttribute positionF = map.template getAttribute("position") ; if(!positionF.isValid()) - positionF = map.template addAttribute("position") ; + positionF = map.template addAttribute("position") ; //Triangule boundary faces & compute for each new face the centroid std::vector boundsDart; @@ -823,9 +825,9 @@ void computeBoundaryConstraintKeepingOldVerticesDual(typename PFP::MAP& map, Ver typedef typename PFP::REAL REAL ; // Face Attribute -> after dual new Vertex Attribute - FaceAttribute positionF = map.template getAttribute("position") ; + FaceAttribute positionF = map.template getAttribute("position") ; if(!positionF.isValid()) - positionF = map.template addAttribute("position") ; + positionF = map.template addAttribute("position") ; //Triangule boundary faces & compute for each new face the centroid std::vector boundsDart; diff --git a/include/Algo/Multiresolution/Map2MR/map2MR_DualRegular.hpp b/include/Algo/Multiresolution/Map2MR/map2MR_DualRegular.hpp index 7516087f7f53ab7958b20822caaeafe6831932ee..3faf811a58357c1f85ea2b1f9959959651589dba 100644 --- a/include/Algo/Multiresolution/Map2MR/map2MR_DualRegular.hpp +++ b/include/Algo/Multiresolution/Map2MR/map2MR_DualRegular.hpp @@ -22,6 +22,8 @@ * * *******************************************************************************/ +#include "Algo/Topo/embedding.h" + namespace CGoGN { @@ -87,8 +89,10 @@ void Map2MR::addNewLevel(bool embedNewVertices) // take care of edge embedding if(m_map.template isOrbitEmbedded()) { - m_map.template setOrbitEmbedding(nf, m_map.template getEmbedding(d)); - m_map.template setOrbitEmbedding(m_map.phi1(m_map.phi1(nf)), m_map.template getEmbedding(d2)); +// m_map.template setOrbitEmbedding(nf, m_map.template getEmbedding(d)); +// m_map.template setOrbitEmbedding(m_map.phi1(m_map.phi1(nf)), m_map.template getEmbedding(d2)); + Algo::Topo::setOrbitEmbedding(m_map, nf, m_map.template getEmbedding(d)); + Algo::Topo::setOrbitEmbedding(m_map, m_map.phi1(m_map.phi1(nf)), m_map.template getEmbedding(d2)); } m_map.decCurrentLevel(); @@ -109,13 +113,15 @@ void Map2MR::addNewLevel(bool embedNewVertices) { if(m_map.template isOrbitEmbedded()) { - m_map.template setOrbitEmbedding(temp, m_map.template getEmbedding( m_map.phi2(temp))); +// m_map.template setOrbitEmbedding(temp, m_map.template getEmbedding( m_map.phi2(temp))); + Algo::Topo::setOrbitEmbedding(m_map, temp, m_map.template getEmbedding( m_map.phi2(temp))); } if(!shareVertexEmbeddings) { //if(m_map.template getEmbedding(d) == EMBNULL) - m_map.template setOrbitEmbeddingOnNewCell(temp) ; + Algo::Topo::setOrbitEmbeddingOnNewCell(m_map, temp); + //m_map.template setOrbitEmbeddingOnNewCell(d2) ; } diff --git a/include/Topology/generic/mapImpl/mapMulti.h b/include/Topology/generic/mapImpl/mapMulti.h index 30f525b162cfb9b56038e9fb2b71aca0b762fe5e..de3e9c30078b91d3476fc3fe001e5f411c6add6d 100644 --- a/include/Topology/generic/mapImpl/mapMulti.h +++ b/include/Topology/generic/mapImpl/mapMulti.h @@ -30,6 +30,8 @@ namespace CGoGN { +class MapMono; + class MapMulti : public GenericMap { template friend class DartMarkerTmpl ; @@ -301,6 +303,8 @@ public: bool copyFrom(const GenericMap& map); + bool copyFromOtherType(const MapMono& map); + void restore_topo_shortcuts(); } ; diff --git a/include/Topology/map/map2.hpp b/include/Topology/map/map2.hpp index 9ea582d3dc0767115eb92de4c719667401ad4eed..fb04d8acb7a80995bcf2acc056c53a4224022eb8 100644 --- a/include/Topology/map/map2.hpp +++ b/include/Topology/map/map2.hpp @@ -243,7 +243,7 @@ template void Map2::createHole(Dart d) { assert(!isBoundaryEdge(d)) ; - this->template boundaryMarkOrbit<2,FACE>(d) ; + Algo::Topo::boundaryMarkOrbit<2,FACE>(*this, d) ; } /*! @name Topological Operators diff --git a/src/Topology/generic/mapMono.cpp b/src/Topology/generic/mapMono.cpp index 0550cf5a07efb2ec68ac7c2f61753eb34560633b..5eb36920d90ee21164e06f5c3704a9c11154b041 100644 --- a/src/Topology/generic/mapMono.cpp +++ b/src/Topology/generic/mapMono.cpp @@ -193,6 +193,9 @@ void MapMono::restore_topo_shortcuts() void MapMono::compactTopo() { + if (fragmentation(DART)==1.0) + return; + std::vector oldnew; m_attribs[DART].compact(oldnew); diff --git a/src/Topology/generic/mapMulti.cpp b/src/Topology/generic/mapMulti.cpp index d36251eb545da673868eb6ee930fb5ba74ed03d9..f79ba47199146fa8fa6de085320b383f4afc4fcf 100644 --- a/src/Topology/generic/mapMulti.cpp +++ b/src/Topology/generic/mapMulti.cpp @@ -23,6 +23,7 @@ *******************************************************************************/ #include "Topology/generic/mapImpl/mapMulti.h" +#include "Topology/generic/mapImpl/mapMono.h" namespace CGoGN { @@ -313,31 +314,77 @@ bool MapMulti::loadMapBin(const std::string& filename) return true; } + +bool MapMulti::copyFromOtherType(const MapMono& mapMR) +{ +// map.compactIfNeeded(1.0); + + // clear the map but do not insert boundary markers dart attribute + GenericMap::init(false); + + // init MR data + initMR(); + + // copy attrib containers from MapMono + for (unsigned int i = 0; i < NB_ORBITS; ++i) + m_attribs[i].copyFrom(mapMR.getAttributeContainer(i)); + + // restore shortcuts + GenericMap::restore_shortcuts(); + restore_topo_shortcuts(); + + AttributeContainer darts = m_attribs[DART]; + for(unsigned int xd = darts.begin(); xd != darts.end(); darts.next(xd)) + { + unsigned int mrdi = m_mrattribs.insertLine() ; + assert(mrdi==xd); + (*m_mrDarts[0])[mrdi] = xd ; + } + + return true; +} + + bool MapMulti::copyFrom(const GenericMap& map) { - const MapMulti& mapMR = reinterpret_cast(map); + const MapMulti* mapMR = dynamic_cast(&map); + - if (mapTypeName() != map.mapTypeName()) + if (mapMR == NULL) { - CGoGNerr << "try to copy from incompatible type map" << CGoGNendl; - return false; + const MapMono* mapmono = dynamic_cast(mapMR); + if (mapmono == NULL) + { + CGoGNerr << "try to copy from incompatible type map" << CGoGNendl; + return false; + } + copyFromOtherType(*mapmono); } // clear the map but do not insert boundary markers dart attribute GenericMap::init(false); + // init MR data without adding the attributes + m_mrattribs.clear(true) ; + m_mrattribs.setRegistry(m_attributes_registry_map) ; + m_mrDarts.clear() ; + m_mrDarts.reserve(16) ; + m_mrNbDarts.clear(); + m_mrNbDarts.reserve(16); + m_mrLevelStack.clear() ; + m_mrLevelStack.reserve(16) ; - // load attrib container + // copy attrib containers for (unsigned int i = 0; i < NB_ORBITS; ++i) - m_attribs[i].copyFrom(mapMR.m_attribs[i]); + m_attribs[i].copyFrom(mapMR->m_attribs[i]); - m_mrattribs.copyFrom(mapMR.m_mrattribs); - m_mrCurrentLevel = mapMR.m_mrCurrentLevel; + m_mrattribs.copyFrom(mapMR->m_mrattribs); - unsigned int nb = mapMR.m_mrNbDarts.size(); - m_mrNbDarts.resize(nb); - for (unsigned int i = 0; i < nb; ++i) - m_mrNbDarts[i] = mapMR.m_mrNbDarts[i]; + m_mrCurrentLevel = mapMR->m_mrCurrentLevel; + + m_mrNbDarts.assign(mapMR->m_mrNbDarts.begin(), mapMR->m_mrNbDarts.end()); + + m_mrLevelStack.assign(mapMR->m_mrLevelStack.begin(), mapMR->m_mrLevelStack.end()); // ?? // restore shortcuts GenericMap::restore_shortcuts();