diff --git a/Apps/Tuto/tuto_oper2.cpp b/Apps/Tuto/tuto_oper2.cpp index 4003fc5e41aa5540863806d63172ab61b0b3c24a..54eed520f562eeafaafb8c9c1966bca2b6e04f70 100644 --- a/Apps/Tuto/tuto_oper2.cpp +++ b/Apps/Tuto/tuto_oper2.cpp @@ -282,6 +282,10 @@ void MyQT::cb_keyPress(int keycode) } } break; + + case 's': + m_render_topo->svgout(myMap, "/tmp/toto.svg", modelViewMatrix(),projectionMatrix(),nb); + break; } updateGL(); diff --git a/include/Algo/Render/GL2/topoRender.h b/include/Algo/Render/GL2/topoRender.h index 08677fc96a0fdf52dc6533744125be5a87f14734..c8f65702bfe12bd70ae50b7e4e056d8dd94e8c5b 100644 --- a/include/Algo/Render/GL2/topoRender.h +++ b/include/Algo/Render/GL2/topoRender.h @@ -36,6 +36,7 @@ #include "Geometry/vector_gen.h" #include "Utils/vbo.h" +#include "Algo/Render/SVG/mapSVGRender.h" // forward namespace CGoGN { namespace Utils { class ShaderSimpleColor; } } @@ -217,6 +218,10 @@ public: template void updateDataGMap(typename PFP::MAP& map, const typename PFP::TVEC3& positions, float ke, float kf, const FunctorSelect& good = allDarts); + + + template + void svgout(typename PFP::MAP& map, const std::string& filename, const glm::mat4& model, const glm::mat4& proj, const FunctorSelect& good = allDarts); }; // just for compatibility with old code diff --git a/include/Algo/Render/GL2/topoRender.hpp b/include/Algo/Render/GL2/topoRender.hpp index f4a9607005c7db9757478f235e1898d42d3bfe32..f452bb6f8b2a79f22fe214b05e12228f0e61b9b9 100644 --- a/include/Algo/Render/GL2/topoRender.hpp +++ b/include/Algo/Render/GL2/topoRender.hpp @@ -422,6 +422,81 @@ Dart TopoRender::picking(typename PFP::MAP& map,int x, int y, const FunctorSelec } +template +void TopoRender::svgout(typename PFP::MAP& map, const std::string& filename, const glm::mat4& model, const glm::mat4& proj, const FunctorSelect& good) +{ + + Algo::Render::SVG::SVGOut svg(filename,model,proj); + + svg.setWidth(3.0f); + + // PHI2 + m_vbo2->bind(); + Geom::Vec3f* ptr = reinterpret_cast(glMapBuffer(GL_ARRAY_BUFFER, GL_READ_ONLY)); + + svg.beginLines(); + for (unsigned int i=0; ibind(); + glUnmapBuffer(GL_ARRAY_BUFFER); + + //PHI1 + m_vbo1->bind(); + ptr = reinterpret_cast(glMapBuffer(GL_ARRAY_BUFFER, GL_READ_ONLY)); + + svg.beginLines(); + for (unsigned int i=0; ibind(); + glUnmapBuffer(GL_ARRAY_BUFFER); + + + m_vbo0->bind(); + ptr= reinterpret_cast(glMapBuffer(GL_ARRAY_BUFFER, GL_READ_ONLY)); + m_vbo3->bind(); + Geom::Vec3f* colorsPtr = reinterpret_cast(glMapBuffer(GL_ARRAY_BUFFER, GL_READ_ONLY)); + + svg.setWidth(5.0f); + + svg.beginLines(); + for (Dart d = map.begin(); d != map.end(); map.next(d)) + { + if (good(d)) + { + unsigned int id = m_attIndex[d]; +// svg.addLine(ptr[id], ptr[id+1], colorsPtr[id]); + svg.addLine(ptr[id], ptr[id+1], Geom::Vec3f(0.0f,0.0f,0.0f)); + } + } + svg.endLines(); + + svg.beginPoints(); + for (Dart d = map.begin(); d != map.end(); map.next(d)) + { + if (good(d)) + { + unsigned int id = m_attIndex[d]; +// svg.addPoint(ptr[id], colorsPtr[id]); + svg.addPoint(ptr[id], Geom::Vec3f(0.0f,0.0f,0.0f)); + } + } + svg.endPoints(); + + + + m_vbo0->bind(); + glUnmapBuffer(GL_ARRAY_BUFFER); + m_vbo3->bind(); + glUnmapBuffer(GL_ARRAY_BUFFER); + + // relations: + +} + }//end namespace GL2 diff --git a/include/Algo/Render/SVG/mapSVGRender.h b/include/Algo/Render/SVG/mapSVGRender.h index ad95ccf76f6b54706e7443d76e0b56e653fd7d62..81fbbe9e2b5571205d50ed18cccd1c671e4ab0a4 100644 --- a/include/Algo/Render/SVG/mapSVGRender.h +++ b/include/Algo/Render/SVG/mapSVGRender.h @@ -63,6 +63,7 @@ class SvgObj { protected: std::vector m_vertices; + std::vector m_colors; std::vector m_vertices3D; Geom::Vec3f m_color; float m_width; @@ -71,6 +72,13 @@ public: void addVertex3D(const Geom::Vec3f& v); + void addVertex(const Geom::Vec3f& v, const Geom::Vec3f& C); + + void addVertex3D(const Geom::Vec3f& v, const Geom::Vec3f& C); + + +// void addColor(const Geom::Vec3f& c); + void setColor(const Geom::Vec3f& c); void setWidth(float w) { m_width=w;} @@ -100,6 +108,12 @@ public: void save(std::ofstream& out); }; +class SvgLines: public SvgObj +{ +public: + void save(std::ofstream& out); +}; + class SvgPolygon: public SvgObj { @@ -127,6 +141,8 @@ protected: std::vector m_objs; + SvgObj* m_current; + public: /** @@ -160,6 +176,23 @@ public: void orderPrimitives(std::list& primitives); + + + void beginPoints(); + + void endPoints(); + + void addPoint(const Geom::Vec3f& P); + void addPoint(const Geom::Vec3f& P, const Geom::Vec3f& C); + + + void beginLines(); + + void endLines(); + + void addLine(const Geom::Vec3f& P, const Geom::Vec3f& P2); + void addLine(const Geom::Vec3f& P, const Geom::Vec3f& P2, const Geom::Vec3f& C); + }; diff --git a/include/Algo/Render/SVG/mapSVGRender.hpp b/include/Algo/Render/SVG/mapSVGRender.hpp index b6d81eb93b8b98959489a86e6ca625cba997d97d..13f21f7549a497d631fd78f4ffae0779f31a01b6 100644 --- a/include/Algo/Render/SVG/mapSVGRender.hpp +++ b/include/Algo/Render/SVG/mapSVGRender.hpp @@ -42,90 +42,47 @@ namespace SVG template void SVGOut::renderPointsToSVG(typename PFP::MAP& map, const typename PFP::TVEC3& position, const FunctorSelect& good, unsigned int thread) { - glm::i32vec4 viewport; - glGetIntegerv(GL_VIEWPORT, &(viewport[0])); - SvgPoints* points = new SvgPoints(); points->setColor(global_color); points->setWidth(global_width); -// DartMarker m(map, thread); -// for(Dart d = map.begin(); d != map.end(); map.next(d)) -// { -// if(!m.isMarked(d) && good(d)) -// { -// const Geom::Vec3f& P = position[d]; -// glm::vec3 Q = glm::project(glm::vec3(P[0],P[1],P[2]),m_model,m_proj,viewport); -// glm::vec3 R = glm::project(glm::vec3(P[0],P[1],P[2]),m_model,glm::mat4(1.0),viewport); -// points->addVertex(Geom::Vec3f(Q[0],float(viewport[3])-Q[1],Q[2])); -// m.markOrbit(VERTEX, d); -// } -// } -// m_objs.push_back(points); TraversorV trav(map,good,thread); for(Dart d = trav.begin(); d != trav.end(); d=trav.next()) { const Geom::Vec3f& P = position[d]; - glm::vec3 Q = glm::project(glm::vec3(P[0],P[1],P[2]),m_model,m_proj,viewport); - glm::vec3 R = glm::project(glm::vec3(P[0],P[1],P[2]),m_model,glm::mat4(1.0),viewport); - points->addVertex(Geom::Vec3f(Q[0],float(viewport[3])-Q[1],Q[2])); + glm::vec3 Q = glm::project(glm::vec3(P[0],P[1],P[2]),m_model,m_proj,m_viewport); + glm::vec3 R = glm::project(glm::vec3(P[0],P[1],P[2]),m_model,glm::mat4(1.0),m_viewport); + points->addVertex(Geom::Vec3f(Q[0],float(m_viewport[3])-Q[1],Q[2])); } + m_objs.push_back(points); } + + + template void SVGOut::renderLinesToSVG(typename PFP::MAP& map, const typename PFP::TVEC3& position, const FunctorSelect& good, unsigned int thread) { - glm::i32vec4 viewport; - glGetIntegerv(GL_VIEWPORT, &(viewport[0])); - -// DartMarker m(map, thread); -// for(Dart d = map.begin(); d != map.end(); map.next(d)) -// { -// if(!m.isMarked(d) && good(d)) -// { -// -// const Geom::Vec3f& P = position[d]; -// glm::vec3 Q = glm::project(glm::vec3(P[0],P[1],P[2]),m_model,m_proj,viewport); -// glm::vec3 R = glm::project(glm::vec3(P[0],P[1],P[2]),m_model,glm::mat4(1.0),viewport); -// -// const Geom::Vec3f& P2 = position[map.phi1(d)]; -// glm::vec3 Q2 = glm::project(glm::vec3(P2[0],P2[1],P2[2]),m_model,m_proj,viewport); -// glm::vec3 R2 = glm::project(glm::vec3(P2[0],P2[1],P2[2]),m_model,glm::mat4(1.0),viewport); -// -// SvgPolyline* pol = new SvgPolyline(); -// pol->addVertex(Geom::Vec3f(Q[0],float(viewport[3])-Q[1],Q[2])); -// pol->addVertex(Geom::Vec3f(Q2[0],float(viewport[3])-Q2[1],Q2[2])); -// -// pol->addVertex3D(Geom::Vec3f(R[0],float(viewport[3])-R[1],R[2])); -// pol->addVertex3D(Geom::Vec3f(R2[0],float(viewport[3])-R2[1],R2[2])); -// -// pol->setColor(global_color); -// pol->setWidth(global_width); -// m_objs.push_back(pol); -// m.markOrbit(EDGE, d); -// } -// } - TraversorE trav(map,good,thread); for(Dart d = trav.begin(); d != trav.end(); d=trav.next()) { const Geom::Vec3f& P = position[d]; - glm::vec3 Q = glm::project(glm::vec3(P[0],P[1],P[2]),m_model,m_proj,viewport); - glm::vec3 R = glm::project(glm::vec3(P[0],P[1],P[2]),m_model,glm::mat4(1.0),viewport); + glm::vec3 Q = glm::project(glm::vec3(P[0],P[1],P[2]),m_model,m_proj,m_viewport); + glm::vec3 R = glm::project(glm::vec3(P[0],P[1],P[2]),m_model,glm::mat4(1.0),m_viewport); const Geom::Vec3f& P2 = position[map.phi1(d)]; - glm::vec3 Q2 = glm::project(glm::vec3(P2[0],P2[1],P2[2]),m_model,m_proj,viewport); - glm::vec3 R2 = glm::project(glm::vec3(P2[0],P2[1],P2[2]),m_model,glm::mat4(1.0),viewport); + glm::vec3 Q2 = glm::project(glm::vec3(P2[0],P2[1],P2[2]),m_model,m_proj,m_viewport); + glm::vec3 R2 = glm::project(glm::vec3(P2[0],P2[1],P2[2]),m_model,glm::mat4(1.0),m_viewport); SvgPolyline* pol = new SvgPolyline(); - pol->addVertex(Geom::Vec3f(Q[0],float(viewport[3])-Q[1],Q[2])); - pol->addVertex(Geom::Vec3f(Q2[0],float(viewport[3])-Q2[1],Q2[2])); + pol->addVertex(Geom::Vec3f(Q[0],float(m_viewport[3])-Q[1],Q[2])); + pol->addVertex(Geom::Vec3f(Q2[0],float(m_viewport[3])-Q2[1],Q2[2])); - pol->addVertex3D(Geom::Vec3f(R[0],float(viewport[3])-R[1],R[2])); - pol->addVertex3D(Geom::Vec3f(R2[0],float(viewport[3])-R2[1],R2[2])); + pol->addVertex3D(Geom::Vec3f(R[0],float(m_viewport[3])-R[1],R[2])); + pol->addVertex3D(Geom::Vec3f(R2[0],float(m_viewport[3])-R2[1],R2[2])); pol->setColor(global_color); pol->setWidth(global_width); @@ -137,55 +94,6 @@ void SVGOut::renderLinesToSVG(typename PFP::MAP& map, const typename PFP::TVEC3& template void SVGOut::renderFacesToSVG(typename PFP::MAP& map, const typename PFP::TVEC3& position, float shrink, bool cull, const FunctorSelect& good, unsigned int thread) { - glm::i32vec4 viewport; - glGetIntegerv(GL_VIEWPORT, &(viewport[0])); - -// DartMarker m(map, thread); -// for(Dart d = map.begin(); d != map.end(); map.next(d)) -// { -// if(!m.isMarked(d) && good(d)) -// { -// bool cullFace=false; -// if (cull) -// { -// const Geom::Vec3f& P = position[d]; -// -// glm::vec3 Q = glm::project(glm::vec3(P[0],P[1],P[2]),m_model,m_proj,viewport); -// const Geom::Vec3f& P2 = position[map.phi1(d)]; -// glm::vec3 R = glm::project(glm::vec3(P2[0],P2[1],P2[2]),m_model,m_proj,viewport); -// const Geom::Vec3f& P3 = position[map.phi1(map.phi1(d))]; -// glm::vec3 S = glm::project(glm::vec3(P3[0],P3[1],P3[2]),m_model,m_proj,viewport); -// glm::vec3 N = glm::cross(S-R,Q-R); -// if (N[2]<0.0f) -// cullFace=true; -// } -// -// if (!cullFace) -// { -// typename PFP::VEC3 center = Algo::Geometry::faceCentroid(map,d,position); -// SvgPolygon* pol = new SvgPolygon(); -// Dart dd = d; -// do -// { -// Geom::Vec3f P = position[d]; -// P = P*shrink + center*(1.0f-shrink); -// glm::vec3 Q = glm::project(glm::vec3(P[0],P[1],P[2]),m_model,m_proj,viewport); -// glm::vec3 R = glm::project(glm::vec3(P[0],P[1],P[2]),m_model,glm::mat4(1.0),viewport); -// pol->addVertex(Geom::Vec3f(Q[0],float(viewport[3])-Q[1],Q[2])); -// pol->addVertex3D(Geom::Vec3f(R[0],R[1],R[2])); -// d = map.phi1(d); -// }while (d!=dd); -// -// pol->close(); -// pol->setColor(global_color); -// pol->setWidth(global_width); -// m_objs.push_back(pol); -// } -// m.markOrbit(FACE, d); -// } -// } - - TraversorF trav(map,good,thread); for(Dart d = trav.begin(); d != trav.end(); d=trav.next()) @@ -195,11 +103,11 @@ void SVGOut::renderFacesToSVG(typename PFP::MAP& map, const typename PFP::TVEC3& { const Geom::Vec3f& P = position[d]; - glm::vec3 Q = glm::project(glm::vec3(P[0],P[1],P[2]),m_model,m_proj,viewport); + glm::vec3 Q = glm::project(glm::vec3(P[0],P[1],P[2]),m_model,m_proj,m_viewport); const Geom::Vec3f& P2 = position[map.phi1(d)]; - glm::vec3 R = glm::project(glm::vec3(P2[0],P2[1],P2[2]),m_model,m_proj,viewport); + glm::vec3 R = glm::project(glm::vec3(P2[0],P2[1],P2[2]),m_model,m_proj,m_viewport); const Geom::Vec3f& P3 = position[map.phi1(map.phi1(d))]; - glm::vec3 S = glm::project(glm::vec3(P3[0],P3[1],P3[2]),m_model,m_proj,viewport); + glm::vec3 S = glm::project(glm::vec3(P3[0],P3[1],P3[2]),m_model,m_proj,m_viewport); glm::vec3 N = glm::cross(S-R,Q-R); if (N[2]<0.0f) cullFace=true; @@ -214,9 +122,9 @@ void SVGOut::renderFacesToSVG(typename PFP::MAP& map, const typename PFP::TVEC3& { Geom::Vec3f P = position[d]; P = P*shrink + center*(1.0f-shrink); - glm::vec3 Q = glm::project(glm::vec3(P[0],P[1],P[2]),m_model,m_proj,viewport); - glm::vec3 R = glm::project(glm::vec3(P[0],P[1],P[2]),m_model,glm::mat4(1.0),viewport); - pol->addVertex(Geom::Vec3f(Q[0],float(viewport[3])-Q[1],Q[2])); + glm::vec3 Q = glm::project(glm::vec3(P[0],P[1],P[2]),m_model,m_proj,m_viewport); + glm::vec3 R = glm::project(glm::vec3(P[0],P[1],P[2]),m_model,glm::mat4(1.0),m_viewport); + pol->addVertex(Geom::Vec3f(Q[0],float(m_viewport[3])-Q[1],Q[2])); pol->addVertex3D(Geom::Vec3f(R[0],R[1],R[2])); d = map.phi1(d); }while (d!=dd); diff --git a/src/Algo/Render/mapSVGRender.cpp b/src/Algo/Render/mapSVGRender.cpp index e901eb7f77bbbdc07c626fca8367db50922f21f6..bf9ce958c25fe71a7486ae8ffb2a89c291c22877 100644 --- a/src/Algo/Render/mapSVGRender.cpp +++ b/src/Algo/Render/mapSVGRender.cpp @@ -43,14 +43,31 @@ namespace Render namespace SVG { + + + void SvgObj::addVertex(const Geom::Vec3f& v) { m_vertices.push_back(v); + m_colors.push_back(m_color); } void SvgObj::addVertex3D(const Geom::Vec3f& v) { m_vertices3D.push_back(v); + m_colors.push_back(m_color); +} + +void SvgObj::addVertex(const Geom::Vec3f& v, const Geom::Vec3f& c) +{ + m_vertices.push_back(v); + m_colors.push_back(c); +} + +void SvgObj::addVertex3D(const Geom::Vec3f& v, const Geom::Vec3f& c) +{ + m_vertices3D.push_back(v); + m_colors.push_back(c); } @@ -90,21 +107,23 @@ void SvgPoints::save(std::ofstream& out) { std::stringstream ss; - for (std::vector::iterator it =m_vertices.begin(); it != m_vertices.end(); ++it) +// for (std::vector::iterator it =m_vertices.begin(); it != m_vertices.end(); ++it) + unsigned int nb = m_vertices.size(); + for (unsigned int i=0; i"<< std::endl; +} +void SvgLines::save(std::ofstream& out) +{ + std::stringstream ss; + +// for (std::vector::iterator it =m_vertices.begin(); it != m_vertices.end(); ++it) + unsigned int nb = m_vertices.size(); + for (unsigned int i=0; i"<< std::endl; + } } + void SvgPolygon::setColorFill(const Geom::Vec3f& c) { m_colorFill=c; @@ -370,6 +416,88 @@ bool compNormObj::operator() (SvgObj* a, SvgObj*b) +void SVGOut::beginPoints() +{ + glm::i32vec4 viewport; + glGetIntegerv(GL_VIEWPORT, &(viewport[0])); + + m_current = new SvgPoints(); + m_current->setColor(global_color); + m_current->setWidth(global_width); +} + +void SVGOut::endPoints() +{ + m_objs.push_back(m_current); +} + +void SVGOut::addPoint(const Geom::Vec3f& P) +{ + glm::vec3 Q = glm::project(glm::vec3(P[0],P[1],P[2]),m_model,m_proj,m_viewport); + glm::vec3 R = glm::project(glm::vec3(P[0],P[1],P[2]),m_model,glm::mat4(1.0),m_viewport); + m_current->addVertex(Geom::Vec3f(Q[0],float(m_viewport[3])-Q[1],Q[2])); + m_current->addVertex3D(Geom::Vec3f(Q[0],float(m_viewport[3])-Q[1],Q[2])); +} + +void SVGOut::addPoint(const Geom::Vec3f& P, const Geom::Vec3f& C) +{ + glm::vec3 Q = glm::project(glm::vec3(P[0],P[1],P[2]),m_model,m_proj,m_viewport); + glm::vec3 R = glm::project(glm::vec3(P[0],P[1],P[2]),m_model,glm::mat4(1.0),m_viewport); + m_current->addVertex(Geom::Vec3f(Q[0],float(m_viewport[3])-Q[1],Q[2]),C); + m_current->addVertex3D(Geom::Vec3f(Q[0],float(m_viewport[3])-Q[1],Q[2]),C); +} + + +void SVGOut::beginLines() +{ + glm::i32vec4 viewport; + glGetIntegerv(GL_VIEWPORT, &(viewport[0])); + + m_current = new SvgLines(); + m_current->setColor(global_color); + m_current->setWidth(global_width); +} + + +void SVGOut::endLines() +{ + m_objs.push_back(m_current); +} + +void SVGOut::addLine(const Geom::Vec3f& P, const Geom::Vec3f& P2) +{ + glm::vec3 Q = glm::project(glm::vec3(P[0],P[1],P[2]),m_model,m_proj,m_viewport); + glm::vec3 R = glm::project(glm::vec3(P[0],P[1],P[2]),m_model,glm::mat4(1.0),m_viewport); + + glm::vec3 Q2 = glm::project(glm::vec3(P2[0],P2[1],P2[2]),m_model,m_proj,m_viewport); + glm::vec3 R2 = glm::project(glm::vec3(P2[0],P2[1],P2[2]),m_model,glm::mat4(1.0),m_viewport); + + m_current->addVertex(Geom::Vec3f(Q[0],float(m_viewport[3])-Q[1],Q[2])); + m_current->addVertex(Geom::Vec3f(Q2[0],float(m_viewport[3])-Q2[1],Q2[2])); + + m_current->addVertex3D(Geom::Vec3f(R[0],float(m_viewport[3])-R[1],R[2])); + m_current->addVertex3D(Geom::Vec3f(R2[0],float(m_viewport[3])-R2[1],R2[2])); +} + + + +void SVGOut::addLine(const Geom::Vec3f& P, const Geom::Vec3f& P2, const Geom::Vec3f& C) +{ + glm::vec3 Q = glm::project(glm::vec3(P[0],P[1],P[2]),m_model,m_proj,m_viewport); + glm::vec3 R = glm::project(glm::vec3(P[0],P[1],P[2]),m_model,glm::mat4(1.0),m_viewport); + + glm::vec3 Q2 = glm::project(glm::vec3(P2[0],P2[1],P2[2]),m_model,m_proj,m_viewport); + glm::vec3 R2 = glm::project(glm::vec3(P2[0],P2[1],P2[2]),m_model,glm::mat4(1.0),m_viewport); + + m_current->addVertex(Geom::Vec3f(Q[0],float(m_viewport[3])-Q[1],Q[2]),C); + m_current->addVertex(Geom::Vec3f(Q2[0],float(m_viewport[3])-Q2[1],Q2[2]),C); + + m_current->addVertex3D(Geom::Vec3f(R[0],float(m_viewport[3])-R[1],R[2]),C); + m_current->addVertex3D(Geom::Vec3f(R2[0],float(m_viewport[3])-R2[1],R2[2]),C); +} + + + } // namespace SVG } // namespace Render