QGIS API Documentation 3.99.0-Master (2fe06baccd8)
Loading...
Searching...
No Matches
qgstiledsceneboundingvolume.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgstiledsceneboundingvolume.cpp
3 --------------------
4 begin : July 2023
5 copyright : (C) 2023 by Nyall Dawson
6 email : nyall dot dawson at gmail dot com
7 ***************************************************************************/
8
9/***************************************************************************
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 ***************************************************************************/
17
19
21#include "qgsgeos.h"
22#include "qgsmatrix4x4.h"
23#include "qgsmultipoint.h"
24#include "qgspolygon.h"
25#include "qgsvector3d.h"
26
31
33{
34 mBox = mBox.transformed( transform );
35}
36
38{
39 if ( transform.isValid() && !transform.isShortCircuited() )
40 {
41 const QVector< QgsVector3D > corners = mBox.corners();
42 QVector< double > x;
43 x.reserve( 8 );
44 QVector< double > y;
45 y.reserve( 8 );
46 QVector< double > z;
47 z.reserve( 8 );
48 for ( int i = 0; i < 8; ++i )
49 {
50 const QgsVector3D &corner = corners[i];
51 x.append( corner.x() );
52 y.append( corner.y() );
53 z.append( corner.z() );
54 }
55 transform.transformInPlace( x, y, z, direction );
56
57 const auto minMaxX = std::minmax_element( x.constBegin(), x.constEnd() );
58 const auto minMaxY = std::minmax_element( y.constBegin(), y.constEnd() );
59 const auto minMaxZ = std::minmax_element( z.constBegin(), z.constEnd() );
60 return QgsBox3D( *minMaxX.first, *minMaxY.first, *minMaxZ.first, *minMaxX.second, *minMaxY.second, *minMaxZ.second );
61 }
62 else
63 {
64 return mBox.extent();
65 }
66}
67
69{
70 auto polygon = std::make_unique< QgsPolygon >();
71
72 const QVector< QgsVector3D > corners = mBox.corners();
73 QVector< double > x;
74 x.reserve( 8 );
75 QVector< double > y;
76 y.reserve( 8 );
77 QVector< double > z;
78 z.reserve( 8 );
79 for ( int i = 0; i < 8; ++i )
80 {
81 const QgsVector3D &corner = corners[i];
82 x.append( corner.x() );
83 y.append( corner.y() );
84 z.append( corner.z() );
85 }
86
87 if ( transform.isValid() && !transform.isShortCircuited() )
88 {
89 transform.transformInPlace( x, y, z, direction );
90 }
91
92 auto mp = std::make_unique< QgsMultiPoint >( x, y );
93 QgsGeos geosMp( mp.get() );
94 return geosMp.convexHull();
95}
96
98{
99 return mBox.intersects( box );
100}
101
TransformDirection
Indicates the direction (forward or inverse) of a transform.
Definition qgis.h:2671
Abstract base class for all geometries.
A 3-dimensional box composed of x, y, z coordinates.
Definition qgsbox3d.h:42
Handles coordinate transforms between two coordinate systems.
Does vector analysis using the GEOS library and handles import, export, and exception handling.
Definition qgsgeos.h:141
QgsAbstractGeometry * convexHull(QString *errorMsg=nullptr) const override
Calculate the convex hull of this.
Definition qgsgeos.cpp:2232
A simple 4x4 matrix implementation useful for transformation in 3D space.
Represents a oriented (rotated) box in 3 dimensions.
QgsOrientedBox3D box() const
Returns the volume's oriented box.
bool intersects(const QgsOrientedBox3D &box) const
Returns true if this bounds intersects the specified box.
QgsTiledSceneBoundingVolume(const QgsOrientedBox3D &box=QgsOrientedBox3D())
Constructor for QgsTiledSceneBoundingVolume, with the specified oriented box.
void transform(const QgsMatrix4x4 &transform)
Applies a transform to the bounding volume.
QgsAbstractGeometry * as2DGeometry(const QgsCoordinateTransform &transform=QgsCoordinateTransform(), Qgis::TransformDirection direction=Qgis::TransformDirection::Forward) const
Returns a new geometry representing the 2-dimensional X/Y center slice of the volume.
QgsBox3D bounds(const QgsCoordinateTransform &transform=QgsCoordinateTransform(), Qgis::TransformDirection direction=Qgis::TransformDirection::Forward) const
Returns the axis aligned bounding box of the volume.
A 3D vector (similar to QVector3D) with the difference that it uses double precision instead of singl...
Definition qgsvector3d.h:30
double y() const
Returns Y coordinate.
Definition qgsvector3d.h:49
double z() const
Returns Z coordinate.
Definition qgsvector3d.h:51
double x() const
Returns X coordinate.
Definition qgsvector3d.h:47