KOSMIndoorMap

scenegraph.h
1 /*
2  SPDX-FileCopyrightText: 2020 Volker Krause <[email protected]>
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 
21 class QPointF;
22 
23 namespace KOSMIndoorMap {
24 
25 class SceneGraphItem;
26 
27 /** Scene graph of the currently displayed level. */
28 class KOSMINDOORMAP_EXPORT SceneGraph
29 {
30 public:
31  explicit SceneGraph();
32  SceneGraph(const SceneGraph&) = delete;
34  ~SceneGraph();
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 
71 private:
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 
87 template<typename T>
88 std::unique_ptr<SceneGraphItemPayload> SceneGraph::findOrCreatePayload(OSM::Element e, int level, LayerSelectorKey layerSelector)
89 {
90  SceneGraphItem ref;
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
OSM-based multi-floor indoor maps for buildings.
Scene graph of the currently displayed level.
Definition: scenegraph.h:28
Scene graph item description and handle for its content.
A reference to any of OSM::Node/OSMWay/OSMRelation.
Definition: element.h:22
OSM::Element element
The OSM::Element this item refers to.
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Sat Oct 23 2021 23:03:45 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.