From f491ef4816075f3e77ee5c6b5f7032ee9de5b514 Mon Sep 17 00:00:00 2001 From: Sylvain Thery Date: Wed, 14 Mar 2012 16:34:51 +0100 Subject: [PATCH] better partial rendering on topo3 add svg rendering --- include/Algo/Render/GL2/topo3Render.h | 31 ++++++- include/Algo/Render/GL2/topo3Render.hpp | 113 ++++++++++++++---------- src/Algo/Render/topo3Render.cpp | 81 ++++++++++++++++- 3 files changed, 173 insertions(+), 52 deletions(-) diff --git a/include/Algo/Render/GL2/topo3Render.h b/include/Algo/Render/GL2/topo3Render.h index 0bad6748..725d8b75 100644 --- a/include/Algo/Render/GL2/topo3Render.h +++ b/include/Algo/Render/GL2/topo3Render.h @@ -36,6 +36,7 @@ #include "Geometry/vector_gen.h" #include "Utils/vbo.h" +#include "Utils/svg.h" // forward namespace CGoGN { namespace Utils { class ShaderSimpleColor; } } @@ -83,6 +84,11 @@ protected: */ GLuint m_nbDarts; + /** + * number of relations 2 to draw + */ + GLuint m_nbRel1; + /** * number of relations 2 to draw */ @@ -266,8 +272,6 @@ public: void dartToCol(Dart d, float& r, float& g, float& b); - - /** * update all drawing buffers to render a dual map * @param map the map @@ -280,6 +284,14 @@ public: template 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 + void updateColors(typename PFP::MAP& map, const typename PFP::TVEC3& colors, const FunctorSelect& good = allDarts); /** * Get back middle position of drawed darts @@ -290,6 +302,17 @@ public: template 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: /** * update all drawing buffers to render a dual map @@ -301,7 +324,7 @@ protected: * @param good selector */ template - 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 @@ -313,7 +336,7 @@ protected: * @param good selector */ template - 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); }; diff --git a/include/Algo/Render/GL2/topo3Render.hpp b/include/Algo/Render/GL2/topo3Render.hpp index 834bfbb8..318e739c 100644 --- a/include/Algo/Render/GL2/topo3Render.hpp +++ b/include/Algo/Render/GL2/topo3Render.hpp @@ -63,10 +63,6 @@ void Topo3Render::updateData(typename PFP::MAP& map, const typename PFP::TVEC3& template 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(mapx); typedef typename PFP::VEC3 VEC3; typedef typename PFP::REAL REAL; @@ -90,8 +86,7 @@ void Topo3Render::updateDataMap3(typename PFP::MAP& mapx, const typename PFP::TV CellMarker cmv(mapx,VOLUME); AutoAttributeHandler centerVolumes(mapx,VOLUME,"centerVolumes"); - Algo::Geometry::computeCentroidVolumes(mapx,positions,centerVolumes,good); - + Algo::Geometry::computeCentroidVolumes(mapx,positions,centerVolumes, allDarts); // debut phi1 AutoAttributeHandler fv1(mapx, DART); @@ -118,7 +113,7 @@ void Topo3Render::updateDataMap3(typename PFP::MAP& mapx, const typename PFP::TV unsigned int posDBI=0; // traverse each face of each volume - TraversorCell traFace(mapx, PFP::MAP::ORBIT_IN_PARENT(FACE),good); + TraversorCell traFace(mapx, PFP::MAP::ORBIT_IN_PARENT(FACE),allDarts); for (Dart d=traFace.begin(); d!=traFace.end(); d=traFace.next()) { vecDartFaces.push_back(d); @@ -157,22 +152,25 @@ void Topo3Render::updateDataMap3(typename PFP::MAP& mapx, const typename PFP::TV float oke = 1.0f - ke; for (unsigned int i = 0; i < nb; ++i) { - VEC3 P = vecPos[i]*ke + vecPos[i+1]*oke; - VEC3 Q = vecPos[i+1]*ke + vecPos[i]*oke; + if (good(d)) + { + VEC3 P = vecPos[i]*ke + vecPos[i+1]*oke; + VEC3 Q = vecPos[i+1]*ke + vecPos[i]*oke; - m_attIndex[d] = posDBI; - posDBI+=2; + m_attIndex[d] = posDBI; + posDBI+=2; - *positionDartBuf++ = P; - *positionDartBuf++ = Q; - *colorDartBuf++ = m_dartsColor; - *colorDartBuf++ = m_dartsColor; + *positionDartBuf++ = P; + *positionDartBuf++ = Q; + *colorDartBuf++ = m_dartsColor; + *colorDartBuf++ = m_dartsColor; - fv1[d] = P*0.1f + Q*0.9f; - fv11[d] = P*0.9f + Q*0.1f; + fv1[d] = P*0.1f + Q*0.9f; + fv11[d] = P*0.9f + Q*0.1f; - fv2[d] = P*0.52f + Q*0.48f; - fv2x[d] = P*0.48f + Q*0.52f; + fv2[d] = P*0.52f + Q*0.48f; + fv2x[d] = P*0.48f + Q*0.52f; + } d = mapx.phi1(d); } @@ -184,25 +182,16 @@ void Topo3Render::updateDataMap3(typename PFP::MAP& mapx, const typename PFP::TV m_vbo4->bind(); 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 - m_vbo3->bind(); - glBufferData(GL_ARRAY_BUFFER, 2*m_nbDarts*sizeof(typename PFP::VEC3), 0, GL_STREAM_DRAW); - GLvoid* PositionBuffer3 = glMapBufferARB(GL_ARRAY_BUFFER, GL_READ_WRITE); + VEC3* positioniF1 = new VEC3[ 2*m_nbDarts]; + VEC3* positioniF2 = new VEC3[ 2*m_nbDarts]; + VEC3* positioniF3 = new VEC3[ 2*m_nbDarts]; - VEC3* positionF1 = reinterpret_cast(PositionBuffer1); - VEC3* positionF2 = reinterpret_cast(PositionBuffer2); - VEC3* positionF3 = reinterpret_cast(PositionBuffer3); + VEC3* positionF1 = positioniF1; + VEC3* positionF2 = positioniF2; + VEC3* positionF3 = positioniF3; + m_nbRel1=0; m_nbRel2=0; m_nbRel3=0; @@ -212,7 +201,7 @@ void Topo3Render::updateDataMap3(typename PFP::MAP& mapx, const typename PFP::TV do { Dart e = mapx.phi2(d); - if (d < e) + if ((d < e) && good(d) && good(e)) { *positionF2++ = fv2[d]; *positionF2++ = fv2x[e]; @@ -221,7 +210,7 @@ void Topo3Render::updateDataMap3(typename PFP::MAP& mapx, const typename PFP::TV m_nbRel2++; } e = mapx.phi3(d); - if (!mapx.isBoundaryMarked(e) && (d < e)) + if (!mapx.isBoundaryMarked(e) && (d < e) && good(d) && good(e)) { *positionF3++ = fv2[d]; *positionF3++ = fv2x[e]; @@ -230,24 +219,28 @@ void Topo3Render::updateDataMap3(typename PFP::MAP& mapx, const typename PFP::TV m_nbRel3++; } e = mapx.phi1(d); - *positionF1++ = fv1[d]; - *positionF1++ = fv11[e]; - + if (good(d) && good(e)) + { + *positionF1++ = fv1[d]; + *positionF1++ = fv11[e]; + m_nbRel1++; + } d = mapx.phi1(d); } while (d != *face ); } 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(); - glUnmapBufferARB(GL_ARRAY_BUFFER); + glBufferData(GL_ARRAY_BUFFER, 4*m_nbRel2*sizeof(typename PFP::VEC3), positioniF2, GL_STREAM_DRAW); 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(); - glUnmapBuffer(GL_ARRAY_BUFFER); + delete[] positioniF1; + delete[] positioniF2; + delete[] positioniF3; } @@ -280,7 +273,7 @@ void Topo3Render::setDartsIdColor(typename PFP::MAP& map, const FunctorSelect& g } 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; } } @@ -288,6 +281,34 @@ void Topo3Render::setDartsIdColor(typename PFP::MAP& map, const FunctorSelect& g glUnmapBuffer(GL_ARRAY_BUFFER); } + +template +void Topo3Render::updateColors(typename PFP::MAP& map, const typename PFP::TVEC3& colors, const FunctorSelect& good) +{ + m_vbo4->bind(); + Geom::Vec3f* colorBuffer = reinterpret_cast(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 Dart Topo3Render::picking(typename PFP::MAP& map, int x, int y, const FunctorSelect& good) { diff --git a/src/Algo/Render/topo3Render.cpp b/src/Algo/Render/topo3Render.cpp index f2dcc233..f1f47d2e 100644 --- a/src/Algo/Render/topo3Render.cpp +++ b/src/Algo/Render/topo3Render.cpp @@ -43,7 +43,7 @@ namespace GL2 { 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_dartsColor(1.0f,1.0f,1.0f) { @@ -192,7 +192,7 @@ void Topo3Render::drawRelation1() m_shader1->setColor(Geom::Vec4f(0.0f,1.0f,1.0f,0.0f)); m_shader1->enableVertexAttribs(); - glDrawArrays(GL_LINES, 0, m_nbDarts*2); + glDrawArrays(GL_LINES, 0, m_nbRel1*2); m_shader1->disableVertexAttribs(); @@ -370,6 +370,83 @@ Dart Topo3Render::pickColor(unsigned int x, unsigned int y) 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(m_vbo3->lockPtr()); + + svg.beginLines(); + for (unsigned int i=0; ireleasePtr(); + + + // PHI2 / beta2 + + ptr = reinterpret_cast(m_vbo2->lockPtr()); + + svg.beginLines(); + for (unsigned int i=0; ireleasePtr(); + + //PHI1 /beta1 + ptr = reinterpret_cast(m_vbo1->lockPtr()); + + svg.beginLines(); + for (unsigned int i=0; ireleasePtr(); + + + const Geom::Vec3f* colorsPtr = reinterpret_cast(m_vbo4->lockPtr()); + ptr= reinterpret_cast(m_vbo0->lockPtr()); + + svg.setWidth(m_topo_dart_width); + + svg.beginLines(); + for (unsigned int i=0; i2.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; i2.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(); +} -- GitLab