Commit 1517fd39 authored by Sylvain Thery's avatar Sylvain Thery
Browse files

Modification of topological rendering

TopoRender & Topo3Render can now directly render Map & GMap (see tuto1 & tuto5)
Correction of bug in gmap2 (face of boundary was not marked)
parent 5835f74c
...@@ -88,7 +88,7 @@ void MyQT::createMap() ...@@ -88,7 +88,7 @@ void MyQT::createMap()
// initialization GL callback // initialization GL callback
void MyQT::cb_initGL() void MyQT::cb_initGL()
{ {
m_render_topo = new Algo::Render::GL2::TopoRenderMapD() ; m_render_topo = new Algo::Render::GL2::TopoRender() ;
} }
// redraw GL callback (clear and swap already done) // redraw GL callback (clear and swap already done)
......
...@@ -25,14 +25,20 @@ ...@@ -25,14 +25,20 @@
#ifndef _TUTO1_ #ifndef _TUTO1_
#define _TUTO1_ #define _TUTO1_
#define USE_GMAP
#include "Utils/Qt/qtSimple.h" #include "Utils/Qt/qtSimple.h"
#include "Utils/cgognStream.h" #include "Utils/cgognStream.h"
#include "Topology/generic/parameters.h" #include "Topology/generic/parameters.h"
#include "Topology/map/embeddedMap2.h"
#include "Algo/Render/GL2/topoRender.h"
#ifdef USE_GMAP
#include "Topology/gmap/embeddedGMap2.h"
#else
#include "Topology/map/embeddedMap2.h"
#endif
#include "Algo/Render/GL2/topoRender.h"
using namespace CGoGN ; using namespace CGoGN ;
...@@ -43,10 +49,15 @@ using namespace CGoGN ; ...@@ -43,10 +49,15 @@ using namespace CGoGN ;
struct PFP: public PFP_STANDARD struct PFP: public PFP_STANDARD
{ {
// definition of the type of the map // definition of the type of the map
#ifdef USE_GMAP
typedef EmbeddedGMap2 MAP;
#else
typedef EmbeddedMap2 MAP; typedef EmbeddedMap2 MAP;
#endif
}; };
class MyQT: public Utils::QT::SimpleQT class MyQT: public Utils::QT::SimpleQT
{ {
Q_OBJECT Q_OBJECT
...@@ -61,7 +72,7 @@ protected: ...@@ -61,7 +72,7 @@ protected:
PFP::MAP myMap; PFP::MAP myMap;
// render (for the topo) // render (for the topo)
Algo::Render::GL2::TopoRenderMapD* m_render_topo; Algo::Render::GL2::TopoRender* m_render_topo;
// just for more compact writing // just for more compact writing
inline Dart PHI1(Dart d) {return myMap.phi1(d);} inline Dart PHI1(Dart d) {return myMap.phi1(d);}
......
...@@ -25,12 +25,18 @@ ...@@ -25,12 +25,18 @@
#ifndef _TUTO2_ #ifndef _TUTO2_
#define _TUTO2_ #define _TUTO2_
#define USE_GMAP
#include "Utils/Qt/qtSimple.h" #include "Utils/Qt/qtSimple.h"
#include "Utils/cgognStream.h" #include "Utils/cgognStream.h"
#include "Topology/generic/parameters.h" #include "Topology/generic/parameters.h"
#include "Topology/map/embeddedMap2.h"
#ifdef USE_GMAP
#include "Topology/gmap/embeddedGMap2.h"
#else
#include "Topology/map/embeddedMap2.h"
#endif
#include "Algo/Render/GL2/mapRender.h" #include "Algo/Render/GL2/mapRender.h"
#include "Utils/Shaders/shaderSimpleColor.h" #include "Utils/Shaders/shaderSimpleColor.h"
...@@ -46,7 +52,11 @@ using namespace CGoGN ; ...@@ -46,7 +52,11 @@ using namespace CGoGN ;
struct PFP: public PFP_STANDARD struct PFP: public PFP_STANDARD
{ {
// definition of the type of the map // definition of the type of the map
#ifdef USE_GMAP
typedef EmbeddedGMap2 MAP;
#else
typedef EmbeddedMap2 MAP; typedef EmbeddedMap2 MAP;
#endif
}; };
......
...@@ -157,7 +157,7 @@ void MyQT::createMap() ...@@ -157,7 +157,7 @@ void MyQT::createMap()
// initialization GL callback // initialization GL callback
void MyQT::cb_initGL() void MyQT::cb_initGL()
{ {
m_render_topo = new Algo::Render::GL2::TopoRenderMapD() ; m_render_topo = new Algo::Render::GL2::TopoRender();
} }
// redraw GL callback (clear and swap already done) // redraw GL callback (clear and swap already done)
......
...@@ -65,7 +65,7 @@ protected: ...@@ -65,7 +65,7 @@ protected:
PFP::TVEC3 position; PFP::TVEC3 position;
// render (for the topo) // render (for the topo)
Algo::Render::GL2::TopoRenderMapD* m_render_topo; Algo::Render::GL2::TopoRender* m_render_topo;
// selected dart (mouse click) // selected dart (mouse click)
Dart dart_selected; Dart dart_selected;
......
...@@ -165,7 +165,7 @@ void MyQT::createMap() ...@@ -165,7 +165,7 @@ void MyQT::createMap()
// initialization GL callback // initialization GL callback
void MyQT::cb_initGL() void MyQT::cb_initGL()
{ {
m_render_topo = new Algo::Render::GL2::TopoRenderMapD() ; m_render_topo = new Algo::Render::GL2::TopoRender() ;
} }
// redraw GL callback (clear and swap already done) // redraw GL callback (clear and swap already done)
......
...@@ -63,7 +63,7 @@ protected: ...@@ -63,7 +63,7 @@ protected:
PFP::TVEC3 position; PFP::TVEC3 position;
// render (for the topo) // render (for the topo)
Algo::Render::GL2::TopoRenderMapD* m_render_topo; Algo::Render::GL2::TopoRender* m_render_topo;
// selected dart (mouse click) // selected dart (mouse click)
std::vector<Dart> dart_selected; std::vector<Dart> dart_selected;
......
...@@ -22,13 +22,18 @@ ...@@ -22,13 +22,18 @@
* * * *
*******************************************************************************/ *******************************************************************************/
#include "tuto5.h" #define WITH_GMAP 1
#include "tuto5.h"
#include <iostream> #include <iostream>
#include "Topology/generic/parameters.h" #include "Topology/generic/parameters.h"
#include "Topology/map/embeddedMap3.h" #ifdef WITH_GMAP
#include "Topology/gmap/embeddedGMap3.h"
#else
#include "Topology/map/embeddedMap3.h"
#endif
#include "Geometry/vector_gen.h" #include "Geometry/vector_gen.h"
#include "Algo/Geometry/boundingbox.h" #include "Algo/Geometry/boundingbox.h"
...@@ -55,7 +60,11 @@ using namespace CGoGN ; ...@@ -55,7 +60,11 @@ using namespace CGoGN ;
struct PFP: public PFP_STANDARD struct PFP: public PFP_STANDARD
{ {
// definition de la carte // definition de la carte
#ifdef WITH_GMAP
typedef EmbeddedGMap3 MAP;
#else
typedef EmbeddedMap3 MAP; typedef EmbeddedMap3 MAP;
#endif
}; };
PFP::MAP myMap; PFP::MAP myMap;
...@@ -143,7 +152,7 @@ void MyQT::cb_initGL() ...@@ -143,7 +152,7 @@ void MyQT::cb_initGL()
// create the render // create the render
m_render = new Algo::Render::GL2::MapRender(); m_render = new Algo::Render::GL2::MapRender();
m_render_topo = new Algo::Render::GL2::Topo3RenderMapD(); m_render_topo = new Algo::Render::GL2::Topo3Render();
// create VBO for position // create VBO for position
m_positionVBO = new Utils::VBO(); m_positionVBO = new Utils::VBO();
...@@ -190,7 +199,7 @@ void MyQT::cb_initGL() ...@@ -190,7 +199,7 @@ void MyQT::cb_initGL()
m_render->initPrimitives<PFP>(myMap, allDarts, Algo::Render::GL2::POINTS); m_render->initPrimitives<PFP>(myMap, allDarts, Algo::Render::GL2::POINTS);
SelectorDartNoBoundary<PFP::MAP> nb(myMap); SelectorDartNoBoundary<PFP::MAP> nb(myMap);
m_render_topo->updateData<PFP>(myMap, nb, position, 0.9f, 0.9f, 0.9f); m_render_topo->updateData<PFP>(myMap, position, 0.9f, 0.9f, 0.9f, nb);
// timer example for animation // timer example for animation
......
...@@ -36,7 +36,7 @@ ...@@ -36,7 +36,7 @@
// forward definitions (minimize includes) // forward definitions (minimize includes)
namespace CGoGN { namespace Algo { namespace Render { namespace GL2 { class MapRender; } } } } namespace CGoGN { namespace Algo { namespace Render { namespace GL2 { class MapRender; } } } }
namespace CGoGN { namespace Algo { namespace Render { namespace GL2 { class Topo3RenderMapD; } } } } namespace CGoGN { namespace Algo { namespace Render { namespace GL2 { class Topo3Render; } } } }
namespace CGoGN { namespace Utils { class VBO; } } namespace CGoGN { namespace Utils { class VBO; } }
namespace CGoGN { namespace Utils { class ShaderSimpleColor; } } namespace CGoGN { namespace Utils { class ShaderSimpleColor; } }
namespace CGoGN { namespace Utils { class Strings3D; } } namespace CGoGN { namespace Utils { class Strings3D; } }
...@@ -63,7 +63,7 @@ class MyQT: public Utils::QT::SimpleQT ...@@ -63,7 +63,7 @@ class MyQT: public Utils::QT::SimpleQT
bool render_topo; bool render_topo;
Algo::Render::GL2::MapRender* m_render; Algo::Render::GL2::MapRender* m_render;
Algo::Render::GL2::Topo3RenderMapD* m_render_topo; Algo::Render::GL2::Topo3Render* m_render_topo;
Utils::VBO* m_positionVBO; Utils::VBO* m_positionVBO;
Utils::VBO* m_dataVBO; Utils::VBO* m_dataVBO;
......
...@@ -60,9 +60,9 @@ protected: ...@@ -60,9 +60,9 @@ protected:
/** /**
* vbo buffers * vbo buffers
* 0: vertices darts * 0: vertices darts
* 1: vertices phi1 * 1: vertices phi1 / beta1
* 2: vertices phi2 * 2: vertices phi2 / beta2
* 3: vertices phi3 * 3: vertices phi3 / beta3
* 4: colors * 4: colors
*/ */
Utils::VBO* m_vbo0; Utils::VBO* m_vbo0;
...@@ -238,8 +238,6 @@ public: ...@@ -238,8 +238,6 @@ public:
*/ */
void overdrawDart(Dart d, float width, float r, float g, float b); void overdrawDart(Dart d, float width, float r, float g, float b);
/* /*
* store darts in color for picking * store darts in color for picking
* @param map the map (must be the same than during updating data) * @param map the map (must be the same than during updating data)
...@@ -248,8 +246,6 @@ public: ...@@ -248,8 +246,6 @@ public:
template<typename PFP> template<typename PFP>
void setDartsIdColor(typename PFP::MAP& map, const FunctorSelect& good); void setDartsIdColor(typename PFP::MAP& map, const FunctorSelect& good);
/** /**
* pick dart with color set bey setDartsIdColor * pick dart with color set bey setDartsIdColor
* Do not forget to apply same transformation to scene before picking than before drawing ! * Do not forget to apply same transformation to scene before picking than before drawing !
...@@ -262,13 +258,6 @@ public: ...@@ -262,13 +258,6 @@ public:
template<typename PFP> template<typename PFP>
Dart picking(typename PFP::MAP& map, const FunctorSelect& good, int x, int y); Dart picking(typename PFP::MAP& map, const FunctorSelect& good, int x, int y);
};
class Topo3RenderMapD: public Topo3Render
{
public:
/** /**
* update all drawing buffers to render a dual map * update all drawing buffers to render a dual map
* @param map the map * @param map the map
...@@ -279,27 +268,37 @@ public: ...@@ -279,27 +268,37 @@ public:
* @param kv exploding coef for face * @param kv exploding coef for face
*/ */
template<typename PFP> template<typename PFP>
void updateData(typename PFP::MAP& map, const FunctorSelect& good, const typename PFP::TVEC3& positions, float ke, float kf, float kv); void updateData(typename PFP::MAP& map, const typename PFP::TVEC3& positions, float ke, float kf, float kv, const FunctorSelect& good = allDarts);
};
protected:
/**
* update all drawing buffers to render a dual map
* @param map the map
* @param positions attribute of position vertices
* @param ke exploding coef for edge
* @param kf exploding coef for face
* @param kv exploding coef for face
* @param good selector
*/
template<typename PFP>
void updateDataMap3(typename PFP::MAP& map, const typename PFP::TVEC3& positions, float ke, float kf, float kv, const FunctorSelect& good = allDarts);
class Topo3RenderGMap: public Topo3Render
{
public:
/** /**
* update all drawing buffers to render a gmap * update all drawing buffers to render a gmap
* @param map the map * @param map the map
* @param good selector
* @param positions attribute of position vertices * @param positions attribute of position vertices
* @param ke exploding coef for edge * @param ke exploding coef for edge
* @param kf exploding coef for face * @param kf exploding coef for face
* @param kv exploding coef for face * @param kv exploding coef for face
* @param good selector
*/ */
template<typename PFP> template<typename PFP>
void updateData(typename PFP::MAP& map, const FunctorSelect& good, const typename PFP::TVEC3& positions, float kd, float ke, float kf, float kv); void updateDataGMap3(typename PFP::MAP& map, const typename PFP::TVEC3& positions, float ke, float kf, float kv, const FunctorSelect& good = allDarts);
}; };
}//end namespace VBO
}//end namespace GL2
}//end namespace Algo }//end namespace Algo
......
...@@ -42,10 +42,27 @@ namespace Render ...@@ -42,10 +42,27 @@ namespace Render
namespace GL2 namespace GL2
{ {
template<typename PFP>
void Topo3Render::updateData(typename PFP::MAP& map, const typename PFP::TVEC3& positions, float ke, float kf, float kv, const FunctorSelect& good)
{
Map3* ptrMap3 = dynamic_cast<Map3*>(&map);
if (ptrMap3 != NULL)
{
updateDataMap3<PFP>(map,positions,ke,kf,kv,good);
}
GMap3* ptrGMap3 = dynamic_cast<GMap3*>(&map);
if (ptrGMap3 != NULL)
{
updateDataGMap3<PFP>(map,positions,ke,kf,kv,good);
}
}
template<typename PFP> template<typename PFP>
void Topo3RenderMapD::updateData(typename PFP::MAP& map, const FunctorSelect& good, const typename PFP::TVEC3& positions, float ke, float kf, float kv) void Topo3Render::updateDataMap3(typename PFP::MAP& mapx, const typename PFP::TVEC3& positions, float ke, float kf, float kv, const FunctorSelect& good)
{ {
Map3& map = reinterpret_cast<Map3&>(mapx);
typedef typename PFP::VEC3 VEC3; typedef typename PFP::VEC3 VEC3;
typedef typename PFP::REAL REAL; typedef typename PFP::REAL REAL;
...@@ -57,8 +74,6 @@ void Topo3RenderMapD::updateData(typename PFP::MAP& map, const FunctorSelect& go ...@@ -57,8 +74,6 @@ void Topo3RenderMapD::updateData(typename PFP::MAP& map, const FunctorSelect& go
m_attIndex = map.template addAttribute<unsigned int>(DART, "dart_index"); m_attIndex = map.template addAttribute<unsigned int>(DART, "dart_index");
} }
m_nbDarts = 0; m_nbDarts = 0;
// table of center of volume // table of center of volume
...@@ -236,7 +251,7 @@ void Topo3RenderMapD::updateData(typename PFP::MAP& map, const FunctorSelect& go ...@@ -236,7 +251,7 @@ void Topo3RenderMapD::updateData(typename PFP::MAP& map, const FunctorSelect& go
m_nbRel2++; m_nbRel2++;
} }
e = map.phi3(d); e = map.phi3(d);
if (!map.isBoundaryFace(d) && (d < e)) if (!map.isBoundaryMarked(e) && (d < e))
{ {
*positionF3++ = fv2[d]; *positionF3++ = fv2[d];
*positionF3++ = fv2x[e]; *positionF3++ = fv2x[e];
...@@ -268,7 +283,6 @@ void Topo3RenderMapD::updateData(typename PFP::MAP& map, const FunctorSelect& go ...@@ -268,7 +283,6 @@ void Topo3RenderMapD::updateData(typename PFP::MAP& map, const FunctorSelect& go
template<typename PFP> template<typename PFP>
void Topo3Render::setDartsIdColor(typename PFP::MAP& map, const FunctorSelect& good) void Topo3Render::setDartsIdColor(typename PFP::MAP& map, const FunctorSelect& good)
{ {
m_vbo4->bind(); m_vbo4->bind();
float* colorBuffer = reinterpret_cast<float*>(glMapBuffer(GL_ARRAY_BUFFER, GL_READ_WRITE)); float* colorBuffer = reinterpret_cast<float*>(glMapBuffer(GL_ARRAY_BUFFER, GL_READ_WRITE));
unsigned int nb=0; unsigned int nb=0;
...@@ -312,15 +326,13 @@ Dart Topo3Render::picking(typename PFP::MAP& map, const FunctorSelect& good, int ...@@ -312,15 +326,13 @@ Dart Topo3Render::picking(typename PFP::MAP& map, const FunctorSelect& good, int
} }
template<typename PFP> template<typename PFP>
void Topo3RenderGMap::updateData(typename PFP::MAP& map, const FunctorSelect& good, const typename PFP::TVEC3& positions, float kd, float ke, float kf, float kv) void Topo3Render::updateDataGMap3(typename PFP::MAP& mapx, const typename PFP::TVEC3& positions, float ke, float kf, float kv, const FunctorSelect& good)
{ {
GMap3& map = reinterpret_cast<GMap3&>(mapx);
typedef typename PFP::VEC3 VEC3; typedef typename PFP::VEC3 VEC3;
typedef typename PFP::REAL REAL; typedef typename PFP::REAL REAL;
AutoAttributeHandler<Geom::Vec3f> posBeta1(map, DART);
AutoAttributeHandler<Geom::Vec3f> posBeta2(map, DART); //beta 3 link is represented at the same location as beta2
AutoAttributeHandler<Geom::Vec3f> posBeta2x(map, DART); //beta 3 link is represented at the same location as beta2
AutoAttributeHandler<Geom::Vec3f> vert(map, DART);
if (m_attIndex.map() != &map) if (m_attIndex.map() != &map)
{ {
...@@ -331,29 +343,25 @@ void Topo3RenderGMap::updateData(typename PFP::MAP& map, const FunctorSelect& go ...@@ -331,29 +343,25 @@ void Topo3RenderGMap::updateData(typename PFP::MAP& map, const FunctorSelect& go
m_nbDarts = 0; m_nbDarts = 0;
// table of face (one dart of each) // table of center of volume
std::vector<Dart> vecDartFaces; std::vector<VEC3> vecCenters;
vecDartFaces.reserve(map.getNbDarts()/6); //6 = nb of darts for tri mesh vecCenters.reserve(1000);
// table of nbfaces per volume // table of nbfaces per volume
std::vector<unsigned int> vecNbFaces; std::vector<unsigned int> vecNbFaces;
vecNbFaces.reserve(vecDartFaces.size()); vecNbFaces.reserve(1000);
// table of face (one dart of each)
// table of center of volume std::vector<Dart> vecDartFaces;
std::vector<VEC3> vecVolCenters; vecDartFaces.reserve(map.getNbDarts()/4);
vecVolCenters.reserve(vecDartFaces.size()/4); // = nb of volumes for a tetra mesh
DartMarker mark(map); // marker for darts DartMarker mark(map); // marker for darts
CellMarker mVol(map, VOLUME);
for (Dart d = map.begin(); d != map.end(); map.next(d)) for (Dart d = map.begin(); d != map.end(); map.next(d))
{ {
if(!mVol.isMarked(d)) if (good(d))
{ {
mVol.mark(d);
CellMarkerStore markVert(map, VERTEX); //marker for vertices CellMarkerStore markVert(map, VERTEX); //marker for vertices
VEC3 center(0); VEC3 center(0, 0, 0);
unsigned int nbVertices = 0; unsigned int nbv = 0;
unsigned int nbFace = 0; unsigned int nbf = 0;
std::list<Dart> visitedFaces; // Faces that are traversed std::list<Dart> visitedFaces; // Faces that are traversed
visitedFaces.push_back(d); // Start with the face of d visitedFaces.push_back(d); // Start with the face of d
...@@ -364,31 +372,285 @@ void Topo3RenderGMap::updateData(typename PFP::MAP& map, const FunctorSelect& go ...@@ -364,31 +372,285 @@ void Topo3RenderGMap::updateData(typename PFP::MAP& map, const FunctorSelect& go
{ {
// store a dart of face // store a dart of face
vecDartFaces.push_back(*face); vecDartFaces.push_back(*face);
nbFace++; nbf++;
Dart dNext = *face ; Dart dNext = *face ;
do do
{ {
mark.mark(dNext); // Mark
m_nbDarts++;
if (!markVert.isMarked(dNext)) if (!markVert.isMarked(dNext))
{ {
markVert.mark(dNext); markVert.mark(dNext);
center += positions[dNext]; center += positions[dNext];
nbVertices++; nbv++;
} }
mark.mark(dNext); // Mark
Dart adj = map.phi2(dNext); // add adjacent face if not done already m_nbDarts++;
Dart adj = map.phi2(dNext); // Get adjacent face
if (adj != dNext && !mark.isMarked(adj)) if (adj != dNext && !mark.isMarked(adj))
visitedFaces.push_back(adj); visitedFaces.push_back(adj); // Add it
dNext = map.phi1(dNext); dNext = map.phi1(dNext);
} while(dNext != *face); } while(dNext != *face);
} }
} }
center /= typename PFP::REAL(nbVertices); center /= typename PFP::REAL(nbv);
vecVolCenters.push_back(center); vecCenters.push_back(center);
vecNbFaces.push_back(nbFace); vecNbFaces.push_back(nbf);
}
}