mapHandler.h 7.81 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"

Pierre Kraemer's avatar
Pierre Kraemer committed
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
namespace CGoGN
{

namespace SCHNApps
{

class MapHandlerGen : public QObject
{
	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; }

Pierre Kraemer's avatar
Pierre Kraemer committed
51 52 53
	const QList<View*>& getLinkedViews() const { return l_views; }
	bool isLinkedToView(View* view) const { return l_views.contains(view); }

54 55
	const qglviewer::Vec& getBBmin() const { return m_bbMin; }
	const qglviewer::Vec& getBBmax() const { return m_bbMax; }
Pierre Kraemer's avatar
Pierre Kraemer committed
56
	float getBBdiagSize() const { return m_bbDiagSize; }
57

Pierre Kraemer's avatar
Pierre Kraemer committed
58 59
	Utils::GLSLShader* getBBDrawerShader() const
	{
60 61 62
		if(m_bbDrawer)
			return m_bbDrawer->getShader();
		else
Pierre Kraemer's avatar
Pierre Kraemer committed
63 64 65
			return NULL;
	}

66 67 68 69 70 71 72 73 74 75 76 77 78 79
	qglviewer::ManipulatedFrame* getFrame() const { return m_frame; }
	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;
	}

Sylvain Thery's avatar
Sylvain Thery committed
80 81
	void frameModified() { DEBUG_EMIT("frameModified");emit(BBisModified());}

Pierre Kraemer's avatar
Pierre Kraemer committed
82 83 84
public:
	virtual void draw(Utils::GLSLShader* shader, int primitive) = 0;
	virtual void drawBB() = 0;
Sylvain Thery's avatar
Sylvain Thery committed
85
	virtual void transformedBB(qglviewer::Vec& bbMin, qglviewer::Vec& bbMax) = 0;
86
	virtual void initBBDrawer() = 0;
Pierre Kraemer's avatar
Pierre Kraemer committed
87 88 89

	void setPrimitiveDirty(int primitive) {	m_render->setPrimitiveDirty(primitive);	}

90 91 92 93 94 95 96
	/*********************************************************
	 * MANAGE TOPOLOGICAL QUERIES
	 *********************************************************/

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

Pierre Kraemer's avatar
Pierre Kraemer committed
97 98 99 100 101 102 103 104 105 106
	/*********************************************************
	 * MANAGE ATTRIBUTES
	 *********************************************************/

	inline void registerAttribute(const AttributeHandlerGen& ah);

	inline QString getAttributeTypeName(unsigned int orbit, const QString& nameAttr) const;

	const AttributeSet& getAttributeSet(unsigned int orbit) const { return m_attribs[orbit]; }

107
	void notifyAttributeModification(const AttributeHandlerGen& attr);
108

109
	void notifyConnectivityModification();
Pierre Kraemer's avatar
Pierre Kraemer committed
110

111
	void clear(bool removeAttrib);
Pierre Kraemer's avatar
Pierre Kraemer committed
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130

	/*********************************************************
	 * 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
131 132 133 134
	/*********************************************************
	 * MANAGE CELL SELECTORS
	 *********************************************************/

Pierre Kraemer's avatar
Pierre Kraemer committed
135
	virtual CellSelectorGen* addCellSelector(unsigned int orbit, const QString& name) = 0;
Pierre Kraemer's avatar
Pierre Kraemer committed
136 137 138
	void removeCellSelector(unsigned int orbit, const QString& name);

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

Pierre Kraemer's avatar
Pierre Kraemer committed
141
private slots:
142 143
	void selectedCellsChanged();

144
public:
145 146
	void updateMutuallyExclusiveSelectors(unsigned int orbit);

Pierre Kraemer's avatar
Pierre Kraemer committed
147 148 149 150 151 152 153 154
	/*********************************************************
	 * MANAGE LINKED VIEWS
	 *********************************************************/

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

155 156 157 158 159 160 161 162 163 164 165 166 167 168 169
	/*********************************************************
	 * MANAGE TOPO_RENDERING
	 *********************************************************/
public:

	virtual void createTopoRender(CGoGN::Utils::GLSLShader* sh1) = 0;
	void deleteTopoRender();
	virtual void updateTopoRender(const QString& name) = 0;
	virtual void drawTopoRender(int code) = 0;

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

protected:
	Algo::Render::GL2::TopoRender* m_topoRender;

Pierre Kraemer's avatar
Pierre Kraemer committed
170 171 172 173 174 175 176 177 178
	/*********************************************************
	 * SIGNALS
	 *********************************************************/

signals:
	void connectivityModified();

