QGIS API Documentation 3.41.0-Master (af5edcb665c)
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
238 bool canBeMerged( int vertexIndex1, int vertexIndex2 ) const;
239
244 Changes merge( int vertexIndex1, int vertexIndex2 );
245
249 bool canBeSplit( int faceIndex ) const;
250
255 Changes splitFace( int faceIndex );
256
261 Changes addVertexInFace( int faceIndex, const QgsMeshVertex &vertex );
262
267 Changes insertVertexInFacesEdge( int faceIndex, int position, const QgsMeshVertex &vertex );
268
273 Changes addFreeVertex( const QgsMeshVertex &vertex );
274
280 Changes removeVertexFillHole( int vertexIndex );
281
287 Changes removeVertices( const QList<int> &vertices );
288
292 Changes changeZValue( const QList<int> &verticesIndexes, const QList<double> &newValues );
293
297 Changes changeXYValue( const QList<int> &verticesIndexes, const QList<QgsPointXY> &newValues );
298
299
301 void applyChanges( const Changes &changes );
302
304 void reverseChanges( const Changes &changes );
305
307 static QgsMeshEditingError counterClockwiseFaces( QgsMeshFace &face, QgsMesh *mesh );
308
315 static QgsMeshEditingError checkTopologyOfVerticesAsFace( const QVector<QgsMeshVertex> &vertices, bool &clockwise );
316
321 void reindex();
322
326 bool renumber();
327
329 QgsMeshEditingError checkConsistency() const;
330
332 static QgsMeshEditingError checkTopology( const QgsMesh &mesh, int maxVerticesPerFace );
333
335 static inline int vertexPositionInFace( int vertexIndex, const QgsMeshFace &face )
336 {
337 return face.indexOf( vertexIndex );
338 }
339
341 static int vertexPositionInFace( const QgsMesh &mesh, int vertexIndex, int faceIndex );
342
343 private:
344
346 static TopologicalFaces createTopologicalFaces(
347 const QVector<QgsMeshFace> &faces,
348 QVector<int> *globalVertexToFace,
349 QgsMeshEditingError &error,
350 bool allowUniqueSharedVertex );
351
353 QSet<int> concernedFacesBy( const QList<int> &faceIndexes ) const;
354
356 void referenceAsFreeVertex( int vertexIndex );
358 void dereferenceAsFreeVertex( int vertexIndex );
359
364 bool eitherSideFacesAndVertices( int vertexIndex1,
365 int vertexIndex2,
366 int &face1,
367 int &face2,
368 int &neighborVertex1InFace1,
369 int &neighborVertex1InFace2,
370 int &neighborVertex2inFace1,
371 int &neighborVertex2inFace2 ) const;
372
373 bool renumberVertices( QVector<int> &oldToNewIndex ) const;
374 bool renumberFaces( QVector<int> &oldToNewIndex ) const;
375
376 //Attributes
377 QgsMesh *mMesh = nullptr;
378 QVector<int> mVertexToFace;
379 QVector<FaceNeighbors> mFacesNeighborhood;
380
381 QSet<int> mFreeVertices;
382
383 int mMaximumVerticesPerFace = 0;
384
386
387};
388
396class CORE_EXPORT QgsMeshVertexCirculator
397{
398 public:
399
401 QgsMeshVertexCirculator( const QgsTopologicalMesh &topologicalMesh, int vertexIndex );
402
408 QgsMeshVertexCirculator( const QgsTopologicalMesh::TopologicalFaces &topologicalFaces, int faceIndex, int vertexIndex );
409
415 QgsMeshVertexCirculator( const QgsTopologicalMesh::TopologicalFaces &topologicalFaces, int vertexIndex );
416
418 int turnCounterClockwise() const;
419
421 int turnClockwise() const;
422
424 int currentFaceIndex() const;
425
427 QgsMeshFace currentFace() const;
428
430 bool goBoundaryClockwise() const;
431
433 bool goBoundaryCounterClockwise() const;
434
436 int oppositeVertexClockwise() const;
437
439 int oppositeVertexCounterClockwise() const;
440
442 bool isValid() const;
443
445 QList<int> facesAround() const;
446
448 int degree() const;
449
450 private:
451 const QVector<QgsMeshFace> mFaces;
452 const QVector<QgsTopologicalMesh::FaceNeighbors> mFacesNeighborhood;
453 const int mVertexIndex = -1;
454 mutable int mCurrentFace = -1;
455 mutable int mLastValidFace = -1;
456 bool mIsValid = false;
457 mutable int mDegree = -1;
458
459 int positionInCurrentFace() const;
460};
461
462#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.