Commit 0ee31044 authored by untereiner's avatar untereiner
Browse files

import des fichiers de l'iness + IHM3

parent 7dcd9b65
......@@ -37,11 +37,8 @@ namespace Algo
namespace IHM
{
template<typename T> class AttributeHandler_IHM ;
class ImplicitHierarchicalMap3 : public EmbeddedMap3<Map3>
{
template<typename T> friend class AttributeHandler_IHM ;
public:
unsigned int m_curLevel ;
......@@ -53,7 +50,7 @@ public:
AttributeHandler<unsigned int> m_edgeId ;
AttributeHandler<unsigned int> m_faceId ;
AttribMultiVect<unsigned int>* m_nextLevelCell[NB_ORBITS] ;
AttributeMultiVector<unsigned int>* m_nextLevelCell[NB_ORBITS] ;
public:
ImplicitHierarchicalMap3() ;
......@@ -62,13 +59,6 @@ public:
void init() ;
/***************************************************
* ATTRIBUTES MANAGEMENT *
***************************************************/
template <typename T>
AttributeHandler_IHM<T> addAttribute(unsigned int orbit, const std::string& nameAttr) ;
/***************************************************
* MAP TRAVERSAL *
***************************************************/
......@@ -79,12 +69,12 @@ public:
Dart phi_1(Dart d) ;
Dart phi2(Dart d) ;
private:
Dart phi2bis(Dart d) ;
public:
Dart phi2(Dart d) ;
Dart phi3(Dart d);
Dart alpha0(Dart d);
......@@ -141,13 +131,24 @@ public:
*/
unsigned int getNewEdgeId() ;
/**
* Return the id of the edge of d
*/
unsigned int getEdgeId(Dart d) ;
/**
* Set an edge id to all darts from an orbit of d
*/
//TODO changer l'ordre des parametres
void setEdgeId(Dart d, unsigned int i, unsigned int orbit);
/***************************************************
* FACE ID MANAGEMENT *
***************************************************/
/**
* Give a new unique id to all the faces of the map
*/
void initFaceId() ;
/**
......@@ -155,10 +156,19 @@ public:
*/
unsigned int getNewFaceId() ;
/**
* Return the id of the face of d
*/
unsigned int getFaceId(Dart d) ;
/**
* Set a face id to all darts from an orbit of d
*/
//TODO changer l'ordre des parametres
void setFaceId(Dart d, unsigned int i, unsigned int orbit);
void setFaceId(unsigned int orbit, Dart d);
/***************************************************
* CELLS INFORMATION *
***************************************************/
......@@ -174,22 +184,22 @@ public:
unsigned int edgeLevel(Dart d) ;
/**
*
* Return the level of the face of d in the current level map
*/
unsigned int faceLevel(Dart d);
/**
*
* Return the level of the volume of d in the current level map
*/
unsigned int volumeLevel(Dart d);
/**
*
* Return the oldest dart of the face of d in the current level map
*/
Dart faceOldestDart(Dart d);
/**
*
* Return the oldest dart of the volume of d in the current level map
*/
Dart volumeOldestDart(Dart d);
......@@ -200,52 +210,18 @@ public:
bool edgeIsSubdivided(Dart d) ;
/**
*
* Return true if the face of d in the current level map
* has already been subdivided to the next level
*/
bool faceIsSubdivided(Dart d) ;
/**
*
* Return true if the volume of d in the current level map
* has already been subdivided to the next level
*/
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
......
......@@ -31,32 +31,6 @@ namespace Algo
namespace IHM
{
/***************************************************
* 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 *
***************************************************/
......@@ -84,7 +58,7 @@ inline Dart ImplicitHierarchicalMap3::phi1(Dart d)
finished = true ;
else
{
if(m_edgeId[it] != edgeId)
while(m_edgeId[it] != edgeId)
it = Map3::phi1(phi2bis(it));
}
} while(!finished) ;
......@@ -106,7 +80,7 @@ inline Dart ImplicitHierarchicalMap3::phi_1(Dart d)
else
{
it = Map3::phi_1(it) ;
if(m_edgeId[it] != edgeId)
while(m_edgeId[it] != edgeId)
it = Map3::phi_1(phi2bis(it)) ;
}
} while(!finished) ;
......@@ -117,20 +91,17 @@ inline Dart ImplicitHierarchicalMap3::phi_1(Dart d)
//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);
it = Map3::phi2(Map3::phi3(it));
return it;
}
......@@ -160,48 +131,52 @@ inline Dart ImplicitHierarchicalMap3::alpha0(Dart d)
inline Dart ImplicitHierarchicalMap3::alpha1(Dart d)
{
assert(m_dartLevel[d] <= m_curLevel || !"Access to a dart introduced after current level") ;
//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;
// 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;
return Map3::alpha2(d);
}
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;
// 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;
return Map3::alpha_2(d);
}
inline Dart ImplicitHierarchicalMap3::begin()
......@@ -222,7 +197,7 @@ inline void ImplicitHierarchicalMap3::next(Dart& d)
do
{
Map3::next(d) ;
} while(m_dartLevel[d] > m_curLevel && d != Map3::end()) ;
} while(d != Map3::end() && m_dartLevel[d] > m_curLevel) ;
}
inline bool ImplicitHierarchicalMap3::foreach_dart_of_vertex(Dart d, FunctorType& f)
......@@ -429,26 +404,28 @@ inline unsigned int ImplicitHierarchicalMap3::getFaceId(Dart d)
return m_faceId[d] ;
}
inline void ImplicitHierarchicalMap3::setFaceId(Dart d, unsigned int i, unsigned int orbit)
inline void ImplicitHierarchicalMap3::setFaceId(unsigned int orbit, Dart d)
{
//Mise a jour de l'id de face pour les brins autour d'une arete
if(orbit == EDGE_ORBIT)
{
Dart e = d;
unsigned int fid;
do
{
fid = getFaceId(e);
m_faceId[e] = fid;
m_faceId[Map3::phi2(e)] = fid;
m_faceId[Map3::phi1(e)] = m_faceId[e];
e = Map3::alpha2(e);
}while(e != d);
}
}
inline void ImplicitHierarchicalMap3::setFaceId(Dart d, unsigned int i, unsigned int orbit)
{
//Mise a jour de l'id de face pour les brins autour de la face
else if(orbit == FACE_ORBIT)
if(orbit == FACE_ORBIT)
{
Dart e = d;
......@@ -466,6 +443,9 @@ inline void ImplicitHierarchicalMap3::setFaceId(Dart d, unsigned int i, unsigned
else if(orbit == DART_ORBIT)
{
m_faceId[d] = i;
if(Map3::phi3(d) != d)
m_faceId[Map3::phi3(d)] = i;
}
}
......@@ -504,65 +484,6 @@ inline unsigned int ImplicitHierarchicalMap3::edgeLevel(Dart d)
return r;
}
template <typename T>
T& AttributeHandler_IHM<T>::operator[](Dart d)
{
ImplicitHierarchicalMap3* m = reinterpret_cast<ImplicitHierarchicalMap3*>(this->m_map) ;
assert(m->m_dartLevel[d] <= m->m_curLevel || !"Access to a dart introduced after current level") ;
assert(m->vertexInsertionLevel(d) <= m->m_curLevel || !"Access to the embedding of a vertex inserted after current level") ;
unsigned int orbit = AttribContainer::orbitAttr(this->m_id) ;
unsigned int nbSteps = m->m_curLevel - m->vertexInsertionLevel(d) ;
unsigned int index = m->getEmbedding(d, orbit) ;
if(index == EMBNULL && nbSteps == 0)
{
index = m->embedNewCell(orbit, d) ;
m->m_nextLevelCell[orbit]->operator[](index) = EMBNULL ;
return this->m_attrib->operator[](index);
}
AttribContainer& cont = m->getAttributeContainer(orbit) ;
unsigned int step = 0 ;
while(step < nbSteps)
{
step++ ;
unsigned int nextIdx = m->m_nextLevelCell[orbit]->operator[](index) ;
if (nextIdx == EMBNULL)
{
nextIdx = m->newCell(orbit) ;
m->copyCell(orbit, nextIdx, index) ;
m->m_nextLevelCell[orbit]->operator[](index) = nextIdx ;
m->m_nextLevelCell[orbit]->operator[](nextIdx) = EMBNULL ;
cont.refLine(index) ;
}
index = nextIdx ;
}
return this->m_attrib->operator[](index);
}
//OK
template <typename T>
const T& AttributeHandler_IHM<T>::operator[](Dart d) const
{
ImplicitHierarchicalMap3* m = reinterpret_cast<ImplicitHierarchicalMap3*>(this->m_map) ;
assert(m->m_dartLevel[d] <= m->m_curLevel || !"Access to a dart introduced after current level") ;
assert(m->vertexInsertionLevel(d) <= m->m_curLevel || !"Access to the embedding of a vertex inserted after current level") ;
unsigned int orbit = AttribContainer::orbitAttr(this->m_id) ;
unsigned int nbSteps = m->m_curLevel - m->vertexInsertionLevel(d) ;
unsigned int index = m->getEmbedding(d, orbit) ;
unsigned int step = 0 ;
while(step < nbSteps)
{
step++ ;
unsigned int next = m->m_nextLevelCell[orbit]->operator[](index) ;
if(next != EMBNULL) index = next ;
else break ;
}
return this->m_attrib->operator[](index);
}
} //namespace IHM
......
......@@ -35,14 +35,28 @@ namespace Algo
namespace IHM
{
enum SubdivideType
{
S_TRI,
S_QUAD
} ;
template <typename PFP>
void subdivideEdge(typename PFP::MAP& map, Dart d, typename PFP::TVEC3& position) ;
template <typename PFP>
Dart subdivideFace(typename PFP::MAP& map, Dart d, typename PFP::TVEC3& position);
void subdivideFace(typename PFP::MAP& map, Dart d, typename PFP::TVEC3& position, SubdivideType sType = S_QUAD);
template <typename PFP>
void subdivideVolume(typename PFP::MAP& map, Dart d, typename PFP::TVEC3& position, SubdivideType sType = S_QUAD);
template <typename PFP>
Dart subdivideFaceTri(typename PFP::MAP& map, Dart d, typename PFP::TVEC3& position);
template <typename PFP>
void subdivideVolume(typename PFP::MAP& map, Dart d, typename PFP::TVEC3& position);
void subdivideVolumeTri(typename PFP::MAP& map, Dart d, typename PFP::TVEC3& position);
template <typename PFP>
void catmullClarck(typename PFP::MAP& map, Dart d, typename PFP::TVEC3& position);
......
......@@ -34,7 +34,6 @@ namespace Algo
namespace IHM
{
//OK
template <typename PFP>
void subdivideEdge(typename PFP::MAP& map, Dart d, typename PFP::TVEC3& position)
{
......@@ -46,8 +45,6 @@ void subdivideEdge(typename PFP::MAP& map, Dart d, typename PFP::TVEC3& position
unsigned int cur = map.getCurrentLevel() ;
map.setCurrentLevel(eLevel) ;
std::cout << "eLevel=" << eLevel << std::endl;
Dart dd = map.phi2(d) ;
typename PFP::VEC3 p1 = position[d] ;
typename PFP::VEC3 p2 = position[map.phi1(d)] ;
......@@ -56,21 +53,20 @@ void subdivideEdge(typename PFP::MAP& map, Dart d, typename PFP::TVEC3& position
map.cutEdge(d) ;
unsigned int eId = map.getEdgeId(d) ;
map.setEdgeId(map.phi1(d), eId, EDGE_ORBIT) ; //sur chaque moitie d'arete
map.setEdgeId(map.phi1(dd), eId, EDGE_ORBIT) ; //TODO peut etre a optimiser
map.setEdgeId(map.phi1(d), eId, EDGE_ORBIT) ; //mise a jour de l'id d'arrete sur chaque moitie d'arete
map.setEdgeId(map.phi1(dd), eId, EDGE_ORBIT) ;
unsigned int fId = map.getFaceId(d);
map.setFaceId(map.phi1(d), fId, EDGE_ORBIT) ;
map.setFaceId(map.phi1(dd), fId, EDGE_ORBIT) ;
map.setFaceId(EDGE_ORBIT, d) ; //mise a jour de l'id de face sur chaque brin de chaque moitie d'arete
map.setFaceId(EDGE_ORBIT, dd) ;
position[map.phi1(d)] = (p1 + p2) * typename PFP::REAL(0.5) ;
map.setCurrentLevel(cur) ;
}
//OK
template <typename PFP>
Dart subdivideFace(typename PFP::MAP& map, Dart d, typename PFP::TVEC3& position)
void subdivideFace(typename PFP::MAP& map, Dart d, typename PFP::TVEC3& position, SubdivideType sType)
{
assert(map.getDartLevel(d) <= map.getCurrentLevel() || !"Access to a dart introduced after current level") ;
assert(!map.faceIsSubdivided(d) || !"Trying to subdivide an already subdivided face") ;
......@@ -81,8 +77,6 @@ Dart subdivideFace(typename PFP::MAP& map, Dart d, typename PFP::TVEC3& position
unsigned int cur = map.getCurrentLevel() ;
map.setCurrentLevel(fLevel) ; // go to the level of the face to subdivide its edges
std::cout << "fLevel=" << fLevel << std::endl;
unsigned int degree = 0 ;
typename PFP::VEC3 p ;
Dart it = old ;
......@@ -98,11 +92,42 @@ Dart subdivideFace(typename PFP::MAP& map, Dart d, typename PFP::TVEC3& position
map.setCurrentLevel(fLevel + 1) ; // go to the next level to perform face subdivision
Dart res;
if(degree == 3 && sType == S_TRI) //subdiviser une face triangulaire
{
Dart dd = map.phi1(old) ;
Dart e = map.phi1(map.phi1(dd)) ;
map.splitFace(dd, e) ; // insert a new edge
unsigned int id = map.getNewEdgeId() ;
map.setEdgeId(map.phi_1(dd), id, EDGE_ORBIT) ; // set the edge id of the inserted edge to the next available id
//res= map.phi_1(e); //un brin de la nouvelle face du milieu
unsigned int idface = map.getFaceId(old);
map.setFaceId(dd, idface, FACE_ORBIT) ;
map.setFaceId(e, idface, FACE_ORBIT) ;
dd = e ;
e = map.phi1(map.phi1(dd)) ;
map.splitFace(dd, e) ;
id = map.getNewEdgeId() ;
map.setEdgeId(map.phi_1(dd), id, EDGE_ORBIT) ;
map.setFaceId(e, idface, FACE_ORBIT) ;
dd = e ;
e = map.phi1(map.phi1(dd)) ;
map.splitFace(dd, e) ;
id = map.getNewEdgeId() ;
map.setEdgeId(map.phi_1(dd), id, EDGE_ORBIT) ;
map.setFaceId(e, idface, FACE_ORBIT) ;
}
else
{
Dart dd = map.phi1(old) ;
map.splitFace(dd, map.phi1(map.phi1(dd))) ;
unsigned int idface = map.getFaceId(d);
map.setFaceId(map.phi1(map.phi1(dd)), idface, FACE_ORBIT) ;
map.setFaceId(map.phi2(map.phi1(map.phi1(dd))), idface, FACE_ORBIT) ;
Dart ne = map.phi2(map.phi_1(dd));
Dart ne2 = map.phi2(ne);
......@@ -113,7 +138,7 @@ Dart subdivideFace(typename PFP::MAP& map, Dart d, typename PFP::TVEC3& position
id = map.getNewEdgeId() ;
map.setEdgeId(ne2, id, EDGE_ORBIT) ;
Dart res = map.phi2(ne);
position[map.phi2(ne)] = p ;
dd = map.phi1(map.phi1(map.phi1(map.phi1(ne)))) ;
while(dd != ne)
......@@ -125,20 +150,26 @@ Dart subdivideFace(typename PFP::MAP& map, Dart d, typename PFP::TVEC3& position
id = map.getNewEdgeId() ;
map.setEdgeId(nne, id, EDGE_ORBIT) ;
map.setFaceId(nne, idface, FACE_ORBIT) ;
dd = next ;
}
position[res] = p ;
unsigned int idface = map.getFaceId(old);
Dart e = dd;
do
{
map.setFaceId(dd, idface, DART_ORBIT) ;
map.setFaceId(map.phi2(dd), idface, DART_ORBIT) ;