KOSMIndoorMap

scenegraph.h
1/*
2 SPDX-FileCopyrightText: 2020 Volker Krause <vkrause@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6
7#ifndef KOSMINDOORMAP_SCENEGRAPH_H
8#define KOSMINDOORMAP_SCENEGRAPH_H
9
10#include "kosmindoormap_export.h"
11
12#include "scenegraphitem.h"
13
14#include <KOSM/Element>
15
16#include <QColor>
17
18#include <memory>
19#include <vector>
20
21class QPointF;
22
23namespace KOSMIndoorMap {
24
25class SceneGraphItem;
26
27/** Scene graph of the currently displayed level. */
28class KOSMINDOORMAP_EXPORT SceneGraph
29{
30public:
31 explicit SceneGraph();
32 SceneGraph(const SceneGraph&) = delete;
35
36 SceneGraph& operator=(const SceneGraph&) = delete;
37 SceneGraph& operator=(SceneGraph &&other);
38
39 /** Clears all data from the scene graph. */
40 void clear();
41
42 // scene builder interface
43 void beginSwap();
44 void addItem(SceneGraphItem &&item);
45 template <typename T>
46 std::unique_ptr<SceneGraphItemPayload> findOrCreatePayload(OSM::Element e, int level, LayerSelectorKey layerSelector);
47 void zSort();
48 void endSwap();
49
50 // dirty state tracking
51 int zoomLevel() const;
52 void setZoomLevel(int zoom);
53 int currentFloorLevel() const;
54 void setCurrentFloorLevel(int level);
55
56 /** Canvas background color. */
57 QColor backgroundColor() const;
58 void setBackgroundColor(const QColor &bg);
59
60 // renderer interface
61 typedef std::pair<std::size_t, std::size_t> LayerOffset;
62 const std::vector<LayerOffset>& layerOffsets() const;
63
64 typedef std::vector<SceneGraphItem>::const_iterator SceneGraphItemIter;
65 SceneGraphItemIter itemsBegin(LayerOffset layer) const;
66 SceneGraphItemIter itemsEnd(LayerOffset layer) const;
67
68 // hit detector interface
69 const std::vector<SceneGraphItem>& items() const;
70
71private:
72 void recomputeLayerIndex();
73
74 static bool itemPoolCompare(const SceneGraphItem &lhs, const SceneGraphItem &rhs);
75 static bool zOrderCompare(const SceneGraphItem &lhs, const SceneGraphItem &rhs);
76
77 std::vector<SceneGraphItem> m_items;
78 std::vector<SceneGraphItem> m_previousItems;
79 std::vector<std::pair<std::size_t, std::size_t>> m_layerOffsets;
80 QColor m_bgColor;
81
82 int m_zoomLevel = 0;
83 int m_floorLevel = 0;
84};
85
86
87template<typename T>
88std::unique_ptr<SceneGraphItemPayload> SceneGraph::findOrCreatePayload(OSM::Element e, int level, LayerSelectorKey layerSelector)
89{
91 ref.element = e;
92 ref.level = level;
93 auto it = std::lower_bound(m_previousItems.begin(), m_previousItems.end(), ref, SceneGraph::itemPoolCompare);
94 for (;it != m_previousItems.end() && (*it).element.type() == e.type() && (*it).element.id() == e.id() && (*it).layerSelector == layerSelector && (*it).level == level && (*it).payload; ++it) {
95 if (dynamic_cast<T*>((*it).payload.get())) {
96 return std::move((*it).payload);
97 }
98 }
99 return std::make_unique<T>();
100}
101
102}
103
104#endif // KOSMINDOORMAP_SCENEGRAPH_H
Scene graph item description and handle for its content.
OSM::Element element
The OSM::Element this item refers to.
Scene graph of the currently displayed level.
Definition scenegraph.h:29
A reference to any of OSM::Node/OSM::Way/OSM::Relation.
Definition element.h:24
OSM-based multi-floor indoor maps for buildings.
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Tue Mar 26 2024 11:20:03 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.