mapHandler.h 2.29 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

14
class MapHandlerGen
15 16
{
public:
Pierre Kraemer's avatar
Pierre Kraemer committed
17
	MapHandlerGen(const QString& name, Window* window, CGoGN::GenericMap* map);
18 19
	virtual ~MapHandlerGen();

20
	const QString& getName() const { return m_name; }
21
	void setName(const QString& name) { m_name = name; }
22

23
	Window* getWindow() const { return m_window; }
24 25
	void setWindow(Window* w) { m_window = w; }

Pierre Kraemer's avatar
Pierre Kraemer committed
26 27
	CGoGN::GenericMap* getGenericMap() { return m_map; }

28 29
	const qglviewer::Vec& getBBmin() const { return m_bbMin; }
	void setBBmin(qglviewer::Vec& v) { m_bbMin = v; }
30

31 32 33
	const qglviewer::Vec& getBBmax() const { return m_bbMax; }
	void setBBmax(qglviewer::Vec& v) { m_bbMax = v; }

34 35
	float getBBdiagSize() { return (m_bbMax - m_bbMin).norm(); }

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

38 39
	void draw(CGoGN::Utils::GLSLShader* shader, int primitive);

40 41 42 43 44 45
	/*********************************************************
	 * MANAGE VBOs
	 *********************************************************/

	CGoGN::Utils::VBO* getVBO(const std::string& name);
	void deleteVBO(const std::string& name);
46

47 48 49 50
	/*********************************************************
	 * MANAGE LINKED VIEWS
	 *********************************************************/

Pierre Kraemer's avatar
Pierre Kraemer committed
51
	void linkView(View* view);
52
	void unlinkView(View* view);
53 54
	const QList<View*>& getLinkedViews() const { return l_views; }
	bool isLinkedToView(View* view) const { return l_views.contains(view); }
55

56
protected:
57
	QString m_name;
58
	Window* m_window;
Pierre Kraemer's avatar
Pierre Kraemer committed
59
	CGoGN::GenericMap* m_map;
60

61 62
	CGoGN::Algo::Render::GL2::MapRender* m_render;

63 64
	qglviewer::Vec m_bbMin;
	qglviewer::Vec m_bbMax;
65

66 67
	QList<View*> l_views;

68
	VBOHash h_vbo;
69
};
70

71 72 73 74 75
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
76
		MapHandlerGen(name, window, map)
77
	{}
78 79 80 81 82 83 84

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

Pierre Kraemer's avatar
Pierre Kraemer committed
85
	typename PFP::MAP* getMap() { return reinterpret_cast<typename PFP::MAP*>(m_map); }
86 87 88

	void updatePrimitives(int primitive, const CGoGN::FunctorSelect& good)
	{
Pierre Kraemer's avatar
Pierre Kraemer committed
89
		m_render->initPrimitives<PFP>(*(reinterpret_cast<typename PFP::MAP*>(m_map)), good, primitive) ;
90
	}
91 92 93
};

#endif