QGIS API Documentation 3.43.0-Master (ebb4087afc0)
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
42class CORE_EXPORT QgsBox3D
43{
44 Q_GADGET
45
46 public:
47
52#ifndef SIP_RUN
53 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(),
54 double xmax = std::numeric_limits<double>::quiet_NaN(), double ymax = std::numeric_limits<double>::quiet_NaN(), double zmax = std::numeric_limits<double>::quiet_NaN(),
55 bool normalize = true );
56
62 QgsBox3D( const QgsPoint &p1, const QgsPoint &p2, bool normalize = true );
63
70 QgsBox3D( const QgsVector3D &corner1, const QgsVector3D &corner2, bool normalize = true );
71
76 QgsBox3D( const QgsRectangle &rect,
77 double zMin = std::numeric_limits<double>::quiet_NaN(), double zMax = std::numeric_limits<double>::quiet_NaN(),
78 bool normalize = true );
79
80#else
81 QgsBox3D( SIP_PYOBJECT x SIP_TYPEHINT( Optional[Union[QgsPoint, QgsVector3D, QgsRectangle, float]] ) = Py_None, SIP_PYOBJECT y SIP_TYPEHINT( Optional[QgsPoint, QgsVector3D, 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 )];
82 % MethodCode
83 if ( sipCanConvertToType( a0, sipType_QgsRectangle, SIP_NOT_NONE ) && a4 == Py_None && a5 == Py_None && a6 == Py_None )
84 {
85 int state;
86 sipIsErr = 0;
87
88 QgsRectangle *p = reinterpret_cast<QgsRectangle *>( sipConvertToType( a0, sipType_QgsRectangle, 0, SIP_NOT_NONE, &state, &sipIsErr ) );
89 if ( !sipIsErr )
90 {
91 double z1 = a1 == Py_None ? std::numeric_limits<double>::quiet_NaN() : PyFloat_AsDouble( a1 );
92 double z2 = a2 == Py_None ? std::numeric_limits<double>::quiet_NaN() : PyFloat_AsDouble( a2 );
93 bool n = a3 == Py_None ? true : PyObject_IsTrue( a3 );
94
95 sipCpp = new QgsBox3D( *p, z1, z2, n );
96 }
97 sipReleaseType( p, sipType_QgsRectangle, state );
98 }
99 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 )
100 {
101 int state;
102 sipIsErr = 0;
103
104 QgsPoint *pt1 = reinterpret_cast<QgsPoint *>( sipConvertToType( a0, sipType_QgsPoint, 0, SIP_NOT_NONE, &state, &sipIsErr ) );
105 if ( !sipIsErr )
106 {
107 QgsPoint *pt2 = reinterpret_cast<QgsPoint *>( sipConvertToType( a1, sipType_QgsPoint, 0, SIP_NOT_NONE, &state, &sipIsErr ) );
108 if ( !sipIsErr )
109 {
110 bool n = a2 == Py_None ? true : PyObject_IsTrue( a2 );
111 sipCpp = new QgsBox3D( *pt1, *pt2, n );
112 }
113 sipReleaseType( pt2, sipType_QgsPoint, state );
114 }
115 sipReleaseType( pt1, sipType_QgsPoint, state );
116 }
117 else if ( sipCanConvertToType( a0, sipType_QgsVector3D, SIP_NOT_NONE ) && sipCanConvertToType( a1, sipType_QgsVector3D, SIP_NOT_NONE ) && a3 == Py_None && a4 == Py_None && a5 == Py_None && a6 == Py_None )
118 {
119 int state;
120 sipIsErr = 0;
121
122 QgsVector3D *corner1 = reinterpret_cast<QgsVector3D *>( sipConvertToType( a0, sipType_QgsVector3D, 0, SIP_NOT_NONE, &state, &sipIsErr ) );
123 if ( !sipIsErr )
124 {
125 QgsVector3D *corner2 = reinterpret_cast<QgsVector3D *>( sipConvertToType( a1, sipType_QgsVector3D, 0, SIP_NOT_NONE, &state, &sipIsErr ) );
126 if ( !sipIsErr )
127 {
128 bool n = a2 == Py_None ? true : PyObject_IsTrue( a2 );
129 sipCpp = new QgsBox3D( *corner1, *corner2, n );
130 }
131 sipReleaseType( corner2, sipType_QgsVector3D, state );
132 }
133 sipReleaseType( corner1, sipType_QgsVector3D, state );
134 }
135 else if (
136 ( a0 == Py_None || PyFloat_AsDouble( a0 ) != -1.0 || !PyErr_Occurred() ) &&
137 ( a1 == Py_None || PyFloat_AsDouble( a1 ) != -1.0 || !PyErr_Occurred() ) &&
138 ( a2 == Py_None || PyFloat_AsDouble( a2 ) != -1.0 || !PyErr_Occurred() ) &&
139 ( a3 == Py_None || PyFloat_AsDouble( a3 ) != -1.0 || !PyErr_Occurred() ) &&
140 ( a4 == Py_None || PyFloat_AsDouble( a3 ) != -1.0 || !PyErr_Occurred() ) &&
141 ( a5 == Py_None || PyFloat_AsDouble( a3 ) != -1.0 || !PyErr_Occurred() ) &&
142 ( a6 == Py_None || PyFloat_AsDouble( a3 ) != -1.0 || !PyErr_Occurred() ) )
143 {
144 double x1 = a0 == Py_None ? std::numeric_limits<double>::quiet_NaN() : PyFloat_AsDouble( a0 );
145 double y1 = a1 == Py_None ? std::numeric_limits<double>::quiet_NaN() : PyFloat_AsDouble( a1 );
146 double z1 = a2 == Py_None ? std::numeric_limits<double>::quiet_NaN() : PyFloat_AsDouble( a2 );
147 double x2 = a3 == Py_None ? std::numeric_limits<double>::quiet_NaN() : PyFloat_AsDouble( a3 );
148 double y2 = a4 == Py_None ? std::numeric_limits<double>::quiet_NaN() : PyFloat_AsDouble( a4 );
149 double z2 = a5 == Py_None ? std::numeric_limits<double>::quiet_NaN() : PyFloat_AsDouble( a5 );
150 bool n = a6 == Py_None ? true : PyObject_IsTrue( a6 );
151 sipCpp = new QgsBox3D( x1, y1, z1, x2, y2, z2, n );
152 }
153 else // Invalid ctor arguments
154 {
155 PyErr_SetString( PyExc_TypeError, QStringLiteral( "Invalid type in constructor arguments." ).toUtf8().constData() );
156 sipIsErr = 1;
157 }
158 % End
159#endif
160
166 void set( double xMin, double yMin, double zMin, double xMax, double yMax, double zMax, bool normalize = true )
167 {
168 mBounds2d.set( xMin, yMin, xMax, yMax, false );
169 mZmin = zMin;
170 mZmax = zMax;
171 if ( normalize )
172 {
174 }
175 }
176
182 void setXMinimum( double x ) SIP_HOLDGIL;
183
189 void setXMaximum( double x ) SIP_HOLDGIL;
190
196 double xMinimum() const SIP_HOLDGIL { return mBounds2d.xMinimum(); }
197
203 double xMaximum() const SIP_HOLDGIL { return mBounds2d.xMaximum(); }
204
210 void setYMinimum( double y ) SIP_HOLDGIL;
211
217 void setYMaximum( double y ) SIP_HOLDGIL;
218
224 double yMinimum() const SIP_HOLDGIL { return mBounds2d.yMinimum(); }
225
231 double yMaximum() const SIP_HOLDGIL { return mBounds2d.yMaximum(); }
232
238 void setZMinimum( double z ) SIP_HOLDGIL;
239
245 void setZMaximum( double z ) SIP_HOLDGIL;
246
252 double zMinimum() const SIP_HOLDGIL { return mZmin; }
253
259 double zMaximum() const SIP_HOLDGIL { return mZmax; }
260
266 void setNull() SIP_HOLDGIL;
267
271 void normalize() SIP_HOLDGIL;
272
278 double width() const SIP_HOLDGIL { return mBounds2d.width(); }
279
285 double height() const SIP_HOLDGIL { return mBounds2d.height(); }
286
292 double depth() const SIP_HOLDGIL { return mZmax - mZmin; }
293
299 QgsVector3D center() const SIP_HOLDGIL;
300
306 double area() const SIP_HOLDGIL { return mBounds2d.area(); }
307
311 double volume() const SIP_HOLDGIL { return mBounds2d.area() * ( mZmax - mZmin ); }
312
316 QgsBox3D intersect( const QgsBox3D &other ) const SIP_HOLDGIL;
317
322 bool is2d() const SIP_HOLDGIL;
323
331 bool is3D() const SIP_HOLDGIL;
332
336 bool intersects( const QgsBox3D &other ) const SIP_HOLDGIL;
337
341 bool contains( const QgsBox3D &other ) const SIP_HOLDGIL;
342
349 bool contains( const QgsPoint &point ) const SIP_HOLDGIL;
350
360 bool contains( double x, double y, double z ) const SIP_HOLDGIL;
361
367 void combineWith( const QgsBox3D &box ) SIP_HOLDGIL;
368
374 void combineWith( double x, double y, double z ) SIP_HOLDGIL;
375
379 QgsRectangle toRectangle() const SIP_HOLDGIL { return mBounds2d; }
380
388 Q_DECL_DEPRECATED double distanceTo( const QVector3D &point ) const SIP_DEPRECATED { return distanceTo( QgsVector3D( point ) ); }
389
396 double distanceTo( const QgsVector3D &point ) const SIP_HOLDGIL;
397
398 bool operator==( const QgsBox3D &other ) const SIP_HOLDGIL;
399
407 void scale( double scaleFactor, const QgsPoint &center = QgsPoint() ) SIP_HOLDGIL;
408
414 void scale( double scaleFactor, double centerX, double centerY, double centerZ ) SIP_HOLDGIL;
415
420 void grow( double delta );
421
431 bool isNull() const SIP_HOLDGIL;
432
441 bool isEmpty() const SIP_HOLDGIL;
442
450 QString toString( int precision = 16 ) const SIP_HOLDGIL;
451
455 QVector< QgsVector3D > corners() const SIP_HOLDGIL;
456
461 QgsBox3D operator-( const QgsVector3D &v ) const SIP_HOLDGIL;
462
467 QgsBox3D operator+( const QgsVector3D &v ) const SIP_HOLDGIL;
468
473 QgsBox3D &operator-=( const QgsVector3D &v ) SIP_HOLDGIL;
474
479 QgsBox3D &operator+=( const QgsVector3D &v ) SIP_HOLDGIL;
480
481
482#ifdef SIP_RUN
483 SIP_PYOBJECT __repr__();
484 % MethodCode
485 QString str = QStringLiteral( "<QgsBox3D(%1, %2, %3, %4, %5, %6)>" )
486 .arg( sipCpp->xMinimum() )
487 .arg( sipCpp->yMinimum() )
488 .arg( sipCpp->zMinimum() )
489 .arg( sipCpp->xMaximum() )
490 .arg( sipCpp->yMaximum() )
491 .arg( sipCpp->zMaximum() );
492 sipRes = PyUnicode_FromString( str.toUtf8().constData() );
493 % End
494#endif
495
496 private:
497
498 QgsRectangle mBounds2d;
499 double mZmin = std::numeric_limits<double>::quiet_NaN();
500 double mZmax = std::numeric_limits<double>::quiet_NaN();
501
502};
503
504#endif // QGSBOX3D_H
A 3-dimensional box composed of x, y, z coordinates.
Definition qgsbox3d.h:43
double yMaximum() const
Returns the maximum y value.
Definition qgsbox3d.h:231
double depth() const
Returns the depth of the box.
Definition qgsbox3d.h:292
double xMinimum() const
Returns the minimum x value.
Definition qgsbox3d.h:196
double zMaximum() const
Returns the maximum z value.
Definition qgsbox3d.h:259
double xMaximum() const
Returns the maximum x value.
Definition qgsbox3d.h:203
double volume() const
Returns the volume of the box.
Definition qgsbox3d.h:311
void normalize()
Normalize the box so it has non-negative width/height/depth.
Definition qgsbox3d.cpp:109
Q_DECL_DEPRECATED double distanceTo(const QVector3D &point) const
Returns the smallest distance between the box and the point point (returns 0 if the point is inside t...
Definition qgsbox3d.h:388
void set(double xMin, double yMin, double zMin, double xMax, double yMax, double zMax, bool normalize=true)
Sets the box from a set of (x,y,z) minimum and maximum coordinates.
Definition qgsbox3d.h:166
double zMinimum() const
Returns the minimum z value.
Definition qgsbox3d.h:252
double yMinimum() const
Returns the minimum y value.
Definition qgsbox3d.h:224
double height() const
Returns the height of the box.
Definition qgsbox3d.h:285
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:31
#define SIP_TYPEHINT(type)
Definition qgis_sip.h:232
#define SIP_DEPRECATED
Definition qgis_sip.h:106
#define SIP_HOLDGIL
Definition qgis_sip.h:171
bool operator==(const QgsFeatureIterator &fi1, const QgsFeatureIterator &fi2)
int precision