Commit 480085e4 authored by Sylvain Thery's avatar Sylvain Thery

update Traversor (class & examples) and add a generic Traversor

class with a factory
parent d0565b60
......@@ -65,17 +65,17 @@ add_executable( tuto_oper3 tuto_oper3.cpp ${tuto_oper3_ui} ${tuto_oper3_moc})
target_link_libraries( tuto_oper3
${CGoGN_LIBS_D} ${CGoGN_EXT_LIBS} )
#QT4_WRAP_UI( tuto_orbits_ui tuto_orbits.ui )
#QT4_WRAP_CPP(tuto_orbits_moc tuto_orbits.h)
#add_executable( tuto_orbits tuto_orbits.cpp ${tuto_orbits_ui} ${tuto_orbits_moc})
#target_link_libraries( tuto_orbits
# ${CGoGN_LIBS_D} ${CGoGN_EXT_LIBS} )
#QT4_WRAP_UI( show_traversors_ui show_traversors.ui )
#QT4_WRAP_CPP(show_traversors_moc show_traversors.h)
#add_executable( show_traversors show_traversors.cpp ${show_traversors_ui} ${show_traversors_moc})
#target_link_libraries( show_traversors
# ${CGoGN_LIBS_D} ${CGoGN_EXT_LIBS} )
QT4_WRAP_UI( tuto_orbits_ui tuto_orbits.ui )
QT4_WRAP_CPP(tuto_orbits_moc tuto_orbits.h)
add_executable( tuto_orbits tuto_orbits.cpp ${tuto_orbits_ui} ${tuto_orbits_moc})
target_link_libraries( tuto_orbits
${CGoGN_LIBS_D} ${CGoGN_EXT_LIBS} )
QT4_WRAP_UI( show_traversors_ui show_traversors.ui )
QT4_WRAP_CPP(show_traversors_moc show_traversors.h)
add_executable( show_traversors show_traversors.cpp ${show_traversors_ui} ${show_traversors_moc})
target_link_libraries( show_traversors
${CGoGN_LIBS_D} ${CGoGN_EXT_LIBS} )
add_executable( tuto_subdivision tuto_subdivision.cpp)
target_link_libraries( tuto_subdivision
......
This diff is collapsed.
......@@ -137,6 +137,9 @@ protected:
void traverse2();
void traverse3();
void dynamicMarkOrbit(unsigned int orb);
// void dyn_trav3XXaY(unsigned int first, unsigned int second);
// slots locaux
public slots:
void cb_combo1(int x);
......
......@@ -56,17 +56,18 @@ void MyQT::slider_text(int x)
void MyQT::orbit_list(int x)
{
storeVerticesInfo<int>(m_att_orbits[x]);
current_orbit = x;
unsigned int orbs[9] = {VERTEX,EDGE,FACE,VOLUME,PFP::MAP::ORBIT_IN_PARENT(VERTEX),PFP::MAP::ORBIT_IN_PARENT(EDGE),PFP::MAP::ORBIT_IN_PARENT(FACE),PFP::MAP::ORBIT_IN_PARENT2(VERTEX),PFP::MAP::ORBIT_IN_PARENT2(EDGE)};
storeVerticesInfoGen(orbs[current_orbit], m_att_orbits[x]);
if (m_clicked != Dart::nil())
{
unsigned int orbs[9] = {VERTEX,EDGE,FACE,VOLUME,PFP::MAP::ORBIT_IN_PARENT(VERTEX),PFP::MAP::ORBIT_IN_PARENT(EDGE),PFP::MAP::ORBIT_IN_PARENT(FACE),PFP::MAP::ORBIT_IN_PARENT2(VERTEX),PFP::MAP::ORBIT_IN_PARENT2(EDGE)};
m_selected.clear();
// easy way to traverse darts of orbit
TraversorDartsOfOrbit<MAP> tra(myMap, orbs[current_orbit], m_clicked);
for (Dart e = tra.begin(); e != tra.end(); e = tra.next())
Traversor<MAP>* tra = Traversor<MAP>::createDartsOfOrbits(myMap,m_clicked,orbs[current_orbit]);
for (Dart e = tra->begin(); e != tra->end(); e = tra->next())
m_selected.push_back(e);
}
......@@ -74,8 +75,8 @@ void MyQT::orbit_list(int x)
updateGL();
}
template<typename T, unsigned int ORBIT>
void MyQT::storeVerticesInfo(const AttributeHandler<T, ORBIT>& attrib)
template< unsigned int ORBIT>
void MyQT::storeVerticesInfo(const AttributeHandler<int, ORBIT>* attrib)
{
SelectorDartNoBoundary<PFP::MAP> nb(myMap);
m_render_topo->computeDartMiddlePositions<PFP>(myMap, middleDarts, nb);
......@@ -86,13 +87,54 @@ void MyQT::storeVerticesInfo(const AttributeHandler<T, ORBIT>& attrib)
if (nb(d))
{
std::stringstream ss;
ss << attrib[d];
ss << (*attrib)[d];
m_strings->addString(ss.str(), middleDarts[d]);
}
}
m_strings->sendToVBO();
}
void MyQT::storeVerticesInfoGen(unsigned int orb, const AttributeHandlerGen* attrib)
{
switch(orb)
{
case VERTEX:
storeVerticesInfo<VERTEX>(static_cast< const AttributeHandler<int, VERTEX>* >(attrib));
break;
case EDGE:
storeVerticesInfo<EDGE>(static_cast< const AttributeHandler<int, EDGE>* >(attrib));
break;
case FACE:
storeVerticesInfo<FACE>(static_cast< const AttributeHandler<int, FACE>* >(attrib));
break;
case VOLUME:
storeVerticesInfo<VOLUME>(static_cast< const AttributeHandler<int, VOLUME>* >(attrib));
break;
case PFP::MAP::VERTEX_OF_PARENT:
storeVerticesInfo<PFP::MAP::VERTEX_OF_PARENT>(static_cast< const AttributeHandler<int, PFP::MAP::VERTEX_OF_PARENT>* >(attrib));
break;
case PFP::MAP::EDGE_OF_PARENT:
storeVerticesInfo<PFP::MAP::EDGE_OF_PARENT>(static_cast< const AttributeHandler<int, PFP::MAP::EDGE_OF_PARENT>* >(attrib));
break;
case PFP::MAP::FACE_OF_PARENT:
storeVerticesInfo<PFP::MAP::FACE_OF_PARENT>(static_cast< const AttributeHandler<int, PFP::MAP::FACE_OF_PARENT>* >(attrib));
break;
case PFP::MAP::VERTEX_OF_PARENT2:
storeVerticesInfo<PFP::MAP::VERTEX_OF_PARENT2>(static_cast< const AttributeHandler<int, PFP::MAP::VERTEX_OF_PARENT2>* >(attrib));
break;
case PFP::MAP::EDGE_OF_PARENT2:
storeVerticesInfo<PFP::MAP::EDGE_OF_PARENT2>(static_cast< const AttributeHandler<int, PFP::MAP::EDGE_OF_PARENT2>* >(attrib));
break;
}
}
void MyQT::cb_initGL()
{
// choose to use GL version 2
......@@ -105,7 +147,7 @@ void MyQT::cb_initGL()
m_strings = new Utils::Strings3D(true, Geom::Vec3f(0.1f,0.0f,0.3f));
registerShader(m_strings);
storeVerticesInfo<int>(m_att_orbits[0]);
storeVerticesInfoGen(VERTEX, m_att_orbits[0]);
}
void MyQT::cb_redraw()
......@@ -132,14 +174,30 @@ void MyQT::cb_mousePress(int button, int x, int y)
m_selected.clear();
// easy way to traverse darts of orbit
TraversorDartsOfOrbit<PFP::MAP> tra(myMap, orbs[current_orbit], m_clicked);
for (Dart e = tra.begin(); e != tra.end(); e = tra.next())
Traversor<MAP>* tra = Traversor<MAP>::createDartsOfOrbits(myMap,m_clicked,orbs[current_orbit]);
for (Dart e = tra->begin(); e != tra->end(); e = tra->next())
m_selected.push_back(e);
}
updateGL();
}
}
template <unsigned int ORB>
void MyQT::init_att_orb(AttributeHandlerGen* attg)
{
int i=0;
TraversorCell<MAP,ORB> tra(myMap);
// AttributeHandler<int,ORB>* attx = reinterpret_cast< AttributeHandler<int,ORB>* >(attg);
AttributeHandler<int,ORB>* att = static_cast< AttributeHandler<int,ORB>* >(attg);
for (Dart d = tra.begin(); d != tra.end(); d = tra.next())
{
(*att)[d] = i++;
}
}
void MyQT::initMap()
{
std::cout << "INIT MAP"<< std::endl;
......@@ -150,78 +208,36 @@ void MyQT::initMap()
prim.hexaGrid_topo(nb,nb,nb);
prim.embedHexaGrid(1.0f,1.0f,1.0f);
m_att_orbits[0] = myMap.addAttribute<int, VERTEX>("vertex");
m_att_orbits[1] = myMap.addAttribute<int, EDGE>("edge");
m_att_orbits[2] = myMap.addAttribute<int, FACE>("face");
m_att_orbits[3] = myMap.addAttribute<int, VOLUME>("volume");
m_att_orbits[4] = myMap.addAttribute<int, VERTEX + PFP::MAP::IN_PARENT>("vertex2");
m_att_orbits[5] = myMap.addAttribute<int, EDGE + PFP::MAP::IN_PARENT>("edge2");
m_att_orbits[6] = myMap.addAttribute<int, FACE + PFP::MAP::IN_PARENT>("face2");
m_att_orbits[7] = myMap.addAttribute<int, VERTEX + PFP::MAP::IN_PARENT2>("vertex1");
m_att_orbits[8] = myMap.addAttribute<int, EDGE + PFP::MAP::IN_PARENT2>("face1");
AttributeHandler<int, VERTEX> att0 = myMap.addAttribute<int, VERTEX>("vertex");
m_att_orbits[0] = new AttributeHandler<int, VERTEX>(att0);
init_att_orb<VERTEX>(m_att_orbits[0]);
int i=0;
TraversorV<MAP> tra0(myMap);
for (Dart d = tra0.begin(); d != tra0.end(); d = tra0.next())
{
m_att_orbits[0][d] = i++;
}
m_att_orbits[1] = new AttributeHandler<int, EDGE>(myMap.addAttribute<int, EDGE>("edge"));
m_att_orbits[2] = new AttributeHandler<int, FACE>(myMap.addAttribute<int, FACE>("face"));
m_att_orbits[3] = new AttributeHandler<int, VOLUME>(myMap.addAttribute<int, VOLUME>("volume"));
m_att_orbits[4] = new AttributeHandler<int, VERTEX + PFP::MAP::IN_PARENT>(myMap.addAttribute<int, VERTEX + PFP::MAP::IN_PARENT>("vertex2"));
m_att_orbits[5] = new AttributeHandler<int, EDGE + PFP::MAP::IN_PARENT>(myMap.addAttribute<int, EDGE + PFP::MAP::IN_PARENT>("edge2"));
m_att_orbits[6] = new AttributeHandler<int, FACE + PFP::MAP::IN_PARENT>(myMap.addAttribute<int, FACE + PFP::MAP::IN_PARENT>("face2"));
m_att_orbits[7] = new AttributeHandler<int, VERTEX + PFP::MAP::IN_PARENT2>(myMap.addAttribute<int, VERTEX + PFP::MAP::IN_PARENT2>("vertex1"));
m_att_orbits[8] = new AttributeHandler<int, EDGE + PFP::MAP::IN_PARENT2>(myMap.addAttribute<int, EDGE + PFP::MAP::IN_PARENT2>("face1"));
i=0;
TraversorE<MAP> tra1(myMap);
for (Dart d = tra1.begin(); d != tra1.end(); d = tra1.next())
{
m_att_orbits[1][d] = i++;
}
i=0;
TraversorF<MAP> tra2(myMap);
for (Dart d = tra2.begin(); d != tra2.end(); d = tra2.next())
{
m_att_orbits[2][d] = i++;
}
i=0;
TraversorW<PFP::MAP> tra3(myMap);
for (Dart d = tra3.begin(); d != tra3.end(); d = tra3.next())
{
m_att_orbits[3][d] = i++;
}
init_att_orb<EDGE>(m_att_orbits[1]);
i=0;
TraversorCell<MAP, VERTEX + PFP::MAP::IN_PARENT> tra02(myMap);
for (Dart d = tra02.begin(); d != tra02.end(); d = tra02.next())
{
m_att_orbits[4][d] = i++;
}
init_att_orb<FACE>(m_att_orbits[2]);
i=0;
TraversorCell<MAP, EDGE + PFP::MAP::IN_PARENT> tra12(myMap);
for (Dart d = tra12.begin(); d != tra12.end(); d = tra12.next())
{
m_att_orbits[5][d] = i++;
}
init_att_orb<VOLUME>(m_att_orbits[3]);
i=0;
TraversorCell<MAP, FACE + PFP::MAP::IN_PARENT> tra22(myMap);
for (Dart d = tra22.begin(); d != tra22.end(); d = tra22.next())
{
m_att_orbits[6][d] = i++;
}
init_att_orb<PFP::MAP::VERTEX_OF_PARENT>(m_att_orbits[4]);
i=0;
TraversorCell<MAP, VERTEX + PFP::MAP::IN_PARENT2> tra01(myMap);
for (Dart d = tra01.begin(); d != tra01.end(); d = tra01.next())
{
m_att_orbits[7][d] = i++;
}
init_att_orb<PFP::MAP::EDGE_OF_PARENT>(m_att_orbits[5]);
i=0;
TraversorCell<MAP, EDGE + PFP::MAP::IN_PARENT2> tra11(myMap);
for (Dart d = tra11.begin(); d != tra11.end(); d = tra11.next())
{
m_att_orbits[8][d] = i++;
}
init_att_orb<PFP::MAP::FACE_OF_PARENT>(m_att_orbits[6]);
init_att_orb<PFP::MAP::VERTEX_OF_PARENT2>(m_att_orbits[7]);
init_att_orb<PFP::MAP::EDGE_OF_PARENT2>(m_att_orbits[8]);
middleDarts = myMap.addAttribute<VEC3, DART>("middle");
}
......
......@@ -105,8 +105,7 @@ class MyQT: public Utils::QT::SimpleQT
Algo::Render::GL2::ExplodeVolumeRender* m_explodeRender;
// AttributeHandler<int> attv2;
AttributeHandler<int> m_att_orbits[9];
AttributeHandlerGen* m_att_orbits[9];
QTimer *m_timer;
unsigned int current_orbit;
......@@ -136,8 +135,13 @@ public:
void initMap();
protected:
template <typename T, unsigned int ORBIT>
void storeVerticesInfo(const AttributeHandler<T, ORBIT>& attrib);
template <unsigned int ORBIT>
void storeVerticesInfo(const AttributeHandler<int, ORBIT>* attrib);
void storeVerticesInfoGen(unsigned int orb, const AttributeHandlerGen* attrib);
template <unsigned int ORB>
void init_att_orb(AttributeHandlerGen* attg);
void cb_redraw();
void cb_initGL();
......
......@@ -22,11 +22,15 @@
* *
*******************************************************************************/
#include "Topology/generic/traversorGen.h"
#ifndef __TRAVERSOR1_H__
#define __TRAVERSOR1_H__
#include "Topology/generic/dart.h"
namespace CGoGN
{
......@@ -36,7 +40,7 @@ namespace CGoGN
// Traverse the edges incident to a given vertex
template <typename MAP>
class Traversor1VE
class Traversor1VE: public Traversor<MAP>
{
private:
MAP& m ;
......@@ -54,7 +58,8 @@ public:
} ;
// Traverse the vertices adjacent to a given vertex through sharing a common edge
class Traversor1VVaE
template <typename MAP>
class Traversor1VVaE: public Traversor<MAP>
{
private:
MAP& m ;
......@@ -77,7 +82,7 @@ public:
// Traverse the vertices incident to a given edge
template <typename MAP>
class Traversor1EV
class Traversor1EV: public Traversor<MAP>
{
private:
MAP& m ;
......@@ -95,7 +100,8 @@ public:
} ;
// Traverse the edges adjacent to a given edge through sharing a common vertex
class Traversor1EEaV
template <typename MAP>
class Traversor1EEaV: public Traversor<MAP>
{
private:
MAP& m ;
......
......@@ -22,38 +22,25 @@
* *
*******************************************************************************/
#include "Topology/generic/traversorGen.h"
#ifndef __TRAVERSOR2_H__
#define __TRAVERSOR2_H__
#include "Topology/generic/dart.h"
namespace CGoGN
{
/*******************************************************************************
GENERIC TRAVERSALS FACTORY
*******************************************************************************/
template <typename MAP>
class Traversor2
{
public:
virtual ~Traversor2() {}
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>
class Traversor2VE: public Traversor<MAP>
{
private:
MAP& m ;
......@@ -70,7 +57,7 @@ public:
// Traverse the faces incident to a given vertex
template <typename MAP>
class Traversor2VF : public Traversor2<MAP>
class Traversor2VF : public Traversor<MAP>
{
private:
MAP& m ;
......@@ -87,7 +74,7 @@ public:
// Traverse the vertices adjacent to a given vertex through sharing a common edge
template <typename MAP>
class Traversor2VVaE : public Traversor2<MAP>
class Traversor2VVaE : public Traversor<MAP>
{
private:
MAP& m ;
......@@ -104,7 +91,7 @@ public:
// Traverse the vertices adjacent to a given vertex through sharing a common face
template <typename MAP>
class Traversor2VVaF : public Traversor2<MAP>
class Traversor2VVaF : public Traversor<MAP>
{
private:
MAP& m ;
......@@ -127,7 +114,7 @@ public:
// Traverse the vertices incident to a given edge
template <typename MAP>
class Traversor2EV : public Traversor2<MAP>
class Traversor2EV : public Traversor<MAP>
{
private:
MAP& m ;
......@@ -144,7 +131,7 @@ public:
// Traverse the faces incident to a given edge
template <typename MAP>
class Traversor2EF : public Traversor2<MAP>
class Traversor2EF : public Traversor<MAP>
{
private:
MAP& m ;
......@@ -161,7 +148,7 @@ public:
// Traverse the edges adjacent to a given edge through sharing a common vertex
template <typename MAP>
class Traversor2EEaV : public Traversor2<MAP>
class Traversor2EEaV : public Traversor<MAP>
{
private:
MAP& m ;
......@@ -180,7 +167,7 @@ public:
// Traverse the edges adjacent to a given edge through sharing a common face
template <typename MAP>
class Traversor2EEaF : public Traversor2<MAP>
class Traversor2EEaF : public Traversor<MAP>
{
private:
MAP& m ;
......@@ -203,7 +190,7 @@ public:
// Traverse the vertices incident to a given face
template <typename MAP>
class Traversor2FV : public Traversor2<MAP>
class Traversor2FV : public Traversor<MAP>
{
private:
MAP& m ;
......@@ -229,7 +216,7 @@ public:
// Traverse the faces adjacent to a given face through sharing a common vertex
template <typename MAP>
class Traversor2FFaV : public Traversor2<MAP>
class Traversor2FFaV : public Traversor<MAP>
{
private:
MAP& m ;
......@@ -248,7 +235,7 @@ public:
// Traverse the faces adjacent to a given face through sharing a common edge
template <typename MAP>
class Traversor2FFaE : public Traversor2<MAP>
class Traversor2FFaE : public Traversor<MAP>
{
private:
MAP& m ;
......
......@@ -454,68 +454,68 @@ Dart Traversor2FFaE<MAP>::next()
}
template<typename MAP>
Traversor2<MAP>* Traversor2<MAP>::createIncident(MAP& map, Dart dart, unsigned int orbX, unsigned int orbY)
{
int code = 0x100*(orbX-VERTEX) + orbY-VERTEX;
switch(code)
{
case 0x0001:
return new Traversor2VE<MAP>(map,dart);
break;
case 0x0002:
return new Traversor2VF<MAP>(map,dart);
break;
case 0x0100:
return new Traversor2EV<MAP>(map,dart);
break;
case 0x0102:
return new Traversor2EF<MAP>(map,dart);
break;
case 0x0200:
return new Traversor2FV<MAP>(map,dart);
break;
case 0x0201:
return new Traversor2FE<MAP>(map,dart);
break;
default:
return NULL;
break;
}
return NULL;
}
template<typename MAP>
Traversor2<MAP>* Traversor2<MAP>::createAdjacent(MAP& map, Dart dart, unsigned int orbX, unsigned int orbY)
{
int code = 0x100*(orbX-VERTEX) + orbY-VERTEX;
switch(code)
{
case 0x0001:
return new Traversor2VVaE<MAP>(map,dart);
break;
case 0x0002:
return new Traversor2VVaF<MAP>(map,dart);
break;
case 0x0100:
return new Traversor2EEaV<MAP>(map,dart);
break;
case 0x0102:
return new Traversor2EEaF<MAP>(map,dart);
break;
case 0x0200:
return new Traversor2FFaV<MAP>(map,dart);
break;
case 0x0201:
return new Traversor2FFaE<MAP>(map,dart);
break;
default:
return NULL;
break;
}
return NULL;
}
//
//template<typename MAP>
//Traversor2<MAP>* Traversor2<MAP>::createIncident(MAP& map, Dart dart, unsigned int orbX, unsigned int orbY)
//{
// int code = 0x100*(orbX-VERTEX) + orbY-VERTEX;
//
// switch(code)
// {
// case 0x0001:
// return new Traversor2VE<MAP>(map,dart);
// break;
// case 0x0002:
// return new Traversor2VF<MAP>(map,dart);
// break;
// case 0x0100:
// return new Traversor2EV<MAP>(map,dart);
// break;
// case 0x0102:
// return new Traversor2EF<MAP>(map,dart);
// break;
// case 0x0200:
// return new Traversor2FV<MAP>(map,dart);
// break;
// case 0x0201:
// return new Traversor2FE<MAP>(map,dart);
// break;
// default:
// return NULL;
// break;
// }
// return NULL;
//}
//
//template<typename MAP>
//Traversor2<MAP>* Traversor2<MAP>::createAdjacent(MAP& map, Dart dart, unsigned int orbX, unsigned int orbY)
//{
// int code = 0x100*(orbX-VERTEX) + orbY-VERTEX;
// switch(code)
// {
// case 0x0001:
// return new Traversor2VVaE<MAP>(map,dart);
// break;
// case 0x0002:
// return new Traversor2VVaF<MAP>(map,dart);
// break;
// case 0x0100:
// return new Traversor2EEaV<MAP>(map,dart);
// break;
// case 0x0102:
// return new Traversor2EEaF<MAP>(map,dart);
// break;
// case 0x0200:
// return new Traversor2FFaV<MAP>(map,dart);
// break;
// case 0x0201:
// return new Traversor2FFaE<MAP>(map,dart);
// break;
// default:
// return NULL;
// break;
// }
// return NULL;
//}
} // namespace CGoGN
......@@ -21,6 +21,7 @@
* Contact information: cgogn@unistra.fr *
* *
*******************************************************************************/
#include "Topology/generic/traversorGen.h"
#ifndef __TRAVERSOR3_H__
#define __TRAVERSOR3_H__
......@@ -28,6 +29,7 @@
#include "Topology/generic/dart.h"
#include "Topology/generic/traversorCell.h"
namespace CGoGN
{
......@@ -53,12 +55,13 @@ public: