From f29d13fe418039199413c704323751fc3c6327bf Mon Sep 17 00:00:00 2001 From: Sylvain Thery Date: Fri, 17 Feb 2012 17:06:03 +0100 Subject: [PATCH] svg output from drawer --- Apps/Tuto/show_traversors.cpp | 44 ++++++++++++------ Apps/Tuto/show_traversors.h | 8 ++++ Apps/Tuto/show_traversors.ui | 23 ++++++++++ include/Utils/drawer.h | 6 +++ include/Utils/svg.h | 5 +++ src/Utils/drawer.cpp | 69 ++++++++++++++++++++++++++++ src/Utils/svg.cpp | 85 +++++++++++++++++++++++++++++------ 7 files changed, 214 insertions(+), 26 deletions(-) diff --git a/Apps/Tuto/show_traversors.cpp b/Apps/Tuto/show_traversors.cpp index e372d167..0950a50e 100644 --- a/Apps/Tuto/show_traversors.cpp +++ b/Apps/Tuto/show_traversors.cpp @@ -106,6 +106,15 @@ void MyQT::cb_combo6(int x) CGoGNerr <<"undefined traversor" << CGoGNendl; } +void MyQT::cb_explode(int x) +{ + m_expl = float (x) /100.0f; + if (m_last==2) + traverse2(); + if (m_last==3) + traverse3(); +} + void MyQT::cb_initGL() { @@ -154,6 +163,13 @@ void MyQT::cb_mousePress(int button, int x, int y) } +void MyQT::cb_Save() +{ + std::string filename = selectFileSave("Export SVG file ",".","(*.svg)"); + Utils::SVG::SVGOut svg(filename,modelViewMatrix(),projectionMatrix()); + m_drawer.toSVG(svg); +} + void MyQT::colorizeCell(Dart d, unsigned int orbit, float r,float g, float b) { TraversorDartsOfOrbitdoo (myMap,orbit,d); @@ -166,37 +182,37 @@ void MyQT::traverse2() { if (m_selected == NIL) return; - + m_last=2; // int code = (m_ajd_or_inci2)*100+m_first2*10+m_second2; SelectorDartNoBoundary nb(myMap); m_drawer.newList(GL_COMPILE); m_drawer.lineWidth(3.0f); m_drawer.pointSize(7.0f); - m_drawer.color3f(1.0f,1.0f,0.0f); + m_drawer.color3f(0.0f,0.7f,0.0f); m_affDarts.clear(); if (m_ajd_or_inci2 == 0) // incident { - Algo::Render::drawerCell(VERTEX+m_second2, m_drawer,myMap,m_selected,position,0.7f); + Algo::Render::drawerCell(VERTEX+m_second2, m_drawer,myMap,m_selected,position,m_expl); m_drawer.color3f(1.0f,0.0f,0.0f); Traversor2* tra = Traversor2::createIncident(myMap,m_selected,VERTEX+m_second2,VERTEX+m_first2); for (Dart d=tra->begin(); d != tra->end(); d= tra->next()) m_affDarts.push_back(d); - Algo::Render::drawerCells(VERTEX+m_first2, m_drawer, myMap,m_affDarts,position,0.7f); + Algo::Render::drawerCells(VERTEX+m_first2, m_drawer, myMap,m_affDarts,position,m_expl); } else // adjacent { - Algo::Render::drawerCell(VERTEX+m_first2, m_drawer,myMap,m_selected,position,0.7f); + Algo::Render::drawerCell(VERTEX+m_first2, m_drawer,myMap,m_selected,position,m_expl); m_drawer.color3f(1.0f,0.0f,0.0f); Traversor2* tra = Traversor2::createAdjacent(myMap,m_selected,VERTEX+m_first2,VERTEX+m_second2); for (Dart d=tra->begin(); d != tra->end(); d= tra->next()) m_affDarts.push_back(d); - Algo::Render::drawerCells(VERTEX+m_first2, m_drawer, myMap,m_affDarts,position,0.7f); + Algo::Render::drawerCells(VERTEX+m_first2, m_drawer, myMap,m_affDarts,position,m_expl); } m_drawer.endList(); @@ -207,35 +223,36 @@ void MyQT::traverse2() void MyQT::traverse3() { -// int code = (m_ajd_or_inci3)*100+m_first3*10+m_second3; -// std::cout << "CODE="<< code << std::endl; if (m_selected == NIL) return; + + m_last=3; + SelectorDartNoBoundary nb(myMap); m_affDarts.clear(); m_drawer.newList(GL_COMPILE); m_drawer.lineWidth(3.0f); m_drawer.pointSize(7.0f); - m_drawer.color3f(1.0f,1.0f,0.0f); + m_drawer.color3f(0.0f,0.7f,0.0f); if (m_ajd_or_inci3 == 0) // incident { - Algo::Render::drawerCell(VERTEX+m_second3, m_drawer,myMap,m_selected,position,0.7f); + Algo::Render::drawerCell(VERTEX+m_second3, m_drawer,myMap,m_selected,position,m_expl); m_drawer.color3f(1.0f,0.0f,0.0f); Traversor3XY tra(myMap,m_selected,VERTEX+m_second3,VERTEX+m_first3); for (Dart d=tra.begin(); d != tra.end(); d= tra.next()) m_affDarts.push_back(d); - Algo::Render::drawerCells(VERTEX+m_first3, m_drawer, myMap,m_affDarts,position,0.7f); + Algo::Render::drawerCells(VERTEX+m_first3, m_drawer, myMap,m_affDarts,position,m_expl); } else // adjacent { - Algo::Render::drawerCell(VERTEX+m_first3, m_drawer,myMap,m_selected,position,0.7f); + Algo::Render::drawerCell(VERTEX+m_first3, m_drawer,myMap,m_selected,position,m_expl); m_drawer.color3f(1.0f,0.0f,0.0f); Traversor3XXaY tra(myMap,m_selected,VERTEX+m_first3,VERTEX+m_second3); for (Dart d=tra.begin(); d != tra.end(); d= tra.next()) m_affDarts.push_back(d); - Algo::Render::drawerCells(VERTEX+m_first3, m_drawer, myMap,m_affDarts,position,0.7f); + Algo::Render::drawerCells(VERTEX+m_first3, m_drawer, myMap,m_affDarts,position,m_expl); } m_drawer.endList(); @@ -280,6 +297,7 @@ int main(int argc, char **argv) sqt.setCallBack( dock.combo4, SIGNAL( activated(int)), SLOT(cb_combo4(int)) ); sqt.setCallBack( dock.combo5, SIGNAL( activated(int)), SLOT(cb_combo5(int)) ); sqt.setCallBack( dock.combo6, SIGNAL( activated(int)), SLOT(cb_combo6(int)) ); + sqt.setCallBack( dock.explodeSlider, SIGNAL(valueChanged(int)), SLOT(cb_explode(int)) ); sqt.setCallBack( dock.checkTopo, SIGNAL( clicked(bool)), SLOT(cb_checkTopo(bool)) ); diff --git a/Apps/Tuto/show_traversors.h b/Apps/Tuto/show_traversors.h index c6cda94f..ffe20321 100644 --- a/Apps/Tuto/show_traversors.h +++ b/Apps/Tuto/show_traversors.h @@ -96,6 +96,8 @@ class MyQT: public Utils::QT::SimpleQT unsigned int m_first2; unsigned int m_ajd_or_inci2; unsigned int m_second2; + float m_expl; + unsigned int m_last; public: MyQT(): m_render_topo(NULL), @@ -106,6 +108,8 @@ public: m_first2(0), m_ajd_or_inci2(0), m_second2(1), + m_expl(0.8f), + m_last(2), m_selected(NIL) {} @@ -122,6 +126,8 @@ protected: void cb_initGL(); + void cb_Save(); + void cb_mousePress(int button, int x, int y); void colorizeCell(Dart d, unsigned int orbit, float r,float g, float b); @@ -139,6 +145,8 @@ public slots: void cb_combo5(int x); void cb_combo6(int x); void cb_checkTopo(bool b); + void cb_explode(int x); + }; #endif diff --git a/Apps/Tuto/show_traversors.ui b/Apps/Tuto/show_traversors.ui index 42afb97e..c53b76bd 100644 --- a/Apps/Tuto/show_traversors.ui +++ b/Apps/Tuto/show_traversors.ui @@ -210,6 +210,29 @@ + + + + 1 + + + 100 + + + 80 + + + Qt::Horizontal + + + + + + + Qt::Horizontal + + + diff --git a/include/Utils/drawer.h b/include/Utils/drawer.h index 8504c48e..56f61968 100644 --- a/include/Utils/drawer.h +++ b/include/Utils/drawer.h @@ -31,6 +31,7 @@ namespace CGoGN { namespace Utils { class VBO; } } namespace CGoGN { namespace Utils { class ShaderColorPerVertex; } } +namespace CGoGN { namespace Utils { namespace SVG { class SVGOut ; } } } namespace CGoGN { @@ -137,6 +138,11 @@ public: * usr as glPointSize */ void pointSize(float ps); + + /** + * rendering in svg struct + */ + void toSVG(Utils::SVG::SVGOut& svg); }; } // namespace Utils diff --git a/include/Utils/svg.h b/include/Utils/svg.h index f78e8d4f..9772e641 100644 --- a/include/Utils/svg.h +++ b/include/Utils/svg.h @@ -81,6 +81,8 @@ public: Geom::Vec3f normal(); + const std::vector& vertices() const; + }; class SvgPoints: public SvgObj @@ -127,6 +129,9 @@ protected: std::vector m_objs; SvgObj* m_current; +protected: + void computeBB(unsigned int& a, unsigned int& b, unsigned int& c, unsigned& d); + public: /** diff --git a/src/Utils/drawer.cpp b/src/Utils/drawer.cpp index 564de83d..cdd2be8d 100644 --- a/src/Utils/drawer.cpp +++ b/src/Utils/drawer.cpp @@ -22,10 +22,12 @@ * * *******************************************************************************/ +#include "GL/glew.h" #include "Utils/drawer.h" #include "Utils/Shaders/shaderColorPerVertex.h" #include "Utils/vbo.h" +#include "Utils/svg.h" namespace CGoGN { @@ -167,6 +169,73 @@ void Drawer::callList() m_shader->disableVertexAttribs(); } + +void Drawer::toSVG(Utils::SVG::SVGOut& svg) +{ + const Geom::Vec3f* ptrP = reinterpret_cast(m_vboPos->lockPtr()); + const Geom::Vec3f* ptrC = reinterpret_cast(m_vboCol->lockPtr()); + + for (std::vector::iterator pp = m_begins.begin(); pp != m_begins.end(); ++pp) + { + svg.setWidth(pp->width); + if (pp->mode == GL_POINTS) + { + unsigned int end = pp->begin + pp->nb; + svg.beginPoints(); + for (unsigned int i=pp->begin; imode == GL_LINES) + { + unsigned int end = pp->begin + pp->nb; + svg.beginLines(); + for (unsigned int i=pp->begin; imode == GL_LINE_LOOP) || (pp->mode == GL_POLYGON)) + { + unsigned int end = pp->begin + pp->nb-1; + svg.beginLines(); + for (unsigned int i=pp->begin; i<=end; ++i) + svg.addLine(ptrP[i], ptrP[i+1], ptrC[i]); + svg.addLine(ptrP[end], ptrP[pp->begin], ptrC[end]); + svg.endLines(); + } + if (pp->mode == GL_TRIANGLES) + { + unsigned int end = pp->begin + pp->nb; + svg.beginLines(); + for (unsigned int i=pp->begin; imode == GL_QUADS) + { + unsigned int end = pp->begin + pp->nb; + svg.beginLines(); + for (unsigned int i=pp->begin; ireleasePtr(); + m_vboCol->releasePtr(); +} + } // namespace Utils } // namespace CGoGN diff --git a/src/Utils/svg.cpp b/src/Utils/svg.cpp index 77e3aab1..e96d9033 100644 --- a/src/Utils/svg.cpp +++ b/src/Utils/svg.cpp @@ -37,6 +37,11 @@ namespace SVG { +const std::vector& SvgObj::vertices() const +{ + return m_vertices; +} + void SvgObj::addVertex(const Geom::Vec3f& v) { m_vertices.push_back(v); @@ -248,19 +253,19 @@ SVGOut::SVGOut(const std::string& filename, const glm::mat4& model, const glm::m } glGetIntegerv(GL_VIEWPORT, &(m_viewport[0])); - - *m_out << ""<< std::endl; - *m_out << ""<< std::endl; - *m_out << "test"<< std::endl; - *m_out << ""<< std::endl; - *m_out << "Rendered from CGoGN"<< std::endl; - - *m_out << ""<< std::endl; - *m_out << ""<< std::endl; - *m_out << ""<< std::endl; - *m_out << "" << std::endl; +// +// *m_out << ""<< std::endl; +// *m_out << ""<< std::endl; +// *m_out << "test"<< std::endl; +// *m_out << ""<< std::endl; +// *m_out << "Rendered from CGoGN"<< std::endl; +// +// *m_out << ""<< std::endl; +// *m_out << ""<< std::endl; +// *m_out << ""<< std::endl; +// *m_out << "" << std::endl; } SVGOut::~SVGOut() @@ -287,6 +292,26 @@ void SVGOut::setWidth(float w) void SVGOut::closeFile() { + unsigned int a = 0; + unsigned int b = 0; + unsigned int c = 1024; + unsigned int d = 1024; + computeBB(a,b,c,d); + + *m_out << ""<< std::endl; + *m_out << ""<< std::endl; + *m_out << "viewBox=\""<< a <<" "<< b <<" "<< c-a << " " << d-b <<"\">"<< std::endl; + *m_out << "test"<< std::endl; + *m_out << ""<< std::endl; + *m_out << "Rendered from CGoGN"<< std::endl; + + *m_out << ""<< std::endl; + *m_out << ""<< std::endl; + *m_out << ""<< std::endl; + *m_out << "" << std::endl; + // here do the sort in necessary for (std::vector::iterator it = m_objs.begin(); it != m_objs.end(); ++it) @@ -300,6 +325,40 @@ void SVGOut::closeFile() } +void SVGOut::computeBB(unsigned int& a, unsigned int& b, unsigned int& c, unsigned& d) +{ + // here do the sort in necessary + a = 100000; + b = 100000; + c = 0; + d = 0; + + for (std::vector::iterator it = m_objs.begin(); it != m_objs.end(); ++it) + { + const std::vector& vert = (*it)->vertices(); + for (std::vector::const_iterator j = vert.begin(); j != vert.end(); ++j) + { + const Geom::Vec3f& P = *j; + if (P[0]c) + c = (unsigned int)(P[0]); + if (P[1]>d) + d = (unsigned int)(P[1]); + } + + if (a>10) + a-=10; + if (b>10) + b-=10; + c+=10; + d+=10; + } +} + + void SVGOut::beginPoints() { -- GitLab