QGIS API Documentation  3.10.0-A Coruña (6c816b4204)
qgs3dutils.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgs3dutils.cpp
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 #include "qgs3dutils.h"
17 
18 #include "qgslinestring.h"
19 #include "qgspolygon.h"
20 #include "qgsfeaturerequest.h"
21 #include "qgsfeatureiterator.h"
22 #include "qgsfeature.h"
23 #include "qgsabstractgeometry.h"
24 #include "qgsvectorlayer.h"
26 #include "qgsfeedback.h"
27 #include "qgsexpression.h"
28 #include "qgsexpressionutils.h"
29 #include "qgsoffscreen3dengine.h"
30 
31 #include "qgs3dmapscene.h"
32 #include "qgsabstract3dengine.h"
33 #include "qgsterraingenerator.h"
34 #include "qgscameracontroller.h"
35 
36 #include "qgsline3dsymbol.h"
37 #include "qgspoint3dsymbol.h"
38 #include "qgspolygon3dsymbol.h"
39 
40 #include <Qt3DExtras/QPhongMaterial>
41 
43 {
44  QImage resImage;
45  QEventLoop evLoop;
46 
47  auto requestImageFcn = [&engine, scene]
48  {
49  if ( scene->sceneState() == Qgs3DMapScene::Ready )
50  {
51  engine.requestCaptureImage();
52  }
53  };
54 
55  auto saveImageFcn = [&evLoop, &resImage]( const QImage & img )
56  {
57  resImage = img;
58  evLoop.quit();
59  };
60 
61  QMetaObject::Connection conn1 = QObject::connect( &engine, &QgsAbstract3DEngine::imageCaptured, saveImageFcn );
62  QMetaObject::Connection conn2;
63 
64  if ( scene->sceneState() == Qgs3DMapScene::Ready )
65  {
66  requestImageFcn();
67  }
68  else
69  {
70  // first wait until scene is loaded
71  conn2 = QObject::connect( scene, &Qgs3DMapScene::sceneStateChanged, requestImageFcn );
72  }
73 
74  evLoop.exec();
75 
76  QObject::disconnect( conn1 );
77  if ( conn2 )
78  QObject::disconnect( conn2 );
79 
80  return resImage;
81 }
82 
83 bool Qgs3DUtils::exportAnimation( const Qgs3DAnimationSettings &animationSettings,
84  const Qgs3DMapSettings &mapSettings,
85  int framesPerSecond,
86  const QString &outputDirectory,
87  const QString &fileNameTemplate,
88  const QSize &outputSize,
89  QString &error,
90  QgsFeedback *feedback
91  )
92 {
93  QgsOffscreen3DEngine engine;
94  engine.setSize( outputSize );
95  Qgs3DMapScene *scene = new Qgs3DMapScene( mapSettings, &engine );
96  engine.setRootEntity( scene );
97 
98  if ( animationSettings.keyFrames().size() < 2 )
99  {
100  error = QObject::tr( "Unable to export 3D animation. Add at least 2 keyframes" );
101  return false;
102  }
103 
104  const float duration = animationSettings.duration(); //in seconds
105  if ( duration <= 0 )
106  {
107  error = QObject::tr( "Unable to export 3D animation (invalid duration)." );
108  return false;
109  }
110 
111  float time = 0;
112  int frameNo = 0;
113  int totalFrames = static_cast<int>( duration * framesPerSecond );
114 
115  if ( fileNameTemplate.isEmpty() )
116  {
117  error = QObject::tr( "Filename template is empty" );
118  return false;
119  }
120 
121  int numberOfDigits = fileNameTemplate.count( QLatin1Char( '#' ) );
122  if ( numberOfDigits < 0 )
123  {
124  error = QObject::tr( "Wrong filename template format (must contain #)" );
125  return false;
126  }
127  const QString token( numberOfDigits, QLatin1Char( '#' ) );
128  if ( !fileNameTemplate.contains( token ) )
129  {
130  error = QObject::tr( "Filename template must contain all # placeholders in one continuous group." );
131  return false;
132  }
133 
134  while ( time <= duration )
135  {
136 
137  if ( feedback )
138  {
139  if ( feedback->isCanceled() )
140  {
141  error = QObject::tr( "Export canceled" );
142  return false;
143  }
144  feedback->setProgress( frameNo / static_cast<double>( totalFrames ) * 100 );
145  }
146  ++frameNo;
147 
148  Qgs3DAnimationSettings::Keyframe kf = animationSettings.interpolate( time );
149  scene->cameraController()->setLookingAtPoint( kf.point, kf.dist, kf.pitch, kf.yaw );
150 
151  QString fileName( fileNameTemplate );
152  const QString frameNoPaddedLeft( QStringLiteral( "%1" ).arg( frameNo, numberOfDigits, 10, QChar( '0' ) ) ); // e.g. 0001
153  fileName.replace( token, frameNoPaddedLeft );
154  const QString path = QDir( outputDirectory ).filePath( fileName );
155 
156  // It would initially return empty rendered image.
157  // Capturing the initial image and throwing it away fixes that.
158  // Hopefully we will find a better fix in the future.
159  Qgs3DUtils::captureSceneImage( engine, scene );
160  QImage img = Qgs3DUtils::captureSceneImage( engine, scene );
161 
162  img.save( path );
163 
164  time += 1.0f / static_cast<float>( framesPerSecond );
165  }
166 
167  return true;
168 }
169 
170 
171 int Qgs3DUtils::maxZoomLevel( double tile0width, double tileResolution, double maxError )
172 {
173  if ( maxError <= 0 || tileResolution <= 0 || tile0width <= 0 )
174  return 0; // invalid input
175 
176  // derived from:
177  // tile width [map units] = tile0width / 2^zoomlevel
178  // tile error [map units] = tile width / tile resolution
179  // + re-arranging to get zoom level if we know tile error we want to get
180  double zoomLevel = -log( tileResolution * maxError / tile0width ) / log( 2 );
181  return round( zoomLevel ); // we could use ceil() here if we wanted to always get to the desired error
182 }
183 
185 {
186  switch ( altClamp )
187  {
188  case Qgs3DTypes::AltClampAbsolute: return QStringLiteral( "absolute" );
189  case Qgs3DTypes::AltClampRelative: return QStringLiteral( "relative" );
190  case Qgs3DTypes::AltClampTerrain: return QStringLiteral( "terrain" );
191  default: Q_ASSERT( false ); return QString();
192  }
193 }
194 
195 
197 {
198  if ( str == QLatin1String( "absolute" ) )
200  else if ( str == QLatin1String( "terrain" ) )
202  else // "relative" (default)
204 }
205 
206 
208 {
209  switch ( altBind )
210  {
211  case Qgs3DTypes::AltBindVertex: return QStringLiteral( "vertex" );
212  case Qgs3DTypes::AltBindCentroid: return QStringLiteral( "centroid" );
213  default: Q_ASSERT( false ); return QString();
214  }
215 }
216 
217 
219 {
220  if ( str == QLatin1String( "vertex" ) )
222  else // "centroid" (default)
224 }
225 
227 {
228  switch ( mode )
229  {
230  case Qgs3DTypes::NoCulling: return QStringLiteral( "no-culling" );
231  case Qgs3DTypes::Front: return QStringLiteral( "front" );
232  case Qgs3DTypes::Back: return QStringLiteral( "back" );
233  case Qgs3DTypes::FrontAndBack: return QStringLiteral( "front-and-back" );
234  }
235  return QString();
236 }
237 
239 {
240  if ( str == QStringLiteral( "front" ) )
241  return Qgs3DTypes::Front;
242  else if ( str == QStringLiteral( "back" ) )
243  return Qgs3DTypes::Back;
244  else if ( str == QStringLiteral( "front-and-back" ) )
246  else
247  return Qgs3DTypes::NoCulling;
248 }
249 
250 float Qgs3DUtils::clampAltitude( const QgsPoint &p, Qgs3DTypes::AltitudeClamping altClamp, Qgs3DTypes::AltitudeBinding altBind, float height, const QgsPoint &centroid, const Qgs3DMapSettings &map )
251 {
252  float terrainZ = 0;
253  if ( altClamp == Qgs3DTypes::AltClampRelative || altClamp == Qgs3DTypes::AltClampTerrain )
254  {
255  QgsPointXY pt = altBind == Qgs3DTypes::AltBindVertex ? p : centroid;
256  terrainZ = map.terrainGenerator()->heightAt( pt.x(), pt.y(), map );
257  }
258 
259  float geomZ = 0;
260  if ( p.is3D() && ( altClamp == Qgs3DTypes::AltClampAbsolute || altClamp == Qgs3DTypes::AltClampRelative ) )
261  geomZ = p.z();
262 
263  float z = ( terrainZ + geomZ ) * map.terrainVerticalScale() + height;
264  return z;
265 }
266 
267 void Qgs3DUtils::clampAltitudes( QgsLineString *lineString, Qgs3DTypes::AltitudeClamping altClamp, Qgs3DTypes::AltitudeBinding altBind, const QgsPoint &centroid, float height, const Qgs3DMapSettings &map )
268 {
269  for ( int i = 0; i < lineString->nCoordinates(); ++i )
270  {
271  float terrainZ = 0;
272  if ( altClamp == Qgs3DTypes::AltClampRelative || altClamp == Qgs3DTypes::AltClampTerrain )
273  {
274  QgsPointXY pt;
275  if ( altBind == Qgs3DTypes::AltBindVertex )
276  {
277  pt.setX( lineString->xAt( i ) );
278  pt.setY( lineString->yAt( i ) );
279  }
280  else
281  {
282  pt.set( centroid.x(), centroid.y() );
283  }
284  terrainZ = map.terrainGenerator()->heightAt( pt.x(), pt.y(), map );
285  }
286 
287  float geomZ = 0;
288  if ( altClamp == Qgs3DTypes::AltClampAbsolute || altClamp == Qgs3DTypes::AltClampRelative )
289  geomZ = lineString->zAt( i );
290 
291  float z = ( terrainZ + geomZ ) * map.terrainVerticalScale() + height;
292  lineString->setZAt( i, z );
293  }
294 }
295 
296 
298 {
299  if ( !polygon->is3D() )
300  polygon->addZValue( 0 );
301 
302  QgsPoint centroid;
303  if ( altBind == Qgs3DTypes::AltBindCentroid )
304  centroid = polygon->centroid();
305 
306  QgsCurve *curve = const_cast<QgsCurve *>( polygon->exteriorRing() );
307  QgsLineString *lineString = qgsgeometry_cast<QgsLineString *>( curve );
308  if ( !lineString )
309  return false;
310 
311  clampAltitudes( lineString, altClamp, altBind, centroid, height, map );
312 
313  for ( int i = 0; i < polygon->numInteriorRings(); ++i )
314  {
315  QgsCurve *curve = const_cast<QgsCurve *>( polygon->interiorRing( i ) );
316  QgsLineString *lineString = qgsgeometry_cast<QgsLineString *>( curve );
317  if ( !lineString )
318  return false;
319 
320  clampAltitudes( lineString, altClamp, altBind, centroid, height, map );
321  }
322  return true;
323 }
324 
325 
326 QString Qgs3DUtils::matrix4x4toString( const QMatrix4x4 &m )
327 {
328  const float *d = m.constData();
329  QStringList elems;
330  elems.reserve( 16 );
331  for ( int i = 0; i < 16; ++i )
332  elems << QString::number( d[i] );
333  return elems.join( ' ' );
334 }
335 
336 QMatrix4x4 Qgs3DUtils::stringToMatrix4x4( const QString &str )
337 {
338  QMatrix4x4 m;
339  float *d = m.data();
340  QStringList elems = str.split( ' ' );
341  for ( int i = 0; i < 16; ++i )
342  d[i] = elems[i].toFloat();
343  return m;
344 }
345 
346 void Qgs3DUtils::extractPointPositions( QgsFeature &f, const Qgs3DMapSettings &map, Qgs3DTypes::AltitudeClamping altClamp, QVector<QVector3D> &positions )
347 {
348  const QgsAbstractGeometry *g = f.geometry().constGet();
349  for ( auto it = g->vertices_begin(); it != g->vertices_end(); ++it )
350  {
351  QgsPoint pt = *it;
352  float geomZ = 0;
353  if ( pt.is3D() )
354  {
355  geomZ = pt.z();
356  }
357  float terrainZ = map.terrainGenerator()->heightAt( pt.x(), pt.y(), map ) * map.terrainVerticalScale();
358  float h;
359  switch ( altClamp )
360  {
362  default:
363  h = geomZ;
364  break;
366  h = terrainZ;
367  break;
369  h = terrainZ + geomZ;
370  break;
371  }
372  positions.append( QVector3D( pt.x() - map.origin().x(), h, -( pt.y() - map.origin().y() ) ) );
373  //qDebug() << positions.last();
374  }
375 }
376 
382 static inline uint outcode( QVector4D v )
383 {
384  // For a discussion of outcodes see pg 388 Dunn & Parberry.
385  // For why you can't just test if the point is in a bounding box
386  // consider the case where a view frustum with view-size 1.5 x 1.5
387  // is tested against a 2x2 box which encloses the near-plane, while
388  // all the points in the box are outside the frustum.
389  // TODO: optimise this with assembler - according to D&P this can
390  // be done in one line of assembler on some platforms
391  uint code = 0;
392  if ( v.x() < -v.w() ) code |= 0x01;
393  if ( v.x() > v.w() ) code |= 0x02;
394  if ( v.y() < -v.w() ) code |= 0x04;
395  if ( v.y() > v.w() ) code |= 0x08;
396  if ( v.z() < -v.w() ) code |= 0x10;
397  if ( v.z() > v.w() ) code |= 0x20;
398  return code;
399 }
400 
401 
412 bool Qgs3DUtils::isCullable( const QgsAABB &bbox, const QMatrix4x4 &viewProjectionMatrix )
413 {
414  uint out = 0xff;
415 
416  for ( int i = 0; i < 8; ++i )
417  {
418  QVector4D p( ( ( i >> 0 ) & 1 ) ? bbox.xMin : bbox.xMax,
419  ( ( i >> 1 ) & 1 ) ? bbox.yMin : bbox.yMax,
420  ( ( i >> 2 ) & 1 ) ? bbox.zMin : bbox.zMax, 1 );
421  QVector4D pc = viewProjectionMatrix * p;
422 
423  // if the logical AND of all the outcodes is non-zero then the BB is
424  // definitely outside the view frustum.
425  out = out & outcode( pc );
426  }
427  return out;
428 }
429 
431 {
432  return QgsVector3D( mapCoords.x() - origin.x(),
433  mapCoords.z() - origin.z(),
434  -( mapCoords.y() - origin.y() ) );
435 
436 }
437 
439 {
440  return QgsVector3D( worldCoords.x() + origin.x(),
441  -worldCoords.z() + origin.y(),
442  worldCoords.y() + origin.z() );
443 }
444 
446 {
447  QgsVector3D mapPoint1 = worldToMapCoordinates( worldPoint1, origin1 );
448  QgsVector3D mapPoint2 = mapPoint1;
449  if ( crs1 != crs2 )
450  {
451  // reproject if necessary
452  QgsCoordinateTransform ct( crs1, crs2, context );
453  try
454  {
455  QgsPointXY pt = ct.transform( QgsPointXY( mapPoint1.x(), mapPoint1.y() ) );
456  mapPoint2.set( pt.x(), pt.y(), mapPoint1.z() );
457  }
458  catch ( const QgsCsException & )
459  {
460  // bad luck, can't reproject for some reason
461  }
462  }
463  return mapToWorldCoordinates( mapPoint2, origin2 );
464 }
465 
466 std::unique_ptr<QgsAbstract3DSymbol> Qgs3DUtils::symbolForGeometryType( QgsWkbTypes::GeometryType geomType )
467 {
468  switch ( geomType )
469  {
471  return std::unique_ptr<QgsAbstract3DSymbol>( new QgsPoint3DSymbol );
473  return std::unique_ptr<QgsAbstract3DSymbol>( new QgsLine3DSymbol );
475  return std::unique_ptr<QgsAbstract3DSymbol>( new QgsPolygon3DSymbol );
476  default:
477  return nullptr;
478  }
479 }
480 
482 {
483  QgsExpressionContext exprContext;
487  return exprContext;
488 }
489 
490 Qt3DExtras::QPhongMaterial *Qgs3DUtils::phongMaterial( const QgsPhongMaterialSettings &settings )
491 {
492  Qt3DExtras::QPhongMaterial *phong = new Qt3DExtras::QPhongMaterial;
493  phong->setAmbient( settings.ambient() );
494  phong->setDiffuse( settings.diffuse() );
495  phong->setSpecular( settings.specular() );
496  phong->setShininess( settings.shininess() );
497  return phong;
498 }
AltitudeClamping
how to handle altitude of vector features
Definition: qgs3dtypes.h:34
3 Class for storage of 3D vectors similar to QVector3D, with the difference that it uses double preci...
Definition: qgsvector3d.h:31
3 Axis-aligned bounding box - in world coords.
Definition: qgsaabb.h:30
void set(double x, double y)
Sets the x and y value of the point.
Definition: qgspointxy.h:124
float shininess() const
Returns shininess of the surface.
double y
Definition: qgspoint.h:42
static std::unique_ptr< QgsAbstract3DSymbol > symbolForGeometryType(QgsWkbTypes::GeometryType geomType)
Returns a new 3D symbol based on given geometry type (or nullptr if geometry type is not supported) ...
Definition: qgs3dutils.cpp:466
static QString altClampingToString(Qgs3DTypes::AltitudeClamping altClamp)
Converts a value from AltitudeClamping enum to a string.
Definition: qgs3dutils.cpp:184
static Qgs3DTypes::CullingMode cullingModeFromString(const QString &str)
Converts a string to a value from CullingMode enum.
Definition: qgs3dutils.cpp:238
virtual float heightAt(double x, double y, const Qgs3DMapSettings &map) const
Returns height at (x,y) in terrain&#39;s CRS.
double zAt(int index) const
Returns the z-coordinate of the specified node in the line string.
QgsPointXY transform(const QgsPointXY &point, TransformDirection direction=ForwardTransform) const SIP_THROW(QgsCsException)
Transform the point from the source CRS to the destination CRS.
QColor specular() const
Returns specular color component.
double y
Definition: qgspointxy.h:48
A class to represent a 2D point.
Definition: qgspointxy.h:43
void setProgress(double progress)
Sets the current progress for the feedback object.
Definition: qgsfeedback.h:63
const QgsCurve * interiorRing(int i) const
Retrieves an interior ring from the curve polygon.
static Qt3DExtras::QPhongMaterial * phongMaterial(const QgsPhongMaterialSettings &settings)
Returns phong material object based on the material settings.
Definition: qgs3dutils.cpp:490
float zMax
Definition: qgsaabb.h:80
3 3D symbol that draws polygon geometries as planar polygons, optionally extruded (with added walls)...
CullingMode
Triangle culling mode.
Definition: qgs3dtypes.h:49
static Qgs3DTypes::AltitudeClamping altClampingFromString(const QString &str)
Converts a string to a value from AltitudeClamping enum.
Definition: qgs3dutils.cpp:196
static QgsExpressionContextScope * projectScope(const QgsProject *project)
Creates a new scope which contains variables and functions relating to a QGIS project.
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Definition: qgsfeature.h:55
static bool isCullable(const QgsAABB &bbox, const QMatrix4x4 &viewProjectionMatrix)
Returns true if bbox is completely outside the current viewing volume.
Definition: qgs3dutils.cpp:412
Will not render anything.
Definition: qgs3dtypes.h:54
3 Basic shading material used for rendering based on the Phong shading model with three color compone...
double y() const
Returns Y coordinate.
Definition: qgsvector3d.h:51
3 Definition of the world
Z_final = z_geometry.
Definition: qgs3dtypes.h:36
void set(double x, double y, double z)
Sets vector coordinates.
Definition: qgsvector3d.h:56
QgsVector3D origin() const
Returns coordinates in map CRS at which 3D scene has origin (0,0,0)
virtual QgsPoint centroid() const
Returns the centroid of the geometry.
Clamp every vertex of feature.
Definition: qgs3dtypes.h:44
Base class for feedback objects to be used for cancellation of something running in a worker thread...
Definition: qgsfeedback.h:44
float zMin
Definition: qgsaabb.h:77
int numInteriorRings() const
Returns the number of interior rings contained with the curve polygon.
Will render only front faces of triangles (recommended when input data are consistent) ...
Definition: qgs3dtypes.h:53
double z() const
Returns Z coordinate.
Definition: qgsvector3d.h:53
static QgsVector3D worldToMapCoordinates(const QgsVector3D &worldCoords, const QgsVector3D &origin)
Converts 3D world coordinates to map coordinates (applies offset and turns (x,y,z) into (x...
Definition: qgs3dutils.cpp:438
static QgsExpressionContextScope * globalScope()
Creates a new scope which contains variables and functions relating to the global QGIS context...
void setRootEntity(Qt3DCore::QEntity *root) override
Sets root entity of the 3D scene.
float yMax
Definition: qgsaabb.h:79
static void extractPointPositions(QgsFeature &f, const Qgs3DMapSettings &map, Qgs3DTypes::AltitudeClamping altClamp, QVector< QVector3D > &positions)
Calculates (x,y,z) positions of (multi)point from the given feature.
Definition: qgs3dutils.cpp:346
static QString cullingModeToString(Qgs3DTypes::CullingMode mode)
Converts a value from CullingMode enum to a string.
Definition: qgs3dutils.cpp:226
Will render only back faces of triangles.
Definition: qgs3dtypes.h:52
Will render both front and back faces of triangles.
Definition: qgs3dtypes.h:51
Keyframe interpolate(float time) const
Interpolates camera position and rotation at the given point in time.
Keyframes keyFrames() const
Returns keyframes of the animation.
3 3D symbol that draws point geometries as 3D objects using one of the predefined shapes...
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
3 Off-screen 3D engine implementation.
SceneState sceneState() const
Returns the current state of the scene.
Definition: qgs3dmapscene.h:80
virtual void requestCaptureImage()=0
Starts a request for an image rendered by the engine.
void setSize(QSize s)
Sets the size of the rendering area (in pixels)
double yAt(int index) const override
Returns the y-coordinate of the specified node in the line string.
void setY(double y)
Sets the y value of the point.
Definition: qgspointxy.h:117
vertex_iterator vertices_end() const
Returns STL-style iterator pointing to the imaginary vertex after the last vertex of the geometry...
T qgsgeometry_cast(const QgsAbstractGeometry *geom)
QgsVector3D point
Point towards which the camera is looking in 3D world coords.
static QgsVector3D mapToWorldCoordinates(const QgsVector3D &mapCoords, const QgsVector3D &origin)
Converts map coordinates to 3D world coordinates (applies offset and turns (x,y,z) into (x...
Definition: qgs3dutils.cpp:430
3 Base class for 3D engine implementation.
static bool exportAnimation(const Qgs3DAnimationSettings &animationSettings, const Qgs3DMapSettings &mapSettings, int framesPerSecond, const QString &outputDirectory, const QString &fileNameTemplate, const QSize &outputSize, QString &error, QgsFeedback *feedback=nullptr)
Captures 3D animation frames to the selected folder.
Definition: qgs3dutils.cpp:83
static float clampAltitude(const QgsPoint &p, Qgs3DTypes::AltitudeClamping altClamp, Qgs3DTypes::AltitudeBinding altBind, float height, const QgsPoint &centroid, const Qgs3DMapSettings &map)
Clamps altitude of a vertex according to the settings, returns Z value.
Definition: qgs3dutils.cpp:250
Abstract base class for curved geometry type.
Definition: qgscurve.h:35
3 Class that holds information about animation in 3D view.
3 3D symbol that draws linestring geometries as planar polygons (created from lines using a buffer wi...
The scene is fully loaded/updated.
Definition: qgs3dmapscene.h:75
float dist
Distance of the camera from the focal point.
Abstract base class for all geometries.
Contains information about the context in which a coordinate transform is executed.
static int maxZoomLevel(double tile0width, double tileResolution, double maxError)
Calculates the highest needed zoom level for tiles in quad-tree given width of the base tile (zoom le...
Definition: qgs3dutils.cpp:171
void setZAt(int index, double z)
Sets the z-coordinate of the specified node in the line string.
Point geometry type, with support for z-dimension and m-values.
Definition: qgspoint.h:37
AltitudeBinding
how to handle clamping of vertices of individual features
Definition: qgs3dtypes.h:42
float xMin
Definition: qgsaabb.h:75
void setX(double x)
Sets the x value of the point.
Definition: qgspointxy.h:107
double x
Definition: qgspointxy.h:47
double terrainVerticalScale() const
Returns vertical scale (exaggeration) of terrain.
const QgsAbstractGeometry * constGet() const
Returns a non-modifiable (const) reference to the underlying abstract geometry primitive.
static QImage captureSceneImage(QgsAbstract3DEngine &engine, Qgs3DMapScene *scene)
Captures image of the current 3D scene of a 3D engine.
Definition: qgs3dutils.cpp:42
GeometryType
The geometry types are used to group QgsWkbTypes::Type in a coarse way.
Definition: qgswkbtypes.h:139
float xMax
Definition: qgsaabb.h:78
bool isCanceled() const
Tells whether the operation has been canceled already.
Definition: qgsfeedback.h:54
3 Entity that encapsulates our 3D scene - contains all other entities (such as terrain) as children...
Definition: qgs3dmapscene.h:54
void imageCaptured(const QImage &image)
Emitted after a call to requestCaptureImage() to return the captured image.
Z_final = z_terrain.
Definition: qgs3dtypes.h:38
static QMatrix4x4 stringToMatrix4x4(const QString &str)
Convert a string to a 4x4 transform matrix.
Definition: qgs3dutils.cpp:336
Line string geometry type, with support for z-dimension and m-values.
Definition: qgslinestring.h:43
static QgsProject * instance()
Returns the QgsProject singleton instance.
Definition: qgsproject.cpp:442
float yMin
Definition: qgsaabb.h:76
This class represents a coordinate reference system (CRS).
bool addZValue(double zValue=0) override
Adds a z-dimension to the geometry, initialized to a preset value.
void sceneStateChanged()
Emitted when the scene&#39;s state has changed.
static Qgs3DTypes::AltitudeBinding altBindingFromString(const QString &str)
Converts a string to a value from AltitudeBinding enum.
Definition: qgs3dutils.cpp:218
Class for doing transforms between two map coordinate systems.
QColor ambient() const
Returns ambient color component.
double xAt(int index) const override
Returns the x-coordinate of the specified node in the line string.
float yaw
Horizontal rotation around the focal point in degrees.
static QgsExpressionContext globalProjectLayerExpressionContext(QgsVectorLayer *layer)
Returns expression context for use in preparation of 3D data of a layer.
Definition: qgs3dutils.cpp:481
static void clampAltitudes(QgsLineString *lineString, Qgs3DTypes::AltitudeClamping altClamp, Qgs3DTypes::AltitudeBinding altBind, const QgsPoint &centroid, float height, const Qgs3DMapSettings &map)
Clamps altitude of vertices of a linestring according to the settings.
Definition: qgs3dutils.cpp:267
QColor diffuse() const
Returns diffuse color component.
double z
Definition: qgspoint.h:43
QgsGeometry geometry
Definition: qgsfeature.h:67
Custom exception class for Coordinate Reference System related exceptions.
Definition: qgsexception.h:65
vertex_iterator vertices_begin() const
Returns STL-style iterator pointing to the first vertex of the geometry.
static QgsVector3D transformWorldCoordinates(const QgsVector3D &worldPoint1, const QgsVector3D &origin1, const QgsCoordinateReferenceSystem &crs1, const QgsVector3D &origin2, const QgsCoordinateReferenceSystem &crs2, const QgsCoordinateTransformContext &context)
Transforms a world point from (origin1, crs1) to (origin2, crs2)
Definition: qgs3dutils.cpp:445
static QgsExpressionContextScope * layerScope(const QgsMapLayer *layer)
Creates a new scope which contains variables and functions relating to a QgsMapLayer.
Polygon geometry type.
Definition: qgspolygon.h:31
const QgsCurve * exteriorRing() const
Returns the curve polygon&#39;s exterior ring.
int nCoordinates() const override
Returns the number of nodes contained in the geometry.
Represents a vector layer which manages a vector based data sets.
Z_final = z_terrain + z_geometry.
Definition: qgs3dtypes.h:37
static QString matrix4x4toString(const QMatrix4x4 &m)
Converts a 4x4 transform matrix to a string.
Definition: qgs3dutils.cpp:326
void setLookingAtPoint(const QgsVector3D &point, float distance, float pitch, float yaw)
Sets the complete camera configuration: the point towards it is looking (in 3D world coordinates)...
static QString altBindingToString(Qgs3DTypes::AltitudeBinding altBind)
Converts a value from AltitudeBinding enum to a string.
Definition: qgs3dutils.cpp:207
bool is3D() const
Returns true if the geometry is 3D and contains a z-value.
Clamp just centroid of feature.
Definition: qgs3dtypes.h:45
QgsCameraController * cameraController()
Returns camera controller.
Definition: qgs3dmapscene.h:62
double x() const
Returns X coordinate.
Definition: qgsvector3d.h:49
float pitch
Tilt of the camera in degrees (0 = looking from the top, 90 = looking from the side, 180 = looking from the bottom)
float duration() const
Returns duration of the whole animation in seconds.
QgsTerrainGenerator * terrainGenerator() const
Returns terrain generator. It takes care of producing terrain tiles from the input data...
double x
Definition: qgspoint.h:41