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

add easy render of map3 boundary

parent 28a70327
......@@ -94,6 +94,9 @@ protected:
*/
float m_topo_relation_width;
/// shifting along normals for 3-map boundary drawing
float m_normalShift;
/**
* initial darts color (set in update)
*/
......@@ -130,7 +133,7 @@ protected:
* affect a color to each dart
*/
template<typename PFP>
void setDartsIdColor(typename PFP::MAP& map);
void setDartsIdColor(typename PFP::MAP& map, bool withBoundary);
/**
* save colors before picking
......@@ -146,7 +149,6 @@ public:
/**
* Constructor
*/
TopoRender();
/**
......@@ -225,7 +227,7 @@ public:
* @return the dart or NIL
*/
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>
......@@ -245,6 +247,13 @@ public:
template <typename PFP>
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
*/
......@@ -254,6 +263,12 @@ public:
* render svg into svg file
*/
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
......
......@@ -32,7 +32,9 @@
#include "Geometry/distances.h"
#include "Algo/Geometry/centroid.h"
#include "Algo/Geometry/normal.h"
#include "Topology/generic/mapBrowser.h"
namespace CGoGN
{
......@@ -46,6 +48,22 @@ namespace Render
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>
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
{
if (withBoundary || !map.isBoundaryMarked2(d))
vecDarts.push_back(d);
}
m_nbDarts = vecDarts.size();
......@@ -130,10 +149,19 @@ void TopoRender::updateDataMap(typename PFP::MAP& mapx, const VertexAttribute<ty
dd = map.phi1(dd);
} 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();
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)
{
......@@ -184,7 +212,7 @@ void TopoRender::updateDataMap(typename PFP::MAP& mapx, const VertexAttribute<ty
Dart e = map.phi2(d);
// 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[e];
......@@ -269,9 +297,19 @@ void TopoRender::updateDataGMap(typename PFP::MAP& mapx, const VertexAttribute<t
dd = map.phi1(dd);
} 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();
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)
{
......@@ -355,7 +393,7 @@ void TopoRender::updateDataGMap(typename PFP::MAP& mapx, const VertexAttribute<t
}
template<typename PFP>
void TopoRender::setDartsIdColor(typename PFP::MAP& map)
void TopoRender::setDartsIdColor(typename PFP::MAP& map, bool withBoundary)
{
m_vbo3->bind();
float* colorBuffer = reinterpret_cast<float*>(glMapBuffer(GL_ARRAY_BUFFER, GL_READ_WRITE));
......@@ -370,33 +408,38 @@ void TopoRender::setDartsIdColor(typename PFP::MAP& map)
for (Dart d = map.begin(); d != map.end(); map.next(d))
{
if (nb < m_nbDarts)
{
float r,g,b;
dartToCol(d, r,g,b);
float* local = colorBuffer+3*m_attIndex[d]; // get the right position in VBO
*local++ = r;
*local++ = g;
*local++ = b;
*local++ = r;
*local++ = g;
*local++ = b;
nb++;
}
else
if (withBoundary || !map.isBoundaryMarked2(d))
{
CGoGNerr << "Error buffer too small for color picking (change the good parameter ?)" << CGoGNendl;
break;
if (nb < m_nbDarts)
{
float r,g,b;
dartToCol(d, r,g,b);
float* local = colorBuffer+3*m_attIndex[d]; // get the right position in VBO
*local++ = r;
*local++ = g;
*local++ = b;
*local++ = r;
*local++ = g;
*local++ = b;
nb++;
}
else
{
CGoGNerr << "Error buffer too small for color picking (change the good parameter ?)" << CGoGNendl;
CGoGNerr << "NB = " << nb << " NBDARTs = "<< m_nbDarts<<CGoGNendl;
break;
}
}
}
glUnmapBuffer(GL_ARRAY_BUFFER);
}
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();
setDartsIdColor<PFP>(map);
setDartsIdColor<PFP>(map,withBoundary);
Dart d = pickColor(x,y);
popColors();
return d;
......
......@@ -43,6 +43,7 @@ TopoRender::TopoRender():
m_nbRel2(0),
m_topo_dart_width(2.0f),
m_topo_relation_width(3.0f),
m_normalShift(0.0f),
m_dartsColor(1.0f,1.0f,1.0f),
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