Skip to content
Permalink
Browse files

Merge pull request #38309 from vcloarec/TINMeshCreaton

TIN Mesh creation
  • Loading branch information
wonder-sk committed Sep 11, 2020
2 parents 5941261 + 89e4d49 commit 7cbf80ff5c3e88f5777437d28db52be8f8b86ac2
Showing with 2,203 additions and 23 deletions.
  1. +1 −1 CMakeLists.txt
  2. +1 −0 python/analysis/analysis_auto.sip
  3. +120 −0 python/analysis/auto_generated/mesh/qgsmeshtriangulation.sip.in
  4. +10 −0 python/core/auto_generated/mesh/qgsmeshlayer.sip.in
  5. +2 −0 python/core/auto_generated/processing/qgsprocessingparameters.sip.in
  6. +100 −0 python/core/auto_generated/processing/qgsprocessingparametertininputlayers.sip.in
  7. +12 −0 python/core/auto_generated/qgsprovidermetadata.sip.in
  8. +1 −0 python/core/core_auto.sip
  9. +1 −1 python/plugins/processing/gui/Postprocessing.py
  10. +3 −0 src/analysis/CMakeLists.txt
  11. +2 −2 src/analysis/interpolation/NormVecDecorator.cpp
  12. +1 −1 src/analysis/interpolation/NormVecDecorator.h
  13. +5 −5 src/analysis/interpolation/qgsdualedgetriangulation.cpp
  14. +1 −1 src/analysis/interpolation/qgsdualedgetriangulation.h
  15. +5 −9 src/analysis/interpolation/qgstininterpolator.cpp
  16. +1 −1 src/analysis/interpolation/qgstriangulation.h
  17. +339 −0 src/analysis/mesh/qgsmeshtriangulation.cpp
  18. +159 −0 src/analysis/mesh/qgsmeshtriangulation.h
  19. +182 −0 src/analysis/processing/qgsalgorithmtinmeshcreation.cpp
  20. +64 −0 src/analysis/processing/qgsalgorithmtinmeshcreation.h
  21. +2 −0 src/analysis/processing/qgsnativealgorithms.cpp
  22. +2 −0 src/core/CMakeLists.txt
  23. +1 −1 src/core/mesh/qgsmeshlayer.h
  24. +2 −0 src/core/processing/qgsprocessingparameters.h
  25. +99 −0 src/core/processing/qgsprocessingparametertininputlayers.cpp
  26. +113 −0 src/core/processing/qgsprocessingparametertininputlayers.h
  27. +2 −0 src/core/processing/qgsprocessingregistry.cpp
  28. +9 −0 src/core/qgsprovidermetadata.cpp
  29. +13 −0 src/core/qgsprovidermetadata.h
  30. +2 −0 src/gui/CMakeLists.txt
  31. +2 −0 src/gui/processing/qgsprocessingguiregistry.cpp
  32. +384 −0 src/gui/processing/qgsprocessingtininputlayerswidget.cpp
  33. +119 −0 src/gui/processing/qgsprocessingtininputlayerswidget.h
  34. +70 −0 src/providers/mdal/qgsmdalprovider.cpp
  35. +4 −0 src/providers/mdal/qgsmdalprovider.h
  36. +150 −0 src/ui/processing/qgsprocessingtinmeshdatawidgetbase.ui
  37. +43 −0 tests/src/analysis/testqgsprocessing.cpp
  38. +49 −0 tests/src/analysis/testqgsprocessingalgs.cpp
  39. +88 −1 tests/src/analysis/testqgstriangulation.cpp
  40. +39 −0 tests/src/gui/testprocessinggui.cpp
@@ -871,7 +871,7 @@ IF (WITH_CORE AND WITH_BINDINGS)
INCLUDE(SIPMacros)

SET(SIP_INCLUDES ${PYQT_SIP_DIR} ${CMAKE_SOURCE_DIR}/python)
SET(SIP_CONCAT_PARTS 9)
SET(SIP_CONCAT_PARTS 11)

