KOSMIndoorMap

routingjob.cpp
1/*
2 SPDX-FileCopyrightText: 2024 Volker Krause <vkrause@kde.org>
3 SPDX-License-Identifier: LGPL-2.0-or-later
4*/
5
6#include "routingjob.h"
7
8#include <logging.h>
9#include "navmesh.h"
10#include "navmesh_p.h"
11#include "navmeshtransform.h"
12#include "route.h"
13#include "routingarea.h"
14#include "routingprofile.h"
15
16#include <QThreadPool>
17
18namespace KOSMIndoorRouting {
19class RoutingJobPrivate {
20public:
21 void performQuery();
22
23 NavMesh m_navMesh;
24 rcVec3 m_start;
25 rcVec3 m_end;
26 RoutingProfile m_profile;
27 Route m_route;
28};
29}
30
31using namespace KOSMIndoorRouting;
32
33RoutingJob::RoutingJob(QObject *parent)
34 : QObject(parent)
35 , d(std::make_unique<RoutingJobPrivate>())
36{
37}
38
39RoutingJob::~RoutingJob() = default;
40
41void RoutingJob::setNavMesh(const NavMesh &navMesh)
42{
43 d->m_navMesh = navMesh;
44}
45
47{
48 d->m_start = start;
49}
50
51void RoutingJob::setEnd(rcVec3 end)
52{
53 d->m_end = end;
54}
55
57{
58 d->m_profile = profile;
59}
60
61void RoutingJob::start()
62{
63 qCDebug(Log) << QThread::currentThread();
64
66 d->performQuery();
67 QMetaObject::invokeMethod(this, &RoutingJob::finished, Qt::QueuedConnection);
68 });
69}
70
71Route RoutingJob::route() const
72{
73 return d->m_route;
74}
75
76void RoutingJobPrivate::performQuery()
77{
78 qCDebug(Log) << QThread::currentThread();
79
80 const auto navMesh = NavMeshPrivate::get(m_navMesh);
81 qCDebug(Log) <<m_start.x <<m_start.y << m_start.z << m_end.x << m_end.y << m_end.z;
82#if HAVE_RECAST
83 dtQueryFilter filter;
84 filter.setIncludeFlags(m_profile.flags());
85 filter.setExcludeFlags(~m_profile.flags());
86 for (int i = 1; i < AREA_TYPE_COUNT - 1; ++i) {
87 filter.setAreaCost(i, m_profile.cost(static_cast<AreaType>(i)));
88 }
89 filter.setAreaCost(RC_WALKABLE_AREA, m_profile.cost(AreaType::Walkable));
90 qCDebug(Log) << filter.getIncludeFlags() << filter.getExcludeFlags();
91
92 rcVec3 polyPickExt({ 2.0f, 4.0f, 2.0f }); // ???
93 dtPolyRef startPoly;
94 navMesh->m_navMeshQuery->findNearestPoly(m_start, polyPickExt, &filter, &startPoly, nullptr);
95 dtPolyRef endPoly;
96 navMesh->m_navMeshQuery->findNearestPoly(m_end, polyPickExt, &filter, &endPoly, nullptr);
97
98 dtPolyRef path[256];
99 int pathCount = 0;
100 qCDebug(Log) <<startPoly <<endPoly;
101 auto status = navMesh->m_navMeshQuery->findPath(startPoly, endPoly, m_start, m_end, &filter, path, &pathCount, 256); // TODO
102 qCDebug(Log) << pathCount << status;
103
104 std::vector<rcVec3> straightPath;
105 straightPath.resize(256);
106 std::vector<uint8_t> straightPathFlags;
107 straightPathFlags.resize(256);
108 int straightPathCount = 0;
109 dtPolyRef straightPathPolys[256];
110 status = navMesh->m_navMeshQuery->findStraightPath(m_start, m_end, path, pathCount, (float*)straightPath.data(), straightPathFlags.data(), straightPathPolys, &straightPathCount, 256, 0);
111 qCDebug(Log) <<straightPathCount << status;
112 std::vector<RouteStep> steps;
113 steps.reserve(straightPathCount);
114 for (int i = 0; i <straightPathCount; ++i) {
115 qCDebug(Log) << " " << straightPath[i].x << " " <<straightPath[i].y << " " << straightPath[i].z << " " <<straightPathFlags[i];
116 steps.push_back({m_navMesh.transform().mapNavToGeo(straightPath[i]), m_navMesh.transform().mapNavHeightToFloorLevel(straightPath[i].y)});
117 }
118 m_route.setSteps(std::move(steps));
119#endif
120}
121
122#include "moc_routingjob.cpp"
Compiled nav mesh for routing.
Definition navmesh.h:22
void setStart(rcVec3 startPos)
start/end position in nav coordinates
void setRoutingProfile(const RoutingProfile &profile)
routing profile
Q_INVOKABLE float cost(KOSMIndoorRouting::AreaType area) const
Cost factors (>= 1.0) for each area type that is included in the search.
Q_SCRIPTABLE Q_NOREPLY void start()
Q_SCRIPTABLE CaptureState status()
QString path(const QString &relativePath)
bool invokeMethod(QObject *context, Functor &&function, FunctorReturnType *ret)
QueuedConnection
QFuture< void > filter(QThreadPool *pool, Sequence &sequence, KeepFunctor &&filterFunction)
QThread * currentThread()
QThreadPool * globalInstance()
void start(Callable &&callableToRun, int priority)
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 Fri Jul 26 2024 11:57:47 by doxygen 1.11.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.