Création d'un compte pour un collaborateur extérieur au laboratoire depuis l'intranet ICube : https://intranet.icube.unistra.fr/fr/labs/member/profile

clippingShader.h 9.41 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
/*******************************************************************************
* CGoGN: Combinatorial and Geometric modeling with Generic N-dimensional Maps  *
* version 0.1                                                                  *
* Copyright (C) 2009-2011, IGG Team, LSIIT, University of Strasbourg           *
*                                                                              *
* 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.           *
*                                                                              *
* Web site: http://cgogn.u-strasbg.fr/                                         *
* Contact information: cgogn@unistra.fr                                        *
*                                                                              *
*******************************************************************************/

#ifndef _CGoGN_CLIPPINGSHADER_H_
#define _CGoGN_CLIPPINGSHADER_H_

#include "Utils/GLSLShader.h"
#include "Geometry/vector_gen.h"
#include "Utils/cgognStream.h"
#include "Utils/shaderMutator.h"
32
#include "Utils/drawer.h"
33
#include <string>
34
35
#include <sstream>
#include <vector>
36
37
38
39
40
41
42
43
44
45
46

namespace CGoGN
{

namespace Utils
{

class ClippingShader : public GLSLShader
{

public:
47
48
49
50
51
52

	/**
	 * enum used to choose which type of clip plane grid to display
	 */
	enum clipPlaneDisplayGridType { STRAIGHT_GRID, RADIAL_GRID };

53
54
55
56
57
	/**
	 * constructor
	 */
	ClippingShader();

58
59
60
61
62
	/**
	 * destructor
	 */
	~ClippingShader();

63
	/**
64
	 * set all parameters for one clip plane
65
	 * @warning planeIndex starts at 0
66
67
68
69
	 * @param vec1 first basis vector
	 * @param vec2 second basis vector
	 * @param origin point of the plane that will be used as origin to display it
	 * @param planeIndex index of the plane to modify
70
	 */
71
	void setClipPlane(Geom::Vec3f vec1, Geom::Vec3f vec2, Geom::Vec3f origin, int planeIndex = 0);
72
73

	/**
74
	 * set first vector for one clip plane
75
76
77
78
	 * @warning planeIndex starts at 0
	 * @param vec1 first basis vector
	 * @param planeIndex index of the plane to modify
	 */
79
	void setClipPlaneFirstVec(Geom::Vec3f vec1, int planeIndex = 0);
80
81

	/**
82
	 * set second vector for one clip plane
83
84
85
86
	 * @warning planeIndex starts at 0
	 * @param vec2 second basis vector
	 * @param planeIndex index of the plane to modify
	 */
87
	void setClipPlaneSecondVec(Geom::Vec3f vec2, int planeIndex = 0);
88
	
89
	/**
90
	 * set origin for one clip plane
91
	 * @warning planeIndex starts at 0
92
93
	 * @param origin point of the plane that will be used as origin to display it
	 * @param planeIndex index of the plane to modify
94
	 */
95
	void setClipPlaneOrigin(Geom::Vec3f origin, int planeIndex = 0);
96
97

	/**
98
	 * get first vector for one clip plane
99
100
	 * @warning planeIndex starts at 0
	 * @param planeIndex index of the plane to modify
101
	 */
102
	Geom::Vec3f getClipPlaneFirstVec(int planeIndex = 0);
103
104

	/**
105
	 * get second vector for one clip plane
106
107
108
	 * @warning planeIndex starts at 0
	 * @param planeIndex index of the plane to modify
	 */
109
	Geom::Vec3f getClipPlaneSecondVec(int planeIndex = 0);
110
111

	/**
112
	 * get origin for one clip plane
113
114
	 * @warning planeIndex starts at 0
	 * @param planeIndex index of the plane to modify
115
	 */
116
	Geom::Vec3f getClipPlaneOrigin(int planeIndex = 0);
117

118
119
	/**
	 * set the color attenuation factor for clipping
120
	 * @param colorAttenuationFactor color attenuation factor
121
	 */
122
	void setClipColorAttenuationFactor(float colorAttenuationFactor);
123

124
125
126
	/**
	 * get the color attenuation factor for clipping
	 */
127
	float getClipColorAttenuationFactor() { return m_colorAttenuationFactor; }
128

129
	/**
130
131
	 * set the clip planes count
	 * - inserts plane clipping instructions into vertex and fragment shader source code
132
	 * but does not modify the geometry shader source code
133
	 * @param planesCount the clip planes count to use
134
	 * @warning this function is designed for shaders which *do not* use a geometry shader
135
	 */
136
	void setClipPlanesCount(int planesCount);
137
	
138
	/**
139
	 * get the clip planes count
140
	 */
141
	int getClipPlanesCount() { return (int)m_clipPlanes.size(); }
142

143
	/**
144
	 * update uniforms (get their locations and send their values again) for clipping
145
146
147
	 */
	void updateClippingUniforms();

148
	/**
149
	 * display all clipping planes
150
	 */
151
	void displayClipPlanes();
152
153

	/**
154
155
156
	 * set the planes display color
	 * @param color the new color
	 */
157
	void setPlaneDisplayColor(Geom::Vec3f color) { m_clipPlanesDisplayColor = color; updateAllClippingPlanesVBOs(); }
158
159
160
161
162
163
164
165
166
167

	/**
	 * get the planes display color
	 */
	Geom::Vec3f getPlaneDisplayColor() { return m_clipPlanesDisplayColor; }

