Skip to content

Commit

Permalink
mesh layer expose datasetIndexAtTime() (#37197)
Browse files Browse the repository at this point in the history
mesh layer expose datasetIndexAtTime()
  • Loading branch information
vcloarec committed Jun 15, 2020
1 parent 4fd98e3 commit b5d6159
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 7 deletions.
18 changes: 18 additions & 0 deletions python/core/auto_generated/mesh/qgsmeshlayer.sip.in
Expand Up @@ -280,6 +280,24 @@ Returns the value of 1D mesh dataset defined on edge that are in the search area
outside the mesh layer and in case triangular mesh was not previously used for rendering


.. versionadded:: 3.14
%End


QgsMeshDatasetIndex datasetIndexAtTime( const QgsDateTimeRange &timeRange, int datasetGroupIndex ) const;
%Docstring
Returns dataset index from datasets group depending on the time range.
If the temporal properties is not active, returns invalid dataset index

:param timeRange: the time range

:return: dataset index

.. note::

the returned dataset index depends on the matching method, see setTemporalMatchingMethod()


.. versionadded:: 3.14
%End

Expand Down
14 changes: 9 additions & 5 deletions src/3d/mesh/qgsmesh3dgeometry_p.cpp
Expand Up @@ -410,11 +410,15 @@ int QgsMeshDataset3dGeometry::extractDataset( QVector<double> &verticalMagnitude

//extract the scalar dataset used to render vertical magnitude of geometry
//define the vertical magnitude datasetIndex
int verticalDataSetIndexNumber = 0;
verticalDataSetIndexNumber = scalarDatasetIndex.dataset();
verticalDataSetIndexNumber = std::min( verticalDataSetIndexNumber, layer->dataProvider()->datasetCount( mVerticalGroupDatasetIndex ) - 1 );
QgsMeshDatasetIndex verticalMagDatasetIndex( mVerticalGroupDatasetIndex, verticalDataSetIndexNumber );

QgsMeshDatasetIndex verticalMagDatasetIndex;
verticalMagDatasetIndex = layer->datasetIndexAtTime( mTimeRange, mVerticalGroupDatasetIndex );
if ( !verticalMagDatasetIndex.isValid() )
{
//if invalid (for example, static mode) use the scalar dataset index
int vertDataSetIndex = scalarDatasetIndex.dataset();
vertDataSetIndex = std::min( vertDataSetIndex, layer->dataProvider()->datasetCount( mVerticalGroupDatasetIndex ) - 1 );
verticalMagDatasetIndex = QgsMeshDatasetIndex( vertDataSetIndex, mVerticalGroupDatasetIndex );
}
//define the active face for vertical magnitude, the inactive faces will not be rendered
// The active face flag values are defined based on the vertival magnitude dataset
activeFaceFlagValues = layer->dataProvider()->areFacesActive( verticalMagDatasetIndex, 0, nativeMesh.faces.count() );
Expand Down
3 changes: 3 additions & 0 deletions src/core/mesh/qgsmeshlayer.cpp
Expand Up @@ -428,6 +428,9 @@ void QgsMeshLayer::setTransformContext( const QgsCoordinateTransformContext &tra

QgsMeshDatasetIndex QgsMeshLayer::datasetIndexAtTime( const QgsDateTimeRange &timeRange, int datasetGroupIndex ) const
{
if ( ! mTemporalProperties->isActive() )
return QgsMeshDatasetIndex( datasetGroupIndex, -1 );

const QDateTime layerReferenceTime = mTemporalProperties->referenceTime();
qint64 startTime = layerReferenceTime.msecsTo( timeRange.begin() );

Expand Down
16 changes: 14 additions & 2 deletions src/core/mesh/qgsmeshlayer.h
Expand Up @@ -326,6 +326,20 @@ class CORE_EXPORT QgsMeshLayer : public QgsMapLayer
*/
QgsMeshDatasetValue dataset1dValue( const QgsMeshDatasetIndex &index, const QgsPointXY &point, double searchRadius ) const;


/**
* Returns dataset index from datasets group depending on the time range.
* If the temporal properties is not active, returns invalid dataset index
*
* \param timeRange the time range
* \returns dataset index
*
* \note the returned dataset index depends on the matching method, see setTemporalMatchingMethod()
*
* \since QGIS 3.14
*/
QgsMeshDatasetIndex datasetIndexAtTime( const QgsDateTimeRange &timeRange, int datasetGroupIndex ) const;

/**
* Returns dataset index from active scalar group depending on the time range.
* If the temporal properties is not active, return the static dataset
Expand Down Expand Up @@ -522,8 +536,6 @@ class CORE_EXPORT QgsMeshLayer : public QgsMapLayer

bool hasSimplifiedMeshes() const;

QgsMeshDatasetIndex datasetIndexAtTime( const QgsDateTimeRange &timeRange, int datasetGroupIndex ) const;

//! Changes scalar settings for classified scalar value (information about is in the metadata
void applyClassificationOnScalarSettings( const QgsMeshDatasetGroupMetadata &meta, QgsMeshRendererScalarSettings &scalarSettings ) const;

Expand Down

0 comments on commit b5d6159

Please sign in to comment.