Commit f243d02b authored by untereiner's avatar untereiner

Adaptive Primal subdivision into Algo/Multiresolution/

parent a91ee675
...@@ -29,6 +29,7 @@ ...@@ -29,6 +29,7 @@
#include "Topology/generic/traversorCell.h" #include "Topology/generic/traversorCell.h"
#include "Topology/generic/traversor2.h" #include "Topology/generic/traversor2.h"
#include "Container/attributeContainer.h"
#include "Algo/Decimation/selector.h" #include "Algo/Decimation/selector.h"
#include "Algo/Decimation/edgeSelector.h" #include "Algo/Decimation/edgeSelector.h"
......
...@@ -136,15 +136,20 @@ void Map2MR_PM<PFP>::createPM(Algo::Decimation::SelectorType s, Algo::Decimation ...@@ -136,15 +136,20 @@ void Map2MR_PM<PFP>::createPM(Algo::Decimation::SelectorType s, Algo::Decimation
template <typename PFP> template <typename PFP>
void Map2MR_PM<PFP>::addNewLevel(unsigned int percentWantedVertices) void Map2MR_PM<PFP>::addNewLevel(unsigned int percentWantedVertices)
{ {
// level handling
m_map.pushLevel() ;
m_map.addLevelBack();
m_map.duplicateDarts(m_map.getMaxLevel());
m_map.setCurrentLevel(m_map.getMaxLevel());
unsigned int nbVertices = m_map.template getNbOrbits<VERTEX>() ; unsigned int nbVertices = m_map.template getNbOrbits<VERTEX>() ;
unsigned int nbWantedVertices = nbVertices * percentWantedVertices / 100 ; unsigned int nbWantedVertices = nbVertices * percentWantedVertices / 100 ;
CGoGNout << " creating PM (" << nbVertices << " vertices).." << /* flush */ CGoGNendl ;
unsigned int nbDeletedVertex=0;
unsigned int percentWantedPerLevel = 20;
unsigned int nbWantedPerLevel = nbWantedVertices * percentWantedPerLevel / 100 ;
//create the new level
m_map.addLevelFront();
m_map.setCurrentLevel(0);
m_map.printMR();
DartMarkerStore me(m_map); //mark edges not to collapse
bool finished = false ; bool finished = false ;
Dart d ; Dart d ;
...@@ -153,39 +158,194 @@ void Map2MR_PM<PFP>::addNewLevel(unsigned int percentWantedVertices) ...@@ -153,39 +158,194 @@ void Map2MR_PM<PFP>::addNewLevel(unsigned int percentWantedVertices)
if(!m_selector->nextEdge(d)) if(!m_selector->nextEdge(d))
break ; break ;
--nbVertices ; if(!me.isMarked(d))
Dart d2 = m_map.phi2(m_map.phi_1(d)) ;
Dart dd2 = m_map.phi2(m_map.phi_1(m_map.phi2(d))) ;
for(typename std::vector<Algo::Decimation::ApproximatorGen<PFP>*>::iterator it = m_approximators.begin(); it != m_approximators.end(); ++it)
{ {
(*it)->approximate(d) ; // compute approximated attributes with its associated detail
(*it)->saveApprox(d) ;
}
m_selector->updateBeforeCollapse(d) ; // update selector //me.mark le 1 voisinage
Dart dt = d;
do
{
Dart dit = dt;
do
{
me.mark(m_map.phi1(dit));
me.mark(m_map.phi1(m_map.phi1(dit)));
dit = m_map.phi2(m_map.phi_1(dit));
}
while(dit != dt);
dt = m_map.phi1(dt);
}while(dt != d);
dt = m_map.phi2(d);
do
{
Dart dit = dt;
do
{
me.mark(m_map.phi1(dit));
me.mark(m_map.phi1(m_map.phi1(dit)));
dit = m_map.phi2(m_map.phi_1(dit));
}
while(dit != dt);
dt = m_map.phi1(dt);
}while(dt != m_map.phi2(d));
collapseEdge(d); //incremente le dartLevel des brins des faces supprime
m_map.incDartLevel(d);
m_map.incDartLevel(m_map.phi1(d));
m_map.incDartLevel(m_map.phi_1(d));
m_map.incDartLevel(m_map.phi2(d));
m_map.incDartLevel(m_map.phi_1(m_map.phi2(d)));
m_map.incDartLevel(m_map.phi1(m_map.phi2(d)));
unsigned int newV = m_map.template embedNewCell<VERTEX>(d2) ; ++nbDeletedVertex ;
unsigned int newE1 = m_map.template embedNewCell<EDGE>(d2) ;
unsigned int newE2 = m_map.template embedNewCell<EDGE>(dd2) ;
// vs->setApproxV(newV) ;
// vs->setApproxE1(newE1) ;
// vs->setApproxE2(newE2) ;
for(typename std::vector<Algo::Decimation::ApproximatorGen<PFP>*>::iterator it = m_approximators.begin(); it != m_approximators.end(); ++it) Dart d2 = m_map.phi2(m_map.phi_1(d)) ;
(*it)->affectApprox(d2); // affect data to the resulting vertex Dart dd2 = m_map.phi2(m_map.phi_1(m_map.phi2(d))) ;
m_selector->updateAfterCollapse(d2, dd2) ; // update selector m_selector->updateBeforeCollapse(d) ; // update selector
if(nbVertices <= nbWantedVertices) collapseEdge(d);
finished = true ;
m_selector->updateAfterCollapse(d2, dd2) ; // update selector
if(nbDeletedVertex <= nbWantedPerLevel)
finished = true ;
}
} }
m_map.popLevel();
CGoGNout << "..done (" << nbVertices << " vertices)" << CGoGNendl ; CGoGNout << "..done (" << nbDeletedVertex << " vertices)" << CGoGNendl ;
m_map.printMR();
// DartMarkerStore me(m_map); //mark edges not to collapse
// DartMarkerStore mc(m_map); //mark darts to collapse
// std::vector<Dart> ec; //save a dart from edge to collapse
//
// for(Dart d = m_map.begin() ; d != m_map.end() ; m_map.next(d))
// {
// if(!me.isMarked(d))
// {
// Dart dt = d;
// do
// {
// Dart dit = dt;
// do
// {
// me.mark(m_map.phi1(dit));
// me.mark(m_map.phi1(m_map.phi1(dit)));
// dit = m_map.phi2(m_map.phi_1(dit));
// }
// while(dit != dt);
//
// dt = m_map.phi1(dt);
// }while(dt != d);
//
// dt = m_map.phi2(d);
// do
// {
// Dart dit = dt;
// do
// {
// me.mark(m_map.phi1(dit));
// me.mark(m_map.phi1(m_map.phi1(dit)));
// dit = m_map.phi2(m_map.phi_1(dit));
// }
// while(dit != dt);
//
// dt = m_map.phi1(dt);
// }while(dt != m_map.phi2(d));
//
//
// ec.push_back(d);
//
// mc.mark(d);
// mc.mark(m_map.phi1(d));
// mc.mark(m_map.phi_1(d));
// mc.mark(m_map.phi2(d));
// mc.mark(m_map.phi_1(m_map.phi2(d)));
// mc.mark(m_map.phi1(m_map.phi2(d)));
// }
// }
// //create the new level
// m_map.addLevelFront();
//
// AttributeContainer& cont = m_map.getMRAttributeContainer();
// AttributeMultiVector<unsigned int>* amv = m_map.getMRDartAttributeVector(m_map.getCurrentLevel());
// for(unsigned int i = cont.begin() ; i < cont.end() ; cont.next(i))
// {
// if(mc.isMarked((*amv)[i]) || (*amv)[i] == NULL)
// {
// //mrlevel++
// }
//
//
// //(*amv)[i] = MRNULL ;
// }
//
//
// for(std::vector<Dart>::iterator it = ec.begin() ; it != ec.end() ; ++it)
// {
//
// }
// // level handling
// m_map.pushLevel() ;
// m_map.addLevelBack();
// m_map.duplicateDarts(m_map.getMaxLevel());
// m_map.setCurrentLevel(m_map.getMaxLevel());
//
// unsigned int nbVertices = m_map.template getNbOrbits<VERTEX>() ;
// unsigned int nbWantedVertices = nbVertices * percentWantedVertices / 100 ;
// CGoGNout << " creating PM (" << nbVertices << " vertices).." << /* flush */ CGoGNendl ;
//
// bool finished = false ;
// Dart d ;
// while(!finished)
// {
// if(!m_selector->nextEdge(d))
// break ;
//
// --nbVertices ;
// Dart d2 = m_map.phi2(m_map.phi_1(d)) ;
// Dart dd2 = m_map.phi2(m_map.phi_1(m_map.phi2(d))) ;
//
// for(typename std::vector<Algo::Decimation::ApproximatorGen<PFP>*>::iterator it = m_approximators.begin(); it != m_approximators.end(); ++it)
// {
// (*it)->approximate(d) ; // compute approximated attributes with its associated detail
// (*it)->saveApprox(d) ;
// }
//
// m_selector->updateBeforeCollapse(d) ; // update selector
//
// collapseEdge(d);
//
// unsigned int newV = m_map.template embedNewCell<VERTEX>(d2) ;
// unsigned int newE1 = m_map.template embedNewCell<EDGE>(d2) ;
// unsigned int newE2 = m_map.template embedNewCell<EDGE>(dd2) ;
//// vs->setApproxV(newV) ;
//// vs->setApproxE1(newE1) ;
//// vs->setApproxE2(newE2) ;
//
// for(typename std::vector<Algo::Decimation::ApproximatorGen<PFP>*>::iterator it = m_approximators.begin(); it != m_approximators.end(); ++it)
// (*it)->affectApprox(d2); // affect data to the resulting vertex
//
// m_selector->updateAfterCollapse(d2, dd2) ; // update selector
//
// if(nbVertices <= nbWantedVertices)
// finished = true ;
// }
//
// m_map.popLevel();
//
// CGoGNout << "..done (" << nbVertices << " vertices)" << CGoGNendl ;
} }
...@@ -193,21 +353,14 @@ template <typename PFP> ...@@ -193,21 +353,14 @@ template <typename PFP>
void Map2MR_PM<PFP>::collapseEdge(Dart d) void Map2MR_PM<PFP>::collapseEdge(Dart d)
{ {
//duplication : //duplication :
m_map.duplicateMRDart(m_map.phi2(m_map.phi1(d))); m_map.duplicateDart(m_map.phi2(m_map.phi1(d)));
m_map.duplicateMRDart(m_map.phi2(m_map.phi_1(d))); m_map.duplicateDart(m_map.phi2(m_map.phi_1(d)));
m_map.duplicateMRDart(m_map.phi2(m_map.phi1(m_map.phi2(d)))); m_map.duplicateDart(m_map.phi2(m_map.phi1(m_map.phi2(d))));
m_map.duplicateMRDart(m_map.phi2(m_map.phi_1(m_map.phi2(d)))); m_map.duplicateDart(m_map.phi2(m_map.phi_1(m_map.phi2(d))));
//effacer : //m_map.collapseEdge(d);
// m_map.unrefMRDart(m_map.phi1(m_map.phi2(d)));
// m_map.unrefMRDart(m_map.phi_1(m_map.phi2(d)));
// m_map.unrefMRDart(m_map.phi2(d));
//
// m_map.unrefMRDart(m_map.phi1(d));
// m_map.unrefMRDart(m_map.phi_1(d));
// m_map.unrefMRDart(d);
m_map.collapseEdge(d); m_map.extractTrianglePair(d);
} }
......
...@@ -34,7 +34,6 @@ ...@@ -34,7 +34,6 @@
namespace CGoGN namespace CGoGN
{ {
}
namespace Algo namespace Algo
{ {
...@@ -124,19 +123,6 @@ public: ...@@ -124,19 +123,6 @@ public:
* SUBDIVISION * * SUBDIVISION *
***************************************************/ ***************************************************/
/**
* add a new resolution level
*/
void addNewLevel(bool embedNewVertices = true) ;
void propagateDartRelation(Dart d, AttributeMultiVector<Dart>* rel) ;
template <unsigned int ORBIT>
void propagateDartEmbedding(Dart d) ;
template <unsigned int ORBIT>
void propagateOrbitEmbedding(Dart d) ;
Dart cutEdge(Dart d) ; Dart cutEdge(Dart d) ;
void splitFace(Dart d, Dart e) ; void splitFace(Dart d, Dart e) ;
...@@ -155,7 +141,9 @@ public: ...@@ -155,7 +141,9 @@ public:
/** /**
* subdivide the face of d to the next level * subdivide the face of d to the next level
*/ */
unsigned int subdivideFace(Dart d) ; unsigned int subdivideFace(Dart d, bool triQuad = true) ;
unsigned int subdivideFace2(Dart d) ;
/** /**
* coarsen the face of d from the next level * coarsen the face of d from the next level
......
...@@ -120,7 +120,8 @@ void TopoRender::updateDataMap(typename PFP::MAP& mapx, const VertexAttribute<ty ...@@ -120,7 +120,8 @@ void TopoRender::updateDataMap(typename PFP::MAP& mapx, const VertexAttribute<ty
const VEC3& P = positions[d]; const VEC3& P = positions[d];
vecPos.push_back(P); vecPos.push_back(P);
center += P; center += P;
d = map.phi1(d); Dart e = map.phi1(d);
d = e;
} while (d != dd); } while (d != dd);
center /= REAL(vecPos.size()); center /= REAL(vecPos.size());
......
...@@ -230,11 +230,11 @@ public: ...@@ -230,11 +230,11 @@ public:
*/ */
unsigned int getMaxLevel() ; unsigned int getMaxLevel() ;
private: //private:
/* // /*
* add a resolution level // * add a resolution level
*/ // */
AttributeMultiVector<unsigned int>* addLevel(); // AttributeMultiVector<unsigned int>* addLevel();
public: public:
/** /**
...@@ -268,14 +268,9 @@ public: ...@@ -268,14 +268,9 @@ public:
void duplicateDarts(unsigned int level); void duplicateDarts(unsigned int level);
/** /**
* * duplicate a dart starting from current level
*/
void duplicateMRDart(Dart d);
/**
*
*/ */
void unrefMRDart(Dart d); void duplicateDart(Dart d) ;
/**************************************** /****************************************
* DARTS MANAGEMENT * * DARTS MANAGEMENT *
...@@ -296,11 +291,6 @@ protected: ...@@ -296,11 +291,6 @@ protected:
*/ */
unsigned int copyDartLine(unsigned int index) ; unsigned int copyDartLine(unsigned int index) ;
/**
* duplicate a dart starting from current level
*/
void duplicateDart(Dart d) ;
/** /**
* Properly deletes a dart in m_attribs[DART] * Properly deletes a dart in m_attribs[DART]
*/ */
...@@ -317,6 +307,12 @@ public: ...@@ -317,6 +307,12 @@ public:
*/ */
unsigned int getDartLevel(Dart d) const ; unsigned int getDartLevel(Dart d) const ;
/**
*
*/
void incDartLevel(Dart d) const ;
/** /**
* get the number of darts inserted in the given leveldart (use only in MRMaps) * get the number of darts inserted in the given leveldart (use only in MRMaps)
*/ */
...@@ -463,6 +459,16 @@ public: ...@@ -463,6 +459,16 @@ public:
template <unsigned int ORBIT> template <unsigned int ORBIT>
AttributeMultiVector<unsigned int>* getEmbeddingAttributeVector() ; AttributeMultiVector<unsigned int>* getEmbeddingAttributeVector() ;
/**
* get the MR attribute container
*/
AttributeContainer& getMRAttributeContainer() ;
/**
* get the MR attribute container
*/
AttributeMultiVector<unsigned int>* getMRDartAttributeVector(unsigned int level) ;
// /** // /**
// * swap two attribute containers // * swap two attribute containers
// */ // */
...@@ -486,6 +492,8 @@ public: ...@@ -486,6 +492,8 @@ public:
*/ */
void viewAttributesTables() ; void viewAttributesTables() ;
void printDartsTable();
protected: protected:
/**************************************** /****************************************
* EMBEDDING ATTRIBUTES MANAGEMENT * * EMBEDDING ATTRIBUTES MANAGEMENT *
......
...@@ -77,13 +77,14 @@ inline unsigned int GenericMap::getMaxLevel() ...@@ -77,13 +77,14 @@ inline unsigned int GenericMap::getMaxLevel()
return m_mrDarts.size() - 1 ; return m_mrDarts.size() - 1 ;
} }
/**************************************** /****************************************
* DARTS MANAGEMENT * * DARTS MANAGEMENT *
****************************************/ ****************************************/
inline Dart GenericMap::newDart() inline Dart GenericMap::newDart()
{ {
unsigned int di = m_attribs[DART].insertLine(); // insert a new dart line 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]) // set all its embeddings if (m_embeddings[i]) // set all its embeddings
...@@ -97,16 +98,11 @@ inline Dart GenericMap::newDart() ...@@ -97,16 +98,11 @@ inline Dart GenericMap::newDart()
m_mrNbDarts[m_mrCurrentLevel]++ ; m_mrNbDarts[m_mrCurrentLevel]++ ;
for(unsigned int i = 0; i < m_mrCurrentLevel; ++i) // for all previous levels 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[i])[mrdi] = MRNULL ; // this MRdart does not exist
for(unsigned int i = m_mrCurrentLevel; i < m_mrDarts.size(); ++i) // for all levels from current to max 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 point to the new dart line (*m_mrDarts[i])[mrdi] = di ; // make this MRdart point to the new dart line
(*m_mrDarts[m_mrCurrentLevel])[mrdi] = di ; // for the current level, this MRdart points to the new dart line
// for(unsigned int i = m_mrCurrentLevel + 1; i < m_mrDarts.size(); ++i) // for all levels from current + 1 to max
// (*m_mrDarts[i])[mrdi] = copyDartLine(di) ; // make this MRdart point to a copy of the new dart line
return Dart::create(mrdi) ; return Dart::create(mrdi) ;
} }
...@@ -119,10 +115,17 @@ inline void GenericMap::deleteDart(Dart d) ...@@ -119,10 +115,17 @@ inline void GenericMap::deleteDart(Dart d)
{ {
unsigned int index = (*m_mrDarts[m_mrCurrentLevel])[d.index] ; unsigned int index = (*m_mrDarts[m_mrCurrentLevel])[d.index] ;
//a Dart can only be deleted if all mrDarts have been deleted if(getDartLevel(d) > m_mrCurrentLevel)
if(getDartLevel(d) == m_mrCurrentLevel)
{ {
//for(unsigned int i = getDartLevel(d) - 1; i >= m_mrCurrentLevel; --i)
//{
(*m_mrDarts[m_mrCurrentLevel])[d.index] = MRNULL ;
//}
}
// a MRdart can only be deleted on its insertion level
if(getDartLevel(d) == m_mrCurrentLevel)
{
if(isDartValid(index)) if(isDartValid(index))
deleteDartLine(index) ; deleteDartLine(index) ;
...@@ -131,27 +134,19 @@ inline void GenericMap::deleteDart(Dart d) ...@@ -131,27 +134,19 @@ inline void GenericMap::deleteDart(Dart d)
} }
else else
{ {
unsigned int di = m_mrDarts[m_mrCurrentLevel - 1]->operator[](d.index) ; unsigned int di = (*m_mrDarts[m_mrCurrentLevel - 1])[d.index]; //m_mrDarts[m_mrCurrentLevel - 1]->operator[](d.index) ;
//si le brin de niveau i pointe sur le meme brin que le niveau i-1 // si le brin de niveau i pointe sur le meme brin que le niveau i-1
if(di != index) if(di != index)
{ {
if(isDartValid(index)) if(isDartValid(index))
deleteDartLine(index) ; deleteDartLine(index) ;
} }
m_mrDarts[m_mrCurrentLevel]->operator[](index) = MRNULL ;
}
// a MRdart can only be deleted on its insertion level for(unsigned int i = m_mrCurrentLevel; i <= getMaxLevel(); ++i) // for all levels from current to max
// assert(getDartLevel(d) == m_mrCurrentLevel || !"deleteDart : try to delete a dart on a level greater than its insertion level") ; {
(*m_mrDarts[i])[d.index] = di ; //copy the index from previous level
// for(unsigned int i = m_mrCurrentLevel; i < m_mrDarts.size(); ++i) }
// { }
// unsigned int index = (*m_mrDarts[i])[d.index] ;
// if(isDartValid(index))
// deleteDartLine(index) ;
// }
// m_mrattribs.removeLine(d.index) ;
// m_mrNbDarts[m_mrCurrentLevel]-- ;
} }
else else
deleteDartLine(dartIndex(d)) ; deleteDartLine(dartIndex(d)) ;
...@@ -199,9 +194,9 @@ inline unsigned int GenericMap::copyDartLine(unsigned int index) ...@@ -199,9 +194,9 @@ inline unsigned int GenericMap::copyDartLine(unsigned int index)
inline void GenericMap::duplicateDart(Dart d) inline void GenericMap::duplicateDart(Dart d)
{ {
assert(getDartLevel(d) <= getCurrentLevel() || !"duplicateDart : called with a dart inserted after current level") ; assert(getDartLevel(d) <= m_mrCurrentLevel || !"duplicateDart : called with a dart inserted after current level") ;
if(getDartLevel(d) == getCurrentLevel()) // no need to duplicate if(getDartLevel(d) == m_mrCurrentLevel) // no need to duplicate
return ; // a dart from its insertion level return ; // a dart from its insertion level
unsigned int oldindex = dartIndex(d) ; unsigned int oldindex = dartIndex(d) ;
...@@ -211,7 +206,7 @@ inline void GenericMap::duplicateDart(Dart d) ...@@ -211,7 +206,7 @@ inline void GenericMap::duplicateDart(Dart d)
unsigned int newindex = copyDartLine(oldindex) ; unsigned int newindex = copyDartLine(oldindex) ;
for(unsigned int i = getCurrentLevel(); i <= getMaxLevel(); ++i) // for all levels from current to max for(unsigned int i = m_mrCurrentLevel; i <= getMaxLevel(); ++i) // for all levels from current to max