surface_render.h 6.83 KB
Newer Older
Pierre Kraemer's avatar
Pierre Kraemer committed
1 2 3 4 5 6 7 8
#ifndef _SURFACE_RENDER_PLUGIN_H_
#define _SURFACE_RENDER_PLUGIN_H_

#include "plugin_interaction.h"
#include "surface_render_dockTab.h"

#include "Utils/Shaders/shaderFlat.h"
#include "Utils/Shaders/shaderPhong.h"
Pierre Kraemer's avatar
Pierre Kraemer committed
9
#include "Utils/Shaders/shaderColorPerVertex.h"
Pierre Kraemer's avatar
Pierre Kraemer committed
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
#include "Utils/Shaders/shaderSimpleColor.h"
#include "Utils/pointSprite.h"

namespace CGoGN
{

namespace SCHNApps
{

class MapHandlerGen;

struct MapParameters
{
	enum FaceShadingStyle
	{
		FLAT = 0,
		PHONG = 1
	};

	MapParameters() :
		positionVBO(NULL),
		normalVBO(NULL),
Pierre Kraemer's avatar
Pierre Kraemer committed
32
		colorVBO(NULL),
Pierre Kraemer's avatar
Pierre Kraemer committed
33 34 35 36
		verticesScaleFactor(1.0f),
		renderVertices(false),
		renderEdges(false),
		renderFaces(true),
37
		faceStyle(FLAT),
Pierre Kraemer's avatar
Pierre Kraemer committed
38
		diffuseColor(0.85f,0.25f,0.19f,0.0f),
Sylvain Thery's avatar
Sylvain Thery committed
39
		simpleColor(0.0f,0.0f,0.0f,0.0f),
40 41
		vertexColor(0.0f,0.0f,1.0f,0.0f),
		backColor(0.85f, 0.25f, 0.19f, 0.0f)
Pierre Kraemer's avatar
Pierre Kraemer committed
42 43 44 45
	{}

	Utils::VBO* positionVBO;
	Utils::VBO* normalVBO;
Pierre Kraemer's avatar
Pierre Kraemer committed
46 47
	Utils::VBO* colorVBO;

Pierre Kraemer's avatar
Pierre Kraemer committed
48
	float verticesScaleFactor;
Sylvain Thery's avatar
Sylvain Thery committed
49
	float basePSradius;
Pierre Kraemer's avatar
Pierre Kraemer committed
50 51 52
	bool renderVertices;
	bool renderEdges;
	bool renderFaces;
53
	bool renderBoundary;
54
	bool renderBackfaces;
Pierre Kraemer's avatar
Pierre Kraemer committed
55
	FaceShadingStyle faceStyle;
56 57 58 59

