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

4
#include <QString>
5

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

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

Pierre Kraemer's avatar
Pierre Kraemer committed
15 16 17 18 19 20
namespace CGoGN
{

namespace SCHNApps
{

21
class MapHandlerGen
22 23
{
public:
Pierre Kraemer's avatar
Pierre Kraemer committed
24
	MapHandlerGen(const QString& name, Window* window, GenericMap* map);
25 26
	virtual ~MapHandlerGen();

27
	const QString& getName() const { return m_name; }
28
	void setName(const QString& name) { m_name = name; }
29

30
	Window* getWindow() const { return m_window; }
31 32
	void setWindow(Window* w) { m_window = w; }

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

35 36
	const qglviewer::Vec& getBBmin() const { return m_bbMin; }
	const qglviewer::Vec& getBBmax() const { return m_bbMax; }
37
	float getBBdiagSize() { return m_bbDiagSize; }
38

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

41
	void draw(Utils::GLSLShader* shader, int primitive) { m_render->draw(shader, primitive); }
42

43 44 45 46
	/*********************************************************
	 * MANAGE VBOs
	 *********************************************************/

47 48 49 50 51 52 53 54
	template <typename ATTR_HANDLER>
	Utils::VBO* createVBO(const ATTR_HANDLER& attr)
	{
		Utils::VBO* vbo = getVBO(QString::fromStdString(attr.name()));
		vbo->updateData(attr);
		return vbo;
	}

55 56 57 58 59 60 61
	template <typename ATTR_HANDLER>
	void updateVBO(const ATTR_HANDLER& attr)
	{
		Utils::VBO* vbo = getVBO(QString::fromStdString(attr.name()));
		vbo->updateData(attr);
	}

62 63 64
	Utils::VBO* getVBO(const QString& name);
	QList<Utils::VBO*> getVBOList() const { return h_vbo.values(); }
	void deleteVBO(const QString& name);
65

66 67 68 69
	/*********************************************************
	 * MANAGE LINKED VIEWS
	 *********************************************************/

Pierre Kraemer's avatar
Pierre Kraemer committed
70
	void linkView(View* view);
71
	void unlinkView(View* view);
72 73
	const QList<View*>& getLinkedViews() const { return l_views; }
	bool isLinkedToView(View* view) const { return l_views.contains(view); }
74

75
protected:
76
	QString m_name;
77
	Window* m_window;
Pierre Kraemer's avatar
Pierre Kraemer committed
78
	GenericMap* m_map;
79

Pierre Kraemer's avatar
Pierre Kraemer committed
80
	Algo::Render::GL2::MapRender* m_render;
81

82 83
	qglviewer::Vec m_bbMin;
	qglviewer::Vec m_bbMax;
84
	float m_bbDiagSize;
85

86 87
	QList<View*> l_views;

88
	VBOHash h_vbo;
89
};
90

91 92 93 94 95
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
96
		MapHandlerGen(name, window, map)
97
	{}
98 99 100 101 102 103 104

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

Pierre Kraemer's avatar
Pierre Kraemer committed
105
	typename PFP::MAP* getMap() { return reinterpret_cast<typename PFP::MAP*>(m_map); }
106

107 108 109 110 111 112 113 114
	void updateBB(const VertexAttribute<typename PFP::VEC3>& position)
	{
		CGoGN::Geom::BoundingBox<typename PFP::VEC3> bb = CGoGN::Algo::Geometry::computeBoundingBox<PFP>(*(reinterpret_cast<typename PFP::MAP*>(m_map)), position);
		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();
	}

115
	void updatePrimitives(int primitive, const FunctorSelect& good = allDarts)
116
	{
Pierre Kraemer's avatar
Pierre Kraemer committed
117
		m_render->initPrimitives<PFP>(*(reinterpret_cast<typename PFP::MAP*>(m_map)), good, primitive) ;
118
	}
119 120
};

Pierre Kraemer's avatar
Pierre Kraemer committed
121 122 123 124
} // namespace SCHNApps

} // namespace CGoGN

125
#endif