Commit c3df6df0 authored by untereiner's avatar untereiner

Merge cgogn:~thery/CGoGN

parents 44d02608 432667ae
...@@ -154,7 +154,7 @@ void MCMesh::MC() ...@@ -154,7 +154,7 @@ void MCMesh::MC()
void MCMesh::updateRender() void MCMesh::updateRender()
{ {
SelectorDartNoBoundary<PFP::MAP> nb(myMap); // SelectorDartNoBoundary<PFP::MAP> nb(myMap);
//TODO add Browser for no border //TODO add Browser for no border
m_render->initPrimitives<PFP>(myMap, Algo::Render::GL2::LINES); m_render->initPrimitives<PFP>(myMap, Algo::Render::GL2::LINES);
m_render->initPrimitives<PFP>(myMap, Algo::Render::GL2::TRIANGLES); m_render->initPrimitives<PFP>(myMap, Algo::Render::GL2::TRIANGLES);
......
...@@ -118,7 +118,6 @@ void MyQT::cb_initGL() ...@@ -118,7 +118,6 @@ void MyQT::cb_initGL()
m_render_topo = new Algo::Render::GL2::Topo3Render(); m_render_topo = new Algo::Render::GL2::Topo3Render();
// SelectorDartNoBoundary<PFP::MAP> nb(myMap);
m_render_topo->updateData<PFP>(myMap, position, 0.95f, 0.9f, 0.8f); m_render_topo->updateData<PFP>(myMap, position, 0.95f, 0.9f, 0.8f);
m_dm_topo = new DartMarker(myMap); m_dm_topo = new DartMarker(myMap);
} }
...@@ -145,7 +144,6 @@ void MyQT::cb_mousePress(int button, int x, int y) ...@@ -145,7 +144,6 @@ void MyQT::cb_mousePress(int button, int x, int y)
{ {
if (Shift()) if (Shift())
{ {
// SelectorDartNoBoundary<PFP::MAP> nb(myMap);
Dart d = m_render_topo->picking<PFP>(myMap, x, y); Dart d = m_render_topo->picking<PFP>(myMap, x, y);
if (d != Dart::nil()) if (d != Dart::nil())
{ {
...@@ -199,7 +197,6 @@ void MyQT::traverse2() ...@@ -199,7 +197,6 @@ void MyQT::traverse2()
return; return;
m_last=2; m_last=2;
// int code = (m_ajd_or_inci2)*100+m_first2*10+m_second2; // int code = (m_ajd_or_inci2)*100+m_first2*10+m_second2;
SelectorDartNoBoundary<PFP::MAP> nb(myMap);
m_drawer.newList(GL_COMPILE); m_drawer.newList(GL_COMPILE);
m_drawer.lineWidth(7.0f); m_drawer.lineWidth(7.0f);
...@@ -266,8 +263,6 @@ void MyQT::traverse3() ...@@ -266,8 +263,6 @@ void MyQT::traverse3()
m_last=3; m_last=3;
SelectorDartNoBoundary<PFP::MAP> nb(myMap);
m_affDarts.clear(); m_affDarts.clear();
m_drawer.newList(GL_COMPILE); m_drawer.newList(GL_COMPILE);
......
...@@ -77,7 +77,8 @@ void MyQT::createMap() ...@@ -77,7 +77,8 @@ void MyQT::createMap()
show(); show();
// render the topo of the map without boundary darts // render the topo of the map without boundary darts
m_render_topo->updateData<PFP>(myMap, position, 0.9f, 0.9f,true ); m_render_topo->setInitialBoundaryDartsColor(0,1,0);
m_render_topo->updateData<PFP>(myMap, position, 0.9f, 0.9f,true);
} }
// initialization GL callback // initialization GL callback
......
...@@ -191,9 +191,10 @@ void MyQT::createMap(int n) ...@@ -191,9 +191,10 @@ void MyQT::createMap(int n)
dm.markAll(); dm.markAll();
m_render_topo->setDartWidth(5.0f); m_render_topo->setDartWidth(4.0f);
m_render_topo->setInitialDartsColor(0.0f,0.0f,0.0f); m_render_topo->setInitialDartsColor(0.0f,0.0f,0.0f);
m_render_topo->updateData<PFP>(myMap, position, 0.9f, 0.9f); // nb m_render_topo->setInitialBoundaryDartsColor(0.0f,0.0f,0.0f);
m_render_topo->updateData<PFP>(myMap, position, 0.9f, 0.9f,true); // nb
for (Dart d=myMap.begin(); d!=myMap.end(); myMap.next(d)) for (Dart d=myMap.begin(); d!=myMap.end(); myMap.next(d))
{ {
...@@ -211,7 +212,8 @@ void MyQT::createMap(int n) ...@@ -211,7 +212,8 @@ void MyQT::createMap(int n)
void MyQT::updateMap() void MyQT::updateMap()
{ {
m_render_topo->updateData<PFP>(myMap, position, 0.9f, 0.9f); // nb m_render_topo->setInitialBoundaryDartsColor(0.0f,0.0f,0.0f);
m_render_topo->updateData<PFP>(myMap, position, 0.9f, 0.9f,true); // nb
for (Dart d=myMap.begin(); d!=myMap.end(); myMap.next(d)) for (Dart d=myMap.begin(); d!=myMap.end(); myMap.next(d))
{ {
if (dm.isMarked(d) && (!myMap.isBoundaryMarked2(d))) if (dm.isMarked(d) && (!myMap.isBoundaryMarked2(d)))
...@@ -227,7 +229,7 @@ void MyQT::updateMap() ...@@ -227,7 +229,7 @@ void MyQT::updateMap()
void MyQT::cb_initGL() void MyQT::cb_initGL()
{ {
glClearColor(1.0f,1.0f,1.0f,1.0f); glClearColor(1.0f,1.0f,1.0f,1.0f);
m_render_topo = new Algo::Render::GL2::TopoRender() ; m_render_topo = new Algo::Render::GL2::TopoRender(0.01f) ;
} }
// redraw GL callback (clear and swap already done) // redraw GL callback (clear and swap already done)
......
...@@ -69,7 +69,7 @@ class MyQT: public Utils::QT::SimpleQT ...@@ -69,7 +69,7 @@ class MyQT: public Utils::QT::SimpleQT
{ {
Q_OBJECT Q_OBJECT
public: public:
MyQT():nb(myMap),m_render_topo(NULL),m_selected(NIL),m_selected2(NIL),dm(myMap),m_shift(0.01f) {} MyQT():m_render_topo(NULL),m_selected(NIL),m_selected2(NIL),dm(myMap),m_shift(0.01f) {}
void cb_redraw(); void cb_redraw();
void cb_initGL(); void cb_initGL();
...@@ -87,8 +87,6 @@ protected: ...@@ -87,8 +87,6 @@ protected:
VertexAttribute<VEC3> position; VertexAttribute<VEC3> position;
DartAttribute<VEC3> colorDarts; DartAttribute<VEC3> colorDarts;
SelectorDartNoBoundary<PFP::MAP> nb;
// render (for the topo) // render (for the topo)
Algo::Render::GL2::TopoRender* m_render_topo; Algo::Render::GL2::TopoRender* m_render_topo;
Dart m_selected; Dart m_selected;
......
...@@ -142,8 +142,7 @@ void MyQT::cb_initGL() ...@@ -142,8 +142,7 @@ void MyQT::cb_initGL()
Utils::GLSLShader::setCurrentOGLVersion(2); Utils::GLSLShader::setCurrentOGLVersion(2);
m_render_topo = new Algo::Render::GL2::Topo3Render(); m_render_topo = new Algo::Render::GL2::Topo3Render();
SelectorDartNoBoundary<PFP::MAP> nb(myMap); m_render_topo->updateData<PFP>(myMap, position, 0.9f, 0.8f, 0.8f);
m_render_topo->updateData<PFP>(myMap, position, 0.9f, 0.8f, 0.8f/*, nb*/);
m_strings = new Utils::Strings3D(true, Geom::Vec3f(0.1f,0.0f,0.3f)); m_strings = new Utils::Strings3D(true, Geom::Vec3f(0.1f,0.0f,0.3f));
registerShader(m_strings); registerShader(m_strings);
...@@ -167,8 +166,7 @@ void MyQT::cb_mousePress(int button, int x, int y) ...@@ -167,8 +166,7 @@ void MyQT::cb_mousePress(int button, int x, int y)
{ {
if (Shift()) if (Shift())
{ {
SelectorDartNoBoundary<PFP::MAP> nb(myMap); m_clicked = m_render_topo->picking<PFP>(myMap, x,y);
m_clicked = m_render_topo->picking<PFP>(myMap, x,y/*, nb*/);
if (m_clicked != Dart::nil()) if (m_clicked != Dart::nil())
{ {
unsigned int orbs[9] = {VERTEX,EDGE,FACE,VOLUME,PFP::MAP::VERTEX_OF_PARENT,PFP::MAP::EDGE_OF_PARENT,PFP::MAP::FACE_OF_PARENT,PFP::MAP::VERTEX_OF_PARENT2,PFP::MAP::EDGE_OF_PARENT2}; unsigned int orbs[9] = {VERTEX,EDGE,FACE,VOLUME,PFP::MAP::VERTEX_OF_PARENT,PFP::MAP::EDGE_OF_PARENT,PFP::MAP::FACE_OF_PARENT,PFP::MAP::VERTEX_OF_PARENT2,PFP::MAP::EDGE_OF_PARENT2};
......
...@@ -75,6 +75,7 @@ void Topo3Render::updateDataMap3(typename PFP::MAP& mapx, const VertexAttribute< ...@@ -75,6 +75,7 @@ void Topo3Render::updateDataMap3(typename PFP::MAP& mapx, const VertexAttribute<
m_nbDarts = 0; m_nbDarts = 0;
for (Dart d = mapx.begin(); d != mapx.end(); mapx.next(d)) for (Dart d = mapx.begin(); d != mapx.end(); mapx.next(d))
{ {
if (!mapx.isBoundaryMarked3(d)) // in the following code Traversor do not traverse boundary
m_nbDarts++; m_nbDarts++;
} }
...@@ -237,25 +238,27 @@ void Topo3Render::setDartsIdColor(typename PFP::MAP& map) ...@@ -237,25 +238,27 @@ void Topo3Render::setDartsIdColor(typename PFP::MAP& map)
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 ( !map.isBoundaryMarked3(d)) // topo3 Render do not traverse boundary
{ {
float r,g,b; if (nb < m_nbDarts)
dartToCol(d, r,g,b); {
float r,g,b;
float* local = colorBuffer+3*m_attIndex[d]; // get the right position in VBO dartToCol(d, r,g,b);
*local++ = r;
*local++ = g; float* local = colorBuffer+3*m_attIndex[d]; // get the right position in VBO
*local++ = b; *local++ = r;
*local++ = r; *local++ = g;
*local++ = g; *local++ = b;
*local++ = b; *local++ = r;
*local++ = g;
nb++; *local++ = b;
} nb++;
else }
{ else
CGoGNerr << "Error buffer too small for color picking (change the selector parameter ?)" << CGoGNendl; {
break; CGoGNerr << "Error buffer too small for color picking (change the selector parameter ?)" << CGoGNendl;
break;
}
} }
} }
glUnmapBuffer(GL_ARRAY_BUFFER); glUnmapBuffer(GL_ARRAY_BUFFER);
...@@ -270,15 +273,18 @@ void Topo3Render::updateColors(typename PFP::MAP& map, const VertexAttribute<typ ...@@ -270,15 +273,18 @@ void Topo3Render::updateColors(typename PFP::MAP& map, const VertexAttribute<typ
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 ( !map.isBoundaryMarked3(d)) // topo3 Render do not traverse boundary
{ {
colorBuffer[m_attIndex[d]] = colors[d]; if (nb < m_nbDarts)
nb++; {
} colorBuffer[m_attIndex[d]] = colors[d];
else nb++;
{ }
CGoGNerr << "Error buffer too small for color picking (change the selector parameter ?)" << CGoGNendl; else
break; {
CGoGNerr << "Error buffer too small for color picking (change the selector parameter ?)" << CGoGNendl;
break;
}
} }
} }
glUnmapBuffer(GL_ARRAY_BUFFER); glUnmapBuffer(GL_ARRAY_BUFFER);
...@@ -313,6 +319,7 @@ void Topo3Render::updateDataGMap3(typename PFP::MAP& mapx, const VertexAttribute ...@@ -313,6 +319,7 @@ void Topo3Render::updateDataGMap3(typename PFP::MAP& mapx, const VertexAttribute
m_nbDarts = 0; m_nbDarts = 0;
for (Dart d = mapx.begin(); d != mapx.end(); mapx.next(d)) for (Dart d = mapx.begin(); d != mapx.end(); mapx.next(d))
{ {
if (!map.isBoundaryMarked3(d)) // in the following code Traversor do not traverse boundary
m_nbDarts++; m_nbDarts++;
} }
......
...@@ -94,11 +94,21 @@ protected: ...@@ -94,11 +94,21 @@ protected:
*/ */
float m_topo_relation_width; float m_topo_relation_width;
/// shifting along normals for 3-map boundary drawing
float m_normalShift;
float m_boundShift;
/** /**
* initial darts color (set in update) * initial darts color (set in update)
*/ */
Geom::Vec3f m_dartsColor; Geom::Vec3f m_dartsColor;
/**
* initial darts color (set in update)
*/
Geom::Vec3f m_dartsBoundaryColor;
float *m_color_save; float *m_color_save;
/** /**
...@@ -130,7 +140,7 @@ protected: ...@@ -130,7 +140,7 @@ protected:
* affect a color to each dart * affect a color to each dart
*/ */
template<typename PFP> template<typename PFP>
void setDartsIdColor(typename PFP::MAP& map); void setDartsIdColor(typename PFP::MAP& map, bool withBoundary);
/** /**
* save colors before picking * save colors before picking
...@@ -146,8 +156,7 @@ public: ...@@ -146,8 +156,7 @@ public:
/** /**
* Constructor * Constructor
*/ */
TopoRender(float bs = 0.01f);
TopoRender();
/** /**
* Destructor * Destructor
...@@ -185,6 +194,7 @@ public: ...@@ -185,6 +194,7 @@ public:
* draw all topo * draw all topo
*/ */
void drawTopo(); void drawTopo();
/** /**
* change dart drawing color * change dart drawing color
* @param d the dart * @param d the dart
...@@ -205,6 +215,8 @@ public: ...@@ -205,6 +215,8 @@ public:
void setInitialDartsColor(float r, float g, float b); void setInitialDartsColor(float r, float g, float b);
void setInitialBoundaryDartsColor(float r, float g, float b);
/** /**
* redraw one dart with specific width and color (not efficient use only for debug with small amount of call) * redraw one dart with specific width and color (not efficient use only for debug with small amount of call)
* @param d the dart * @param d the dart
...@@ -225,7 +237,7 @@ public: ...@@ -225,7 +237,7 @@ public:
* @return the dart or NIL * @return the dart or NIL
*/ */
template<typename PFP> template<typename PFP>
Dart picking(typename PFP::MAP& map, int x, int y); Dart picking(typename PFP::MAP& map, int x, int y, bool withBoundary=false);
template<typename PFP> template<typename PFP>
...@@ -245,6 +257,13 @@ public: ...@@ -245,6 +257,13 @@ public:
template <typename PFP> template <typename PFP>
void updateDataGMap(typename PFP::MAP& map, const VertexAttribute<typename PFP::VEC3>& positions, float ke, float kf, bool withBoundary = false); void updateDataGMap(typename PFP::MAP& map, const VertexAttribute<typename PFP::VEC3>& positions, float ke, float kf, bool withBoundary = false);
/**
* Special update function used to draw boundary of map3
*/
template<typename PFP>
void updateDataBoundary(typename PFP::MAP& map, const VertexAttribute<typename PFP::VEC3>& positions, float ke, float kf,float ns);
/** /**
* render to svg struct * render to svg struct
*/ */
...@@ -254,6 +273,18 @@ public: ...@@ -254,6 +273,18 @@ public:
* render svg into svg file * render svg into svg file
*/ */
void svgout2D(const std::string& filename, const glm::mat4& model, const glm::mat4& proj); void svgout2D(const std::string& filename, const glm::mat4& model, const glm::mat4& proj);
/**
* @brief set normal shift for boundary of dim 3 drawing
* @param ns distance shift along normals (use BB.diagSize()/100 is good approximation)
*/
void setNormalShift(float ns);
/**
* @brief set boundary shift for boundary of dim 2 drawing
* @param ns distance shift
*/
void setBoundaryShift(float bs);
}; };
// just for compatibility with old code // just for compatibility with old code
......
...@@ -30,9 +30,12 @@ ...@@ -30,9 +30,12 @@
#include "Topology/map/embeddedMap2.h" #include "Topology/map/embeddedMap2.h"
#include "Topology/gmap/embeddedGMap2.h" #include "Topology/gmap/embeddedGMap2.h"
#include "Algo/Geometry/basic.h"
#include "Geometry/distances.h" #include "Geometry/distances.h"
#include "Algo/Geometry/centroid.h" #include "Algo/Geometry/centroid.h"
#include "Algo/Geometry/normal.h"
#include "Topology/generic/mapBrowser.h"
namespace CGoGN namespace CGoGN
{ {
...@@ -46,6 +49,22 @@ namespace Render ...@@ -46,6 +49,22 @@ namespace Render
namespace GL2 namespace GL2
{ {
template<typename PFP>
void TopoRender::updateDataBoundary(typename PFP::MAP& map, const VertexAttribute<typename PFP::VEC3>& positions, float ke, float kf,float ns)
{
m_normalShift = ns;
SelectorDartBoundary<typename PFP::MAP> sdb(map);
MapBrowserSelector mbs(map,sdb);
map.setBrowser(&mbs);
updateData<PFP>(map,positions, ke, kf,true);
map.setBrowser(NULL);
m_normalShift = 0.0f;
}
template<typename PFP> template<typename PFP>
void TopoRender::updateData(typename PFP::MAP& map, const VertexAttribute<typename PFP::VEC3>& positions, float ke, float kf, bool withBoundary) void TopoRender::updateData(typename PFP::MAP& map, const VertexAttribute<typename PFP::VEC3>& positions, float ke, float kf, bool withBoundary)
{ {
...@@ -83,6 +102,7 @@ void TopoRender::updateDataMap(typename PFP::MAP& mapx, const VertexAttribute<ty ...@@ -83,6 +102,7 @@ void TopoRender::updateDataMap(typename PFP::MAP& mapx, const VertexAttribute<ty
{ {
if (withBoundary || !map.isBoundaryMarked2(d)) if (withBoundary || !map.isBoundaryMarked2(d))
vecDarts.push_back(d); vecDarts.push_back(d);
} }
m_nbDarts = vecDarts.size(); m_nbDarts = vecDarts.size();
...@@ -120,41 +140,96 @@ void TopoRender::updateDataMap(typename PFP::MAP& mapx, const VertexAttribute<ty ...@@ -120,41 +140,96 @@ void TopoRender::updateDataMap(typename PFP::MAP& mapx, const VertexAttribute<ty
if (!mf.isMarked(d)) if (!mf.isMarked(d))
{ {
vecPos.clear(); vecPos.clear();
VEC3 center = Algo::Surface::Geometry::faceCentroidELW<PFP>(mapx,d,positions); if (!map.isBoundaryMarked2(d))
float k = 1.0f - kf;
Dart dd = d;
do
{ {
vecPos.push_back(center*k + positions[dd]*kf); VEC3 center = Algo::Surface::Geometry::faceCentroidELW<PFP>(mapx,d,positions);
dd = map.phi1(dd); float k = 1.0f - kf;
} while (dd != d); Dart dd = d;
do
unsigned int nb = vecPos.size(); {
vecPos.push_back(vecPos.front()); // copy the first for easy computation on next loop vecPos.push_back(center*k + positions[dd]*kf);
dd = map.phi1(dd);
} while (dd != d);
k = 1.0f - ke;
for (unsigned int i = 0; i < nb; ++i)
if (m_normalShift > 0.0f)
{
VEC3 normal = Algo::Surface::Geometry::newellNormal<PFP>(mapx,d,positions);
for (typename std::vector<VEC3>::iterator pit = vecPos.begin(); pit != vecPos.end(); ++pit)
{
*pit -= normal*m_normalShift;
}
}
unsigned int nb = vecPos.size();
vecPos.push_back(vecPos.front()); // copy the first for easy computation on next loop
k = 1.0f - ke;
for (unsigned int i = 0; i < nb; ++i)
{
VEC3 P = vecPos[i]*ke + vecPos[i+1]*k;
VEC3 Q = vecPos[i+1]*ke + vecPos[i]*k;
m_attIndex[d] = indexDC;
indexDC+=2;
*positionDartBuf++ = P;
*positionDartBuf++ = Q;
*colorDartBuf++ = m_dartsColor;
*colorDartBuf++ = m_dartsColor;
VEC3 f = P*0.5f + Q*0.5f;
fv2[d] = f;
f = P*0.1f + Q*0.9f;
fv1[d] = f;
f = P*0.9f + Q*0.1f;
fv11[d] = f;
d = map.phi1(d);
}
mf.markOrbit<FACE>(d);
}
else if (withBoundary)
{ {
VEC3 P = vecPos[i]*ke + vecPos[i+1]*k;
VEC3 Q = vecPos[i+1]*ke + vecPos[i]*k;
m_attIndex[d] = indexDC; Dart dd = d;
indexDC+=2; do
*positionDartBuf++ = P; {
*positionDartBuf++ = Q; Dart ee = mapx.phi2(dd);
*colorDartBuf++ = m_dartsColor; VEC3 normal = Algo::Surface::Geometry::newellNormal<PFP>(mapx,ee,positions);
*colorDartBuf++ = m_dartsColor; VEC3 vd = Algo::Surface::Geometry::vectorOutOfDart<PFP>(mapx,ee,positions);
VEC3 f = P*0.5f + Q*0.5f; VEC3 v = vd ^ normal;
fv2[d] = f; v.normalize();
f = P*0.1f + Q*0.9f; VEC3 P = positions[map.phi1(ee)] + v* m_boundShift;
fv1[d] = f; vecPos.push_back(P);
f = P*0.9f + Q*0.1f; dd = map.phi1(dd);
fv11[d] = f; ee = mapx.phi2(dd);
d = map.phi1(d); P = positions[map.phi1(ee)] + v* m_boundShift;
vecPos.push_back(P);
} while (dd != d);
unsigned int nb = vecPos.size()/2;
float k = 1.0f - ke;
for (unsigned int i = 0; i < nb; ++i)
{
VEC3 P = vecPos[2*i]*ke + vecPos[2*i+1]*k;
VEC3 Q = vecPos[2*i+1]*ke + vecPos[2*i]*k;
m_attIndex[d] = indexDC;
indexDC+=2;
*positionDartBuf++ = P;
*positionDartBuf++ = Q;
*colorDartBuf++ = m_dartsBoundaryColor;
*colorDartBuf++ = m_dartsBoundaryColor;
VEC3 f = P*0.5f + Q*0.5f;
fv2[d] = f;
f = P*0.1f + Q*0.9f;
fv1[d] = f;
f = P*0.9f + Q*0.1f;
fv11[d] = f;
d = map.phi1(d);
}
mf.markOrbit<FACE>(d);
} }
mf.markOrbit<FACE>(d);
} }
} }
...@@ -184,7 +259,7 @@ void TopoRender::updateDataMap(typename PFP::MAP& mapx, const VertexAttribute<ty ...@@ -184,7 +259,7 @@ void TopoRender::updateDataMap(typename PFP::MAP& mapx, const VertexAttribute<ty
Dart e = map.phi2(d); Dart e = map.phi2(d);
// if (good(e) && (e.index > d.index)) // if (good(e) && (e.index > d.index))
if ( (withBoundary || !map.isBoundaryMarked2(e)) && (d < e )) if ( (withBoundary || !map.isBoundaryMarked2(e)) && (e.index > d.index))