QGIS API Documentation 3.41.0-Master (3440c17df1d)
Loading...
Searching...
No Matches
qgs3dutils.h
Go to the documentation of this file.
1/***************************************************************************
2 qgs3dutils.h
3 --------------------------------------
4 Date : July 2017
5 Copyright : (C) 2017 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 QGS3DUTILS_H
17#define QGS3DUTILS_H
18
19class QgsLineString;
20class QgsPolygon;
21class QgsFeedback;
22
25class Qgs3DMapScene;
28
29namespace Qt3DExtras
30{
31 class QPhongMaterial;
32}
33
34class QSurface;
35
36#include "qgs3dmapsettings.h"
38#include "qgs3dtypes.h"
39#include "qgsaabb.h"
40#include "qgsray3d.h"
41#include "qgsraycastingutils.h"
42
43#include <QSize>
44#include <Qt3DRender/QCamera>
45#include <Qt3DRender/QCullFace>
46
47#include <memory>
48
49#define SIP_NO_FILE
50
52
58class _3D_EXPORT Qgs3DUtils
59{
60 public:
61
67 static QImage captureSceneImage( QgsAbstract3DEngine &engine, Qgs3DMapScene *scene );
68
77 static QImage captureSceneDepthBuffer( QgsAbstract3DEngine &engine, Qgs3DMapScene *scene );
78
84 static double calculateEntityGpuMemorySize( Qt3DCore::QEntity *entity );
85
104 static bool exportAnimation( const Qgs3DAnimationSettings &animationSettings,
105 Qgs3DMapSettings &mapSettings,
106 int framesPerSecond,
107 const QString &outputDirectory,
108 const QString &fileNameTemplate,
109 const QSize &outputSize,
110 QString &error,
111 QgsFeedback *feedback = nullptr
112 );
113
118 static int maxZoomLevel( double tile0width, double tileResolution, double maxError );
119
121 static QString altClampingToString( Qgis::AltitudeClamping altClamp );
123 static Qgis::AltitudeClamping altClampingFromString( const QString &str );
124
126 static QString altBindingToString( Qgis::AltitudeBinding altBind );
128 static Qgis::AltitudeBinding altBindingFromString( const QString &str );
129
131 static QString cullingModeToString( Qgs3DTypes::CullingMode mode );
133 static Qgs3DTypes::CullingMode cullingModeFromString( const QString &str );
134
136 static float clampAltitude( const QgsPoint &p, Qgis::AltitudeClamping altClamp, Qgis::AltitudeBinding altBind, float offset, const QgsPoint &centroid, const Qgs3DRenderContext &context );
138 static void clampAltitudes( QgsLineString *lineString, Qgis::AltitudeClamping altClamp, Qgis::AltitudeBinding altBind, const QgsPoint &centroid, float offset, const Qgs3DRenderContext &context );
140 static bool clampAltitudes( QgsPolygon *polygon, Qgis::AltitudeClamping altClamp, Qgis::AltitudeBinding altBind, float offset, const Qgs3DRenderContext &context );
141
143 static QString matrix4x4toString( const QMatrix4x4 &m );
145 static QMatrix4x4 stringToMatrix4x4( const QString &str );
146
148 static void extractPointPositions( const QgsFeature &f, const Qgs3DRenderContext &context, const QgsVector3D &chunkOrigin, Qgis::AltitudeClamping altClamp, QVector<QVector3D> &positions );
149
154 static bool isCullable( const QgsAABB &bbox, const QMatrix4x4 &viewProjectionMatrix );
155
157 static QgsVector3D mapToWorldCoordinates( const QgsVector3D &mapCoords, const QgsVector3D &origin );
159 static QgsVector3D worldToMapCoordinates( const QgsVector3D &worldCoords, const QgsVector3D &origin );
160
165 static QgsAABB layerToWorldExtent( const QgsRectangle &extent, double zMin, double zMax, const QgsCoordinateReferenceSystem &layerCrs, const QgsVector3D &mapOrigin, const QgsCoordinateReferenceSystem &mapCrs, const QgsCoordinateTransformContext &context );
166
171 static QgsRectangle worldToLayerExtent( const QgsAABB &bbox, const QgsCoordinateReferenceSystem &layerCrs, const QgsVector3D &mapOrigin, const QgsCoordinateReferenceSystem &mapCrs, const QgsCoordinateTransformContext &context );
172
177 static QgsAABB mapToWorldExtent( const QgsRectangle &extent, double zMin, double zMax, const QgsVector3D &mapOrigin );
178
183 static QgsAABB mapToWorldExtent( const QgsBox3D &box3D, const QgsVector3D &mapOrigin );
184
189 static QgsRectangle worldToMapExtent( const QgsAABB &bbox, const QgsVector3D &mapOrigin );
190
192 static QgsVector3D transformWorldCoordinates( const QgsVector3D &worldPoint1, const QgsVector3D &origin1, const QgsCoordinateReferenceSystem &crs1, const QgsVector3D &origin2, const QgsCoordinateReferenceSystem &crs2,
193 const QgsCoordinateTransformContext &context );
194
202 static void estimateVectorLayerZRange( QgsVectorLayer *layer, double &zMin, double &zMax );
203
205 static QgsExpressionContext globalProjectLayerExpressionContext( QgsVectorLayer *layer );
206
208 static QgsPhongMaterialSettings phongMaterialFromQt3DComponent( Qt3DExtras::QPhongMaterial *material );
209
211 static QgsRay3D rayFromScreenPoint( const QPoint &point, const QSize &windowSize, Qt3DRender::QCamera *camera );
212
217 static QVector3D screenPointToWorldPos( const QPoint &screenPoint, double depth, const QSize &screenSize, Qt3DRender::QCamera *camera );
218
223 static void pitchAndYawFromViewVector( QVector3D vect, double &pitch, double &yaw );
224
231 static QVector2D screenToTextureCoordinates( QVector2D screenXY, QSize winSize );
232
239 static QVector2D textureToScreenCoordinates( QVector2D textureXY, QSize winSize );
240
247 static double decodeDepth( const QRgb &pixel )
248 {
249 return ( ( qRed( pixel ) / 255.0 + qGreen( pixel ) ) / 255.0 + qBlue( pixel ) ) / 255.0;
250 }
251
257 static std::unique_ptr< QgsPointCloudLayer3DRenderer > convert2DPointCloudRendererTo3D( QgsPointCloudRenderer *renderer );
258
266 static QHash<QgsMapLayer *, QVector<QgsRayCastingUtils::RayHit>> castRay( Qgs3DMapScene *scene, const QgsRay3D &ray, const QgsRayCastingUtils::RayCastContext &context );
267
279 static QgsRectangle tryReprojectExtent2D( const QgsRectangle &extent, const QgsCoordinateReferenceSystem &crs1, const QgsCoordinateReferenceSystem &crs2, const QgsCoordinateTransformContext &context );
280
292 static float screenSpaceError( float epsilon, float distance, int screenSize, float fov );
293
306 static void computeBoundingBoxNearFarPlanes( const QgsAABB &bbox, const QMatrix4x4 &viewMatrix, float &fnear, float &ffar );
307
315 static Qt3DRender::QCullFace::CullingMode qt3DcullingMode( Qgs3DTypes::CullingMode mode );
316
325 static QByteArray addDefinesToShaderCode( const QByteArray &shaderCode, const QStringList &defines );
326
335 static QByteArray removeDefinesFromShaderCode( const QByteArray &shaderCode, const QStringList &defines );
336
344 static void decomposeTransformMatrix( const QMatrix4x4 &matrix, QVector3D &translation, QQuaternion &rotation, QVector3D &scale );
345
352 static int openGlMaxClipPlanes( QSurface *surface );
353};
354
355#endif // QGS3DUTILS_H
AltitudeClamping
Altitude clamping.
Definition qgis.h:3699
AltitudeBinding
Altitude binding.
Definition qgis.h:3712
CullingMode
Triangle culling mode.
Definition qgs3dtypes.h:36
static double decodeDepth(const QRgb &pixel)
Decodes the depth value from the pixel's color value The depth value is encoded from OpenGL side (the...
Definition qgs3dutils.h:247
A 3-dimensional box composed of x, y, z coordinates.
Definition qgsbox3d.h:43
This class represents a coordinate reference system (CRS).
Contains information about the context in which a coordinate transform is executed.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
Definition qgsfeature.h:58
Base class for feedback objects to be used for cancellation of something running in a worker thread.
Definition qgsfeedback.h:44
Line string geometry type, with support for z-dimension and m-values.
3D renderer that renders all points from a point cloud layer
Abstract base class for 2d point cloud renderers.
Point geometry type, with support for z-dimension and m-values.
Definition qgspoint.h:49
Polygon geometry type.
Definition qgspolygon.h:33
A representation of a ray in 3D.
Definition qgsray3d.h:31
A rectangle specified with double values.
Class for storage of 3D vectors similar to QVector3D, with the difference that it uses double precisi...
Definition qgsvector3d.h:31
Represents a vector layer which manages a vector based data sets.
#define str(x)
Definition qgis.cpp:39
Helper struct to store ray casting parameters.