QGIS API Documentation 3.40.0-Bratislava (b56115d8743)
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#define SIP_NO_FILE
23
24#include <QVector>
25#include <QVector3D>
26#include <QSet>
27#include <QList>
28#include <memory>
29#include "qgis_core.h"
30#include "qgsmeshdataprovider.h"
31#include "qgsgeometry.h"
32#include "qgsmeshspatialindex.h"
33#include "qgstopologicalmesh.h"
35
37class QgsRectangle;
38
51class CORE_EXPORT QgsTriangularMesh // TODO rename to QgsRendererMesh in QGIS 4
52{
53 public:
54
57
64 bool update( QgsMesh *nativeMesh, const QgsCoordinateTransform &transform );
65
76 bool update( QgsMesh *nativeMesh );
77
84 const QVector<QgsMeshVertex> &vertices() const ;
85
87 const QVector<QgsMeshFace> &triangles() const ;
88
90 const QVector<QgsMeshEdge> &edges() const ;
91
97 Q_DECL_DEPRECATED const QVector<QgsMeshVertex> &centroids() const ;
98
103 const QVector<QgsMeshVertex> &faceCentroids() const ;
104
109 const QVector<QgsMeshVertex> &edgeCentroids() const ;
110
112 const QVector<int> &trianglesToNativeFaces() const ;
113
115 const QVector<int> &edgesToNativeEdges() const ;
116
125 QgsPointXY transformFromLayerToTrianglesCoordinates( const QgsPointXY &point ) const;
126
136 int faceIndexForPoint( const QgsPointXY &point ) const ;
137
147 int faceIndexForPoint_v2( const QgsPointXY &point ) const;
148
158 int nativeFaceIndexForPoint( const QgsPointXY &point ) const ;
159
169 QList<int> nativeFaceIndexForRectangle( const QgsRectangle &rectangle ) const ;
170
180 QList<int> faceIndexesForRectangle( const QgsRectangle &rectangle ) const ;
181
189 QList<int> edgeIndexesForRectangle( const QgsRectangle &rectangle ) const ;
190
199 QVector<QVector3D> vertexNormals( float vertScale ) const;
200
216 QVector<QgsTriangularMesh *> simplifyMesh( double reductionFactor, int minimumTrianglesCount = 10 ) const;
217
224 double averageTriangleSize() const;
225
236 int levelOfDetail() const;
237
245 QgsRectangle extent() const;
246
251 bool contains( const QgsMesh::ElementType &type ) const;
252
263 {
264 public:
265
267 Changes() = default;
268
272 Changes( const QgsTopologicalMesh::Changes &topologicalChanges, const QgsMesh &nativeMesh );
273
274 private:
275 // triangular mesh elements that can be changed if the triangular mesh is updated, are not stored and have to be retrieve
276 QVector<QgsMeshVertex> mAddedVertices;
277 QList<int> mVerticesIndexesToRemove;
278 QList<int> mChangedVerticesCoordinates;
279 mutable QList<double> mOldZValue;
280 QList<double> mNewZValue;
281 QList<QgsPointXY> mOldXYValue;
282 QList<QgsPointXY> mNewXYValue;
283
284 QVector<QgsMeshFace> mNativeFacesToAdd;
285 QList<int> mNativeFaceIndexesToRemove;
286 QVector<QgsMeshFace> mNativeFacesToRemove;
287 QList<int> mNativeFaceIndexesGeometryChanged;
288 QVector<QgsMeshFace> mNativeFacesGeometryChanged;
289 mutable QList<int> mTriangleIndexesGeometryChanged;
290
291 mutable int mTrianglesAddedStartIndex = 0; // defined each time the changes are apply
292 mutable QList<int> mRemovedTriangleIndexes; // defined when changes are apply the first time
293
294 friend class QgsTriangularMesh;
295 };
296
302 void applyChanges( const Changes &changes );
303
309 void reverseChanges( const Changes &changes, const QgsMesh &nativeMesh );
310
317 QgsMeshVertex nativeToTriangularCoordinates( const QgsMeshVertex &vertex ) const;
318
325 QgsMeshVertex triangularToNativeCoordinates( const QgsMeshVertex &vertex ) const;
326
333 QgsRectangle nativeExtent();
334
335 private:
336
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
384 friend class TestQgsTriangularMesh;
385};
386
387namespace QgsMeshUtils
388{
390 CORE_EXPORT QgsGeometry toGeometry( const QgsMeshFace &face, const QVector<QgsMeshVertex> &vertices );
391
393 CORE_EXPORT QgsMeshVertex centroid( const QgsMeshFace &face, const QVector<QgsMeshVertex> &vertices );
394
396 CORE_EXPORT std::unique_ptr< QgsPolygon > toPolygon( const QgsMeshFace &face, const QVector<QgsMeshVertex> &vertices );
397
402 CORE_EXPORT QSet<int> nativeFacesFromTriangles( const QList<int> &triangleIndexes, const QVector<int> &trianglesToNativeFaces );
403
408 CORE_EXPORT QSet<int> nativeEdgesFromEdges( const QList<int> &edgesIndexes, const QVector<int> &edgesToNativeEdges );
409
414 CORE_EXPORT QSet<int> nativeVerticesFromTriangles( const QList<int> &triangleIndexes, const QVector<QgsMeshFace> &triangles );
415
420 CORE_EXPORT QSet<int> nativeVerticesFromEdges( const QList<int> &edgesIndexes, const QVector<QgsMeshEdge> &edges );
421
426 bool isInTriangleFace( const QgsPointXY point, const QgsMeshFace &face, const QVector<QgsMeshVertex> &vertices );
427
432 void setCounterClockwise( QgsMeshFace &triangle, const QgsMeshVertex &v0, const QgsMeshVertex &v1, const QgsMeshVertex &v2 );
433
434};
435
436#endif // QGSTRIANGULARMESH_H
TransformDirection
Indicates the direction (forward or inverse) of a transform.
Definition qgis.h:2502
Class for doing transforms between two map coordinate systems.
A geometry is the spatial representation of a feature.
A spatial index for QgsMeshFace or QgsMeshEdge objects.
A class to represent a 2D point.
Definition qgspointxy.h:60
Point geometry type, with support for z-dimension and m-values.
Definition qgspoint.h:49
A rectangle specified with double values.
Contains information about the context of a rendering operation.
Class that contains topological differences between two states of a topological mesh,...
The Changes class is used to make changes of the triangular and to keep traces of this changes If a C...
Changes()=default
Default constructor, no changes.
Triangular/Derived Mesh is mesh with vertices in map coordinates.
QVector< int > QgsMeshFace
List of vertex indexes.
Mesh - vertices, edges and faces.
ElementType
Defines type of mesh elements.