KOSMIndoorMap

navmeshtransform.h
1/*
2 SPDX-FileCopyrightText: 2024 Volker Krause <vkrause@kde.org>
3 SPDX-License-Identifier: LGPL-2.0-or-later
4*/
5
6#ifndef KOSMINDOORROUTING_NAVMESHTRANSFORM_H
7#define KOSMINDOORROUTING_NAVMESHTRANSFORM_H
8
9#include "kosmindoorrouting_export.h"
10
11#include <osm/datatypes.h>
12
13#include <QTransform>
14
15#include <cmath>
16
17namespace KOSMIndoorRouting {
18
19/** 3D vector type compatible with the Recast API. */
20struct rcVec3 {
21 [[nodiscard]] inline operator float*() { return &x; }
22 [[nodiscard]] inline operator const float*() const { return &x; }
23
24 float x = {};
25 float y = {};
26 float z = {};
27};
28
29class NavMeshTransform {
30public:
31 void initialize(OSM::BoundingBox bbox);
32
33 template <typename T>
34 [[nodiscard]] inline T mapGeoToNav(const T &p) const
35 {
36 return m_transform.map(p);
37 }
38
39 [[nodiscard]] inline QPointF mapGeoToNav(OSM::Coordinate c) const
40 {
41 return mapGeoToNav(QPointF(c.lonF(), c.latF()));
42 }
43
44 [[nodiscard]] inline float mapHeightToNav(int floorLevel) const
45 {
46 // TODO
47 return (float)floorLevel;
48 }
49
50 [[nodiscard]] inline rcVec3 mapGeoHeightToNav(OSM::Coordinate c, int floorLevel) const
51 {
52 const auto p = mapGeoToNav(c);
53 return { (float)p.x(), mapHeightToNav(floorLevel), (float)p.y() };
54 }
55
56 [[nodiscard]] inline OSM::Coordinate mapNavToGeo(rcVec3 p) const
57 {
58 const auto c = m_transform.inverted().map(QPointF(p.x, p.z));
59 return OSM::Coordinate(c.y(), c.x());
60 }
61
62 [[nodiscard]] inline int mapNavHeightToFloorLevel(float height) const
63 {
64 return (int)std::round(height);
65 }
66private:
67 QTransform m_transform;
68};
69}
70
71#endif
Bounding box, ie.
Definition datatypes.h:95
Coordinate, stored as 1e7 * degree to avoid floating point precision issues, and offset to unsigned v...
Definition datatypes.h:37
QTransform inverted(bool *invertible) const const
QLine map(const QLine &l) const const
3D vector type compatible with the Recast API.
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 17:06:15 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.