Commit 790ec12a authored by untereiner's avatar untereiner

Apparition des IHM3 et quelques modifs sur les 3-cartes

parent 44019bb7
/*******************************************************************************
* CGoGN: Combinatorial and Geometric modeling with Generic N-dimensional Maps *
* version 0.1 *
* Copyright (C) 2009, IGG Team, LSIIT, University of Strasbourg *
* *
* This library is free software; you can redistribute it and/or modify it *
* under the terms of the GNU Lesser General Public License as published by the *
* Free Software Foundation; either version 2.1 of the License, or (at your *
* option) any later version. *
* *
* This library is distributed in the hope that it will be useful, but WITHOUT *
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or *
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License *
* for more details. *
* *
* You should have received a copy of the GNU Lesser General Public License *
* along with this library; if not, write to the Free Software Foundation, *
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. *
* *
* Web site: https://iggservis.u-strasbg.fr/CGoGN/ *
* Contact information: cgogn@unistra.fr *
* *
*******************************************************************************/
#ifndef __IMPLICIT_HIERARCHICAL_MAP3__
#define __IMPLICIT_HIERARCHICAL_MAP3__
#include "Topology/map/map3.h"
#include "Topology/generic/embeddedMap3.h"
namespace CGoGN
{
namespace Algo
{
namespace IHM3
{
template<typename T> class AttributeHandler_IHM ;
class ImplicitHierarchicalMap3 : public EmbeddedMap3<Map3>
{
template<typename T> friend class AttributeHandler_IHM ;
public:
unsigned int m_curLevel ;
unsigned int m_maxLevel ;
unsigned int m_edgeIdCount ;
unsigned int m_faceIdCount;
AttributeHandler<unsigned int> m_dartLevel ;
AttributeHandler<unsigned int> m_edgeId ;
AttributeHandler<unsigned int> m_faceId ;
AttribMultiVect<unsigned int>* m_nextLevelCell[NB_ORBITS] ;
public:
ImplicitHierarchicalMap3() ;
~ImplicitHierarchicalMap3() ;
void init() ;
/***************************************************
* ATTRIBUTES MANAGEMENT *
***************************************************/
template <typename T>
AttributeHandler_IHM<T> addAttribute(unsigned int orbit, const std::string& nameAttr) ;
/***************************************************
* MAP TRAVERSAL *
***************************************************/
virtual Dart newDart() ;
Dart phi1(Dart d) ;
Dart phi_1(Dart d) ;
private:
Dart phi2bis(Dart d) ;
public:
Dart phi2(Dart d) ;
Dart phi3(Dart d);
Dart alpha0(Dart d);
Dart alpha1(Dart d);
Dart alpha2(Dart d);
Dart alpha_2(Dart d);
virtual Dart begin() ;
virtual Dart end() ;
virtual void next(Dart& d) ;
virtual bool foreach_dart_of_vertex(Dart d, FunctorType& f) ;
virtual bool foreach_dart_of_edge(Dart d, FunctorType& f) ;
bool foreach_dart_of_oriented_face(Dart d, FunctorType& f);
virtual bool foreach_dart_of_face(Dart d, FunctorType& f) ;
bool foreach_dart_of_oriented_volume(Dart d, FunctorType& f);
virtual bool foreach_dart_of_volume(Dart d, FunctorType& f) ;
virtual bool foreach_dart_of_cc(Dart d, FunctorType& f) ;
/***************************************************
* LEVELS MANAGEMENT *
***************************************************/
unsigned int getCurrentLevel() ;
void setCurrentLevel(unsigned int l) ;
unsigned int getMaxLevel() ;
unsigned int getDartLevel(Dart d) ;
void setDartLevel(Dart d, unsigned int i) ;
/***************************************************
* EDGE ID MANAGEMENT *
***************************************************/
/**
* Give a new unique id to all the edges of the map
*/
void initEdgeId() ;
/**
* Return the next available edge id
*/
unsigned int getNewEdgeId() ;
unsigned int getEdgeId(Dart d) ;
void setEdgeId(Dart d, unsigned int i, unsigned int orbit);
/***************************************************
* FACE ID MANAGEMENT *
***************************************************/
void initFaceId() ;
/**
* Return the next available face id
*/
unsigned int getNewFaceId() ;
unsigned int getFaceId(Dart d) ;
void setFaceId(Dart d, unsigned int i, unsigned int orbit);
/***************************************************
* CELLS INFORMATION *
***************************************************/
/**
* Return the level of insertion of the vertex of d
*/
unsigned int vertexInsertionLevel(Dart d) ;
/**
* Return the level of the edge of d in the current level map
*/
unsigned int edgeLevel(Dart d) ;
/**
*
*/
unsigned int faceLevel(Dart d);
/**
*
*/
unsigned int volumeLevel(Dart d);
/**
*
*/
Dart faceOldestDart(Dart d);
/**
*
*/
Dart volumeOldestDart(Dart d);
/**
* Return true if the edge of d in the current level map
* has already been subdivided to the next level
*/
bool edgeIsSubdivided(Dart d) ;
/**
*
*/
bool faceIsSubdivided(Dart d) ;
/**
*
*/
bool volumeIsSubdivided(Dart d);
} ;
template <typename T>
class AttributeHandler_IHM : public AttributeHandler<T>
{
public:
typedef T DATA_TYPE ;
AttributeHandler_IHM() : AttributeHandler<T>()
{}
AttributeHandler_IHM(GenericMap* m, unsigned int idAttr) : AttributeHandler<T>(m, idAttr)
{}
AttribMultiVect<T>* getDataVector() const
{
return AttributeHandler<T>::getDataVector() ;
}
bool isValid() const
{
return AttributeHandler<T>::isValid() ;
}
T& operator[](Dart d) ;
const T& operator[](Dart d) const ;
T& operator[](unsigned int a)
{
return AttributeHandler<T>::operator[](a) ;
}
const T& operator[](unsigned int a) const
{
return AttributeHandler<T>::operator[](a) ;
}
} ;
} //namespace IHM
} //namespace Algo
} //namespace CGoGN
#include "Algo/ImplicitHierarchicalMesh/ihm3.hpp"
#endif
/*******************************************************************************
* CGoGN: Combinatorial and Geometric modeling with Generic N-dimensional Maps *
* version 0.1 *
* Copyright (C) 2009, IGG Team, LSIIT, University of Strasbourg *
* *
* This library is free software; you can redistribute it and/or modify it *
* under the terms of the GNU Lesser General Public License as published by the *
* Free Software Foundation; either version 2.1 of the License, or (at your *
* option) any later version. *
* *
* This library is distributed in the hope that it will be useful, but WITHOUT *
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or *
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License *
* for more details. *
* *
* You should have received a copy of the GNU Lesser General Public License *
* along with this library; if not, write to the Free Software Foundation, *
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. *
* *
* Web site: https://iggservis.u-strasbg.fr/CGoGN/ *
* Contact information: cgogn@unistra.fr *
* *
*******************************************************************************/
namespace CGoGN
{
namespace Algo
{
namespace IHM3
{
/***************************************************
* ATTRIBUTES MANAGEMENT *
***************************************************/
template <typename T>
AttributeHandler_IHM<T> ImplicitHierarchicalMap3::addAttribute(unsigned int orbit, const std::string& nameAttr)
{
bool addNextLevelCell = false ;
if(!isOrbitEmbedded(orbit))
addNextLevelCell = true ;
AttributeHandler<T> h = Map3::addAttribute<T>(orbit, nameAttr) ;
if(addNextLevelCell)
{
AttribContainer& cellCont = m_attribs[orbit] ;
unsigned int index = cellCont.addAttribute<unsigned int>("nextLevelCell") ;
AttribMultiVect<unsigned int>& amv = cellCont.getDataVector<unsigned int>(index) ;
m_nextLevelCell[orbit] = &amv ;
for(unsigned int i = cellCont.begin(); i < cellCont.end(); cellCont.next(i))
amv[i] = EMBNULL ;
}
return AttributeHandler_IHM<T>(this, h.id()) ;
}
/***************************************************
* MAP TRAVERSAL *
***************************************************/
inline Dart ImplicitHierarchicalMap3::newDart()
{
Dart d = Map3::newDart() ;
m_dartLevel[d] = m_curLevel ;
if(m_curLevel > m_maxLevel) // update max level
m_maxLevel = m_curLevel ; // if needed
return d ;
}
inline Dart ImplicitHierarchicalMap3::phi1(Dart d)
{
assert(m_dartLevel[d] <= m_curLevel || !"Access to a dart introduced after current level") ;
bool finished = false ;
unsigned int edgeId = m_edgeId[d] ;
Dart it = d ;
do
{
it = Map3::phi1(it) ;
if(m_dartLevel[it] <= m_curLevel)
finished = true ;
else
{
if(m_edgeId[it] != edgeId)
it = Map3::phi1(phi2bis(it));
}
} while(!finished) ;
return it ;
}
inline Dart ImplicitHierarchicalMap3::phi_1(Dart d)
{
assert(m_dartLevel[d] <= m_curLevel || !"Access to a dart introduced after current level") ;
bool finished = false ;
Dart it = Map3::phi_1(d) ;
unsigned int edgeId = m_edgeId[it] ;
do
{
if(m_dartLevel[it] <= m_curLevel)
finished = true ;
else
{
it = Map3::phi_1(it) ;
if(m_edgeId[it] != edgeId)
it = Map3::phi_1(phi2bis(it)) ;
}
} while(!finished) ;
return it ;
}
//TODO A verifier si besoin d'assertion
inline Dart ImplicitHierarchicalMap3::phi2bis(Dart d)
{
//assert(m_dartLevel[d] <= m_curLevel || !"Access to a dart introduced after current level") ;
unsigned int faceId = m_faceId[d];
Dart it = d;
it = Map3::phi2(it) ;
if(m_faceId[it] == faceId)
return it;
else
{
while(m_faceId[it] != faceId)
it = Map3::alpha_2(it);
return it;
}
}
inline Dart ImplicitHierarchicalMap3::phi2(Dart d)
{
assert(m_dartLevel[d] <= m_curLevel || !"Access to a dart introduced after current level") ;
return Map3::phi2(Map3::phi_1(phi1(d))) ;
}
inline Dart ImplicitHierarchicalMap3::phi3(Dart d)
{
assert(m_dartLevel[d] <= m_curLevel || !"Access to a dart introduced after current level") ;
if(Map3::phi3(d) == d)
return d;
return Map3::phi3(Map3::phi_1(phi1(d)));
}
inline Dart ImplicitHierarchicalMap3::alpha0(Dart d)
{
return phi3(d) ;
}
inline Dart ImplicitHierarchicalMap3::alpha1(Dart d)
{
assert(m_dartLevel[d] <= m_curLevel || !"Access to a dart introduced after current level") ;
return Map3::alpha1(d) ;
}
inline Dart ImplicitHierarchicalMap3::alpha2(Dart d)
{
assert(m_dartLevel[d] <= m_curLevel || !"Access to a dart introduced after current level") ;
Dart e = phi2(d);
Dart f = phi3(e);
if (f != e)
return f;
f = d;
e = phi3(f);
while (e != f)
{
f = phi2(e);
e = phi3(f);
}
return f;
}
inline Dart ImplicitHierarchicalMap3::alpha_2(Dart d)
{
assert(m_dartLevel[d] <= m_curLevel || !"Access to a dart introduced after current level") ;
Dart e = phi3(d);
if (e != d)
return phi2(e);
e = d;
Dart f = phi2(d);
while (phi3(f) != f)
{
e = phi3(f);
f = phi2(e);
}
return e;
}
inline Dart ImplicitHierarchicalMap3::begin()
{
Dart d = Map3::begin() ;
while(m_dartLevel[d] > m_curLevel)
Map3::next(d) ;
return d ;
}
inline Dart ImplicitHierarchicalMap3::end()
{
return Map3::end() ;
}
inline void ImplicitHierarchicalMap3::next(Dart& d)
{
do
{
Map3::next(d) ;
} while(m_dartLevel[d] > m_curLevel && d != Map3::end()) ;
}
inline bool ImplicitHierarchicalMap3::foreach_dart_of_vertex(Dart d, FunctorType& f)
{
DartMarkerStore mv(*this); // Lock a marker
bool found = false; // Last functor return value
std::list<Dart> darts_list; //Darts that are traversed
darts_list.push_back(d); //Start with the dart d
std::list<Dart>::iterator darts;
mv.mark(d);
for(darts = darts_list.begin(); !found && darts != darts_list.end() ; ++darts)
{
Dart dc = *darts;
//add phi21 and phi23 successor if they are not marked yet
Dart d2 = phi2(dc);
Dart d21 = phi1(d2); // turn in volume
Dart d23 = phi3(d2); // change volume
if(!mv.isMarked(d21))
{
darts_list.push_back(d21);
mv.mark(d21);
}
if((d23!=d2) && !mv.isMarked(d23))
{
darts_list.push_back(d23);
mv.mark(d23);
}
found = f(dc);
}
return found;
}
inline bool ImplicitHierarchicalMap3::foreach_dart_of_edge(Dart d, FunctorType& f)
{
Dart dNext = d;
do {
if (f(dNext))
return true;
Dart d2 = phi2(dNext);
if (d2 != dNext)
return f(d2);
else
return false;
dNext = alpha2(dNext);
} while (dNext != d);
return false;
}
inline bool ImplicitHierarchicalMap3::foreach_dart_of_oriented_face(Dart d, FunctorType& f)
{
Dart dNext = d ;
do
{
if (f(dNext))
return true ;
dNext = phi1(dNext) ;
} while (dNext != d) ;
return false ;
}
inline bool ImplicitHierarchicalMap3::foreach_dart_of_face(Dart d, FunctorType& f)
{
if (foreach_dart_of_oriented_face(d,f)) return true;
Dart d3 = phi3(d);
if (d3 != d) return foreach_dart_of_oriented_face(d3,f);
return false;
}
inline bool ImplicitHierarchicalMap3::foreach_dart_of_oriented_volume(Dart d, FunctorType& f)
{
DartMarkerStore mark(*this); // Lock a marker
bool found = false; // Last functor return value
std::list<Dart> visitedFaces; // Faces that are traversed
visitedFaces.push_back(d); // Start with the face of d
std::list<Dart>::iterator face;
// For every face added to the list
for (face = visitedFaces.begin(); !found && face != visitedFaces.end(); ++face)
{
if (!mark.isMarked(*face)) // Face has not been visited yet
{
// Apply functor to the darts of the face
found = foreach_dart_of_oriented_face(*face, f);
// If functor returns false then mark visited darts (current face)
// and add non visited adjacent faces to the list of face
if (!found)
{
Dart dNext = *face ;
do
{
mark.mark(dNext); // Mark
Dart adj = phi2(dNext); // Get adjacent face
if (adj != dNext && !mark.isMarked(adj))
visitedFaces.push_back(adj); // Add it
dNext = phi1(dNext);
} while(dNext != *face);
}
}
}
return found;
}
inline bool ImplicitHierarchicalMap3::foreach_dart_of_volume(Dart d, FunctorType& f)
{
return foreach_dart_of_oriented_volume(d, f) ;
}
inline bool ImplicitHierarchicalMap3::foreach_dart_of_cc(Dart d, FunctorType& f)
{
return foreach_dart_of_oriented_volume(d, f) ;
}
/***************************************************
* LEVELS MANAGEMENT *
***************************************************/
inline unsigned int ImplicitHierarchicalMap3::getCurrentLevel()
{
return m_curLevel ;
}
inline void ImplicitHierarchicalMap3::setCurrentLevel(unsigned int l)
{
assert(l >= 0 || !"Trying to set current level to a negative value") ;
m_curLevel = l ;
}
inline unsigned int ImplicitHierarchicalMap3::getMaxLevel()
{
return m_maxLevel ;
}
inline unsigned int ImplicitHierarchicalMap3::getDartLevel(Dart d)
{
return m_dartLevel[d] ;
}