Skip to content

Commit

Permalink
Merge pull request #38309 from vcloarec/TINMeshCreaton
Browse files Browse the repository at this point in the history
TIN Mesh creation
  • Loading branch information
wonder-sk committed Sep 11, 2020
2 parents 5941261 + 89e4d49 commit 7cbf80f
Show file tree
Hide file tree
Showing 40 changed files with 2,203 additions and 23 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions python/analysis/analysis_auto.sip
Expand Up @@ -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
Expand Down
120 changes: 120 additions & 0 deletions python/analysis/auto_generated/mesh/qgsmeshtriangulation.sip.in
@@ -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 *
************************************************************************/
10 changes: 10 additions & 0 deletions python/core/auto_generated/mesh/qgsmeshlayer.sip.in
Expand Up @@ -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
Expand Down
Expand Up @@ -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
Expand Down
@@ -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 *
************************************************************************/
12 changes: 12 additions & 0 deletions python/core/auto_generated/qgsprovidermetadata.sip.in
Expand Up @@ -34,6 +34,7 @@ Holds metadata about mesh driver
CanWriteFaceDatasets,
CanWriteVertexDatasets,
CanWriteEdgeDatasets,
CanWriteMeshData,
};

typedef QFlags<QgsMeshDriverMetadata::MeshDriverCapability> MeshDriverCapabilities;
Expand Down Expand Up @@ -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();
Expand Down
1 change: 1 addition & 0 deletions python/core/core_auto.sip
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion python/plugins/processing/gui/Postprocessing.py
Expand Up @@ -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:
Expand Down
3 changes: 3 additions & 0 deletions src/analysis/CMakeLists.txt
Expand Up @@ -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
Expand Down Expand Up @@ -228,6 +229,7 @@ SET(QGIS_ANALYSIS_SRCS
vector/qgszonalstatistics.cpp

mesh/qgsmeshcontours.cpp
mesh/qgsmeshtriangulation.cpp

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

mesh/qgsmeshcontours.h
mesh/qgsmeshtriangulation.h

network/qgsgraph.h
network/qgsgraphanalyzer.h
Expand Down
4 changes: 2 additions & 2 deletions src/analysis/interpolation/NormVecDecorator.cpp
Expand Up @@ -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 );
}

2 changes: 1 addition & 1 deletion src/analysis/interpolation/NormVecDecorator.h
Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions src/analysis/interpolation/qgsdualedgetriangulation.cpp
Expand Up @@ -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 );
Expand All @@ -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;
}
Expand Down Expand Up @@ -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 );

Expand Down Expand Up @@ -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 );
}
Expand Down

0 comments on commit 7cbf80f

Please sign in to comment.