Commit 8704c3dc authored by Sylvain Thery's avatar Sylvain Thery

add easy render of map3 boundary

parent 28a70327
...@@ -94,6 +94,9 @@ protected: ...@@ -94,6 +94,9 @@ protected:
*/ */
float m_topo_relation_width; float m_topo_relation_width;
/// shifting along normals for 3-map boundary drawing
float m_normalShift;
/** /**
* initial darts color (set in update) * initial darts color (set in update)
*/ */
...@@ -130,7 +133,7 @@ protected: ...@@ -130,7 +133,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,7 +149,6 @@ public: ...@@ -146,7 +149,6 @@ public:
/** /**
* Constructor * Constructor
*/ */
TopoRender(); TopoRender();
/** /**
...@@ -225,7 +227,7 @@ public: ...@@ -225,7 +227,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 +247,13 @@ public: ...@@ -245,6 +247,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 +263,12 @@ public: ...@@ -254,6 +263,12 @@ 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);
}; };
// just for compatibility with old code // just for compatibility with old code
......
...@@ -32,7 +32,9 @@ ...@@ -32,7 +32,9 @@
#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 +48,22 @@ namespace Render ...@@ -46,6 +48,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 +101,7 @@ void TopoRender::updateDataMap(typename PFP::MAP& mapx, const VertexAttribute<ty ...@@ -83,6 +101,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();
...@@ -130,10 +149,19 @@ void TopoRender::updateDataMap(typename PFP::MAP& mapx, const VertexAttribute<ty ...@@ -130,10 +149,19 @@ void TopoRender::updateDataMap(typename PFP::MAP& mapx, const VertexAttribute<ty
dd = map.phi1(dd); dd = map.phi1(dd);
} while (dd != d); } while (dd != d);
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(); unsigned int nb = vecPos.size();
vecPos.push_back(vecPos.front()); // copy the first for easy computation on next loop vecPos.push_back(vecPos.front()); // copy the first for easy computation on next loop
k = 1.0f - ke; k = 1.0f - ke;
for (unsigned int i = 0; i < nb; ++i) for (unsigned int i = 0; i < nb; ++i)
{ {
...@@ -184,7 +212,7 @@ void TopoRender::updateDataMap(typename PFP::MAP& mapx, const VertexAttribute<ty ...@@ -184,7 +212,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))
{ {
*positionF2++ = fv2[d]; *positionF2++ = fv2[d];
*positionF2++ = fv2[e]; *positionF2++ = fv2[e];
...@@ -269,9 +297,19 @@ void TopoRender::updateDataGMap(typename PFP::MAP& mapx, const VertexAttribute<t ...@@ -269,9 +297,19 @@ void TopoRender::updateDataGMap(typename PFP::MAP& mapx, const VertexAttribute<t
dd = map.phi1(dd); dd = map.phi1(dd);
} while (dd != d); } while (dd != d);
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(); unsigned int nb = vecPos.size();
vecPos.push_back(vecPos.front()); // copy the first for easy computation on next loop vecPos.push_back(vecPos.front()); // copy the first for easy computation on next loop
k = 1.0f - ke; k = 1.0f - ke;
for (unsigned int i = 0; i < nb; ++i) for (unsigned int i = 0; i < nb; ++i)
{ {
...@@ -355,7 +393,7 @@ void TopoRender::updateDataGMap(typename PFP::MAP& mapx, const VertexAttribute<t ...@@ -355,7 +393,7 @@ void TopoRender::updateDataGMap(typename PFP::MAP& mapx, const VertexAttribute<t
} }
template<typename PFP> template<typename PFP>
void TopoRender::setDartsIdColor(typename PFP::MAP& map) void TopoRender::setDartsIdColor(typename PFP::MAP& map, bool withBoundary)
{ {
m_vbo3->bind(); m_vbo3->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));
...@@ -370,6 +408,9 @@ void TopoRender::setDartsIdColor(typename PFP::MAP& map) ...@@ -370,6 +408,9 @@ void TopoRender::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 (withBoundary || !map.isBoundaryMarked2(d))
{
if (nb < m_nbDarts) if (nb < m_nbDarts)
{ {
float r,g,b; float r,g,b;
...@@ -386,17 +427,19 @@ void TopoRender::setDartsIdColor(typename PFP::MAP& map) ...@@ -386,17 +427,19 @@ void TopoRender::setDartsIdColor(typename PFP::MAP& map)
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;
CGoGNerr << "NB = " << nb << " NBDARTs = "<< m_nbDarts<<CGoGNendl;
break; break;
} }
} }
}
glUnmapBuffer(GL_ARRAY_BUFFER); glUnmapBuffer(GL_ARRAY_BUFFER);
} }
template<typename PFP> template<typename PFP>
Dart TopoRender::picking(typename PFP::MAP& map,int x, int y) Dart TopoRender::picking(typename PFP::MAP& map,int x, int y, bool withBoundary)
{ {
pushColors(); pushColors();
setDartsIdColor<PFP>(map); setDartsIdColor<PFP>(map,withBoundary);
Dart d = pickColor(x,y); Dart d = pickColor(x,y);
popColors(); popColors();
return d; return d;
......
...@@ -43,6 +43,7 @@ TopoRender::TopoRender(): ...@@ -43,6 +43,7 @@ TopoRender::TopoRender():
m_nbRel2(0), m_nbRel2(0),
m_topo_dart_width(2.0f), m_topo_dart_width(2.0f),
m_topo_relation_width(3.0f), m_topo_relation_width(3.0f),
m_normalShift(0.0f),
m_dartsColor(1.0f,1.0f,1.0f), m_dartsColor(1.0f,1.0f,1.0f),
m_bufferDartPosition(NULL) m_bufferDartPosition(NULL)
{ {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment