Skip to content

Commit 27c670e

Browse files
committedJan 24, 2019
expose mesh spatial index similarly to vector spatial index to API. fix travis issues and documentation
1 parent 9d4d1c9 commit 27c670e

File tree

8 files changed

+113
-98
lines changed

8 files changed

+113
-98
lines changed
 
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
/************************************************************************
2+
* This file has been generated automatically from *
3+
* *
4+
* src/core/mesh/qgsmeshspatialindex.h *
5+
* *
6+
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
7+
************************************************************************/
8+
9+
10+
11+
12+
13+
14+
class QgsMeshSpatialIndex
15+
{
16+
%Docstring
17+
18+
A spatial index for QgsMeshFace objects.
19+
20+
QgsMeshSpatialIndex objects are implicitly shared and can be inexpensively copied.
21+
22+
.. note::
23+
24+
While the underlying libspatialindex is not thread safe on some platforms, the QgsMeshSpatialIndex
25+
class implements its own locks and accordingly, a single QgsMeshSpatialIndex object can safely
26+
be used across multiple threads
27+
28+
.. seealso:: :py:class:`QgsSpatialIndex`
29+
30+
31+
.. versionadded:: 3.6
32+
%End
33+
34+
%TypeHeaderCode
35+
#include "qgsmeshspatialindex.h"
36+
%End
37+
public:
38+
39+
QgsMeshSpatialIndex();
40+
%Docstring
41+
Constructor for :py:class:`QgsSpatialIndex`. Creates an empty R-tree index.
42+
%End
43+
44+
explicit QgsMeshSpatialIndex( const QgsMesh &triangularMesh, QgsFeedback *feedback = 0 );
45+
%Docstring
46+
Constructor - creates R-tree and bulk loads faces from the specified mesh
47+
48+
The optional ``feedback`` object can be used to allow cancelation of bulk face loading. Ownership
49+
of ``feedback`` is not transferred, and callers must take care that the lifetime of feedback exceeds
50+
that of the spatial index construction.
51+
%End
52+
53+
QgsMeshSpatialIndex( const QgsMeshSpatialIndex &other );
54+
%Docstring
55+
Copy constructor
56+
%End
57+
58+
~QgsMeshSpatialIndex();
59+
60+
61+
QList<int> intersects( const QgsRectangle &rectangle ) const;
62+
%Docstring
63+
Returns a list of face ids with a bounding box which intersects the specified ``rectangle``.
64+
65+
.. note::
66+
67+
The intersection test is performed based on the face bounding boxes only, so it is necessary
68+
to manually test the returned faces for exact geometry intersection when required.
69+
%End
70+
71+
QList<int> nearestNeighbor( const QgsPointXY &point, int neighbors ) const;
72+
%Docstring
73+
Returns nearest neighbors to a ``point``. The number of neighbours returned is specified
74+
by the ``neighbours`` argument.
75+
76+
.. note::
77+
78+
The nearest neighbour test is performed based on the face bounding boxes only,
79+
so this method is not guaranteed to return the actual closest neighbours.
80+
%End
81+
82+
};
83+
84+
/************************************************************************
85+
* This file has been generated automatically from *
86+
* *
87+
* src/core/mesh/qgsmeshspatialindex.h *
88+
* *
89+
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
90+
************************************************************************/

‎python/core/auto_generated/qgsspatialindex.sip.in

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ QgsSpatialIndex objects are implicitly shared and can be inexpensively copied.
2929
be used across multiple threads.
3030

3131
.. seealso:: :py:class:`QgsSpatialIndexKDBush`
32+
33+
.. seealso:: :py:class:`QgsMeshSpatialIndex`
3234
%End
3335

3436
%TypeHeaderCode
@@ -157,7 +159,6 @@ Gets reference count - just for debugging!
157159

158160
};
159161

160-
161162
/************************************************************************
162163
* This file has been generated automatically from *
163164
* *

‎python/core/core_auto.sip

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,7 @@
239239
%Include auto_generated/raster/qgshillshaderenderer.sip
240240
%Include auto_generated/mesh/qgsmeshlayerinterpolator.sip
241241
%Include auto_generated/mesh/qgsmeshrenderersettings.sip
242+
%Include auto_generated/mesh/qgsmeshspatialindex.sip
242243
%Include auto_generated/scalebar/qgsdoubleboxscalebarrenderer.sip
243244
%Include auto_generated/scalebar/qgsnumericscalebarrenderer.sip
244245
%Include auto_generated/scalebar/qgsscalebarsettings.sip

‎src/core/mesh/qgsmeshspatialindex.cpp

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@
1313
* *
1414
***************************************************************************/
1515

16-
///@cond PRIVATE
17-
1816
#include "qgsmeshspatialindex.h"
1917

2018
#include "qgsmeshdataprovider.h"
@@ -195,7 +193,7 @@ class QgsMeshFaceIteratorDataStream : public IDataStream
195193

