Skip to content

Commit

Permalink
Move QgsOrientedBoundingBox out to own file
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Jul 15, 2023
1 parent 525098b commit f6cae1f
Show file tree
Hide file tree
Showing 12 changed files with 392 additions and 285 deletions.
93 changes: 93 additions & 0 deletions python/core/auto_generated/geometry/qgsorientedboundingbox.sip.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
/************************************************************************
* This file has been generated automatically from *
* *
* src/core/geometry/qgsorientedboundingbox.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/






class QgsOrientedBoundingBox
{
%Docstring(signature="appended")
Represents a oriented (rotated) bounding box in 3 dimensions.

.. warning::

Non-stable API, exposed to Python for unit testing only.

.. versionadded:: 3.34
%End

%TypeHeaderCode
#include "qgsorientedboundingbox.h"
%End
public:

QgsOrientedBoundingBox();
%Docstring
Constructor for a null bounding box.
%End

QgsOrientedBoundingBox( const QList<double> &center, QList< double > &halfAxes );
%Docstring
Constructor for a oriented bounding box, with a specified center and half axes matrix.
%End

bool isNull() const;
%Docstring
Returns ``True`` if the box is a null bounding box.
%End

double centerX() const;
%Docstring
Returns the center x-coordinate.

.. seealso:: :py:func:`centerY`

.. seealso:: :py:func:`centerZ`
%End

double centerY() const;
%Docstring
Returns the center y-coordinate.

.. seealso:: :py:func:`centerX`

.. seealso:: :py:func:`centerZ`
%End

double centerZ() const;
%Docstring
Returns the center z-coordinate.

.. seealso:: :py:func:`centerX`

.. seealso:: :py:func:`centerY`
%End


QList< double > halfAxesList() const /PyName=halfAxes/;
%Docstring
Returns the half axes matrix;
%End

QgsBox3d extent() const;
%Docstring
Returns the overall bounding box of the object.
%End

};


/************************************************************************
* This file has been generated automatically from *
* *
* src/core/geometry/qgsorientedboundingbox.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/
72 changes: 0 additions & 72 deletions python/core/auto_generated/tiledmesh/qgscesiumutils.sip.in
Original file line number Diff line number Diff line change
Expand Up @@ -11,78 +11,6 @@



class QgsOrientedBoundingBox
{
%Docstring(signature="appended")
Represents a oriented (rotated) bounding box in 3 dimensions.

.. warning::

Non-stable API, exposed to Python for unit testing only.

.. versionadded:: 3.34
%End

%TypeHeaderCode
#include "qgscesiumutils.h"
%End
public:

QgsOrientedBoundingBox();
%Docstring
Constructor for a null bounding box.
%End

QgsOrientedBoundingBox( const QList<double> &center, QList< double > &halfAxes );
%Docstring
Constructor for a oriented bounding box, with a specified center and half axes matrix.
%End

bool isNull() const;
%Docstring
Returns ``True`` if the box is a null bounding box.
%End

double centerX() const;
%Docstring
Returns the center x-coordinate.

.. seealso:: :py:func:`centerY`

.. seealso:: :py:func:`centerZ`
%End

double centerY() const;
%Docstring
Returns the center y-coordinate.

.. seealso:: :py:func:`centerX`

.. seealso:: :py:func:`centerZ`
%End

double centerZ() const;
%Docstring
Returns the center z-coordinate.

.. seealso:: :py:func:`centerX`

.. seealso:: :py:func:`centerY`
%End


QList< double > halfAxesList() const /PyName=halfAxes/;
%Docstring
Returns the half axes matrix;
%End

QgsBox3d extent() const;
%Docstring
Returns the overall bounding box of the object.
%End

};

class QgsCesiumUtils
{
%Docstring(signature="appended")
Expand Down
1 change: 1 addition & 0 deletions python/core/core_auto.sip
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,7 @@
%Include auto_generated/geometry/qgsmultipoint.sip
%Include auto_generated/geometry/qgsmultipolygon.sip
%Include auto_generated/geometry/qgsmultisurface.sip
%Include auto_generated/geometry/qgsorientedboundingbox.sip
%Include auto_generated/geometry/qgspoint.sip
%Include auto_generated/geometry/qgspolygon.sip
%Include auto_generated/geometry/qgsquadrilateral.sip
Expand Down
2 changes: 2 additions & 0 deletions src/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -847,6 +847,7 @@ set(QGIS_CORE_SRCS
geometry/qgsmultipoint.cpp
geometry/qgsmultipolygon.cpp
geometry/qgsmultisurface.cpp
geometry/qgsorientedboundingbox.cpp
geometry/qgspoint.cpp
geometry/qgspolygon.cpp
geometry/qgsquadrilateral.cpp
Expand Down Expand Up @@ -1431,6 +1432,7 @@ set(QGIS_CORE_HDRS
geometry/qgsmultipoint.h
geometry/qgsmultipolygon.h
geometry/qgsmultisurface.h
geometry/qgsorientedboundingbox.h
geometry/qgspoint.h
geometry/qgspolygon.h
geometry/qgsquadrilateral.h
Expand Down
74 changes: 74 additions & 0 deletions src/core/geometry/qgsorientedboundingbox.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/***************************************************************************
qgsorientedboundingbox.cpp
--------------------
begin : July 2023
copyright : (C) 2023 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 "qgsorientedboundingbox.h"
#include "qgsbox3d.h"

QgsOrientedBoundingBox::QgsOrientedBoundingBox() = default;

QgsOrientedBoundingBox::QgsOrientedBoundingBox( const QList<double> &center, QList<double> &halfAxes )
{
if ( center.size() == 3 )
{
mCenter[0] = center.at( 0 );
mCenter[1] = center.at( 1 );
mCenter[2] = center.at( 2 );
}
if ( halfAxes.size() == 9 )
{
for ( int i = 0; i < 9; ++i )
{
mHalfAxes[i] = halfAxes.at( i );
}
}
}

bool QgsOrientedBoundingBox::isNull() const
{
return std::isnan( mCenter[0] ) || std::isnan( mCenter[1] ) || std::isnan( mCenter[2] );
}

QList< double > QgsOrientedBoundingBox::halfAxesList() const
{
QList< double > res;
res.reserve( 9 );
for ( int i = 0; i < 9; ++i )
{
res.append( mHalfAxes[i] );
}
return res;
}

QgsBox3d QgsOrientedBoundingBox::extent() const
{
const double extent[3]
{
std::fabs( mHalfAxes[0] ) + std::fabs( mHalfAxes[3] ) + std::fabs( mHalfAxes[6] ),
std::fabs( mHalfAxes[1] ) + std::fabs( mHalfAxes[4] ) + std::fabs( mHalfAxes[7] ),
std::fabs( mHalfAxes[2] ) + std::fabs( mHalfAxes[5] ) + std::fabs( mHalfAxes[8] ),
};

const double minX = mCenter[0] - extent[0];
const double maxX = mCenter[0] + extent[0];
const double minY = mCenter[1] - extent[1];
const double maxY = mCenter[1] + extent[1];
const double minZ = mCenter[2] - extent[2];
const double maxZ = mCenter[2] + extent[2];

return QgsBox3d( minX, minY, minZ, maxX, maxY, maxZ );
}
107 changes: 107 additions & 0 deletions src/core/geometry/qgsorientedboundingbox.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
/***************************************************************************
qgsorientedboundingbox.h
--------------------
begin : July 2023
copyright : (C) 2023 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 QGSORIENTEDBOUNDINGBOX_H
#define QGSORIENTEDBOUNDINGBOX_H

#include "qgis_core.h"
#include "qgis_sip.h"

#include <QList>
#include <limits>

class QgsBox3d;

/**
* \brief Represents a oriented (rotated) bounding box in 3 dimensions.
*
* \ingroup core
*
* \warning Non-stable API, exposed to Python for unit testing only.
*
* \since QGIS 3.34
*/
class CORE_EXPORT QgsOrientedBoundingBox
{
public:

/**
* Constructor for a null bounding box.
*/
QgsOrientedBoundingBox();

/**
* Constructor for a oriented bounding box, with a specified center and half axes matrix.
*/
QgsOrientedBoundingBox( const QList<double> &center, QList< double > &halfAxes );

/**
* Returns TRUE if the box is a null bounding box.
*/
bool isNull() const;

/**
* Returns the center x-coordinate.
*
* \see centerY()
* \see centerZ()
*/
double centerX() const { return mCenter[0]; }

/**
* Returns the center y-coordinate.
* \see centerX()
* \see centerZ()
*/
double centerY() const { return mCenter[1]; }

/**
* Returns the center z-coordinate.
*
* \see centerX()
* \see centerY()
*/
double centerZ() const { return mCenter[2]; }

/**
* Returns the half axes matrix;
*/
const double *halfAxes() const SIP_SKIP { return mHalfAxes; }

/**
* Returns the half axes matrix;
*/
QList< double > halfAxesList() const SIP_PYNAME( halfAxes );

/**
* Returns the overall bounding box of the object.
*/
QgsBox3d extent() const;

private:

double mCenter[ 3 ] { std::numeric_limits< double >::quiet_NaN(), std::numeric_limits< double >::quiet_NaN(), std::numeric_limits< double >::quiet_NaN() };
double mHalfAxes[9] { 1, 0, 0, 0, 1, 0, 0, 0, 1 };

friend class QgsCesiumUtils;

};


#endif // QGSORIENTEDBOUNDINGBOX_H
3 changes: 2 additions & 1 deletion src/core/tiledmesh/qgscesiumtilesdataprovider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "qgscesiumutils.h"
#include "qgssphere.h"
#include "qgslogger.h"
#include "qgsorientedboundingbox.h"

#include <QUrl>
#include <QIcon>
Expand Down Expand Up @@ -72,7 +73,7 @@ void QgsCesiumTilesDataProviderSharedData::setTilesetContent( const QString &til
}
else if ( rootBoundingVolume.contains( "box" ) )
{
const QgsOrientedBoundingBox bbox = QgsOrientedBoundingBox::fromJson( rootBoundingVolume["box"] );
const QgsOrientedBoundingBox bbox = QgsCesiumUtils::parseBox( rootBoundingVolume["box"] );
if ( !bbox.isNull() )
{
const QgsBox3d rootRegion = bbox.extent();
Expand Down
Loading

0 comments on commit f6cae1f

Please sign in to comment.