QGIS API Documentation 4.1.0-Master (5bf3c20f3c9)
Loading...
Searching...
No Matches
qgstriangularmesh.h
Go to the documentation of this file.
1/***************************************************************************
2 qgstriangularmesh.h
3 -------------------
4 begin : April 2018
5 copyright : (C) 2018 by Peter Petrik
6 email : zilolv 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 QGSTRIANGULARMESH_H
19#define QGSTRIANGULARMESH_H
20
21
22#include <memory>
23
24#include "qgis_core.h"
26#include "qgsgeometry.h"
27#include "qgsmeshdataprovider.h"
28#include "qgsmeshspatialindex.h"
29#include "qgstopologicalmesh.h"
30
31#include <QList>
32#include <QSet>
33#include <QVector>
34#include <QVector3D>
35
36#define SIP_NO_FILE
37
39class QgsRectangle;
40
53class CORE_EXPORT QgsTriangularMesh // TODO rename to QgsRendererMesh in QGIS 5
54{
55 public:
58
65 bool update( QgsMesh *nativeMesh, const QgsCoordinateTransform &transform );
66
77 bool update( QgsMesh *nativeMesh );
78
85 const QVector<QgsMeshVertex> &vertices() const;
86
88 const QVector<QgsMeshFace> &triangles() const;
89
91 const QVector<QgsMeshEdge> &edges() const;
92
98 Q_DECL_DEPRECATED const QVector<QgsMeshVertex> &centroids() const;
99
104 const QVector<QgsMeshVertex> &faceCentroids() const;
105
110 const QVector<QgsMeshVertex> &edgeCentroids() const;
111
113 const QVector<int> &trianglesToNativeFaces() const;
114
116 const QVector<int> &edgesToNativeEdges() const;
117
127
137 int faceIndexForPoint( const QgsPointXY &point ) const;
138
148 int faceIndexForPoint_v2( const QgsPointXY &point ) const;
149
159 int nativeFaceIndexForPoint( const QgsPointXY &point ) const;
160
170 QList<int> nativeFaceIndexForRectangle( const QgsRectangle &rectangle ) const;
171
181 QList<int> faceIndexesForRectangle( const QgsRectangle &rectangle ) const;
182
190 QList<int> edgeIndexesForRectangle( const QgsRectangle &rectangle ) const;
191
199
200 QVector<QVector3D> vertexNormals( float vertScale ) const;
201
217 QVector<QgsTriangularMesh *> simplifyMesh( double reductionFactor, int minimumTrianglesCount = 10 ) const;
218
225 double averageTriangleSize() const;
226
237 int levelOfDetail() const;
238
246 QgsRectangle extent() const;
247
252 bool contains( const QgsMesh::ElementType &type ) const;
253
265 {
266 public:
268 Changes() = default;
269
273 Changes( const QgsTopologicalMesh::Changes &topologicalChanges, const QgsMesh &nativeMesh );
274
275 private:
276 // triangular mesh elements that can be changed if the triangular mesh is updated, are not stored and have to be retrieve
277 QVector<QgsMeshVertex> mAddedVertices;
278 QList<int> mVerticesIndexesToRemove;
279 QList<int> mChangedVerticesCoordinates;
280 mutable QList<double> mOldZValue;
281 QList<double> mNewZValue;
282 QList<QgsPointXY> mOldXYValue;
283 QList<QgsPointXY> mNewXYValue;
284
285 QVector<QgsMeshFace> mNativeFacesToAdd;
286 QList<int> mNativeFaceIndexesToRemove;
287 QVector<QgsMeshFace> mNativeFacesToRemove;
288 QList<int> mNativeFaceIndexesGeometryChanged;
289 QVector<QgsMeshFace> mNativeFacesGeometryChanged;
290 mutable QList<int> mTriangleIndexesGeometryChanged;
291
292 mutable int mTrianglesAddedStartIndex = 0; // defined each time the changes are apply
293 mutable QList<int> mRemovedTriangleIndexes; // defined when changes are apply the first time
294
295 friend class QgsTriangularMesh;
296 };
297
303 void applyChanges( const Changes &changes );
304
310 void reverseChanges( const Changes &changes, const QgsMesh &nativeMesh );
311
319
327
335
336 private:
347 void triangulate( const QgsMeshFace &face, int nativeIndex );
348
349 void addVertex( const QgsMeshVertex &vertex );
350
351 QgsMeshVertex transformVertex( const QgsMeshVertex &vertex, Qgis::TransformDirection direction ) const;
352
353 // calculate the centroid of the native mesh, mNativeMeshCentroids container must have the emplacment for the corresponding centroid before calling this method
354 QgsMeshVertex calculateCentroid( const QgsMeshFace &nativeFace ) const;
355
356 // check clock wise and calculate average size of triangles
357 void finalizeTriangles();
358
359 // vertices: map CRS; 0-N ... native vertices, N+1 - len ... extra vertices
360 // faces are derived triangles
361 QgsMesh mTriangularMesh;
362 QVector<int> mTrianglesToNativeFaces; //len(mTrianglesToNativeFaces) == len(mTriangles). Mapping derived -> native
363 QVector<int> mEdgesToNativeEdges; //len(mEdgesToNativeEdges) == len(mEdges). Mapping derived -> native
364
365 // centroids of the native faces in map CRS
366 QVector<QgsMeshVertex> mNativeMeshFaceCentroids;
367
368 // centroids of the native edges in map CRS
369 QVector<QgsMeshVertex> mNativeMeshEdgeCentroids;
370
371 QgsMeshSpatialIndex mSpatialFaceIndex;
372 QgsMeshSpatialIndex mSpatialEdgeIndex;
373 QgsCoordinateTransform mCoordinateTransform; //coordinate transform used to convert native mesh vertices to map vertices
374
375 mutable QgsRectangle mExtent;
376 mutable bool mIsExtentValid = false;
377
378 // average size of the triangles
379 double mAverageTriangleSize = 0;
380 int mLod = 0;
381
382 const QgsTriangularMesh *mBaseTriangularMesh = nullptr;
383
385};
386
387
388#endif // QGSTRIANGULARMESH_H
TransformDirection
Indicates the direction (forward or inverse) of a transform.
Definition qgis.h:2764
Handles coordinate transforms between two coordinate systems.
A spatial index for QgsMeshFace or QgsMeshEdge objects.
Represents a 2D point.
Definition qgspointxy.h:62
A rectangle specified with double values.
Contains information about the context of a rendering operation.
Contains topological differences between two states of a topological mesh, only accessible from the Q...
Makes changes to a triangular mesh and keeps track of these changes.
Changes()=default
Default constructor, no changes.
const QVector< QgsMeshVertex > & edgeCentroids() const
Returns centroids of the native edges in map CRS.
friend class TestQgsTriangularMesh
const QVector< QgsMeshFace > & triangles() const
Returns triangles.
QVector< QgsTriangularMesh * > simplifyMesh(double reductionFactor, int minimumTrianglesCount=10) const
Returns simplified meshes.
QgsRectangle nativeExtent()
Returns the extent of the mesh in the native mesh coordinates system, returns empty extent if the tra...
QgsPointXY transformFromLayerToTrianglesCoordinates(const QgsPointXY &point) const
Transforms a point from layer coordinates system to triangular Mesh coordinates system.
int levelOfDetail() const
Returns the corresponding index of level of detail on which this mesh is associated.
QgsRectangle extent() const
Returns the extent of the triangular mesh in map coordinates.
int faceIndexForPoint(const QgsPointXY &point) const
Finds index of triangle at given point It uses spatial indexing.
int nativeFaceIndexForPoint(const QgsPointXY &point) const
Finds index of native face at given point It uses spatial indexing.
double averageTriangleSize() const
Returns the average size of triangles in map unit.
void reverseChanges(const Changes &changes, const QgsMesh &nativeMesh)
Reverses the changes on the triangular mesh (see Changes).
void applyChanges(const Changes &changes)
Applies the changes on the triangular mesh (see Changes).
QList< int > edgeIndexesForRectangle(const QgsRectangle &rectangle) const
Finds indexes of edges intersecting given bounding box It uses spatial indexing.
Q_DECL_DEPRECATED const QVector< QgsMeshVertex > & centroids() const
Returns centroids of the native faces in map CRS.
const QVector< QgsMeshVertex > & vertices() const
Returns vertices in map coordinate system.
const QVector< QgsMeshEdge > & edges() const
Returns edges.
bool contains(const QgsMesh::ElementType &type) const
Returns whether the mesh contains mesh elements of given type.
QgsMeshVertex triangularToNativeCoordinates(const QgsMeshVertex &vertex) const
Transforms the vertex from triangular mesh coordinates system to native coordinates system.
QVector< QVector3D > vertexNormals(float vertScale) const
Calculates and returns normal vector on each vertex that is part of any face.
QgsMeshVertex nativeToTriangularCoordinates(const QgsMeshVertex &vertex) const
Transforms the vertex from native coordinates system to triangular mesh coordinates system.
bool update(QgsMesh *nativeMesh, const QgsCoordinateTransform &transform)
Constructs triangular mesh from layer's native mesh and transform to destination CRS.
const QVector< QgsMeshVertex > & faceCentroids() const
Returns centroids of the native faces in map CRS.
QList< int > nativeFaceIndexForRectangle(const QgsRectangle &rectangle) const
Finds indexes of native faces which bounding boxes intersect given bounding box It uses spatial index...
const QVector< int > & trianglesToNativeFaces() const
Returns mapping between triangles and original faces.
const QVector< int > & edgesToNativeEdges() const
Returns mapping between edges and original edges.
QList< int > faceIndexesForRectangle(const QgsRectangle &rectangle) const
Finds indexes of triangles intersecting given bounding box It uses spatial indexing.
int faceIndexForPoint_v2(const QgsPointXY &point) const
Finds index of triangle at given point It uses spatial indexing and don't use geos to be faster.
QVector< int > QgsMeshFace
List of vertex indexes.
QgsPoint QgsMeshVertex
xyz coords of vertex
Mesh - vertices, edges and faces.
ElementType
Defines type of mesh elements.