Création d'un compte pour un collaborateur extérieur au laboratoire depuis l'intranet ICube : https://intranet.icube.unistra.fr/fr/labs/member/profile

mapHandler.h 3.54 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/functor.h"
12
#include "Topology/generic/attributeHandler.h"
13
14
#include "Utils/vbo.h"
#include "Algo/Render/GL2/mapRender.h"
15
#include "Algo/Geometry/boundingbox.h"
16

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

namespace SCHNApps
{

23
class MapHandlerGen : public QObject
24
{
25
26
	Q_OBJECT

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

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

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

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

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

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

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

48
public:
49
	void draw(Utils::GLSLShader* shader, int primitive) { m_render->draw(shader, primitive); }
50

51
52
53
54
	/*********************************************************
	 * MANAGE VBOs
	 *********************************************************/

55
56
57
	template <typename ATTR_HANDLER>
	Utils::VBO* createVBO(const ATTR_HANDLER& attr)
	{
58
59
60
61
62
63
64
		QString name = QString::fromStdString(attr.name());
		Utils::VBO* vbo = getVBO(name);
		if(!vbo)
		{
			vbo = new Utils::VBO();
			h_vbo.insert(name, vbo);
		}
65
		vbo->updateData(attr);
66
		emit(vboAdded(vbo));
67
68
69
		return vbo;
	}

70
71
72
73
	template <typename ATTR_HANDLER>
	void updateVBO(const ATTR_HANDLER& attr)
	{
		Utils::VBO* vbo = getVBO(QString::fromStdString(attr.name()));
74
75
		if(vbo)
			vbo->updateData(attr);
76
77
	}

78
79
	Utils::VBO* getVBO(const QString& name);
	QList<Utils::VBO*> getVBOList() const { return h_vbo.values(); }
80
	QList<Utils::VBO*> getVBOList(const std::string& typeName);
81
	void deleteVBO(const QString& name);
82

83
84
85
86
	/*********************************************************
	 * MANAGE LINKED VIEWS
	 *********************************************************/

Pierre Kraemer's avatar
Pierre Kraemer committed
87
	void linkView(View* view);
88
	void unlinkView(View* view);
89
90
	const QList<View*>& getLinkedViews() const { return l_views; }
	bool isLinkedToView(View* view) const { return l_views.contains(view); }
91

92
protected:
93
	QString m_name;
94
	Window* m_window;
Pierre Kraemer's avatar
Pierre Kraemer committed
95
	GenericMap* m_map;
96

Pierre Kraemer's avatar
Pierre Kraemer committed
97
	Algo::Render::GL2::MapRender* m_render;
98

99
100
	qglviewer::Vec m_bbMin;
	qglviewer::Vec m_bbMax;
101
	float m_bbDiagSize;
102

103
104
	QList<View*> l_views;

105
	VBOHash h_vbo;
106
107
108
109

signals:
	void vboAdded(Utils::VBO* vbo);
	void vboRemoved(Utils::VBO* vbo);
110
};
111

112
113
114
115
116
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
117
		MapHandlerGen(name, window, map)
118
	{}
119
120
121
122
123
124
125

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

Pierre Kraemer's avatar
Pierre Kraemer committed
126
	typename PFP::MAP* getMap() { return static_cast<typename PFP::MAP*>(m_map); }
127

128
129
	void updateBB(const VertexAttribute<typename PFP::VEC3>& position)
	{
Pierre Kraemer's avatar
Pierre Kraemer committed
130
		CGoGN::Geom::BoundingBox<typename PFP::VEC3> bb = CGoGN::Algo::Geometry::computeBoundingBox<PFP>(*(static_cast<typename PFP::MAP*>(m_map)), position);
131
132
133
134
135
		m_bbMin = qglviewer::Vec(bb.min()[0], bb.min()[1], bb.min()[2]);
		m_bbMax = qglviewer::Vec(bb.max()[0], bb.max()[1], bb.max()[2]);
		m_bbDiagSize = (m_bbMax - m_bbMin).norm();
	}

136
	void updatePrimitives(int primitive, const FunctorSelect& good = allDarts)
137
	{
Pierre Kraemer's avatar
Pierre Kraemer committed
138
		m_render->initPrimitives<PFP>(*(static_cast<typename PFP::MAP*>(m_map)), good, primitive) ;
139
	}
140
141
};

Pierre Kraemer's avatar
Pierre Kraemer committed
142
143
144
145
} // namespace SCHNApps

} // namespace CGoGN

146
#endif