Commit b066d4a5 authored by Pierre Kraemer's avatar Pierre Kraemer

deplacement fonctions .cpp -> .hpp

parent 7594d4f2
......@@ -88,6 +88,8 @@ protected:
template <int I>
inline void involutionUnsew(Dart d);
inline virtual void compactTopoRelations(const std::vector<unsigned int>& oldnew);
/****************************************
* DARTS TRAVERSALS *
****************************************/
......
......@@ -126,6 +126,31 @@ inline void MapMono::involutionUnsew(Dart d)
(*m_involution[I])[e.index] = e ;
}
inline void MapMono::compactTopoRelations(const std::vector<unsigned int>& oldnew)
{
for (unsigned int i = m_attribs[DART].begin(); i != m_attribs[DART].end(); m_attribs[DART].next(i))
{
for (unsigned int j = 0; j < m_permutation.size(); ++j)
{
Dart d = (*m_permutation[j])[i];
if (d.index != oldnew[d.index])
(*m_permutation[j])[i] = Dart(oldnew[d.index]);
}
for (unsigned int j = 0; j < m_permutation_inv.size(); ++j)
{
Dart d = (*m_permutation_inv[j])[i];
if (d.index != oldnew[d.index])
(*m_permutation_inv[j])[i] = Dart(oldnew[d.index]);
}
for (unsigned int j = 0; j < m_involution.size(); ++j)
{
Dart d = (*m_involution[j])[i];
if (d.index != oldnew[d.index])
(*m_involution[j])[i] = Dart(oldnew[d.index]);
}
}
}
/****************************************
* DARTS TRAVERSALS *
****************************************/
......
......@@ -151,6 +151,8 @@ protected:
template <int I>
inline void involutionUnsew(Dart d);
inline virtual void compactTopoRelations(const std::vector<unsigned int>& oldnew);
/****************************************
* MR CONTAINER MANAGEMENT *
****************************************/
......
......@@ -34,12 +34,12 @@ namespace CGoGN
* Class of 2-dimensional G-maps
* with managed embeddings
*/
class EmbeddedGMap2 : public GMap2
class EmbeddedGMap2 : public GMap2<MapMono>
{
public:
typedef GMap2 TOPO_MAP;
typedef GMap2<MapMono> TOPO_MAP;
static const unsigned int DIMENSION = 2 ;
static const unsigned int DIMENSION = TOPO_MAP::DIMENSION ;
/**
* create a new face with managed embeddings
......
......@@ -34,12 +34,12 @@ namespace CGoGN
* Class of 3-dimensional G-maps
* with managed embeddings
*/
class EmbeddedGMap3 : public GMap3
class EmbeddedGMap3 : public GMap3<MapMono>
{
public:
typedef GMap3 TOPO_MAP;
typedef GMap3<MapMono> TOPO_MAP;
static const unsigned int DIMENSION = 3 ;
static const unsigned int DIMENSION = TOPO_MAP::DIMENSION ;
/*!
*
......
......@@ -55,14 +55,10 @@ public:
virtual void update_topo_shortcuts();
virtual void compactTopoRelations(const std::vector<unsigned int>& oldnew);
/*! @name Basic Topological Operators
* Access and Modification
*************************************************************************/
virtual Dart newDart();
Dart beta0(const Dart d) const;
void beta0sew(Dart d, Dart e);
......
......@@ -73,19 +73,39 @@ inline void GMap0<MAP>::update_topo_shortcuts()
template <class MAP>
inline Dart GMap0<MAP>::beta0(Dart d) const
{
return MAP::getInvolution<0>(d);
return MAP::template getInvolution<0>(d);
}
template <class MAP>
inline void GMap0<MAP>::beta0sew(Dart d, Dart e)
{
MAP::involutionSew<0>(d,e);
MAP::template involutionSew<0>(d,e);
}
template <class MAP>
inline void GMap0<MAP>::beta0unsew(Dart d)
{
MAP::involutionUnsew<0>(d);
MAP::template involutionUnsew<0>(d);
}
/*! @name Constructors and Destructors
* To generate or delete edges in a 0-G-map
*************************************************************************/
template <class MAP>
Dart GMap0<MAP>::newEdge()
{
Dart d1 = this->newDart();
Dart d2 = this->newDart();
beta0sew(d1,d2);
return d1;
}
template <class MAP>
void GMap0<MAP>::deleteEdge(Dart d)
{
this->deleteDart(beta0(d));
this->deleteDart(d);
}
/*! @name Cell Functors
......
......@@ -54,8 +54,6 @@ public:
virtual void update_topo_shortcuts();
virtual void compactTopoRelations(const std::vector<unsigned int>& oldnew);
/*! @name Basic Topological Operators
* Access and Modification
*************************************************************************/
......@@ -94,12 +92,6 @@ public:
*/
Dart newCycle(unsigned int nbEdges);
//! Create an new face for boundary (marked)
/*! @param nbEdges the number of edges
* @return return a dart of the face
*/
// Dart newBoundaryCycle(unsigned int nbEdges);
//! Delete a face erasing all its darts
/*! @param d a dart of the face
*/
......
......@@ -71,7 +71,7 @@ inline void GMap1<MAP>::update_topo_shortcuts()
template <class MAP>
inline Dart GMap1<MAP>::beta1(Dart d) const
{
return MAP::getInvolution<1>(d);
return MAP::template getInvolution<1>(d);
}
template <class MAP>
......@@ -105,7 +105,7 @@ inline Dart GMap1<MAP>::phi1(Dart d) const
template <class MAP>
inline Dart GMap1<MAP>::phi_1(Dart d) const
{
return beta0(beta1(d)) ;
return this->beta0(beta1(d)) ;
}
template <class MAP>
......@@ -143,13 +143,47 @@ inline Dart GMap1<MAP>::alpha_1(Dart d) const
template <class MAP>
inline void GMap1<MAP>::beta1sew(Dart d, Dart e)
{
MAP::involutionSew<1>(d,e);
MAP::template involutionSew<1>(d,e);
}
template <class MAP>
inline void GMap1<MAP>::beta1unsew(Dart d)
{
MAP::involutionUnsew<1>(d);
MAP::template involutionUnsew<1>(d);
}
/*! @name Constructors and Destructors
* To generate or delete faces in a 1-G-map
*************************************************************************/
template <class MAP>
Dart GMap1<MAP>::newCycle(unsigned int nbEdges)
{
assert(nbEdges > 0 || !"Cannot create a face with no edge") ;
Dart d0 = ParentMap::newEdge(); // create the first edge
Dart dp = this->beta0(d0); // store an extremity
for (unsigned int i = 1; i < nbEdges; ++i)
{
Dart di = ParentMap::newEdge(); // create the next edge
beta1sew(dp,di);
dp = this->beta0(di); // change the preceding
}
beta1sew(dp,d0); // sew the last with the first
return d0;
}
template <class MAP>
void GMap1<MAP>::deleteCycle(Dart d)
{
Dart e = phi1(d);
while (e != d)
{
Dart f = phi1(e);
this->deleteEdge(e);
e = f;
}
this->deleteEdge(d);
}
/*! @name Topological Operators
......
......@@ -61,8 +61,6 @@ public:
virtual void update_topo_shortcuts();
virtual void compactTopoRelations(const std::vector<unsigned int>& oldnew);
/*! @name Basic Topological Operators
* Access and Modification
*************************************************************************/
......
......@@ -71,7 +71,7 @@ inline void GMap2<MAP>::update_topo_shortcuts()
template <class MAP>
inline Dart GMap2<MAP>::beta2(Dart d) const
{
return MAP::getInvolution<2>(d);
return MAP::template getInvolution<2>(d);
}
template <class MAP>
......@@ -147,25 +147,666 @@ inline Dart GMap2<MAP>::alpha_1(Dart d) const
template <class MAP>
inline void GMap2<MAP>::beta2sew(Dart d, Dart e)
{
MAP::involutionSew<2>(d,e);
MAP::template involutionSew<2>(d,e);
}
template <class MAP>
inline void GMap2<MAP>::beta2unsew(Dart d)
{
MAP::involutionUnsew<2>(d);
MAP::template involutionUnsew<2>(d);
}
/*! @name Constructors and Destructors
* To generate or delete faces in a 2-G-map
*************************************************************************/
template <class MAP>
Dart GMap2<MAP>::newFace(unsigned int nbEdges, bool withBoundary)
{
Dart d = ParentMap::newCycle(nbEdges);
if (withBoundary)
{
Dart e = newBoundaryCycle(nbEdges);
Dart it = d;
do
{
beta2sew(it, this->beta0(e));
beta2sew(this->beta0(it), e);
it = this->phi1(it);
e = this->phi_1(e);
} while (it != d);
}
return d;
}
template <class MAP>
void GMap2<MAP>::deleteFace(Dart d)
{
assert(!this->isBoundaryMarked2(d)) ;
Dart it = d ;
do
{
if(!isBoundaryEdge(it))
unsewFaces(it) ;
it = this->phi1(it) ;
} while(it != d) ;
Dart dd = phi2(d) ;
ParentMap::deleteCycle(d) ;
ParentMap::deleteCycle(dd) ;
}
template <class MAP>
void GMap2<MAP>::deleteCC(Dart d)
{
DartMarkerStore mark(*this);
std::vector<Dart> visited;
visited.reserve(1024) ;
visited.push_back(d);
mark.mark(d) ;
for(unsigned int i = 0; i < visited.size(); ++i)
{
Dart d0 = this->beta0(visited[i]) ;
if(!mark.isMarked(d0))
{
visited.push_back(d0) ;
mark.mark(d0);
}
Dart d1 = this->beta1(visited[i]) ;
if(!mark.isMarked(d1))
{
visited.push_back(d1) ;
mark.mark(d1);
}
Dart d2 = beta2(visited[i]) ;
if(!mark.isMarked(d2))
{
visited.push_back(d2) ;
mark.mark(d2);
}
}
for(std::vector<Dart>::iterator it = visited.begin(); it != visited.end(); ++it)
this->deleteDart(*it) ;
}
template <class MAP>
void GMap2<MAP>::fillHole(Dart d)
{
assert(isBoundaryEdge(d)) ;
Dart dd = d ;
if(!this->isBoundaryMarked2(dd))
dd = phi2(dd) ;
this->template boundaryUnmarkOrbit<FACE,2>(dd) ;
}
/*! @name Topological Operators
* Topological operations on 2-G-maps
*************************************************************************/
template <class MAP>
void GMap2<MAP>::splitVertex(Dart d, Dart e)
{
assert(sameVertex(d, e));
if(!sameOrientedVertex(d, e))
e = beta2(e) ;
Dart dd = phi2(d) ;
Dart ee = phi2(e) ;
beta2unsew(d) ;
beta2unsew(e) ;
ParentMap::cutEdge(dd); // Cut the edge of dd (make a new edge)
ParentMap::cutEdge(ee); // Cut the edge of ee (make a new edge)
beta2sew(this->phi1(dd), this->beta0(this->phi1(ee))); // Sew the two faces along the new edge
beta2sew(this->phi1(ee), this->beta0(this->phi1(dd)));
beta2sew(d, this->beta0(dd)) ;
beta2sew(e, this->beta0(ee)) ;
}
template <class MAP>
Dart GMap2<MAP>::deleteVertex(Dart d)
{
if(isBoundaryVertex(d))
return NIL ;
Dart res = NIL ;
Dart vit = d ;
do
{
if(res == NIL && this->phi1(this->phi1(d)) != d)
res = this->phi1(d) ;
Dart d0 = this->beta0(vit) ;
Dart d02 = beta2(d0) ;
Dart d01 = this->beta1(d0) ;
Dart d021 = this->beta1(d02) ;
this->beta1unsew(d0) ;
this->beta1unsew(d02) ;
this->beta1sew(d0, d02) ;
this->beta1sew(d01, d021) ;
vit = alpha1(vit) ;
} while(vit != d) ;
ParentMap::deleteCycle(d) ;
return res ;
}
template <class MAP>
Dart GMap2<MAP>::cutEdge(Dart d)
{
Dart e = phi2(d) ;
Dart nd = ParentMap::cutEdge(d) ;
Dart ne = ParentMap::cutEdge(e) ;
beta2sew(nd, this->beta1(ne)) ;
beta2sew(ne, this->beta1(nd)) ;
return nd ;
}
template <class MAP>
bool GMap2<MAP>::uncutEdge(Dart d)
{
if(vertexDegree(this->phi1(d)) == 2)
{
ParentMap::uncutEdge(d) ;
ParentMap::uncutEdge(beta2(d)) ;
return true ;
}
return false ;
}
template <class MAP>
Dart GMap2<MAP>::collapseEdge(Dart d, bool delDegenerateFaces)
{
Dart resV = NIL ;
Dart e = phi2(d);
beta2unsew(d); // Unlink the opposite edges
beta2unsew(e);
Dart f = this->phi1(e) ;
Dart h = alpha1(e);
if (h != e)
resV = h;
if (f != e && delDegenerateFaces)
{
ParentMap::collapseEdge(e) ; // Collapse edge e
collapseDegeneratedFace(f) ; // and collapse its face if degenerated
}
else
ParentMap::collapseEdge(e) ; // Just collapse edge e
f = this->phi1(d) ;
if(resV == NIL)
{
h = alpha1(d);
if (h != d)
resV = h;
}
if (f != d && delDegenerateFaces)
{
ParentMap::collapseEdge(d) ; // Collapse edge d
collapseDegeneratedFace(f) ; // and collapse its face if degenerated
}
else
ParentMap::collapseEdge(d) ; // Just collapse edge d
return resV ;
}
template <class MAP>
bool GMap2<MAP>::flipEdge(Dart d)
{
if (!isBoundaryEdge(d))
{
Dart e = phi2(d);
Dart dNext = this->phi1(d);
Dart eNext = this->phi1(e);
Dart dPrev = this->phi_1(d);
Dart ePrev = this->phi_1(e);
Dart dNext2 = this->phi1(dNext);
Dart eNext2 = this->phi1(eNext);
this->beta1unsew(d) ;
this->beta1unsew(eNext) ;
this->beta1unsew(e) ;
this->beta1unsew(dNext) ;
this->beta1unsew(dNext2) ;
this->beta1unsew(eNext2) ;
this->beta1sew(this->beta0(e), eNext2) ;
this->beta1sew(d, this->beta0(eNext)) ;
this->beta1sew(this->beta0(d), dNext2) ;
this->beta1sew(e, this->beta0(dNext)) ;
this->beta1sew(eNext, this->beta0(dPrev)) ;
this->beta1sew(dNext, this->beta0(ePrev)) ;
return true ;
}
return false ; // cannot flip a border edge
}
template <class MAP>
bool GMap2<MAP>::flipBackEdge(Dart d)
{
if (!isBoundaryEdge(d))
{
Dart e = phi2(d);
Dart dNext = this->phi1(d);
Dart eNext = this->phi1(e);
Dart dPrev = this->phi_1(d);
Dart ePrev = this->phi_1(e);
Dart dPrev1 = this->beta1(dPrev) ;
Dart ePrev1 = this->beta1(ePrev) ;
this->beta1unsew(d) ;
this->beta1unsew(eNext) ;
this->beta1unsew(e) ;
this->beta1unsew(dNext) ;
this->beta1unsew(dPrev) ;
this->beta1unsew(ePrev) ;
this->beta1sew(this->beta0(e), dPrev) ;
this->beta1sew(d, dPrev1) ;
this->beta1sew(this->beta0(d), ePrev) ;
this->beta1sew(e, ePrev1) ;
this->beta1sew(eNext, this->beta0(dPrev)) ;
this->beta1sew(dNext, this->beta0(ePrev)) ;
return true ;
}
return false ; // cannot flip a border edge
}
//template <class MAP>
//void GMap2<MAP>::insertEdgeInVertex(Dart d, Dart e)
//{
// assert(!sameVertex(d,e) && phi2(e)==phi_1(e));
//
// phi1sew(phi_1(d),phi_1(e));
//}
//
//template <class MAP>
//void GMap2<MAP>::removeEdgeFromVertex(Dart d)
//{
// assert(phi2(d)!=d);
//
// phi1sew(phi_1(d),phi2(d));
//}
template <class MAP>
void GMap2<MAP>::sewFaces(Dart d, Dart e, bool withBoundary)
{
// if sewing with fixed points
if (!withBoundary)
{
assert(beta2(d) == d && beta2(this->beta0(d)) == this->beta0(d) && beta2(e) == e && beta2(this->beta0(e)) == this->beta0(e)) ;
beta2sew(d, this->beta0(e)) ;
beta2sew(e, this->beta0(d)) ;
return ;
}
assert(isBoundaryEdge(d) && isBoundaryEdge(e)) ;
Dart dd = phi2(d) ;
Dart ee = phi2(e) ;
beta2unsew(d) ; // unsew faces from boundary
beta2unsew(this->beta0(d)) ;
beta2unsew(e) ;
beta2unsew(this->beta0(e)) ;
if (ee != this->phi_1(dd))
{
Dart eeN = this->phi1(ee) ; // remove the boundary edge
Dart dd1 = this->beta1(dd) ;
this->beta1unsew(eeN) ;
this->beta1unsew(dd1) ;
this->beta1sew(this->beta0(ee), dd) ;
this->beta1sew(eeN, dd1) ;
}
if (dd != this->phi_1(ee))
{
Dart ddN = this->phi1(dd) ; // and properly close incident boundaries
Dart ee1 = this->beta1(ee) ;
this->beta1unsew(ddN) ;
this->beta1unsew(ee1) ;
this->beta1sew(this->beta0(dd), ee) ;
this->beta1sew(ddN, ee1) ;
}
ParentMap::deleteCycle(dd) ;
beta2sew(d, this->beta0(e)) ; // sew the faces
beta2sew(e, this->beta0(d)) ;
}
template <class MAP>
void GMap2<MAP>::unsewFaces(Dart d)
{
assert(!isBoundaryEdge(d)) ;
Dart dd = phi2(d);
Dart e = newBoundaryCycle(2);
Dart ee = this->phi1(e) ;
Dart f = findBoundaryEdgeOfVertex(d) ;
if (f != NIL)
{
Dart f1 = this->beta1(f) ;
this->beta1unsew(ee) ;
this->beta1unsew(f) ;
this->beta1sew(f, this->beta0(e)) ;
this->beta1sew(f1, ee) ;
}
f = findBoundaryEdgeOfVertex(dd) ;
if (f != NIL)
{
Dart f1 = this->beta1(f) ;
this->beta1unsew(e) ;
this->beta1unsew(f) ;
this->beta1sew(f, this->beta0(ee)) ;
this->beta1sew(f1, e) ;
}
beta2unsew(d) ;
beta2unsew(this->beta0(d)) ;
beta2unsew(dd) ;
beta2unsew(this->beta0(dd)) ;
beta2sew(d, this->beta0(e)) ; // sew faces
beta2sew(e, this->beta0(d)) ;
beta2sew(dd, this->beta0(ee)) ; // to the boundary
beta2sew(ee, this->beta0(dd)) ;
}
template <class MAP>
bool GMap2<MAP>::collapseDegeneratedFace(Dart d)
{
Dart e = this->phi1(d); // Check if the face is a loop
if (this->phi1(e) == d) // Yes: it contains one or two edge(s)
{
Dart d2 = phi2(d) ; // Check opposite edges
Dart e2 = phi2(e) ;
beta2unsew(d) ;
beta2unsew(this->beta0(d)) ;
if(d != e)
{
beta2unsew(e) ;
beta2unsew(this->beta0(e)) ;
beta2sew(d2, this->beta0(e2)) ;
beta2sew(e2, this->beta0(d2)) ;
}
else
{
Dart d21 = this->beta1(d2) ;
Dart d2N = this->phi1(d2) ;