QGIS API Documentation  3.16.0-Hannover (43b64b13f3)
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 == QLatin1String( "front" ) )
241  return Qgs3DTypes::Front;
242  else if ( str == QLatin1String( "back" ) )
243  return Qgs3DTypes::Back;
244  else if ( str == QLatin1String( "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 
445 static QgsRectangle _tryReprojectExtent2D( const QgsRectangle &extent, const QgsCoordinateReferenceSystem &crs1, const QgsCoordinateReferenceSystem &crs2, const QgsCoordinateTransformContext &context )
446 {
447  QgsRectangle extentMapCrs( extent );
448  if ( crs1 != crs2 )
449  {
450  // reproject if necessary
451  QgsCoordinateTransform ct( crs1, crs2, context );
452  try
453  {
454  extentMapCrs = ct.transformBoundingBox( extentMapCrs );
455  }
456  catch ( const QgsCsException & )
457  {
458  // bad luck, can't reproject for some reason
459  QgsDebugMsg( QStringLiteral( "3D utils: transformation of extent failed: " ) + extentMapCrs.toString( -1 ) );
460  }
461  }
462  return extentMapCrs;
463 }
464 
465 QgsAABB Qgs3DUtils::layerToWorldExtent( const QgsRectangle &extent, double zMin, double zMax, const QgsCoordinateReferenceSystem &layerCrs, const QgsVector3D &mapOrigin, const QgsCoordinateReferenceSystem &mapCrs, const QgsCoordinateTransformContext &context )
466 {
467  QgsRectangle extentMapCrs( _tryReprojectExtent2D( extent, layerCrs, mapCrs, context ) );
468  return mapToWorldExtent( extentMapCrs, zMin, zMax, mapOrigin );
469 }
470 
472 {
473  QgsRectangle extentMap = worldToMapExtent( bbox, mapOrigin );
474  return _tryReprojectExtent2D( extentMap, mapCrs, layerCrs, context );
475 }
476 
477 QgsAABB Qgs3DUtils::mapToWorldExtent( const QgsRectangle &extent, double zMin, double zMax, const QgsVector3D &mapOrigin )
478 {
479  QgsVector3D extentMin3D( extent.xMinimum(), extent.yMinimum(), zMin );
480  QgsVector3D extentMax3D( extent.xMaximum(), extent.yMaximum(), zMax );
481  QgsVector3D worldExtentMin3D = mapToWorldCoordinates( extentMin3D, mapOrigin );
482  QgsVector3D worldExtentMax3D = mapToWorldCoordinates( extentMax3D, mapOrigin );
483  QgsAABB rootBbox( worldExtentMin3D.x(), worldExtentMin3D.y(), worldExtentMin3D.z(),
484  worldExtentMax3D.x(), worldExtentMax3D.y(), worldExtentMax3D.z() );
485  return rootBbox;
486 }
487 
489 {
490  QgsVector3D worldExtentMin3D = Qgs3DUtils::worldToMapCoordinates( QgsVector3D( bbox.xMin, bbox.yMin, bbox.zMin ), mapOrigin );
491  QgsVector3D worldExtentMax3D = Qgs3DUtils::worldToMapCoordinates( QgsVector3D( bbox.xMax, bbox.yMax, bbox.zMax ), mapOrigin );
492  QgsRectangle extentMap( worldExtentMin3D.x(), worldExtentMin3D.y(), worldExtentMax3D.x(), worldExtentMax3D.y() );
493  // we discard zMin/zMax here because we don't need it
494  return extentMap;
495 }
496 
497 
499 {
500  QgsVector3D mapPoint1 = worldToMapCoordinates( worldPoint1, origin1 );
501  QgsVector3D mapPoint2 = mapPoint1;
502  if ( crs1 != crs2 )
503  {
504  // reproject if necessary
505  QgsCoordinateTransform ct( crs1, crs2, context );
506  try
507  {
508  QgsPointXY pt = ct.transform( QgsPointXY( mapPoint1.x(), mapPoint1.y() ) );
509  mapPoint2.set( pt.x(), pt.y(), mapPoint1.z() );
510  }
511  catch ( const QgsCsException & )
512  {
513  // bad luck, can't reproject for some reason
514  }
515  }
516  return mapToWorldCoordinates( mapPoint2, origin2 );
517 }
518 
519 void Qgs3DUtils::estimateVectorLayerZRange( QgsVectorLayer *layer, double &zMin, double &zMax )
520 {
521  if ( !QgsWkbTypes::hasZ( layer->wkbType() ) )
522  {
523  zMin = 0;
524  zMax = 0;
525  return;
526  }
527 
528  zMin = std::numeric_limits<double>::max();
529  zMax = std::numeric_limits<double>::min();
530 
531  QgsFeature f;
532  QgsFeatureIterator it = layer->getFeatures( QgsFeatureRequest().setNoAttributes().setLimit( 100 ) );
533  while ( it.nextFeature( f ) )
534  {
535  QgsGeometry g = f.geometry();
536  for ( auto vit = g.vertices_begin(); vit != g.vertices_end(); ++vit )
537  {
538  double z = ( *vit ).z();
539  if ( z < zMin ) zMin = z;
540  if ( z > zMax ) zMax = z;
541  }
542  }
543 
544  if ( zMin == std::numeric_limits<double>::max() && zMax == std::numeric_limits<double>::min() )
545  {
546  zMin = 0;
547  zMax = 0;
548  }
549 }
550 
552 {
553  QgsExpressionContext exprContext;
557  return exprContext;
558 }
559 
561 {
562  QgsPhongMaterialSettings settings;
563  settings.setAmbient( material->ambient() );
564  settings.setDiffuse( material->diffuse() );
565  settings.setSpecular( material->specular() );
566  settings.setShininess( material->shininess() );
567  return settings;
568 }
QgsCurve
Abstract base class for curved geometry type.
Definition: qgscurve.h:36
Qgs3DUtils::clampAltitude
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
QgsAbstractGeometry::vertices_end
vertex_iterator vertices_end() const
Returns STL-style iterator pointing to the imaginary vertex after the last vertex of the geometry.
Definition: qgsabstractgeometry.h:924
qgspolygon.h
QgsVectorLayer::getFeatures
QgsFeatureIterator getFeatures(const QgsFeatureRequest &request=QgsFeatureRequest()) const FINAL
Queries the layer for features specified in request.
Definition: qgsvectorlayer.cpp:993
QgsExpressionContext
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
Definition: qgsexpressioncontext.h:370
Qgs3DUtils::maxZoomLevel
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
qgsexpressioncontextutils.h
QgsFeedback::setProgress
void setProgress(double progress)
Sets the current progress for the feedback object.
Definition: qgsfeedback.h:62
Qgs3DTypes::AltitudeBinding
AltitudeBinding
how to handle clamping of vertices of individual features
Definition: qgs3dtypes.h:43
QgsLineString::xAt
double xAt(int index) const override
Returns the x-coordinate of the specified node in the line string.
Definition: qgslinestring.cpp:762
QgsPointXY::y
double y
Definition: qgspointxy.h:48
QgsCoordinateTransformContext
Contains information about the context in which a coordinate transform is executed.
Definition: qgscoordinatetransformcontext.h:58
QgsVectorLayer::wkbType
Q_INVOKABLE QgsWkbTypes::Type wkbType() const FINAL
Returns the WKBType or WKBUnknown in case of error.
Definition: qgsvectorlayer.cpp:664
qgsfeaturerequest.h
Qgs3DTypes::AltClampTerrain
@ AltClampTerrain
Z_final = z_terrain.
Definition: qgs3dtypes.h:38
Qgs3DUtils::mapToWorldCoordinates
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
Qgs3DUtils::exportAnimation
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
QgsPolygon
Polygon geometry type.
Definition: qgspolygon.h:34
QgsExpressionContextUtils::globalScope
static QgsExpressionContextScope * globalScope()
Creates a new scope which contains variables and functions relating to the global QGIS context.
Definition: qgsexpressioncontextutils.cpp:34
qgslinestring.h
Qgs3DAnimationSettings::Keyframe
keyframe definition
Definition: qgs3danimationsettings.h:46
qgsline3dsymbol.h
QgsPoint
Point geometry type, with support for z-dimension and m-values.
Definition: qgspoint.h:38
qgsexpression.h
QgsVector3D::y
double y() const
Returns Y coordinate.
Definition: qgsvector3d.h:51
Qgs3DAnimationSettings::Keyframe::pitch
float pitch
Tilt of the camera in degrees (0 = looking from the top, 90 = looking from the side,...
Definition: qgs3danimationsettings.h:50
QgsOffscreen3DEngine::setRootEntity
void setRootEntity(Qt3DCore::QEntity *root) override
Sets root entity of the 3D scene.
Definition: qgsoffscreen3dengine.cpp:205
QgsCurvePolygon::exteriorRing
const QgsCurve * exteriorRing() const SIP_HOLDGIL
Returns the curve polygon's exterior ring.
Definition: qgscurvepolygon.h:87
QgsVector3D
3 Class for storage of 3D vectors similar to QVector3D, with the difference that it uses double preci...
Definition: qgsvector3d.h:32
Qgs3DAnimationSettings::keyFrames
Keyframes keyFrames() const
Returns keyframes of the animation.
Definition: qgs3danimationsettings.h:59
QgsPointXY::x
Q_GADGET double x
Definition: qgspointxy.h:47
QgsLineString::yAt
double yAt(int index) const override
Returns the y-coordinate of the specified node in the line string.
Definition: qgslinestring.cpp:770
QgsLineString::zAt
double zAt(int index) const
Returns the z-coordinate of the specified node in the line string.
Definition: qgslinestring.h:278
Qgs3DTypes::AltClampRelative
@ AltClampRelative
Z_final = z_terrain + z_geometry.
Definition: qgs3dtypes.h:37
qgsfeatureiterator.h
Qgs3DTypes::AltBindCentroid
@ AltBindCentroid
Clamp just centroid of feature.
Definition: qgs3dtypes.h:45
QgsRectangle::yMinimum
double yMinimum() const SIP_HOLDGIL
Returns the y minimum value (bottom side of rectangle).
Definition: qgsrectangle.h:177
QgsExpressionContextUtils::layerScope
static QgsExpressionContextScope * layerScope(const QgsMapLayer *layer)
Creates a new scope which contains variables and functions relating to a QgsMapLayer.
Definition: qgsexpressioncontextutils.cpp:265
qgsfeature.h
QgsPointXY::setY
void setY(double y) SIP_HOLDGIL
Sets the y value of the point.
Definition: qgspointxy.h:117
QgsFeature::geometry
QgsGeometry geometry
Definition: qgsfeature.h:67
QgsPoint::z
double z
Definition: qgspoint.h:43
Qgs3DUtils::captureSceneImage
static QImage captureSceneImage(QgsAbstract3DEngine &engine, Qgs3DMapScene *scene)
Captures image of the current 3D scene of a 3D engine.
Definition: qgs3dutils.cpp:42
QgsProject::instance
static QgsProject * instance()
Returns the QgsProject singleton instance.
Definition: qgsproject.cpp:468
Qgs3DUtils::worldToMapExtent
static QgsRectangle worldToMapExtent(const QgsAABB &bbox, const QgsVector3D &mapOrigin)
Converts axis aligned bounding box in 3D world coordinates to extent in map coordinates.
Definition: qgs3dutils.cpp:488
Qgs3DUtils::phongMaterialFromQt3DComponent
static QgsPhongMaterialSettings phongMaterialFromQt3DComponent(Qt3DExtras::QPhongMaterial *material)
Returns phong material settings object based on the Qt3D material.
Definition: qgs3dutils.cpp:560
Qgs3DUtils::altBindingFromString
static Qgs3DTypes::AltitudeBinding altBindingFromString(const QString &str)
Converts a string to a value from AltitudeBinding enum.
Definition: qgs3dutils.cpp:218
QgsAbstract3DEngine::imageCaptured
void imageCaptured(const QImage &image)
Emitted after a call to requestCaptureImage() to return the captured image.
QgsPhongMaterialSettings::setSpecular
void setSpecular(const QColor &specular)
Sets specular color component.
Definition: qgsphongmaterialsettings.h:75
QgsDebugMsg
#define QgsDebugMsg(str)
Definition: qgslogger.h:38
QgsVector3D::set
void set(double x, double y, double z)
Sets vector coordinates.
Definition: qgsvector3d.h:56
Qgs3DUtils::worldToLayerExtent
static QgsRectangle worldToLayerExtent(const QgsAABB &bbox, const QgsCoordinateReferenceSystem &layerCrs, const QgsVector3D &mapOrigin, const QgsCoordinateReferenceSystem &mapCrs, const QgsCoordinateTransformContext &context)
Converts axis aligned bounding box in 3D world coordinates to extent in map layer CRS.
Definition: qgs3dutils.cpp:471
QgsLineString
Line string geometry type, with support for z-dimension and m-values.
Definition: qgslinestring.h:44
QgsCoordinateTransform::transform
QgsPointXY transform(const QgsPointXY &point, TransformDirection direction=ForwardTransform) const SIP_THROW(QgsCsException)
Transform the point from the source CRS to the destination CRS.
Definition: qgscoordinatetransform.cpp:239
QgsAABB::zMax
float zMax
Definition: qgsaabb.h:83
QgsAABB::yMin
float yMin
Definition: qgsaabb.h:79
Qgs3DUtils::clampAltitudes
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
QgsPointXY::setX
void setX(double x) SIP_HOLDGIL
Sets the x value of the point.
Definition: qgspointxy.h:107
QgsRectangle
A rectangle specified with double values.
Definition: qgsrectangle.h:42
Qgs3DUtils::stringToMatrix4x4
static QMatrix4x4 stringToMatrix4x4(const QString &str)
Convert a string to a 4x4 transform matrix.
Definition: qgs3dutils.cpp:336
Qgs3DUtils::transformWorldCoordinates
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:498
QgsPointXY::set
void set(double x, double y) SIP_HOLDGIL
Sets the x and y value of the point.
Definition: qgspointxy.h:124
QgsLineString::nCoordinates
int nCoordinates() const override SIP_HOLDGIL
Returns the number of nodes contained in the geometry.
Definition: qgslinestring.cpp:708
Qgs3DMapScene::sceneState
SceneState sceneState() const
Returns the current state of the scene.
Definition: qgs3dmapscene.h:100
Qgs3DMapScene::sceneStateChanged
void sceneStateChanged()
Emitted when the scene's state has changed.
QgsPhongMaterialSettings
3 Basic shading material used for rendering based on the Phong shading model with three color compone...
Definition: qgsphongmaterialsettings.h:37
Qgs3DUtils::globalProjectLayerExpressionContext
static QgsExpressionContext globalProjectLayerExpressionContext(QgsVectorLayer *layer)
Returns expression context for use in preparation of 3D data of a layer.
Definition: qgs3dutils.cpp:551
QgsCurvePolygon::numInteriorRings
int numInteriorRings() const SIP_HOLDGIL
Returns the number of interior rings contained with the curve polygon.
Definition: qgscurvepolygon.h:77
QgsRectangle::xMaximum
double xMaximum() const SIP_HOLDGIL
Returns the x maximum value (right side of rectangle).
Definition: qgsrectangle.h:162
QgsPoint::y
double y
Definition: qgspoint.h:42
QgsFeatureRequest
This class wraps a request for features to a vector layer (or directly its vector data provider).
Definition: qgsfeaturerequest.h:76
Qgs3DTypes::CullingMode
CullingMode
Triangle culling mode.
Definition: qgs3dtypes.h:50
QgsExpressionContextUtils::projectScope
static QgsExpressionContextScope * projectScope(const QgsProject *project)
Creates a new scope which contains variables and functions relating to a QGIS project.
Definition: qgsexpressioncontextutils.cpp:222
Qgs3DUtils::mapToWorldExtent
static QgsAABB mapToWorldExtent(const QgsRectangle &extent, double zMin, double zMax, const QgsVector3D &mapOrigin)
Converts map extent to axis aligned bounding box in 3D world coordinates.
Definition: qgs3dutils.cpp:477
QgsCsException
Custom exception class for Coordinate Reference System related exceptions.
Definition: qgsexception.h:66
Qgs3DTypes::AltBindVertex
@ AltBindVertex
Clamp every vertex of feature.
Definition: qgs3dtypes.h:44
Qgs3DAnimationSettings::Keyframe::dist
float dist
Distance of the camera from the focal point.
Definition: qgs3danimationsettings.h:49
QgsTerrainGenerator::heightAt
virtual float heightAt(double x, double y, const Qgs3DMapSettings &map) const
Returns height at (x,y) in terrain's CRS.
Definition: qgsterraingenerator.cpp:51
QgsVector3D::z
double z() const
Returns Z coordinate.
Definition: qgsvector3d.h:53
qgs3dutils.h
Qgs3DMapScene::cameraController
QgsCameraController * cameraController()
Returns camera controller.
Definition: qgs3dmapscene.h:76
Qgs3DTypes::Front
@ Front
Will render only back faces of triangles.
Definition: qgs3dtypes.h:52
QgsFeedback
Base class for feedback objects to be used for cancellation of something running in a worker thread.
Definition: qgsfeedback.h:44
Qgs3DAnimationSettings::duration
float duration() const
Returns duration of the whole animation in seconds.
Definition: qgs3danimationsettings.cpp:23
Qgs3DUtils::matrix4x4toString
static QString matrix4x4toString(const QMatrix4x4 &m)
Converts a 4x4 transform matrix to a string.
Definition: qgs3dutils.cpp:326
QgsPhongMaterialSettings::setShininess
void setShininess(float shininess)
Sets shininess of the surface.
Definition: qgsphongmaterialsettings.h:77
QgsAbstractGeometry::vertices_begin
vertex_iterator vertices_begin() const
Returns STL-style iterator pointing to the first vertex of the geometry.
Definition: qgsabstractgeometry.h:911
QgsOffscreen3DEngine::setSize
void setSize(QSize s)
Sets the size of the rendering area (in pixels)
Definition: qgsoffscreen3dengine.cpp:107
qgsterraingenerator.h
Qgs3DUtils::altBindingToString
static QString altBindingToString(Qgs3DTypes::AltitudeBinding altBind)
Converts a value from AltitudeBinding enum to a string.
Definition: qgs3dutils.cpp:207
Qgs3DTypes::FrontAndBack
@ FrontAndBack
Will not render anything.
Definition: qgs3dtypes.h:54
qgsexpressionutils.h
QgsAABB::xMin
float xMin
Definition: qgsaabb.h:78
QgsAABB
3 Axis-aligned bounding box - in world coords.
Definition: qgsaabb.h:34
QgsPoint::x
Q_GADGET double x
Definition: qgspoint.h:41
qgsabstract3dengine.h
Qgs3DTypes::AltClampAbsolute
@ AltClampAbsolute
Z_final = z_geometry.
Definition: qgs3dtypes.h:36
Qgs3DMapSettings
3 Definition of the world
Definition: qgs3dmapsettings.h:54
QgsRectangle::xMinimum
double xMinimum() const SIP_HOLDGIL
Returns the x minimum value (left side of rectangle).
Definition: qgsrectangle.h:167
QgsCurvePolygon::interiorRing
const QgsCurve * interiorRing(int i) const SIP_HOLDGIL
Retrieves an interior ring from the curve polygon.
Definition: qgscurvepolygon.h:100
Qgs3DMapSettings::origin
QgsVector3D origin() const
Returns coordinates in map CRS at which 3D scene has origin (0,0,0)
Definition: qgs3dmapsettings.h:86
qgscameracontroller.h
QgsAbstract3DEngine
3 Base class for 3D engine implementation.
Definition: qgsabstract3dengine.h:58
Qgs3DUtils::altClampingToString
static QString altClampingToString(Qgs3DTypes::AltitudeClamping altClamp)
Converts a value from AltitudeClamping enum to a string.
Definition: qgs3dutils.cpp:184
QgsPhongMaterialSettings::setDiffuse
void setDiffuse(const QColor &diffuse)
Sets diffuse color component.
Definition: qgsphongmaterialsettings.h:73
QgsGeometry::constGet
const QgsAbstractGeometry * constGet() const SIP_HOLDGIL
Returns a non-modifiable (const) reference to the underlying abstract geometry primitive.
Definition: qgsgeometry.cpp:128
QgsCameraController::setLookingAtPoint
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),...
Definition: qgscameracontroller.cpp:200
QgsCoordinateReferenceSystem
This class represents a coordinate reference system (CRS).
Definition: qgscoordinatereferencesystem.h:206
Qgs3DUtils::cullingModeFromString
static Qgs3DTypes::CullingMode cullingModeFromString(const QString &str)
Converts a string to a value from CullingMode enum.
Definition: qgs3dutils.cpp:238
QgsAbstractGeometry
Abstract base class for all geometries.
Definition: qgsabstractgeometry.h:74
QgsAbstractGeometry::is3D
bool is3D() const SIP_HOLDGIL
Returns true if the geometry is 3D and contains a z-value.
Definition: qgsabstractgeometry.h:206
Qgs3DUtils::estimateVectorLayerZRange
static void estimateVectorLayerZRange(QgsVectorLayer *layer, double &zMin, double &zMax)
Try to estimate range of Z values used in the given vector layer and store that in zMin and zMax.
Definition: qgs3dutils.cpp:519
Qgs3DMapSettings::terrainGenerator
QgsTerrainGenerator * terrainGenerator() const
Returns terrain generator. It takes care of producing terrain tiles from the input data.
Definition: qgs3dmapsettings.h:272
qgsvectorlayer.h
Qgs3DAnimationSettings::Keyframe::point
QgsVector3D point
Point towards which the camera is looking in 3D world coords.
Definition: qgs3danimationsettings.h:48
QgsPointXY
A class to represent a 2D point.
Definition: qgspointxy.h:44
Qgs3DMapScene
3 Entity that encapsulates our 3D scene - contains all other entities (such as terrain) as children.
Definition: qgs3dmapscene.h:69
Qgs3DTypes::AltitudeClamping
AltitudeClamping
how to handle altitude of vector features
Definition: qgs3dtypes.h:35
QgsFeedback::isCanceled
bool isCanceled() const
Tells whether the operation has been canceled already.
Definition: qgsfeedback.h:53
qgspolygon3dsymbol.h
Qgs3DUtils::altClampingFromString
static Qgs3DTypes::AltitudeClamping altClampingFromString(const QString &str)
Converts a string to a value from AltitudeClamping enum.
Definition: qgs3dutils.cpp:196
QgsLineString::setZAt
void setZAt(int index, double z)
Sets the z-coordinate of the specified node in the line string.
Definition: qgslinestring.h:452
QgsRectangle::yMaximum
double yMaximum() const SIP_HOLDGIL
Returns the y maximum value (top side of rectangle).
Definition: qgsrectangle.h:172
Qgs3DMapScene::Ready
@ Ready
The scene is fully loaded/updated.
Definition: qgs3dmapscene.h:95
Qgs3DTypes::Back
@ Back
Will render only front faces of triangles (recommended when input data are consistent)
Definition: qgs3dtypes.h:53
QgsAbstractGeometry::centroid
virtual QgsPoint centroid() const
Returns the centroid of the geometry.
Definition: qgsabstractgeometry.cpp:167
QgsFeatureIterator::nextFeature
bool nextFeature(QgsFeature &f)
Definition: qgsfeatureiterator.h:374
QgsGeometry
A geometry is the spatial representation of a feature.
Definition: qgsgeometry.h:124
QgsVectorLayer
Represents a vector layer which manages a vector based data sets.
Definition: qgsvectorlayer.h:387
Qgs3DUtils::isCullable
static bool isCullable(const QgsAABB &bbox, const QMatrix4x4 &viewProjectionMatrix)
Returns true if bbox is completely outside the current viewing volume.
Definition: qgs3dutils.cpp:412
qgspoint3dsymbol.h
Qgs3DAnimationSettings::interpolate
Keyframe interpolate(float time) const
Interpolates camera position and rotation at the given point in time.
Definition: qgs3danimationsettings.cpp:28
Qgs3DAnimationSettings::Keyframe::yaw
float yaw
Horizontal rotation around the focal point in degrees.
Definition: qgs3danimationsettings.h:51
QgsAABB::yMax
float yMax
Definition: qgsaabb.h:82
QgsAbstract3DEngine::requestCaptureImage
virtual void requestCaptureImage()=0
Starts a request for an image rendered by the engine.
QgsPhongMaterialSettings::setAmbient
void setAmbient(const QColor &ambient)
Sets ambient color component.
Definition: qgsphongmaterialsettings.h:71
Qgs3DAnimationSettings
3 Class that holds information about animation in 3D view.
Definition: qgs3danimationsettings.h:39
Qgs3DUtils::layerToWorldExtent
static QgsAABB layerToWorldExtent(const QgsRectangle &extent, double zMin, double zMax, const QgsCoordinateReferenceSystem &layerCrs, const QgsVector3D &mapOrigin, const QgsCoordinateReferenceSystem &mapCrs, const QgsCoordinateTransformContext &context)
Converts extent (in map layer's CRS) to axis aligned bounding box in 3D world coordinates.
Definition: qgs3dutils.cpp:465
QgsWkbTypes::hasZ
static bool hasZ(Type type) SIP_HOLDGIL
Tests whether a WKB type contains the z-dimension.
Definition: qgswkbtypes.h:1043
qgsoffscreen3dengine.h
Qgs3DUtils::worldToMapCoordinates
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
QgsFeature
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Definition: qgsfeature.h:56
Qgs3DUtils::extractPointPositions
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
QgsGeometry::vertices_end
QgsAbstractGeometry::vertex_iterator vertices_end() const
Returns STL-style iterator pointing to the imaginary vertex after the last vertex of the geometry.
Definition: qgsgeometry.cpp:1843
Qgs3DUtils::cullingModeToString
static QString cullingModeToString(Qgs3DTypes::CullingMode mode)
Converts a value from CullingMode enum to a string.
Definition: qgs3dutils.cpp:226
QgsGeometry::vertices_begin
QgsAbstractGeometry::vertex_iterator vertices_begin() const
Returns STL-style iterator pointing to the first vertex of the geometry.
Definition: qgsgeometry.cpp:1836
QgsAABB::zMin
float zMin
Definition: qgsaabb.h:80
QgsAABB::xMax
float xMax
Definition: qgsaabb.h:81
QgsCurvePolygon::addZValue
bool addZValue(double zValue=0) override
Adds a z-dimension to the geometry, initialized to a preset value.
Definition: qgscurvepolygon.cpp:1185
QgsCoordinateTransform
Class for doing transforms between two map coordinate systems.
Definition: qgscoordinatetransform.h:53
QgsFeatureIterator
Wrapper for iterator of features from vector data provider or vector layer.
Definition: qgsfeatureiterator.h:265
qgsfeedback.h
QgsVector3D::x
double x() const
Returns X coordinate.
Definition: qgsvector3d.h:49
Qgs3DTypes::NoCulling
@ NoCulling
Will render both front and back faces of triangles.
Definition: qgs3dtypes.h:51
QgsOffscreen3DEngine
3 Off-screen 3D engine implementation.
Definition: qgsoffscreen3dengine.h:65
qgsabstractgeometry.h
qgs3dmapscene.h
Qgs3DMapSettings::terrainVerticalScale
double terrainVerticalScale() const
Returns vertical scale (exaggeration) of terrain.
Definition: qgs3dmapsettings.cpp:439