Commit cdcdc295 authored by Pierre Kraemer's avatar Pierre Kraemer
Browse files

Merge cgogn:~thery/CGoGN

parents 43efa6b8 f33a7c45
...@@ -244,12 +244,13 @@ void MyQT::cb_keyPress(int code) ...@@ -244,12 +244,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
...@@ -282,8 +285,31 @@ void MyQT::cb_keyPress(int keycode) ...@@ -282,8 +285,31 @@ void MyQT::cb_keyPress(int keycode)
} }
} }
break; break;
case 'b':
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;
} }
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">
......
...@@ -37,6 +37,8 @@ ...@@ -37,6 +37,8 @@
#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; } }
namespace CGoGN { namespace Utils { class ShaderColorPerVertex; } } namespace CGoGN { namespace Utils { class ShaderColorPerVertex; } }
...@@ -75,10 +77,17 @@ protected: ...@@ -75,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
*/ */
...@@ -217,6 +226,9 @@ public: ...@@ -217,6 +226,9 @@ public:
template <typename PFP> template <typename PFP>
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);
void svgout2D(const std::string& filename, const glm::mat4& model, const glm::mat4& proj);
}; };
// 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,6 +421,7 @@ Dart TopoRender::picking(typename PFP::MAP& map,int x, int y, const FunctorSelec ...@@ -422,6 +421,7 @@ Dart TopoRender::picking(typename PFP::MAP& map,int x, int y, const FunctorSelec
} }
}//end namespace GL2 }//end namespace GL2
}//end namespace Algo }//end namespace Algo
......
...@@ -22,178 +22,60 @@ ...@@ -22,178 +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_vertices3D; template <typename PFP>
Geom::Vec3f m_color; 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);
float m_width;
public:
void addVertex(const Geom::Vec3f& v);
void addVertex3D(const Geom::Vec3f& v);
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 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;
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);
};
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,215 +23,60 @@ ...@@ -23,215 +23,60 @@
*******************************************************************************/ *******************************************************************************/
#include "GL/glew.h"
#include "Algo/Geometry/centroid.h"
namespace CGoGN namespace CGoGN
{ {
namespace Algo namespace Algo
{ {
namespace Render namespace Render
{ {
namespace SVG namespace SVG
{ {
template <typename PFP> template <typename PFP>
void SVGOut::renderPointsToSVG(typename PFP::MAP& map, const typename PFP::TVEC3& position, const FunctorSelect& good, unsigned int thread) void renderVertices(Utils::SVG::SVGOut& svg, typename PFP::MAP& map, const typename PFP::TVEC3& position, const FunctorSelect& good, unsigned int thread)
{ {
glm::i32vec4 viewport; TraversorCell<typename PFP::MAP> trac(map,VERTEX,good);
glGetIntegerv(GL_VIEWPORT, &(viewport[0])); svg.beginPoints();
for (Dart d=trac.begin(); d!=trac.end(); d=trac.next())
SvgPoints* points = new SvgPoints(); svg.addPoint(position[d]);
points->setColor(global_color); svg.endPoints();
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<typename PFP::MAP> 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]));
}
} }
template <typename PFP> template <typename PFP>
void SVGOut::renderLinesToSVG(typename PFP::MAP& map, const typename PFP::TVEC3& position, const FunctorSelect& good, unsigned int thread) void renderVertices(Utils::SVG::SVGOut& svg, typename PFP::MAP& map, const typename PFP::TVEC3& position, const typename PFP::TVEC3& color, const FunctorSelect& good, unsigned int thread)
{ {
glm::i32vec4 viewport; TraversorCell<typename PFP::MAP> trac(map,VERTEX,good);