QGIS API Documentation 3.34.0-Prizren (ffbdd678812)
Loading...
Searching...
No Matches
qgsbox3d.h
Go to the documentation of this file.
1/***************************************************************************
2 qgsbox3d.h
3 ----------
4 begin : April 2017
5 copyright : (C) 2017 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#ifndef QGSBOX3D_H
19#define QGSBOX3D_H
20
21#include "qgis_core.h"
22#include "qgsrectangle.h"
23
24#include <QVector3D>
25
26#include "qgspoint.h"
27
28class QgsVector3D;
29
43class CORE_EXPORT QgsBox3D
44{
45 Q_GADGET
46
47 public:
48
53#ifndef SIP_RUN
54 QgsBox3D( double xmin = std::numeric_limits<double>::quiet_NaN(), double ymin = std::numeric_limits<double>::quiet_NaN(), double zmin = std::numeric_limits<double>::quiet_NaN(),
55 double xmax = std::numeric_limits<double>::quiet_NaN(), double ymax = std::numeric_limits<double>::quiet_NaN(), double zmax = std::numeric_limits<double>::quiet_NaN(),
56 bool normalize = true );
57
63 QgsBox3D( const QgsPoint &p1, const QgsPoint &p2, bool normalize = true );
64
69 QgsBox3D( const QgsRectangle &rect,
70 double zMin = std::numeric_limits<double>::quiet_NaN(), double zMax = std::numeric_limits<double>::quiet_NaN(),
71 bool normalize = true );
72#else
73 QgsBox3D( SIP_PYOBJECT x SIP_TYPEHINT( Optional[Union[QgsPoint, QgsRectangle, float]] ) = Py_None, SIP_PYOBJECT y SIP_TYPEHINT( Optional[QgsPoint, float] ) = Py_None, SIP_PYOBJECT z SIP_TYPEHINT( Optional[Union[bool, float]] ) = Py_None, SIP_PYOBJECT x2 SIP_TYPEHINT( Optional[Union[bool, float]] ) = Py_None, SIP_PYOBJECT y2 SIP_TYPEHINT( Optional[float] ) = Py_None, SIP_PYOBJECT z2 SIP_TYPEHINT( Optional[float] ) = Py_None, SIP_PYOBJECT n SIP_TYPEHINT( Optional[bool] ) = Py_None ) [( double x = 0.0, double y = 0.0, double z = 0.0, double x2 = 0.0, double y2 = 0.0, double z2 = 0.0, bool n = true )];
74 % MethodCode
75 if ( sipCanConvertToType( a0, sipType_QgsRectangle, SIP_NOT_NONE ) && a4 == Py_None && a5 == Py_None && a6 == Py_None )
76 {
77 int state;
78 sipIsErr = 0;
79
80 QgsRectangle *p = reinterpret_cast<QgsRectangle *>( sipConvertToType( a0, sipType_QgsRectangle, 0, SIP_NOT_NONE, &state, &sipIsErr ) );
81 if ( sipIsErr )
82 {
83 sipReleaseType( p, sipType_QgsRectangle, state );
84 }
85 else
86 {
87 double z1 = a1 == Py_None ? std::numeric_limits<double>::quiet_NaN() : PyFloat_AsDouble( a1 );
88 double z2 = a2 == Py_None ? std::numeric_limits<double>::quiet_NaN() : PyFloat_AsDouble( a2 );
89 bool n = a3 == Py_None ? true : PyObject_IsTrue( a3 );
90
91 sipCpp = new QgsBox3D( *p, z1, z2, n );
92 }
93 }
94 else if ( sipCanConvertToType( a0, sipType_QgsPoint, SIP_NOT_NONE ) && sipCanConvertToType( a1, sipType_QgsPoint, SIP_NOT_NONE ) && a3 == Py_None && a4 == Py_None && a5 == Py_None && a6 == Py_None )
95 {
96 int state;
97 sipIsErr = 0;
98
99 QgsPoint *pt1 = reinterpret_cast<QgsPoint *>( sipConvertToType( a0, sipType_QgsPoint, 0, SIP_NOT_NONE, &state, &sipIsErr ) );
100 if ( sipIsErr )
101 {
102 sipReleaseType( pt1, sipType_QgsPoint, state );
103 }
104 else
105 {
106 QgsPoint *pt2 = reinterpret_cast<QgsPoint *>( sipConvertToType( a1, sipType_QgsPoint, 0, SIP_NOT_NONE, &state, &sipIsErr ) );
107 if ( sipIsErr )
108 {
109 sipReleaseType( pt2, sipType_QgsPoint, state );
110 }
111 else
112 {
113 bool n = a2 == Py_None ? true : PyObject_IsTrue( a2 );
114 sipCpp = new QgsBox3D( *pt1, *pt2, n );
115 }
116 }
117 }
118 else if (
119 ( a0 == Py_None || PyFloat_AsDouble( a0 ) != -1.0 || !PyErr_Occurred() ) &&
120 ( a1 == Py_None || PyFloat_AsDouble( a1 ) != -1.0 || !PyErr_Occurred() ) &&
121 ( a2 == Py_None || PyFloat_AsDouble( a2 ) != -1.0 || !PyErr_Occurred() ) &&
122 ( a3 == Py_None || PyFloat_AsDouble( a3 ) != -1.0 || !PyErr_Occurred() ) &&
123 ( a4 == Py_None || PyFloat_AsDouble( a3 ) != -1.0 || !PyErr_Occurred() ) &&
124 ( a5 == Py_None || PyFloat_AsDouble( a3 ) != -1.0 || !PyErr_Occurred() ) &&
125 ( a6 == Py_None || PyFloat_AsDouble( a3 ) != -1.0 || !PyErr_Occurred() ) )
126 {
127 double x1 = a0 == Py_None ? std::numeric_limits<double>::quiet_NaN() : PyFloat_AsDouble( a0 );
128 double y1 = a1 == Py_None ? std::numeric_limits<double>::quiet_NaN() : PyFloat_AsDouble( a1 );
129 double z1 = a2 == Py_None ? std::numeric_limits<double>::quiet_NaN() : PyFloat_AsDouble( a2 );
130 double x2 = a3 == Py_None ? std::numeric_limits<double>::quiet_NaN() : PyFloat_AsDouble( a3 );
131 double y2 = a4 == Py_None ? std::numeric_limits<double>::quiet_NaN() : PyFloat_AsDouble( a4 );
132 double z2 = a5 == Py_None ? std::numeric_limits<double>::quiet_NaN() : PyFloat_AsDouble( a5 );
133 bool n = a6 == Py_None ? true : PyObject_IsTrue( a6 );
134 sipCpp = new QgsBox3D( x1, y1, z1, x2, y2, z2, n );
135 }
136 else // Invalid ctor arguments
137 {
138 PyErr_SetString( PyExc_TypeError, QStringLiteral( "Invalid type in constructor arguments." ).toUtf8().constData() );
139 sipIsErr = 1;
140 }
141 % End
142#endif
143
149 void setXMinimum( double x ) SIP_HOLDGIL;
150
156 void setXMaximum( double x ) SIP_HOLDGIL;
157
163 double xMinimum() const SIP_HOLDGIL { return mBounds2d.xMinimum(); }
164
170 double xMaximum() const SIP_HOLDGIL { return mBounds2d.xMaximum(); }
171
177 void setYMinimum( double y ) SIP_HOLDGIL;
178
184 void setYMaximum( double y ) SIP_HOLDGIL;
185
191 double yMinimum() const SIP_HOLDGIL { return mBounds2d.yMinimum(); }
192
198 double yMaximum() const SIP_HOLDGIL { return mBounds2d.yMaximum(); }
199
205 void setZMinimum( double z ) SIP_HOLDGIL;
206
212 void setZMaximum( double z ) SIP_HOLDGIL;
213
219 double zMinimum() const SIP_HOLDGIL { return mZmin; }
220
226 double zMaximum() const SIP_HOLDGIL { return mZmax; }
227
233 void setNull() SIP_HOLDGIL;
234
238 void normalize() SIP_HOLDGIL;
239
245 double width() const SIP_HOLDGIL { return mBounds2d.width(); }
246
252 double height() const SIP_HOLDGIL { return mBounds2d.height(); }
253
259 double depth() const SIP_HOLDGIL { return mZmax - mZmin; }
260
266 QgsVector3D center() const SIP_HOLDGIL;
267
271 double volume() const SIP_HOLDGIL { return mBounds2d.area() * ( mZmax - mZmin ); }
272
276 QgsBox3D intersect( const QgsBox3D &other ) const SIP_HOLDGIL;
277
282 bool is2d() const SIP_HOLDGIL;
283
291 bool is3D() const SIP_HOLDGIL;
292
296 bool intersects( const QgsBox3D &other ) const SIP_HOLDGIL;
297
301 bool contains( const QgsBox3D &other ) const SIP_HOLDGIL;
302
309 bool contains( const QgsPoint &point ) const SIP_HOLDGIL;
310
320 bool contains( double x, double y, double z ) const SIP_HOLDGIL;
321
327 void combineWith( const QgsBox3D &box ) SIP_HOLDGIL;
328
334 void combineWith( double x, double y, double z ) SIP_HOLDGIL;
335
339 QgsRectangle toRectangle() const SIP_HOLDGIL { return mBounds2d; }
340
347 double distanceTo( const QVector3D &point ) const SIP_HOLDGIL;
348
349 bool operator==( const QgsBox3D &other ) const SIP_HOLDGIL;
350
358 void scale( double scaleFactor, const QgsPoint &center = QgsPoint() ) SIP_HOLDGIL;
359
365 void scale( double scaleFactor, double centerX, double centerY, double centerZ ) SIP_HOLDGIL;
366
376 bool isNull() const SIP_HOLDGIL;
377
386 bool isEmpty() const SIP_HOLDGIL;
387
395 QString toString( int precision = 16 ) const SIP_HOLDGIL;
396
400 QVector< QgsVector3D > corners() const SIP_HOLDGIL;
401
406 QgsBox3D operator-( const QgsVector3D &v ) const SIP_HOLDGIL;
407
412 QgsBox3D operator+( const QgsVector3D &v ) const SIP_HOLDGIL;
413
418 QgsBox3D &operator-=( const QgsVector3D &v ) SIP_HOLDGIL;
419
424 QgsBox3D &operator+=( const QgsVector3D &v ) SIP_HOLDGIL;
425
426
427#ifdef SIP_RUN
428 SIP_PYOBJECT __repr__();
429 % MethodCode
430 QString str = QStringLiteral( "<QgsBox3D(%1, %2, %3, %4, %5, %6)>" )
431 .arg( sipCpp->xMinimum() )
432 .arg( sipCpp->yMinimum() )
433 .arg( sipCpp->zMinimum() )
434 .arg( sipCpp->xMaximum() )
435 .arg( sipCpp->yMaximum() )
436 .arg( sipCpp->zMaximum() );
437 sipRes = PyUnicode_FromString( str.toUtf8().constData() );
438 % End
439#endif
440
441 private:
442
443 QgsRectangle mBounds2d;
444 double mZmin = std::numeric_limits<double>::quiet_NaN();
445 double mZmax = std::numeric_limits<double>::quiet_NaN();
446
447};
448
449#endif // QGSBOX3D_H
A 3-dimensional box composed of x, y, z coordinates.
Definition qgsbox3d.h:44
double yMaximum() const
Returns the maximum y value.
Definition qgsbox3d.h:198
double depth() const
Returns the depth of the box.
Definition qgsbox3d.h:259
double xMinimum() const
Returns the minimum x value.
Definition qgsbox3d.h:163
double zMaximum() const
Returns the maximum z value.
Definition qgsbox3d.h:226
double xMaximum() const
Returns the maximum x value.
Definition qgsbox3d.h:170
double zMinimum() const
Returns the minimum z value.
Definition qgsbox3d.h:219
double yMinimum() const
Returns the minimum y value.
Definition qgsbox3d.h:191
double height() const
Returns the height of the box.
Definition qgsbox3d.h:252
Point geometry type, with support for z-dimension and m-values.
Definition qgspoint.h:49
A rectangle specified with double values.
Class for storage of 3D vectors similar to QVector3D, with the difference that it uses double precisi...
Definition qgsvector3d.h:32
#define str(x)
Definition qgis.cpp:38
#define SIP_TYPEHINT(type)
Definition qgis_sip.h:227
#define SIP_HOLDGIL
Definition qgis_sip.h:166
bool operator==(const QgsFeatureIterator &fi1, const QgsFeatureIterator &fi2)
int precision