IF (NOT BINDINGS_GLOBAL_INSTALL)
SET(PYTHON_SITE_PACKAGES_DIR ${QGIS_DATA_DIR}/python)
@@ -5,6 +5,7 @@
%Include auto_generated/interpolation/qgsinterpolator.sip
%Include auto_generated/interpolation/qgstininterpolator.sip
%Include auto_generated/mesh/qgsmeshcontours.sip
%Include auto_generated/mesh/qgsmeshtriangulation.sip
%Include auto_generated/network/qgsgraph.sip
%Include auto_generated/network/qgsgraphanalyzer.sip
%Include auto_generated/network/qgsgraphbuilder.sip
@@ -0,0 +1,120 @@
/************************************************************************
* This file has been generated automatically from *
* *
* src/analysis/mesh/qgsmeshtriangulation.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/






class QgsMeshTriangulation : QObject
{
%Docstring

Class that handles mesh creation with Delaunay constrained triangulation

.. versionadded:: 3.16
%End

%TypeHeaderCode
#include "qgsmeshtriangulation.h"
%End
public:

QgsMeshTriangulation();
%Docstring
Constructor
%End

~QgsMeshTriangulation();

bool addVertices( QgsFeatureIterator &vertexFeatureIterator, int valueAttribute, const QgsCoordinateTransform &transform, QgsFeedback *feedback = 0, long featureCount = 1 );
%Docstring
Adds vertices to the triangulation from a feature iterator, return ``True`` if successful.

:param vertexFeatureIterator: the feature iterator of vertices to insert
:param valueAttribute: the index of the attribute that represents the value of vertices, if -1 uses Z coordinate of vertices
:param transform: the coordinates transform used to transform coordinates
:param feedback: feedback argument may be specified to allow cancellation and progress reports
:param featureCount: the count of feature to allow progress report of the feedback
%End

bool addBreakLines( QgsFeatureIterator &lineFeatureIterator, int valueAttribute, const QgsCoordinateTransform &transformContext, QgsFeedback *feedback = 0, long featureCount = 1 );
%Docstring
Adds break lines from a vector layer, return ``True`` if successful.

:param lineFeatureIterator: the feature iterator of break lines to insert
:param valueAttribute: the index of the attribute that represents the value of vertices, if -1 uses Z coordinate of vertices
:param transform: the coordinates transform used to transform coordinates
:param feedback: feedback argument may be specified to allow cancellation and progress reports
:param featureCount: the count of feature to allow progress report of the feedback

.. warning::

if the feature iterator contains only point geometries, the vertices will be added only without treating them as breaklines
%End

QgsMesh triangulatedMesh() const;
%Docstring
Returns the triangulated mesh
%End

void setCrs( const QgsCoordinateReferenceSystem &crs );
%Docstring
Sets the coordinate reference system used for the triangulation
%End

private:
QgsMeshTriangulation( const QgsMeshTriangulation &rhs );
};


class QgsMeshZValueDatasetGroup: QgsMeshDatasetGroup
{
%Docstring

Convenient class that can be used to obtain a datasetgroup on vertices that represents the Z value of the mesh vertices

.. versionadded:: 3.16
%End

%TypeHeaderCode
#include "qgsmeshtriangulation.h"
%End
public:

QgsMeshZValueDatasetGroup( const QString &datasetGroupName, const QgsMesh &mesh );
%Docstring
Constructor

:param datasetGroupName: the name of the dataset group
:param mesh: the mesh used to create the Z value dataset
%End

virtual void initialize();

virtual QgsMeshDatasetMetadata datasetMetadata( int datasetIndex ) const;

virtual int datasetCount() const;

virtual QgsMeshDataset *dataset( int index ) const;

virtual QgsMeshDatasetGroup::Type type() const;
virtual QDomElement writeXml( QDomDocument &doc, const QgsReadWriteContext &context ) const;


private:
QgsMeshZValueDatasetGroup( const QgsMeshZValueDatasetGroup &rhs );
};

/************************************************************************
* This file has been generated automatically from *
* *
* src/analysis/mesh/qgsmeshtriangulation.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/
@@ -164,6 +164,16 @@ Adds datasets to the mesh from file with ``path``. Use the the time ``defaultRef
.. versionadded:: 3.14
%End

bool addDatasets( QgsMeshDatasetGroup *datasetGroup /Transfer/ );
%Docstring
Adds extra datasets to the mesh. Take ownership.

:param datasetGroup: the extra dataset group

:return: whether the dataset is effectively added

.. versionadded:: 3.16
%End

bool saveDataset( const QString &path, int datasetGroupIndex, QString driver );
%Docstring
@@ -299,6 +299,8 @@ their acceptable ranges, defaults, etc.
sipType = sipType_QgsProcessingParameterDatabaseTable;
else if ( sipCpp->type() == QgsProcessingParameterFieldMapping::typeName() )
sipType = sipType_QgsProcessingParameterFieldMapping;
else if ( sipCpp->type() == QgsProcessingParameterTinInputLayers::typeName() )
sipType = sipType_QgsProcessingParameterTinInputLayers;
else
sipType = nullptr;
%End
@@ -0,0 +1,100 @@
/************************************************************************
* This file has been generated automatically from *
* *
* src/core/processing/qgsprocessingparametertininputlayers.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/



class QgsProcessingParameterTinInputLayers: QgsProcessingParameterDefinition
{
%Docstring
A parameter for processing algorithms that need a list of input vector layers to construct a TIN
A valid value for this parameter is a list (QVariantList), where each item is a map (QVariantMap) in this form:
{
'source': string that represents identification of the vector layer,
'type': how the vector layer is used : as vertices, structure lines or break lines
'attributeIndex' : the index of the attribute of the vector layer used to defined the Z value of vertices,
if -1, the Z coordinates of features are used
}

.. versionadded:: 3.16
%End

%TypeHeaderCode
#include "qgsprocessingparametertininputlayers.h"
%End
public:

enum Type
{
Vertices,
StructureLines,
BreakLines
};

struct InputLayer
{
QString source; //!The source of the input layer
Type type; //!The type of the input layer (see Type)
int attributeIndex; //! The attribute index used for Z value of vertices
};

QgsProcessingParameterTinInputLayers( const QString &name, const QString &description = QString() );
%Docstring
Constructor
%End

virtual QgsProcessingParameterDefinition *clone() const;

virtual QString type() const;

virtual bool checkValueIsAcceptable( const QVariant &input, QgsProcessingContext *context = 0 ) const;

virtual QString valueAsPythonString( const QVariant &value, QgsProcessingContext &context ) const;

virtual QString asPythonString( QgsProcessing::PythonOutputType outputType = QgsProcessing::PythonQgsProcessingAlgorithmSubclass ) const;


static QString typeName();
%Docstring
Returns the type name for the parameter class.
%End
};

class QgsProcessingParameterTypeTinInputLayers : QgsProcessingParameterType
{
%Docstring
Parameter type definition for QgsProcessingParameterTinInputLayers.

.. versionadded:: 3.16
%End

%TypeHeaderCode
#include "qgsprocessingparametertininputlayers.h"
%End
public:
virtual QgsProcessingParameterDefinition *create( const QString &name ) const /Factory/;

virtual QString description() const;

virtual QString name() const;

virtual QString id() const;

virtual QString pythonImportString() const;

virtual QString className() const;

virtual QStringList acceptedPythonTypes() const;
};

/************************************************************************
* This file has been generated automatically from *
* *
* src/core/processing/qgsprocessingparametertininputlayers.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/
@@ -34,6 +34,7 @@ Holds metadata about mesh driver
CanWriteFaceDatasets,
CanWriteVertexDatasets,
CanWriteEdgeDatasets,
CanWriteMeshData,
};

typedef QFlags<QgsMeshDriverMetadata::MeshDriverCapability> MeshDriverCapabilities;
@@ -225,6 +226,17 @@ eg. "yes" value will be returned as true, 0 will be returned as false
Creates a new instance of the raster data provider.

.. versionadded:: 3.10
%End

virtual bool createMeshData(
const QgsMesh &mesh,
const QString uri,
const QString &driverName,
const QgsCoordinateReferenceSystem &crs ) const;
%Docstring
Creates mesh data source, that is the mesh frame stored in file, memory or with other way (depending of the provider)

.. versionadded:: 3.16
%End

virtual QList<QPair<QString, QString> > pyramidResamplingMethods();
@@ -469,6 +469,7 @@
%Include auto_generated/processing/qgsprocessingparameteraggregate.sip
%Include auto_generated/processing/qgsprocessingparameterfieldmap.sip
%Include auto_generated/processing/qgsprocessingparameters.sip
%Include auto_generated/processing/qgsprocessingparametertininputlayers.sip
%Include auto_generated/processing/qgsprocessingparametertype.sip
%Include auto_generated/processing/qgsprocessingparametervectortilewriterlayers.sip
%Include auto_generated/processing/qgsprocessingprovider.sip
@@ -83,7 +83,7 @@ def handleAlgorithmResults(alg, context, feedback=None, showResults=True, parame
if style is None:
if layer.type() == QgsMapLayerType.RasterLayer:
style = ProcessingConfig.getSetting(ProcessingConfig.RASTER_STYLE)
else:
elif layer.type() == QgsMapLayerType.VectorLayer:
if layer.geometryType() == QgsWkbTypes.PointGeometry:
style = ProcessingConfig.getSetting(ProcessingConfig.VECTOR_POINT_STYLE)
elif layer.geometryType() == QgsWkbTypes.LineGeometry:
@@ -186,6 +186,7 @@ SET(QGIS_ANALYSIS_SRCS
processing/qgsalgorithmsumlinelength.cpp
processing/qgsalgorithmsymmetricaldifference.cpp
processing/qgsalgorithmtaperedbuffer.cpp
processing/qgsalgorithmtinmeshcreation.cpp
processing/qgsalgorithmtransect.cpp
processing/qgsalgorithmtransform.cpp
processing/qgsalgorithmtranslate.cpp
@@ -228,6 +229,7 @@ SET(QGIS_ANALYSIS_SRCS
vector/qgszonalstatistics.cpp

mesh/qgsmeshcontours.cpp
mesh/qgsmeshtriangulation.cpp

network/qgsgraph.cpp
network/qgsgraphbuilder.cpp
@@ -295,6 +297,7 @@ SET(QGIS_ANALYSIS_HDRS
interpolation/qgstininterpolator.h

mesh/qgsmeshcontours.h
mesh/qgsmeshtriangulation.h

network/qgsgraph.h
network/qgsgraphanalyzer.h
@@ -577,12 +577,12 @@ bool NormVecDecorator::saveTriangulation( QgsFeatureSink *sink, QgsFeedback *fee
return mTIN->saveTriangulation( sink, feedback );
}

QgsMesh NormVecDecorator::triangulationToMesh() const
QgsMesh NormVecDecorator::triangulationToMesh( QgsFeedback *feedback ) const
{
if ( !mTIN )
{
return QgsMesh();
}
return mTIN->triangulationToMesh();
return mTIN->triangulationToMesh( feedback );
}

@@ -69,7 +69,7 @@ class ANALYSIS_EXPORT NormVecDecorator: public TriDecorator

bool saveTriangulation( QgsFeatureSink *sink, QgsFeedback *feedback = nullptr ) const override;

QgsMesh triangulationToMesh() const override;
QgsMesh triangulationToMesh( QgsFeedback *feedback = nullptr ) const override;

protected:
//! Is TRUE, if the normals already have been estimated
@@ -266,10 +266,10 @@ int QgsDualEdgeTriangulation::addPoint( const QgsPoint &p )
//edges to modify
int edgeFromVirtualToExtremeSide1 = mHalfEdge[mHalfEdge[closestEdge]->getNext()]->getDual();
int edgeFromVirtualToExtremeSide2 = mHalfEdge[mHalfEdge[mHalfEdge[closestEdge]->getDual()]->getNext()]->getNext();
int edgeFromeExtremeToVirtualSide2 = mHalfEdge[edgeFromVirtualToExtremeSide2]->getDual();
int edgeFromExtremeToVirtualSide2 = mHalfEdge[edgeFromVirtualToExtremeSide2]->getDual();
//insert new edge
int edgeFromExtremeToNewPoint = insertEdge( -10, -10, newPoint, false, false );
int edgeFromNewPointToExtrem = insertEdge( edgeFromExtremeToNewPoint, edgeFromeExtremeToVirtualSide2, extremPoint, false, false );
int edgeFromNewPointToExtrem = insertEdge( edgeFromExtremeToNewPoint, edgeFromExtremeToVirtualSide2, extremPoint, false, false );
int edgeFromNewPointToVirtualSide1 = insertEdge( -10, edgeFromVirtualToExtremeSide1, -1, false, false );
int edgeFromVirtualToNewPointSide1 = insertEdge( edgeFromNewPointToVirtualSide1, -10, newPoint, false, false );
int edgeFromNewPointToVirtualSide2 = insertEdge( -10, edgeFromVirtualToNewPointSide1, -1, false, false );
@@ -282,7 +282,7 @@ int QgsDualEdgeTriangulation::addPoint( const QgsPoint &p )
//modify existing edges
mHalfEdge.at( edgeFromVirtualToExtremeSide1 )->setNext( edgeFromExtremeToNewPoint );
mHalfEdge.at( edgeFromVirtualToExtremeSide2 )->setNext( edgeFromExtremeToOpposite );
mHalfEdge.at( edgeFromeExtremeToVirtualSide2 )->setNext( edgeFromVirtualToNewPointSide2 );
mHalfEdge.at( edgeFromExtremeToVirtualSide2 )->setNext( edgeFromVirtualToNewPointSide2 );

return newPoint;
}
@@ -3167,7 +3167,7 @@ bool QgsDualEdgeTriangulation::saveTriangulation( QgsFeatureSink *sink, QgsFeedb
return !feedback || !feedback->isCanceled();
}

QgsMesh QgsDualEdgeTriangulation::triangulationToMesh() const
QgsMesh QgsDualEdgeTriangulation::triangulationToMesh( QgsFeedback *feedBack ) const
{
QVector<bool> alreadyVisitedEdges( mHalfEdge.count(), false );

@@ -3199,7 +3199,7 @@ QgsMesh QgsDualEdgeTriangulation::triangulationToMesh() const
containVirtualPoint |= currentEdge->getPoint() == -1;
currentEdge = mHalfEdge.at( currentEdge->getNext() );
}
while ( currentEdge != firstEdge && !containVirtualPoint );
while ( currentEdge != firstEdge && !containVirtualPoint && ( !feedBack || !feedBack->isCanceled() ) );
if ( !containVirtualPoint )
mesh.faces.append( face );
}

0 comments on commit 7cbf80f

Please sign in to comment.
You can’t perform that action at this time.