Commit c4c86f8d authored by Sylvain Thery's avatar Sylvain Thery
Browse files

update of toporendering (and picking) for gmap (onw OK)

a define in tuto*.h allow testing with gmap
parent 94bef722
...@@ -25,7 +25,7 @@ ...@@ -25,7 +25,7 @@
#ifndef _TUTO1_ #ifndef _TUTO1_
#define _TUTO1_ #define _TUTO1_
#define USE_GMAP //#define USE_GMAP
#include "Utils/Qt/qtSimple.h" #include "Utils/Qt/qtSimple.h"
#include "Utils/cgognStream.h" #include "Utils/cgognStream.h"
......
...@@ -25,7 +25,7 @@ ...@@ -25,7 +25,7 @@
#ifndef _TUTO2_ #ifndef _TUTO2_
#define _TUTO2_ #define _TUTO2_
#define USE_GMAP //#define USE_GMAP
#include "Utils/Qt/qtSimple.h" #include "Utils/Qt/qtSimple.h"
......
...@@ -174,7 +174,7 @@ void MyQT::cb_mouseClick(int button, int x, int y) ...@@ -174,7 +174,7 @@ void MyQT::cb_mouseClick(int button, int x, int y)
{ {
if (button == Qt::LeftButton) if (button == Qt::LeftButton)
{ {
Dart d = m_render_topo->picking<PFP>(myMap,allDarts,x,y); Dart d = m_render_topo->picking<PFP>(myMap,x,y);
if (d != NIL) if (d != NIL)
CGoGNout << "Dart "<< d << CGoGNendl; CGoGNout << "Dart "<< d << CGoGNendl;
......
...@@ -28,8 +28,14 @@ ...@@ -28,8 +28,14 @@
#include "Utils/Qt/qtSimple.h" #include "Utils/Qt/qtSimple.h"
#include "Utils/cgognStream.h" #include "Utils/cgognStream.h"
//#define USE_GMAP
#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/topoRender.h" #include "Algo/Render/GL2/topoRender.h"
...@@ -43,7 +49,11 @@ using namespace CGoGN ; ...@@ -43,7 +49,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
}; };
......
...@@ -61,7 +61,7 @@ void MyQT::cb_mouseClick(int button, int x, int y) ...@@ -61,7 +61,7 @@ void MyQT::cb_mouseClick(int button, int x, int y)
if (button == Qt::LeftButton) if (button == Qt::LeftButton)
{ {
Dart d = m_render_topo->picking<PFP>(myMap,allDarts,x,y); Dart d = m_render_topo->picking<PFP>(myMap,x,y);
if (d != NIL) if (d != NIL)
{ {
dart_selected.clear(); dart_selected.clear();
......
...@@ -22,50 +22,18 @@ ...@@ -22,50 +22,18 @@
* * * *
*******************************************************************************/ *******************************************************************************/
#define WITH_GMAP 1
#include "tuto5.h" #include "tuto5.h"
#include <iostream> #include <iostream>
#include "Topology/generic/parameters.h"
#ifdef WITH_GMAP
#include "Topology/gmap/embeddedGMap3.h"
#else
#include "Topology/map/embeddedMap3.h"
#endif
#include "Geometry/vector_gen.h"
#include "Algo/Geometry/boundingbox.h"
#include "Algo/Render/GL2/mapRender.h"
#include "Utils/Shaders/shaderSimpleColor.h"
#include "Algo/Modelisation/primitives3d.h" #include "Algo/Modelisation/primitives3d.h"
#include "Algo/Modelisation/polyhedron.h" #include "Algo/Modelisation/polyhedron.h"
#include "Algo/Modelisation/subdivision.h" #include "Algo/Modelisation/subdivision.h"
#include "Algo/Render/GL2/topo3Render.h" #include "Algo/Render/GL2/topo3Render.h"
#include "Topology/generic/cellmarker.h"
#include "Utils/text3d.h"
#include "Utils/pointSprite.h"
#include "Utils/Shaders/shaderVectorPerVertex.h"
#include "Utils/cgognStream.h"
#include "Algo/Render/SVG/mapSVGRender.h" #include "Algo/Render/SVG/mapSVGRender.h"
using namespace CGoGN ;
struct PFP: public PFP_STANDARD
{
// definition de la carte
#ifdef WITH_GMAP
typedef EmbeddedGMap3 MAP;
#else
typedef EmbeddedMap3 MAP;
#endif
};
PFP::MAP myMap; PFP::MAP myMap;
PFP::TVEC3 position ; PFP::TVEC3 position ;
...@@ -224,10 +192,13 @@ void MyQT::cb_redraw() ...@@ -224,10 +192,13 @@ void MyQT::cb_redraw()
if (render_topo) if (render_topo)
m_render_topo->drawTopo(); m_render_topo->drawTopo();
Dart d = myMap.phi2(myMap.begin()); /* Dart d = myMap.phi2(myMap.begin());
m_render_topo->overdrawDart(d, 5, 1.0f, 0.0f, 1.0f); m_render_topo->overdrawDart(d, 5, 1.0f, 0.0f, 1.0f);
d = myMap.phi1(myMap.begin()); d = myMap.phi1(myMap.begin());
m_render_topo->overdrawDart(d, 5, 1.0f, 0.0f, 1.0f); m_render_topo->overdrawDart(d, 5, 1.0f, 0.0f, 1.0f);
*/
m_render_topo->overdrawDart(m_selected, 5, 1.0f, 0.0f, 1.0f);
glDisable(GL_POLYGON_OFFSET_FILL); glDisable(GL_POLYGON_OFFSET_FILL);
...@@ -252,15 +223,18 @@ void MyQT::cb_mousePress(int button, int x, int y) ...@@ -252,15 +223,18 @@ void MyQT::cb_mousePress(int button, int x, int y)
{ {
if (Shift()) if (Shift())
{ {
Dart d = m_render_topo->picking<PFP>(myMap, allDarts, x,y); SelectorDartNoBoundary<PFP::MAP> nb(myMap);
Dart d = m_render_topo->picking<PFP>(myMap, x,y, nb);
if (d != Dart::nil()) if (d != Dart::nil())
{ {
CGoGNout << "Dart "<< d << " clicked" << CGoGNendl; CGoGNout << "Dart "<< d << " clicked" << CGoGNendl;
m_selected = d;
} }
else else
{ {
statusMsg(""); statusMsg("");
} }
updateGL();
} }
} }
...@@ -339,6 +313,9 @@ int main(int argc, char **argv) ...@@ -339,6 +313,9 @@ int main(int argc, char **argv)
sqt.setCallBack( dock.slider_vectors, SIGNAL(valueChanged(int)), SLOT(slider_vectors(int)) ); sqt.setCallBack( dock.slider_vectors, SIGNAL(valueChanged(int)), SLOT(slider_vectors(int)) );
sqt.setCallBack( dock.slider_text, SIGNAL(valueChanged(int)), SLOT(slider_text(int)) ); sqt.setCallBack( dock.slider_text, SIGNAL(valueChanged(int)), SLOT(slider_text(int)) );
sqt.m_selected = myMap.begin();
sqt.show(); sqt.show();
sqt.slider_balls(50); sqt.slider_balls(50);
......
...@@ -27,6 +27,30 @@ ...@@ -27,6 +27,30 @@
#include <iostream> #include <iostream>
#define WITH_GMAP 1
#include "Topology/generic/parameters.h"
#ifdef WITH_GMAP
#include "Topology/gmap/embeddedGMap3.h"
#else
#include "Topology/map/embeddedMap3.h"
#endif
#include "Geometry/vector_gen.h"
#include "Algo/Geometry/boundingbox.h"
#include "Algo/Render/GL2/mapRender.h"
#include "Utils/Shaders/shaderSimpleColor.h"
#include "Algo/Render/GL2/topo3Render.h"
#include "Topology/generic/cellmarker.h"
#include "Utils/text3d.h"
#include "Utils/pointSprite.h"
#include "Utils/Shaders/shaderVectorPerVertex.h"
#include "Utils/cgognStream.h"
#include "Utils/Qt/qtSimple.h" #include "Utils/Qt/qtSimple.h"
...@@ -34,14 +58,19 @@ ...@@ -34,14 +58,19 @@
// inclure qtui.h juste après le ui_xxx.h // inclure qtui.h juste après le ui_xxx.h
#include "Utils/Qt/qtui.h" #include "Utils/Qt/qtui.h"
// forward definitions (minimize includes)
namespace CGoGN { namespace Algo { namespace Render { namespace GL2 { class MapRender; } } } } using namespace CGoGN ;
namespace CGoGN { namespace Algo { namespace Render { namespace GL2 { class Topo3Render; } } } }
namespace CGoGN { namespace Utils { class VBO; } } struct PFP: public PFP_STANDARD
namespace CGoGN { namespace Utils { class ShaderSimpleColor; } } {
namespace CGoGN { namespace Utils { class Strings3D; } } // definition de la carte
namespace CGoGN { namespace Utils { class PointSprite; } } #ifdef WITH_GMAP
namespace CGoGN { namespace Utils { class ShaderVectorPerVertex; } } typedef EmbeddedGMap3 MAP;
#else
typedef EmbeddedMap3 MAP;
#endif
};
using namespace CGoGN ; using namespace CGoGN ;
...@@ -74,7 +103,7 @@ class MyQT: public Utils::QT::SimpleQT ...@@ -74,7 +103,7 @@ class MyQT: public Utils::QT::SimpleQT
Utils::PointSprite* m_sprite; Utils::PointSprite* m_sprite;
QTimer *m_timer; QTimer *m_timer;
public: public:
MyQT(): MyQT():
render_text(true), render_text(true),
...@@ -92,6 +121,7 @@ public: ...@@ -92,6 +121,7 @@ public:
m_timer(NULL) m_timer(NULL)
{} {}
Dart m_selected;
protected: protected:
void storeVerticesInfo(); void storeVerticesInfo();
......
...@@ -256,7 +256,7 @@ public: ...@@ -256,7 +256,7 @@ public:
* @return the dart or NIL * @return the dart or NIL
*/ */
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, int x, int y, const FunctorSelect& good=allDarts);
/** /**
* update all drawing buffers to render a dual map * update all drawing buffers to render a dual map
......
...@@ -86,11 +86,16 @@ void Topo3Render::updateDataMap3(typename PFP::MAP& mapx, const typename PFP::TV ...@@ -86,11 +86,16 @@ void Topo3Render::updateDataMap3(typename PFP::MAP& mapx, const typename PFP::TV
std::vector<Dart> vecDartFaces; std::vector<Dart> vecDartFaces;
vecDartFaces.reserve(map.getNbDarts()/4); vecDartFaces.reserve(map.getNbDarts()/4);
unsigned int posDBI=0;
DartMarker mark(map); // marker for darts DartMarker mark(map); // marker for darts
for (Dart d = map.begin(); d != map.end(); map.next(d)) for (Dart d = map.begin(); d != map.end(); map.next(d))
{ {
if (good(d)) if (good(d))
{ {
m_attIndex[d] = posDBI;
posDBI+=2;
CellMarkerStore markVert(map, VERTEX); //marker for vertices CellMarkerStore markVert(map, VERTEX); //marker for vertices
VEC3 center(0, 0, 0); VEC3 center(0, 0, 0);
unsigned int nbv = 0; unsigned int nbv = 0;
...@@ -148,7 +153,6 @@ void Topo3Render::updateDataMap3(typename PFP::MAP& mapx, const typename PFP::TV ...@@ -148,7 +153,6 @@ void Topo3Render::updateDataMap3(typename PFP::MAP& mapx, const typename PFP::TV
glBufferData(GL_ARRAY_BUFFER, 2*m_nbDarts*sizeof(VEC3), 0, GL_STREAM_DRAW); glBufferData(GL_ARRAY_BUFFER, 2*m_nbDarts*sizeof(VEC3), 0, GL_STREAM_DRAW);
GLvoid* PositionDartsBuffer = glMapBuffer(GL_ARRAY_BUFFER, GL_READ_WRITE); GLvoid* PositionDartsBuffer = glMapBuffer(GL_ARRAY_BUFFER, GL_READ_WRITE);
VEC3* positionDartBuf = reinterpret_cast<VEC3*>(PositionDartsBuffer); VEC3* positionDartBuf = reinterpret_cast<VEC3*>(PositionDartsBuffer);
unsigned int posDBI=0;
...@@ -169,8 +173,6 @@ void Topo3Render::updateDataMap3(typename PFP::MAP& mapx, const typename PFP::TV ...@@ -169,8 +173,6 @@ void Topo3Render::updateDataMap3(typename PFP::MAP& mapx, const typename PFP::TV
{ {
const VEC3& P = positions[d]; const VEC3& P = positions[d];
vecPos.push_back(P); vecPos.push_back(P);
m_attIndex[d] = posDBI;
posDBI+=2;
center += P; center += P;
d = map.phi1(d); d = map.phi1(d);
} while (d != dd); } while (d != dd);
...@@ -196,8 +198,8 @@ void Topo3Render::updateDataMap3(typename PFP::MAP& mapx, const typename PFP::TV ...@@ -196,8 +198,8 @@ void Topo3Render::updateDataMap3(typename PFP::MAP& mapx, const typename PFP::TV
*positionDartBuf++ = P; *positionDartBuf++ = P;
*positionDartBuf++ = Q; *positionDartBuf++ = Q;
*colorDartBuf++ = VEC3(1.,1.,1.); *colorDartBuf++ = VEC3(1.,1.,1.0);
*colorDartBuf++ = VEC3(1.,1.,1.); *colorDartBuf++ = VEC3(1.,1.,1.0);
fv1[d] = P*0.1f + Q*0.9f; fv1[d] = P*0.1f + Q*0.9f;
fv11[d] = P*0.9f + Q*0.1f; fv11[d] = P*0.9f + Q*0.1f;
...@@ -289,12 +291,13 @@ void Topo3Render::setDartsIdColor(typename PFP::MAP& map, const FunctorSelect& g ...@@ -289,12 +291,13 @@ void Topo3Render::setDartsIdColor(typename PFP::MAP& map, const FunctorSelect& g
for (Dart d = map.begin(); d != map.end(); map.next(d)) for (Dart d = map.begin(); d != map.end(); map.next(d))
{ {
if (nb < m_nbDarts) if (good(d))
{ {
if (good(d)) if (nb < m_nbDarts)
{ {
float r,g,b; float r,g,b;
dartToCol(d, r,g,b); dartToCol(d, r,g,b);
float* local = colorBuffer+3*m_attIndex[d]; // get the right position in VBO float* local = colorBuffer+3*m_attIndex[d]; // get the right position in VBO
*local++ = r; *local++ = r;
*local++ = g; *local++ = g;
...@@ -305,18 +308,20 @@ void Topo3Render::setDartsIdColor(typename PFP::MAP& map, const FunctorSelect& g ...@@ -305,18 +308,20 @@ void Topo3Render::setDartsIdColor(typename PFP::MAP& map, const FunctorSelect& g
nb++; nb++;
} }
} else
else {
{ CGoGNerr << "Error buffer too small for color picking (change the good parameter ?)" << CGoGNendl;
CGoGNerr << "Error buffer too small for color picking (change the good parameter ?)" << CGoGNendl; d = map.end();
d = map.end(); }
} }
} }
glUnmapBuffer(GL_ARRAY_BUFFER); glUnmapBuffer(GL_ARRAY_BUFFER);
std::cout << "NB DARTS="<<m_nbDarts<< std::endl;
} }
template<typename PFP> template<typename PFP>
Dart Topo3Render::picking(typename PFP::MAP& map, const FunctorSelect& good, int x, int y) Dart Topo3Render::picking(typename PFP::MAP& map, int x, int y, const FunctorSelect& good)
{ {
pushColors(); pushColors();
setDartsIdColor<PFP>(map,good); setDartsIdColor<PFP>(map,good);
...@@ -353,11 +358,15 @@ void Topo3Render::updateDataGMap3(typename PFP::MAP& mapx, const typename PFP::T ...@@ -353,11 +358,15 @@ void Topo3Render::updateDataGMap3(typename PFP::MAP& mapx, const typename PFP::T
std::vector<Dart> vecDartFaces; std::vector<Dart> vecDartFaces;
vecDartFaces.reserve(map.getNbDarts()/4); vecDartFaces.reserve(map.getNbDarts()/4);
unsigned int posDBI=0;
DartMarker mark(map); // marker for darts DartMarker mark(map); // marker for darts
for (Dart d = map.begin(); d != map.end(); map.next(d)) for (Dart d = map.begin(); d != map.end(); map.next(d))
{ {
if (good(d)) if (good(d))
{ {
m_attIndex[d] = posDBI;
posDBI+=2;
CellMarkerStore markVert(map, VERTEX); //marker for vertices CellMarkerStore markVert(map, VERTEX); //marker for vertices
VEC3 center(0, 0, 0); VEC3 center(0, 0, 0);
unsigned int nbv = 0; unsigned int nbv = 0;
...@@ -383,6 +392,7 @@ void Topo3Render::updateDataGMap3(typename PFP::MAP& mapx, const typename PFP::T ...@@ -383,6 +392,7 @@ void Topo3Render::updateDataGMap3(typename PFP::MAP& mapx, const typename PFP::T
nbv++; nbv++;
} }
mark.mark(dNext); // Mark mark.mark(dNext); // Mark
mark.mark(map.beta0(dNext));
m_nbDarts++; m_nbDarts++;
Dart adj = map.phi2(dNext); // Get adjacent face Dart adj = map.phi2(dNext); // Get adjacent face
if (adj != dNext && !mark.isMarked(adj)) if (adj != dNext && !mark.isMarked(adj))
...@@ -414,7 +424,6 @@ void Topo3Render::updateDataGMap3(typename PFP::MAP& mapx, const typename PFP::T ...@@ -414,7 +424,6 @@ void Topo3Render::updateDataGMap3(typename PFP::MAP& mapx, const typename PFP::T
glBufferData(GL_ARRAY_BUFFER, 2*m_nbDarts*sizeof(VEC3), 0, GL_STREAM_DRAW); glBufferData(GL_ARRAY_BUFFER, 2*m_nbDarts*sizeof(VEC3), 0, GL_STREAM_DRAW);
GLvoid* PositionDartsBuffer = glMapBuffer(GL_ARRAY_BUFFER, GL_READ_WRITE); GLvoid* PositionDartsBuffer = glMapBuffer(GL_ARRAY_BUFFER, GL_READ_WRITE);
VEC3* positionDartBuf = reinterpret_cast<VEC3*>(PositionDartsBuffer); VEC3* positionDartBuf = reinterpret_cast<VEC3*>(PositionDartsBuffer);
unsigned int posDBI=0;
std::vector<Dart>::iterator face = vecDartFaces.begin(); std::vector<Dart>::iterator face = vecDartFaces.begin();
for (unsigned int iVol=0; iVol<vecNbFaces.size(); ++iVol) for (unsigned int iVol=0; iVol<vecNbFaces.size(); ++iVol)
...@@ -433,8 +442,6 @@ void Topo3Render::updateDataGMap3(typename PFP::MAP& mapx, const typename PFP::T ...@@ -433,8 +442,6 @@ void Topo3Render::updateDataGMap3(typename PFP::MAP& mapx, const typename PFP::T
{ {
const VEC3& P = positions[d]; const VEC3& P = positions[d];
vecPos.push_back(P); vecPos.push_back(P);
m_attIndex[d] = posDBI;
posDBI+=2;
center += P; center += P;
d = map.phi1(d); d = map.phi1(d);
} while (d != dd); } while (d != dd);
...@@ -568,260 +575,6 @@ void Topo3Render::updateDataGMap3(typename PFP::MAP& mapx, const typename PFP::T ...@@ -568,260 +575,6 @@ void Topo3Render::updateDataGMap3(typename PFP::MAP& mapx, const typename PFP::T
m_vbo4->bind(); m_vbo4->bind();
glUnmapBuffer(GL_ARRAY_BUFFER); glUnmapBuffer(GL_ARRAY_BUFFER);
} }
/*{
GMap3& map = reinterpret_cast<GMap3&>(mapx);
float kd=0.95f;
typedef typename PFP::VEC3 VEC3;
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)
{
m_attIndex = map.template getAttribute<unsigned int>(DART, "dart_index");
if (!m_attIndex.isValid())
m_attIndex = map.template addAttribute<unsigned int>(DART, "dart_index");
}
m_nbDarts = 0;
// table of face (one dart of each)
std::vector<Dart> vecDartFaces;
vecDartFaces.reserve(map.getNbDarts()/6); //6 = nb of darts for tri mesh
// table of nbfaces per volume
std::vector<unsigned int> vecNbFaces;
vecNbFaces.reserve(vecDartFaces.size());
// table of center of volume
std::vector<VEC3> vecVolCenters;
vecVolCenters.reserve(vecDartFaces.size()/4); // = nb of volumes for a tetra mesh
DartMarker mark(map); // marker for darts
CellMarker mVol(map, VOLUME);
for (Dart d = map.begin(); d != map.end(); map.next(d))
{
if (good(d))
{
if(!mVol.isMarked(d))
{
mVol.mark(d);
CellMarkerStore markVert(map, VERTEX); //marker for vertices
VEC3 center(0);
unsigned int nbVertices = 0;
unsigned int nbFace = 0;
std::list<Dart> visitedFaces; // Faces that are traversed
visitedFaces.push_back(d); // Start with the face of d
// For every face added to the list
for (std::list<Dart>::iterator face = visitedFaces.begin(); face != visitedFaces.end(); ++face)
{
if (!mark.isMarked(*face)) // Face has not been visited yet
{
// store a dart of face
vecDartFaces.push_back(*face);
nbFace++;
Dart dNext = *face ;
do
{
mark.mark(dNext); // Mark
m_nbDarts++;
if (!markVert.isMarked(dNext))
{
markVert.mark(dNext);
center += positions[dNext];
nbVertices++;
}
Dart adj = map.phi2(dNext); // add adjacent face if not done already
if (adj != dNext && !mark.isMarked(adj))
visitedFaces.push_back(adj);
dNext = map.phi1(dNext);
} while(dNext != *face);
}
}
center /= typename PFP::REAL(nbVertices);
vecVolCenters.push_back(center);
vecNbFaces.push_back(nbFace);
}
}
}
m_nbDarts *= 2; // x2 : only one orientation is used for the previous computation, multiply by 2 to get the number of darts
//colors
m_vbo4->bind();
glBufferData(GL_ARRAY_BUFFER, 2*m_nbDarts*sizeof(VEC3), 0, GL_STREAM_DRAW);
GLvoid* ColorDartsBuffer = glMapBuffer(GL_ARRAY_BUFFER, GL_READ_WRITE);
VEC3* colorDartBuf = reinterpret_cast<VEC3*>(ColorDartsBuffer);