33 : QObject( meshLayer )
34 , mMesh( meshLayer ? meshLayer->nativeMesh() : nullptr )
35 , mTriangularMesh( meshLayer ? meshLayer->triangularMeshByLodIndex( 0 ) : nullptr )
36 , mUndoStack( meshLayer ? meshLayer->undoStack() : nullptr )
48 , mTriangularMesh( triangularMesh )
50 mUndoStack =
new QUndoStack(
this );
56 std::unique_ptr<QgsMeshDatasetGroup> zValueDatasetGroup = std::make_unique<QgsMeshVerticesElevationDatasetGroup>( tr(
"vertices Z value" ), mMesh );
62 mZValueDatasetGroup = zValueDatasetGroup.get();
64 return zValueDatasetGroup.release();
79 for (
int vi : freeVertices )
107 mTriangularMesh->
update( mMesh );
134 auto faceIt = mMesh->
faces.begin();
135 while ( faceIt != mMesh->
faces.end() )
138 faceIt = mMesh->
faces.erase( faceIt );
164 Q_ASSERT( vertexIndexes.count() == vertices.count() );
166 QVector<QgsPoint> ring;
167 for (
int i = 0; i < vertices.size(); ++i )
169 const QgsPoint &vertex = vertices[i];
170 ring.append( vertex );
172 std::unique_ptr< QgsPolygon > polygon = std::make_unique< QgsPolygon >();
174 const QgsGeometry newFaceGeom( polygon.release() );
176 geomEngine->prepareGeometry();
178 const QgsRectangle boundingBox = newFaceGeom.boundingBox();
179 int newFaceSize = vertexIndexes.count();
181 if ( !concernedFaceIndex.isEmpty() )
185 for (
const int faceIndex : concernedFaceIndex )
188 int existingFaceSize = existingFace.count();
189 bool shareVertex =
false;
190 for (
int i = 0; i < existingFaceSize; ++i )
192 if ( vertexIndexes.contains( existingFace.at( i ) ) )
201 for (
int i = 0; i < existingFaceSize; ++i )
203 int index1 = existingFace.at( i );
204 int index2 = existingFace.at( ( i + 1 ) % existingFaceSize );
209 if ( ! vertexIndexes.contains( index1 ) && !vertexIndexes.contains( index2 ) )
212 if ( geomEngine->intersects( edgeGeom.
constGet() ) )
217 for (
int vi = 0; vi < vertexIndexes.count(); ++vi )
219 int vertInNewFace1 = vertexIndexes.at( vi );
220 int vertInNewFace2 = vertexIndexes.at( ( vi + 1 ) % newFaceSize );
221 bool hasToBeTest =
false;
223 if ( vertInNewFace1 != -1 && vertInNewFace2 != -1 )
225 hasToBeTest = vertInNewFace1 != index1 &&
226 vertInNewFace2 != index2 &&
227 vertInNewFace1 != index2 &&
228 vertInNewFace2 != index1;
232 if ( vertInNewFace1 == -1 )
233 hasToBeTest &= vertInNewFace2 != index1 && vertInNewFace2 != index2;
236 if ( vertInNewFace2 == -1 )
237 hasToBeTest &= vertInNewFace1 != index1 && vertInNewFace1 != index2;
243 const QgsMeshVertex &nv2 = vertices.at( ( vi + 1 ) % newFaceSize );
255 const QgsGeometry existingFaceGeom = QgsMeshUtils::toGeometry( existingFace, mTriangularMesh->
vertices() );
256 if ( geomEngine->intersects( existingFaceGeom.
constGet() ) )
264 for (
const int freeVertexIndex : freeVertices )
266 if ( vertexIndexes.contains( freeVertexIndex ) )
270 if ( geomEngine->contains( &vertex ) )
279 const QList<int> newFaceVerticesIndexes( face.toList() );
280 QList<QgsMeshVertex> allVertices;
281 allVertices.reserve( face.count() );
283 allVertices.append( mTriangularMesh->
vertices().at( i ) );
295 QVector<QgsMeshFace> facesToAdd = prepareFaces( {face}, error );
318 const QList<int> face = prepareFaceWithNewVertices( verticesIndex, newVertices, error );
320 if ( face.isEmpty() )
329 int size = face.size();
330 QList<QgsMeshVertex> allVertices;
331 allVertices.reserve( verticesIndex.size() );
333 for (
int i = 0; i < size; ++i )
335 int index = face.at( i );
338 if ( newVertPos >= newVertices.count() )
340 allVertices.append( newVertices.at( newVertPos++ ) );
344 allVertices.append( mTriangularMesh->
vertices().at( index ) );
349 int prevIndex = face.at( ( i - 1 + size ) % size );
350 int nextIndex = face.at( ( i + 1 ) % size );
357 if ( prevOppVertex == nextIndex )
364 if ( nextOppVertex == prevIndex )
367 if ( nextIndex != nextOppVertex && prevIndex != prevOppVertex )
374void QgsMeshEditor::applyEdit( QgsMeshEditor::Edit &edit )
376 mTopologicalMesh.
applyChanges( edit.topologicalChanges );
377 mTriangularMesh->
applyChanges( edit.triangularMeshChanges );
379 if ( mZValueDatasetGroup &&
380 ( !edit.topologicalChanges.newVerticesZValues().isEmpty() ||
381 !edit.topologicalChanges.verticesToRemoveIndexes().isEmpty() ||
382 !edit.topologicalChanges.addedVertices().isEmpty() ) )
385 updateElementsCount( edit.topologicalChanges );
388void QgsMeshEditor::reverseEdit( QgsMeshEditor::Edit &edit )
391 mTriangularMesh->
reverseChanges( edit.triangularMeshChanges, *mMesh );
393 if ( mZValueDatasetGroup &&
394 ( !edit.topologicalChanges.newVerticesZValues().isEmpty() ||
395 !edit.topologicalChanges.verticesToRemoveIndexes().isEmpty() ||
396 !edit.topologicalChanges.addedVertices().isEmpty() ) )
399 updateElementsCount( edit.topologicalChanges,
false );
402void QgsMeshEditor::applyAddVertex( QgsMeshEditor::Edit &edit,
const QgsMeshVertex &vertex,
double tolerance )
407 int faceEdgeIntersect = -1;
408 int edgePosition = -1;
412 if (
edgeIsClose( vertexInTriangularCoordinate, tolerance, faceEdgeIntersect, edgePosition ) )
420 if ( includingFaceIndex != -1 )
421 topologicChanges = mTopologicalMesh.
addVertexInFace( includingFaceIndex, vertex );
426 applyEditOnTriangularMesh( edit, topologicChanges );
428 if ( mZValueDatasetGroup )
431 updateElementsCount( edit.topologicalChanges );
434bool QgsMeshEditor::applyRemoveVertexFillHole( QgsMeshEditor::Edit &edit,
int vertexIndex )
440 applyEditOnTriangularMesh( edit, changes );
442 if ( mZValueDatasetGroup )
445 updateElementsCount( edit.topologicalChanges );
452void QgsMeshEditor::applyRemoveVerticesWithoutFillHole( QgsMeshEditor::Edit &edit,
const QList<int> &verticesIndexes )
454 applyEditOnTriangularMesh( edit, mTopologicalMesh.
removeVertices( verticesIndexes ) );
456 if ( mZValueDatasetGroup )
459 updateElementsCount( edit.topologicalChanges );
464 applyEditOnTriangularMesh( edit, mTopologicalMesh.
addFaces( faces ) );
466 updateElementsCount( edit.topologicalChanges );
469void QgsMeshEditor::applyRemoveFaces( QgsMeshEditor::Edit &edit,
const QList<int> &faceToRemoveIndex )
471 applyEditOnTriangularMesh( edit, mTopologicalMesh.
removeFaces( faceToRemoveIndex ) );
473 updateElementsCount( edit.topologicalChanges );
476void QgsMeshEditor::applyChangeZValue( QgsMeshEditor::Edit &edit,
const QList<int> &verticesIndexes,
const QList<double> &newValues )
478 applyEditOnTriangularMesh( edit, mTopologicalMesh.
changeZValue( verticesIndexes, newValues ) );
480 if ( mZValueDatasetGroup )
484void QgsMeshEditor::applyChangeXYValue( QgsMeshEditor::Edit &edit,
const QList<int> &verticesIndexes,
const QList<QgsPointXY> &newValues )
486 applyEditOnTriangularMesh( edit, mTopologicalMesh.
changeXYValue( verticesIndexes, newValues ) );
489void QgsMeshEditor::applyFlipEdge( QgsMeshEditor::Edit &edit,
int vertexIndex1,
int vertexIndex2 )
491 applyEditOnTriangularMesh( edit, mTopologicalMesh.
flipEdge( vertexIndex1, vertexIndex2 ) );
493 updateElementsCount( edit.topologicalChanges );
496void QgsMeshEditor::applyMerge( QgsMeshEditor::Edit &edit,
int vertexIndex1,
int vertexIndex2 )
498 applyEditOnTriangularMesh( edit, mTopologicalMesh.
merge( vertexIndex1, vertexIndex2 ) );
500 updateElementsCount( edit.topologicalChanges );
503void QgsMeshEditor::applySplit( QgsMeshEditor::Edit &edit,
int faceIndex )
505 applyEditOnTriangularMesh( edit, mTopologicalMesh.
splitFace( faceIndex ) );
507 updateElementsCount( edit.topologicalChanges );
512 applyEditOnTriangularMesh( edit, editing->
apply(
this ) );
514 updateElementsCount( edit.topologicalChanges );
516 if ( mZValueDatasetGroup )
525 edit.topologicalChanges = topologicChanges;
526 edit.triangularMeshChanges = triangularChanges;
572 point.
y() - tolerance,
573 point.
x() + tolerance,
574 point.
y() + tolerance );
577 double minDist = std::numeric_limits<double>::max();
579 double epsilon = std::numeric_limits<double>::epsilon() * tolerance;
580 for (
const int nativeFaceIndex : nativeFaces )
583 const int faceSize = face.size();
584 for (
int i = 0; i < faceSize; ++i )
600 if ( dist < tolerance && dist < minDist )
602 faceIndex = nativeFaceIndex;
609 if ( edgePosition != -1 )
618 return mValidFacesCount;
623 return mValidVerticesCount;
628 return mMaximumVerticesPerFace;
657 return mTopologicalMesh.
canBeMerged( vertexIndex1, vertexIndex2 );
670 return mTopologicalMesh.
canBeSplit( faceIndex );
675 QList<int> faceIndexesSplittable;
677 for (
const int faceIndex : faceIndexes )
679 faceIndexesSplittable.append( faceIndex );
681 if ( faceIndexesSplittable.isEmpty() )
686 return faceIndexesSplittable.count();
689QVector<QgsMeshFace> QgsMeshEditor::prepareFaces(
const QVector<QgsMeshFace> &faces,
QgsMeshEditingError &error )
const
691 QVector<QgsMeshFace> treatedFaces = faces;
695 for (
int i = 0; i < treatedFaces.count(); ++i )
698 if ( mMaximumVerticesPerFace != 0 && face.count() > mMaximumVerticesPerFace )
712QList<int> QgsMeshEditor::prepareFaceWithNewVertices(
const QList<int> &face,
const QList<QgsMeshVertex> &newVertices,
QgsMeshEditingError &error )
const
714 if ( mMaximumVerticesPerFace != 0 && face.count() > mMaximumVerticesPerFace )
720 int faceSize = face.count();
721 QVector<QgsMeshVertex> vertices( faceSize );
722 int newVertexPos = 0;
723 for (
int i = 0; i < faceSize; ++i )
725 if ( face.at( i ) == -1 )
727 if ( newVertexPos >= newVertices.count() )
729 vertices[i] = newVertices.at( newVertexPos++ );
731 else if ( face.at( i ) >= 0 )
733 if ( face.at( i ) >= mTriangularMesh->
vertices().count() )
738 vertices[i] = mTriangularMesh->
vertices().at( face.at( i ) );
750 bool clockwise =
false;
756 QList<int> newFace = face;
757 for (
int i = 0; i < faceSize / 2; ++i )
759 int temp = newFace[i];
760 newFace[i] = face.at( faceSize - i - 1 );
761 newFace[faceSize - i - 1] = temp;
773 QVector<QgsMeshFace> facesToAdd = prepareFaces( faces, error );
797 mUndoStack->beginMacro( tr(
"Add a face with new %n vertices",
nullptr, newVertices.count() ) );
801 for (
int i = 0; i < vertexIndexes.count(); ++i )
803 int index = vertexIndexes.at( i );
805 face[i] = newVertexIndex++;
811 mUndoStack->endMacro();
818 QVector<QgsMeshVertex> verticesInLayerCoordinate( vertices.count() );
819 int ignoredVertex = 0;
820 for (
int i = 0; i < vertices.count(); ++i )
822 const QgsPointXY &pointInTriangularMesh = vertices.at( i );
823 bool isTooClose =
false;
825 if ( triangleIndex != -1 )
828 for (
int j = 0; j < 3; ++j )
831 double dist = pointInTriangularMesh.
distance( facePoint );
832 if ( dist < tolerance )
845 if ( verticesInLayerCoordinate.at( i ).isEmpty() )
849 if ( ignoredVertex < vertices.count() )
854 int effectivlyAddedVertex = vertices.count() - ignoredVertex;
856 return effectivlyAddedVertex;
868 QList<int> verticesIndexes = verticesToRemoveIndexes;
870 QSet<int> concernedNativeFaces;
871 for (
const int vi : std::as_const( verticesIndexes ) )
874 concernedNativeFaces.unite( QSet< int >( faces.begin(), faces.end() ) );
888 QList<int> remainingVertices;
891 return remainingVertices;
902 for (
const int faceIndex : facesToCheck )
905 int faceSize = face.count();
906 QVector<QgsPointXY> pointsInTriangularMeshCoordinate( faceSize );
907 QVector<QgsPointXY> points( faceSize );
908 for (
int i = 0; i < faceSize; ++i )
911 int ip1 = face[( i + 1 ) % faceSize];
912 int ip2 = face[( i + 2 ) % faceSize];
918 double ux = p0.x() - p1.
x();
919 double uy = p0.y() - p1.
y();
920 double vx = p2.
x() - p1.
x();
921 double vy = p2.
y() - p1.
y();
923 double crossProduct = ux * vy - uy * vx;
924 if ( crossProduct >= 0 )
933 QList<int> otherFaceIndexes =
936 for (
const int otherFaceIndex : otherFaceIndexes )
939 int existingFaceSize = otherFace.count();
940 bool shareVertex =
false;
941 for (
int i = 0; i < existingFaceSize; ++i )
943 if ( face.contains( otherFace.at( i ) ) )
952 for (
int i = 0; i < existingFaceSize; ++i )
954 int index1 = otherFace.at( i );
955 int index2 = otherFace.at( ( i + 1 ) % existingFaceSize );
956 if ( ! face.contains( index1 ) && !face.contains( index2 ) )
958 const QgsPointXY &v1 = transformFunction( index1 );
959 const QgsPointXY &v2 = transformFunction( index2 );
968 QVector<QgsPointXY> otherPoints( existingFaceSize );
969 for (
int i = 0; i < existingFaceSize; ++i )
970 otherPoints[i] = transformFunction( otherFace.at( i ) );
972 if ( deformedFace.
intersects( existingFaceGeom ) )
978 for (
const int vertexIndex : freeVerticesIndex )
980 const QgsPointXY &mapPoint = transformFunction( vertexIndex );
981 if ( deformedFace.
contains( &mapPoint ) )
988 for (
const int vertexIndex : freeVerticesIndex )
990 const QgsMeshVertex &newFreeVertexPosition = transformFunction( vertexIndex );
994 if ( originalIncludingFace != -1 )
999 int faceSize = face.count();
1000 QVector<QgsPointXY> points( faceSize );
1001 for (
int i = 0; i < faceSize; ++i )
1002 points[i] = transformFunction( face.at( i ) );
1005 const QgsPointXY ptXY( newFreeVertexPosition );
1006 if ( deformedFace.
contains( &ptXY ) )
1033 mUndoStack->clear();
1037 : mMeshEditor( meshEditor )
1046 for (
int i =
mEdits.count() - 1; i >= 0; --i )
1055 for ( QgsMeshEditor::Edit &edit :
mEdits )
1061 , mVertices( vertices )
1062 , mTolerance( tolerance )
1064 setText( QObject::tr(
"Add %n vertices",
nullptr, mVertices.count() ) );
1069 if ( !mVertices.isEmpty() )
1071 for (
int i = 0; i < mVertices.count(); ++i )
1076 QgsMeshEditor::Edit edit;
1077 mMeshEditor->applyAddVertex( edit, vertex, mTolerance );
1084 for ( QgsMeshEditor::Edit &edit :
mEdits )
1091 const QList<int> &verticesToRemoveIndexes,
1092 QList<int> *remainingVerticesPointer )
1094 , mVerticesToRemoveIndexes( verticesToRemoveIndexes )
1095 , mRemainingVerticesPointer( remainingVerticesPointer )
1097 setText( QObject::tr(
"Remove %n vertices filling holes",
nullptr, verticesToRemoveIndexes.count() ) );
1102 int initialVertexCount = mVerticesToRemoveIndexes.count();
1103 if ( !mVerticesToRemoveIndexes.isEmpty() )
1105 QgsMeshEditor::Edit edit;
1106 QList<int> vertexToRetry;
1107 while ( !mVerticesToRemoveIndexes.isEmpty() )
1110 for (
const int &vertex : std::as_const( mVerticesToRemoveIndexes ) )
1112 if (
mMeshEditor->applyRemoveVertexFillHole( edit, vertex ) )
1115 vertexToRetry.append( vertex );
1118 if ( vertexToRetry.count() == mVerticesToRemoveIndexes.count() )
1121 mVerticesToRemoveIndexes = vertexToRetry;
1124 if ( initialVertexCount == mVerticesToRemoveIndexes.count() )
1125 setObsolete(
true );
1127 if ( mRemainingVerticesPointer !=
nullptr )
1128 *mRemainingVerticesPointer = mVerticesToRemoveIndexes;
1130 mRemainingVerticesPointer =
nullptr;
1132 mVerticesToRemoveIndexes.clear();
1136 for ( QgsMeshEditor::Edit &edit :
mEdits )
1144 const QList<int> &verticesToRemoveIndexes )
1146 , mVerticesToRemoveIndexes( verticesToRemoveIndexes )
1148 setText( QObject::tr(
"Remove %n vertices without filling holes",
nullptr, verticesToRemoveIndexes.count() ) ) ;
1153 if ( !mVerticesToRemoveIndexes.isEmpty() )
1155 QgsMeshEditor::Edit edit;
1157 mMeshEditor->applyRemoveVerticesWithoutFillHole( edit, mVerticesToRemoveIndexes );
1160 mVerticesToRemoveIndexes.clear();
1164 for ( QgsMeshEditor::Edit &edit :
mEdits )
1173 setText( QObject::tr(
"Add %n face(s)",
nullptr, faces.
meshFaces().count() ) );
1180 QgsMeshEditor::Edit edit;
1188 for ( QgsMeshEditor::Edit &edit :
mEdits )
1195 , mfacesToRemoveIndexes( facesToRemoveIndexes )
1197 setText( QObject::tr(
"Remove %n face(s)",
nullptr, facesToRemoveIndexes.count() ) );
1202 if ( !mfacesToRemoveIndexes.isEmpty() )
1204 QgsMeshEditor::Edit edit;
1205 mMeshEditor->applyRemoveFaces( edit, mfacesToRemoveIndexes );
1208 mfacesToRemoveIndexes.clear();
1212 for ( QgsMeshEditor::Edit &edit :
mEdits )
1229 return !mUndoStack->isClean();
1237 mUndoStack->clear();
1247 if ( !mTopologicalMesh.
renumber() )
1282 return mTopologicalMesh;
1287 return mTriangularMesh;
1292 , mVerticesIndexes( verticesIndexes )
1293 , mNewValues( newValues )
1295 setText( QObject::tr(
"Change %n vertices Z Value",
nullptr, verticesIndexes.count() ) );
1300 if ( !mVerticesIndexes.isEmpty() )
1302 QgsMeshEditor::Edit edit;
1303 mMeshEditor->applyChangeZValue( edit, mVerticesIndexes, mNewValues );
1305 mVerticesIndexes.clear();
1310 for ( QgsMeshEditor::Edit &edit :
mEdits )
1317 , mVerticesIndexes( verticesIndexes )
1318 , mNewValues( newValues )
1320 setText( QObject::tr(
"Move %n vertices",
nullptr, verticesIndexes.count() ) );
1325 if ( !mVerticesIndexes.isEmpty() )
1327 QgsMeshEditor::Edit edit;
1328 mMeshEditor->applyChangeXYValue( edit, mVerticesIndexes, mNewValues );
1330 mVerticesIndexes.clear();
1335 for ( QgsMeshEditor::Edit &edit :
mEdits )
1343 , mVerticesIndexes( verticesIndexes )
1344 , mNewCoordinates( newCoordinates )
1346 setText( QObject::tr(
"Transform %n vertices coordinates",
nullptr, verticesIndexes.count() ) );
1351 if ( !mVerticesIndexes.isEmpty() )
1353 QgsMeshEditor::Edit editXY;
1354 QList<QgsPointXY> newXY;
1355 newXY.reserve( mNewCoordinates.count() );
1356 QgsMeshEditor::Edit editZ;
1358 newZ.reserve( mNewCoordinates.count() );
1360 for (
const QgsPoint &pt : std::as_const( mNewCoordinates ) )
1363 newZ.append( pt.z() );
1366 mMeshEditor->applyChangeXYValue( editXY, mVerticesIndexes, newXY );
1368 mMeshEditor->applyChangeZValue( editZ, mVerticesIndexes, newZ );
1370 mVerticesIndexes.clear();
1371 mNewCoordinates.clear();
1375 for ( QgsMeshEditor::Edit &edit :
mEdits )
1384 , mVertexIndex1( vertexIndex1 )
1385 , mVertexIndex2( vertexIndex2 )
1387 setText( QObject::tr(
"Flip edge" ) );
1392 if ( mVertexIndex1 >= 0 && mVertexIndex2 >= 0 )
1394 QgsMeshEditor::Edit edit;
1395 mMeshEditor->applyFlipEdge( edit, mVertexIndex1, mVertexIndex2 );
1402 for ( QgsMeshEditor::Edit &edit :
mEdits )
1409 , mVertexIndex1( vertexIndex1 )
1410 , mVertexIndex2( vertexIndex2 )
1412 setText( QObject::tr(
"Merge faces" ) );
1417 if ( mVertexIndex1 >= 0 && mVertexIndex2 >= 0 )
1419 QgsMeshEditor::Edit edit;
1420 mMeshEditor->applyMerge( edit, mVertexIndex1, mVertexIndex2 );
1427 for ( QgsMeshEditor::Edit &edit :
mEdits )
1434 , mFaceIndexes( faceIndexes )
1436 setText( QObject::tr(
"Split %n face(s)",
nullptr, faceIndexes.count() ) );
1441 if ( !mFaceIndexes.isEmpty() )
1443 for (
int faceIndex : std::as_const( mFaceIndexes ) )
1445 QgsMeshEditor::Edit edit;
1449 mFaceIndexes.clear();
1453 for ( QgsMeshEditor::Edit &edit :
mEdits )
1460 , mAdvancedEditing( advancdEdit )
1462 setText( advancdEdit->
text() );
1467 if ( mAdvancedEditing )
1469 QgsMeshEditor::Edit edit;
1472 mMeshEditor->applyAdvancedEdit( edit, mAdvancedEditing );
1476 mAdvancedEditing =
nullptr;
1480 for ( QgsMeshEditor::Edit &edit :
mEdits )
The Qgis class provides global constants for use throughout the application.
MeshEditingErrorType
Type of error that can occur during mesh frame editing.
@ TooManyVerticesInFace
A face has more vertices than the maximum number supported per face.
@ InvalidFace
An error occurs due to an invalid face (for example, vertex indexes are unordered)
@ UniqueSharedVertex
A least two faces share only one vertices.
@ ManifoldFace
ManifoldFace.
@ InvalidVertex
An error occurs due to an invalid vertex (for example, vertex index is out of range the available ver...
@ FlatFace
A flat face is present.
static double sqrDistToLine(double ptX, double ptY, double x1, double y1, double x2, double y2, double &minDistX, double &minDistY, double epsilon)
Returns the squared distance between a point and a line.
A geometry is the spatial representation of a feature.
static QgsGeometry fromPolylineXY(const QgsPolylineXY &polyline)
Creates a new LineString geometry from a list of QgsPointXY points.
const QgsAbstractGeometry * constGet() const
Returns a non-modifiable (const) reference to the underlying abstract geometry primitive.
bool contains(const QgsPointXY *p) const
Returns true if the geometry contains the point p.
static QgsGeometry fromPolygonXY(const QgsPolygonXY &polygon)
Creates a new geometry from a QgsPolygonXY.
static QgsGeometryEngine * createGeometryEngine(const QgsAbstractGeometry *geometry, double precision=0.0)
Creates and returns a new geometry engine representing the specified geometry using precision on a gr...
bool intersects(const QgsRectangle &rectangle) const
Returns true if this geometry exactly intersects with a rectangle.
Line string geometry type, with support for z-dimension and m-values.
Abstract class that can be derived to implement advanced editing on mesh.
virtual QgsTopologicalMesh::Changes apply(QgsMeshEditor *meshEditor)=0
Apply a change to mesh Editor.
virtual bool isFinished() const
Returns whether the advanced edit is finished, if not, this edit has to be applied again with QgsMesh...
virtual QString text() const
Returns a short text string describing what this advanced edit does. Default implementation return a ...
virtual int maximumVerticesCountPerFace() const
Returns the maximum number of vertices per face supported by the current mesh, if returns 0,...
Abstract class that represents a dataset group.
void setStatisticObsolete() const
Sets statistic obsolete, that means statistic will be recalculated when requested.
Class that represents an error during mesh editing.
Qgis::MeshEditingErrorType errorType
QgsMeshEditingError()
Constructor of the default error, that is NoError.
Class that makes edit operation on a mesh.
friend class QgsMeshLayerUndoCommandSplitFaces
QgsMeshEditingError initialize()
Initializes the mesh editor and returns first error if the internal native mesh has topological error...
friend class QgsMeshLayerUndoCommandMerge
void changeXYValues(const QList< int > &verticesIndexes, const QList< QgsPointXY > &newValues)
Changes the (X,Y) coordinates values of the vertices with indexes in verticesIndexes with the values ...
int validFacesCount() const
Returns the count of valid faces, that is non void faces in the mesh.
friend class QgsMeshLayerUndoCommandRemoveVerticesWithoutFillHoles
QgsMeshEditingError removeFaces(const QList< int > &facesToRemove)
Removes faces faces to the mesh, returns topological errors if this operation fails (operation is not...
QgsMeshEditingError addFaces(const QVector< QgsMeshFace > &faces)
Adds faces faces to the mesh, returns topological errors if this operation fails (operation is not re...
bool checkConsistency(QgsMeshEditingError &error) const
Return true if the edited mesh is consistent.
QList< int > removeVerticesFillHoles(const QList< int > &verticesToRemoveIndexes)
Removes vertices with indexes in the list verticesToRemoveIndexes in the mesh the surrounding faces A...
void flipEdge(int vertexIndex1, int vertexIndex2)
Flips edge (vertexIndex1, vertexIndex2)
QgsRectangle extent() const
Returns the extent of the edited mesh.
friend class QgsMeshLayerUndoCommandAddVertices
bool faceCanBeSplit(int faceIndex) const
Returns true if face with index faceIndex can be split.
QgsMeshEditingError initializeWithErrorsFix()
Initializes the mesh editor.
int maximumVerticesPerFace() const
Returns the maximum count of vertices per face that the mesh can support.
QgsMeshEditingError addFace(const QVector< int > &vertexIndexes)
Adds a face face to the mesh with vertex indexes vertexIndexes, returns topological errors if this op...
QgsMeshEditor(QgsMeshLayer *meshLayer)
Constructor with a specified layer meshLayer.
void merge(int vertexIndex1, int vertexIndex2)
Merges faces separated by vertices with indexes vertexIndex1 and vertexIndex2.
bool edgeIsClose(QgsPointXY point, double tolerance, int &faceIndex, int &edgePosition)
Returns true if an edge of face is closest than the tolerance from the point in triangular mesh coord...
QgsMeshEditingError removeVerticesWithoutFillHoles(const QList< int > &verticesToRemoveIndexes)
Removes vertices with indexes in the list verticesToRemoveIndexes in the mesh removing the surroundin...
bool isFaceGeometricallyCompatible(const QgsMeshFace &face) const
Returns true if the face does not intersect or contains any other elements (faces or vertices) The to...
QList< int > freeVerticesIndexes() const
Returns all the free vertices indexes.
friend class QgsMeshLayerUndoCommandChangeXYValue
bool isVertexOnBoundary(int vertexIndex) const
Returns whether the vertex with index vertexIndex is on a boundary.
friend class QgsMeshLayerUndoCommandFlipEdge
bool faceCanBeAdded(const QgsMeshFace &face) const
Returns true if a face can be added to the mesh.
void changeCoordinates(const QList< int > &verticesIndexes, const QList< QgsPoint > &newCoordinates)
Changes the (X,Y,Z) coordinates values of the vertices with indexes in vertices indexes with the valu...
void stopEditing()
Stops editing.
friend class QgsMeshLayerUndoCommandAdvancedEditing
bool canBeMerged(int vertexIndex1, int vertexIndex2) const
Returns true if faces separated by vertices with indexes vertexIndex1 and vertexIndex2 can be merged.
friend class QgsMeshLayerUndoCommandAddFaces
QgsMeshEditingError addFaceWithNewVertices(const QList< int > &vertexIndexes, const QList< QgsMeshVertex > &newVertices)
Adds a face formed by some vertices vertexIndexes to the mesh, returns topological errors if this ope...
friend class QgsMeshLayerUndoCommandChangeCoordinates
bool edgeCanBeFlipped(int vertexIndex1, int vertexIndex2) const
Returns true if the edge can be flipped (only available for edge shared by two faces with 3 vertices)
int splitFaces(const QList< int > &faceIndexes)
Splits faces with index faceIndexes.
QgsMeshVertexCirculator vertexCirculator(int vertexIndex) const
Returns a vertex circulator linked to this mesh around the vertex with index vertexIndex.
bool faceCanBeAddedWithNewVertices(const QList< int > &verticesIndex, const QList< QgsMeshVertex > &newVertices) const
Returns true if a face formed by some vertices can be added to the mesh.
void meshEdited()
Emitted when the mesh is edited.
void changeZValues(const QList< int > &verticesIndexes, const QList< double > &newValues)
Changes the Z values of the vertices with indexes in vertices indexes with the values in newValues.
void resetTriangularMesh(QgsTriangularMesh *triangularMesh)
Resets the triangular mesh.
bool isModified() const
Returns whether the mesh has been modified.
void advancedEdit(QgsMeshAdvancedEditing *editing)
Applies an advance editing on the edited mesh, see QgsMeshAdvancedEditing.
bool canBeTransformed(const QList< int > &facesToCheck, const std::function< const QgsMeshVertex(int)> &transformFunction) const
Returns true if faces with index in transformedFaces can be transformed without obtaining topologic o...
int addVertices(const QVector< QgsMeshVertex > &vertices, double tolerance)
Adds vertices in triangular mesh coordinate in the mesh.
int validVerticesCount() const
Returns the count of valid vertices, that is non void vertices in the mesh.
friend class QgsMeshLayerUndoCommandRemoveVerticesFillHoles
bool isVertexFree(int vertexIndex) const
Returns whether the vertex with index vertexIndex is a free vertex.
bool reindex(bool renumbering)
Reindexes the mesh, that is remove unusued index of face and vertices, this operation void the undo/r...
friend class QgsMeshLayerUndoCommandChangeZValue
QgsTriangularMesh * triangularMesh()
Returns a pointer to the triangular mesh.
bool fixError(const QgsMeshEditingError &error)
Tries to fix the topological error in the mesh.
QgsMeshDatasetGroup * createZValueDatasetGroup()
Creates and returns a scalar dataset group with value on vertex that is can be used to access the Z v...
friend class QgsMeshLayerUndoCommandRemoveFaces
QgsTopologicalMesh & topologicalMesh()
Returns a reference to the topological mesh.
int addPointsAsVertices(const QVector< QgsPoint > &point, double tolerance)
Adds points as vertices in triangular mesh coordinate in the mesh.
QgsMeshLayerUndoCommandAddFaces(QgsMeshEditor *meshEditor, QgsTopologicalMesh::TopologicalFaces &faces)
Constructor with the associated meshEditor and faces that will be added.
QgsMeshLayerUndoCommandAddVertices(QgsMeshEditor *meshEditor, const QVector< QgsMeshVertex > &vertices, double tolerance)
Constructor with the associated meshEditor and vertices that will be added.
QgsMeshLayerUndoCommandAdvancedEditing(QgsMeshEditor *meshEditor, QgsMeshAdvancedEditing *advancdEdit)
Constructor with the associated meshEditor.
QgsMeshLayerUndoCommandChangeCoordinates(QgsMeshEditor *meshEditor, const QList< int > &verticesIndexes, const QList< QgsPoint > &newCoordinates)
Constructor with the associated meshEditor and indexes verticesIndexes of the vertices that will have...
QgsMeshLayerUndoCommandChangeXYValue(QgsMeshEditor *meshEditor, const QList< int > &verticesIndexes, const QList< QgsPointXY > &newValues)
Constructor with the associated meshEditor and indexes verticesIndexes of the vertices that will have...
QgsMeshLayerUndoCommandChangeZValue(QgsMeshEditor *meshEditor, const QList< int > &verticesIndexes, const QList< double > &newValues)
Constructor with the associated meshEditor and indexes verticesIndexes of the vertices that will have...
QgsMeshLayerUndoCommandFlipEdge(QgsMeshEditor *meshEditor, int vertexIndex1, int vertexIndex2)
Constructor with the associated meshEditor and the vertex indexes of the edge (vertexIndex1,...
QgsMeshLayerUndoCommandMerge(QgsMeshEditor *meshEditor, int vertexIndex1, int vertexIndex2)
Constructor with the associated meshEditor and the vertex indexes of the edge (vertexIndex1,...
Base class for undo/redo command for mesh editing.
QList< QgsMeshEditor::Edit > mEdits
QgsMeshLayerUndoCommandMeshEdit(QgsMeshEditor *meshEditor)
Constructor for the base class.
QPointer< QgsMeshEditor > mMeshEditor
QgsMeshLayerUndoCommandRemoveFaces(QgsMeshEditor *meshEditor, const QList< int > &facesToRemoveIndexes)
Constructor with the associated meshEditor and indexes facesToRemoveIndexes of the faces that will be...
QgsMeshLayerUndoCommandRemoveVerticesFillHoles(QgsMeshEditor *meshEditor, const QList< int > &verticesToRemoveIndexes, QList< int > *remainingVerticesPointer=nullptr)
Constructor with the associated meshEditor and vertices that will be removed.
QgsMeshLayerUndoCommandRemoveVerticesWithoutFillHoles(QgsMeshEditor *meshEditor, const QList< int > &verticesToRemoveIndexes)
Constructor with the associated meshEditor and vertices that will be removed.
QgsMeshLayerUndoCommandSplitFaces(QgsMeshEditor *meshEditor, const QList< int > &faceIndexes)
Constructor with the associated meshEditor and indexes faceIndexes of the faces to split.
Represents a mesh layer supporting display of data on structured or unstructured meshes.
QgsMeshDataProvider * dataProvider() override
Returns the layer's data provider, it may be nullptr.
Convenient class that turn around a vertex and provide information about faces and vertices.
bool goBoundaryCounterClockwise() const
Sets the circulator on the boundary face turning counter clockwise, return false is there isn't bound...
int oppositeVertexCounterClockwise() const
Returns the opposite vertex of the current face and on the edge on the side turning counter clockwise...
bool goBoundaryClockwise() const
Sets the circulator on the boundary face turning clockwise, return false is there isn't boundary face...
int oppositeVertexClockwise() const
Returns the opposite vertex of the current face and on the edge on the side turning clockwise.
A class to represent a 2D point.
double distance(double x, double y) const
Returns the distance between this point and a specified x, y coordinate.
Point geometry type, with support for z-dimension and m-values.
bool isEmpty() const override
Returns true if the geometry is empty.
A rectangle specified with double values.
Class that contains topological differences between two states of a topological mesh,...
QVector< QgsMeshFace > removedFaces() const
Returns the faces that are removed with this changes.
QVector< QgsMeshVertex > addedVertices() const
Returns the added vertices with this changes.
bool isEmpty() const
Returns whether changes are empty, that there is nothing to change.
QVector< QgsMeshFace > addedFaces() const
Returns the face that are added with this changes.
QList< int > verticesToRemoveIndexes() const
Returns the indexes of vertices to remove.
Class that contains independent faces an topological information about this faces.
void clear()
Clears all data contained in the instance.
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 QgsMeshEditingError checkTopologyOfVerticesAsFace(const QVector< QgsMeshVertex > &vertices, bool &clockwise)
Checks the topology of the vertices as they are contained in a face and returns indication on directi...
Changes changeZValue(const QList< int > &verticesIndexes, const QList< double > &newValues)
Changes the Z values of the vertices with indexes in vertices indexes with the values in newValues.
static QgsTopologicalMesh createTopologicalMesh(QgsMesh *mesh, int maxVerticesPerFace, QgsMeshEditingError &error)
Creates a topologicaly consistent mesh with mesh, this static method modifies mesh to be topological ...
bool isVertexFree(int vertexIndex) const
Returns whether the vertex is a free vertex.
static QgsMeshEditingError counterClockwiseFaces(QgsMeshFace &face, QgsMesh *mesh)
Checks the topology of the face and sets it counter clockwise if necessary.
Changes removeVertexFillHole(int vertexIndex)
Removes the vertex with index vertexIndex.
void applyChanges(const Changes &changes)
Applies the changes.
QgsMeshEditingError checkConsistency() const
Checks the consistency of the topological mesh and return false if there is a consistency issue.
Changes removeVertices(const QList< int > &vertices)
Removes all the vertices with index in the list vertices If vertices in linked with faces,...
Changes changeXYValue(const QList< int > &verticesIndexes, const QList< QgsPointXY > &newValues)
Changes the (X,Y) values of the vertices with indexes in vertices indexes with the values in newValue...
void reindex()
Reindexes faces and vertices, after this operation, the topological mesh can't be edited anymore and ...
QgsMeshEditingError facesCanBeAdded(const TopologicalFaces &topologicalFaces) const
Returns whether the faces can be added to the mesh.
bool renumber()
Renumbers the indexes of vertices and faces using the Reverse CutHill McKee Algorithm.
Changes flipEdge(int vertexIndex1, int vertexIndex2)
Flips edge (vertexIndex1, vertexIndex2) The method returns a instance of the class QgsTopologicalMesh...
QgsMeshEditingError facesCanBeRemoved(const QList< int > &facesIndexes)
Returns whether faces with index in faceIndexes can be removed/ The method an error object with type ...
void reverseChanges(const Changes &changes)
Reverses the changes.
Changes addFaces(const TopologicalFaces &topologicFaces)
Adds faces topologicFaces to the topologic mesh.
Changes merge(int vertexIndex1, int vertexIndex2)
Merges faces separated by vertices with indexes vertexIndex1 and vertexIndex2 The method returns a in...
Changes removeFaces(const QList< int > &facesIndexes)
Removes faces with index in faceIndexes.
QList< int > freeVerticesIndexes() const
Returns a list of vertices are not linked to any faces.
bool edgeCanBeFlipped(int vertexIndex1, int vertexIndex2) const
Returns true if the edge can be flipped (only available for edge shared by two faces with 3 vertices)
Changes addVertexInFace(int faceIndex, const QgsMeshVertex &vertex)
Adds a vertex in the face with index faceIndex.
bool canBeMerged(int vertexIndex1, int vertexIndex2) const
Returns true if faces separated by vertices with indexes vertexIndex1 and vertexIndex2 can be merged.
QList< int > facesAroundVertex(int vertexIndex) const
Returns the indexes of faces that are around the vertex with index vertexIndex.
bool canBeSplit(int faceIndex) const
Returns true if face with index faceIndex can be split.
Changes addFreeVertex(const QgsMeshVertex &vertex)
Adds a free vertex in the face, that is a vertex tha tis not included or linked with any faces.
Changes insertVertexInFacesEdge(int faceIndex, int position, const QgsMeshVertex &vertex)
Inserts a vertex in the edge of face with index faceIndex at position .
bool isVertexOnBoundary(int vertexIndex) const
Returns whether the vertex is on a boundary.
Changes splitFace(int faceIndex)
Splits face with index faceIndex The method returns a instance of the class QgsTopologicalMesh::Chang...
static TopologicalFaces createNewTopologicalFaces(const QVector< QgsMeshFace > &faces, bool uniqueSharedVertexAllowed, QgsMeshEditingError &error)
Creates new topological faces that are not yet included in the mesh.
QgsMeshVertexCirculator vertexCirculator(int vertexIndex) const
Returns a vertex circulator linked to this mesh around the vertex with index vertexIndex.
The Changes class is used to make changes of the triangular and to keep traces of this changes If a C...
Triangular/Derived Mesh is mesh with vertices in map coordinates.
const QVector< QgsMeshFace > & triangles() const
Returns triangles.
QgsRectangle nativeExtent()
Returns the extent of the mesh in the native mesh coordinates system, returns empty extent if the tra...
int nativeFaceIndexForPoint(const QgsPointXY &point) const
Finds index of native face at given point It uses spatial indexing.
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)
const QVector< QgsMeshVertex > & vertices() const
Returns vertices in map coordinate system.
QgsMeshVertex triangularToNativeCoordinates(const QgsMeshVertex &vertex) const
Transforms the vertex from triangular mesh coordinates system to native coordinates system.
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...
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.
int vertexCount() const
Returns number of vertices.
QVector< QgsMeshVertex > vertices
QgsMeshFace face(int index) const
Returns a face at the index.
QVector< QgsMeshFace > faces
int faceCount() const
Returns number of faces.