196194
/**
197195
* \ingroup core
198-
* \class QgsSpatialIndexData
196+
* \class QgsSpatialIndexData
199197
* \brief Data of spatial index that may be implicitly shared
200198
* \note not available in Python bindings
201199
*/
@@ -208,10 +206,10 @@ class QgsMeshSpatialIndexData : public QSharedData
208206
}
209207

210208
/**
211-
* Constructor for QgsSpatialIndexData which bulk loads features from the specified feature iterator
209+
* Constructor for QgsSpatialIndexData which bulk loads faces from the specified mesh
212210
* \a fi.
213211
*
214-
* The optional \a feedback object can be used to allow cancelation of bulk feature loading. Ownership
212+
* The optional \a feedback object can be used to allow cancelation of bulk face loading. Ownership
215213
* of \a feedback is not transferred, and callers must take care that the lifetime of feedback exceeds
216214
* that of the spatial index construction.
217215
*/
@@ -342,5 +340,3 @@ QList<int> QgsMeshSpatialIndex::nearestNeighbor( const QgsPointXY &point, int ne
342340

343341
return list;
344342
}
345-
346-
///@endcond

‎src/core/mesh/qgsmeshspatialindex.h

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,8 @@
1616
#ifndef QGSMESHSPATIALINDEX_H
1717
#define QGSMESHSPATIALINDEX_H
1818

19-
///@cond PRIVATE
20-
2119
#include "qgis_sip.h"
2220

23-
#define SIP_NO_FILE
24-
2521
class QgsRectangle;
2622
class QgsPointXY;
2723
class QgsFeedback;
@@ -45,13 +41,12 @@ class QgsMeshSpatialIndexData;
4541
* class implements its own locks and accordingly, a single QgsMeshSpatialIndex object can safely
4642
* be used across multiple threads
4743
*
48-
* \see QgsSpatialIndex
44+
* \see QgsSpatialIndex, which is for vector features
4945
*
5046
* \since QGIS 3.6
5147
*/
52-
class CORE_NO_EXPORT QgsMeshSpatialIndex
48+
class CORE_EXPORT QgsMeshSpatialIndex
5349
{
54-
5550
public:
5651

5752
/**
@@ -60,9 +55,9 @@ class CORE_NO_EXPORT QgsMeshSpatialIndex
6055
QgsMeshSpatialIndex();
6156

6257
/**
63-
* Constructor - creates R-tree and bulk loads it with features from the iterator.
58+
* Constructor - creates R-tree and bulk loads faces from the specified mesh
6459
*
65-
* The optional \a feedback object can be used to allow cancelation of bulk feature loading. Ownership
60+
* The optional \a feedback object can be used to allow cancelation of bulk face loading. Ownership
6661
* of \a feedback is not transferred, and callers must take care that the lifetime of feedback exceeds
6762
* that of the spatial index construction.
6863
*/
@@ -80,25 +75,22 @@ class CORE_NO_EXPORT QgsMeshSpatialIndex
8075
/**
8176
* Returns a list of face ids with a bounding box which intersects the specified \a rectangle.
8277
*
83-
* \note The intersection test is performed based on the feature bounding boxes only, so for non-point
84-
* geometry features it is necessary to manually test the returned features for exact geometry intersection
85-
* when required.
78+
* \note The intersection test is performed based on the face bounding boxes only, so it is necessary
79+
* to manually test the returned faces for exact geometry intersection when required.
8680
*/
8781
QList<int> intersects( const QgsRectangle &rectangle ) const;
8882

8983
/**
9084
* Returns nearest neighbors to a \a point. The number of neighbours returned is specified
9185
* by the \a neighbours argument.
9286
*
93-
* \note The nearest neighbour test is performed based on the feature bounding boxes only, so for non-point
94-
* geometry features this method is not guaranteed to return the actual closest neighbours.
87+
* \note The nearest neighbour test is performed based on the face bounding boxes only,
88+
* so this method is not guaranteed to return the actual closest neighbours.
9589
*/
9690
QList<int> nearestNeighbor( const QgsPointXY &point, int neighbors ) const;
9791

9892
private:
9993
QSharedDataPointer<QgsMeshSpatialIndexData> d;
10094
};
10195

102-
///@endcond
103-
10496
#endif //QGSMESHSPATIALINDEX_H

‎src/core/mesh/qgstriangularmesh.cpp