	void attributeAdded(unsigned int orbit, const QString& nameAttr);
	void attributeModified(unsigned int orbit, QString nameAttr);
179
	void attributeRemoved(unsigned int orbit, const QString& nameAttr);
Pierre Kraemer's avatar
Pierre Kraemer committed
180 181 182 183

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

Pierre Kraemer's avatar
Pierre Kraemer committed
184 185
	void cellSelectorAdded(unsigned int orbit, const QString& name);
	void cellSelectorRemoved(unsigned int orbit, const QString& name);
186
	void selectedCellsChanged(CellSelectorGen* cs);
Pierre Kraemer's avatar
Pierre Kraemer committed
187

Sylvain Thery's avatar
Sylvain Thery committed
188 189
	void BBisModified();

Pierre Kraemer's avatar
Pierre Kraemer committed
190 191 192
protected:
	QString m_name;
	SCHNApps* m_schnapps;
193

Pierre Kraemer's avatar
Pierre Kraemer committed
194 195
	GenericMap* m_map;

Pierre Kraemer's avatar
Pierre Kraemer committed
196 197
	qglviewer::ManipulatedFrame* m_frame;

Pierre Kraemer's avatar
Pierre Kraemer committed
198 199 200
	qglviewer::Vec m_bbMin;
	qglviewer::Vec m_bbMax;
	float m_bbDiagSize;
201
	Utils::Drawer* m_bbDrawer;
202

Pierre Kraemer's avatar
Pierre Kraemer committed
203 204 205 206 207 208
	Algo::Render::GL2::MapRender* m_render;

	QList<View*> l_views;

	VBOSet m_vbo;
	AttributeSet m_attribs[NB_ORBITS];
209

210
	CellSelectorSet m_cellSelectors[NB_ORBITS];
211 212


Pierre Kraemer's avatar
Pierre Kraemer committed
213 214 215 216 217 218
};


template <typename PFP>
class MapHandler : public MapHandlerGen
{
Pierre Kraemer's avatar
Pierre Kraemer committed
219 220 221
	typedef typename PFP::MAP MAP;
	typedef typename PFP::VEC3 VEC3;

Pierre Kraemer's avatar
Pierre Kraemer committed
222 223 224 225 226 227 228 229 230 231 232
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
233 234
	inline MAP* getMap() { return static_cast<MAP*>(m_map); }

235 236 237 238 239 240 241
	/*********************************************************
	 * MANAGE TOPOLOGICAL QUERIES
	 *********************************************************/

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

Pierre Kraemer's avatar
Pierre Kraemer committed
242 243 244 245 246
	/*********************************************************
	 * MANAGE ATTRIBUTES
	 *********************************************************/

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

	template <typename T, unsigned int ORBIT>
Sylvain Thery's avatar
Sylvain Thery committed
250
	AttributeHandler<T, ORBIT, MAP> addAttribute(const QString& nameAttr, bool registerAttr = true);
Pierre Kraemer's avatar
Pierre Kraemer committed
251 252 253 254

	/*********************************************************
	 * MANAGE DRAWING
	 *********************************************************/
255

Pierre Kraemer's avatar
Pierre Kraemer committed
256 257 258
	void draw(Utils::GLSLShader* shader, int primitive);
	void drawBB();

Sylvain Thery's avatar
Sylvain Thery committed
259
	void updateBB(const VertexAttribute<VEC3, MAP>& position);
260
	void initBBDrawer();
Pierre Kraemer's avatar
Pierre Kraemer committed
261 262
	void updateBBDrawer();

Sylvain Thery's avatar
Sylvain Thery committed
263 264 265
	void transformedBB(qglviewer::Vec& bbMin, qglviewer::Vec& bbMax);


266 267 268 269 270 271 272 273
	/*********************************************************
	 * MANAGE TOPO DRAWING
	 *********************************************************/
	void createTopoRender(CGoGN::Utils::GLSLShader* sh1);
	void updateTopoRender(const QString& positionName);
	void drawTopoRender(int code);


Pierre Kraemer's avatar
Pierre Kraemer committed
274 275 276 277 278 279 280 281
	/*********************************************************
	 * 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
282

Pierre Kraemer's avatar
Pierre Kraemer committed
283
protected:
Pierre Kraemer's avatar
Pierre Kraemer committed
284
	Geom::BoundingBox<VEC3> m_bb;
Pierre Kraemer's avatar
Pierre Kraemer committed
285 286 287 288 289 290
};

} // namespace SCHNApps

} // namespace CGoGN

291

Pierre Kraemer's avatar
Pierre Kraemer committed
292 293 294
#include "mapHandler.hpp"

#endif