mapHandler.h 4.41 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
	inline void notifyConnectivityModification()
82
	{
83 84 85 86
		m_render->setPrimitiveDirty(Algo::Render::GL2::POINTS);
		m_render->setPrimitiveDirty(Algo::Render::GL2::LINES);
		m_render->setPrimitiveDirty(Algo::Render::GL2::TRIANGLES);

87
		emit(connectivityModified());
88 89
	}

90 91 92 93
	/*********************************************************
	 * MANAGE VBOs
	 *********************************************************/

94
	template <typename ATTR_HANDLER>
95
	Utils::VBO* createVBO(const ATTR_HANDLER& attr);
96

97
	template <typename ATTR_HANDLER>
98
	void updateVBO(const ATTR_HANDLER& attr);
99

100
	Utils::VBO* getVBO(const QString& name) const;
101
	inline QList<Utils::VBO*> getVBOList() const { return h_vbo.values(); }
102
	void deleteVBO(const QString& name);
103

104 105 106 107
	/*********************************************************
	 * MANAGE LINKED VIEWS
	 *********************************************************/

Pierre Kraemer's avatar
Pierre Kraemer committed
108
	void linkView(View* view);
109
	void unlinkView(View* view);
110 111
	inline const QList<View*>& getLinkedViews() const { return l_views; }
	inline bool isLinkedToView(View* view) const { return l_views.contains(view); }
112

113
protected:
114
	QString m_name;
115
	Window* m_window;
Pierre Kraemer's avatar
Pierre Kraemer committed
116
	GenericMap* m_map;
117

Pierre Kraemer's avatar
Pierre Kraemer committed
118
	Algo::Render::GL2::MapRender* m_render;
119

120 121
	qglviewer::Vec m_bbMin;
	qglviewer::Vec m_bbMax;
122
	float m_bbDiagSize;
123

124 125
	QList<View*> l_views;

126
	VBOHash h_vbo;
127
	AttributeHash h_attribs[NB_ORBITS];
128 129

signals:
130 131 132 133 134
	void connectivityModified();

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

135 136
	void vboAdded(Utils::VBO* vbo);
	void vboRemoved(Utils::VBO* vbo);
137
};
138

139 140 141 142 143
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
144
		MapHandlerGen(name, window, map)
145
	{}
146 147 148 149 150 151 152

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

153
	void draw(Utils::GLSLShader* shader, int primitive);
154

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

157
	void updateBB(const VertexAttribute<typename PFP::VEC3>& position);
158 159
};

Pierre Kraemer's avatar
Pierre Kraemer committed
160 161 162 163
} // namespace SCHNApps

} // namespace CGoGN

164 165
#include "mapHandler.hpp"

166
#endif