19#include "moc_qgsmeshtriangulation.cpp"
57 addVerticesFromFeature( feat, valueAttribute, transform, feedback );
85 addVerticesFromFeature( feat, valueAttribute, transform, feedback );
89 addBreakLinesFromFeature( feat, valueAttribute, transform, feedback );
101 return mTriangulation->addPoint( vertex );
106 return mTriangulation->triangulationToMesh( feedback );
131 if ( valueAttribute >= 0 )
132 value = feature.
attribute( valueAttribute ).toDouble();
138 if ( valueAttribute < 0 )
139 mTriangulation->addPoint( *vit );
150 double valueOnVertex = 0;
151 if ( valueAttribute >= 0 )
152 valueOnVertex = feature.
attribute( valueAttribute ).toDouble();
155 std::vector<const QgsCurve *> curves;
170 std::vector< const QgsCurvePolygon * > polygons;
176 polygons.emplace_back( qgsgeometry_cast< const QgsCurvePolygon * >( ms->
geometryN( i ) ) );
181 polygons.emplace_back( qgsgeometry_cast< const QgsCurvePolygon * >( geom.
constGet() ) );
191 if ( polygon->exteriorRing() )
192 curves.emplace_back( polygon->exteriorRing() );
194 for (
int i = 0; i < polygon->numInteriorRings(); ++i )
198 curves.emplace_back( polygon->interiorRing( i ) );
211 curves.emplace_back( qgsgeometry_cast< const QgsCurve * >( mc->
geometryN( i ) ) );
216 curves.emplace_back( qgsgeometry_cast< const QgsCurve * >( geom.
constGet() ) );
220 for (
const QgsCurve *curve : curves )
229 curve->points( linePoints );
230 bool hasZ = curve->is3D();
231 if ( valueAttribute >= 0 )
232 for (
int i = 0; i < linePoints.count(); ++i )
237 linePoints[i].setZ( valueOnVertex );
240 const QgsPoint &point = linePoints.at( i );
241 linePoints[i] =
QgsPoint( point.
x(), point.
y(), valueOnVertex );
252 mDataset = std::make_unique< QgsMeshZValueDataset >( mesh );
262 if ( datasetIndex != 0 )
265 return mDataset->metadata();
275 return mDataset.get();
282 return QDomElement();
289 if ( vertex.z() < mZMinimum )
290 mZMinimum = vertex.z();
291 if ( vertex.z() > mZMaximum )
292 mZMaximum = vertex.z();
298 if ( valueIndex < 0 || valueIndex >= mMesh.
vertexCount() )
308 QVector<double> zValues( count );
309 for (
int i = valueIndex; i < valueIndex + count; ++i )
310 zValues[i - valueIndex] = mMesh.
vertex( i ).
z();
317 Q_UNUSED( faceIndex );
326 return ( faceIndex > 0 && faceIndex < mMesh.
faceCount() );
343 return QObject::tr(
"Delaunay triangulation" );
349 QList<int> vertexIndextoTriangulate;
351 QList<int> removedVerticesFromTriangulation;
356 vertexIndextoTriangulate.append( vertexIndex );
358 removedVerticesFromTriangulation.append( vertexIndex );
361 bool triangulationReady =
false;
365 while ( !triangulationReady )
369 QVector<int> triangulationVertexToMeshVertex( vertexIndextoTriangulate.count() );
372 for (
int i = 0; i < vertexIndextoTriangulate.count(); ++i )
374 triangulationVertexToMeshVertex[i] = vertexIndextoTriangulate.at( i );
375 triangulation.
addVertex( destinationMesh->
vertices.at( vertexIndextoTriangulate.at( i ) ) );
381 QVector<QgsMeshFace> rawDestinationFaces = resultingTriangulation.
faces;
383 for (
QgsMeshFace &destinationFace : rawDestinationFaces )
385 for (
int &vertexIndex : destinationFace )
386 vertexIndex = triangulationVertexToMeshVertex[vertexIndex];
390 QVector<QgsMeshFace> destinationFaces;
391 for (
const QgsMeshFace &face : rawDestinationFaces )
394 destinationFaces.append( face );
397 bool facesReady =
false;
399 while ( !facesReady && !giveUp )
411 triangulationReady =
true;
427 removedVerticesFromTriangulation.append( error.
elementIndex );
428 vertexIndextoTriangulate.removeOne( error.
elementIndex );
439 if ( !removedVerticesFromTriangulation.isEmpty() )
440 mMessage = QObject::tr(
"%n vertices have not been included in the triangulation",
nullptr, removedVerticesFromTriangulation.count() );
444 if ( triangulationReady && !giveUp )
@ 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.
GeometryType
The geometry types are used to group Qgis::WkbType in a coarse way.
@ Forward
Forward transform (from source to destination)
The vertex_iterator class provides STL-style iterator for vertices.
This class represents a coordinate reference system (CRS).
Custom exception class for Coordinate Reference System related exceptions.
Curve polygon geometry type.
Abstract base class for curved geometry type.
DualEdgeTriangulation is an implementation of a triangulation class based on the dual edge data struc...
Wrapper for iterator of features from vector data provider or vector layer.
bool nextFeature(QgsFeature &f)
Fetch next feature and stores in f, returns true on success.
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
Q_INVOKABLE QVariant attribute(const QString &name) const
Lookup attribute value by attribute name.
Base class for feedback objects to be used for cancellation of something running in a worker thread.
bool isCanceled() const
Tells whether the operation has been canceled already.
void setProgress(double progress)
Sets the current progress for the feedback object.
int numGeometries() const
Returns the number of geometries within the collection.
const QgsAbstractGeometry * geometryN(int n) const
Returns a const reference to a geometry from within the collection.
A geometry is the spatial representation of a feature.
Qgis::GeometryOperationResult transform(const QgsCoordinateTransform &ct, Qgis::TransformDirection direction=Qgis::TransformDirection::Forward, bool transformZ=false)
Transforms this geometry as described by the coordinate transform ct.
const QgsAbstractGeometry * constGet() const
Returns a non-modifiable (const) reference to the underlying abstract geometry primitive.
bool isMultipart() const
Returns true if WKB of the geometry is of WKBMulti* type.
QgsAbstractGeometry::vertex_iterator vertices_begin() const
Returns STL-style iterator pointing to the first vertex of the geometry.
Qgis::WkbType wkbType() const
Returns type of the geometry as a WKB type (point / linestring / polygon etc.)
QgsAbstractGeometry::vertex_iterator vertices_end() const
Returns STL-style iterator pointing to the imaginary vertex after the last vertex of the geometry.
@ SourceBreakLines
Break lines.
QList< int > mInputVertices
QgsMeshDataBlock is a block of integers/doubles that can be used to retrieve: active flags (e....
@ ScalarDouble
Scalar double values.
@ ActiveFlagInteger
Integer boolean flag whether face is active.
void setValues(const QVector< double > &vals)
Sets values.
void setValid(bool valid)
Sets block validity.
Abstract class that represents a dataset group.
void calculateStatistic() const
Calculates the statistics (minimum and maximum)
QgsMeshDatasetValue represents single dataset value.
Abstract class that represents a dataset.
QgsMeshEditingDelaunayTriangulation()
QString text() const override
Returns a short text string describing what this advanced edit does. Default implementation return a ...
Class that represents an error during mesh editing.
Qgis::MeshEditingErrorType errorType
Class that makes edit operation on a mesh.
bool isFaceGeometricallyCompatible(const QgsMeshFace &face) const
Returns true if the face does not intersect or contains any other elements (faces or vertices) The to...
bool isVertexOnBoundary(int vertexIndex) const
Returns whether the vertex with index vertexIndex is on a boundary.
bool isVertexFree(int vertexIndex) const
Returns whether the vertex with index vertexIndex is a free vertex.
QgsTopologicalMesh & topologicalMesh()
Returns a reference to the topological mesh.
Class that handles mesh creation with Delaunay constrained triangulation.
bool addBreakLines(QgsFeatureIterator &lineFeatureIterator, int valueAttribute, const QgsCoordinateTransform &transformContext, QgsFeedback *feedback=nullptr, long featureCount=1)
Adds break lines from a vector layer, return true if successful.
int addVertex(const QgsPoint &vertex)
Adds a new vertex in the triangulation and returns the index of the new vertex.
void setCrs(const QgsCoordinateReferenceSystem &crs)
Sets the coordinate reference system used for the triangulation.
bool addVertices(QgsFeatureIterator &vertexFeatureIterator, int valueAttribute, const QgsCoordinateTransform &transform, QgsFeedback *feedback=nullptr, long featureCount=1)
Adds vertices to the triangulation from a feature iterator, return true if successful.
QgsMesh triangulatedMesh(QgsFeedback *feedback=nullptr) const
Returns the triangulated mesh.
int datasetCount() const override
Returns the count of datasets in the group.
QDomElement writeXml(QDomDocument &doc, const QgsReadWriteContext &context) const override
Write dataset group information in a DOM element.
void initialize() override
Initialize the dataset group.
QgsMeshDataset * dataset(int index) const override
Returns the dataset with index.
QgsMeshDatasetMetadata datasetMetadata(int datasetIndex) const override
Returns the metadata of the dataset with index datasetIndex.
QgsMeshZValueDatasetGroup(const QString &datasetGroupName, const QgsMesh &mesh)
Constructor.
QgsMeshDataBlock areFacesActive(int faceIndex, int count) const override
Returns whether faces are active.
QgsMeshDatasetMetadata metadata() const override
Returns the metadata of the dataset.
QgsMeshZValueDataset(const QgsMesh &mesh)
Constructor with the mesh.
bool isActive(int faceIndex) const override
Returns whether the face is active.
int valuesCount() const override
Returns the values count.
QgsMeshDatasetValue datasetValue(int valueIndex) const override
Returns the value with index valueIndex.
QgsMeshDataBlock datasetValues(bool isScalar, int valueIndex, int count) const override
Returns count values from valueIndex.
Multi curve geometry collection.
Multi surface geometry collection.
Point geometry type, with support for z-dimension and m-values.
The class is used as a container of context for various read/write operations on other objects.
Class that contains topological differences between two states of a topological mesh,...
Class that contains independent faces an topological information about this faces.
QgsMeshEditingError checkConsistency() const
Checks the consistency of the topological mesh and return false if there is a consistency issue.
QgsMeshEditingError facesCanBeAdded(const TopologicalFaces &topologicalFaces) const
Returns whether the faces can be added to the mesh.
Changes addFaces(const TopologicalFaces &topologicFaces)
Adds faces topologicFaces to the topologic mesh.
QgsMesh * mesh() const
Returns a pointer to the wrapped mesh.
static TopologicalFaces createNewTopologicalFaces(const QVector< QgsMeshFace > &faces, bool uniqueSharedVertexAllowed, QgsMeshEditingError &error)
Creates new topological faces that are not yet included in the mesh.
static Qgis::GeometryType geometryType(Qgis::WkbType type)
Returns the geometry type for a WKB type, e.g., both MultiPolygon and CurvePolygon would have a Polyg...
QVector< QgsPoint > QgsPointSequence
#define QgsDebugMsgLevel(str, level)
QVector< int > QgsMeshFace
List of vertex indexes.
const QgsCoordinateReferenceSystem & crs
Mesh - vertices, edges and faces.
int vertexCount() const
Returns number of vertices.
QVector< QgsMeshVertex > vertices
QVector< QgsMeshFace > faces
int faceCount() const
Returns number of faces.
QgsMeshVertex vertex(int index) const
Returns a vertex at the index.