Lines changed: 5 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -22,47 +22,10 @@
2222
#include "qgstriangularmesh.h"
2323
#include "qgsrendercontext.h"
2424
#include "qgscoordinatetransform.h"
25-
#include "qgsfeatureid.h"
2625
#include "qgsgeometry.h"
2726
#include "qgsrectangle.h"
28-
#include "qgsfeatureiterator.h"
2927
#include "qgslogger.h"
30-
31-
///@cond PRIVATE
32-
33-
QgsMeshFeatureIterator::QgsMeshFeatureIterator( QgsMesh *mesh )
34-
: QgsAbstractFeatureIterator( QgsFeatureRequest() )
35-
, mMesh( mesh )
36-
{}
37-
38-
QgsMeshFeatureIterator::~QgsMeshFeatureIterator() = default;
39-
40-
bool QgsMeshFeatureIterator::rewind()
41-
{
42-
it = 0;
43-
return true;
44-
}
45-
bool QgsMeshFeatureIterator::close()
46-
{
47-
mMesh = nullptr;
48-
return true;
49-
}
50-
51-
bool QgsMeshFeatureIterator::fetchFeature( QgsFeature &f )
52-
{
53-
if ( !mMesh || mMesh->faces.size() <= it )
54-
return false;
55-
56-
const QgsMeshFace &face = mMesh->faces.at( it ) ;
57-
QgsGeometry geom = QgsMeshUtils::toGeometry( face, mMesh->vertices );
58-
f.setGeometry( geom );
59-
f.setId( it );
60-
++it;
61-
return true;
62-
}
63-
64-
65-
///@endcond
28+
#include "qgsmeshspatialindex.h"
6629

6730
static void ENP_centroid_step( const QPolygonF &pX, double &cx, double &cy, double &signedArea, int i, int i1 )
6831
{
@@ -108,6 +71,7 @@ static void ENP_centroid( const QPolygonF &pX, double &cx, double &cy )
10871
cy /= ( 6.0 * signedArea );
10972
}
11073

74+
11175
void QgsTriangularMesh::triangulate( const QgsMeshFace &face, int nativeIndex )
11276
{
11377
int vertexCount = face.size();
@@ -128,6 +92,9 @@ void QgsTriangularMesh::triangulate( const QgsMeshFace &face, int nativeIndex )
12892
mTrianglesToNativeFaces.push_back( nativeIndex );
12993
}
13094

95+
QgsTriangularMesh::~QgsTriangularMesh() = default;
96+
QgsTriangularMesh::QgsTriangularMesh() = default;
97+
13198
void QgsTriangularMesh::update( QgsMesh *nativeMesh, QgsRenderContext *context )
13299
{
133100
Q_ASSERT( nativeMesh );

‎src/core/mesh/qgstriangularmesh.h

Lines changed: 2 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -26,44 +26,12 @@
2626
#include "qgis_core.h"
2727
#include "qgsmeshdataprovider.h"
2828
#include "qgsgeometry.h"
29-
#include "qgsfeatureid.h"
3029
#include "qgsmeshspatialindex.h"
31-
#include "qgsfeatureiterator.h"
3230

3331
class QgsRenderContext;
3432
class QgsCoordinateTransform;
3533
class QgsRectangle;
3634

37-
///@cond PRIVATE
38-
39-
/**
40-
* Delivers mesh faces as features
41-
*/
42-
class CORE_NO_EXPORT QgsMeshFeatureIterator : public QgsAbstractFeatureIterator
43-
{
44-
public:
45-
46-
/**
47-
* This constructor creates a feature iterator, that delivers all features
48-
*
49-
* \param mesh The mesh to use
50-
*/
51-
QgsMeshFeatureIterator( QgsMesh *mesh );
52-
~QgsMeshFeatureIterator() override;
53-
54-
bool rewind() override;
55-
bool close() override;
56-
57-
protected:
58-
bool fetchFeature( QgsFeature &f ) override;
59-
60-
private:
61-
QgsMesh *mMesh = nullptr;
62-
int it = 0;
63-
};
64-
65-
///@endcond
66-
6735
/**
6836
* \ingroup core
6937
*
@@ -79,9 +47,9 @@ class CORE_EXPORT QgsTriangularMesh
7947
{
8048
public:
8149
//! Ctor
82-
QgsTriangularMesh() = default;
50+
QgsTriangularMesh();
8351
//! Dtor
84-
~QgsTriangularMesh() = default;
52+
~QgsTriangularMesh();
8553

8654
/**
8755
* Constructs triangular mesh from layer's native mesh and context. Populates spatial index.

‎src/core/qgsspatialindex.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ class QgsFeatureSource;
6363
* be used across multiple threads.
6464
*
6565
* \see QgsSpatialIndexKDBush, which is an optimised non-mutable index for point geometries only.
66+
* \see QgsMeshSpatialIndex, which is for mesh faces
6667
*/
6768
class CORE_EXPORT QgsSpatialIndex : public QgsFeatureSink
6869
{
@@ -214,5 +215,4 @@ class CORE_EXPORT QgsSpatialIndex : public QgsFeatureSink
214215

215216
};
216217

217-
#endif
218-
218+
#endif //QGSSPATIALINDEX_H

0 commit comments

Comments
 (0)
Please sign in to comment.