QGIS API Documentation 3.32.0-Lima (311a8cb8a6)
qgsraycastingutils_p.h
Go to the documentation of this file.
1/***************************************************************************
2 qgsraycastingutils_p.h
3 --------------------------------------
4 Date : June 2018
5 Copyright : (C) 2018 by Martin Dobias
6 Email : wonder dot sk at gmail dot com
7 ***************************************************************************
8 * *
9 * This program is free software; you can redistribute it and/or modify *
10 * it under the terms of the GNU General Public License as published by *
11 * the Free Software Foundation; either version 2 of the License, or *
12 * (at your option) any later version. *
13 * *
14 ***************************************************************************/
15
16#ifndef QGSRAYCASTINGUTILS_P_H
17#define QGSRAYCASTINGUTILS_P_H
18
20
21//
22// W A R N I N G
23// -------------
24//
25// This file is not part of the QGIS API. It exists purely as an
26// implementation detail. This header file may change from version to
27// version without notice, or even be removed.
28//
29
30#include "qgsfeatureid.h"
31#include <QSize>
32#include <QVariantMap>
33#include <QVector3D>
34
35#define SIP_NO_FILE
36
37class QgsAABB;
38
39namespace Qt3DRender
40{
41 class QCamera;
42}
43
44
45namespace QgsRayCastingUtils
46{
47
53 class Ray3D
54 {
55 public:
56 Ray3D();
57 explicit Ray3D( QVector3D origin, QVector3D direction = QVector3D( 0.0f, 0.0f, 1.0f ), float distance = 1.0f );
58
59 QVector3D origin() const;
60 void setOrigin( QVector3D value );
61
62 QVector3D direction() const;
63 void setDirection( QVector3D value );
64
65 float distance() const;
66 void setDistance( float distance );
67
68 bool contains( QVector3D point ) const;
69 bool contains( const Ray3D &ray ) const;
70
71 QVector3D point( float t ) const;
72 float projectedDistance( QVector3D point ) const;
73
74 QVector3D project( QVector3D vector ) const;
75
76 float distance( QVector3D point ) const;
77
78 Ray3D &transform( const QMatrix4x4 &matrix );
79 Ray3D transformed( const QMatrix4x4 &matrix ) const;
80
81 // TODO c++20 - replace with = default
82 bool operator==( const Ray3D &other ) const;
83 bool operator!=( const Ray3D &other ) const;
84
85 private:
86 QVector3D m_origin;
87 QVector3D m_direction;
88 float m_distance = 1.0f;
89 };
90
97 bool rayBoxIntersection( const Ray3D &r, const QgsAABB &aabb );
98
104 bool rayTriangleIntersection( const Ray3D &ray,
105 QVector3D a,
106 QVector3D b,
107 QVector3D c,
108 QVector3D &uvw,
109 float &t );
110
114 struct RayHit
115 {
117 RayHit( const float distance, const QVector3D pos, const QgsFeatureId fid = FID_NULL, const QVariantMap attributes = QVariantMap() )
118 : distance( distance )
119 , pos( pos )
120 , fid( fid )
121 , attributes( attributes )
122 {
123 }
124 float distance;
125 QVector3D pos;
126 QgsFeatureId fid;
127 QVariantMap attributes;
128 };
129
133 struct RayCastContext
134 {
135 RayCastContext( bool singleResult = true, QSize screenSize = QSize(), float maxDistance = 0.f )
136 : singleResult( singleResult )
137 , screenSize( screenSize )
138 , maxDistance( maxDistance )
139 {}
140 bool singleResult;
141 QSize screenSize;
142
147 float maxDistance;
148 };
149}
150
152
153#endif // QGSRAYCASTINGUTILS_P_H
3
Definition: qgsaabb.h:34
As part of the API refactoring and improvements which landed in the Processing API was substantially reworked from the x version This was done in order to allow much of the underlying Processing framework to be ported into c
#define FID_NULL
Definition: qgsfeatureid.h:29
qint64 QgsFeatureId
64 bit feature ids negative numbers are used for uncommitted/newly added features
Definition: qgsfeatureid.h:28
bool operator==(const QgsFeatureIterator &fi1, const QgsFeatureIterator &fi2)
bool operator!=(const QgsFeatureIterator &fi1, const QgsFeatureIterator &fi2)