Commit f33a7c45 authored by Sylvain Thery's avatar Sylvain Thery

cleaning svg rendering & update usage

parent a2b1046d
...@@ -242,12 +242,13 @@ void MyQT::cb_keyPress(int code) ...@@ -242,12 +242,13 @@ void MyQT::cb_keyPress(int code)
{ {
if (code == 's') if (code == 's')
{ {
std::string filename = selectFileSave("Export SVG file "); std::string filename = selectFileSave("Export SVG file ",".","(*.svg)");
CGoGNout << "Exporting "<<filename<<CGoGNendl; Utils::SVG::SVGOut svg(filename,modelViewMatrix(),projectionMatrix());
Algo::Render::SVG::SVGOut svg(filename,modelViewMatrix(),projectionMatrix()); svg.setWidth(1.0f);
// svg.renderLinesToSVG<PFP>(myMap,position); svg.setColor(Geom::Vec3f(0.0f,0.0f,0.5f));
svg.setColor(Geom::Vec3f(1.,0.,0.)); Algo::Render::SVG::renderEdges<PFP>(svg,myMap,position);
svg.renderFacesToSVG<PFP>(myMap,position,0.8f); svg.setWidth(5.0f);
Algo::Render::SVG::renderVertices<PFP>(svg,myMap,position);
//svg destruction close the file //svg destruction close the file
} }
if (code == 't') if (code == 't')
......
...@@ -38,7 +38,8 @@ int main(int argc, char **argv) ...@@ -38,7 +38,8 @@ int main(int argc, char **argv)
sqt.setDock(& sqt.dock); sqt.setDock(& sqt.dock);
sqt.setCallBack( sqt.dock.listOper, SIGNAL(currentRowChanged(int)), SLOT(operation(int)) ); sqt.setCallBack( sqt.dock.listOper, SIGNAL(currentRowChanged(int)), SLOT(operation(int)) );
sqt.setCallBack( sqt.dock.svg, SIGNAL(clicked()), SLOT(svg()) );
sqt.setCallBack( sqt.dock.widthSlider, SIGNAL(valueChanged(int)), SLOT(width(int)) );
int n=3; int n=3;
if (argc==2) if (argc==2)
n = atoi(argv[1]); n = atoi(argv[1]);
...@@ -46,6 +47,8 @@ int main(int argc, char **argv) ...@@ -46,6 +47,8 @@ int main(int argc, char **argv)
// example code itself // example code itself
sqt.createMap(n); sqt.createMap(n);
sqt.width(5);
// set help message in menu // set help message in menu
sqt.setHelpMsg("First Tuto: \nCreate two faces\nsew them\nand affect positions"); sqt.setHelpMsg("First Tuto: \nCreate two faces\nsew them\nand affect positions");
// final show for redraw // final show for redraw
...@@ -283,11 +286,30 @@ void MyQT::cb_keyPress(int keycode) ...@@ -283,11 +286,30 @@ void MyQT::cb_keyPress(int keycode)
} }
break; break;
case 's': case 'b':
m_render_topo->svgout<PFP>(myMap, "/tmp/toto.svg", modelViewMatrix(),projectionMatrix(),nb); for (Dart d=myMap.begin(); d!=myMap.end(); myMap.next(d))
{
if (!myMap.isBoundaryMarked(d))
{
colorDarts[d] = Geom::Vec3f(0.0f,0.0f,0.0f);
m_render_topo->setDartColor(d,0.0f,0.0f,0.0f);
}
}
break; break;
} }
updateGL();
}
void MyQT::svg()
{
std::string filename = selectFileSave("snapshot file", ".", "(*.svg)");
m_render_topo->svgout2D(filename, modelViewMatrix(),projectionMatrix());
}
void MyQT::width(int w)
{
m_render_topo->setDartWidth(w);
m_render_topo->setRelationWidth(w);
updateGL(); updateGL();
} }
...@@ -105,6 +105,8 @@ public: ...@@ -105,6 +105,8 @@ public:
public slots: public slots:
void operation(int x); void operation(int x);
void svg();
void width(int w);
}; };
......
...@@ -96,6 +96,29 @@ ...@@ -96,6 +96,29 @@
</item> </item>
</widget> </widget>
</item> </item>
<item>
<widget class="QSlider" name="widthSlider">
<property name="minimum">
<number>1</number>
</property>
<property name="maximum">
<number>10</number>
</property>
<property name="value">
<number>5</number>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="svg">
<property name="text">
<string>SnapshotSVG</string>
</property>
</widget>
</item>
<item> <item>
<spacer name="verticalSpacer"> <spacer name="verticalSpacer">
<property name="orientation"> <property name="orientation">
......
...@@ -36,7 +36,8 @@ ...@@ -36,7 +36,8 @@
#include "Geometry/vector_gen.h" #include "Geometry/vector_gen.h"
#include "Utils/vbo.h" #include "Utils/vbo.h"
#include "Algo/Render/SVG/mapSVGRender.h"
#include "Utils/svg.h"
// forward // forward
namespace CGoGN { namespace Utils { class ShaderSimpleColor; } } namespace CGoGN { namespace Utils { class ShaderSimpleColor; } }
...@@ -76,10 +77,17 @@ protected: ...@@ -76,10 +77,17 @@ protected:
*/ */
GLuint m_nbDarts; GLuint m_nbDarts;
/**
* number of relations 1 to draw
*/
GLuint m_nbRel1;
/** /**
* number of relations 2 to draw * number of relations 2 to draw
*/ */
GLuint m_nbRel2; GLuint m_nbRel2;
/** /**
* width of lines use to draw darts * width of lines use to draw darts
*/ */
...@@ -220,8 +228,7 @@ public: ...@@ -220,8 +228,7 @@ public:
void updateDataGMap(typename PFP::MAP& map, const typename PFP::TVEC3& positions, float ke, float kf, const FunctorSelect& good = allDarts); void updateDataGMap(typename PFP::MAP& map, const typename PFP::TVEC3& positions, float ke, float kf, const FunctorSelect& good = allDarts);
template<typename PFP> void svgout2D(const std::string& filename, const glm::mat4& model, const glm::mat4& proj);
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 // just for compatibility with old code
......
...@@ -139,9 +139,9 @@ void TopoRender::updateDataMap(typename PFP::MAP& mapx, const typename PFP::TVEC ...@@ -139,9 +139,9 @@ void TopoRender::updateDataMap(typename PFP::MAP& mapx, const typename PFP::TVEC
m_attIndex[d] = indexDC; m_attIndex[d] = indexDC;
indexDC+=2; indexDC+=2;
*positionDartBuf++ = P; *positionDartBuf++ = P;
*colorDartBuf++ = m_dartsColor;
*positionDartBuf++ = Q; *positionDartBuf++ = Q;
*colorDartBuf++ = m_dartsColor; *colorDartBuf++ = m_dartsColor;
*colorDartBuf++ = m_dartsColor;
VEC3 f = P*0.5f + Q*0.5f; VEC3 f = P*0.5f + Q*0.5f;
fv2[d] = f; fv2[d] = f;
f = P*0.1f + Q*0.9f; f = P*0.1f + Q*0.9f;
...@@ -172,7 +172,6 @@ void TopoRender::updateDataMap(typename PFP::MAP& mapx, const typename PFP::TVEC ...@@ -172,7 +172,6 @@ void TopoRender::updateDataMap(typename PFP::MAP& mapx, const typename PFP::TVEC
VEC3* positionF2 = reinterpret_cast<VEC3*>(PositionBuffer2); VEC3* positionF2 = reinterpret_cast<VEC3*>(PositionBuffer2);
m_nbRel2 =0; m_nbRel2 =0;
for(std::vector<Dart>::iterator id = vecDarts.begin(); id!= vecDarts.end(); id++) for(std::vector<Dart>::iterator id = vecDarts.begin(); id!= vecDarts.end(); id++)
{ {
Dart d = *id; Dart d = *id;
...@@ -191,6 +190,7 @@ void TopoRender::updateDataMap(typename PFP::MAP& mapx, const typename PFP::TVEC ...@@ -191,6 +190,7 @@ void TopoRender::updateDataMap(typename PFP::MAP& mapx, const typename PFP::TVEC
*positionF1++ = fv1[d]; *positionF1++ = fv1[d];
*positionF1++ = fv11[e]; *positionF1++ = fv11[e];
} }
m_nbRel1 = vecDarts.size()/2;
m_vbo1->bind(); m_vbo1->bind();
glUnmapBuffer(GL_ARRAY_BUFFER); glUnmapBuffer(GL_ARRAY_BUFFER);
...@@ -225,6 +225,8 @@ void TopoRender::updateDataGMap(typename PFP::MAP& mapx, const typename PFP::TVE ...@@ -225,6 +225,8 @@ void TopoRender::updateDataGMap(typename PFP::MAP& mapx, const typename PFP::TVE
} }
m_nbDarts = vecDarts.size(); m_nbDarts = vecDarts.size();
// debut phi1 // debut phi1
AutoAttributeHandler<VEC3> fv1(map, DART); AutoAttributeHandler<VEC3> fv1(map, DART);
// fin phi1 // fin phi1
...@@ -333,15 +335,11 @@ void TopoRender::updateDataGMap(typename PFP::MAP& mapx, const typename PFP::TVE ...@@ -333,15 +335,11 @@ void TopoRender::updateDataGMap(typename PFP::MAP& mapx, const typename PFP::TVE
VEC3* positionF1 = reinterpret_cast<VEC3*>(PositionBuffer1); VEC3* positionF1 = reinterpret_cast<VEC3*>(PositionBuffer1);
VEC3* positionF2 = reinterpret_cast<VEC3*>(PositionBuffer2); VEC3* positionF2 = reinterpret_cast<VEC3*>(PositionBuffer2);
m_nbRel2 =0; m_nbRel2 = 0;
for(std::vector<Dart>::iterator id = vecDarts.begin(); id!= vecDarts.end(); id++) for(std::vector<Dart>::iterator id = vecDarts.begin(); id!= vecDarts.end(); id++)
{ {
Dart d = *id; Dart d = *id;
Dart e = map.beta2(d); Dart e = map.beta2(d);
// if (good(e) && (e.index > d.index))
if (good(e) && (d < e )) if (good(e) && (d < e ))
{ {
*positionF2++ = fv2[d]; *positionF2++ = fv2[d];
...@@ -353,6 +351,7 @@ void TopoRender::updateDataGMap(typename PFP::MAP& mapx, const typename PFP::TVE ...@@ -353,6 +351,7 @@ void TopoRender::updateDataGMap(typename PFP::MAP& mapx, const typename PFP::TVE
*positionF1++ = fv1[d]; *positionF1++ = fv1[d];
*positionF1++ = fv1[e]; *positionF1++ = fv1[e];
} }
m_nbRel1 = vecDarts.size()/2;
m_vbo1->bind(); m_vbo1->bind();
glUnmapBuffer(GL_ARRAY_BUFFER); glUnmapBuffer(GL_ARRAY_BUFFER);
...@@ -422,80 +421,6 @@ Dart TopoRender::picking(typename PFP::MAP& map,int x, int y, const FunctorSelec ...@@ -422,80 +421,6 @@ Dart TopoRender::picking(typename PFP::MAP& map,int x, int y, const FunctorSelec
} }
template<typename PFP>
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<typename PFP::VEC3*>(glMapBuffer(GL_ARRAY_BUFFER, GL_READ_ONLY));
svg.beginLines();
for (unsigned int i=0; i<m_nbRel2; ++i)
svg.addLine(ptr[2*i], ptr[2*i+1],Geom::Vec3f(1.0f,0.0f,0.0f));
svg.endLines();
m_vbo2->bind();
glUnmapBuffer(GL_ARRAY_BUFFER);
//PHI1
m_vbo1->bind();
ptr = reinterpret_cast<typename PFP::VEC3*>(glMapBuffer(GL_ARRAY_BUFFER, GL_READ_ONLY));
svg.beginLines();
for (unsigned int i=0; i<m_nbDarts; ++i)
svg.addLine(ptr[2*i], ptr[2*i+1],Geom::Vec3f(0.0f,1.0f,1.0f));
svg.endLines();
m_vbo1->bind();
glUnmapBuffer(GL_ARRAY_BUFFER);
m_vbo0->bind();
ptr= reinterpret_cast<typename PFP::VEC3*>(glMapBuffer(GL_ARRAY_BUFFER, GL_READ_ONLY));
m_vbo3->bind();
Geom::Vec3f* colorsPtr = reinterpret_cast<typename PFP::VEC3*>(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 }//end namespace GL2
......
...@@ -22,211 +22,60 @@ ...@@ -22,211 +22,60 @@
* * * *
*******************************************************************************/ *******************************************************************************/
#ifndef _MAP_SVG_RENDER #ifndef _MAP_SVG_RENDER_
#define _MAP_SVG_RENDER #define _MAP_SVG_RENDER_
#include <vector> #include <vector>
#include <fstream> #include <fstream>
#include <sstream> #include <sstream>
#include "Geometry/vector_gen.h" #include "Utils/svg.h"
#include "Topology/generic/functor.h" #include "Topology/generic/traversorCell.h"
#include "Topology/generic/dartmarker.h"
#include "glm/gtc/matrix_transform.hpp"
#include "glm/gtc/type_precision.hpp"
#include "glm/glm.hpp"
#include "glm/gtc/matrix_projection.hpp"
#include "glm/gtc/matrix_transform.hpp"
/**
* A set of functions that allow the creation of rendering
* object using Vertex-Buffer-Object.
* Function are made for dual-2-map and can be used on
* any subset of a dual-N-map which is a 2-map
*/
namespace CGoGN namespace CGoGN
{ {
namespace Algo namespace Algo
{ {
namespace Render namespace Render
{ {
namespace SVG namespace SVG
{ {
/**
* render vertices in a SVGOut
* @warning no depth ordering
*/
template <typename PFP>
void renderVertices(Utils::SVG::SVGOut& svg, typename PFP::MAP& map, const typename PFP::TVEC3& position, const FunctorSelect& good=allDarts, unsigned int thread=0);
class SvgObj /**
{ * render colored vertices in a SVGOut
protected: * @warning no depth ordering
std::vector<Geom::Vec3f> m_vertices; */
std::vector<Geom::Vec3f> m_colors; template <typename PFP>
std::vector<Geom::Vec3f> m_vertices3D; void renderVertices(Utils::SVG::SVGOut& svg, typename PFP::MAP& map, const typename PFP::TVEC3& position, const typename PFP::TVEC3& color, const FunctorSelect& good=allDarts, unsigned int thread=0);
Geom::Vec3f m_color;
float m_width;
public:
void addVertex(const Geom::Vec3f& v);
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;}
void close();
virtual void save(std::ofstream& out)=0;
unsigned int nbv() const { return m_vertices3D.size();}
const Geom::Vec3f& P(unsigned int i) const { return m_vertices3D[i];}
Geom::Vec3f normal();
};
class SvgPoints: public SvgObj
{
public:
void save(std::ofstream& out);
};
class SvgPolyline: public SvgObj
{
public:
void save(std::ofstream& out);
};
class SvgLines: public SvgObj
{
public:
void save(std::ofstream& out);
};
class SvgPolygon: public SvgObj
{
protected:
Geom::Vec3f m_colorFill;
public:
void setColorFill(const Geom::Vec3f& c);
void save(std::ofstream& out);
};
class SVGOut
{
protected:
std::ofstream* m_out;
const glm::mat4& m_model;
const glm::mat4& m_proj;
glm::i32vec4 m_viewport;
Geom::Vec3f global_color;
float global_width;
std::vector<SvgObj*> m_objs;
SvgObj* m_current;
public:
/**
* Object that allow the rendering/exporting in svg file
* @param filename file name ended by .svg
* @param model the modelview matrix
* @param proj the projection matrix
*/
SVGOut(const std::string& filename, const glm::mat4& model, const glm::mat4& proj);
/**
* destructor
* flush and close the file
*/
~SVGOut();
void setColor(const Geom::Vec3f& col);
void setWidth(float w);
void closeFile();
template <typename PFP>
void renderLinesToSVG(typename PFP::MAP& map, const typename PFP::TVEC3& position, const FunctorSelect& good = allDarts, unsigned int thread=0);
template <typename PFP>
void renderFacesToSVG(typename PFP::MAP& map, const typename PFP::TVEC3& position, float shrink, bool cull = false, const FunctorSelect& good = allDarts, unsigned int thread=0);
template <typename PFP>
void renderPointsToSVG(typename PFP::MAP& map, const typename PFP::TVEC3& position, const FunctorSelect& good = allDarts, unsigned int thread=0);
void orderPrimitives(std::list<SvgObj*>& 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);
};
struct compSvgObj /**
{ * render edges in a SVGOut
int points_plane (SvgPolygon* pol_points, SvgPolygon* pol_plane, float& averageZ); * @warning no depth ordering
bool operator() (SvgObj* a, SvgObj*b); */
}; template <typename PFP>
void renderEdges(Utils::SVG::SVGOut& svg, typename PFP::MAP& map, const typename PFP::TVEC3& position, const FunctorSelect& good=allDarts, unsigned int thread=0);
struct compNormObj
{
// int points_plane (SvgPolygon* pol_points, SvgPolygon* pol_plane);
bool operator() (SvgObj* a, SvgObj*b);
};
// /**
//class BSP_SVG * render colored edges in a SVGOut
//{ * @warning no depth ordering
//protected: */
// std::list<BSP_SVG*> m_front; template <typename PFP>
// std::list<BSP_SVG*> m_back; void renderEdges(Utils::SVG::SVGOut& svg, typename PFP::MAP& map, const typename PFP::TVEC3& position, const typename PFP::TVEC3& color, const FunctorSelect& good=allDarts, unsigned int thread=0);
// std::list<BSP_SVG*> m_intersect;
// SvgObj* m_obj;
//
//public:
// void insert(SvgObj*)
//};
} // namespace SVG }
} // namespace Render }
} // namespace Algo }
} // namespace CGoGN }
#include "Algo/Render/SVG/mapSVGRender.hpp" #include "Algo/Render/SVG/mapSVGRender.hpp"
......
...@@ -23,123 +23,60 @@ ...@@ -23,123 +23,60 @@
*******************************************************************************/ *******************************************************************************/