mapHandler.h 8.67 KB
Newer Older
Pierre Kraemer's avatar
Pierre Kraemer committed
1
2
3
4
5
6
7
8
#ifndef _MAPHANDLER_H_
#define _MAPHANDLER_H_

#include <QString>

#include "types.h"
#include "view.h"
#include "plugin.h"
Pierre Kraemer's avatar
Pierre Kraemer committed
9
#include "cellSelector.h"
Pierre Kraemer's avatar
Pierre Kraemer committed
10
11
12
13

#include "Topology/generic/genericmap.h"
#include "Topology/generic/functor.h"
#include "Topology/generic/attributeHandler.h"
14

15
#include "Utils/drawer.h"
16

Pierre Kraemer's avatar
Pierre Kraemer committed
17
#include "Algo/Render/GL2/mapRender.h"
18
#include "Algo/Render/GL2/topoRender.h"
Pierre Kraemer's avatar
Pierre Kraemer committed
19
20
#include "Algo/Geometry/boundingbox.h"

21
22
#include "Algo/Topo/basic.h"

23
24
#include "Utils/vbo.h"

Thery Sylvain's avatar
Thery Sylvain committed
25
#include "dll.h"
Sylvain Thery's avatar
Sylvain Thery committed
26

Pierre Kraemer's avatar
Pierre Kraemer committed
27
28
29
30
31
32
namespace CGoGN
{

namespace SCHNApps
{

Sylvain Thery's avatar
Sylvain Thery committed
33
class SCHNAPPS_API MapHandlerGen : public QObject
Pierre Kraemer's avatar
Pierre Kraemer committed
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
{
	Q_OBJECT

	friend class View;

public:
	MapHandlerGen(const QString& name, SCHNApps* s, GenericMap* map);
	virtual ~MapHandlerGen();

	const QString& getName() const { return m_name; }

public slots:
	QString getName() { return m_name; }
	SCHNApps* getSCHNApps() const { return m_schnapps; }

	bool isSelectedMap() const { return m_schnapps->getSelectedMap() == this; }

	GenericMap* getGenericMap() const { return m_map; }

53
54
55
	/*********************************************************
	 * MANAGE FRAME
	 *********************************************************/
Pierre Kraemer's avatar
Pierre Kraemer committed
56

57
public slots:
58
	qglviewer::ManipulatedFrame* getFrame() const { return m_frame; }
59

60
61
62
63
64
65
66
67
68
69
70
71
72
	glm::mat4 getFrameMatrix() const
	{
		GLdouble m[16];
		m_frame->getMatrix(m);
		glm::mat4 matrix;
		for(unsigned int i = 0; i < 4; ++i)
		{
			for(unsigned int j = 0; j < 4; ++j)
				matrix[i][j] = (float)m[i*4+j];
		}
		return matrix;
	}

73
private slots:
74
75
76
77
78
79
	void frameModified()
	{
		DEBUG_EMIT("frameModified");
		emit(boundingBoxModified());
	}

80
81
82
83
84
	/*********************************************************
	 * MANAGE BOUNDING BOX
	 *********************************************************/

public slots:
85
86
87
88
89
	void setBBVertexAttribute(const QString& name)
	{
		m_bbVertexAttribute = m_map->getAttributeVectorGen(VERTEX, name.toStdString());
		updateBB();
	}
90
91
92
93

	AttributeMultiVectorGen* getBBVertexAttribute() const { return m_bbVertexAttribute; }

	QString getBBVertexAttributeName() const
94
95
96
97
98
99
	{
		if (m_bbVertexAttribute)
			return QString::fromStdString(m_bbVertexAttribute->getName());
		else
			return QString();
	}
Sylvain Thery's avatar
Sylvain Thery committed
100

101
102
103
104
105
106
107
108
109
110
	float getBBdiagSize() const { return m_bbDiagSize; }

	Utils::GLSLShader* getBBDrawerShader() const
	{
		if(m_bbDrawer)
			return m_bbDrawer->getShader();
		else
			return NULL;
	}

111
	virtual bool transformedBB(qglviewer::Vec& bbMin, qglviewer::Vec& bbMax) = 0;
Pierre Kraemer's avatar
Pierre Kraemer committed
112

113
114
115
protected:
	virtual void updateBB() = 0;

116
117
118
119
	/*********************************************************
	 * MANAGE DRAWING
	 *********************************************************/

120
public:
121
122
123
	virtual void draw(Utils::GLSLShader* shader, int primitive) = 0;
	virtual void drawBB() = 0;

Pierre Kraemer's avatar
Pierre Kraemer committed
124
125
	void setPrimitiveDirty(int primitive) {	m_render->setPrimitiveDirty(primitive);	}

126
127
128
129
130
131
132
	/*********************************************************
	 * MANAGE TOPOLOGICAL QUERIES
	 *********************************************************/

	virtual unsigned int getNbDarts() = 0;
	virtual unsigned int getNbOrbits(unsigned int orbit) = 0;

Pierre Kraemer's avatar
Pierre Kraemer committed
133
134
135
136
137
	/*********************************************************
	 * MANAGE ATTRIBUTES
	 *********************************************************/

	inline void registerAttribute(const AttributeHandlerGen& ah);
138
	inline void registerAttribute(unsigned int orbit, const QString& name, const QString& typeName);
Pierre Kraemer's avatar
Pierre Kraemer committed
139
140
141
142

	inline QString getAttributeTypeName(unsigned int orbit, const QString& nameAttr) const;
	const AttributeSet& getAttributeSet(unsigned int orbit) const { return m_attribs[orbit]; }

143
144
	void notifyAttributeModification(const AttributeHandlerGen& attr);
	void notifyConnectivityModification();
Pierre Kraemer's avatar
Pierre Kraemer committed
145

146
	void clear(bool removeAttrib);
Pierre Kraemer's avatar
Pierre Kraemer committed
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165

	/*********************************************************
	 * MANAGE VBOs
	 *********************************************************/

public slots:
	Utils::VBO* createVBO(const AttributeMultiVectorGen* attr);
	Utils::VBO* createVBO(const AttributeHandlerGen& attr);
	Utils::VBO* createVBO(const QString& name);

	void updateVBO(const AttributeMultiVectorGen* attr);
	void updateVBO(const AttributeHandlerGen& attr);
	void updateVBO(const QString& name);

	Utils::VBO* getVBO(const QString& name) const;
	const VBOSet& getVBOSet() const { return m_vbo; }

	void deleteVBO(const QString& name);

Pierre Kraemer's avatar
Pierre Kraemer committed
166
167
168
169
	/*********************************************************
	 * MANAGE CELL SELECTORS
	 *********************************************************/

Pierre Kraemer's avatar
Pierre Kraemer committed
170
	virtual CellSelectorGen* addCellSelector(unsigned int orbit, const QString& name) = 0;
Pierre Kraemer's avatar
Pierre Kraemer committed
171
172
173
	void removeCellSelector(unsigned int orbit, const QString& name);

	CellSelectorGen* getCellSelector(unsigned int orbit, const QString& name) const;
174
175
	const CellSelectorSet& getCellSelectorSet(unsigned int orbit) const { return m_cellSelectors[orbit]; }

Pierre Kraemer's avatar
Pierre Kraemer committed
176
private slots:
177
178
	void selectedCellsChanged();

179
public:
180
181
	void updateMutuallyExclusiveSelectors(unsigned int orbit);

Pierre Kraemer's avatar
Pierre Kraemer committed
182
183
184
185
186
187
188
189
	/*********************************************************
	 * MANAGE LINKED VIEWS
	 *********************************************************/

private:
	void linkView(View* view);
	void unlinkView(View* view);

190
191
192
193
public slots:
	const QList<View*>& getLinkedViews() const { return l_views; }
	bool isLinkedToView(View* view) const { return l_views.contains(view); }

194
195
196
197
	/*********************************************************
	 * MANAGE TOPO_RENDERING
	 *********************************************************/

198
public:
199
	virtual void createTopoRender(CGoGN::Utils::GLSLShader* s) = 0;
200
	void deleteTopoRender();
201
	virtual void updateTopoRender(const QString& positionAttributeName) = 0;
202
203
	virtual void drawTopoRender(int code) = 0;

204
	inline Algo::Render::GL2::TopoRender* getTopoRender() { return m_topoRender; }
205

Pierre Kraemer's avatar
Pierre Kraemer committed
206
207
208
209
210
211
212
213
214
	/*********************************************************
	 * SIGNALS
	 *********************************************************/

signals:
	void connectivityModified();

	void attributeAdded(unsigned int orbit, const QString& nameAttr);
	void attributeModified(unsigned int orbit, QString nameAttr);
215
	void attributeRemoved(unsigned int orbit, const QString& nameAttr);
Pierre Kraemer's avatar
Pierre Kraemer committed
216
217
218
219

	void vboAdded(Utils::VBO* vbo);
	void vboRemoved(Utils::VBO* vbo);

Pierre Kraemer's avatar
Pierre Kraemer committed
220
221
	void cellSelectorAdded(unsigned int orbit, const QString& name);
	void cellSelectorRemoved(unsigned int orbit, const QString& name);
222
	void selectedCellsChanged(CellSelectorGen* cs);
Pierre Kraemer's avatar
Pierre Kraemer committed
223

224
	void boundingBoxModified();
Sylvain Thery's avatar
Sylvain Thery committed
225

Pierre Kraemer's avatar
Pierre Kraemer committed
226
227
228
protected:
	QString m_name;
	SCHNApps* m_schnapps;
229

Pierre Kraemer's avatar
Pierre Kraemer committed
230
231
	GenericMap* m_map;

Pierre Kraemer's avatar
Pierre Kraemer committed
232
233
	qglviewer::ManipulatedFrame* m_frame;

234
	AttributeMultiVectorGen* m_bbVertexAttribute;
Pierre Kraemer's avatar
Pierre Kraemer committed
235
	float m_bbDiagSize;
236
	Utils::Drawer* m_bbDrawer;
237

Pierre Kraemer's avatar
Pierre Kraemer committed
238
	Algo::Render::GL2::MapRender* m_render;
239
	Algo::Render::GL2::TopoRender* m_topoRender;
Pierre Kraemer's avatar
Pierre Kraemer committed
240
241
242
243
244

	QList<View*> l_views;

	VBOSet m_vbo;
	AttributeSet m_attribs[NB_ORBITS];
245

246
	CellSelectorSet m_cellSelectors[NB_ORBITS];
Pierre Kraemer's avatar
Pierre Kraemer committed
247
248
249
250
251
252
};


template <typename PFP>
class MapHandler : public MapHandlerGen
{
Pierre Kraemer's avatar
Pierre Kraemer committed
253
254
255
	typedef typename PFP::MAP MAP;
	typedef typename PFP::VEC3 VEC3;

Pierre Kraemer's avatar
Pierre Kraemer committed
256
257
258
259
260
261
262
263
264
265
266
public:
	MapHandler(const QString& name, SCHNApps* s, typename PFP::MAP* map) :
		MapHandlerGen(name, s, map)
	{}

