Commit e584d06b authored by Pierre Kraemer's avatar Pierre Kraemer
Browse files

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
}
/****************************************
......
......@@ -27,7 +27,7 @@
namespace CGoGN
{
Map2MR_Primal::Map2MR_Primal() :
Map2MR_PrimalAdapt::Map2MR_PrimalAdapt() :
shareVertexEmbeddings(true),
vertexVertexFunctor(NULL),
edgeVertexFunctor(NULL),
......@@ -40,24 +40,18 @@ Map2MR_Primal::Map2MR_Primal() :
* CELLS INFORMATION *
***************************************************/
unsigned int Map2MR_Primal::vertexInsertionLevel(Dart d)
unsigned int Map2MR_PrimalAdapt::edgeLevel(Dart d)
{
assert(getDartLevel(d) <= getCurrentLevel() || !"vertexInsertionLevel : called with a dart introduced after current level") ;
return getDartLevel(d) ;
}
unsigned int Map2MR_Primal::edgeLevel(Dart d)
{
assert(getDartLevel(d) <= getCurrentLevel() || !"edgeLevel : called with a dart introduced after current level") ;
assert(getDartLevel(d) <= getCurrentLevel() || !"edgeLevel : called with a dart inserted after current level") ;
unsigned int ld = getDartLevel(d) ;
unsigned int ldd = getDartLevel(phi2(d)) ; // the level of an edge is the maximum of the
return ld > ldd ? ld : ldd ; // insertion levels of its two darts
}
unsigned int Map2MR_Primal::faceLevel(Dart d)
unsigned int Map2MR_PrimalAdapt::faceLevel(Dart d)
{
assert(getDartLevel(d) <= getCurrentLevel() || !"faceLevel : called with a dart introduced after current level") ;
assert(getDartLevel(d) <= getCurrentLevel() || !"faceLevel : called with a dart inserted after current level") ;
if(getCurrentLevel() == 0)
return 0 ;
......@@ -94,9 +88,9 @@ unsigned int Map2MR_Primal::faceLevel(Dart d)
return min2 ;
}
Dart Map2MR_Primal::faceOrigin(Dart d)
Dart Map2MR_PrimalAdapt::faceOrigin(Dart d)
{
assert(getDartLevel(d) <= getCurrentLevel() || !"faceOrigin : called with a dart introduced after current level") ;
assert(getDartLevel(d) <= getCurrentLevel() || !"faceOrigin : called with a dart inserted after current level") ;
pushLevel() ;
Dart p = d ;
......@@ -111,9 +105,9 @@ Dart Map2MR_Primal::faceOrigin(Dart d)
return p ;
}
Dart Map2MR_Primal::faceOldestDart(Dart d)
Dart Map2MR_PrimalAdapt::faceOldestDart(Dart d)
{
assert(getDartLevel(d) <= getCurrentLevel() || !"faceOldestDart : called with a dart introduced after current level") ;
assert(getDartLevel(d) <= getCurrentLevel() || !"faceOldestDart : called with a dart inserted after current level") ;
Dart it = d ;
Dart oldest = it ;
......@@ -133,9 +127,9 @@ Dart Map2MR_Primal::faceOldestDart(Dart d)
return oldest ;
}
bool Map2MR_Primal::edgeIsSubdivided(Dart d)
bool Map2MR_PrimalAdapt::edgeIsSubdivided(Dart d)
{
assert(getDartLevel(d) <= getCurrentLevel() || !"edgeIsSubdivided : called with a dart introduced after current level") ;
assert(getDartLevel(d) <= getCurrentLevel() || !"edgeIsSubdivided : called with a dart inserted after current level") ;
if(getCurrentLevel() == getMaxLevel())
return false ;
......@@ -150,9 +144,9 @@ bool Map2MR_Primal::edgeIsSubdivided(Dart d)
return false ;
}
bool Map2MR_Primal::edgeCanBeCoarsened(Dart d)
bool Map2MR_PrimalAdapt::edgeCanBeCoarsened(Dart d)
{
assert(getDartLevel(d) <= getCurrentLevel() || !"edgeCanBeCoarsened : called with a dart introduced after current level") ;
assert(getDartLevel(d) <= getCurrentLevel() || !"edgeCanBeCoarsened : called with a dart inserted after current level") ;
if(edgeIsSubdivided(d))
{
......@@ -175,9 +169,9 @@ bool Map2MR_Primal::edgeCanBeCoarsened(Dart d)
return false ;
}
bool Map2MR_Primal::faceIsSubdivided(Dart d)
bool Map2MR_PrimalAdapt::faceIsSubdivided(Dart d)
{
assert(getDartLevel(d) <= getCurrentLevel() || !"faceIsSubdivided : called with a dart introduced after current level") ;
assert(getDartLevel(d) <= getCurrentLevel() || !"faceIsSubdivided : called with a dart inserted after current level") ;
if(getCurrentLevel() == getMaxLevel())
return false ;
......@@ -194,9 +188,9 @@ bool Map2MR_Primal::faceIsSubdivided(Dart d)
return subd ;
}
bool Map2MR_Primal::faceIsSubdividedOnce(Dart d)
bool Map2MR_PrimalAdapt::faceIsSubdividedOnce(Dart d)
{
assert(getDartLevel(d) <= getCurrentLevel() || !"faceIsSubdividedOnce : called with a dart introduced after current level") ;
assert(getDartLevel(d) <= getCurrentLevel() || !"faceIsSubdividedOnce : called with a dart inserted after current level") ;
if(getCurrentLevel() == getMaxLevel())
return false ;
......@@ -256,43 +250,9 @@ bool Map2MR_Primal::faceIsSubdividedOnce(Dart d)
* SUBDIVISION *
***************************************************/
bool Map2MR_Primal::dartIsDuplicated(Dart d)
{
assert(getDartLevel(d) <= getCurrentLevel() || !"dartIsDuplicated : called with a dart introduced after current level") ;
if(getCurrentLevel() == 0)
return true ;
unsigned int prevdi = (*m_mrDarts[m_mrCurrentLevel - 1])[d.index] ;
unsigned int curdi = (*m_mrDarts[m_mrCurrentLevel])[d.index] ;
if(prevdi != curdi)
return true ;
return false ;
}
void Map2MR_Primal::duplicateDart(Dart d)
{
assert(getDartLevel(d) <= getCurrentLevel() || !"duplicateDart : called with a dart introduced after current level") ;
assert(getDartLevel(d) < getCurrentLevel() || !"duplicateDart : try to duplicate a dart whose insertion level is current level") ;
unsigned int oldindex = dartIndex(d) ;
unsigned int newindex = newCopyOfDartLine(oldindex) ;
for(unsigned int i = getCurrentLevel(); i <= getMaxLevel(); ++i)
{
(*m_mrDarts[i])[d.index] = newindex ;
if(shareVertexEmbeddings)
{
unsigned int emb = (*m_embeddings[VERTEX])[oldindex] ;
(*m_embeddings[VERTEX])[newindex] = emb ;
if(emb != EMBNULL)
m_attribs[VERTEX].refLine(emb);
}
}
}
//void Map2MR_Primal::propagatePhi1(Dart d)
//void Map2MR_PrimalAdapt::propagatePhi1(Dart d)
//{
// assert(getDartLevel(d) <= getCurrentLevel() || !"propagatePhi1 : called with a dart introduced after current level") ;
// assert(getDartLevel(d) <= getCurrentLevel() || !"propagatePhi1 : called with a dart inserted after current level") ;
//
// if(getCurrentLevel() == getMaxLevel())
// return ;
......@@ -313,9 +273,9 @@ void Map2MR_Primal::duplicateDart(Dart d)
// } while(!finished) ;
//}
//
//void Map2MR_Primal::propagatePhi_1(Dart d)
//void Map2MR_PrimalAdapt::propagatePhi_1(Dart d)
//{
// assert(getDartLevel(d) <= getCurrentLevel() || !"propagatePhi_1 : called with a dart introduced after current level") ;
// assert(getDartLevel(d) <= getCurrentLevel() || !"propagatePhi_1 : called with a dart inserted after current level") ;
//
// if(getCurrentLevel() == getMaxLevel())
// return ;
......@@ -336,50 +296,36 @@ void Map2MR_Primal::duplicateDart(Dart d)
// } while(!finished) ;
//}
void Map2MR_Primal::addNewLevel()
void Map2MR_PrimalAdapt::addNewLevel()
{
addLevel() ;
unsigned int maxL = getMaxLevel() ;
if(shareVertexEmbeddings)
{
for(unsigned int i = m_mrattribs.begin(); i != m_mrattribs.end(); m_mrattribs.next(i))
{
unsigned int previdx = (*m_mrDarts[maxL - 1])[i] ;
unsigned int newidx = (*m_mrDarts[maxL])[i] ;
unsigned int emb = (*m_embeddings[VERTEX])[previdx] ;
(*m_embeddings[VERTEX])[newidx] = emb ;
if(emb != EMBNULL)
m_attribs[VERTEX].refLine(emb);
}
}
else
{
}
}
void Map2MR_Primal::subdivideEdge(Dart d)
void Map2MR_PrimalAdapt::subdivideEdge(Dart d)
{
assert(getDartLevel(d) <= getCurrentLevel() || !"subdivideEdge : called with a dart introduced after current level") ;
assert(getDartLevel(d) <= getCurrentLevel() || !"subdivideEdge : called with a dart inserted after current level") ;
assert(!edgeIsSubdivided(d) || !"Trying to subdivide an already subdivided edge") ;
assert(getCurrentLevel() == edgeLevel(d) || !"Trying to subdivide an edge on a bad current level") ;
if(getCurrentLevel() == getMaxLevel())
addNewLevel() ;
incCurrentLevel() ;
if(!dartIsDuplicated(d))
duplicateDart(d) ;
duplicateDart(d) ;
Dart dd = phi2(d) ;
if(!dartIsDuplicated(dd))
duplicateDart(dd) ;
duplicateDart(dd) ;
Dart d1 = phi1(d) ;
if(!dartIsDuplicated(d1))
duplicateDart(d1) ;
duplicateDart(d1) ;
Dart dd1 = phi1(dd) ;
if(!dartIsDuplicated(dd1))
duplicateDart(dd1) ;
duplicateDart(dd1) ;
cutEdge(d) ;
(*edgeVertexFunctor)(phi1(d)) ;
......@@ -387,9 +333,9 @@ void Map2MR_Primal::subdivideEdge(Dart d)
decCurrentLevel() ;
}
void Map2MR_Primal::coarsenEdge(Dart d)
void Map2MR_PrimalAdapt::coarsenEdge(Dart d)
{
assert(getDartLevel(d) <= getCurrentLevel() || !"coarsenEdge : called with a dart introduced after current level") ;
assert(getDartLevel(d) <= getCurrentLevel() || !"coarsenEdge : called with a dart inserted after current level") ;
assert(edgeCanBeCoarsened(d) || !"Trying to coarsen an edge that can not be coarsened") ;
incCurrentLevel() ;
......@@ -401,9 +347,9 @@ void Map2MR_Primal::coarsenEdge(Dart d)
removeLevel() ;
}
unsigned int Map2MR_Primal::subdivideFace(Dart d)
unsigned int Map2MR_PrimalAdapt::subdivideFace(Dart d)
{
assert(getDartLevel(d) <= getCurrentLevel() || !"subdivideFace : called with a dart introduced after current level") ;
assert(getDartLevel(d) <= getCurrentLevel() || !"subdivideFace : called with a dart inserted after current level") ;
assert(!faceIsSubdivided(d) || !"Trying to subdivide an already subdivided face") ;
unsigned int fLevel = faceLevel(d) ;
......@@ -412,22 +358,19 @@ unsigned int Map2MR_Primal::subdivideFace(Dart d)
pushLevel() ;
setCurrentLevel(fLevel) ; // go to the level of the face to subdivide its edges
if(getCurrentLevel() == getMaxLevel())
addNewLevel() ;
unsigned int degree = 0 ;
Dart it = old ;
do
{
++degree ; // compute the degree of the face
Dart nf = phi2(it) ;
if(faceLevel(nf) == fLevel - 1)
if(faceLevel(nf) == fLevel - 1) // check if neighboring faces have to be subdivided first
subdivideFace(nf) ;
it = phi1(it) ;
} while(it != old) ;
unsigned int degree = 0 ;
it = old ;
do
{
++degree ; // compute the degree of the face
if(!edgeIsSubdivided(it))
subdivideEdge(it) ; // and cut the edges (if they are not already)
subdivideEdge(it) ; // and cut the edges (if they are not already)
it = phi1(it) ;
} while(it != old) ;
......@@ -483,9 +426,9 @@ unsigned int Map2MR_Primal::subdivideFace(Dart d)
return fLevel ;
}
void Map2MR_Primal::coarsenFace(Dart d)
void Map2MR_PrimalAdapt::coarsenFace(Dart d)
{
assert(getDartLevel(d) <= getCurrentLevel() || !"coarsenFace : called with a dart introduced after current level") ;
assert(getDartLevel(d) <= getCurrentLevel() || !"coarsenFace : called with a dart inserted after current level") ;
assert(faceIsSubdividedOnce(d) || !"Trying to coarsen a non-subdivided face or a more than once subdivided face") ;
unsigned int degree = 0 ;
......@@ -531,4 +474,31 @@ void Map2MR_Primal::coarsenFace(Dart d)
removeLevel() ;
}
/* =================================================================================================== */
/* =================================================================================================== */
/* =================================================================================================== */
Map2MR_PrimalRegular::Map2MR_PrimalRegular() :
shareVertexEmbeddings(true)
{
initMR() ;
}
void Map2MR_PrimalRegular::addNewLevel()
{
pushLevel() ;
addLevel() ;
popLevel() ;
}
} // 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