Initial framework for 3D box class

This commit is contained in:
Nyall Dawson 2017-04-10 19:42:59 +10:00
parent 8637b22149
commit 0d843ff4e6
6 changed files with 491 additions and 0 deletions

View File

@ -25,6 +25,7 @@
%Include qgsattributetableconfig.sip
%Include qgsattributeeditorelement.sip
%Include qgsbearingutils.sip
%Include qgsbox3d.sip
%Include qgsbrowsermodel.sip
%Include qgsclipper.sip
%Include qgscolorramp.sip

191
python/core/qgsbox3d.sip Normal file
View File

@ -0,0 +1,191 @@
/************************************************************************
* This file has been generated automatically from *
* *
* src/core/qgsbox3d.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/
class QgsBox3d
{
%Docstring
A 3-dimensional box composed of x, y, z coordinates.
A box composed of x/y/z minimum and maximum values. It is often used to return the 3D
extent of a geometry or collection of geometries.
.. versionadded:: 3.0
\see QgsRectangle
%End
%TypeHeaderCode
#include "qgsbox3d.h"
%End
public:
QgsBox3d( double xmin = 0, double ymin = 0, double mZmin = 0, double xmax = 0, double ymax = 0, double mZmax = 0 );
%Docstring
Constructor for QgsBox3D which accepts the ranges of x/y/z coordinates.
%End
QgsBox3d( const QgsPointV2 &p1, const QgsPointV2 &p2 );
%Docstring
Constructs a QgsBox3D from two points representing opposite corners of the box.
The box is normalized after construction.
%End
void setXMinimum( double x );
%Docstring
Sets the minimum x value.
\see xMinimum()
\see setXMaximum()
%End
void setXMaximum( double x );
%Docstring
Sets the maximum x value.
\see xMaximum()
\see setXMinimum()
%End
double xMinimum() const;
%Docstring
Returns the minimum x value.
\see setXMinimum()
\see xMaximum()
:rtype: float
%End
double xMaximum() const;
%Docstring
Returns the maximum x value.
\see setXMaximum()
\see xMinimum()
:rtype: float
%End
void setYMinimum( double y );
%Docstring
Sets the minimum y value.
\see yMinimum()
\see setYMaximum()
%End
void setYMaximum( double y );
%Docstring
Sets the maximum y value.
\see yMaximum()
\see setYMinimum()
%End
double yMinimum() const;
%Docstring
Returns the minimum y value.
\see setYMinimum()
\see yMaximum()
:rtype: float
%End
double yMaximum() const;
%Docstring
Returns the maximum y value.
\see setYMaximum()
\see yMinimum()
:rtype: float
%End
void setZMinimum( double z );
%Docstring
Sets the minimum z value.
\see zMinimum()
\see setZMaximum()
%End
void setZMaximum( double z );
%Docstring
Sets the maximum z value.
\see zMaximum()
\see setZMinimum()
%End
double zMinimum() const;
%Docstring
Returns the minimum z value.
\see setZMinimum()
\see zMaximum()
:rtype: float
%End
double zMaximum() const;
%Docstring
Returns the maximum z value.
\see setZMaximum()
\see zMinimum()
:rtype: float
%End
void normalize();
%Docstring
Normalize the box so it has non-negative width/height/depth.
%End
double width() const;
%Docstring
Returns the width of the box.
\see height()
\see depth()
:rtype: float
%End
double height() const;
%Docstring
Returns the height of the box.
\see width()
\see depth()
:rtype: float
%End
double depth() const;
%Docstring
Returns the depth of the box.
\see width()
\see height()
:rtype: float
%End
QgsBox3d intersect( const QgsBox3d &other ) const;
%Docstring
Returns the intersection of this box and another 3D box.
:rtype: QgsBox3d
%End
bool intersects( const QgsBox3d &other ) const;
%Docstring
Returns true if box intersects with another box.
:rtype: bool
%End
bool contains( const QgsBox3d &other ) const;
%Docstring
Returns true when box contains other box.
:rtype: bool
%End
bool contains( const QgsPointV2 &point ) const;
%Docstring
Returns true when box contains a point.
:rtype: bool
%End
};
/************************************************************************
* This file has been generated automatically from *
* *
* src/core/qgsbox3d.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/

View File

@ -101,6 +101,7 @@ SET(QGIS_CORE_SRCS
qgsattributetableconfig.cpp
qgsattributeeditorelement.cpp
qgsbearingutils.cpp
qgsbox3d.cpp
qgsbrowsermodel.cpp
qgscachedfeatureiterator.cpp
qgscacheindex.cpp
@ -673,6 +674,7 @@ SET(QGIS_CORE_HDRS
qgsattributetableconfig.h
qgsattributeeditorelement.h
qgsbearingutils.h
qgsbox3d.h
qgscachedfeatureiterator.h
qgscacheindex.h
qgscacheindexfeatureid.h

109
src/core/qgsbox3d.cpp Normal file
View File

@ -0,0 +1,109 @@
/***************************************************************************
qgsbox3d.cpp
------------
begin : April 2017
copyright : (C) 2017 by Nyall Dawson
email : nyall dot dawson at gmail dot com
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#include "qgsbox3d.h"
QgsBox3d::QgsBox3d( double xmin, double ymin, double zmin, double xmax, double ymax, double zmax )
: mBounds2d( xmin, ymin, xmax, ymax )
, mZmin( zmin )
, mZmax( zmax )
{}
QgsBox3d::QgsBox3d( const QgsPointV2 &p1, const QgsPointV2 &p2 )
: mBounds2d( p1.x(), p1.y(), p2.x(), p2.y() )
, mZmin( qMin( p1.z(), p2.z() ) )
, mZmax( qMax( p1.z(), p2.z() ) )
{
mBounds2d.normalize();
}
void QgsBox3d::setXMinimum( double x )
{
mBounds2d.setXMinimum( x );
}
void QgsBox3d::setXMaximum( double x )
{
mBounds2d.setXMaximum( x );
}
void QgsBox3d::setYMinimum( double y )
{
mBounds2d.setYMinimum( y );
}
void QgsBox3d::setYMaximum( double y )
{
mBounds2d.setYMaximum( y );
}
void QgsBox3d::setZMinimum( double z )
{
mZmin = z;
}
void QgsBox3d::setZMaximum( double z )
{
mZmax = z;
}
void QgsBox3d::normalize()
{
mBounds2d.normalize();
double z1 = qMin( mZmin, mZmax );
double z2 = qMax( mZmin, mZmax );
mZmin = z1;
mZmax = z2;
}
QgsBox3d QgsBox3d::intersect( const QgsBox3d &other ) const
{
QgsRectangle intersect2d = mBounds2d.intersect( &( other.mBounds2d ) );
double zMin = qMax( mZmin, other.mZmin );
double zMax = qMin( mZmax, other.mZmax );
return QgsBox3d( intersect2d.xMinimum(), intersect2d.yMinimum(), zMin,
intersect2d.xMaximum(), intersect2d.yMaximum(), zMax );
}
bool QgsBox3d::intersects( const QgsBox3d &other ) const
{
if ( !mBounds2d.intersects( other.mBounds2d ) )
return false;
double z1 = ( mZmin > other.mZmin ? mZmin : other.mZmin );
double z2 = ( mZmax < other.mZmax ? mZmax : other.mZmax );
if ( z1 > z2 )
return false;
return true;
}
bool QgsBox3d::contains( const QgsBox3d &other ) const
{
if ( !mBounds2d.contains( other.mBounds2d ) )
return false;
return ( other.mZmin >= mZmin && other.mZmax <= mZmax );
}
bool QgsBox3d::contains( const QgsPointV2 &p ) const
{
if ( !mBounds2d.contains( QgsPoint( p.x(), p.y() ) ) )
return false;
return mZmin <= p.z() && p.z() <= mZmax;
}

187
src/core/qgsbox3d.h Normal file
View File

@ -0,0 +1,187 @@
/***************************************************************************
qgsbox3d.h
----------
begin : April 2017
copyright : (C) 2017 by Nyall Dawson
email : nyall dot dawson at gmail dot com
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#ifndef QGSBOX3D_H
#define QGSBOX3D_H
#include "qgis_core.h"
#include "qgsrectangle.h"
#include "qgspointv2.h"
/** \ingroup core
* A 3-dimensional box composed of x, y, z coordinates.
*
* A box composed of x/y/z minimum and maximum values. It is often used to return the 3D
* extent of a geometry or collection of geometries.
*
* \since QGIS 3.0
* \see QgsRectangle
*/
class CORE_EXPORT QgsBox3d
{
public:
/**
* Constructor for QgsBox3D which accepts the ranges of x/y/z coordinates.
*/
QgsBox3d( double xmin = 0, double ymin = 0, double mZmin = 0, double xmax = 0, double ymax = 0, double mZmax = 0 );
/**
* Constructs a QgsBox3D from two points representing opposite corners of the box.
* The box is normalized after construction.
*/
QgsBox3d( const QgsPointV2 &p1, const QgsPointV2 &p2 );
/**
* Sets the minimum \a x value.
* \see xMinimum()
* \see setXMaximum()
*/
void setXMinimum( double x );
/**
* Sets the maximum \a x value.
* \see xMaximum()
* \see setXMinimum()
*/
void setXMaximum( double x );
/**
* Returns the minimum x value.
* \see setXMinimum()
* \see xMaximum()
*/
double xMinimum() const { return mBounds2d.xMinimum(); }
/**
* Returns the maximum x value.
* \see setXMaximum()
* \see xMinimum()
*/
double xMaximum() const { return mBounds2d.xMaximum(); }
/**
* Sets the minimum \a y value.
* \see yMinimum()
* \see setYMaximum()
*/
void setYMinimum( double y );
/**
* Sets the maximum \a y value.
* \see yMaximum()
* \see setYMinimum()
*/
void setYMaximum( double y );
/**
* Returns the minimum y value.
* \see setYMinimum()
* \see yMaximum()
*/
double yMinimum() const { return mBounds2d.yMinimum(); }
/**
* Returns the maximum y value.
* \see setYMaximum()
* \see yMinimum()
*/
double yMaximum() const { return mBounds2d.yMaximum(); }
/**
* Sets the minimum \a z value.
* \see zMinimum()
* \see setZMaximum()
*/
void setZMinimum( double z );
/**
* Sets the maximum \a z value.
* \see zMaximum()
* \see setZMinimum()
*/
void setZMaximum( double z );
/**
* Returns the minimum z value.
* \see setZMinimum()
* \see zMaximum()
*/
double zMinimum() const { return mZmin; }
/**
* Returns the maximum z value.
* \see setZMaximum()
* \see zMinimum()
*/
double zMaximum() const { return mZmax; }
/**
* Normalize the box so it has non-negative width/height/depth.
*/
void normalize();
/**
* Returns the width of the box.
* \see height()
* \see depth()
*/
double width() const { return mBounds2d.width(); }
/**
* Returns the height of the box.
* \see width()
* \see depth()
*/
double height() const { return mBounds2d.height(); }
/**
* Returns the depth of the box.
* \see width()
* \see height()
*/
double depth() const { return mZmax - mZmin; }
/**
* Returns the intersection of this box and another 3D box.
*/
QgsBox3d intersect( const QgsBox3d &other ) const;
/**
* Returns true if box intersects with another box.
*/
bool intersects( const QgsBox3d &other ) const;
/**
* Returns true when box contains other box.
*/
bool contains( const QgsBox3d &other ) const;
/**
* Returns true when box contains a \a point.
*/
bool contains( const QgsPointV2 &point ) const;
private:
QgsRectangle mBounds2d;
double mZmin = 0.0;
double mZmax = 0.0;
};
#endif // QGSBOX3D_H

View File

@ -32,6 +32,7 @@ class QRectF;
*
* QgsRectangle is used to store a rectangle when double values are required.
* Examples are storing a layer extent or the current view extent of a map
* \see QgsBox3d
*/
class CORE_EXPORT QgsRectangle
{