QGIS API Documentation 3.41.0-Master (02257426e5a)
Loading...
Searching...
No Matches
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
30
33
47class CORE_EXPORT QgsTopologicalMesh
48{
49 public:
50
51 using FaceNeighbors = QVector<int>;
52
62 class CORE_EXPORT TopologicalFaces
63 {
64 public:
65
67 QVector<QgsMeshFace> meshFaces() const {return mFaces;}
68
70 void clear();
71
73 QVector<FaceNeighbors> facesNeighborhood() const;
74
76 int vertexToFace( int vertexIndex ) const;
77
78 private:
79 QVector<QgsMeshFace> mFaces; // the faces containing the vertices indexes in the mesh
80 QVector<FaceNeighbors> mFacesNeighborhood; // neighborhood of the faces, face indexes are local
81 QMultiHash<int, int> mVerticesToFace; // map of vertices to incident face, face indexes are local
82 QList<int> mBoundaries; // list of boundary vertices indexes in the mesh
83
84 friend class QgsTopologicalMesh;
86 };
87
88
96 class CORE_EXPORT Changes
97 {
98 public:
99
101 QVector<QgsMeshFace> addedFaces() const;
102
104 QVector<QgsMeshFace> removedFaces() const;
105
107 QList<int> removedFaceIndexes() const;
108
110 QVector<QgsMeshVertex> addedVertices() const;
111
113 QList<int> verticesToRemoveIndexes() const;
114
116 QList<int> changedCoordinatesVerticesIndexes() const;
117
119 QList<double> newVerticesZValues() const;
120
122 QList<QgsPointXY> newVerticesXYValues() const;
123
125 QList<QgsPointXY> oldVerticesXYValues() const;
126
128 QList<int> nativeFacesIndexesGeometryChanged() const;
129
131 bool isEmpty() const;
132
133 protected:
134 int mAddedFacesFirstIndex = 0;
135 QList<int> mFaceIndexesToRemove; // the removed faces indexes in the mesh
136 QVector<QgsMeshFace> mFacesToAdd;
137 QVector<FaceNeighbors> mFacesNeighborhoodToAdd;
138 QVector<QgsMeshFace> mFacesToRemove;
139 QVector<FaceNeighbors> mFacesNeighborhoodToRemove;
140 QList<std::array<int, 4>> mNeighborhoodChanges; // {index of concerned face, neighbor position, previous value, changed value}
141
142 QVector<QgsMeshVertex> mVerticesToAdd;
143 QVector<int> mVertexToFaceToAdd;
145 QList<QgsMeshVertex> mRemovedVertices;
147 QList<std::array<int, 3>> mVerticesToFaceChanges; // {index of concerned vertex, previous value, changed value}
148
150 QList<double> mNewZValues;
151 QList<double> mOldZValues;
152 QList<QgsPointXY> mNewXYValues;
153 QList<QgsPointXY> mOldXYValues;
155
157 void clearChanges();
158
159 private:
160 int addedFaceIndexInMesh( int internalIndex ) const;
161 int removedFaceIndexInMesh( int internalIndex ) const;
162
163 friend class QgsTopologicalMesh;
164 };
165
170 static QgsTopologicalMesh createTopologicalMesh( QgsMesh *mesh, int maxVerticesPerFace, QgsMeshEditingError &error );
171
173 static TopologicalFaces createNewTopologicalFaces( const QVector<QgsMeshFace> &faces, bool uniqueSharedVertexAllowed, QgsMeshEditingError &error );
174
175 //----------- access element methods
176
178 QVector<int> neighborsOfFace( int faceIndex ) const;
179
181 QList<int> facesAroundVertex( int vertexIndex ) const;
182
184 QgsMesh *mesh() const;
185
187 int firstFaceLinked( int vertexIndex ) const;
188
190 bool isVertexOnBoundary( int vertexIndex ) const;
191
193 bool isVertexFree( int vertexIndex ) const;
194
196 QList<int> freeVerticesIndexes() const;
197
199 QgsMeshVertexCirculator vertexCirculator( int vertexIndex ) const;
200
201 //----------- editing methods
202
204 QgsMeshEditingError facesCanBeAdded( const TopologicalFaces &topologicalFaces ) const;
205
210 Changes addFaces( const TopologicalFaces &topologicFaces );
211
216 QgsMeshEditingError facesCanBeRemoved( const QList<int> &facesIndexes );
217
222 Changes removeFaces( const QList<int> &facesIndexes );
223
227 bool edgeCanBeFlipped( int vertexIndex1, int vertexIndex2 ) const;
228
233 Changes flipEdge( int vertexIndex1, int vertexIndex2 );
234
241 bool delaunayConditionForEdge( int vertexIndex1, int vertexIndex2 );
242
246 bool canBeMerged( int vertexIndex1, int vertexIndex2 ) const;
247
252 Changes merge( int vertexIndex1, int vertexIndex2 );
253
257 bool canBeSplit( int faceIndex ) const;
258
263 Changes splitFace( int faceIndex );
264
269 Changes addVertexInFace( int faceIndex, const QgsMeshVertex &vertex );
270
275 Changes insertVertexInFacesEdge( int faceIndex, int position, const QgsMeshVertex &vertex );
276
281 Changes addFreeVertex( const QgsMeshVertex &vertex );
282
288 Changes removeVertexFillHole( int vertexIndex );
289
295 Changes removeVertices( const QList<int> &vertices );
296
300 Changes changeZValue( const QList<int> &verticesIndexes, const QList<double> &newValues );
301
305 Changes changeXYValue( const QList<int> &verticesIndexes, const QList<QgsPointXY> &newValues );
306
307
309 void applyChanges( const Changes &changes );
310
312 void reverseChanges( const Changes &changes );
313
315 static QgsMeshEditingError counterClockwiseFaces( QgsMeshFace &face, QgsMesh *mesh );
316
323 static QgsMeshEditingError checkTopologyOfVerticesAsFace( const QVector<QgsMeshVertex> &vertices, bool &clockwise );
324
329 void reindex();
330
334 bool renumber();
335
337 QgsMeshEditingError checkConsistency() const;
338
340 static QgsMeshEditingError checkTopology( const QgsMesh &mesh, int maxVerticesPerFace );
341
343 static inline int vertexPositionInFace( int vertexIndex, const QgsMeshFace &face )
344 {
345 return face.indexOf( vertexIndex );
346 }
347
349 static int vertexPositionInFace( const QgsMesh &mesh, int vertexIndex, int faceIndex );
350
351 private:
352
354 static TopologicalFaces createTopologicalFaces(
355 const QVector<QgsMeshFace> &faces,
356 QVector<int> *globalVertexToFace,
357 QgsMeshEditingError &error,
358 bool allowUniqueSharedVertex );
359
361 QSet<int> concernedFacesBy( const QList<int> &faceIndexes ) const;
362
364 void referenceAsFreeVertex( int vertexIndex );
366 void dereferenceAsFreeVertex( int vertexIndex );
367
372 bool eitherSideFacesAndVertices( int vertexIndex1,
373 int vertexIndex2,
374 int &face1,
375 int &face2,
376 int &neighborVertex1InFace1,
377 int &neighborVertex1InFace2,
378 int &neighborVertex2inFace1,
379 int &neighborVertex2inFace2 ) const;
380
381 bool renumberVertices( QVector<int> &oldToNewIndex ) const;
382 bool renumberFaces( QVector<int> &oldToNewIndex ) const;
383
384 //Attributes
385 QgsMesh *mMesh = nullptr;
386 QVector<int> mVertexToFace;
387 QVector<FaceNeighbors> mFacesNeighborhood;
388
389 QSet<int> mFreeVertices;
390
391 int mMaximumVerticesPerFace = 0;
392
394
395};
396
404class CORE_EXPORT QgsMeshVertexCirculator
405{
406 public:
407
409 QgsMeshVertexCirculator( const QgsTopologicalMesh &topologicalMesh, int vertexIndex );
410
416 QgsMeshVertexCirculator( const QgsTopologicalMesh::TopologicalFaces &topologicalFaces, int faceIndex, int vertexIndex );
417
423 QgsMeshVertexCirculator( const QgsTopologicalMesh::TopologicalFaces &topologicalFaces, int vertexIndex );
424
426 int turnCounterClockwise() const;
427
429 int turnClockwise() const;
430
432 int currentFaceIndex() const;
433
435 QgsMeshFace currentFace() const;
436
438 bool goBoundaryClockwise() const;
439
441 bool goBoundaryCounterClockwise() const;
442
444 int oppositeVertexClockwise() const;
445
447 int oppositeVertexCounterClockwise() const;
448
450 bool isValid() const;
451
453 QList<int> facesAround() const;
454
456 int degree() const;
457
458 private:
459 const QVector<QgsMeshFace> mFaces;
460 const QVector<QgsTopologicalMesh::FaceNeighbors> mFacesNeighborhood;
461 const int mVertexIndex = -1;
462 mutable int mCurrentFace = -1;
463 mutable int mLastValidFace = -1;
464 bool mIsValid = false;
465 mutable int mDegree = -1;
466
467 int positionInCurrentFace() const;
468};
469
470#endif // QGSTOPOLOGICALMESH_H
Class that represents an error during mesh editing.
Convenient class that turn around a vertex and provide information about faces and vertices.
Point geometry type, with support for z-dimension and m-values.
Definition qgspoint.h:49
Class that contains topological differences between two states of a topological mesh,...
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
Class that contains independent faces an topological information about this faces.
QVector< QgsMeshFace > meshFaces() const
Returns faces.
Class that wraps a QgsMesh to ensure the consistency of the mesh during editing and help to access to...
static int vertexPositionInFace(int vertexIndex, const QgsMeshFace &face)
Returns vertex position in face.
QVector< int > FaceNeighbors
#define SIP_NO_FILE
#define SIP_SKIP
Definition qgis_sip.h:126
QVector< int > QgsMeshFace
List of vertex indexes.
Mesh - vertices, edges and faces.