QGIS API Documentation 3.43.0-Master (cd2944e57f9)
qgstopologicalmesh.h
Go to the documentation of this file.
1/***************************************************************************
2 qgstopologicalmesh.h - QgsTopologicalMesh
3
4 ---------------------
5 begin : 18.6.2021
6 copyright : (C) 2021 by Vincent Cloarec
7 email : vcloarec at gmail dot com
8 ***************************************************************************
9 * *
10 * This program is free software; you can redistribute it and/or modify *
11 * it under the terms of the GNU General Public License as published by *
12 * the Free Software Foundation; either version 2 of the License, or *
13 * (at your option) any later version. *
14 * *
15 ***************************************************************************/
16#ifndef QGSTOPOLOGICALMESH_H
17#define QGSTOPOLOGICALMESH_H
18
19#include <QSet>
20
21#include "qgsmeshdataprovider.h"
22
23#if defined(_MSC_VER)
24template CORE_EXPORT QVector<int> SIP_SKIP;
25template CORE_EXPORT QList<int> SIP_SKIP;
26template CORE_EXPORT QVector<QVector<int>> SIP_SKIP;
27#endif
28
31
45class CORE_EXPORT QgsTopologicalMesh
46{
47 public:
48
49 using FaceNeighbors = QVector<int>;
50
60 class CORE_EXPORT TopologicalFaces
61 {
62 public:
63
68 SIP_SKIP QVector<QgsMeshFace> meshFaces() const {return mFaces;}
69
71 void clear();
72
78 SIP_SKIP QVector<FaceNeighbors> facesNeighborhood() const;
79
81 int vertexToFace( int vertexIndex ) const;
82
83 private:
84 QVector<QgsMeshFace> mFaces; // the faces containing the vertices indexes in the mesh
85 QVector<FaceNeighbors> mFacesNeighborhood; // neighborhood of the faces, face indexes are local
86 QMultiHash<int, int> mVerticesToFace; // map of vertices to incident face, face indexes are local
87 QList<int> mBoundaries; // list of boundary vertices indexes in the mesh
88
89 friend class QgsTopologicalMesh;
91 };
92
93
101 class CORE_EXPORT Changes
102 {
103 public:
104
110 SIP_SKIP QVector<QgsMeshFace> addedFaces() const;
111
117 SIP_SKIP QVector<QgsMeshFace> removedFaces() const;
118
120 QList<int> removedFaceIndexes() const;
121
123#ifndef SIP_RUN
124 QVector<QgsMeshVertex> addedVertices() const;
125#else
126 QVector<QgsPoint> addedVertices() const;
127#endif
128
130 QList<int> verticesToRemoveIndexes() const;
131
133 QList<int> changedCoordinatesVerticesIndexes() const;
134
136 QList<double> newVerticesZValues() const;
137
139 QList<QgsPointXY> newVerticesXYValues() const;
140
142 QList<QgsPointXY> oldVerticesXYValues() const;
143
145 QList<int> nativeFacesIndexesGeometryChanged() const;
146
148 bool isEmpty() const;
149
150 protected:
151 int mAddedFacesFirstIndex = 0;
152 QList<int> mFaceIndexesToRemove; // the removed faces indexes in the mesh
153 QVector<QgsMeshFace> mFacesToAdd;
154 QVector<FaceNeighbors> mFacesNeighborhoodToAdd;
155 QVector<QgsMeshFace> mFacesToRemove;
156 QVector<FaceNeighbors> mFacesNeighborhoodToRemove;
157 QList<std::array<int, 4>> mNeighborhoodChanges; // {index of concerned face, neighbor position, previous value, changed value}
158
159 QVector<QgsMeshVertex> mVerticesToAdd;
160 QVector<int> mVertexToFaceToAdd;
162 QList<QgsMeshVertex> mRemovedVertices;
164 QList<std::array<int, 3>> mVerticesToFaceChanges; // {index of concerned vertex, previous value, changed value}
165
167 QList<double> mNewZValues;
168 QList<double> mOldZValues;
169 QList<QgsPointXY> mNewXYValues;
170 QList<QgsPointXY> mOldXYValues;
172
174 void clearChanges();
175
176 private:
177 int addedFaceIndexInMesh( int internalIndex ) const;
178 int removedFaceIndexInMesh( int internalIndex ) const;
179
180 friend class QgsTopologicalMesh;
181 };
182
187 static QgsTopologicalMesh createTopologicalMesh( QgsMesh *mesh, int maxVerticesPerFace, QgsMeshEditingError &error );
188
194 SIP_SKIP static TopologicalFaces createNewTopologicalFaces( const QVector<QgsMeshFace> &faces, bool uniqueSharedVertexAllowed, QgsMeshEditingError &error );
195
196 //----------- access element methods
197
199 QVector<int> neighborsOfFace( int faceIndex ) const;
200
202 QList<int> facesAroundVertex( int vertexIndex ) const;
203
205 QgsMesh *mesh() const;
206
208 int firstFaceLinked( int vertexIndex ) const;
209
211 bool isVertexOnBoundary( int vertexIndex ) const;
212
214 bool isVertexFree( int vertexIndex ) const;
215
217 QList<int> freeVerticesIndexes() const;
218
224 SIP_SKIP QgsMeshVertexCirculator vertexCirculator( int vertexIndex ) const;
225
226 //----------- editing methods
227
229 QgsMeshEditingError facesCanBeAdded( const TopologicalFaces &topologicalFaces ) const;
230
235 Changes addFaces( const TopologicalFaces &topologicFaces );
236
241 QgsMeshEditingError facesCanBeRemoved( const QList<int> &facesIndexes );
242
247 Changes removeFaces( const QList<int> &facesIndexes );
248
252 bool edgeCanBeFlipped( int vertexIndex1, int vertexIndex2 ) const;
253
258 Changes flipEdge( int vertexIndex1, int vertexIndex2 );
259
266 bool delaunayConditionForEdge( int vertexIndex1, int vertexIndex2 );
267
271 bool canBeMerged( int vertexIndex1, int vertexIndex2 ) const;
272
277 Changes merge( int vertexIndex1, int vertexIndex2 );
278
282 bool canBeSplit( int faceIndex ) const;
283
288 Changes splitFace( int faceIndex );
289
294 Changes addVertexInFace( int faceIndex, const QgsMeshVertex &vertex );
295
300 Changes insertVertexInFacesEdge( int faceIndex, int position, const QgsMeshVertex &vertex );
301
306 Changes addFreeVertex( const QgsMeshVertex &vertex );
307
313 Changes removeVertexFillHole( int vertexIndex );
314
320 Changes removeVertices( const QList<int> &vertices );
321
325 Changes changeZValue( const QList<int> &verticesIndexes, const QList<double> &newValues );
326
330 Changes changeXYValue( const QList<int> &verticesIndexes, const QList<QgsPointXY> &newValues );
331
332
334 void applyChanges( const Changes &changes );
335
337 void reverseChanges( const Changes &changes );
338
340 static QgsMeshEditingError counterClockwiseFaces( QgsMeshFace &face, QgsMesh *mesh );
341
349 SIP_SKIP static QgsMeshEditingError checkTopologyOfVerticesAsFace( const QVector<QgsMeshVertex> &vertices, bool &clockwise );
350
355 void reindex();
356
360 bool renumber();
361
363 QgsMeshEditingError checkConsistency() const;
364
366 static QgsMeshEditingError checkTopology( const QgsMesh &mesh, int maxVerticesPerFace );
367
369 static inline int vertexPositionInFace( int vertexIndex, const QgsMeshFace &face )
370 {
371 return face.indexOf( vertexIndex );
372 }
373
375 static int vertexPositionInFace( const QgsMesh &mesh, int vertexIndex, int faceIndex );
376
377 private:
378
380 static TopologicalFaces createTopologicalFaces(
381 const QVector<QgsMeshFace> &faces,
382 QVector<int> *globalVertexToFace,
383 QgsMeshEditingError &error,
384 bool allowUniqueSharedVertex );
385
387 QSet<int> concernedFacesBy( const QList<int> &faceIndexes ) const;
388
390 void referenceAsFreeVertex( int vertexIndex );
392 void dereferenceAsFreeVertex( int vertexIndex );
393
398 bool eitherSideFacesAndVertices( int vertexIndex1,
399 int vertexIndex2,
400 int &face1,
401 int &face2,
402 int &neighborVertex1InFace1,
403 int &neighborVertex1InFace2,
404 int &neighborVertex2inFace1,
405 int &neighborVertex2inFace2 ) const;
406
407 bool renumberVertices( QVector<int> &oldToNewIndex ) const;
408 bool renumberFaces( QVector<int> &oldToNewIndex ) const;
409
410 //Attributes
411 QgsMesh *mMesh = nullptr;
412 QVector<int> mVertexToFace;
413 QVector<FaceNeighbors> mFacesNeighborhood;
414
415 QSet<int> mFreeVertices;
416
417 int mMaximumVerticesPerFace = 0;
418
420
421};
422
423#ifndef SIP_RUN
424
434class CORE_EXPORT QgsMeshVertexCirculator
435{
436 public:
437
439 QgsMeshVertexCirculator( const QgsTopologicalMesh &topologicalMesh, int vertexIndex );
440
446 QgsMeshVertexCirculator( const QgsTopologicalMesh::TopologicalFaces &topologicalFaces, int faceIndex, int vertexIndex );
447
453 QgsMeshVertexCirculator( const QgsTopologicalMesh::TopologicalFaces &topologicalFaces, int vertexIndex );
454
456 int turnCounterClockwise() const;
457
459 int turnClockwise() const;
460
462 int currentFaceIndex() const;
463
465 QgsMeshFace currentFace() const;
466
468 bool goBoundaryClockwise() const;
469
471 bool goBoundaryCounterClockwise() const;
472
474 int oppositeVertexClockwise() const;
475
477 int oppositeVertexCounterClockwise() const;
478
480 bool isValid() const;
481
483 QList<int> facesAround() const;
484
486 int degree() const;
487
488 private:
489 const QVector<QgsMeshFace> mFaces;
490 const QVector<QgsTopologicalMesh::FaceNeighbors> mFacesNeighborhood;
491 const int mVertexIndex = -1;
492 mutable int mCurrentFace = -1;
493 mutable int mLastValidFace = -1;
494 bool mIsValid = false;
495 mutable int mDegree = -1;
496
497 int positionInCurrentFace() const;
498};
499#endif
500
501#endif // QGSTOPOLOGICALMESH_H
Represents an error which occurred during mesh editing.
Convenience class that turns around a vertex and provides information about faces and vertices.
Point geometry type, with support for z-dimension and m-values.
Definition qgspoint.h:49
Contains topological differences between two states of a topological mesh, only accessible from the Q...
QVector< FaceNeighbors > mFacesNeighborhoodToRemove
QList< QgsMeshVertex > mRemovedVertices
QList< std::array< int, 4 > > mNeighborhoodChanges
QList< int > mNativeFacesIndexesGeometryChanged
QVector< QgsMeshFace > mFacesToAdd
QVector< FaceNeighbors > mFacesNeighborhoodToAdd
QList< std::array< int, 3 > > mVerticesToFaceChanges
QVector< QgsMeshVertex > mVerticesToAdd
QVector< QgsMeshFace > mFacesToRemove
Contains independent faces and topological information about these faces.
QVector< QgsMeshFace > meshFaces() const
Returns faces.
Wraps a QgsMesh to ensure the consistency of the mesh during editing and helps to access elements fro...
static int vertexPositionInFace(int vertexIndex, const QgsMeshFace &face)
Returns vertex position in face.
QVector< int > FaceNeighbors
#define SIP_SKIP
Definition qgis_sip.h:126
QVector< int > QgsMeshFace
List of vertex indexes.
Mesh - vertices, edges and faces.