	Geom::Vec4f diffuseColor;
	Geom::Vec4f simpleColor;
	Geom::Vec4f vertexColor;
60
	Geom::Vec4f backColor;
Pierre Kraemer's avatar
Pierre Kraemer committed
61 62
};

Sylvain Thery's avatar
Sylvain Thery committed
63
/**
Sylvain Thery's avatar
Sylvain Thery committed
64
* @brief Plugin for 2-Maps topology rendering.
Sylvain Thery's avatar
Sylvain Thery committed
65 66 67 68 69 70 71
* Some parameters are per view / per map:
* - drawing of relations and dart
* - colors
* Others are only per map:
* - position attribute
* - scale factors
*/
Pierre Kraemer's avatar
Pierre Kraemer committed
72
class Surface_Render_Plugin : public PluginInteraction
Pierre Kraemer's avatar
Pierre Kraemer committed
73 74
{
	Q_OBJECT
Pierre Kraemer's avatar
Pierre Kraemer committed
75

Pierre Kraemer's avatar
Pierre Kraemer committed
76
	Q_INTERFACES(CGoGN::SCHNApps::Plugin)
Sylvain Thery's avatar
Sylvain Thery committed
77 78 79
#if CGOGN_QT_DESIRED_VERSION == 5
	Q_PLUGIN_METADATA(IID "CGoGN.SCHNapps.Plugin")
#endif
Pierre Kraemer's avatar
Pierre Kraemer committed
80

Pierre Kraemer's avatar
Pierre Kraemer committed
81
	friend class Surface_Render_DockTab;
Pierre Kraemer's avatar
Pierre Kraemer committed
82 83

public:
Pierre Kraemer's avatar
Pierre Kraemer committed
84
	Surface_Render_Plugin()
Pierre Kraemer's avatar
Pierre Kraemer committed
85 86
	{}

Pierre Kraemer's avatar
Pierre Kraemer committed
87
	~Surface_Render_Plugin()
Pierre Kraemer's avatar
Pierre Kraemer committed
88 89 90 91 92 93
	{}

private:
	virtual bool enable();
	virtual void disable();

94 95
	virtual void draw(View *view) {}
	virtual void drawMap(View* view, MapHandlerGen* map);
Pierre Kraemer's avatar
Pierre Kraemer committed
96

Sylvain Thery's avatar
Sylvain Thery committed
97 98 99 100 101 102
	virtual void keyPress(View* , QKeyEvent* ) {}
	virtual void keyRelease(View* , QKeyEvent* ) {}
	virtual void mousePress(View* , QMouseEvent* ) {}
	virtual void mouseRelease(View* , QMouseEvent* ) {}
	virtual void mouseMove(View* , QMouseEvent* ) {}
	virtual void wheelEvent(View* , QWheelEvent* ) {}
Pierre Kraemer's avatar
Pierre Kraemer committed
103 104 105 106 107 108 109 110 111 112 113 114 115 116

	virtual void viewLinked(View *view) {}
	virtual void viewUnlinked(View *view) {}

private slots:
	// slots called from SCHNApps signals
	void selectedViewChanged(View* prev, View* cur);
	void selectedMapChanged(MapHandlerGen* prev, MapHandlerGen* cur);
	void mapAdded(MapHandlerGen* map);
	void mapRemoved(MapHandlerGen* map);

	// slots called from MapHandler signals
	void vboAdded(Utils::VBO* vbo);
	void vboRemoved(Utils::VBO* vbo);
117
	void selectedMapBoundingBoxModified();
Pierre Kraemer's avatar
Pierre Kraemer committed
118

119
	void schnappsClosing();
Sylvain Thery's avatar
Sylvain Thery committed
120

Pierre Kraemer's avatar
Pierre Kraemer committed
121 122
public slots:
	// slots for Python calls
Sylvain Thery's avatar
Sylvain Thery committed
123
	/**
Sylvain Thery's avatar
Sylvain Thery committed
124
	 * @brief [PYTHON] change the position VBO use for rendering for specific view and map
Sylvain Thery's avatar
Sylvain Thery committed
125 126 127 128
	 * @param view the view name
	 * @param map the map name
	 * @param vbo the positionvbo name
	 */
Pierre Kraemer's avatar
Pierre Kraemer committed
129
	void changePositionVBO(const QString& view, const QString& map, const QString& vbo);
Sylvain Thery's avatar
Sylvain Thery committed
130 131

	/**
Sylvain Thery's avatar
Sylvain Thery committed
132
	 * @brief [PYTHON] change the normal VBO use for rendering (phong) for specific view and map
Sylvain Thery's avatar
Sylvain Thery committed
133 134 135 136
	 * @param view the view name
	 * @param map the map name
	 * @param vbo the normal vbo name
	 */
Pierre Kraemer's avatar
Pierre Kraemer committed
137
	void changeNormalVBO(const QString& view, const QString& map, const QString& vbo);
Sylvain Thery's avatar
Sylvain Thery committed
138 139

	/**
Sylvain Thery's avatar
Sylvain Thery committed
140
	 * @brief [PYTHON] change the color VBO use for rendering for specific view and map
Sylvain Thery's avatar
Sylvain Thery committed
141 142 143 144
	 * @param view the view name
	 * @param map the map name
	 * @param vbo the normal vbo name
	 */
Pierre Kraemer's avatar
Pierre Kraemer committed
145
	void changeColorVBO(const QString& view, const QString& map, const QString& vbo);
Sylvain Thery's avatar
Sylvain Thery committed
146 147

	/**
Sylvain Thery's avatar
Sylvain Thery committed
148
	 * @brief [PYTHON] choice if vertices should be rendered (for specific view and map)
Sylvain Thery's avatar
Sylvain Thery committed
149 150 151 152
	 * @param view the view name
	 * @param map the map name
	 * @param b rendered or not
	 */
Pierre Kraemer's avatar
Pierre Kraemer committed
153
	void changeRenderVertices(const QString& view, const QString& map, bool b);
Sylvain Thery's avatar
Sylvain Thery committed
154 155

	/**
Sylvain Thery's avatar
Sylvain Thery committed
156
	 * @brief [PYTHON] change the size of vertices VerticesScaleFactor
Sylvain Thery's avatar
Sylvain Thery committed
157 158 159 160
	 * @param view the view name
	 * @param map the map name
	 * @param f scale parameter [0,2]
	 */
Pierre Kraemer's avatar
Pierre Kraemer committed
161
	void changeVerticesScaleFactor(const QString&view, const QString& map, float f);
Sylvain Thery's avatar
Sylvain Thery committed
162 163

	/**
Sylvain Thery's avatar
Sylvain Thery committed
164
	 * @brief [PYTHON] choice if edges should be rendered (for specific view and map)
Sylvain Thery's avatar
Sylvain Thery committed
165 166 167 168
	 * @param view the view name
	 * @param map the map name
	 * @param b rendered or not
	 */
Pierre Kraemer's avatar
Pierre Kraemer committed
169
	void changeRenderEdges(const QString& view, const QString& map, bool b);
Sylvain Thery's avatar
Sylvain Thery committed
170 171

	/**
Sylvain Thery's avatar
Sylvain Thery committed
172
	 * @brief [PYTHON] choice if faces should be rendered (for specific view and map)
Sylvain Thery's avatar
Sylvain Thery committed
173 174 175 176
	 * @param view the view name
	 * @param map the map name
	 * @param b rendered or not
	 */
Pierre Kraemer's avatar
Pierre Kraemer committed
177
	void changeRenderFaces(const QString& view, const QString& map, bool b);
Sylvain Thery's avatar
Sylvain Thery committed
178 179

	/**
Sylvain Thery's avatar
Sylvain Thery committed
180
	 * @brief [PYTHON] change the style of rendering of faces (flat of phong)
Sylvain Thery's avatar
Sylvain Thery committed
181 182 183 184 185 186 187
	 * @param view the view name
	 * @param map the map name
	 * @param style 0:flat 1:phong
	 */
	void changeFacesStyle(const QString& view, const QString& map, int style);

	/**
Sylvain Thery's avatar
Sylvain Thery committed
188
	 * @brief [PYTHON] choose if boundary should be rendered or not.
Sylvain Thery's avatar
Sylvain Thery committed
189 190 191 192
	 * @param view the view name
	 * @param map the map name
	 * @param b rendered or not
	 */
193
	void changeRenderBoundary(const QString& view, const QString& map, bool b);
Sylvain Thery's avatar
Sylvain Thery committed
194 195

	/**
Sylvain Thery's avatar
Sylvain Thery committed
196
	 * @brief [PYTHON] change the color use for face rendering (when no volor VBO is used)
Sylvain Thery's avatar
Sylvain Thery committed
197 198 199 200 201 202
	 * @param view the view name
	 * @param map the map name
	 * @param r red value [0,1]
	 * @param g green value [0,1]
	 * @param b blue value [0,1]
	 */
203
	void changeFaceColor(const QString& view, const QString& map, float r, float g, float b);
Sylvain Thery's avatar
Sylvain Thery committed
204 205

	/**
Sylvain Thery's avatar
Sylvain Thery committed
206
	 * @brief [PYTHON] change the color use for edge line rendering.
Sylvain Thery's avatar
Sylvain Thery committed
207 208 209 210 211 212
	 * @param view the view name
	 * @param map the map name
	 * @param r red value [0,1]
	 * @param g green value [0,1]
	 * @param b blue value [0,1]
	 */
213
	void changeEdgeColor(const QString& view, const QString& map, float r, float g, float b);
Sylvain Thery's avatar
Sylvain Thery committed
214 215

	/**
Sylvain Thery's avatar
Sylvain Thery committed
216
	 * @brief [PYTHON] change the color use for vertices point sprite rendering.
Sylvain Thery's avatar
Sylvain Thery committed
217 218 219 220 221 222
	 * @param view the view name
	 * @param map the map name
	 * @param r red value [0,1]
	 * @param g green value [0,1]
	 * @param b blue value [0,1]
	 */
223
	void changeVertexColor(const QString& view, const QString& map, float r, float g, float b);
Sylvain Thery's avatar
Sylvain Thery committed
224 225

	/**
Sylvain Thery's avatar
Sylvain Thery committed
226
	 * @brief [PYTHON] change the color use for back-faces.
Sylvain Thery's avatar
Sylvain Thery committed
227 228 229 230 231 232
	 * @param view the view name
	 * @param map the map name
	 * @param r red value [0,1]
	 * @param g green value [0,1]
	 * @param b blue value [0,1]
	 */
233
	void changeBackColor(const QString& view, const QString& map, float r, float g, float b);
Sylvain Thery's avatar
Sylvain Thery committed
234 235

	/**
Sylvain Thery's avatar
Sylvain Thery committed
236
	 * @brief [PYTHON] choose if back-faces should be rendered.
Sylvain Thery's avatar
Sylvain Thery committed
237 238 239 240
	 * @param view the view name
	 * @param map the map name
	 * @param b
	 */
241
	void changeRenderBackfaces(const QString& view, const QString& map, bool b);
242

243

Pierre Kraemer's avatar
Pierre Kraemer committed
244
protected:
Pierre Kraemer's avatar
Pierre Kraemer committed
245
	Surface_Render_DockTab* m_dockTab;
Pierre Kraemer's avatar
Pierre Kraemer committed
246 247 248 249
	QHash<View*, QHash<MapHandlerGen*, MapParameters> > h_viewParameterSet;

	CGoGN::Utils::ShaderFlat* m_flatShader;
	CGoGN::Utils::ShaderPhong* m_phongShader;
Pierre Kraemer's avatar
Pierre Kraemer committed
250
	CGoGN::Utils::ShaderColorPerVertex* m_colorPerVertexShader;
Pierre Kraemer's avatar
Pierre Kraemer committed
251 252
	CGoGN::Utils::ShaderSimpleColor* m_simpleColorShader;
	CGoGN::Utils::PointSprite* m_pointSprite;
Sylvain Thery's avatar
Sylvain Thery committed
253

Pierre Kraemer's avatar
Pierre Kraemer committed
254 255 256 257 258 259 260
};

} // namespace SCHNApps

} // namespace CGoGN

#endif