QGIS API Documentation  3.14.0-Pi (9f7028fd23)
qgsmeshlayerutils.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsmeshlayerutils.h
3  --------------------------
4  begin : August 2018
5  copyright : (C) 2018 by Martin Dobias
6  email : wonder dot sk at gmail dot com
7  ***************************************************************************/
8 
9 /***************************************************************************
10  * *
11  * This program is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU General Public License as published by *
13  * the Free Software Foundation; either version 2 of the License, or *
14  * (at your option) any later version. *
15  * *
16  ***************************************************************************/
17 
18 #ifndef QGSMESHLAYERUTILS_H
19 #define QGSMESHLAYERUTILS_H
20 
21 #define SIP_NO_FILE
22 
23 #include "qgis_core.h"
24 #include "qgsrectangle.h"
25 #include "qgsmaptopixel.h"
26 #include "qgsmeshdataprovider.h"
28 
29 #include <QVector>
30 #include <QSize>
31 
33 
35 class QgsTriangularMesh;
36 class QgsMeshDataBlock;
39 class QgsMeshLayer;
40 
48 class CORE_EXPORT QgsMeshLayerUtils
49 {
50  public:
51 
60  static int datasetValuesCount( const QgsMesh *mesh, QgsMeshDatasetGroupMetadata::DataType dataType );
61 
69 
79  static QgsMeshDataBlock datasetValues(
80  const QgsMeshLayer *meshLayer,
81  QgsMeshDatasetIndex index,
82  int valueIndex,
83  int count );
84 
98  static QVector<QgsVector> griddedVectorValues(
99  const QgsMeshLayer *meshLayer,
100  const QgsMeshDatasetIndex index,
101  double xSpacing,
102  double ySpacing,
103  const QSize &size,
104  const QgsPointXY &minCorner );
105 
111  static QVector<double> calculateMagnitudes( const QgsMeshDataBlock &block );
112 
123  static void boundingBoxToScreenRectangle(
124  const QgsMapToPixel &mtp,
125  const QSize &outputSize,
126  const QgsRectangle &bbox,
127  int &leftLim, int &rightLim, int &topLim, int &bottomLim );
128 
135  static double interpolateFromVerticesData(
136  double fraction,
137  double val1, double val2
138  );
139 
146  static QgsMeshDatasetValue interpolateFromVerticesData( double fraction,
147  const QgsMeshDatasetValue &val1, const QgsMeshDatasetValue &val2
148  );
149 
161  static double interpolateFromVerticesData(
162  const QgsPointXY &p1, const QgsPointXY &p2, const QgsPointXY &p3,
163  double val1, double val2, double val3, const QgsPointXY &pt
164  );
165 
179  static QgsVector interpolateVectorFromVerticesData(
180  const QgsPointXY &p1, const QgsPointXY &p2, const QgsPointXY &p3,
181  QgsVector vect1, QgsVector vect2, QgsVector vect3, const QgsPointXY &pt
182  );
183 
193  static double interpolateFromFacesData(
194  const QgsPointXY &p1, const QgsPointXY &p2, const QgsPointXY &p3,
195  double val, const QgsPointXY &pt );
196 
208  static QgsVector interpolateVectorFromFacesData(
209  const QgsPointXY &p1, const QgsPointXY &p2, const QgsPointXY &p3,
210  QgsVector vect, const QgsPointXY &pt );
211 
217  static QVector<double> interpolateFromFacesData(
218  QVector<double> valuesOnFaces,
219  const QgsMesh *nativeMesh,
220  const QgsTriangularMesh *triangularMesh,
221  QgsMeshDataBlock *active,
223  );
224 
230  static QVector<double> resampleFromVerticesToFaces(
231  const QVector<double> valuesOnVertices,
232  const QgsMesh *nativeMesh,
233  const QgsTriangularMesh *triangularMesh,
234  const QgsMeshDataBlock *active,
236  );
237 
248  static QVector<double> calculateMagnitudeOnVertices(
249  const QgsMeshLayer *meshLayer,
250  const QgsMeshDatasetIndex index,
251  QgsMeshDataBlock *activeFaceFlagValues,
253 
261  static QgsRectangle triangleBoundingBox( const QgsPointXY &p1, const QgsPointXY &p2, const QgsPointXY &p3 );
262 
271  static QString formatTime( double hours, const QDateTime &referenceTime, const QgsMeshTimeSettings &settings );
272 
281  static QVector<QVector3D> calculateNormals(
282  const QgsTriangularMesh &triangularMesh,
283  const QVector<double> &verticalMagnitude,
284  bool isRelative );
285 
293  static void createDatasetGroupTreeItems( const QList<QgsMeshDatasetGroupMetadata> &metadataList,
294  QgsMeshDatasetGroupTreeItem *rootItem, int startingIndex )
295  {
296  QMap<QString, QgsMeshDatasetGroupTreeItem *> mNameToItem;
297  for ( int i = 0; i < metadataList.count(); ++i )
298  {
299  int groupIndex = startingIndex + i;
300  const QgsMeshDatasetGroupMetadata meta = metadataList.at( i );
301  const QString name = meta.name();
302  const QStringList subdatasets = name.split( '/' );
303 
304  QString displayName = name;
305  QgsMeshDatasetGroupTreeItem *parent = rootItem;
306 
307  if ( subdatasets.size() == 2 )
308  {
309  auto it = mNameToItem.find( subdatasets[0] );
310  if ( it == mNameToItem.end() )
311  QgsDebugMsg( QStringLiteral( "Unable to find parent group for %1." ).arg( name ) );
312  else
313  {
314  displayName = subdatasets[1];
315  parent = it.value();
316  }
317  }
318  else if ( subdatasets.size() != 1 )
319  QgsDebugMsg( QStringLiteral( "Ignoring too deep child group name %1." ).arg( name ) );
320 
321  QgsMeshDatasetGroupTreeItem *item = new QgsMeshDatasetGroupTreeItem( displayName, meta.isVector(), groupIndex );
322  parent->appendChild( item );
323  if ( mNameToItem.contains( name ) )
324  QgsDebugMsg( QStringLiteral( "Group %1 is not unique" ).arg( displayName ) );
325  mNameToItem[name] = item;
326  }
327  }
328 };
329 
331 
332 #endif // QGSMESHLAYERUTILS_H
QgsMeshTimeSettings
Definition: qgsmeshtimesettings.h:35
qgsrectangle.h
qgsmaptopixel.h
QgsMeshDatasetValue
Definition: qgsmeshdataset.h:76
QgsMeshDatasetGroupTreeItem
Definition: qgsmeshdataset.h:546
QgsMesh
Definition: qgsmeshdataprovider.h:57
QgsDebugMsg
#define QgsDebugMsg(str)
Definition: qgslogger.h:38
QgsRectangle
Definition: qgsrectangle.h:41
QgsMeshRendererScalarSettings::NeighbourAverage
@ NeighbourAverage
Does a simple average of values defined for all surrounding faces/vertices.
Definition: qgsmeshrenderersettings.h:116
QgsMeshDatasetIndex
Definition: qgsmeshdataset.h:45
QgsMeshLayer
Definition: qgsmeshlayer.h:94
QgsMeshRendererScalarSettings::DataResamplingMethod
DataResamplingMethod
Resampling of value from dataset.
Definition: qgsmeshrenderersettings.h:105
QgsMeshDatasetGroupMetadata::name
QString name() const
Returns name of the dataset group.
Definition: qgsmeshdataset.cpp:164
QgsMesh3dAveragingMethod
Definition: qgsmesh3daveraging.h:39
QgsPointXY
Definition: qgspointxy.h:43
qgsmeshrenderersettings.h
QgsMeshDatasetGroupMetadata
Definition: qgsmeshdataset.h:348
QgsMapToPixel
Definition: qgsmaptopixel.h:37
QgsMeshDatasetGroupMetadata::DataType
DataType
Location of where data is specified for datasets in the dataset group.
Definition: qgsmeshdataset.h:353
QgsMeshDatasetGroupTreeItem::appendChild
void appendChild(QgsMeshDatasetGroupTreeItem *item)
Appends a item child.
Definition: qgsmeshdataset.cpp:493
QgsVector
Definition: qgsvector.h:29
QgsMeshDataBlock
Definition: qgsmeshdataset.h:134
QgsTriangularMesh
Definition: qgstriangularmesh.h:49
QgsMeshDatasetGroupMetadata::isVector
bool isVector() const
Returns whether dataset group has vector data.
Definition: qgsmeshdataset.cpp:149
qgsmeshdataprovider.h