Class: QgsTopologicalMesh

Wraps a QgsMesh to ensure the consistency of the mesh during editing and helps to access elements from other elements.

A topological face must:

  • be convex

  • be oriented counter-clockwise

  • not share a unique vertex with another face

Added in version 3.22.

Methods

addFaces

Adds faces topologicFaces to the topologic mesh.

addFreeVertex

Adds a free vertex in the face, that is a vertex that is not included or linked with any faces.

addVertexInFace

Adds a vertex in the face with index faceIndex.

applyChanges

Applies the changes

canBeMerged

Returns True if faces separated by vertices with indexes vertexIndex1 and vertexIndex2 can be merged

canBeSplit

Returns True if face with index faceIndex can be split

changeXYValue

Changes the (X,Y) values of the vertices with indexes in vertices indexes with the values in newValues

changeZValue

Changes the Z values of the vertices with indexes in vertices indexes with the values in newValues

checkConsistency

Checks the consistency of the topological mesh and return False if there is a consistency issue

delaunayConditionForEdge

Check if Delaunay condition holds for given edge returns True if delaunay condition holds False otherwise

edgeCanBeFlipped

Returns True if the edge can be flipped (only available for edge shared by two faces with 3 vertices)

facesAroundVertex

Returns the indexes of faces that are around the vertex with index vertexIndex

facesCanBeAdded

Returns whether the faces can be added to the mesh

facesCanBeRemoved

Returns whether faces with index in faceIndexes can be removed The method an error object with type QgsMeshEditingError.NoError if the faces can be removed, otherwise returns the corresponding error

firstFaceLinked

Returns the index of the first face linked, returns -1 if it is a free vertex or out of range index

flipEdge

Flips edge (vertexIndex1, vertexIndex2) The method returns a instance of the class QgsTopologicalMesh.Change that can be used to reverse or reapply the operation.

freeVerticesIndexes

Returns a list of vertices are not linked to any faces

insertVertexInFacesEdge

Inserts a vertex in the edge of face with index faceIndex at position .

isVertexFree

Returns whether the vertex is a free vertex

isVertexOnBoundary

Returns whether the vertex is on a boundary

merge

Merges faces separated by vertices with indexes vertexIndex1 and vertexIndex2 The method returns a instance of the class QgsTopologicalMesh.Change that can be used to reverse or reapply the operation.

mesh

Returns a pointer to the wrapped mesh

neighborsOfFace

Returns the indexes of neighbor faces of the face with index faceIndex

reindex

Reindexes faces and vertices, after this operation, the topological mesh can't be edited anymore and only the method mesh can be used to access to the raw mesh.

removeFaces

Removes faces with index in faceIndexes.

removeVertexFillHole

Removes the vertex with index vertexIndex.

removeVertices

Removes all the vertices with index in the list vertices If vertices in linked with faces, the operation leads also to remove the faces without filling holes.

renumber

Renumbers the indexes of vertices and faces using the Reverse CutHill McKee Algorithm

reverseChanges

Reverses the changes

splitFace

Splits face with index faceIndex The method returns a instance of the class QgsTopologicalMesh.Change that can be used to reverse or reapply the operation.

Static Methods

checkTopology

Checks the topology of the mesh mesh, if error occurs, this mesh can't be edited

counterClockwiseFaces

Checks the topology of the face and sets it counter clockwise if necessary

createTopologicalMesh

Creates a topologicaly consistent mesh with mesh, this static method modifies mesh to be topological consistent and return a QgsTopologicalMesh instance that contains and handles this mesh (does not take ownership).

vertexPositionInFace

Returns vertex position in face

class qgis.core.QgsTopologicalMesh[source]

Bases: object

class Changes[source]

Bases: object

Contains topological differences between two states of a topological mesh, only accessible from the QgsTopologicalMesh class.

Added in version 3.22.

addedVertices(self) List[QgsPoint]

Returns the added vertices with this changes

Return type:

List[QgsPoint]

changedCoordinatesVerticesIndexes(self) List[int]

Returns the indexes of vertices that have changed coordinates

Return type:

List[int]

clearChanges(self)[source]

Clears all changes

isEmpty(self) bool[source]

Returns whether changes are empty, that there is nothing to change

Return type:

bool

nativeFacesIndexesGeometryChanged(self) List[int]

Returns a list of the native face indexes that have a geometry changed

Return type:

List[int]

newVerticesXYValues(self) List[QgsPointXY]

Returns the new (X,Y) values of vertices that have changed their coordinates

Return type:

List[QgsPointXY]

newVerticesZValues(self) List[float]

Returns the new Z values of vertices that have changed their coordinates

Return type:

List[float]

oldVerticesXYValues(self) List[QgsPointXY]

Returns the old (X,Y) values of vertices that have changed their coordinates

Return type:

List[QgsPointXY]

removedFaceIndexes(self) List[int]

Returns the indexes of the faces that are removed with this changes

Return type:

List[int]

verticesToRemoveIndexes(self) List[int]

Returns the indexes of vertices to remove

Return type:

List[int]

class TopologicalFaces[source]

Bases: object

Contains independent faces and topological information about these faces.

