mapHandler.h 9.04 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 90 91 92 93 94 95 96 97

	void showBB(bool b)
	{
		m_showBB = b;
		foreach(View* view, l_views)
			view->updateGL();
	}
	
	bool isBBshown() const
	{
		return m_showBB;
	}

98 99 100 101
	void setBBVertexAttribute(const QString& name)
	{
		m_bbVertexAttribute = m_map->getAttributeVectorGen(VERTEX, name.toStdString());
		updateBB();
Sylvain Thery's avatar
Sylvain Thery committed
102 103 104 105 106 107 108
		// for update of interface
		if (m_schnapps->getSelectedMap() == this)
		{
			m_schnapps->setSelectedMap("NONE");
			m_schnapps->setSelectedMap(this->getName());
		}

109
	}
110 111 112 113

	AttributeMultiVectorGen* getBBVertexAttribute() const { return m_bbVertexAttribute; }

	QString getBBVertexAttributeName() const
114 115 116 117 118 119
	{
		if (m_bbVertexAttribute)
			return QString::fromStdString(m_bbVertexAttribute->getName());
		else
			return QString();
	}
Sylvain Thery's avatar
Sylvain Thery committed
120

121 122
	float getBBdiagSize() const { return m_bbDiagSize; }

123
	inline Utils::Drawer* getBBDrawer() const
124
	{
125
		return m_bbDrawer;
126 127
	}

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

130
protected:
131
	bool m_showBB;
132 133
	virtual void updateBB() = 0;

134 135 136 137
	/*********************************************************
	 * MANAGE DRAWING
	 *********************************************************/

138
public:
139 140 141
	virtual void draw(Utils::GLSLShader* shader, int primitive) = 0;
	virtual void drawBB() = 0;

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

144 145 146 147 148 149 150
	/*********************************************************
	 * MANAGE TOPOLOGICAL QUERIES
	 *********************************************************/

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

Pierre Kraemer's avatar
Pierre Kraemer committed
151 152 153 154 155
	/*********************************************************
	 * MANAGE ATTRIBUTES
	 *********************************************************/

	inline void registerAttribute(const AttributeHandlerGen& ah);
156
	inline void registerAttribute(unsigned int orbit, const QString& name, const QString& typeName);
Pierre Kraemer's avatar
Pierre Kraemer committed
157 158 159 160

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

161 162
	void notifyAttributeModification(const AttributeHandlerGen& attr);
	void notifyConnectivityModification();
Pierre Kraemer's avatar
Pierre Kraemer committed
163

164
	void clear(bool removeAttrib);
Pierre Kraemer's avatar
Pierre Kraemer committed
165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183

	/*********************************************************
	 * 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
184 185 186 187
	/*********************************************************
	 * MANAGE CELL SELECTORS
	 *********************************************************/

Pierre Kraemer's avatar
Pierre Kraemer committed
188
	virtual CellSelectorGen* addCellSelector(unsigned int orbit, const QString& name) = 0;
Pierre Kraemer's avatar
Pierre Kraemer committed
189 190 191
	void removeCellSelector(unsigned int orbit, const QString& name);

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

Pierre Kraemer's avatar
Pierre Kraemer committed
194
private slots:
195 196
	void selectedCellsChanged();

197
public:
198 199
	void updateMutuallyExclusiveSelectors(unsigned int orbit);

Pierre Kraemer's avatar
Pierre Kraemer committed
200 201 202 203 204 205 206 207
	/*********************************************************
	 * MANAGE LINKED VIEWS
	 *********************************************************/

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

208 209 210 211
public slots:
	const QList<View*>& getLinkedViews() const { return l_views; }
	bool isLinkedToView(View* view) const { return l_views.contains(view); }

212 213 214 215
	/*********************************************************
	 * MANAGE TOPO_RENDERING
	 *********************************************************/

216
public:
217
	virtual void createTopoRender(std::vector<CGoGN::Utils::GLSLShader*> s) = 0;
218
	void deleteTopoRender();
219
	virtual void updateTopoRender(const QString& positionAttributeName) = 0;
220 221
	virtual void drawTopoRender(int code) = 0;

222
	inline Algo::Render::GL2::TopoRender* getTopoRender() { return m_topoRender; }
223

Pierre Kraemer's avatar
Pierre Kraemer committed
224 225 226 227 228 229 230 231 232
	/*********************************************************
	 * SIGNALS
	 *********************************************************/

signals:
	void connectivityModified();

	void attributeAdded(unsigned int orbit, const QString& nameAttr);
	void attributeModified(unsigned int orbit, QString nameAttr);
