mapSVGRender.hpp 8.46 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
* Contact information: cgogn@unistra.fr                                        *
*                                                                              *
*******************************************************************************/


#include "GL/glew.h"
#include "Algo/Geometry/centroid.h"

namespace CGoGN
{

namespace Algo
{

namespace Render
{

namespace SVG
{

Sylvain Thery's avatar
Sylvain Thery committed
41
42
43
44
45
46
47
48
49

template <typename PFP>
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);
Sylvain Thery's avatar
Sylvain Thery committed
50
	points->setWidth(global_width);
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
//	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())
Sylvain Thery's avatar
Sylvain Thery committed
68
	{
69
70
71
72
		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]));
Sylvain Thery's avatar
Sylvain Thery committed
73
74
75
76
	}
}


77
78
79
80
81
82
template <typename PFP>
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]));

83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
//	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<typename PFP::MAP> trav(map,good,thread);

	for(Dart d = trav.begin(); d != trav.end(); d=trav.next())
114
	{
115
116
117
		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);
118

119
120
121
		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);
122

123
124
125
		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]));
126

127
128
		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]));
129

130
131
132
		pol->setColor(global_color);
		pol->setWidth(global_width);
		m_objs.push_back(pol);
133
134
135
136
137
	}
}


template <typename PFP>
138
void SVGOut::renderFacesToSVG(typename PFP::MAP& map, const typename PFP::TVEC3& position, float shrink, bool cull, const FunctorSelect& good, unsigned int thread)
139
140
141
142
{
	glm::i32vec4 viewport;
	glGetIntegerv(GL_VIEWPORT, &(viewport[0]));

143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
//	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<PFP>(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<typename PFP::MAP> trav(map,good,thread);

	for(Dart d = trav.begin(); d != trav.end(); d=trav.next())
192
	{
193
194
		bool cullFace=false;
		if (cull)
195
		{
196
			const Geom::Vec3f& P = position[d];
197

198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
			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<PFP>(map,d,position);
			SvgPolygon* pol = new SvgPolygon();
			Dart dd = d;
			do
214
			{
215
216
217
218
219
220
221
222
223
224
225
226
227
				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);
228
229
		}
	}
230

231
232
233
234
235
236
237
}


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