	/**
	 * set the planes display grids type
	 * @param gridType the new grid type
	 */
168
	void setPlaneDisplayType(clipPlaneDisplayGridType gridType) { m_clipPlanesDisplayType = gridType; updateAllClippingPlanesVBOs(); }
169
170
171
172
173
174
175
176
177
178

	/**
	 * get the planes display grids type
	 */
	clipPlaneDisplayGridType getPlaneDisplayType() { return m_clipPlanesDisplayType; }

	/**
	 * set the planes display grid x resolution
	 * @param res the new resolution
	 */
179
	void setPlaneDisplayXRes(size_t res) { m_clipPlanesDisplayXRes = res; updateAllClippingPlanesVBOs(); }
180
181
182
183
184
185
186
187
188
189

	/**
	 * get the planes display grid x resolution
	 */
	size_t getPlaneDisplayXRes() { return m_clipPlanesDisplayXRes; }

	/**
	 * set the planes display grid y resolution
	 * @param res the new resolution
	 */
190
	void setPlaneDisplayYRes(size_t res) { m_clipPlanesDisplayYRes = res; updateAllClippingPlanesVBOs(); }
191
192
193
194
195
196
197
198

	/**
	 * get the planes display grid y resolution
	 */
	size_t getPlaneDisplayYRes() { return m_clipPlanesDisplayYRes; }

	/**
	 * set the planes display size
199
200
	 * @param size the new size
	 */
201
	void setPlaneDisplaySize(float size) { m_clipPlanesDisplaySize = size;sendClippingPlanesUniform();updateAllClippingPlanesVBOs(); }
202
203

	/**
204
	 * get the planes display size
205
	 */
206
	float getPlaneDisplaySize() { return m_clipPlanesDisplaySize; }
207

208
209
210

private:

211
	/**
212
	 * clip planes structure
213
214
215
216
217
218
	 */
	struct clipPlane
	{
		Geom::Vec3f firstVec, secondVec, origin;
	};

219
	/**
220
	 * sends the clip planes arrays to shader
221
222
223
224
	 */
	void sendClippingPlanesUniform();

	/**
225
	 * sends the color attenuation factor to shader
226
227
228
	 */
	void sendColorAttenuationFactorUniform();

229
230
231
232
233
234
	/**
	 * update clip planes parameters arrays
	 * @param planeIndex index of the plane
	 */
	void updateClippingPlanesArrays(int planeIndex);

235
	/**
236
	 * update VBO for one plane
237
238
239
240
	 * @param planeIndex index of the plane
	 */
	void updateClippingPlaneVBO(int planeIndex);

241
242
243
244
245
	/**
	 * update VBOs for all planes
	 */
	void updateAllClippingPlanesVBOs();

246
247
	/**
	 * original vertex shader source code (without clipping)
248
249
250
251
	 */
	std::string originalVertShaderSrc;

	/**
252
	 * original fragment shader source code (without clipping)
253
254
255
	 */
	std::string originalFragShaderSrc;

256
	/**
257
	 * clip planes array
258
	 */
259
260
	std::vector<clipPlane> m_clipPlanes;

261
	/**
262
	 * clip planes equations array (size = 4*(planes count))
263
	 * - ** only used for sending planes data to shader **
264
	 */
265
	std::vector<float> m_clipPlanesEquations;
266

267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
	/**
	 * clip planes first vectors array (size = 3*(planes count))
	 * - ** only used for sending planes data to shader **
	 */
	std::vector<float> m_clipPlanesFirstVectors;

	/**
	 * clip planes second vectors array (size = 3*(planes count))
	 * - ** only used for sending planes data to shader **
	 */
	std::vector<float> m_clipPlanesSecondVectors;

	/**
	 * clip planes origins array (size = 3*(planes count))
	 * - ** only used for sending planes data to shader **
	 */
	std::vector<float> m_clipPlanesOrigins;

285
	/**
286
	 * clip planes equations vector uniform id
287
	 */
288
	GLint m_unif_clipPlanesEquations;
289
	
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
	/**
	 * clip planes first vectors uniform id
	 */
	GLint m_unif_clipPlanesFirstVectors;

	/**
	 * clip planes second vectors uniform id
	 */
	GLint m_unif_clipPlanesSecondVectors;

	/**
	 * clip planes origins uniform id
	 */
	GLint m_unif_clipPlanesOrigins;

	/**
	 * clip planes size uniform id
	 */
	GLint m_unif_clipPlanesDisplaySize;

310
311
312
313
314
315
316
317
318
319
	/**
	 * color attenuation factor
	 */
	float m_colorAttenuationFactor;
	
	/**
	 * color attenuation factor uniform id
	 */
	GLint m_unif_colorAttenuationFactor;

320
	/**
321
322
323
324
325
	 * clip planes drawers array
	 */
	std::vector<Drawer*> m_clipPlanesDrawers;

	/**
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
	 * clip planes display color
	 */
	Geom::Vec3f m_clipPlanesDisplayColor;

	/**
	 * clip planes display grid type
	 */
	clipPlaneDisplayGridType m_clipPlanesDisplayType;

	/**
	 * clip planes x grid display resolution
	 */
	size_t m_clipPlanesDisplayXRes;

	/**
	 * clip planes y grid display resolution
	 */
	size_t m_clipPlanesDisplayYRes;

	/**
	 * clip planes display size
347
	 */
348
	float m_clipPlanesDisplaySize;
349

350
351
352
353
354
	/**
	 * use advanced plane clipping ?
	 */
	bool m_useAdvancedPlaneClipping;

355
356
357
358
359
360
361
362
};


} // namespace Utils

} // namespace CGoGN

#endif