233
	void attributeRemoved(unsigned int orbit, const QString& nameAttr);
Pierre Kraemer's avatar
Pierre Kraemer committed
234 235 236 237

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

Pierre Kraemer's avatar
Pierre Kraemer committed
238 239
	void cellSelectorAdded(unsigned int orbit, const QString& name);
	void cellSelectorRemoved(unsigned int orbit, const QString& name);
240
	void selectedCellsChanged(CellSelectorGen* cs);
Pierre Kraemer's avatar
Pierre Kraemer committed
241

242
	void boundingBoxModified();
Sylvain Thery's avatar
Sylvain Thery committed
243

Pierre Kraemer's avatar
Pierre Kraemer committed
244 245 246
protected:
	QString m_name;
	SCHNApps* m_schnapps;
247

Pierre Kraemer's avatar
Pierre Kraemer committed
248 249
	GenericMap* m_map;

Pierre Kraemer's avatar
Pierre Kraemer committed
250 251
	qglviewer::ManipulatedFrame* m_frame;

252
	AttributeMultiVectorGen* m_bbVertexAttribute;
Pierre Kraemer's avatar
Pierre Kraemer committed
253
	float m_bbDiagSize;
254
	Utils::Drawer* m_bbDrawer;
255

Pierre Kraemer's avatar
Pierre Kraemer committed
256
	Algo::Render::GL2::MapRender* m_render;
257
	Algo::Render::GL2::TopoRender* m_topoRender;
Pierre Kraemer's avatar
Pierre Kraemer committed
258 259 260 261 262

	QList<View*> l_views;

	VBOSet m_vbo;
	AttributeSet m_attribs[NB_ORBITS];
263

264
	CellSelectorSet m_cellSelectors[NB_ORBITS];
Pierre Kraemer's avatar
Pierre Kraemer committed
265 266 267 268 269 270
};


template <typename PFP>
class MapHandler : public MapHandlerGen
{
Pierre Kraemer's avatar
Pierre Kraemer committed
271 272 273
	typedef typename PFP::MAP MAP;
	typedef typename PFP::VEC3 VEC3;

Pierre Kraemer's avatar
Pierre Kraemer committed
274 275 276 277 278 279 280 281 282 283 284
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
285 286
	inline MAP* getMap() { return static_cast<MAP*>(m_map); }

287 288 289 290 291 292 293
	/*********************************************************
	 * MANAGE TOPOLOGICAL QUERIES
	 *********************************************************/

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

Pierre Kraemer's avatar
Pierre Kraemer committed
294 295 296 297 298
	/*********************************************************
	 * MANAGE ATTRIBUTES
	 *********************************************************/

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

	template <typename T, unsigned int ORBIT>
Sylvain Thery's avatar
Sylvain Thery committed
302
	AttributeHandler<T, ORBIT, MAP> addAttribute(const QString& nameAttr, bool registerAttr = true);
Pierre Kraemer's avatar
Pierre Kraemer committed
303 304 305 306

	/*********************************************************
	 * MANAGE DRAWING
	 *********************************************************/
307

Pierre Kraemer's avatar
Pierre Kraemer committed
308 309 310
	void draw(Utils::GLSLShader* shader, int primitive);
	void drawBB();

311
	void updateBB();
Pierre Kraemer's avatar
Pierre Kraemer committed
312 313
	void updateBBDrawer();

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

316 317 318
	/*********************************************************
	 * MANAGE TOPO DRAWING
	 *********************************************************/
319

320
	void createTopoRender(std::vector<CGoGN::Utils::GLSLShader*> s);
321
	void updateTopoRender(const QString& positionAttributeName);
322 323
	void drawTopoRender(int code);

Pierre Kraemer's avatar
Pierre Kraemer committed
324 325 326 327 328 329 330 331
	/*********************************************************
	 * 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
332

Pierre Kraemer's avatar
Pierre Kraemer committed
333
protected:
Pierre Kraemer's avatar
Pierre Kraemer committed
334
	Geom::BoundingBox<VEC3> m_bb;
Sylvain Thery's avatar
Sylvain Thery committed
335 336

public:
Sylvain Thery's avatar
Sylvain Thery committed
337
	inline const Geom::BoundingBox<VEC3>& getBB() const { return m_bb; }
Pierre Kraemer's avatar
Pierre Kraemer committed
338 339 340 341 342 343 344 345 346
};

} // namespace SCHNApps

} // namespace CGoGN

#include "mapHandler.hpp"

#endif