QGIS API Documentation 3.41.0-Master (af5edcb665c)
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
20#include "qgsmatrix4x4.h"
21#include "qgsvector3d.h"
22#include "qgsmultipoint.h"
23#include "qgsgeos.h"
24#include "qgspolygon.h"
25
30
32{
33 mBox = mBox.transformed( transform );
34}
35
37{
38 if ( transform.isValid() && !transform.isShortCircuited() )
39 {
40 const QVector< QgsVector3D > corners = mBox.corners();
41 QVector< double > x;
42 x.reserve( 8 );
43 QVector< double > y;
44 y.reserve( 8 );
45 QVector< double > z;
46 z.reserve( 8 );
47 for ( int i = 0; i < 8; ++i )
48 {
49 const QgsVector3D &corner = corners[i];
50 x.append( corner.x() );
51 y.append( corner.y() );
52 z.append( corner.z() );
53 }
54 transform.transformInPlace( x, y, z, direction );
55
56 const auto minMaxX = std::minmax_element( x.constBegin(), x.constEnd() );
57 const auto minMaxY = std::minmax_element( y.constBegin(), y.constEnd() );
58 const auto minMaxZ = std::minmax_element( z.constBegin(), z.constEnd() );
59 return QgsBox3D( *minMaxX.first, *minMaxY.first, *minMaxZ.first, *minMaxX.second, *minMaxY.second, *minMaxZ.second );
60 }
61 else
62 {
63 return mBox.extent();
64 }
65}
66
68{
69 std::unique_ptr< QgsPolygon > polygon = std::make_unique< QgsPolygon >();
70
71 const QVector< QgsVector3D > corners = mBox.corners();
72 QVector< double > x;
73 x.reserve( 8 );
74 QVector< double > y;
75 y.reserve( 8 );
76 QVector< double > z;
77 z.reserve( 8 );
78 for ( int i = 0; i < 8; ++i )
79 {
80 const QgsVector3D &corner = corners[i];
81 x.append( corner.x() );
82 y.append( corner.y() );
83 z.append( corner.z() );
84 }
85
86 if ( transform.isValid() && !transform.isShortCircuited() )
87 {
88 transform.transformInPlace( x, y, z, direction );
89 }
90
91 std::unique_ptr< QgsMultiPoint > mp = std::make_unique< QgsMultiPoint >( x, y );
92 QgsGeos geosMp( mp.get() );
93 return geosMp.convexHull();
94}
95
97{
98 return mBox.intersects( box );
99}
100
TransformDirection
Indicates the direction (forward or inverse) of a transform.
Definition qgis.h:2565
Abstract base class for all geometries.
A 3-dimensional box composed of x, y, z coordinates.
Definition qgsbox3d.h:43
Class for doing transforms between two map coordinate systems.
Does vector analysis using the GEOS library and handles import, export, and exception handling.
Definition qgsgeos.h:139
QgsAbstractGeometry * convexHull(QString *errorMsg=nullptr) const override
Calculate the convex hull of this.
Definition qgsgeos.cpp:2212
A simple 4x4 matrix implementation useful for transformation in 3D space.
Represents a oriented (rotated) box in 3 dimensions.
QgsBox3D extent() const
Returns the overall bounding box of the object.
bool intersects(const QgsOrientedBox3D &other) const
Returns true if the box intersects the other box.
QVector< QgsVector3D > corners() const
Returns an array of all corners as 3D vectors.
QgsOrientedBox3D transformed(const QgsMatrix4x4 &transform) const
Returns box transformed by a 4x4 matrix.
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.
Class for storage of 3D vectors similar to QVector3D, with the difference that it uses double precisi...
Definition qgsvector3d.h:31
double y() const
Returns Y coordinate.
Definition qgsvector3d.h:50
double z() const
Returns Z coordinate.
Definition qgsvector3d.h:52
double x() const
Returns X coordinate.
Definition qgsvector3d.h:48