mapHandler.h 5.99 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 14

#include "Topology/generic/genericmap.h"
#include "Topology/generic/attribmap.h"
#include "Topology/generic/functor.h"
#include "Topology/generic/attributeHandler.h"
15

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

19 20 21
#include "Utils/vbo.h"
#include "Utils/drawer.h"

Pierre Kraemer's avatar
Pierre Kraemer committed
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
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
48 49 50
	const QList<View*>& getLinkedViews() const { return l_views; }
	bool isLinkedToView(View* view) const { return l_views.contains(view); }

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

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

63 64 65 66 67 68 69 70 71 72 73 74 75 76
	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;
	}

Pierre Kraemer's avatar
Pierre Kraemer committed
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140
public:
	virtual void draw(Utils::GLSLShader* shader, int primitive) = 0;
	virtual void drawBB() = 0;

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

	/*********************************************************
	 * MANAGE ATTRIBUTES
	 *********************************************************/

	template <typename T, unsigned int ORBIT>
	AttributeHandler<T, ORBIT> getAttribute(const QString& nameAttr, bool onlyRegistered = true) const;

	template <typename T, unsigned int ORBIT>
	AttributeHandler<T, ORBIT> addAttribute(const QString& nameAttr, bool registerAttr = true);

	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]; }

	void notifyAttributeModification(const AttributeHandlerGen& attr)
	{
		QString nameAttr = QString::fromStdString(attr.name());
		if(m_vbo.contains(nameAttr))
			m_vbo[nameAttr]->updateData(attr);

		emit(attributeModified(attr.getOrbit(), nameAttr));

		foreach(View* view, l_views)
			view->updateGL();
	}

	void notifyConnectivityModification()
	{
		m_render->setPrimitiveDirty(Algo::Render::GL2::POINTS);
		m_render->setPrimitiveDirty(Algo::Render::GL2::LINES);
		m_render->setPrimitiveDirty(Algo::Render::GL2::TRIANGLES);

		emit(connectivityModified());

		foreach(View* view, l_views)
			view->updateGL();
	}

	/*********************************************************
	 * 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
141 142 143 144 145 146 147 148 149 150
	/*********************************************************
	 * MANAGE CELL SELECTORS
	 *********************************************************/

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

	CellSelectorGen* getCellSelector(unsigned int orbit, const QString& name) const;
	const QMap<QString, CellSelectorGen*>& getCellSelectorSet(unsigned int orbit) const { return m_cellSelectors[orbit]; }

Pierre Kraemer's avatar
Pierre Kraemer committed
151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171
	/*********************************************************
	 * MANAGE LINKED VIEWS
	 *********************************************************/

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

	/*********************************************************
	 * SIGNALS
	 *********************************************************/

signals:
	void connectivityModified();

	void attributeAdded(unsigned int orbit, const QString& nameAttr);
	void attributeModified(unsigned int orbit, QString nameAttr);

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

Pierre Kraemer's avatar
Pierre Kraemer committed
172 173
	void cellSelectorAdded(unsigned int orbit, const QString& name);
	void cellSelectorRemoved(unsigned int orbit, const QString& name);
174
	void selectedCellsChanged();
Pierre Kraemer's avatar
Pierre Kraemer committed
175

Pierre Kraemer's avatar
Pierre Kraemer committed
176 177 178
protected:
	QString m_name;
	SCHNApps* m_schnapps;
179

Pierre Kraemer's avatar
Pierre Kraemer committed
180 181
	GenericMap* m_map;

Pierre Kraemer's avatar
Pierre Kraemer committed
182 183
	qglviewer::ManipulatedFrame* m_frame;

Pierre Kraemer's avatar
Pierre Kraemer committed
184 185 186
	qglviewer::Vec m_bbMin;
	qglviewer::Vec m_bbMax;
	float m_bbDiagSize;
187 188
	Utils::Drawer* m_bbDrawer;

Pierre Kraemer's avatar
Pierre Kraemer committed
189 190 191 192 193 194
	Algo::Render::GL2::MapRender* m_render;

	QList<View*> l_views;

	VBOSet m_vbo;
	AttributeSet m_attribs[NB_ORBITS];
195

Pierre Kraemer's avatar
Pierre Kraemer committed
196
	QMap<QString, CellSelectorGen*> m_cellSelectors[NB_ORBITS];
Pierre Kraemer's avatar
Pierre Kraemer committed
197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213
};


template <typename PFP>
class MapHandler : public MapHandlerGen
{
public:
	MapHandler(const QString& name, SCHNApps* s, typename PFP::MAP* map) :
		MapHandlerGen(name, s, map)
	{}

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

214 215
	inline typename PFP::MAP* getMap() { return static_cast<typename PFP::MAP*>(m_map); }

Pierre Kraemer's avatar
Pierre Kraemer committed
216 217 218 219 220 221
	void draw(Utils::GLSLShader* shader, int primitive);
	void drawBB();

	void updateBB(const VertexAttribute<typename PFP::VEC3>& position);
	void updateBBDrawer();

Pierre Kraemer's avatar
Pierre Kraemer committed
222 223
	CellSelectorGen* addPrimitiveSelector(unsigned int orbit, const QString& name);

Pierre Kraemer's avatar
Pierre Kraemer committed
224 225 226 227 228 229 230 231 232 233 234
protected:
	Geom::BoundingBox<typename PFP::VEC3> m_bb;
};

} // namespace SCHNApps

} // namespace CGoGN

#include "mapHandler.hpp"

#endif