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

first version of Map2MR primal almost functional

parent c5412ed5
......@@ -29,6 +29,7 @@
namespace CGoGN
{
/*******************************************************************************
GENERIC TRAVERSALS FACTORY
*******************************************************************************/
......@@ -38,20 +39,18 @@ class Traversor2
{
public:
virtual ~Traversor2() {}
virtual Dart begin() =0;
virtual Dart end() =0;
virtual Dart next() =0;
virtual Dart begin() = 0;
virtual Dart end() = 0;
virtual Dart next() = 0;
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);
};
/*******************************************************************************
VERTEX CENTERED TRAVERSALS
*******************************************************************************/
// Traverse the edges incident to a given vertex
template <typename MAP>
class Traversor2VE : public Traversor2<MAP>
......@@ -228,7 +227,6 @@ public:
Traversor2FE(MAP& map, Dart dart):Traversor2FV<MAP>(map,dart){}
} ;
// Traverse the faces adjacent to a given face through sharing a common vertex
template <typename MAP>
class Traversor2FFaV : public Traversor2<MAP>
......
......@@ -26,6 +26,9 @@
#define __MAP2MR_PRIMAL__
#include "Topology/map/embeddedMap2.h"
#include "Topology/generic/traversor2.h"
#include <cmath>
namespace CGoGN
{
......@@ -35,9 +38,9 @@ class Map2MR_Primal : public EmbeddedMap2
protected:
bool shareVertexEmbeddings ;
// FunctorType& vertexVertexFunctor ;
// FunctorType& edgeVertexFunctor ;
// FunctorType& faceVertexFunctor ;
FunctorType* vertexVertexFunctor ;
FunctorType* edgeVertexFunctor ;
FunctorType* faceVertexFunctor ;
public:
Map2MR_Primal() ;
......@@ -106,45 +109,348 @@ public:
***************************************************/
protected:
bool dartIsDuplicated(Dart d) ;
void duplicateDart(Dart d) ;
// void propagatePhi1(Dart d) ;
// void propagatePhi_1(Dart d) ;
/**
* add a new resolution level
*/
void addNewLevel() ;
public:
/**
* 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
*/
void coarsenFace(Dart d) ;
// /**
// * vertices attributes management
// */
// void setVertexVertexFunctor(FunctorType& f) { vertexVertexFunctor = f ; }
// void computeVertexVertex(Dart d) { vertexVertexFunctor(d) ; }
//
// void setEdgeVertexFunctor(FunctorType& f) { edgeVertexFunctor = f ; }
// void computeEdgeVertex(Dart d) { edgeVertexFunctor(d) ; }
//
// void setFaceVertexFunctor(FunctorType& f) { faceVertexFunctor = f ; }
// void computeFaceVertex(Dart d) { faceVertexFunctor(d) ; }
/**
* vertices attributes management
*/
void setVertexVertexFunctor(FunctorType* f) { vertexVertexFunctor = f ; }
void setEdgeVertexFunctor(FunctorType* f) { edgeVertexFunctor = f ; }
void setFaceVertexFunctor(FunctorType* f) { faceVertexFunctor = f ; }
} ;
/*********************************************************************************
* 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
......
......@@ -27,7 +27,11 @@
namespace CGoGN
{
Map2MR_Primal::Map2MR_Primal() : shareVertexEmbeddings(true)
Map2MR_Primal::Map2MR_Primal() :
shareVertexEmbeddings(true),
vertexVertexFunctor(NULL),
edgeVertexFunctor(NULL),
faceVertexFunctor(NULL)
{
initMR() ;
}
......@@ -252,32 +256,92 @@ 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)
{
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) ;
unsigned int newindex = newCopyOfDartLine(oldindex) ;
for(unsigned int i = getCurrentLevel(); i <= getMaxLevel(); ++i)
(*m_mrDarts[i])[d.index] = newindex ;
if(shareVertexEmbeddings)
{
(*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);
}
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)
//{
// 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()
{
addLevel() ;
unsigned int maxL = getMaxLevel() ;
if(shareVertexEmbeddings)
{
unsigned int maxL = getMaxLevel() ;
for(unsigned int i = m_mrattribs.begin(); i != m_mrattribs.end(); m_mrattribs.next(i))
{
unsigned int previdx = (*m_mrDarts[maxL - 1])[i] ;
......@@ -288,31 +352,53 @@ void Map2MR_Primal::addNewLevel()
m_attribs[VERTEX].refLine(emb);
}
}
else
{
}
}
unsigned int Map2MR_Primal::subdivideEdge(Dart d)
void Map2MR_Primal::subdivideEdge(Dart d)
{
assert(getDartLevel(d) <= getCurrentLevel() || !"subdivideEdge : called with a dart introduced after current level") ;
assert(!edgeIsSubdivided(d) || !"Trying to subdivide an already subdivided edge") ;
unsigned int eLevel = edgeLevel(d) ;
pushLevel() ;
assert(getCurrentLevel() == edgeLevel(d) || !"Trying to subdivide an edge on a bad current level") ;
if(eLevel == getMaxLevel())
if(getCurrentLevel() == getMaxLevel())
addNewLevel() ;
setCurrentLevel(eLevel + 1) ;
incCurrentLevel() ;
if(!dartIsDuplicated(d))
duplicateDart(d) ;
Dart dd = phi2(d) ;
duplicateDart(d) ;
duplicateDart(phi1(d)) ;
duplicateDart(dd) ;
duplicateDart(phi1(dd)) ;
if(!dartIsDuplicated(dd))
duplicateDart(dd) ;
Dart d1 = phi1(d) ;
if(!dartIsDuplicated(d1))
duplicateDart(d1) ;
Dart dd1 = phi1(dd) ;
if(!dartIsDuplicated(dd1))
duplicateDart(dd1) ;
cutEdge(d) ;
(*edgeVertexFunctor)(phi1(d)) ;
popLevel() ;
decCurrentLevel() ;
}
return eLevel ;
void Map2MR_Primal::coarsenEdge(Dart d)
{
assert(getDartLevel(d) <= getCurrentLevel() || !"coarsenEdge : called with a dart introduced after current level") ;
assert(edgeCanBeCoarsened(d) || !"Trying to coarsen an edge that can not be coarsened") ;
incCurrentLevel() ;
uncutEdge(d) ;
decCurrentLevel() ;
unsigned int maxL = getMaxLevel() ;
if(getCurrentLevel() == maxL - 1 && getNbInsertedDarts(maxL) == 0)
removeLevel() ;
}
unsigned int Map2MR_Primal::subdivideFace(Dart d)
......@@ -326,13 +412,22 @@ unsigned int Map2MR_Primal::subdivideFace(Dart d)
pushLevel() ;
setCurrentLevel(fLevel) ; // go to the level of the face to subdivide its edges
unsigned int degree = 0 ;
Dart it = old ;
do
{
++degree ;
if(!edgeIsSubdivided(it)) // first cut the edges (if they are not already)
subdivideEdge(it) ; // and compute the degree of the face
Dart nf = phi2(it) ;
if(faceLevel(nf) == fLevel - 1)
subdivideFace(nf) ;
it = phi1(it) ;
} while(it != old) ;
unsigned int degree = 0 ;
it = old ;
do