mapHandler.h 4.51 KB
Newer Older
1 2
#ifndef _MAPHANDLER_H_
#define _MAPHANDLER_H_
3

4
#include <QString>
5

6
#include "types.h"
7
#include "view.h"
8
#include "plugin.h"
9

Pierre Kraemer's avatar
Pierre Kraemer committed
10
#include "Topology/generic/genericmap.h"
11
#include "Topology/generic/attribmap.h"
12
#include "Topology/generic/functor.h"
13
#include "Topology/generic/attributeHandler.h"
14 15
#include "Utils/vbo.h"
#include "Algo/Render/GL2/mapRender.h"
16
#include "Algo/Geometry/boundingbox.h"
17

Pierre Kraemer's avatar
Pierre Kraemer committed
18 19 20 21 22 23
namespace CGoGN
{

namespace SCHNApps
{

24
class MapHandlerGen : public QObject
25
{
26 27
	Q_OBJECT

28
public:
Pierre Kraemer's avatar
Pierre Kraemer committed
29
	MapHandlerGen(const QString& name, Window* window, GenericMap* map);
30 31
	virtual ~MapHandlerGen();

32
	inline const QString& getName() const { return m_name; }
33 34

public slots:
35 36
	inline QString getName() { return m_name; }
	inline void setName(const QString& name) { m_name = name; }
37

38 39
	inline Window* getWindow() const { return m_window; }
	inline void setWindow(Window* w) { m_window = w; }
40

41
	inline GenericMap* getGenericMap() const { return m_map; }
Pierre Kraemer's avatar
Pierre Kraemer committed
42

43 44 45
	inline const qglviewer::Vec& getBBmin() const { return m_bbMin; }
	inline const qglviewer::Vec& getBBmax() const { return m_bbMax; }
	inline float getBBdiagSize() const { return m_bbDiagSize; }
46

47
	inline bool isUsed() const { return !l_views.empty(); }
Pierre Kraemer's avatar
Pierre Kraemer committed
48

49
public:
50 51
	virtual void draw(Utils::GLSLShader* shader, int primitive) = 0;

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

54 55 56 57 58
	/*********************************************************
	 * MANAGE ATTRIBUTES
	 *********************************************************/

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

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

64
	template <typename T, unsigned int ORBIT>
65 66 67 68 69 70 71 72
	inline void registerAttribute(const AttributeHandler<T, ORBIT>& ah);

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

	inline const AttributeHash& getAttributesList(unsigned int orbit) const { return h_attribs[orbit];	}

	template <typename T, unsigned int ORBIT>
	inline void notifyAttributeModification(const AttributeHandler<T, ORBIT>& attr)
73
	{
74 75 76 77 78
		QString nameAttr = QString::fromStdString(attr.name());
		if(h_vbo.contains(nameAttr))
			h_vbo[nameAttr]->updateData(attr);

		emit(attributeModified(ORBIT, nameAttr));
79 80 81

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

84
	inline void notifyConnectivityModification()
85
	{
86 87 88 89
		m_render->setPrimitiveDirty(Algo::Render::GL2::POINTS);
		m_render->setPrimitiveDirty(Algo::Render::GL2::LINES);
		m_render->setPrimitiveDirty(Algo::Render::GL2::TRIANGLES);

90
		emit(connectivityModified());
91 92 93

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

96 97 98 99
	/*********************************************************
	 * MANAGE VBOs
	 *********************************************************/

100
	template <typename ATTR_HANDLER>
101
	Utils::VBO* createVBO(const ATTR_HANDLER& attr);
102

103
	template <typename ATTR_HANDLER>
104
	void updateVBO(const ATTR_HANDLER& attr);
105

106
	Utils::VBO* getVBO(const QString& name) const;
107
	inline QList<Utils::VBO*> getVBOList() const { return h_vbo.values(); }
108
	void deleteVBO(const QString& name);
109

110 111 112 113
	/*********************************************************
	 * MANAGE LINKED VIEWS
	 *********************************************************/

Pierre Kraemer's avatar
Pierre Kraemer committed
114
	void linkView(View* view);
115
	void unlinkView(View* view);
116 117
	inline const QList<View*>& getLinkedViews() const { return l_views; }
	inline bool isLinkedToView(View* view) const { return l_views.contains(view); }
118

119
protected:
120
	QString m_name;
121
	Window* m_window;
Pierre Kraemer's avatar
Pierre Kraemer committed
122
	GenericMap* m_map;
123

Pierre Kraemer's avatar
Pierre Kraemer committed
124
	Algo::Render::GL2::MapRender* m_render;
125

126 127
	qglviewer::Vec m_bbMin;
	qglviewer::Vec m_bbMax;
128
	float m_bbDiagSize;
129

130 131
	QList<View*> l_views;

132
	VBOHash h_vbo;
133
	AttributeHash h_attribs[NB_ORBITS];
134 135

signals:
136 137 138 139 140
	void connectivityModified();

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

141 142
	void vboAdded(Utils::VBO* vbo);
	void vboRemoved(Utils::VBO* vbo);
143
};
144

145 146 147 148 149
template <typename PFP>
class MapHandler : public MapHandlerGen
{
public:
	MapHandler(const QString& name, Window* window, typename PFP::MAP* map) :
Pierre Kraemer's avatar
Pierre Kraemer committed
150
		MapHandlerGen(name, window, map)
151
	{}
152 153 154 155 156 157 158

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

159
	void draw(Utils::GLSLShader* shader, int primitive);
160

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

163
	void updateBB(const VertexAttribute<typename PFP::VEC3>& position);
164 165
};

Pierre Kraemer's avatar
Pierre Kraemer committed
166 167 168 169
} // namespace SCHNApps

} // namespace CGoGN

170 171
#include "mapHandler.hpp"

172
#endif