surface_render.h 6.5 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"
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),
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),
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;
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
};

Pierre Kraemer's avatar
Pierre Kraemer committed
63
class Surface_Render_Plugin : public PluginInteraction
Pierre Kraemer's avatar
Pierre Kraemer committed
64 65
{
	Q_OBJECT
66

Pierre Kraemer's avatar
Pierre Kraemer committed
67
	Q_INTERFACES(CGoGN::SCHNApps::Plugin)
Sylvain Thery's avatar
Sylvain Thery committed
68 69 70
#if CGOGN_QT_DESIRED_VERSION == 5
	Q_PLUGIN_METADATA(IID "CGoGN.SCHNapps.Plugin")
#endif
71

Pierre Kraemer's avatar
Pierre Kraemer committed
72
	friend class Surface_Render_DockTab;
Pierre Kraemer's avatar
Pierre Kraemer committed
73 74

public:
Pierre Kraemer's avatar
Pierre Kraemer committed
75
	Surface_Render_Plugin()
Pierre Kraemer's avatar
Pierre Kraemer committed
76 77
	{}

Pierre Kraemer's avatar
Pierre Kraemer committed
78
	~Surface_Render_Plugin()
Pierre Kraemer's avatar
Pierre Kraemer committed
79 80 81 82 83 84
	{}

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

85 86
	virtual void draw(View *view) {}
	virtual void drawMap(View* view, MapHandlerGen* map);
Pierre Kraemer's avatar
Pierre Kraemer committed
87

Sylvain Thery's avatar
Sylvain Thery committed
88 89 90 91 92 93
	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
94 95 96 97 98 99 100 101 102 103 104 105 106 107

	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);
108
	void selectedMapBoundingBoxModified();
Pierre Kraemer's avatar
Pierre Kraemer committed
109

110
	void schnappsClosing();
Sylvain Thery's avatar
Sylvain Thery committed
111

Pierre Kraemer's avatar
Pierre Kraemer committed
112 113
public slots:
	// slots for Python calls
Sylvain Thery's avatar
Sylvain Thery committed
114 115 116 117 118 119
	/**
	 * @brief change the position VBO use for rendering for specific view and map
	 * @param view the view name
	 * @param map the map name
	 * @param vbo the positionvbo name
	 */
Pierre Kraemer's avatar
Pierre Kraemer committed
120
	void changePositionVBO(const QString& view, const QString& map, const QString& vbo);
Sylvain Thery's avatar
Sylvain Thery committed
121 122 123 124 125 126 127

	/**
	 * @brief change the normal VBO use for rendering (phong) for specific view and map
	 * @param view the view name
	 * @param map the map name
	 * @param vbo the normal vbo name
	 */
Pierre Kraemer's avatar
Pierre Kraemer committed
128
	void changeNormalVBO(const QString& view, const QString& map, const QString& vbo);
Sylvain Thery's avatar
Sylvain Thery committed
129 130 131 132 133 134 135

	/**
	 * @brief change the color VBO use for rendering for specific view and map
	 * @param view the view name
	 * @param map the map name
	 * @param vbo the normal vbo name
	 */
136
	void changeColorVBO(const QString& view, const QString& map, const QString& vbo);
Sylvain Thery's avatar
Sylvain Thery committed
137 138 139 140 141 142 143

	/**
	 * @brief choice if vertices should be rendered (for specific view and map)
	 * @param view the view name
	 * @param map the map name
	 * @param b rendered or not
	 */
Pierre Kraemer's avatar
Pierre Kraemer committed
144
	void changeRenderVertices(const QString& view, const QString& map, bool b);
Sylvain Thery's avatar
Sylvain Thery committed
145 146 147 148 149 150 151

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

	/**
	 * @brief choice if edges should be rendered (for specific view and map)
	 * @param view the view name
	 * @param map the map name
	 * @param b rendered or not
	 */
Pierre Kraemer's avatar
Pierre Kraemer committed
160
	void changeRenderEdges(const QString& view, const QString& map, bool b);
Sylvain Thery's avatar
Sylvain Thery committed
161 162 163 164 165 166 167

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

	/**
	 * @brief change the style of rendering of faces (flat of phong)
	 * @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);

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

	/**
	 * @brief change the color use for face rendering (when no volor VBO is used)
	 * @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]
	 */
194
	void changeFaceColor(const QString& view, const QString& map, float r, float g, float b);
Sylvain Thery's avatar
Sylvain Thery committed
195 196 197 198 199 200 201 202 203

	/**
	 * @brief change the color use for edge line rendering.
	 * @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]
	 */
204
	void changeEdgeColor(const QString& view, const QString& map, float r, float g, float b);
Sylvain Thery's avatar
Sylvain Thery committed
205 206 207 208 209 210 211 212 213

	/**
	 * @brief change the color use for vertices point sprite rendering.
	 * @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]
	 */
214
	void changeVertexColor(const QString& view, const QString& map, float r, float g, float b);
Sylvain Thery's avatar
Sylvain Thery committed
215 216 217 218 219 220 221 222 223

	/**
	 * @brief change the color use for back-faces.
	 * @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]
	 */
224
	void changeBackColor(const QString& view, const QString& map, float r, float g, float b);
Sylvain Thery's avatar
Sylvain Thery committed
225 226 227 228 229 230 231

	/**
	 * @brief choose if back-faces should be rendered.
	 * @param view the view name
	 * @param map the map name
	 * @param b
	 */
232
	void changeRenderBackfaces(const QString& view, const QString& map, bool b);
233

234

Pierre Kraemer's avatar
Pierre Kraemer committed
235
protected:
Pierre Kraemer's avatar
Pierre Kraemer committed
236
	Surface_Render_DockTab* m_dockTab;
Pierre Kraemer's avatar
Pierre Kraemer committed
237 238 239 240
	QHash<View*, QHash<MapHandlerGen*, MapParameters> > h_viewParameterSet;

	CGoGN::Utils::ShaderFlat* m_flatShader;
	CGoGN::Utils::ShaderPhong* m_phongShader;
241
	CGoGN::Utils::ShaderColorPerVertex* m_colorPerVertexShader;
Pierre Kraemer's avatar
Pierre Kraemer committed
242 243
	CGoGN::Utils::ShaderSimpleColor* m_simpleColorShader;
	CGoGN::Utils::PointSprite* m_pointSprite;
Sylvain Thery's avatar
Sylvain Thery committed
244

Pierre Kraemer's avatar
Pierre Kraemer committed
245 246 247 248 249 250 251
};

} // namespace SCHNApps

} // namespace CGoGN

#endif