QGIS API Documentation 3.99.0-Master (d270888f95f)
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 "qgspoint.h"
23#include "qgsrectangle.h"
24
25#include <QString>
26#include <QVector3D>
27
28using namespace Qt::StringLiterals;
29
30class QgsVector3D;
31
44class CORE_EXPORT QgsBox3D
45{
46 Q_GADGET
47
48 public:
49
54#ifndef SIP_RUN
55 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(),
56 double xmax = std::numeric_limits<double>::quiet_NaN(), double ymax = std::numeric_limits<double>::quiet_NaN(), double zmax = std::numeric_limits<double>::quiet_NaN(),
57 bool normalize = true );
58
64 QgsBox3D( const QgsPoint &p1, const QgsPoint &p2, bool normalize = true );
65
72 QgsBox3D( const QgsVector3D &corner1, const QgsVector3D &corner2, bool normalize = true );
73
78 explicit QgsBox3D( const QgsRectangle &rect,
79 double zMin = std::numeric_limits<double>::quiet_NaN(), double zMax = std::numeric_limits<double>::quiet_NaN(),
80 bool normalize = true );
81
82#else
83 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 )];
84 % MethodCode
85 if ( sipCanConvertToType( a0, sipType_QgsRectangle, SIP_NOT_NONE ) && a4 == Py_None && a5 == Py_None && a6 == Py_None )
86 {
87 int state;
88 sipIsErr = 0;
89
90 QgsRectangle *p = reinterpret_cast<QgsRectangle *>( sipConvertToType( a0, sipType_QgsRectangle, 0, SIP_NOT_NONE, &state, &sipIsErr ) );
91 if ( !sipIsErr )
92 {
93 double z1 = a1 == Py_None ? std::numeric_limits<double>::quiet_NaN() : PyFloat_AsDouble( a1 );
94 double z2 = a2 == Py_None ? std::numeric_limits<double>::quiet_NaN() : PyFloat_AsDouble( a2 );
95 bool n = a3 == Py_None ? true : PyObject_IsTrue( a3 );
96
97 sipCpp = new QgsBox3D( *p, z1, z2, n );
98 }
99 sipReleaseType( p, sipType_QgsRectangle, state );
100 }
101 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 )
102 {
103 int state;
104 sipIsErr = 0;
105
106 QgsPoint *pt1 = reinterpret_cast<QgsPoint *>( sipConvertToType( a0, sipType_QgsPoint, 0, SIP_NOT_NONE, &state, &sipIsErr ) );
107 if ( !sipIsErr )
108 {
109 QgsPoint *pt2 = reinterpret_cast<QgsPoint *>( sipConvertToType( a1, sipType_QgsPoint, 0, SIP_NOT_NONE, &state, &sipIsErr ) );
110 if ( !sipIsErr )
111 {
112 bool n = a2 == Py_None ? true : PyObject_IsTrue( a2 );
113 sipCpp = new QgsBox3D( *pt1, *pt2, n );
114 }
115 sipReleaseType( pt2, sipType_QgsPoint, state );
116 }
117 sipReleaseType( pt1, sipType_QgsPoint, state );
118 }
119 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 )
120 {
121 int state;
122 sipIsErr = 0;
123
124 QgsVector3D *corner1 = reinterpret_cast<QgsVector3D *>( sipConvertToType( a0, sipType_QgsVector3D, 0, SIP_NOT_NONE, &state, &sipIsErr ) );
125 if ( !sipIsErr )
126 {
127 QgsVector3D *corner2 = reinterpret_cast<QgsVector3D *>( sipConvertToType( a1, sipType_QgsVector3D, 0, SIP_NOT_NONE, &state, &sipIsErr ) );
128 if ( !sipIsErr )
129 {
130 bool n = a2 == Py_None ? true : PyObject_IsTrue( a2 );
131 sipCpp = new QgsBox3D( *corner1, *corner2, n );
132 }
133 sipReleaseType( corner2, sipType_QgsVector3D, state );
134 }
135 sipReleaseType( corner1, sipType_QgsVector3D, state );
136 }
137 else if (
138 ( a0 == Py_None || PyFloat_AsDouble( a0 ) != -1.0 || !PyErr_Occurred() ) &&
139 ( a1 == Py_None || PyFloat_AsDouble( a1 ) != -1.0 || !PyErr_Occurred() ) &&
140 ( a2 == Py_None || PyFloat_AsDouble( a2 ) != -1.0 || !PyErr_Occurred() ) &&
141 ( a3 == Py_None || PyFloat_AsDouble( a3 ) != -1.0 || !PyErr_Occurred() ) &&
142 ( a4 == Py_None || PyFloat_AsDouble( a3 ) != -1.0 || !PyErr_Occurred() ) &&
143 ( a5 == Py_None || PyFloat_AsDouble( a3 ) != -1.0 || !PyErr_Occurred() ) &&
144 ( a6 == Py_None || PyFloat_AsDouble( a3 ) != -1.0 || !PyErr_Occurred() ) )
145 {
146 double x1 = a0 == Py_None ? std::numeric_limits<double>::quiet_NaN() : PyFloat_AsDouble( a0 );
147 double y1 = a1 == Py_None ? std::numeric_limits<double>::quiet_NaN() : PyFloat_AsDouble( a1 );
148 double z1 = a2 == Py_None ? std::numeric_limits<double>::quiet_NaN() : PyFloat_AsDouble( a2 );
149 double x2 = a3 == Py_None ? std::numeric_limits<double>::quiet_NaN() : PyFloat_AsDouble( a3 );
150 double y2 = a4 == Py_None ? std::numeric_limits<double>::quiet_NaN() : PyFloat_AsDouble( a4 );
151 double z2 = a5 == Py_None ? std::numeric_limits<double>::quiet_NaN() : PyFloat_AsDouble( a5 );
152 bool n = a6 == Py_None ? true : PyObject_IsTrue( a6 );
153 sipCpp = new QgsBox3D( x1, y1, z1, x2, y2, z2, n );
154 }
155 else // Invalid ctor arguments
156 {
157 PyErr_SetString( PyExc_TypeError, u"Invalid type in constructor arguments."_s.toUtf8().constData() );
158 sipIsErr = 1;
159 }
160 % End
161#endif
162
168 void set( double xMin, double yMin, double zMin, double xMax, double yMax, double zMax, bool normalize = true )
169 {
170 mBounds2d.set( xMin, yMin, xMax, yMax, false );
171 mZmin = zMin;
172 mZmax = zMax;
173 if ( normalize )
174 {
176 }
177 }
178
184 void setXMinimum( double x ) SIP_HOLDGIL;
185
191 void setXMaximum( double x ) SIP_HOLDGIL;
192
198 double xMinimum() const SIP_HOLDGIL { return mBounds2d.xMinimum(); }
199
205 double xMaximum() const SIP_HOLDGIL { return mBounds2d.xMaximum(); }
206
212 void setYMinimum( double y ) SIP_HOLDGIL;
213
219 void setYMaximum( double y ) SIP_HOLDGIL;
220
226 double yMinimum() const SIP_HOLDGIL { return mBounds2d.yMinimum(); }
227
233 double yMaximum() const SIP_HOLDGIL { return mBounds2d.yMaximum(); }
234
240 void setZMinimum( double z ) SIP_HOLDGIL;
241
247 void setZMaximum( double z ) SIP_HOLDGIL;
248
254 double zMinimum() const SIP_HOLDGIL { return mZmin; }
255
261 double zMaximum() const SIP_HOLDGIL { return mZmax; }
262
268 void setNull() SIP_HOLDGIL;
269
273 void normalize() SIP_HOLDGIL;
274
280 double width() const SIP_HOLDGIL { return mBounds2d.width(); }
281
287 double height() const SIP_HOLDGIL { return mBounds2d.height(); }
288
294 double depth() const SIP_HOLDGIL { return mZmax - mZmin; }
295
301 QgsVector3D center() const SIP_HOLDGIL;
302
308 double area() const SIP_HOLDGIL { return mBounds2d.area(); }
309
313 double volume() const SIP_HOLDGIL { return mBounds2d.area() * ( mZmax - mZmin ); }
314
318 QgsBox3D intersect( const QgsBox3D &other ) const SIP_HOLDGIL;
319
324 bool is2d() const SIP_HOLDGIL;
325
333 bool is3D() const SIP_HOLDGIL;
334
338 bool intersects( const QgsBox3D &other ) const SIP_HOLDGIL;
339
343 bool contains( const QgsBox3D &other ) const SIP_HOLDGIL;
344
351 bool contains( const QgsPoint &point ) const SIP_HOLDGIL;
352
362 bool contains( double x, double y, double z ) const SIP_HOLDGIL;
363
369 void combineWith( const QgsBox3D &box ) SIP_HOLDGIL;
370
376 void combineWith( double x, double y, double z ) SIP_HOLDGIL;
377
381 QgsRectangle toRectangle() const SIP_HOLDGIL { return mBounds2d; }
382
390 Q_DECL_DEPRECATED double distanceTo( const QVector3D &point ) const SIP_DEPRECATED { return distanceTo( QgsVector3D( point ) ); }
391
398 double distanceTo( const QgsVector3D &point ) const SIP_HOLDGIL;
399
400 bool operator==( const QgsBox3D &other ) const SIP_HOLDGIL;
401
409 void scale( double scaleFactor, const QgsPoint &center = QgsPoint() ) SIP_HOLDGIL;
410
416 void scale( double scaleFactor, double centerX, double centerY, double centerZ ) SIP_HOLDGIL;
417
422 void grow( double delta );
423
433 bool isNull() const SIP_HOLDGIL;
434
443 bool isEmpty() const SIP_HOLDGIL;
444
452 QString toString( int precision = 16 ) const SIP_HOLDGIL;
453
457 QVector< QgsVector3D > corners() const SIP_HOLDGIL;
458
463 QgsBox3D operator-( const QgsVector3D &v ) const SIP_HOLDGIL;
464
469 QgsBox3D operator+( const QgsVector3D &v ) const SIP_HOLDGIL;
470
475 QgsBox3D &operator-=( const QgsVector3D &v ) SIP_HOLDGIL;
476
481 QgsBox3D &operator+=( const QgsVector3D &v ) SIP_HOLDGIL;
482
483
484#ifdef SIP_RUN
485 SIP_PYOBJECT __repr__();
486 % MethodCode
487 QString str = u"<QgsBox3D(%1, %2, %3, %4, %5, %6)>"_s
488 .arg( sipCpp->xMinimum() )
489 .arg( sipCpp->yMinimum() )
490 .arg( sipCpp->zMinimum() )
491 .arg( sipCpp->xMaximum() )
492 .arg( sipCpp->yMaximum() )
493 .arg( sipCpp->zMaximum() );
494 sipRes = PyUnicode_FromString( str.toUtf8().constData() );
495 % End
496#endif
497
498 private:
499
500 QgsRectangle mBounds2d;
501 double mZmin = std::numeric_limits<double>::quiet_NaN();
502 double mZmax = std::numeric_limits<double>::quiet_NaN();
503
504};
505
506#endif // QGSBOX3D_H
A 3-dimensional box composed of x, y, z coordinates.
Definition qgsbox3d.h:45
double yMaximum() const
Returns the maximum y value.
Definition qgsbox3d.h:233
double depth() const
Returns the depth of the box.
Definition qgsbox3d.h:294
double xMinimum() const
Returns the minimum x value.
Definition qgsbox3d.h:198
double zMaximum() const
Returns the maximum z value.
Definition qgsbox3d.h:261
double xMaximum() const
Returns the maximum x value.
Definition qgsbox3d.h:205
double volume() const
Returns the volume of the box.
Definition qgsbox3d.h:313
void normalize()
Normalize the box so it has non-negative width/height/depth.
Definition qgsbox3d.cpp:115
QgsRectangle toRectangle() const
Converts the box to a 2D rectangle.
Definition qgsbox3d.h:381
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:390
double area() const
Returns the area of the box.
Definition qgsbox3d.h:308
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:168
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(), double xmax=std::numeric_limits< double >::quiet_NaN(), double ymax=std::numeric_limits< double >::quiet_NaN(), double zmax=std::numeric_limits< double >::quiet_NaN(), bool normalize=true)
Constructor for QgsBox3D which accepts the ranges of x/y/z coordinates.
Definition qgsbox3d.cpp:30
double width() const
Returns the width of the box.
Definition qgsbox3d.h:280
double zMinimum() const
Returns the minimum z value.
Definition qgsbox3d.h:254
double yMinimum() const
Returns the minimum y value.
Definition qgsbox3d.h:226
double height() const
Returns the height of the box.
Definition qgsbox3d.h:287
Point geometry type, with support for z-dimension and m-values.
Definition qgspoint.h:53
A rectangle specified with double values.
A 3D vector (similar to QVector3D) with the difference that it uses double precision instead of singl...
Definition qgsvector3d.h:33
#define SIP_TYPEHINT(type)
Definition qgis_sip.h:240
#define SIP_DEPRECATED
Definition qgis_sip.h:114
#define SIP_HOLDGIL
Definition qgis_sip.h:179
bool operator==(const QgsFeatureIterator &fi1, const QgsFeatureIterator &fi2)