Commit 0ee31044 authored by untereiner's avatar untereiner

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);
......
......@@ -24,6 +24,8 @@
#include "Algo/Modelisation/polyhedron.h"
#include <vector>
#include "Geometry/bounding_box.h"
#include <set>
namespace CGoGN
{
......@@ -54,16 +56,45 @@ typename PFP::VEC3 stringToEmb(std::string s)
return coord;
}
unsigned int gcd(unsigned int a, unsigned int b)
{
while ( true )
{
if ( a == 0 )
return b;
b %= a;
if ( b == 0 )
return a;
a %= b;
}
}
template <typename PFP>
bool importInESS(typename PFP::MAP& map, const std::string& filename, std::vector<std::string>& attrNames)
{
typedef typename PFP::VEC3 VEC3;
unsigned int em;
AttributeHandler<VEC3> position = map.template addAttribute<VEC3>(VERTEX_ORBIT, "position") ;
attrNames.push_back(position.name()) ;
AttributeContainer& container = map.getAttributeContainer(VERTEX_CELL) ;
AttributeHandler<int> objects = map.template addAttribute<int>(FACE_ORBIT, "objects") ;
attrNames.push_back(objects.name()) ;
//stocker les boundingbox contenu dans le fichier
std::vector<std::pair<VEC3,VEC3> > coordonnees; //tableau de paires (x,y)
coordonnees.reserve(50);
//classer les coordonnees en x
std::multimap<int, unsigned int> coordonneesX;
//classer les coordonnees en y
std::multimap<int, unsigned int> coordonneesY;
std::set<int> sx;
std::set<int> sy;
// open file
std::ifstream fp(filename.c_str(), std::ios::in);
......@@ -73,15 +104,20 @@ bool importInESS(typename PFP::MAP& map, const std::string& filename, std::vecto
return false;
}
//
// Lecture du fichier
//
std::string line;
size_t posData, posCoord;
std::string bg;
int count = 0;
unsigned int size = 0;
//two columns cutted
std::getline(fp, line);
posData = line.find("\t");
++count;
// First column
//Bounding box : first coord & second coord
......@@ -89,37 +125,17 @@ bool importInESS(typename PFP::MAP& map, const std::string& filename, std::vecto
posCoord = bg.find(") (");
VEC3 c1 = stringToEmb<PFP>(bg.substr(0, posCoord));
VEC3 c2 = stringToEmb<PFP>(bg.substr(posCoord+3));
std::cout << std::endl;
std::vector<std::vector<VEC3> > coordonnees; //tableau 2D avec les x en fonction des y
coordonnees.reserve(50);
//coordonnees.push_back(std::pair<VEC3,VEC3>(c1,c2));
// coordonneesX.insert(std::pair<int, unsigned int >(c1[0],size));
// coordonneesY.insert(std::pair<int, unsigned int >(c1[1],size));
sx.insert(c1[0]);
sx.insert(c2[0]);
// Dart d = map.newFace(4);
//
// em = container.insertLine();
// position[em] = c1;
// map.setDartEmbedding(VERTEX_ORBIT, d, em);
// d = map.phi1(d);
//
// em = container.insertLine();
// position[em] = VEC3(c2[0],c1[1],c2[2]);
// map.setDartEmbedding(VERTEX_ORBIT, d, em);
// d = map.phi1(d);
//
// em = container.insertLine();
// position[em] = c2;
// map.setDartEmbedding(VERTEX_ORBIT, d, em);
// d = map.phi1(d);
//
// em = container.insertLine();
// position[em] = VEC3(c1[0],c2[1],c1[2]);
// map.setDartEmbedding(VERTEX_ORBIT, d, em);
// d = map.phi1(d);
// id = container.insertLine();
// position[id] = stringToEmb<PFP>(bg.substr(0, posCoord));
// id = container.insertLine();
// position[id] = stringToEmb<PFP>(bg.substr(posCoord+3));
sy.insert(c1[1]);
sy.insert(c2[1]);
size++;
while ( std::getline( fp, line ) )
{
......@@ -132,46 +148,310 @@ bool importInESS(typename PFP::MAP& map, const std::string& filename, std::vecto
VEC3 c1 = stringToEmb<PFP>(bg.substr(0, posCoord));
VEC3 c2 = stringToEmb<PFP>(bg.substr(posCoord+3));
std::cout << std::endl;
coordonnees.push_back(std::pair<VEC3,VEC3>(c1,c2));
// coordonneesX.insert(std::pair<int, unsigned int >(c1[0],size));
// coordonneesY.insert(std::pair<int, unsigned int >(c1[1],size));
sx.insert(c1[0]);
sx.insert(c2[0]);
sy.insert(c1[1]);
sy.insert(c2[1]);
Dart d = map.newFace(4);
em = container.insertLine();
position[em] = c1;
map.setDartEmbedding(VERTEX_ORBIT, d, em);
d = map.phi1(d);
em = container.insertLine();
position[em] = VEC3(c2[0],c1[1],c2[2]);
map.setDartEmbedding(VERTEX_ORBIT, d, em);
d = map.phi1