QGIS API Documentation  3.12.1-BucureČ™ti (121cc00ff0)
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 
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 
551 std::unique_ptr<QgsAbstract3DSymbol> Qgs3DUtils::symbolForGeometryType( QgsWkbTypes::GeometryType geomType )
552 {
553  switch ( geomType )
554  {
556  return std::unique_ptr<QgsAbstract3DSymbol>( new QgsPoint3DSymbol );
558  return std::unique_ptr<QgsAbstract3DSymbol>( new QgsLine3DSymbol );
560  return std::unique_ptr<QgsAbstract3DSymbol>( new QgsPolygon3DSymbol );
561  default:
562  return nullptr;
563  }
564 }
565 
567 {
568  QgsExpressionContext exprContext;
572  return exprContext;
573 }
574 
575 Qt3DExtras::QPhongMaterial *Qgs3DUtils::phongMaterial( const QgsPhongMaterialSettings &settings )
576 {
577  Qt3DExtras::QPhongMaterial *phong = new Qt3DExtras::QPhongMaterial;
578  phong->setAmbient( settings.ambient() );
579  phong->setDiffuse( settings.diffuse() );
580  phong->setSpecular( settings.specular() );
581  phong->setShininess( settings.shininess() );
582  return phong;
583 }
AltitudeClamping
how to handle altitude of vector features
Definition: qgs3dtypes.h:34
Wrapper for iterator of features from vector data provider or vector layer.
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
A rectangle specified with double values.
Definition: qgsrectangle.h:41
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:551
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.
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
double zAt(int index) const
Returns the z-coordinate of the specified node in the line string.
Q_INVOKABLE QgsWkbTypes::Type wkbType() const FINAL
Returns the WKBType or WKBUnknown in case of error.
#define QgsDebugMsg(str)
Definition: qgslogger.h:38
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:64
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:575
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
A geometry is the spatial representation of a feature.
Definition: qgsgeometry.h:122
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
static bool hasZ(Type type)
Tests whether a WKB type contains the z-dimension.
Definition: qgswkbtypes.h:917
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.
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&#39;s CRS) to axis aligned bounding box in 3D world coordinates.
Definition: qgs3dutils.cpp:465
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:45
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:90
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...
QString toString(int precision=16) const
Returns a string representation of form xmin,ymin : xmax,ymax Coordinates will be truncated to the sp...
This class wraps a request for features to a vector layer (or directly its vector data provider)...
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:85
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.
double yMinimum() const
Returns the y minimum value (bottom side of rectangle).
Definition: qgsrectangle.h:177
double xMaximum() const
Returns the x maximum value (right side of rectangle).
Definition: qgsrectangle.h:162
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:55
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
3 Entity that encapsulates our 3D scene - contains all other entities (such as terrain) as children...
Definition: qgs3dmapscene.h:58
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:450
float yMin
Definition: qgsaabb.h:76
This class represents a coordinate reference system (CRS).
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
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 xMinimum() const
Returns the x minimum value (left side of rectangle).
Definition: qgsrectangle.h:167
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:566
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
double yMaximum() const
Returns the y maximum value (top side of rectangle).
Definition: qgsrectangle.h:172
QgsFeatureIterator getFeatures(const QgsFeatureRequest &request=QgsFeatureRequest()) const FINAL
Queries the layer for features specified in request.
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 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
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
static QgsExpressionContextScope * layerScope(const QgsMapLayer *layer)
Creates a new scope which contains variables and functions relating to a QgsMapLayer.
bool nextFeature(QgsFeature &f)
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.
QgsAbstractGeometry::vertex_iterator vertices_end() const
Returns STL-style iterator pointing to the imaginary vertex after the last vertex of the geometry...
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
QgsAbstractGeometry::vertex_iterator vertices_begin() const
Returns STL-style iterator pointing to the first vertex of the geometry.
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:66
QgsRectangle transformBoundingBox(const QgsRectangle &rectangle, TransformDirection direction=ForwardTransform, bool handle180Crossover=false) const SIP_THROW(QgsCsException)
Transforms a rectangle from the source CRS to the destination CRS.
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