	~MapHandler()
	{
		if (m_map)
			delete m_map;
	}

Pierre Kraemer's avatar
Pierre Kraemer committed
267
268
	inline MAP* getMap() { return static_cast<MAP*>(m_map); }

269
270
271
272
273
274
275
	/*********************************************************
	 * MANAGE TOPOLOGICAL QUERIES
	 *********************************************************/

	unsigned int getNbDarts();
	unsigned int getNbOrbits(unsigned int orbit);

Pierre Kraemer's avatar
Pierre Kraemer committed
276
277
278
279
280
	/*********************************************************
	 * MANAGE ATTRIBUTES
	 *********************************************************/

	template <typename T, unsigned int ORBIT>
Sylvain Thery's avatar
Sylvain Thery committed
281
	AttributeHandler<T, ORBIT, MAP> getAttribute(const QString& nameAttr, bool onlyRegistered = true) const;
Pierre Kraemer's avatar
Pierre Kraemer committed
282
283

	template <typename T, unsigned int ORBIT>
Sylvain Thery's avatar
Sylvain Thery committed
284
	AttributeHandler<T, ORBIT, MAP> addAttribute(const QString& nameAttr, bool registerAttr = true);
Pierre Kraemer's avatar
Pierre Kraemer committed
285
286
287
288

