Commit 56f2be8c authored by Sylvain Thery's avatar Sylvain Thery

optimization of map compacting

parent 05b0276d
...@@ -337,6 +337,13 @@ public: ...@@ -337,6 +337,13 @@ public:
*/ */
void compact(std::vector<unsigned int>& mapOldNew); void compact(std::vector<unsigned int>& mapOldNew);
/**
* Test the fragmentation of container,
* in fact just size/max_size
* @return 1 if full filled - 0 is lots of holes
*/
inline float fragmentation();
/************************************** /**************************************
* LINES MANAGEMENT * * LINES MANAGEMENT *
**************************************/ **************************************/
......
...@@ -227,6 +227,11 @@ inline bool AttributeContainer::used(unsigned int index) const ...@@ -227,6 +227,11 @@ inline bool AttributeContainer::used(unsigned int index) const
return m_holesBlocks[index / _BLOCKSIZE_]->used(index % _BLOCKSIZE_) != 0; return m_holesBlocks[index / _BLOCKSIZE_]->used(index % _BLOCKSIZE_) != 0;
} }
inline float AttributeContainer::fragmentation()
{
return float(m_size) / float(m_maxSize);
}
/************************************** /**************************************
* CONTAINER TRAVERSAL * * CONTAINER TRAVERSAL *
**************************************/ **************************************/
......
...@@ -430,8 +430,17 @@ protected: ...@@ -430,8 +430,17 @@ protected:
public: public:
/** /**
* compact the map * compact the map
* @warning the quickTraversals needs to be updated
*/ */
void compact() ; void compact(bool topoOnly = false) ;
/**
* test if containers are fragmented
* ~1.0 no need to compact
* ~0.0 need to compact
*/
inline float fragmentation(unsigned int orbit);
/** /**
* @brief dump all attributes of map in CSV format (; separated columns) * @brief dump all attributes of map in CSV format (; separated columns)
......
...@@ -322,4 +322,11 @@ inline AttributeMultiVector<Dart>* GenericMap::getRelation(const std::string& na ...@@ -322,4 +322,11 @@ inline AttributeMultiVector<Dart>* GenericMap::getRelation(const std::string& na
return amv ; return amv ;
} }
inline float GenericMap::fragmentation(unsigned int orbit)
{
if (isOrbitEmbedded(orbit))
return m_attribs[orbit].fragmentation();
return 1.0f;
}
} //namespace CGoGN } //namespace CGoGN
...@@ -165,7 +165,7 @@ protected: ...@@ -165,7 +165,7 @@ protected:
template <int I> template <int I>
inline void permutationUnsew(Dart d); inline void permutationUnsew(Dart d);
inline virtual void compactTopo(); virtual void compactTopo();
/**************************************** /****************************************
* MR CONTAINER MANAGEMENT * * MR CONTAINER MANAGEMENT *
......
...@@ -297,48 +297,6 @@ inline void MapMulti::permutationUnsew(Dart d) ...@@ -297,48 +297,6 @@ inline void MapMulti::permutationUnsew(Dart d)
(*m_permutation_inv[I])[e_index] = e ; (*m_permutation_inv[I])[e_index] = e ;
} }
inline void MapMulti::compactTopo()
{
std::vector<unsigned int> oldnewMR;
m_mrattribs.compact(oldnewMR);
std::vector<unsigned int> oldnew;
m_attribs[DART].compact(oldnew);
unsigned int nbl = m_mrDarts.size();
for (unsigned int i = m_mrattribs.begin(); i != m_mrattribs.end(); m_mrattribs.next(i))
{
for (unsigned int level = 0; level < nbl; ++level)
{
unsigned int& d = m_mrDarts[level]->operator[](i);
if (d != oldnew[d])
d = oldnew[d];
}
}
for (unsigned int i = m_attribs[DART].begin(); i != m_attribs[DART].end(); m_attribs[DART].next(i))
{
for (unsigned int j = 0; j < m_permutation.size(); ++j)
{
Dart d = (*m_permutation[j])[i];
if (d.index != oldnewMR[d.index])
(*m_permutation[j])[i] = Dart(oldnewMR[d.index]);
}
for (unsigned int j = 0; j < m_permutation_inv.size(); ++j)
{
Dart d = (*m_permutation_inv[j])[i];
if (d.index != oldnewMR[d.index])
(*m_permutation_inv[j])[i] = Dart(oldnewMR[d.index]);
}
for (unsigned int j = 0; j < m_involution.size(); ++j)
{
Dart d = (*m_involution[j])[i];
if (d.index != oldnewMR[d.index])
(*m_involution[j])[i] = Dart(oldnewMR[d.index]);
}
}
}
/**************************************** /****************************************
* MR CONTAINER MANAGEMENT * * MR CONTAINER MANAGEMENT *
****************************************/ ****************************************/
......
...@@ -216,6 +216,17 @@ void AttributeContainer::compact(std::vector<unsigned int>& mapOldNew) ...@@ -216,6 +216,17 @@ void AttributeContainer::compact(std::vector<unsigned int>& mapOldNew)
mapOldNew.clear(); mapOldNew.clear();
mapOldNew.resize(realEnd(),0xffffffff); mapOldNew.resize(realEnd(),0xffffffff);
//VERSION THAT PRESERVE ORDER OF ELEMENTS ?
// unsigned int down = 0;
// for (unsigned int occup = realBegin(); occup != realEnd(); next(occup))
// {
// mapOldNew[occup] = down;
// copyLine(down,occup);
// // copy ref counter
// setNbRefs(down,getNbRefs(occup));
// down++;
// }
// fill the holes with data & create the map Old->New // fill the holes with data & create the map Old->New
unsigned int up = realRBegin(); unsigned int up = realRBegin();
unsigned int down = 0; unsigned int down = 0;
......
...@@ -424,44 +424,33 @@ void GenericMap::dumpAttributesAndMarkers() ...@@ -424,44 +424,33 @@ void GenericMap::dumpAttributesAndMarkers()
// } // }
} }
void GenericMap::compact()
void GenericMap::compact(bool topoOnly)
{ {
// compact embedding attribs compactTopo();
std::vector< std::vector<unsigned int>* > oldnews(NB_ORBITS,NULL);
if (topoOnly)
return;
std::vector<unsigned int> oldnew;
for (unsigned int orbit = 0; orbit < NB_ORBITS; ++orbit) for (unsigned int orbit = 0; orbit < NB_ORBITS; ++orbit)
{ {
if ((orbit != DART) && (isOrbitEmbedded(orbit))) if ((orbit != DART) && (isOrbitEmbedded(orbit)))
{ {
oldnews[orbit] = new std::vector<unsigned int>; m_attribs[orbit].compact(oldnew);
m_attribs[orbit].compact(*(oldnews[orbit]));
}
}
// update embedding indices of topo
for (unsigned int i = m_attribs[DART].begin(); i != m_attribs[DART].end(); m_attribs[DART].next(i)) for (unsigned int i = m_attribs[DART].begin(); i != m_attribs[DART].end(); m_attribs[DART].next(i))
{
for (unsigned int orbit = 0; orbit < NB_ORBITS; ++orbit)
{
if ((orbit != DART) && (isOrbitEmbedded(orbit)))
{ {
unsigned int& idx = m_embeddings[orbit]->operator[](i); unsigned int& idx = m_embeddings[orbit]->operator[](i);
unsigned int jdx = oldnews[orbit]->operator[](idx); unsigned int jdx = oldnew[idx];
if ((jdx != 0xffffffff) && (jdx != idx)) if (jdx != 0xffffffff)
idx = jdx; idx = jdx;
} }
} }
} }
// delete allocated vectors
for (unsigned int orbit = 0; orbit < NB_ORBITS; ++orbit)
if (oldnews[orbit] != NULL)
delete oldnews[orbit];
// compact topo (depends on map implementation)
compactTopo();
} }
void GenericMap::dumpCSV() const void GenericMap::dumpCSV() const
{ {
for (unsigned int orbit = 0; orbit < NB_ORBITS; ++orbit) for (unsigned int orbit = 0; orbit < NB_ORBITS; ++orbit)
......
...@@ -416,4 +416,49 @@ void MapMulti::restore_topo_shortcuts() ...@@ -416,4 +416,49 @@ void MapMulti::restore_topo_shortcuts()
} }
} }
// TODO A VERIFIER ET A TESTER
void MapMulti::compactTopo()
{
std::vector<unsigned int> oldnewMR;
m_mrattribs.compact(oldnewMR);
unsigned int nbl = m_mrDarts.size();
for (unsigned int i = m_mrattribs.begin(); i != m_mrattribs.end(); m_mrattribs.next(i))
{
for (unsigned int level = 0; level < nbl; ++level)
{
unsigned int& d = m_mrDarts[level]->operator[](i);
if (oldnewMR[d] != AttributeContainer::UNKNOWN)
d = oldnewMR[d];
}
}
m_attribs[DART].compact(oldnewMR);
for (unsigned int i = m_attribs[DART].begin(); i != m_attribs[DART].end(); m_attribs[DART].next(i))
{
for (unsigned int j = 0; j < m_permutation.size(); ++j)
{
Dart d = (*m_permutation[j])[i];
if (oldnewMR[d.index] != AttributeContainer::UNKNOWN)
(*m_permutation[j])[i] = Dart(oldnewMR[d.index]);
}
for (unsigned int j = 0; j < m_permutation_inv.size(); ++j)
{
Dart d = (*m_permutation_inv[j])[i];
if (oldnewMR[d.index] != AttributeContainer::UNKNOWN)
(*m_permutation_inv[j])[i] = Dart(oldnewMR[d.index]);
}
for (unsigned int j = 0; j < m_involution.size(); ++j)
{
Dart d = (*m_involution[j])[i];
if (oldnewMR[d.index] != AttributeContainer::UNKNOWN)
(*m_involution[j])[i] = Dart(oldnewMR[d.index]);
}
}
}
} //namespace CGoGN } //namespace CGoGN
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment