From 439c915055d89d6a5c7c82b441bbe02f3fe5e8d8 Mon Sep 17 00:00:00 2001 From: Sylvain Thery Date: Wed, 25 Jun 2014 16:48:51 +0200 Subject: [PATCH] more compacting functions --- include/Container/holeblockref.h | 2 ++ include/Topology/generic/genericmap.h | 20 ++++++++++-- src/Topology/generic/genericmap.cpp | 44 +++++++++++++++++++++++++++ 3 files changed, 64 insertions(+), 2 deletions(-) diff --git a/include/Container/holeblockref.h b/include/Container/holeblockref.h index 468d18f2..841ac010 100644 --- a/include/Container/holeblockref.h +++ b/include/Container/holeblockref.h @@ -189,6 +189,8 @@ public: void saveBin(CGoGNostream& fs); bool loadBin(CGoGNistream& fs); + + unsigned int* getTableFree(unsigned int & nb) {nb =m_nbfree; return m_tableFree;} }; } // namespace CGoGN diff --git a/include/Topology/generic/genericmap.h b/include/Topology/generic/genericmap.h index abc54e5a..40afa3a6 100644 --- a/include/Topology/generic/genericmap.h +++ b/include/Topology/generic/genericmap.h @@ -431,14 +431,30 @@ public: /** * compact the map * @warning the quickTraversals needs to be updated + * @param topoOnly compact only the topo ? */ void compact(bool topoOnly = false) ; + /** + * compact a container (and update embedding attribute of topo) + * @param orbit orbit of container to compact + * @param frag minimum fragmentation value for compacting (default value 1.0 mean always compact)s + */ + void compactOrbitContainer(unsigned int orbit, float frag=1.0); + + /** + * @brief compact if containers are fragmented. + * @warning the quickTraversals needs to be updated + * @param frag if fragmentation (filling) of containers inferior to frag then compact + * @param topoOnly compact only the topo ? + */ + void compactIfNeeded(float frag, bool topoOnly = false) ; + /** * test if containers are fragmented - * ~1.0 no need to compact - * ~0.0 need to compact + * ~1.0 (full filled) no need to compact + * ~0.0 (lots of holes) need to compact */ inline float fragmentation(unsigned int orbit); diff --git a/src/Topology/generic/genericmap.cpp b/src/Topology/generic/genericmap.cpp index ed93a24b..0f1c1d70 100644 --- a/src/Topology/generic/genericmap.cpp +++ b/src/Topology/generic/genericmap.cpp @@ -450,6 +450,50 @@ void GenericMap::compact(bool topoOnly) } } +void GenericMap::compactOrbitContainer(unsigned int orbit, float frag) +{ + std::vector oldnew; + + if (isOrbitEmbedded(orbit) && (fragmentation(orbit)< frag)) + { + m_attribs[orbit].compact(oldnew); + for (unsigned int i = m_attribs[DART].begin(); i != m_attribs[DART].end(); m_attribs[DART].next(i)) + { + unsigned int& idx = m_embeddings[orbit]->operator[](i); + unsigned int jdx = oldnew[idx]; + if (jdx != 0xffffffff) + idx = jdx; + } + } +} + + +void GenericMap::compactIfNeeded(float frag, bool topoOnly) +{ + if (fragmentation(DART)< frag) + compactTopo(); + + if (topoOnly) + return; + + std::vector oldnew; + + for (unsigned int orbit = 0; orbit < NB_ORBITS; ++orbit) + { + if ((orbit != DART) && (isOrbitEmbedded(orbit)) && (fragmentation(orbit)< frag)) + { + m_attribs[orbit].compact(oldnew); + for (unsigned int i = m_attribs[DART].begin(); i != m_attribs[DART].end(); m_attribs[DART].next(i)) + { + unsigned int& idx = m_embeddings[orbit]->operator[](i); + unsigned int jdx = oldnew[idx]; + if (jdx != 0xffffffff) + idx = jdx; + } + } + } +} + void GenericMap::dumpCSV() const { -- GitLab