Commit 8a94b2da authored by Pierre Kraemer's avatar Pierre Kraemer
Browse files

first version of Map2MR primal almost functional

parent c5412ed5
...@@ -29,6 +29,7 @@ ...@@ -29,6 +29,7 @@
namespace CGoGN namespace CGoGN
{ {
/******************************************************************************* /*******************************************************************************
GENERIC TRAVERSALS FACTORY GENERIC TRAVERSALS FACTORY
*******************************************************************************/ *******************************************************************************/
...@@ -38,20 +39,18 @@ class Traversor2 ...@@ -38,20 +39,18 @@ class Traversor2
{ {
public: public:
virtual ~Traversor2() {} virtual ~Traversor2() {}
virtual Dart begin() =0; virtual Dart begin() = 0;
virtual Dart end() =0; virtual Dart end() = 0;
virtual Dart next() =0; virtual Dart next() = 0;
static Traversor2<MAP>* createIncident(MAP& map, Dart dart, unsigned int orbX, unsigned int orbY); static Traversor2<MAP>* createIncident(MAP& map, Dart dart, unsigned int orbX, unsigned int orbY);
static Traversor2<MAP>* createAdjacent(MAP& map, Dart dart, unsigned int orbX, unsigned int orbY); static Traversor2<MAP>* createAdjacent(MAP& map, Dart dart, unsigned int orbX, unsigned int orbY);
}; };
/******************************************************************************* /*******************************************************************************
VERTEX CENTERED TRAVERSALS VERTEX CENTERED TRAVERSALS
*******************************************************************************/ *******************************************************************************/
// Traverse the edges incident to a given vertex // Traverse the edges incident to a given vertex
template <typename MAP> template <typename MAP>
class Traversor2VE : public Traversor2<MAP> class Traversor2VE : public Traversor2<MAP>
...@@ -228,7 +227,6 @@ public: ...@@ -228,7 +227,6 @@ public:
Traversor2FE(MAP& map, Dart dart):Traversor2FV<MAP>(map,dart){} Traversor2FE(MAP& map, Dart dart):Traversor2FV<MAP>(map,dart){}
} ; } ;
// Traverse the faces adjacent to a given face through sharing a common vertex // Traverse the faces adjacent to a given face through sharing a common vertex
template <typename MAP> template <typename MAP>
class Traversor2FFaV : public Traversor2<MAP> class Traversor2FFaV : public Traversor2<MAP>
......
...@@ -26,6 +26,9 @@ ...@@ -26,6 +26,9 @@
#define __MAP2MR_PRIMAL__ #define __MAP2MR_PRIMAL__
#include "Topology/map/embeddedMap2.h" #include "Topology/map/embeddedMap2.h"
#include "Topology/generic/traversor2.h"
#include <cmath>
namespace CGoGN namespace CGoGN
{ {
...@@ -35,9 +38,9 @@ class Map2MR_Primal : public EmbeddedMap2 ...@@ -35,9 +38,9 @@ class Map2MR_Primal : public EmbeddedMap2
protected: protected:
bool shareVertexEmbeddings ; bool shareVertexEmbeddings ;
// FunctorType& vertexVertexFunctor ; FunctorType* vertexVertexFunctor ;
// FunctorType& edgeVertexFunctor ; FunctorType* edgeVertexFunctor ;
// FunctorType& faceVertexFunctor ; FunctorType* faceVertexFunctor ;
public: public:
Map2MR_Primal() ; Map2MR_Primal() ;
...@@ -106,45 +109,348 @@ public: ...@@ -106,45 +109,348 @@ public:
***************************************************/ ***************************************************/
protected: protected:
bool dartIsDuplicated(Dart d) ;
void duplicateDart(Dart d) ; void duplicateDart(Dart d) ;
// void propagatePhi1(Dart d) ;
// void propagatePhi_1(Dart d) ;
/** /**
* add a new resolution level * add a new resolution level
*/ */
void addNewLevel() ; void addNewLevel() ;
public:
/** /**
* subdivide the edge of d to the next level * subdivide the edge of d to the next level
*/ */
unsigned int subdivideEdge(Dart d) ; void subdivideEdge(Dart d) ;
/** /**
* subdivide the face of d to the next level * coarsen the edge of d from the next level
*/ */
unsigned int subdivideFace(Dart d) ; void coarsenEdge(Dart d) ;
public:
/** /**
* coarsen the edge of d from the next level * subdivide the face of d to the next level
*/ */
void coarsenEdge(Dart d) ; unsigned int subdivideFace(Dart d) ;
/** /**
* coarsen the face of d from the next level * coarsen the face of d from the next level
*/ */
void coarsenFace(Dart d) ; void coarsenFace(Dart d) ;
// /** /**
// * vertices attributes management * vertices attributes management
// */ */
// void setVertexVertexFunctor(FunctorType& f) { vertexVertexFunctor = f ; } void setVertexVertexFunctor(FunctorType* f) { vertexVertexFunctor = f ; }
// void computeVertexVertex(Dart d) { vertexVertexFunctor(d) ; }
// void setEdgeVertexFunctor(FunctorType* f) { edgeVertexFunctor = f ; }
// void setEdgeVertexFunctor(FunctorType& f) { edgeVertexFunctor = f ; }
// void computeEdgeVertex(Dart d) { edgeVertexFunctor(d) ; } void setFaceVertexFunctor(FunctorType* f) { faceVertexFunctor = f ; }
// } ;
// void setFaceVertexFunctor(FunctorType& f) { faceVertexFunctor = f ; }
// void computeFaceVertex(Dart d) { faceVertexFunctor(d) ; }
/*********************************************************************************
* VERTEX FUNCTORS
*********************************************************************************/
template <typename PFP>
class PipoVertexVertexFunctor : public FunctorType
{
protected:
typename PFP::MAP& m_map ;
typename PFP::TVEC3& m_position ;
public:
PipoVertexVertexFunctor(typename PFP::MAP& m, typename PFP::TVEC3& p) : m_map(m), m_position(p)
{}
bool operator() (Dart d)
{
m_map.decCurrentLevel() ;
typename PFP::VEC3 p = m_position[d] ;
m_map.incCurrentLevel() ;
m_position[d] = p ;
return false ;
}
} ;
template <typename PFP>
class PipoEdgeVertexFunctor : public FunctorType
{
protected:
typename PFP::MAP& m_map ;
typename PFP::TVEC3& m_position ;
public:
PipoEdgeVertexFunctor(typename PFP::MAP& m, typename PFP::TVEC3& p) : m_map(m), m_position(p)
{}
bool operator() (Dart d)
{
Dart d1 = m_map.phi2(d) ;
m_map.decCurrentLevel() ;
Dart d2 = m_map.phi2(d1) ;
typename PFP::VEC3 p = (m_position[d1] + m_position[d2]) / 2.0 ;
m_map.incCurrentLevel() ;
m_position[d] = p ;
return false ;
}
} ;
template <typename PFP>
class PipoFaceVertexFunctor : public FunctorType
{
protected:
typename PFP::MAP& m_map ;
typename PFP::TVEC3& m_position ;
public:
PipoFaceVertexFunctor(typename PFP::MAP& m, typename PFP::TVEC3& p) : m_map(m), m_position(p)
{}
bool operator() (Dart d)
{
Dart df = m_map.phi1(m_map.phi1(d)) ;
m_map.decCurrentLevel() ;
typename PFP::VEC3 p(0) ;
unsigned int degree = 0 ;
Traversor2FV<typename PFP::MAP> trav(m_map, df) ;
for(Dart it = trav.begin(); it != trav.end(); it = trav.next())
{
++degree ;
p += m_position[it] ;
}
p /= degree ;
m_map.incCurrentLevel() ;
m_position[d] = p ;
return false ;
}
} ;
template <typename PFP>
class LoopVertexVertexFunctor : public FunctorType
{
protected:
typename PFP::MAP& m_map ;
typename PFP::TVEC3& m_position ;
public:
LoopVertexVertexFunctor(typename PFP::MAP& m, typename PFP::TVEC3& p) : m_map(m), m_position(p)
{}
bool operator() (Dart d)
{
m_map.decCurrentLevel() ;
typename PFP::VEC3 np(0) ;
unsigned int degree = 0 ;
Traversor2VVaE<typename PFP::MAP> trav(m_map, d) ;
for(Dart it = trav.begin(); it != trav.end(); it = trav.next())
{
++degree ;
np += m_position[it] ;
}
float tmp = 3.0 + 2.0 * cos(2.0 * M_PI / degree) ;
float beta = (5.0 / 8.0) - ( tmp * tmp / 64.0 ) ;
np *= beta / degree ;
typename PFP::VEC3 vp = m_position[d] ;
vp *= 1.0 - beta ;
m_map.incCurrentLevel() ;
m_position[d] = np + vp ;
return false ;
}
} ;
template <typename PFP>
class LoopEdgeVertexFunctor : public FunctorType
{
protected:
typename PFP::MAP& m_map ;
typename PFP::TVEC3& m_position ;
public:
LoopEdgeVertexFunctor(typename PFP::MAP& m, typename PFP::TVEC3& p) : m_map(m), m_position(p)
{}
bool operator() (Dart d)
{
Dart d1 = m_map.phi2(d) ;
m_map.decCurrentLevel() ;
Dart d2 = m_map.phi2(d1) ;
Dart d3 = m_map.phi_1(d1) ;
Dart d4 = m_map.phi_1(d2) ;
typename PFP::VEC3 p1 = m_position[d1] ;
typename PFP::VEC3 p2 = m_position[d2] ;
typename PFP::VEC3 p3 = m_position[d3] ;
typename PFP::VEC3 p4 = m_position[d4] ;
p1 *= 3.0 / 8.0 ;
p2 *= 3.0 / 8.0 ;
p3 *= 1.0 / 8.0 ;
p4 *= 1.0 / 8.0 ;
m_map.incCurrentLevel() ;
m_position[d] = p1 + p2 + p3 + p4 ;
return false ;
}
} ;
template <typename PFP>
class CCVertexVertexFunctor : public FunctorType
{
protected:
typename PFP::MAP& m_map ;
typename PFP::TVEC3& m_position ;
public:
CCVertexVertexFunctor(typename PFP::MAP& m, typename PFP::TVEC3& p) : m_map(m), m_position(p)
{}
bool operator() (Dart d)
{
m_map.decCurrentLevel() ;
typename PFP::VEC3 np1(0) ;
typename PFP::VEC3 np2(0) ;
unsigned int degree1 = 0 ;
unsigned int degree2 = 0 ;
Dart it = d ;
do
{
++degree1 ;
Dart dd = m_map.phi1(it) ;
np1 += m_position[dd] ;
Dart end = m_map.phi_1(it) ;
dd = m_map.phi1(dd) ;
do
{
++degree2 ;
np2 += m_position[dd] ;
dd = m_map.phi1(dd) ;
} while(dd != end) ;
it = m_map.alpha1(it) ;
} while(it != d) ;
float beta = 3.0 / (2.0 * degree1) ;
float gamma = 1.0 / (4.0 * degree2) ;
np1 *= beta / degree1 ;
np2 *= gamma / degree2 ;
typename PFP::VEC3 vp = m_position[d] ;
vp *= 1.0 - beta - gamma ;
m_map.incCurrentLevel() ;
m_position[d] = np1 + np2 + vp ;
return false ;
}
} ;
template <typename PFP>
class CCEdgeVertexFunctor : public FunctorType
{
protected:
typename PFP::MAP& m_map ;
typename PFP::TVEC3& m_position ;
public:
CCEdgeVertexFunctor(typename PFP::MAP& m, typename PFP::TVEC3& p) : m_map(m), m_position(p)
{}
bool operator() (Dart d)
{
Dart d1 = m_map.phi2(d) ;
m_map.decCurrentLevel() ;
Dart d2 = m_map.phi2(d1) ;
Dart d3 = m_map.phi_1(d1) ;
Dart d4 = m_map.phi_1(d2) ;
Dart d5 = m_map.phi1(m_map.phi1(d1)) ;
Dart d6 = m_map.phi1(m_map.phi1(d2)) ;
typename PFP::VEC3 p1 = m_position[d1] ;
typename PFP::VEC3 p2 = m_position[d2] ;
typename PFP::VEC3 p3 = m_position[d3] ;
typename PFP::VEC3 p4 = m_position[d4] ;
typename PFP::VEC3 p5 = m_position[d5] ;
typename PFP::VEC3 p6 = m_position[d6] ;
p1 *= 3.0 / 8.0 ;
p2 *= 3.0 / 8.0 ;
p3 *= 1.0 / 16.0 ;
p4 *= 1.0 / 16.0 ;
p5 *= 1.0 / 16.0 ;
p6 *= 1.0 / 16.0 ;
m_map.incCurrentLevel() ;
m_position[d] = p1 + p2 + p3 + p4 + p5 + p6 ;
return false ;
}
} ;
template <typename PFP>
class CCFaceVertexFunctor : public FunctorType
{
protected:
typename PFP::MAP& m_map ;
typename PFP::TVEC3& m_position ;
public:
CCFaceVertexFunctor(typename PFP::MAP& m, typename PFP::TVEC3& p) : m_map(m), m_position(p)
{}
bool operator() (Dart d)
{
Dart df = m_map.phi1(m_map.phi1(d)) ;
m_map.decCurrentLevel() ;
typename PFP::VEC3 p(0) ;
unsigned int degree = 0 ;
Traversor2FV<typename PFP::MAP> trav(m_map, df) ;
for(Dart it = trav.begin(); it != trav.end(); it = trav.next())
{
++degree ;
p += m_position[it] ;
}
p /= degree ;
m_map.incCurrentLevel() ;
m_position[d] = p ;
return false ;
}
} ; } ;
} // namespace CGoGN } // namespace CGoGN
......
...@@ -27,7 +27,11 @@ ...@@ -27,7 +27,11 @@
namespace CGoGN namespace CGoGN
{ {
Map2MR_Primal::Map2MR_Primal() : shareVertexEmbeddings(true) Map2MR_Primal::Map2MR_Primal() :
shareVertexEmbeddings(true),
vertexVertexFunctor(NULL),
edgeVertexFunctor(NULL),
faceVertexFunctor(NULL)
{ {
initMR() ; initMR() ;
} }
...@@ -252,32 +256,92 @@ bool Map2MR_Primal::faceIsSubdividedOnce(Dart d) ...@@ -252,32 +256,92 @@ bool Map2MR_Primal::faceIsSubdividedOnce(Dart d)
* SUBDIVISION * * 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) void Map2MR_Primal::duplicateDart(Dart d)
{ {
if(getDartLevel(d) < getCurrentLevel()) 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)
{ {
unsigned int oldindex = dartIndex(d) ; (*m_mrDarts[i])[d.index] = newindex ;
unsigned int newindex = newCopyOfDartLine(oldindex) ; if(shareVertexEmbeddings)
for(unsigned int i = getCurrentLevel(); i <= getMaxLevel(); ++i)
{ {
(*m_mrDarts[i])[d.index] = newindex ; unsigned int emb = (*m_embeddings[VERTEX])[oldindex] ;
if(shareVertexEmbeddings) (*m_embeddings[VERTEX])[newindex] = emb ;
{ if(emb != EMBNULL)
unsigned int emb = (*m_embeddings[VERTEX])[oldindex] ; m_attribs[VERTEX].refLine(emb);
(*m_embeddings[VERTEX])[newindex] = emb ;
if(emb != EMBNULL)
m_attribs[VERTEX].refLine(emb);
}
} }
} }
} }
//void Map2MR_Primal::propagatePhi1(Dart d)
//{
// assert(getDartLevel(d) <= getCurrentLevel() || !"propagatePhi1 : called with a dart introduced after current level") ;
//
// if(getCurrentLevel() == getMaxLevel())
// return ;
//
// bool finished = false ;
// unsigned int i = getCurrentLevel() + 1 ;
// do
// {
// unsigned int prevdi = (*m_mrDarts[i - 1])[d.index] ;
// unsigned int curdi = (*m_mrDarts[i])[d.index] ;
// if(curdi != prevdi)
// (*m_phi1)[curdi] = (*m_phi1)[prevdi] ;
// else
// finished = true ;
// ++i ;
// if(i > getMaxLevel())
// finished = true ;
// } while(!finished) ;
//}
//
//void Map2MR_Primal::propagatePhi_1(Dart d)
//{
// assert(getDartLevel(d) <= getCurrentLevel() || !"propagatePhi_1 : called with a dart introduced after current level") ;
//
// if(getCurrentLevel() == getMaxLevel())
// return ;
//
// bool finished = false ;
// unsigned int i = getCurrentLevel() + 1 ;
// do
// {
// unsigned int prevdi = (*m_mrDarts[i - 1])[d.index] ;
// unsigned int curdi = (*m_mrDarts[i])[d.index] ;
// if(curdi != prevdi)
// (*m_phi_1)[curdi] = (*m_phi_1)[prevdi] ;
// else
// finished = true ;
// ++i ;
// if(i > getMaxLevel())
// finished = true ;
// } while(!finished) ;
//}
void Map2MR_Primal::addNewLevel() void Map2MR_Primal::addNewLevel()
{ {
addLevel() ; addLevel() ;
unsigned int maxL = getMaxLevel() ;
if(shareVertexEmbeddings) if(shareVertexEmbeddings)
{ {
unsigned int maxL = getMaxLevel() ;
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))
{ {