shaderIsoLines.h 3.78 KB
Newer Older
Sylvain Thery's avatar
Sylvain Thery committed
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
32
33
34
35
/*******************************************************************************
* CGoGN: Combinatorial and Geometric modeling with Generic N-dimensional Maps  *
* version 0.1                                                                  *
* Copyright (C) 2009-2012, 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.unistra.fr/                                           *
* Contact information: cgogn@unistra.fr                                        *
*                                                                              *
*******************************************************************************/

#ifndef __CGOGN_SHADER_ISO_LINES__
#define __CGOGN_SHADER_ISO_LINES__

#include "Utils/GLSLShader.h"
#include "Geometry/vector_gen.h"

namespace CGoGN
{

namespace Utils
{
Sylvain Thery's avatar
Sylvain Thery committed
36
37
38
39
/**
 * Shader to draw iso-lines on a triangles mesh.
 * Iso-line are computed on a data vertex attribute (float)
 */
Sylvain Thery's avatar
Sylvain Thery committed
40
41
42
class ShaderIsoLines : public GLSLShader
{
protected:
Sylvain Thery's avatar
Sylvain Thery committed
43
	/// shader sources
Sylvain Thery's avatar
Sylvain Thery committed
44
45
46
47
    static std::string vertexShaderText;
    static std::string fragmentShaderText;
    static std::string geometryShaderText;

Sylvain Thery's avatar
Sylvain Thery committed
48
    /// uniform locations
Sylvain Thery's avatar
Sylvain Thery committed
49
50
51
52
53
54
	CGoGNGLuint m_unif_colorMin;
	CGoGNGLuint m_unif_colorMax;
	CGoGNGLuint m_unif_vmin;
	CGoGNGLuint m_unif_vmax;
	CGoGNGLuint m_unif_vnb;

Sylvain Thery's avatar
Sylvain Thery committed
55
	// colors of iso-lines
Sylvain Thery's avatar
Sylvain Thery committed
56
57
	Geom::Vec4f m_colorMin;
	Geom::Vec4f m_colorMax;
Sylvain Thery's avatar
Sylvain Thery committed
58
59

	/// min/max of data attribute
Sylvain Thery's avatar
Sylvain Thery committed
60
61
	float m_vmin;
	float m_vmax;
Sylvain Thery's avatar
Sylvain Thery committed
62
63

	/// number of iso-line to draw
Sylvain Thery's avatar
Sylvain Thery committed
64
65
66
67
68
69
70
71
	int m_vnb;

	VBO* m_vboPos;
	VBO* m_vboData;

	void getLocations();

public:
Sylvain Thery's avatar
Sylvain Thery committed
72
73
74
75
	/**
	 * constructor
	 * @param max number of isolines drawable per triangle (as low as possible for performance)
	 */
Sylvain Thery's avatar
Sylvain Thery committed
76
77
	ShaderIsoLines(int maxNbIsoPerTriangle=6);

Sylvain Thery's avatar
Sylvain Thery committed
78
79
80
81
82
	/**
	 * set colors for min and max isoLine, interpolated between
//	 * @param colorMin color for minimum iso-line value
	 * @param colorMax color for maximum iso-line value
	 */
Sylvain Thery's avatar
Sylvain Thery committed
83
84
	void setColors(const Geom::Vec4f& colorMin, const Geom::Vec4f& colorMax);

Sylvain Thery's avatar
Sylvain Thery committed
85
86
87
88
89
90
	/**
	 * Set min and max value of used atribute
	 * @param attMin minimun of attribute
	 * @param attMax maximun of attribute
	 */

Sylvain Thery's avatar
Sylvain Thery committed
91
92
	void setDataBound(float attMin, float attMax);

Sylvain Thery's avatar
Sylvain Thery committed
93
94
95
	/**
	 * set the number of iso-lines (default is 32)
	 */
Sylvain Thery's avatar
Sylvain Thery committed
96
97
98
	void setNbIso(int nb);

	/**
Sylvain Thery's avatar
Sylvain Thery committed
99
100
101
102
103
104
105
106
	 * set max number of isolines per triangle
	 * If to small risk of missing lines
	 * if to big performance problem
	 */
	void setNbMaxIsoLinePerTriangle(int nb) { changeNbMaxVertices(2*nb); }

	/**
	 * Position attribute
Sylvain Thery's avatar
Sylvain Thery committed
107
108
109
110
	 */
	void setAttributePosition(VBO* vbo);

	/**
Sylvain Thery's avatar
Sylvain Thery committed
111
	 * Data attribute for iso-lines must be of type float
Sylvain Thery's avatar
Sylvain Thery committed
112
113
114
115
116
117
118
119
120
	 */
	void setAttributeData(VBO* vbo);
};

} // namespace Utils

} // namespace CGoGN

#endif