Commit f491ef48 authored by Sylvain Thery's avatar Sylvain Thery

better partial rendering on topo3

add svg rendering
parent e2fc1ed9
...@@ -36,6 +36,7 @@ ...@@ -36,6 +36,7 @@
#include "Geometry/vector_gen.h" #include "Geometry/vector_gen.h"
#include "Utils/vbo.h" #include "Utils/vbo.h"
#include "Utils/svg.h"
// forward // forward
namespace CGoGN { namespace Utils { class ShaderSimpleColor; } } namespace CGoGN { namespace Utils { class ShaderSimpleColor; } }
...@@ -83,6 +84,11 @@ protected: ...@@ -83,6 +84,11 @@ protected:
*/ */
GLuint m_nbDarts; GLuint m_nbDarts;
/**
* number of relations 2 to draw
*/
GLuint m_nbRel1;
/** /**
* number of relations 2 to draw * number of relations 2 to draw
*/ */
...@@ -266,8 +272,6 @@ public: ...@@ -266,8 +272,6 @@ public:
void dartToCol(Dart d, float& r, float& g, float& b); void dartToCol(Dart d, float& r, float& g, float& b);
/** /**
* 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
...@@ -280,6 +284,14 @@ public: ...@@ -280,6 +284,14 @@ public:
template<typename PFP> template<typename PFP>
void updateData(typename PFP::MAP& map, const typename PFP::TVEC3& positions, float ke, float kf, float kv, const FunctorSelect& good = allDarts); void updateData(typename PFP::MAP& map, const typename PFP::TVEC3& positions, float ke, float kf, float kv, const FunctorSelect& good = allDarts);
/**
* update color buffer with color attributte handler
* @param map the map
* @param good selector
* @param colors attribute of dart's colors
*/
template<typename PFP>
void updateColors(typename PFP::MAP& map, const typename PFP::TVEC3& colors, const FunctorSelect& good = allDarts);
/** /**
* Get back middle position of drawed darts * Get back middle position of drawed darts
...@@ -290,6 +302,17 @@ public: ...@@ -290,6 +302,17 @@ public:
template<typename PFP> template<typename PFP>
void computeDartMiddlePositions(typename PFP::MAP& map, typename PFP::TVEC3& posExpl, const FunctorSelect& good = allDarts); void computeDartMiddlePositions(typename PFP::MAP& map, typename PFP::TVEC3& posExpl, const FunctorSelect& good = allDarts);
/**
* render to svg struct
*/
void toSVG(Utils::SVG::SVGOut& svg);
/**
* render svg into svg file
*/
void svgout2D(const std::string& filename, const glm::mat4& model, const glm::mat4& proj);
protected: protected:
/** /**
* update all drawing buffers to render a dual map * update all drawing buffers to render a dual map
...@@ -301,7 +324,7 @@ protected: ...@@ -301,7 +324,7 @@ protected:
* @param good selector * @param good selector
*/ */
template<typename PFP> template<typename PFP>
void updateDataMap3(typename PFP::MAP& map, const typename PFP::TVEC3& positions, float ke, float kf, float kv, const FunctorSelect& good = allDarts); void updateDataMap3(typename PFP::MAP& map, const typename PFP::TVEC3& positions, float ke, float kf, float kv, const FunctorSelect& good);
/** /**
* update all drawing buffers to render a gmap * update all drawing buffers to render a gmap
...@@ -313,7 +336,7 @@ protected: ...@@ -313,7 +336,7 @@ protected:
* @param good selector * @param good selector
*/ */
template<typename PFP> template<typename PFP>
void updateDataGMap3(typename PFP::MAP& map, const typename PFP::TVEC3& positions, float ke, float kf, float kv, const FunctorSelect& good = allDarts); void updateDataGMap3(typename PFP::MAP& map, const typename PFP::TVEC3& positions, float ke, float kf, float kv, const FunctorSelect& good);
}; };
......
...@@ -63,10 +63,6 @@ void Topo3Render::updateData(typename PFP::MAP& map, const typename PFP::TVEC3& ...@@ -63,10 +63,6 @@ void Topo3Render::updateData(typename PFP::MAP& map, const typename PFP::TVEC3&
template<typename PFP> template<typename PFP>
void Topo3Render::updateDataMap3(typename PFP::MAP& mapx, const typename PFP::TVEC3& positions, float ke, float kf, float kv, const FunctorSelect& good) void Topo3Render::updateDataMap3(typename PFP::MAP& mapx, const typename PFP::TVEC3& positions, float ke, float kf, float kv, const FunctorSelect& good)
{ {
typedef typename PFP::VEC3 VEC3;
typedef typename PFP::REAL REAL;
// Map3& map = dynamic_cast<Map3&>(mapx);
typedef typename PFP::VEC3 VEC3; typedef typename PFP::VEC3 VEC3;
typedef typename PFP::REAL REAL; typedef typename PFP::REAL REAL;
...@@ -90,8 +86,7 @@ void Topo3Render::updateDataMap3(typename PFP::MAP& mapx, const typename PFP::TV ...@@ -90,8 +86,7 @@ void Topo3Render::updateDataMap3(typename PFP::MAP& mapx, const typename PFP::TV
CellMarker cmv(mapx,VOLUME); CellMarker cmv(mapx,VOLUME);
AutoAttributeHandler<VEC3> centerVolumes(mapx,VOLUME,"centerVolumes"); AutoAttributeHandler<VEC3> centerVolumes(mapx,VOLUME,"centerVolumes");
Algo::Geometry::computeCentroidVolumes<PFP>(mapx,positions,centerVolumes,good); Algo::Geometry::computeCentroidVolumes<PFP>(mapx,positions,centerVolumes, allDarts);
// debut phi1 // debut phi1
AutoAttributeHandler<VEC3> fv1(mapx, DART); AutoAttributeHandler<VEC3> fv1(mapx, DART);
...@@ -118,7 +113,7 @@ void Topo3Render::updateDataMap3(typename PFP::MAP& mapx, const typename PFP::TV ...@@ -118,7 +113,7 @@ void Topo3Render::updateDataMap3(typename PFP::MAP& mapx, const typename PFP::TV
unsigned int posDBI=0; unsigned int posDBI=0;
// traverse each face of each volume // traverse each face of each volume
TraversorCell<typename PFP::MAP> traFace(mapx, PFP::MAP::ORBIT_IN_PARENT(FACE),good); TraversorCell<typename PFP::MAP> traFace(mapx, PFP::MAP::ORBIT_IN_PARENT(FACE),allDarts);
for (Dart d=traFace.begin(); d!=traFace.end(); d=traFace.next()) for (Dart d=traFace.begin(); d!=traFace.end(); d=traFace.next())
{ {
vecDartFaces.push_back(d); vecDartFaces.push_back(d);
...@@ -157,22 +152,25 @@ void Topo3Render::updateDataMap3(typename PFP::MAP& mapx, const typename PFP::TV ...@@ -157,22 +152,25 @@ void Topo3Render::updateDataMap3(typename PFP::MAP& mapx, const typename PFP::TV
float oke = 1.0f - ke; float oke = 1.0f - ke;
for (unsigned int i = 0; i < nb; ++i) for (unsigned int i = 0; i < nb; ++i)
{ {
VEC3 P = vecPos[i]*ke + vecPos[i+1]*oke; if (good(d))
VEC3 Q = vecPos[i+1]*ke + vecPos[i]*oke; {
VEC3 P = vecPos[i]*ke + vecPos[i+1]*oke;
VEC3 Q = vecPos[i+1]*ke + vecPos[i]*oke;
m_attIndex[d] = posDBI; m_attIndex[d] = posDBI;
posDBI+=2; posDBI+=2;
*positionDartBuf++ = P; *positionDartBuf++ = P;
*positionDartBuf++ = Q; *positionDartBuf++ = Q;
*colorDartBuf++ = m_dartsColor; *colorDartBuf++ = m_dartsColor;
*colorDartBuf++ = m_dartsColor; *colorDartBuf++ = m_dartsColor;
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;
fv2[d] = P*0.52f + Q*0.48f; fv2[d] = P*0.52f + Q*0.48f;
fv2x[d] = P*0.48f + Q*0.52f; fv2x[d] = P*0.48f + Q*0.52f;
}
d = mapx.phi1(d); d = mapx.phi1(d);
} }
...@@ -184,25 +182,16 @@ void Topo3Render::updateDataMap3(typename PFP::MAP& mapx, const typename PFP::TV ...@@ -184,25 +182,16 @@ void Topo3Render::updateDataMap3(typename PFP::MAP& mapx, const typename PFP::TV
m_vbo4->bind(); m_vbo4->bind();
glUnmapBuffer(GL_ARRAY_BUFFER); glUnmapBuffer(GL_ARRAY_BUFFER);
// phi1
m_vbo1->bind();
glBufferData(GL_ARRAY_BUFFER, 2*m_nbDarts*sizeof(typename PFP::VEC3), 0, GL_STREAM_DRAW);
GLvoid* PositionBuffer1 = glMapBufferARB(GL_ARRAY_BUFFER, GL_READ_WRITE);
//phi2
m_vbo2->bind();
glBufferData(GL_ARRAY_BUFFER, 2*m_nbDarts*sizeof(typename PFP::VEC3), 0, GL_STREAM_DRAW);
GLvoid* PositionBuffer2 = glMapBufferARB(GL_ARRAY_BUFFER, GL_READ_WRITE);
//phi3 VEC3* positioniF1 = new VEC3[ 2*m_nbDarts];
m_vbo3->bind(); VEC3* positioniF2 = new VEC3[ 2*m_nbDarts];
glBufferData(GL_ARRAY_BUFFER, 2*m_nbDarts*sizeof(typename PFP::VEC3), 0, GL_STREAM_DRAW); VEC3* positioniF3 = new VEC3[ 2*m_nbDarts];
GLvoid* PositionBuffer3 = glMapBufferARB(GL_ARRAY_BUFFER, GL_READ_WRITE);
VEC3* positionF1 = reinterpret_cast<VEC3*>(PositionBuffer1); VEC3* positionF1 = positioniF1;
VEC3* positionF2 = reinterpret_cast<VEC3*>(PositionBuffer2); VEC3* positionF2 = positioniF2;
VEC3* positionF3 = reinterpret_cast<VEC3*>(PositionBuffer3); VEC3* positionF3 = positioniF3;
m_nbRel1=0;
m_nbRel2=0; m_nbRel2=0;
m_nbRel3=0; m_nbRel3=0;
...@@ -212,7 +201,7 @@ void Topo3Render::updateDataMap3(typename PFP::MAP& mapx, const typename PFP::TV ...@@ -212,7 +201,7 @@ void Topo3Render::updateDataMap3(typename PFP::MAP& mapx, const typename PFP::TV
do do
{ {
Dart e = mapx.phi2(d); Dart e = mapx.phi2(d);
if (d < e) if ((d < e) && good(d) && good(e))
{ {
*positionF2++ = fv2[d]; *positionF2++ = fv2[d];
*positionF2++ = fv2x[e]; *positionF2++ = fv2x[e];
...@@ -221,7 +210,7 @@ void Topo3Render::updateDataMap3(typename PFP::MAP& mapx, const typename PFP::TV ...@@ -221,7 +210,7 @@ void Topo3Render::updateDataMap3(typename PFP::MAP& mapx, const typename PFP::TV
m_nbRel2++; m_nbRel2++;
} }
e = mapx.phi3(d); e = mapx.phi3(d);
if (!mapx.isBoundaryMarked(e) && (d < e)) if (!mapx.isBoundaryMarked(e) && (d < e) && good(d) && good(e))
{ {
*positionF3++ = fv2[d]; *positionF3++ = fv2[d];
*positionF3++ = fv2x[e]; *positionF3++ = fv2x[e];
...@@ -230,24 +219,28 @@ void Topo3Render::updateDataMap3(typename PFP::MAP& mapx, const typename PFP::TV ...@@ -230,24 +219,28 @@ void Topo3Render::updateDataMap3(typename PFP::MAP& mapx, const typename PFP::TV
m_nbRel3++; m_nbRel3++;
} }
e = mapx.phi1(d); e = mapx.phi1(d);
*positionF1++ = fv1[d]; if (good(d) && good(e))
*positionF1++ = fv11[e]; {
*positionF1++ = fv1[d];
*positionF1++ = fv11[e];
m_nbRel1++;
}
d = mapx.phi1(d); d = mapx.phi1(d);
} while (d != *face ); } while (d != *face );
} }
m_vbo3->bind(); m_vbo3->bind();
glUnmapBufferARB(GL_ARRAY_BUFFER); glBufferData(GL_ARRAY_BUFFER, 4*m_nbRel3*sizeof(typename PFP::VEC3), positioniF3, GL_STREAM_DRAW);
m_vbo2->bind(); m_vbo2->bind();
glUnmapBufferARB(GL_ARRAY_BUFFER); glBufferData(GL_ARRAY_BUFFER, 4*m_nbRel2*sizeof(typename PFP::VEC3), positioniF2, GL_STREAM_DRAW);
m_vbo1->bind(); m_vbo1->bind();
glUnmapBuffer(GL_ARRAY_BUFFER); glBufferData(GL_ARRAY_BUFFER, 2*m_nbRel1*sizeof(typename PFP::VEC3), positioniF1, GL_STREAM_DRAW);
m_vbo4->bind(); delete[] positioniF1;
glUnmapBuffer(GL_ARRAY_BUFFER); delete[] positioniF2;
delete[] positioniF3;
} }
...@@ -280,7 +273,7 @@ void Topo3Render::setDartsIdColor(typename PFP::MAP& map, const FunctorSelect& g ...@@ -280,7 +273,7 @@ void Topo3Render::setDartsIdColor(typename PFP::MAP& map, const FunctorSelect& g
} }
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 selector parameter ?)" << CGoGNendl;
break; break;
} }
} }
...@@ -288,6 +281,34 @@ void Topo3Render::setDartsIdColor(typename PFP::MAP& map, const FunctorSelect& g ...@@ -288,6 +281,34 @@ void Topo3Render::setDartsIdColor(typename PFP::MAP& map, const FunctorSelect& g
glUnmapBuffer(GL_ARRAY_BUFFER); glUnmapBuffer(GL_ARRAY_BUFFER);
} }
template<typename PFP>
void Topo3Render::updateColors(typename PFP::MAP& map, const typename PFP::TVEC3& colors, const FunctorSelect& good)
{
m_vbo4->bind();
Geom::Vec3f* colorBuffer = reinterpret_cast<Geom::Vec3f*>(glMapBuffer(GL_ARRAY_BUFFER, GL_READ_WRITE));
unsigned int nb=0;
for (Dart d = map.begin(); d != map.end(); map.next(d))
{
if (good(d))
{
if (nb < m_nbDarts)
{
colorBuffer[m_attIndex[d]] = colors[d];
nb++;
}
else
{
CGoGNerr << "Error buffer too small for color picking (change the selector parameter ?)" << CGoGNendl;
break;
}
}
}
glUnmapBuffer(GL_ARRAY_BUFFER);
}
template<typename PFP> template<typename PFP>
Dart Topo3Render::picking(typename PFP::MAP& map, int x, int y, const FunctorSelect& good) Dart Topo3Render::picking(typename PFP::MAP& map, int x, int y, const FunctorSelect& good)
{ {
......
...@@ -43,7 +43,7 @@ namespace GL2 ...@@ -43,7 +43,7 @@ namespace GL2
{ {
Topo3Render::Topo3Render(): Topo3Render::Topo3Render():
m_nbDarts(0),m_nbRel2(0),m_nbRel3(0), m_nbDarts(0),m_nbRel1(0),m_nbRel2(0),m_nbRel3(0),
m_topo_dart_width(2.0f), m_topo_relation_width(3.0f),m_color_save(NULL), m_topo_dart_width(2.0f), m_topo_relation_width(3.0f),m_color_save(NULL),
m_dartsColor(1.0f,1.0f,1.0f) m_dartsColor(1.0f,1.0f,1.0f)
{ {
...@@ -192,7 +192,7 @@ void Topo3Render::drawRelation1() ...@@ -192,7 +192,7 @@ void Topo3Render::drawRelation1()
m_shader1->setColor(Geom::Vec4f(0.0f,1.0f,1.0f,0.0f)); m_shader1->setColor(Geom::Vec4f(0.0f,1.0f,1.0f,0.0f));
m_shader1->enableVertexAttribs(); m_shader1->enableVertexAttribs();
glDrawArrays(GL_LINES, 0, m_nbDarts*2); glDrawArrays(GL_LINES, 0, m_nbRel1*2);
m_shader1->disableVertexAttribs(); m_shader1->disableVertexAttribs();
...@@ -370,6 +370,83 @@ Dart Topo3Render::pickColor(unsigned int x, unsigned int y) ...@@ -370,6 +370,83 @@ Dart Topo3Render::pickColor(unsigned int x, unsigned int y)
return colToDart(color); return colToDart(color);
} }
void Topo3Render::svgout2D(const std::string& filename, const glm::mat4& model, const glm::mat4& proj)
{
Utils::SVG::SVGOut svg(filename,model,proj);
toSVG(svg);
}
void Topo3Render::toSVG(Utils::SVG::SVGOut& svg)
{
svg.setWidth(m_topo_relation_width);
// PHI3 / beta3
const Geom::Vec3f* ptr = reinterpret_cast<Geom::Vec3f*>(m_vbo3->lockPtr());
svg.beginLines();
for (unsigned int i=0; i<m_nbRel3; ++i)
{
Geom::Vec3f P = (ptr[4*i]+ ptr[4*i+3])/2.0f;
Geom::Vec3f Q = (ptr[4*i+1]+ ptr[4*i+2])/2.0f;
svg.addLine(P, Q,Geom::Vec3f(0.8f,0.8f,0.0f));
}
svg.endLines();
m_vbo3->releasePtr();
// PHI2 / beta2
ptr = reinterpret_cast<Geom::Vec3f*>(m_vbo2->lockPtr());
svg.beginLines();
for (unsigned int i=0; i<m_nbRel2; ++i)
{
Geom::Vec3f P = (ptr[4*i]+ ptr[4*i+3])/2.0f;
Geom::Vec3f Q = (ptr[4*i+1]+ ptr[4*i+2])/2.0f;
svg.addLine(P, Q,Geom::Vec3f(0.8f,0.0f,0.0f));
}
svg.endLines();
m_vbo2->releasePtr();
//PHI1 /beta1
ptr = reinterpret_cast<Geom::Vec3f*>(m_vbo1->lockPtr());
svg.beginLines();
for (unsigned int i=0; i<m_nbRel1; ++i)
svg.addLine(ptr[2*i], ptr[2*i+1],Geom::Vec3f(0.0f,0.7f,0.7f));
svg.endLines();
m_vbo1->releasePtr();
const Geom::Vec3f* colorsPtr = reinterpret_cast<const Geom::Vec3f*>(m_vbo4->lockPtr());
ptr= reinterpret_cast<Geom::Vec3f*>(m_vbo0->lockPtr());
svg.setWidth(m_topo_dart_width);
svg.beginLines();
for (unsigned int i=0; i<m_nbDarts; ++i)
{
Geom::Vec3f col = colorsPtr[2*i];
if (col.norm2()>2.9f)
col = Geom::Vec3f(1.0f,1.0f,1.0f) - col;
svg.addLine(ptr[2*i], ptr[2*i+1], col);
}
svg.endLines();
svg.beginPoints();
for (unsigned int i=0; i<m_nbDarts; ++i)
{
Geom::Vec3f col = colorsPtr[2*i];
if (col.norm2()>2.9f)
col = Geom::Vec3f(1.0f,1.0f,1.0f) - col;
svg.addPoint(ptr[2*i], col);
}
svg.endPoints();
m_vbo0->releasePtr();
m_vbo4->releasePtr();
}
......
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