This class supports unique shared vertices between faces.

Added in version 3.22.

clear(self)[source]

Clears all data contained in the instance.

vertexToFace(self, vertexIndex: int) int[source]

Returns a face linked to the vertices with index vertexIndex

Parameters:

vertexIndex (int)

Return type:

int

addFaces(self, topologicFaces: QgsTopologicalMesh.TopologicalFaces) QgsTopologicalMesh.Changes[source]

Adds faces topologicFaces to the topologic mesh. The method returns a instance of the class QgsTopologicalMesh.Change that can be used to reverse or reapply the operation.

Parameters:

topologicFaces (QgsTopologicalMesh.TopologicalFaces)

Return type:

QgsTopologicalMesh.Changes

addFreeVertex(self, vertex: QgsPoint) QgsTopologicalMesh.Changes[source]

Adds a free vertex in the face, that is a vertex that is not included or linked with any faces. The method returns a instance of the class QgsTopologicalMesh.Change that can be used to reverse or reapply the operation.

Parameters:

vertex (QgsPoint)

Return type:

QgsTopologicalMesh.Changes

addVertexInFace(self, faceIndex: int, vertex: QgsPoint) QgsTopologicalMesh.Changes[source]

Adds a vertex in the face with index faceIndex. The including face is removed and new faces surrounding the added vertex are added. The method returns a instance of the class QgsTopologicalMesh.Change that can be used to reverse or reapply the operation.

Parameters:
Return type:

QgsTopologicalMesh.Changes

applyChanges(self, changes: QgsTopologicalMesh.Changes)[source]

Applies the changes

Parameters:

changes (QgsTopologicalMesh.Changes)

canBeMerged(self, vertexIndex1: int, vertexIndex2: int) bool[source]

Returns True if faces separated by vertices with indexes vertexIndex1 and vertexIndex2 can be merged

Parameters:
  • vertexIndex1 (int)

  • vertexIndex2 (int)

Return type:

bool

canBeSplit(self, faceIndex: int) bool[source]

Returns True if face with index faceIndex can be split

Parameters:

faceIndex (int)

Return type:

bool

changeXYValue(self, verticesIndexes: Iterable[int], newValues: Iterable[QgsPointXY]) QgsTopologicalMesh.Changes[source]

Changes the (X,Y) values of the vertices with indexes in vertices indexes with the values in newValues

Parameters:
  • verticesIndexes (Iterable[int])

  • newValues (Iterable[QgsPointXY])

Return type:

QgsTopologicalMesh.Changes

changeZValue(self, verticesIndexes: Iterable[int], newValues: Iterable[float]) QgsTopologicalMesh.Changes[source]

Changes the Z values of the vertices with indexes in vertices indexes with the values in newValues

Parameters:
  • verticesIndexes (Iterable[int])

  • newValues (Iterable[float])

Return type:

QgsTopologicalMesh.Changes

checkConsistency(self) QgsMeshEditingError[source]

Checks the consistency of the topological mesh and return False if there is a consistency issue

Return type:

QgsMeshEditingError

static checkTopology(mesh: QgsMesh, maxVerticesPerFace: int) QgsMeshEditingError[source]

Checks the topology of the mesh mesh, if error occurs, this mesh can’t be edited

Parameters:
  • mesh (QgsMesh)

  • maxVerticesPerFace (int)

Return type:

QgsMeshEditingError

static counterClockwiseFaces(face: Iterable[int], mesh: QgsMesh | None) QgsMeshEditingError[source]

Checks the topology of the face and sets it counter clockwise if necessary

Parameters:
  • face (Iterable[int])

  • mesh (Optional[QgsMesh])

Return type:

QgsMeshEditingError

static createTopologicalMesh(mesh: QgsMesh | None, maxVerticesPerFace: int, error: QgsMeshEditingError) QgsTopologicalMesh[source]

Creates a topologicaly consistent mesh with mesh, this static method modifies mesh to be topological consistent and return a QgsTopologicalMesh instance that contains and handles this mesh (does not take ownership).

Parameters:
Return type:

QgsTopologicalMesh

delaunayConditionForEdge(self, vertexIndex1: int, vertexIndex2: int) bool[source]

Check if Delaunay condition holds for given edge returns True if delaunay condition holds False otherwise

Added in version 3.42.

Parameters:
  • vertexIndex1 (int)

  • vertexIndex2 (int)

Return type:

bool

edgeCanBeFlipped(self, vertexIndex1: int, vertexIndex2: int) bool[source]

Returns True if the edge can be flipped (only available for edge shared by two faces with 3 vertices)

Parameters:
  • vertexIndex1 (int)

  • vertexIndex2 (int)

Return type:

bool

facesAroundVertex(self, vertexIndex: int) List[int]

Returns the indexes of faces that are around the vertex with index vertexIndex

Parameters:

vertexIndex (int)

Return type:

List[int]

facesCanBeAdded(self, topologicalFaces: QgsTopologicalMesh.TopologicalFaces) QgsMeshEditingError[source]

Returns whether the faces can be added to the mesh

Parameters:

topologicalFaces (QgsTopologicalMesh.TopologicalFaces)

