Commit 43efa6b8 authored by Pierre Kraemer's avatar Pierre Kraemer

MRdarts and levels management

parent ed04faec
...@@ -86,7 +86,7 @@ protected: ...@@ -86,7 +86,7 @@ protected:
bool inTriangle(const typename PFP::VEC3& P, const typename PFP::VEC3& normal, const typename PFP::VEC3& Ta, const typename PFP::VEC3& Tb, const typename PFP::VEC3& Tc); bool inTriangle(const typename PFP::VEC3& P, const typename PFP::VEC3& normal, const typename PFP::VEC3& Ta, const typename PFP::VEC3& Tb, const typename PFP::VEC3& Tc);
void recompute2Ears( Dart d, const typename PFP::VEC3& normalPoly, bool convex); void recompute2Ears( Dart d, const typename PFP::VEC3& normalPoly, bool convex);
float computeEarInit(Dart d, const typename PFP::VEC3& normalPoly, float& val); float computeEarInit(Dart d, const typename PFP::VEC3& normalPoly, float& val);
...@@ -101,7 +101,6 @@ public: ...@@ -101,7 +101,6 @@ public:
void trianguleFace(Dart d); void trianguleFace(Dart d);
void triangule(const FunctorSelect& good = allDarts, unsigned int thread = 0); void triangule(const FunctorSelect& good = allDarts, unsigned int thread = 0);
}; };
} // namespace Modelisation } // namespace Modelisation
......
...@@ -127,6 +127,11 @@ protected: ...@@ -127,6 +127,11 @@ protected:
*/ */
AttributeMultiVector<unsigned int>* m_mrLevels ; AttributeMultiVector<unsigned int>* m_mrLevels ;
/**
* vector that stores the number of darts inserted on each resolution level
*/
std::vector<unsigned int> m_mrNbDarts ;
/** /**
* current level in multiresolution map * current level in multiresolution map
*/ */
...@@ -146,11 +151,6 @@ public: ...@@ -146,11 +151,6 @@ public:
virtual std::string mapTypeName() = 0 ; virtual std::string mapTypeName() = 0 ;
/**
* initialize the multiresolution attribute container
*/
void initMR() ;
/** /**
* Clear the map * Clear the map
* @param removeAttrib * @param removeAttrib
...@@ -168,6 +168,13 @@ public: ...@@ -168,6 +168,13 @@ public:
* MULTIRES * * MULTIRES *
****************************************/ ****************************************/
void printMR() ;
/**
* initialize the multiresolution attribute container
*/
void initMR() ;
/** /**
* get the current resolution level (use only in MRMaps) * get the current resolution level (use only in MRMaps)
*/ */
...@@ -178,6 +185,16 @@ public: ...@@ -178,6 +185,16 @@ public:
*/ */
void setCurrentLevel(unsigned int l) ; void setCurrentLevel(unsigned int l) ;
/**
* increment the current resolution level (use only in MRMaps)
*/
void incCurrentLevel() ;
/**
* decrement the current resolution level (use only in MRMaps)
*/
void decCurrentLevel() ;
/** /**
* store current resolution level on a stack (use only in MRMaps) * store current resolution level on a stack (use only in MRMaps)
*/ */
...@@ -199,14 +216,9 @@ public: ...@@ -199,14 +216,9 @@ public:
void addLevel() ; void addLevel() ;
/** /**
* add a resolution level and duplicate all darts (use only in MRMaps) * remove last resolution level (use only in MRMaps)
*/ */
void addLevelDuplicate() ; void removeLevel() ;
/**
* get the insertion level of a dart (use only in MRMaps)
*/
unsigned int getDartLevel(Dart d) ;
/**************************************** /****************************************
* DARTS MANAGEMENT * * DARTS MANAGEMENT *
...@@ -222,6 +234,14 @@ protected: ...@@ -222,6 +234,14 @@ protected:
*/ */
void deleteDart(Dart d) ; void deleteDart(Dart d) ;
private:
/**
* internal functions
*/
void deleteDartLine(unsigned int index) ;
void copyDartLine(unsigned int dest, unsigned int src) ;
unsigned int newCopyOfDartLine(unsigned int index) ;
public: public:
/** /**
* get the index of dart in topological table * get the index of dart in topological table
...@@ -229,15 +249,30 @@ public: ...@@ -229,15 +249,30 @@ public:
unsigned int dartIndex(Dart d); unsigned int dartIndex(Dart d);
/** /**
* return true if the dart d refers to a valid index * get the insertion level of a dart (use only in MRMaps)
*/ */
bool isDartValid(Dart d) ; unsigned int getDartLevel(Dart d) ;
/**
* get the number of darts inserted in the given leveldart (use only in MRMaps)
*/
unsigned int getNbInsertedDarts(unsigned int level) ;
/**
* get the number of darts that define the map of the given leveldart (use only in MRMaps)
*/
unsigned int getNbDarts(unsigned int level) ;
/** /**
* @return the number of darts in the map * @return the number of darts in the map
*/ */
unsigned int getNbDarts() ; unsigned int getNbDarts() ;
/**
* return true if the dart d refers to a valid index
*/
bool isDartValid(Dart d) ;
/**************************************** /****************************************
* EMBEDDING MANAGEMENT * * EMBEDDING MANAGEMENT *
****************************************/ ****************************************/
...@@ -266,11 +301,11 @@ public: ...@@ -266,11 +301,11 @@ public:
/** /**
* Copy the index of the cell associated to a dart over an other dart * Copy the index of the cell associated to a dart over an other dart
* @param d the dart to overwrite (dest)
* @param e the dart to copy (src)
* @param orbit the id of orbit embedding * @param orbit the id of orbit embedding
* @param dest the dart to overwrite
* @param src the dart to copy
*/ */
void copyDartEmbedding(unsigned int orbit, Dart d, Dart e) ; void copyDartEmbedding(unsigned int orbit, Dart dest, Dart src) ;
/** /**
* Allocation of some place in attrib table * Allocation of some place in attrib table
...@@ -357,6 +392,11 @@ public: ...@@ -357,6 +392,11 @@ public:
*/ */
void initOrbitEmbedding(unsigned int orbit, bool realloc = false) ; void initOrbitEmbedding(unsigned int orbit, bool realloc = false) ;
/**
* print attributes name of map in std::cout (for debugging)
*/
void viewAttributesTables() ;
protected: protected:
/**************************************** /****************************************
* EMBEDDING ATTRIBUTES MANAGEMENT * * EMBEDDING ATTRIBUTES MANAGEMENT *
...@@ -536,11 +576,6 @@ public: ...@@ -536,11 +576,6 @@ public:
*/ */
unsigned int getNbOrbits(unsigned int orbit, const FunctorSelect& good = allDarts) ; unsigned int getNbOrbits(unsigned int orbit, const FunctorSelect& good = allDarts) ;
/**
* print attributes name of map in std::cout (for debugging)
*/
void viewAttributesTables();
protected: protected:
/// boundary marker /// boundary marker
Mark m_boundaryMarker; Mark m_boundaryMarker;
......
...@@ -25,13 +25,6 @@ ...@@ -25,13 +25,6 @@
namespace CGoGN namespace CGoGN
{ {
inline unsigned int GenericMap::dartIndex(Dart d)
{
if (m_isMultiRes)
return m_mrDarts[m_mrCurrentLevel]->operator[](d.index) ;
return d.index;
}
/**************************************** /****************************************
* MULTIRES * * MULTIRES *
****************************************/ ****************************************/
...@@ -49,6 +42,22 @@ inline void GenericMap::setCurrentLevel(unsigned int l) ...@@ -49,6 +42,22 @@ inline void GenericMap::setCurrentLevel(unsigned int l)
CGoGNout << "setCurrentLevel : try to access nonexistent resolution level" << CGoGNendl ; CGoGNout << "setCurrentLevel : try to access nonexistent resolution level" << CGoGNendl ;
} }
inline void GenericMap::incCurrentLevel()
{
if(m_mrCurrentLevel < m_mrDarts.size())
++m_mrCurrentLevel ;
else
CGoGNout << "incCurrentLevel : already at maximum resolution level" << CGoGNendl ;
}
inline void GenericMap::decCurrentLevel()
{
if(m_mrCurrentLevel > 0)
--m_mrCurrentLevel ;
else
CGoGNout << "decCurrentLevel : already at minimum resolution level" << CGoGNendl ;
}
inline void GenericMap::pushLevel() inline void GenericMap::pushLevel()
{ {
m_mrLevelStack.push_back(m_mrCurrentLevel) ; m_mrLevelStack.push_back(m_mrCurrentLevel) ;
...@@ -65,11 +74,6 @@ inline unsigned int GenericMap::getMaxLevel() ...@@ -65,11 +74,6 @@ inline unsigned int GenericMap::getMaxLevel()
return m_mrDarts.size() - 1 ; return m_mrDarts.size() - 1 ;
} }
inline unsigned int GenericMap::getDartLevel(Dart d)
{
return m_mrLevels->operator[](d.index) ;
}
/**************************************** /****************************************
* DARTS MANAGEMENT * * DARTS MANAGEMENT *
****************************************/ ****************************************/
...@@ -82,86 +86,173 @@ inline Dart GenericMap::newDart() ...@@ -82,86 +86,173 @@ inline Dart GenericMap::newDart()
if (m_embeddings[i]) if (m_embeddings[i])
(*m_embeddings[i])[di] = EMBNULL ; (*m_embeddings[i])[di] = EMBNULL ;
} }
if (m_isMultiRes) if (m_isMultiRes)
{ {
unsigned int mrdi = m_mrattribs.insertLine() ; unsigned int mrdi = m_mrattribs.insertLine() ;
m_mrLevels->operator[](mrdi) = m_mrCurrentLevel ; (*m_mrLevels)[mrdi] = m_mrCurrentLevel ;
m_mrNbDarts[m_mrCurrentLevel]++ ;
for(unsigned int i = 0; i < m_mrCurrentLevel; ++i) for(unsigned int i = 0; i < m_mrCurrentLevel; ++i)
m_mrDarts[i]->operator[](mrdi) = MRNULL ; (*m_mrDarts[i])[mrdi] = MRNULL ;
m_mrDarts[m_mrCurrentLevel]->operator[](mrdi) = di ; (*m_mrDarts[m_mrCurrentLevel])[mrdi] = di ;
for(unsigned int i = m_mrCurrentLevel + 1; i < m_mrDarts.size(); ++i) for(unsigned int i = m_mrCurrentLevel + 1; i < m_mrDarts.size(); ++i)
{ (*m_mrDarts[i])[mrdi] = newCopyOfDartLine(di) ;
unsigned int dj = m_attribs[DART].insertLine();
for(unsigned int o = 0; o < NB_ORBITS; ++o)
{
if (m_embeddings[o])
(*m_embeddings[o])[dj] = EMBNULL ;
}
m_mrDarts[i]->operator[](mrdi) = dj ;
}
return Dart::create(mrdi) ; return Dart::create(mrdi) ;
} }
return Dart::create(di) ; return Dart::create(di) ;
} }
inline void GenericMap::deleteDart(Dart d) inline void GenericMap::deleteDart(Dart d)
{ {
unsigned int d_index = dartIndex(d); // hypothese : lors d'une suppression de brin, les attributs du brin supprimé
m_attribs[DART].removeLine(d_index) ; // sont identiques à tous les niveaux > au niveau où a lieu la suppression
for (unsigned int t = 0; t < m_nbThreads; ++t) if(m_isMultiRes)
m_markTables[DART][t]->operator[](d_index).clear() ; {
// if a dart is deleted on its insertion level
// all the darts pointed in greater levels are deleted
// and then the MRdart is deleted
if((*m_mrLevels)[d.index] == m_mrCurrentLevel)
{
for(unsigned int i = m_mrCurrentLevel; i < m_mrDarts.size(); ++i)
deleteDartLine((*m_mrDarts[i])[d.index]) ;
m_mrattribs.removeLine(d.index) ;
m_mrNbDarts[m_mrCurrentLevel]-- ;
}
// if a dart is deleted after its insertion level
// the dart of previous level is copied in the greater levels
else
{
unsigned int dprev = (*m_mrDarts[m_mrCurrentLevel - 1])[d.index] ;
for(unsigned int i = m_mrCurrentLevel; i < m_mrDarts.size(); ++i)
copyDartLine((*m_mrDarts[i])[d.index], dprev) ;
}
}
else
deleteDartLine(dartIndex(d)) ;
}
inline void GenericMap::deleteDartLine(unsigned int index)
{
m_attribs[DART].removeLine(index) ; // free the dart line
for (unsigned int t = 0; t < m_nbThreads; ++t) // clear markers of
(*m_markTables[DART][t])[index].clear() ; // the removed dart
for(unsigned int orbit = 0; orbit < NB_ORBITS; ++orbit) for(unsigned int orbit = 0; orbit < NB_ORBITS; ++orbit)
{ {
if (m_embeddings[orbit]) if (m_embeddings[orbit]) // for each embedded orbit
{ {
unsigned int emb = (*m_embeddings[orbit])[d_index] ; unsigned int emb = (*m_embeddings[orbit])[index] ; // get the embedding of the dart
if(emb != EMBNULL) if(emb != EMBNULL)
{ {
if(m_attribs[orbit].unrefLine(emb)) if(m_attribs[orbit].unrefLine(emb)) // unref the pointed embedding line
{ {
for (unsigned int t = 0; t < m_nbThreads; ++t) for (unsigned int t = 0; t < m_nbThreads; ++t) // and clear its markers if it was
m_markTables[orbit][t]->operator[](emb).clear() ; (*m_markTables[orbit][t])[emb].clear() ; // its last unref (and was thus freed)
} }
} }
} }
} }
}
// hypothese : le brin MR pointe vers le même brin pour tous les niveaux >= au courant inline void GenericMap::copyDartLine(unsigned int dest, unsigned int src)
if(m_isMultiRes) {
for(unsigned int orbit = 0; orbit < NB_ORBITS; ++orbit)
{ {
if(m_mrCurrentLevel == 0) if (m_embeddings[orbit]) // for each embedded orbit
m_mrattribs.removeLine(d.index) ;
else
{ {
unsigned int di = m_mrDarts[m_mrCurrentLevel - 1]->operator[](d.index) ; unsigned int emb = (*m_embeddings[orbit])[dest] ; // get the embedding of the destination dart
for(unsigned int i = m_mrCurrentLevel; i < m_mrDarts.size(); ++i) if(emb != EMBNULL)
m_mrDarts[i]->operator[](d.index) = di ; {
if(m_attribs[orbit].unrefLine(emb)) // unref the pointed embedding line
{
for (unsigned int t = 0; t < m_nbThreads; ++t) // and clear its markers if it was
(*m_markTables[orbit][t])[emb].clear() ; // its last unref (and was thus freed)
}
}
}
}
m_attribs[DART].copyLine(dest, src) ;
for(unsigned int orbit = 0; orbit < NB_ORBITS; ++orbit)
{
if (m_embeddings[orbit]) // for each embedded orbit
{
unsigned int emb = (*m_embeddings[orbit])[src] ; // add a ref to the pointed attributes
if(emb != EMBNULL)
m_attribs[orbit].refLine(emb) ;
} }
} }
} }
inline bool GenericMap::isDartValid(Dart d) inline unsigned int GenericMap::newCopyOfDartLine(unsigned int index)
{ {
return !d.isNil() && m_attribs[DART].used(dartIndex(d)) ; unsigned int newindex = m_attribs[DART].insertLine() ;
m_attribs[DART].copyLine(newindex, index) ;
for(unsigned int orbit = 0; orbit < NB_ORBITS; ++orbit)
{
if (m_embeddings[orbit])
{
unsigned int emb = (*m_embeddings[orbit])[newindex] ; // add a ref to the pointed attributes
if(emb != EMBNULL)
m_attribs[orbit].refLine(emb) ;
}
}
return newindex ;
} }
inline unsigned int GenericMap::getNbDarts() inline unsigned int GenericMap::dartIndex(Dart d)
{ {
if(m_isMultiRes) if (m_isMultiRes)
return (*m_mrDarts[m_mrCurrentLevel])[d.index] ;
return d.index;
}
inline unsigned int GenericMap::getDartLevel(Dart d)
{
return (*m_mrLevels)[d.index] ;
}
inline unsigned int GenericMap::getNbInsertedDarts(unsigned int level)
{
if(level < m_mrDarts.size())
return m_mrNbDarts[level] ;
else
return 0 ;
}
inline unsigned int GenericMap::getNbDarts(unsigned int level)
{
if(level < m_mrDarts.size())
{ {
unsigned int nbDarts = 0 ; unsigned int nb = 0 ;
for(unsigned int i = m_mrattribs.begin(); i != m_mrattribs.end(); m_mrattribs.next(i)) for(unsigned int i = 0; i <= level; ++i)
if(m_mrLevels->operator[](i) <= m_mrCurrentLevel) nb += m_mrNbDarts[i] ;
++nbDarts ; return nb ;
return nbDarts ;
} }
else
return 0 ;
}
inline unsigned int GenericMap::getNbDarts()
{
if(m_isMultiRes)
return getNbDarts(m_mrCurrentLevel) ;
return m_attribs[DART].size() ; return m_attribs[DART].size() ;
} }
inline bool GenericMap::isDartValid(Dart d)
{
return !d.isNil() && m_attribs[DART].used(dartIndex(d)) ;
}
/**************************************** /****************************************
* EMBEDDING MANAGEMENT * * EMBEDDING MANAGEMENT *
****************************************/ ****************************************/
...@@ -192,10 +283,10 @@ inline unsigned int GenericMap::getEmbedding(unsigned int orbit, Dart d) ...@@ -192,10 +283,10 @@ inline unsigned int GenericMap::getEmbedding(unsigned int orbit, Dart d)
return (*m_embeddings[orbit])[d_index] ; return (*m_embeddings[orbit])[d_index] ;
} }
inline void GenericMap::copyDartEmbedding(unsigned int orbit, Dart d, Dart e) inline void GenericMap::copyDartEmbedding(unsigned int orbit, Dart dest, Dart src)
{ {
assert(isOrbitEmbedded(orbit) || !"Invalid parameter: orbit not embedded"); assert(isOrbitEmbedded(orbit) || !"Invalid parameter: orbit not embedded");
setDartEmbedding(orbit, d, getEmbedding(orbit, e)); setDartEmbedding(orbit, dest, getEmbedding(orbit, src));
} }
inline unsigned int GenericMap::newCell(unsigned int orbit) inline unsigned int GenericMap::newCell(unsigned int orbit)
...@@ -313,7 +404,7 @@ inline AttributeMultiVector<Dart>* GenericMap::addRelation(const std::string& na ...@@ -313,7 +404,7 @@ inline AttributeMultiVector<Dart>* GenericMap::addRelation(const std::string& na
// set new relation to fix point for all the darts of the map // set new relation to fix point for all the darts of the map
for(unsigned int i = cont.begin(); i < cont.end(); cont.next(i)) for(unsigned int i = cont.begin(); i < cont.end(); cont.next(i))
amv->operator[](i) = i ; (*amv)[i] = i ;
return amv ; return amv ;
} }
......
...@@ -122,23 +122,6 @@ GenericMap::~GenericMap() ...@@ -122,23 +122,6 @@ GenericMap::~GenericMap()
} }
} }
void GenericMap::initMR()
{
#ifndef CGoGN_FORCE_MR
m_isMultiRes = true;
#endif
m_mrattribs.clear(true) ;
m_mrDarts.clear() ;
m_mrDarts.reserve(16) ;
m_mrLevelStack.clear() ;
m_mrLevelStack.reserve(16) ;
m_mrLevels = m_mrattribs.addAttribute<unsigned int>("MRLevel") ;
addLevel() ;
setCurrentLevel(0) ;
}
void GenericMap::clear(bool removeAttrib) void GenericMap::clear(bool removeAttrib)
{ {
if (removeAttrib) if (removeAttrib)
...@@ -155,9 +138,7 @@ void GenericMap::clear(bool removeAttrib) ...@@ -155,9 +138,7 @@ void GenericMap::clear(bool removeAttrib)
else else
{ {
for(unsigned int i = 0; i < NB_ORBITS; ++i) for(unsigned int i = 0; i < NB_ORBITS; ++i)
{
m_attribs[i].clear(false) ; m_attribs[i].clear(false) ;
}
} }
if (m_isMultiRes) if (m_isMultiRes)
...@@ -168,6 +149,42 @@ void GenericMap::clear(bool removeAttrib) ...@@ -168,6 +149,42 @@ void GenericMap::clear(bool removeAttrib)
* MULTIRES * * MULTIRES *
****************************************/ ****************************************/
void GenericMap::printMR()
{
std::cout << std::endl ;
for(unsigned int j = 0; j < m_mrNbDarts.size(); ++j)
std::cout << m_mrNbDarts[j] << " / " ;
std::cout << std::endl << "==========" << std::endl ;
for(unsigned int i = m_mrattribs.begin(); i != m_mrattribs.end(); m_mrattribs.next(i))
{
std::cout << (*m_mrLevels)[i] << " / " ;
for(unsigned int j = 0; j < m_mrDarts.size(); ++j)
std::cout << (*m_mrDarts[j])[i] << " ; " ;
std::cout << std::endl ;
}
}
void GenericMap::initMR()
{
#ifndef CGoGN_FORCE_MR
m_isMultiRes = true;
#endif
m_mrattribs.clear(true) ;
m_mrDarts.clear() ;
m_mrDarts.reserve(16) ;
m_mrNbDarts.clear();
m_mrNbDarts.reserve(16);
m_mrLevelStack.clear() ;
m_mrLevelStack.reserve(16) ;
m_mrLevels = m_mrattribs.addAttribute<unsigned int>("MRLevel") ;
addLevel() ;
setCurrentLevel(0) ;
}
void GenericMap::addLevel() void GenericMap::addLevel()
{ {
unsigned int newLevel = m_mrDarts.size() ; unsigned int newLevel = m_mrDarts.size() ;
...@@ -176,20 +193,41 @@ void GenericMap::addLevel() ...@@ -176,20 +193,41 @@ void GenericMap::addLevel()
AttributeMultiVector<unsigned int>* amvMR = m_mrattribs.addAttribute<unsigned int>(ss.str()) ; AttributeMultiVector<unsigned int>* amvMR = m_mrattribs.addAttribute<unsigned int>(ss.str()) ;
m_mrDarts.push_back(amvMR) ; m_mrDarts.push_back(amvMR) ;
m_mrNbDarts.push_back(0) ;
// copy the darts pointers of the previous level
if(m_mrDarts.size() > 1) if(m_mrDarts.size() > 1)
{
// copy the darts indices of the previous level