QGIS API Documentation 3.37.0-Master (fdefdf9c27f)
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 class QGeometryRenderer;
43}
44
45
46namespace QgsRayCastingUtils
47{
48
54 class Ray3D
55 {
56 public:
57 Ray3D();
58 explicit Ray3D( QVector3D origin, QVector3D direction = QVector3D( 0.0f, 0.0f, 1.0f ), float distance = 1.0f );
59
60 QVector3D origin() const;
61 void setOrigin( QVector3D value );
62
63 QVector3D direction() const;
64 void setDirection( QVector3D value );
65
66 float distance() const;
67 void setDistance( float distance );
68
69 bool contains( QVector3D point ) const;
70 bool contains( const Ray3D &ray ) const;
71
72 QVector3D point( float t ) const;
73 float projectedDistance( QVector3D point ) const;
74
75 QVector3D project( QVector3D vector ) const;
76
77 float distance( QVector3D point ) const;
78
79 Ray3D &transform( const QMatrix4x4 &matrix );
80 Ray3D transformed( const QMatrix4x4 &matrix ) const;
81
82 // TODO c++20 - replace with = default
83 bool operator==( const Ray3D &other ) const;
84 bool operator!=( const Ray3D &other ) const;
85
86 private:
87 QVector3D m_origin;
88 QVector3D m_direction;
89 float m_distance = 1.0f;
90 };
91
98 bool rayBoxIntersection( const Ray3D &r, const QgsAABB &aabb );
99
105 bool rayTriangleIntersection( const Ray3D &ray,
106 QVector3D a,
107 QVector3D b,
108 QVector3D c,
109 QVector3D &uvw,
110 float &t );
111
118 bool rayMeshIntersection( Qt3DRender::QGeometryRenderer *geometryRenderer,
119 const QgsRayCastingUtils::Ray3D &r,
120 const QMatrix4x4 &worldTransform,
121 QVector3D &intPt,
122 int &triangleIndex );
123
127 struct RayHit
128 {
130 RayHit( const float distance, const QVector3D pos, const QgsFeatureId fid = FID_NULL, const QVariantMap attributes = QVariantMap() )
131 : distance( distance )
132 , pos( pos )
133 , fid( fid )
134 , attributes( attributes )
135 {
136 }
137 float distance;
138 QVector3D pos;
139 QgsFeatureId fid;
140 QVariantMap attributes;
141 };
142
146 struct RayCastContext
147 {
148 RayCastContext( bool singleResult = true, QSize screenSize = QSize(), float maxDistance = 0.f )
149 : singleResult( singleResult )
150 , screenSize( screenSize )
151 , maxDistance( maxDistance )
152 {}
153 bool singleResult;
154 QSize screenSize;
155
160 float maxDistance;
161 };
162}
163
165
166#endif // QGSRAYCASTINGUTILS_P_H
3
Definition: qgsaabb.h:33
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)