	/*********************************************************
	 * MANAGE DRAWING
	 *********************************************************/
289

Pierre Kraemer's avatar
Pierre Kraemer committed
290
291
292
	void draw(Utils::GLSLShader* shader, int primitive);
	void drawBB();

293
	void updateBB();
Pierre Kraemer's avatar
Pierre Kraemer committed
294
295
	void updateBBDrawer();

296
	bool transformedBB(qglviewer::Vec& bbMin, qglviewer::Vec& bbMax);
Sylvain Thery's avatar
Sylvain Thery committed
297

298
299
300
	/*********************************************************
	 * MANAGE TOPO DRAWING
	 *********************************************************/
301

302
303
	void createTopoRender(CGoGN::Utils::GLSLShader* s);
	void updateTopoRender(const QString& positionAttributeName);
304
305
	void drawTopoRender(int code);

Pierre Kraemer's avatar
Pierre Kraemer committed
306
307
308
309
310
311
312
313
	/*********************************************************
	 * MANAGE CELL SELECTORS
	 *********************************************************/

	virtual CellSelectorGen* addCellSelector(unsigned int orbit, const QString& name);

	template <unsigned int ORBIT>
	CellSelector<MAP, ORBIT>* getCellSelector(const QString& name) const;
Pierre Kraemer's avatar
Pierre Kraemer committed
314

Pierre Kraemer's avatar
Pierre Kraemer committed
315
protected:
Pierre Kraemer's avatar
Pierre Kraemer committed
316
	Geom::BoundingBox<VEC3> m_bb;
Pierre Kraemer's avatar
Pierre Kraemer committed
317
318
319
320
321
322
323
324
325
};

} // namespace SCHNApps

} // namespace CGoGN

#include "mapHandler.hpp"

#endif