Commit e584d06b authored by Pierre Kraemer's avatar Pierre Kraemer

MR : code simplification

parent 8a94b2da
...@@ -166,7 +166,7 @@ public: ...@@ -166,7 +166,7 @@ public:
MarkSet& getMarkerSet(unsigned int orbit, unsigned int thread) { return m_marksets[orbit][thread]; } MarkSet& getMarkerSet(unsigned int orbit, unsigned int thread) { return m_marksets[orbit][thread]; }
/**************************************** /****************************************
* MULTIRES * * RESOLUTION LEVELS MANAGEMENT *
****************************************/ ****************************************/
void printMR() ; void printMR() ;
...@@ -238,10 +238,15 @@ protected: ...@@ -238,10 +238,15 @@ protected:
/** /**
* create a copy of a dart (based on its index in m_attribs[DART]) and returns its index * create a copy of a dart (based on its index in m_attribs[DART]) and returns its index
*/ */
unsigned int newCopyOfDartLine(unsigned int index) ; unsigned int copyDartLine(unsigned int index) ;
/** /**
* internal functions * duplicate a dart starting from current level
*/
void duplicateDart(Dart d) ;
/**
* Properly deletes a dart in m_attribs[DART]
*/ */
void deleteDartLine(unsigned int index) ; void deleteDartLine(unsigned int index) ;
......
...@@ -80,26 +80,24 @@ inline unsigned int GenericMap::getMaxLevel() ...@@ -80,26 +80,24 @@ inline unsigned int GenericMap::getMaxLevel()
inline Dart GenericMap::newDart() inline Dart GenericMap::newDart()
{ {
unsigned int di = m_attribs[DART].insertLine(); unsigned int di = m_attribs[DART].insertLine(); // insert a new dart line
for(unsigned int i = 0; i < NB_ORBITS; ++i) for(unsigned int i = 0; i < NB_ORBITS; ++i)
{ {
if (m_embeddings[i]) if (m_embeddings[i]) // set all its embeddings
(*m_embeddings[i])[di] = EMBNULL ; (*m_embeddings[i])[di] = EMBNULL ; // to EMBNULL
} }
if (m_isMultiRes) if (m_isMultiRes)
{ {
unsigned int mrdi = m_mrattribs.insertLine() ; unsigned int mrdi = m_mrattribs.insertLine() ; // insert a new MRdart line
(*m_mrLevels)[mrdi] = m_mrCurrentLevel ; (*m_mrLevels)[mrdi] = m_mrCurrentLevel ; // set the introduction level of the dart
m_mrNbDarts[m_mrCurrentLevel]++ ; m_mrNbDarts[m_mrCurrentLevel]++ ;
for(unsigned int i = 0; i < m_mrCurrentLevel; ++i) for(unsigned int i = 0; i < m_mrCurrentLevel; ++i) // for all previous levels
(*m_mrDarts[i])[mrdi] = MRNULL ; (*m_mrDarts[i])[mrdi] = MRNULL ; // this MRdart does not exist
(*m_mrDarts[m_mrCurrentLevel])[mrdi] = di ; for(unsigned int i = m_mrCurrentLevel; i < m_mrDarts.size(); ++i) // for all levels from current to max
(*m_mrDarts[i])[mrdi] = di ; // make this MRdart points to the new dart line
for(unsigned int i = m_mrCurrentLevel + 1; i < m_mrDarts.size(); ++i)
(*m_mrDarts[i])[mrdi] = di ; // newCopyOfDartLine(di) ;
return Dart::create(mrdi) ; return Dart::create(mrdi) ;
} }
...@@ -151,23 +149,44 @@ inline void GenericMap::deleteDartLine(unsigned int index) ...@@ -151,23 +149,44 @@ inline void GenericMap::deleteDartLine(unsigned int index)
} }
} }
inline unsigned int GenericMap::newCopyOfDartLine(unsigned int index) inline unsigned int GenericMap::copyDartLine(unsigned int index)
{ {
unsigned int newindex = m_attribs[DART].insertLine() ; // create a new dart line unsigned int newindex = m_attribs[DART].insertLine() ; // create a new dart line
m_attribs[DART].copyLine(newindex, index) ; // copy the given dart line m_attribs[DART].copyLine(newindex, index) ; // copy the given dart line
for(unsigned int orbit = 0; orbit < NB_ORBITS; ++orbit) for(unsigned int orbit = 0; orbit < NB_ORBITS; ++orbit)
{ {
if (m_embeddings[orbit]) // put the embeddings of the if (m_embeddings[orbit])
(*m_embeddings[orbit])[newindex] = EMBNULL ; // new line to EMBNULL // (*m_embeddings[orbit])[newindex] = EMBNULL ;
// { {
// unsigned int emb = (*m_embeddings[orbit])[newindex] ; unsigned int emb = (*m_embeddings[orbit])[newindex] ; // add a ref to the cells pointed
// if(emb != EMBNULL) if(emb != EMBNULL) // by the new dart line
// m_attribs[orbit].refLine(emb) ; m_attribs[orbit].refLine(emb) ;
// } }
} }
return newindex ; return newindex ;
} }
inline void GenericMap::duplicateDart(Dart d)
{
assert(getDartLevel(d) <= getCurrentLevel() || !"duplicateDart : called with a dart inserted after current level") ;
if(getDartLevel(d) == getCurrentLevel()) // no need to duplicate
return ; // a dart from its insertion level
unsigned int oldindex = dartIndex(d) ;
if((*m_mrDarts[m_mrCurrentLevel - 1])[d.index] != oldindex) // no need to duplicate if the dart is already
return ; // duplicated with respect to previous level
unsigned int newindex = copyDartLine(oldindex) ;
for(unsigned int i = getCurrentLevel(); i <= getMaxLevel(); ++i) // for all levels from current to max
{
assert((*m_mrDarts[i])[d.index] == oldindex || !"duplicateDart : dart was already duplicated on a greater level") ;
(*m_mrDarts[i])[d.index] = newindex ; // make this MRdart points to the new dart line
}
}
inline unsigned int GenericMap::dartIndex(Dart d) inline unsigned int GenericMap::dartIndex(Dart d)
{ {
if (m_isMultiRes) if (m_isMultiRes)
......
...@@ -33,7 +33,7 @@ ...@@ -33,7 +33,7 @@
namespace CGoGN namespace CGoGN
{ {
class Map2MR_Primal : public EmbeddedMap2 class Map2MR_PrimalAdapt : public EmbeddedMap2
{ {
protected: protected:
bool shareVertexEmbeddings ; bool shareVertexEmbeddings ;
...@@ -43,19 +43,14 @@ protected: ...@@ -43,19 +43,14 @@ protected:
FunctorType* faceVertexFunctor ; FunctorType* faceVertexFunctor ;
public: public:
Map2MR_Primal() ; Map2MR_PrimalAdapt() ;
std::string mapTypeName() { return "Map2MR_Primal" ; } std::string mapTypeName() { return "Map2MR_PrimalAdapt" ; }
/*************************************************** /***************************************************
* CELLS INFORMATION * * CELLS INFORMATION *
***************************************************/ ***************************************************/
/**
* Return the level of insertion of the vertex of d
*/
unsigned int vertexInsertionLevel(Dart d) ;
/** /**
* Return the level of the edge of d in the current level map * Return the level of the edge of d in the current level map
*/ */
...@@ -109,8 +104,6 @@ public: ...@@ -109,8 +104,6 @@ public:
***************************************************/ ***************************************************/
protected: protected:
bool dartIsDuplicated(Dart d) ;
void duplicateDart(Dart d) ;
// void propagatePhi1(Dart d) ; // void propagatePhi1(Dart d) ;
// void propagatePhi_1(Dart d) ; // void propagatePhi_1(Dart d) ;
...@@ -151,6 +144,18 @@ public: ...@@ -151,6 +144,18 @@ public:
} ; } ;
class Map2MR_PrimalRegular : public EmbeddedMap2
{
protected:
bool shareVertexEmbeddings ;
public:
Map2MR_PrimalRegular() ;
std::string mapTypeName() { return "Map2MR_PrimalRegular" ; }
void addNewLevel() ;
} ;
......
...@@ -199,32 +199,40 @@ void GenericMap::addLevel() ...@@ -199,32 +199,40 @@ void GenericMap::addLevel()
if(m_mrDarts.size() > 1) if(m_mrDarts.size() > 1)
{ {
AttributeMultiVector<unsigned int>* prevAttrib = m_mrDarts[newLevel - 1] ; AttributeMultiVector<unsigned int>* prevAttrib = m_mrDarts[newLevel - 1] ; // copy the indices of
m_mrattribs.copyAttribute(newAttrib->getIndex(), prevAttrib->getIndex()) ; m_mrattribs.copyAttribute(newAttrib->getIndex(), prevAttrib->getIndex()) ; // previous level into new level
// // duplicate all the darts in the new level
// for(unsigned int i = m_mrattribs.begin(); i != m_mrattribs.end(); m_mrattribs.next(i)) // for(unsigned int i = m_mrattribs.begin(); i != m_mrattribs.end(); m_mrattribs.next(i))
// { // {
// unsigned int oldi = (*prevAttrib)[i] ; // get the index of the dart in previous level // unsigned int oldi = (*prevAttrib)[i] ; // get the index of the dart in previous level
// (*newAttrib)[i] = newCopyOfDartLine(oldi) ; // copy the dart and affect it to the new level // (*newAttrib)[i] = copyDartLine(oldi) ; // copy the dart and affect it to the new level
// } // }
} }
} }
void GenericMap::removeLevel() void GenericMap::removeLevel()
{ {
if(!m_mrDarts.empty()) unsigned int maxL = getMaxLevel() ;
if(maxL > 0)
{ {
unsigned int maxL = getMaxLevel() ; AttributeMultiVector<unsigned int>* maxMR = m_mrDarts[maxL] ;
AttributeMultiVector<unsigned int>* amvMR = m_mrDarts[maxL] ; AttributeMultiVector<unsigned int>* prevMR = m_mrDarts[maxL - 1] ;
for(unsigned int i = m_mrattribs.begin(); i != m_mrattribs.end(); m_mrattribs.next(i)) for(unsigned int i = m_mrattribs.begin(); i != m_mrattribs.end(); m_mrattribs.next(i))
{ {
deleteDartLine((*amvMR)[i]) ; unsigned int idx = (*maxMR)[i] ;
if((*m_mrLevels)[i] == maxL) if((*m_mrLevels)[i] == maxL) // if the MRdart was introduced on the level we're removing
m_mrattribs.removeLine(i) ; {
deleteDartLine(idx) ; // delete the pointed dart line
m_mrattribs.removeLine(i) ; // delete the MRdart line
}
else // if the dart was introduced on a previous level
{
if(idx != (*prevMR)[i]) // delete the pointed dart line only if
deleteDartLine(idx) ; // it is not shared with previous level
}
} }
m_mrattribs.removeAttribute<unsigned int>(m_mrDarts[maxL]->getIndex()) ; m_mrattribs.removeAttribute<unsigned int>(maxMR->getIndex()) ;
m_mrDarts.pop_back() ; m_mrDarts.pop_back() ;
m_mrNbDarts.pop_back() ; m_mrNbDarts.pop_back() ;
...@@ -240,25 +248,25 @@ void GenericMap::removeLevel() ...@@ -240,25 +248,25 @@ void GenericMap::removeLevel()
void GenericMap::setDartEmbedding(unsigned int orbit, Dart d, unsigned int emb) void GenericMap::setDartEmbedding(unsigned int orbit, Dart d, unsigned int emb)
{ {
assert(isOrbitEmbedded(orbit) || !"Invalid parameter: orbit not embedded"); assert(isOrbitEmbedded(orbit) || !"Invalid parameter: orbit not embedded");
unsigned int old = getEmbedding(orbit, d); unsigned int old = getEmbedding(orbit, d);
// if same emb nothing to do if (old == emb) // if same emb
if (old == emb) return; // nothing to do
return;
// if different then unref the old emb if (old != EMBNULL) // if different
if (old != EMBNULL)
{ {
if(m_attribs[orbit].unrefLine(old)) if(m_attribs[orbit].unrefLine(old)) // then unref the old emb
{ {
for (unsigned int t = 0; t < m_nbThreads; ++t) // clear the markers if it was the for (unsigned int t = 0; t < m_nbThreads; ++t) // clear the markers if it was the
(*m_markTables[orbit][t])[old].clear(); // last unref of the line (*m_markTables[orbit][t])[old].clear(); // last unref of the line
} }
} }
// ref the new emb
if (emb != EMBNULL) if (emb != EMBNULL)
m_attribs[orbit].refLine(emb); m_attribs[orbit].refLine(emb); // ref the new emb
// affect the embedding to the dart
(*m_embeddings[orbit])[dartIndex(d)] = emb ; (*m_embeddings[orbit])[dartIndex(d)] = emb ; // finally affect the embedding to the dart
} }
/**************************************** /****************************************
......
This diff is collapsed.
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