Commit e584d06b authored by Pierre Kraemer's avatar Pierre Kraemer

MR : code simplification

parent 8a94b2da
......@@ -166,7 +166,7 @@ public:
MarkSet& getMarkerSet(unsigned int orbit, unsigned int thread) { return m_marksets[orbit][thread]; }
/****************************************
* MULTIRES *
* RESOLUTION LEVELS MANAGEMENT *
****************************************/
void printMR() ;
......@@ -238,10 +238,15 @@ protected:
/**
* 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) ;
......
......@@ -80,26 +80,24 @@ inline unsigned int GenericMap::getMaxLevel()
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)
{
if (m_embeddings[i])
(*m_embeddings[i])[di] = EMBNULL ;
if (m_embeddings[i]) // set all its embeddings
(*m_embeddings[i])[di] = EMBNULL ; // to EMBNULL
}
if (m_isMultiRes)
{
unsigned int mrdi = m_mrattribs.insertLine() ;
(*m_mrLevels)[mrdi] = m_mrCurrentLevel ;
unsigned int mrdi = m_mrattribs.insertLine() ; // insert a new MRdart line
(*m_mrLevels)[mrdi] = m_mrCurrentLevel ; // set the introduction level of the dart
m_mrNbDarts[m_mrCurrentLevel]++ ;
for(unsigned int i = 0; i < m_mrCurrentLevel; ++i)
(*m_mrDarts[i])[mrdi] = MRNULL ;
for(unsigned int i = 0; i < m_mrCurrentLevel; ++i) // for all previous levels
(*m_mrDarts[i])[mrdi] = MRNULL ; // this MRdart does not exist
(*m_mrDarts[m_mrCurrentLevel])[mrdi] = di ;
for(unsigned int i = m_mrCurrentLevel + 1; i < m_mrDarts.size(); ++i)
(*m_mrDarts[i])[mrdi] = di ; // newCopyOfDartLine(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
return Dart::create(mrdi) ;
}
......@@ -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
m_attribs[DART].copyLine(newindex, index) ; // copy the given dart line
for(unsigned int orbit = 0; orbit < NB_ORBITS; ++orbit)
{
if (m_embeddings[orbit]) // put the embeddings of the
(*m_embeddings[orbit])[newindex] = EMBNULL ; // new line to EMBNULL
// {
// unsigned int emb = (*m_embeddings[orbit])[newindex] ;
// if(emb != EMBNULL)
// m_attribs[orbit].refLine(emb) ;
// }
if (m_embeddings[orbit])
// (*m_embeddings[orbit])[newindex] = EMBNULL ;
{
unsigned int emb = (*m_embeddings[orbit])[newindex] ; // add a ref to the cells pointed
if(emb != EMBNULL) // by the new dart line
m_attribs[orbit].refLine(emb) ;
}
}
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)
{
if (m_isMultiRes)
......
......@@ -33,7 +33,7 @@
namespace CGoGN
{
class Map2MR_Primal : public EmbeddedMap2
class Map2MR_PrimalAdapt : public EmbeddedMap2
{
protected:
bool shareVertexEmbeddings ;
......@@ -43,19 +43,14 @@ protected:
FunctorType* faceVertexFunctor ;
public:
Map2MR_Primal() ;
Map2MR_PrimalAdapt() ;
std::string mapTypeName() { return "Map2MR_Primal" ; }
std::string mapTypeName() { return "Map2MR_PrimalAdapt" ; }
/***************************************************
* 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
*/
......@@ -109,8 +104,6 @@ public:
***************************************************/
protected:
bool dartIsDuplicated(Dart d) ;
void duplicateDart(Dart d) ;
// void propagatePhi1(Dart d) ;
// void propagatePhi_1(Dart d) ;
......@@ -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()
if(m_mrDarts.size() > 1)
{
AttributeMultiVector<unsigned int>* prevAttrib = m_mrDarts[newLevel - 1] ;
m_mrattribs.copyAttribute(newAttrib->getIndex(), prevAttrib->getIndex()) ;
AttributeMultiVector<unsigned int>* prevAttrib = m_mrDarts[newLevel - 1] ; // copy the indices of
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))
// {
// 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
// unsigned int oldi = (*prevAttrib)[i] ; // get the index of the dart in previous level
// (*newAttrib)[i] = copyDartLine(oldi) ; // copy the dart and affect it to the new level
// }
}
}
void GenericMap::removeLevel()
{
if(!m_mrDarts.empty())
unsigned int maxL = getMaxLevel() ;
if(maxL > 0)
{
unsigned int maxL = getMaxLevel() ;
AttributeMultiVector<unsigned int>* amvMR = m_mrDarts[maxL] ;
AttributeMultiVector<unsigned int>* maxMR = 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))
{
deleteDartLine((*amvMR)[i]) ;
if((*m_mrLevels)[i] == maxL)
m_mrattribs.removeLine(i) ;
unsigned int idx = (*maxMR)[i] ;
if((*m_mrLevels)[i] == maxL) // if the MRdart was introduced on the level we're removing
{
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_mrNbDarts.pop_back() ;
......@@ -240,25 +248,25 @@ void GenericMap::removeLevel()
void GenericMap::setDartEmbedding(unsigned int orbit, Dart d, unsigned int emb)
{
assert(isOrbitEmbedded(orbit) || !"Invalid parameter: orbit not embedded");
unsigned int old = getEmbedding(orbit, d);
// if same emb nothing to do
if (old == emb)
return;
// if different then unref the old emb
if (old != EMBNULL)
if (old == emb) // if same emb
return; // nothing to do
if (old != EMBNULL) // if different
{
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
(*m_markTables[orbit][t])[old].clear(); // last unref of the line
}
}
// ref the new emb
if (emb != EMBNULL)
m_attribs[orbit].refLine(emb);
// affect the embedding to the dart
(*m_embeddings[orbit])[dartIndex(d)] = emb ;
m_attribs[orbit].refLine(emb); // ref the new 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