QGIS API Documentation
4.3.0-Master (16eddb2670e)
Toggle main menu visibility
Loading...
Searching...
No Matches
src
core
tiledscene
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
18
#include "
qgstiledsceneboundingvolume.h
"
19
20
#include "
qgscoordinatetransform.h
"
21
#include "
qgsgeos.h
"
22
#include "
qgsmatrix4x4.h
"
23
#include "
qgsmultipoint.h
"
24
#include "
qgspolygon.h
"
25
#include "
qgsvector3d.h
"
26
27
QgsTiledSceneBoundingVolume::QgsTiledSceneBoundingVolume
(
const
QgsOrientedBox3D
&
box
)
28
: mBox(
box
)
29
{}
30
31
void
QgsTiledSceneBoundingVolume::transform
(
const
QgsMatrix4x4
&
transform
)
32
{
33
mBox = mBox.transformed(
transform
);
34
}
35
36
QgsBox3D
QgsTiledSceneBoundingVolume::bounds
(
const
QgsCoordinateTransform
&
transform
,
Qgis::TransformDirection
direction )
const
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
67
std::unique_ptr<QgsAbstractGeometry>
QgsTiledSceneBoundingVolume::as2DGeometry
(
const
QgsCoordinateTransform
&
transform
,
Qgis::TransformDirection
direction )
const
68
{
69
auto
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
auto
mp = std::make_unique< QgsMultiPoint >( x, y );
92
QgsGeos
geosMp( mp.get() );
93
return
std::unique_ptr<QgsAbstractGeometry>( geosMp.
convexHull
() );
94
}
95
96
bool
QgsTiledSceneBoundingVolume::intersects
(
const
QgsOrientedBox3D
&
box
)
const
97
{
98
return
mBox.intersects(
box
);
99
}
Qgis::TransformDirection
TransformDirection
Indicates the direction (forward or inverse) of a transform.
Definition
qgis.h:2882
QgsBox3D
A 3-dimensional box composed of x, y, z coordinates.
Definition
qgsbox3d.h:45
QgsCoordinateTransform
Handles coordinate transforms between two coordinate systems.
Definition
qgscoordinatetransform.h:63
QgsGeos
Does vector analysis using the GEOS library and handles import, export, and exception handling.
Definition
qgsgeos.h:192
QgsGeos::convexHull
QgsAbstractGeometry * convexHull(QString *errorMsg=nullptr, QgsFeedback *feedback=nullptr) const override
Calculate the convex hull of this geometry.
Definition
qgsgeos.cpp:2576
QgsMatrix4x4
A simple 4x4 matrix implementation useful for transformation in 3D space.
Definition
qgsmatrix4x4.h:42
QgsOrientedBox3D
Represents a oriented (rotated) box in 3 dimensions.
Definition
qgsorientedbox3d.h:48
QgsTiledSceneBoundingVolume::box
QgsOrientedBox3D box() const
Returns the volume's oriented box.
Definition
qgstiledsceneboundingvolume.h:77
QgsTiledSceneBoundingVolume::intersects
bool intersects(const QgsOrientedBox3D &box) const
Returns true if this bounds intersects the specified box.
Definition
qgstiledsceneboundingvolume.cpp:96
QgsTiledSceneBoundingVolume::QgsTiledSceneBoundingVolume
QgsTiledSceneBoundingVolume(const QgsOrientedBox3D &box=QgsOrientedBox3D())
Constructor for QgsTiledSceneBoundingVolume, with the specified oriented box.
Definition
qgstiledsceneboundingvolume.cpp:27
QgsTiledSceneBoundingVolume::as2DGeometry
std::unique_ptr< 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.
Definition
qgstiledsceneboundingvolume.cpp:67
QgsTiledSceneBoundingVolume::transform
void transform(const QgsMatrix4x4 &transform)
Applies a transform to the bounding volume.
Definition
qgstiledsceneboundingvolume.cpp:31
QgsTiledSceneBoundingVolume::bounds
QgsBox3D bounds(const QgsCoordinateTransform &transform=QgsCoordinateTransform(), Qgis::TransformDirection direction=Qgis::TransformDirection::Forward) const
Returns the axis aligned bounding box of the volume.
Definition
qgstiledsceneboundingvolume.cpp:36
QgsVector3D
A 3D vector (similar to QVector3D) with the difference that it uses double precision instead of singl...
Definition
qgsvector3d.h:33
QgsVector3D::y
double y() const
Returns Y coordinate.
Definition
qgsvector3d.h:60
QgsVector3D::z
double z() const
Returns Z coordinate.
Definition
qgsvector3d.h:62
QgsVector3D::x
double x() const
Returns X coordinate.
Definition
qgsvector3d.h:58
qgscoordinatetransform.h
qgsgeos.h
qgsmatrix4x4.h
qgsmultipoint.h
qgspolygon.h
qgstiledsceneboundingvolume.h
qgsvector3d.h
Generated on
for QGIS API Documentation by
1.17.0