Return type:

QgsMeshEditingError

facesCanBeRemoved(self, facesIndexes: Iterable[int]) QgsMeshEditingError[source]

Returns whether faces with index in faceIndexes can be removed The method an error object with type QgsMeshEditingError.NoError if the faces can be removed, otherwise returns the corresponding error

Parameters:

facesIndexes (Iterable[int])

Return type:

QgsMeshEditingError

firstFaceLinked(self, vertexIndex: int) int[source]

Returns the index of the first face linked, returns -1 if it is a free vertex or out of range index

Parameters:

vertexIndex (int)

Return type:

int

flipEdge(self, vertexIndex1: int, vertexIndex2: int) QgsTopologicalMesh.Changes[source]

Flips edge (vertexIndex1, vertexIndex2) The method returns a instance of the class QgsTopologicalMesh.Change that can be used to reverse or reapply the operation.

Parameters:
  • vertexIndex1 (int)

  • vertexIndex2 (int)

Return type:

QgsTopologicalMesh.Changes

freeVerticesIndexes(self) List[int]

Returns a list of vertices are not linked to any faces

Return type:

List[int]

insertVertexInFacesEdge(self, faceIndex: int, position: int, vertex: QgsPoint) QgsTopologicalMesh.Changes[source]

Inserts a vertex in the edge of face with index faceIndex at position . The faces that are on each side of the edge are removed and replaced by new faces constructed by a triangulation.

Parameters:
  • faceIndex (int)

  • position (int)

  • vertex (QgsPoint)

Return type:

QgsTopologicalMesh.Changes

isVertexFree(self, vertexIndex: int) bool[source]

Returns whether the vertex is a free vertex

Parameters:

vertexIndex (int)

Return type:

bool

isVertexOnBoundary(self, vertexIndex: int) bool[source]

Returns whether the vertex is on a boundary

Parameters:

vertexIndex (int)

Return type:

bool

merge(self, vertexIndex1: int, vertexIndex2: int) QgsTopologicalMesh.Changes[source]

Merges faces separated by vertices with indexes vertexIndex1 and vertexIndex2 The method returns a instance of the class QgsTopologicalMesh.Change that can be used to reverse or reapply the operation.

Parameters:
  • vertexIndex1 (int)

  • vertexIndex2 (int)

Return type:

QgsTopologicalMesh.Changes

mesh(self) QgsMesh | None[source]

Returns a pointer to the wrapped mesh

Return type:

Optional[QgsMesh]

neighborsOfFace(self, faceIndex: int) List[int]

Returns the indexes of neighbor faces of the face with index faceIndex

Parameters:

faceIndex (int)

Return type:

List[int]

reindex(self)[source]

Reindexes faces and vertices, after this operation, the topological mesh can’t be edited anymore and only the method mesh can be used to access to the raw mesh.

removeFaces(self, facesIndexes: Iterable[int]) QgsTopologicalMesh.Changes[source]

Removes faces with index in faceIndexes. The method returns a instance of the class QgsTopologicalMesh.Change that can be used to reverse or reapply the operation.

Parameters:

facesIndexes (Iterable[int])

Return type:

QgsTopologicalMesh.Changes

removeVertexFillHole(self, vertexIndex: int) QgsTopologicalMesh.Changes[source]

Removes the vertex with index vertexIndex. If the vertex in linked with faces, the operation leads also to remove the faces. In this case, the hole is filled by a triangulation. The method returns a instance of the class QgsTopologicalMesh.Change that can be used to reverse or reapply the operation.

Parameters:

vertexIndex (int)

Return type:

QgsTopologicalMesh.Changes

removeVertices(self, vertices: Iterable[int]) QgsTopologicalMesh.Changes[source]

Removes all the vertices with index in the list vertices If vertices in linked with faces, the operation leads also to remove the faces without filling holes. The method returns a instance of the class QgsTopologicalMesh.Change that can be used to reverse or reapply the operation.

Parameters:

vertices (Iterable[int])

Return type:

QgsTopologicalMesh.Changes

renumber(self) bool[source]

Renumbers the indexes of vertices and faces using the Reverse CutHill McKee Algorithm

Return type:

bool

reverseChanges(self, changes: QgsTopologicalMesh.Changes)[source]

Reverses the changes

Parameters:

changes (QgsTopologicalMesh.Changes)

splitFace(self, faceIndex: int) QgsTopologicalMesh.Changes[source]

Splits face with index faceIndex The method returns a instance of the class QgsTopologicalMesh.Change that can be used to reverse or reapply the operation.

Parameters:

faceIndex (int)

Return type:

QgsTopologicalMesh.Changes

static vertexPositionInFace(vertexIndex: int, face: Iterable[int]) int[source]

Returns vertex position in face

Parameters:
  • vertexIndex (int)

  • face (Iterable[int])

Return type:

int

static vertexPositionInFace(mesh: QgsMesh, vertexIndex: int, faceIndex: int) int[source]

Returns vertex position in face

Parameters:
  • mesh (QgsMesh)

  • vertexIndex (int)

  • faceIndex (int)

Return type:

int