QGIS API Documentation  3.26.3-Buenos Aires (65e4edfdad)
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 
19 #include "qgis_sip.h"
20 
21 class QgsLineString;
22 class QgsPolygon;
23 class QgsFeedback;
24 
27 class Qgs3DMapScene;
30 
31 namespace Qt3DExtras
32 {
33  class QPhongMaterial;
34 }
35 
36 #include "qgs3dmapsettings.h"
37 #include "qgs3danimationsettings.h"
38 #include "qgs3dtypes.h"
39 #include "qgsaabb.h"
40 #include "qgsray3d.h"
41 
42 #include <Qt3DRender/QCamera>
43 
44 #include <memory>
45 
46 #define SIP_NO_FILE
47 
54 class _3D_EXPORT Qgs3DUtils
55 {
56  public:
57 
63  static QImage captureSceneImage( QgsAbstract3DEngine &engine, Qgs3DMapScene *scene );
64 
73  static QImage captureSceneDepthBuffer( QgsAbstract3DEngine &engine, Qgs3DMapScene *scene );
74 
93  static bool exportAnimation( const Qgs3DAnimationSettings &animationSettings,
94  Qgs3DMapSettings &mapSettings,
95  int framesPerSecond,
96  const QString &outputDirectory,
97  const QString &fileNameTemplate,
98  const QSize &outputSize,
99  QString &error,
100  QgsFeedback *feedback = nullptr
101  );
102 
107  static int maxZoomLevel( double tile0width, double tileResolution, double maxError );
108 
110  static QString altClampingToString( Qgis::AltitudeClamping altClamp );
112  static Qgis::AltitudeClamping altClampingFromString( const QString &str );
113 
115  static QString altBindingToString( Qgis::AltitudeBinding altBind );
117  static Qgis::AltitudeBinding altBindingFromString( const QString &str );
118 
120  static QString cullingModeToString( Qgs3DTypes::CullingMode mode );
122  static Qgs3DTypes::CullingMode cullingModeFromString( const QString &str );
123 
125  static float clampAltitude( const QgsPoint &p, Qgis::AltitudeClamping altClamp, Qgis::AltitudeBinding altBind, float height, const QgsPoint &centroid, const Qgs3DMapSettings &map );
127  static void clampAltitudes( QgsLineString *lineString, Qgis::AltitudeClamping altClamp, Qgis::AltitudeBinding altBind, const QgsPoint &centroid, float height, const Qgs3DMapSettings &map );
129  static bool clampAltitudes( QgsPolygon *polygon, Qgis::AltitudeClamping altClamp, Qgis::AltitudeBinding altBind, float height, const Qgs3DMapSettings &map );
130 
132  static QString matrix4x4toString( const QMatrix4x4 &m );
134  static QMatrix4x4 stringToMatrix4x4( const QString &str );
135 
137  static void extractPointPositions( const QgsFeature &f, const Qgs3DMapSettings &map, Qgis::AltitudeClamping altClamp, QVector<QVector3D> &positions );
138 
143  static bool isCullable( const QgsAABB &bbox, const QMatrix4x4 &viewProjectionMatrix );
144 
146  static QgsVector3D mapToWorldCoordinates( const QgsVector3D &mapCoords, const QgsVector3D &origin );
148  static QgsVector3D worldToMapCoordinates( const QgsVector3D &worldCoords, const QgsVector3D &origin );
149 
154  static QgsAABB layerToWorldExtent( const QgsRectangle &extent, double zMin, double zMax, const QgsCoordinateReferenceSystem &layerCrs, const QgsVector3D &mapOrigin, const QgsCoordinateReferenceSystem &mapCrs, const QgsCoordinateTransformContext &context );
155 
160  static QgsRectangle worldToLayerExtent( const QgsAABB &bbox, const QgsCoordinateReferenceSystem &layerCrs, const QgsVector3D &mapOrigin, const QgsCoordinateReferenceSystem &mapCrs, const QgsCoordinateTransformContext &context );
161 
166  static QgsAABB mapToWorldExtent( const QgsRectangle &extent, double zMin, double zMax, const QgsVector3D &mapOrigin );
167 
172  static QgsRectangle worldToMapExtent( const QgsAABB &bbox, const QgsVector3D &mapOrigin );
173 
175  static QgsVector3D transformWorldCoordinates( const QgsVector3D &worldPoint1, const QgsVector3D &origin1, const QgsCoordinateReferenceSystem &crs1, const QgsVector3D &origin2, const QgsCoordinateReferenceSystem &crs2,
176  const QgsCoordinateTransformContext &context );
177 
185  static void estimateVectorLayerZRange( QgsVectorLayer *layer, double &zMin, double &zMax );
186 
188  static QgsExpressionContext globalProjectLayerExpressionContext( QgsVectorLayer *layer );
189 
191  static QgsPhongMaterialSettings phongMaterialFromQt3DComponent( Qt3DExtras::QPhongMaterial *material );
192 
194  static QgsRay3D rayFromScreenPoint( const QPoint &point, const QSize &windowSize, Qt3DRender::QCamera *camera );
195 
200  static QVector3D screenPointToWorldPos( const QPoint &screenPoint, double depth, const QSize &screenSize, Qt3DRender::QCamera *camera );
201 
206  static void pitchAndYawFromViewVector( QVector3D vect, double &pitch, double &yaw );
207 
214  static QVector2D screenToTextureCoordinates( QVector2D screenXY, QSize winSize );
215 
222  static QVector2D textureToScreenCoordinates( QVector2D textureXY, QSize winSize );
223 
230  static double decodeDepth( const QRgb &pixel )
231  {
232  return ( ( qRed( pixel ) / 255.0 + qGreen( pixel ) ) / 255.0 + qBlue( pixel ) ) / 255.0;
233  }
234 
240  static std::unique_ptr< QgsPointCloudLayer3DRenderer > convert2DPointCloudRendererTo3D( QgsPointCloudRenderer *renderer );
241 };
242 
243 #endif // QGS3DUTILS_H
QgsExpressionContext
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
Definition: qgsexpressioncontext.h:406
QgsCoordinateTransformContext
Contains information about the context in which a coordinate transform is executed.
Definition: qgscoordinatetransformcontext.h:57
qgs3danimationsettings.h
QgsPolygon
Polygon geometry type.
Definition: qgspolygon.h:33
QgsPoint
Point geometry type, with support for z-dimension and m-values.
Definition: qgspoint.h:48
QgsMeshUtils::centroid
CORE_EXPORT QgsMeshVertex centroid(const QgsMeshFace &face, const QVector< QgsMeshVertex > &vertices)
Returns the centroid of the face.
Definition: qgstriangularmesh.cpp:955
qgsaabb.h
QgsVector3D
Class for storage of 3D vectors similar to QVector3D, with the difference that it uses double precisi...
Definition: qgsvector3d.h:31
QgsLineString
Line string geometry type, with support for z-dimension and m-values.
Definition: qgslinestring.h:44
QgsRectangle
A rectangle specified with double values.
Definition: qgsrectangle.h:41
QgsPhongMaterialSettings
Basic shading material used for rendering based on the Phong shading model with three color component...
Definition: qgsphongmaterialsettings.h:44
QgsAbstract3DSymbol
Abstract base class for 3D symbols that are used by VectorLayer3DRenderer objects.
Definition: qgsabstract3dsymbol.h:46
Qgs3DTypes::CullingMode
CullingMode
Triangle culling mode.
Definition: qgs3dtypes.h:48
Qgis::AltitudeBinding
AltitudeBinding
Altitude binding.
Definition: qgis.h:1770
QgsRay3D
A representation of a ray in 3D.
Definition: qgsray3d.h:30
QgsFeedback
Base class for feedback objects to be used for cancellation of something running in a worker thread.
Definition: qgsfeedback.h:44
qgsray3d.h
qgis_sip.h
QgsAABB
Axis-aligned bounding box - in world coords.
Definition: qgsaabb.h:33
qgs3dtypes.h
Qgs3DMapSettings
Definition of the world.
Definition: qgs3dmapsettings.h:57
QgsAbstract3DEngine
Base class for 3D engine implementation. A 3D engine is responsible for setting up rendering with Qt3...
Definition: qgsabstract3dengine.h:60
QgsCoordinateReferenceSystem
This class represents a coordinate reference system (CRS).
Definition: qgscoordinatereferencesystem.h:211
Qgs3DMapScene
Entity that encapsulates our 3D scene - contains all other entities (such as terrain) as children.
Definition: qgs3dmapscene.h:70
qgs3dmapsettings.h
Qgs3DUtils::decodeDepth
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:230
str
#define str(x)
Definition: qgis.cpp:37
QgsVectorLayer
Represents a vector layer which manages a vector based data sets.
Definition: qgsvectorlayer.h:391
QgsPointCloudRenderer
Abstract base class for 2d point cloud renderers.
Definition: qgspointcloudrenderer.h:296
Qgs3DUtils
Miscellaneous utility functions used from 3D code.
Definition: qgs3dutils.h:54
Qgs3DAnimationSettings
Class that holds information about animation in 3D view. The animation is defined as a series of keyf...
Definition: qgs3danimationsettings.h:38
QgsFeature
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
Definition: qgsfeature.h:55
QgsPointCloudLayer3DRenderer
3D renderer that renders all points from a point cloud layer
Definition: qgspointcloudlayer3drenderer.h:228
Qgis::AltitudeClamping
AltitudeClamping
Altitude clamping.
Definition: qgis.h:1757
Qt3DExtras
Definition: qgs3dmapscene.h:41