mapSVGRender.h 5.14 KB
Newer Older
1
2
3
/*******************************************************************************
* CGoGN: Combinatorial and Geometric modeling with Generic N-dimensional Maps  *
* version 0.1                                                                  *
4
* Copyright (C) 2009-2011, IGG Team, LSIIT, University of Strasbourg           *
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
*                                                                              *
* This library is free software; you can redistribute it and/or modify it      *
* under the terms of the GNU Lesser General Public License as published by the *
* Free Software Foundation; either version 2.1 of the License, or (at your     *
* option) any later version.                                                   *
*                                                                              *
* This library is distributed in the hope that it will be useful, but WITHOUT  *
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or        *
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License  *
* for more details.                                                            *
*                                                                              *
* You should have received a copy of the GNU Lesser General Public License     *
* along with this library; if not, write to the Free Software Foundation,      *
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA.           *
*                                                                              *
20
* Web site: http://cgogn.u-strasbg.fr/                                         *
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
* Contact information: cgogn@unistra.fr                                        *
*                                                                              *
*******************************************************************************/

#ifndef _MAP_SVG_RENDER
#define _MAP_SVG_RENDER

#include <vector>
#include <fstream>
#include <sstream>

#include "Geometry/vector_gen.h"
#include "Topology/generic/functor.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 Algo
{

namespace Render
{

namespace SVG
{

class SvgObj
{
protected:
Sylvain Thery's avatar
Sylvain Thery committed
65
	std::vector<Geom::Vec3f> m_vertices;
66
	std::vector<Geom::Vec3f> m_vertices3D;
67
	Geom::Vec3f m_color;
Sylvain Thery's avatar
Sylvain Thery committed
68
	float m_width;
69
public:
Sylvain Thery's avatar
Sylvain Thery committed
70
71
	void addVertex(const Geom::Vec3f& v);

72
73
	void addVertex3D(const Geom::Vec3f& v);

Sylvain Thery's avatar
Sylvain Thery committed
74
75
76
77
78
79
	void setColor(const Geom::Vec3f& c);

	void setWidth(float w) { m_width=w;}

	void close();

80
	virtual void save(std::ofstream& out)=0;
Sylvain Thery's avatar
Sylvain Thery committed
81

82
	unsigned int nbv() const { return m_vertices3D.size();}
Sylvain Thery's avatar
Sylvain Thery committed
83

84
	const Geom::Vec3f& P(unsigned int i) const  { return m_vertices3D[i];}
Sylvain Thery's avatar
Sylvain Thery committed
85
86
87

	Geom::Vec3f normal();

88
89
};

Sylvain Thery's avatar
Sylvain Thery committed
90
class SvgPoints: public SvgObj
91
{
Sylvain Thery's avatar
Sylvain Thery committed
92
93
94
public:
	void save(std::ofstream& out);
};
95
96


Sylvain Thery's avatar
Sylvain Thery committed
97
98
class SvgPolyline: public SvgObj
{
Sylvain Thery's avatar
Sylvain Thery committed
99
public:
100
101
102
103
	void save(std::ofstream& out);
};


Sylvain Thery's avatar
Sylvain Thery committed
104
class SvgPolygon: public SvgObj
105
106
{
protected:
Sylvain Thery's avatar
Sylvain Thery committed
107
	Geom::Vec3f m_colorFill;
108
public:
Sylvain Thery's avatar
Sylvain Thery committed
109
110
111
112

	void setColorFill(const Geom::Vec3f& c);

	void save(std::ofstream& out);
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
};


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 = SelectorTrue(), unsigned int thread=0);

	template <typename PFP>
	void renderFacesToSVG(typename PFP::MAP& map, const typename PFP::TVEC3& position, float shrink, const FunctorSelect& good = SelectorTrue(), unsigned int thread=0);

Sylvain Thery's avatar
Sylvain Thery committed
158
159
160
161
	template <typename PFP>
	void renderPointsToSVG(typename PFP::MAP& map, const typename PFP::TVEC3& position, const FunctorSelect& good = SelectorTrue(), unsigned int thread=0);


162
	void orderPrimitives(std::list<SvgObj*>& primitives);
163
164
165
};


Sylvain Thery's avatar
Sylvain Thery committed
166
167
struct compSvgObj
{
168
169
170
171
172
173
174
	int points_plane (SvgPolygon* pol_points, SvgPolygon* pol_plane, float& averageZ);
	bool operator() (SvgObj* a, SvgObj*b);
};

struct compNormObj
{
//	int points_plane (SvgPolygon* pol_points, SvgPolygon* pol_plane);
Sylvain Thery's avatar
Sylvain Thery committed
175
176
177
	bool operator() (SvgObj* a, SvgObj*b);
};

178
179
180
181
182
183
184
185
186
187
188
189
//
//class BSP_SVG
//{
//protected:
//	std::list<BSP_SVG*> m_front;
//	std::list<BSP_SVG*> m_back;
//	std::list<BSP_SVG*> m_intersect;
//	SvgObj* m_obj;
//
//public:
//	void insert(SvgObj*)
//};
Sylvain Thery's avatar
Sylvain Thery committed
190
191


192
193
194
195
196
197
198
199
200

} // namespace SVG
} // namespace Render
} // namespace Algo
} // namespace CGoGN

#include "Algo/Render/SVG/mapSVGRender.hpp"

#endif