QGIS API Documentation  3.18.1-Zürich (202f1bf7e5)
qgsmeshdataset.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgsmeshdataset.cpp
3  -----------------------
4  begin : April 2018
5  copyright : (C) 2018 by Peter Petrik
6  email : zilolv 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 #include "qgsmeshdataset.h"
19 #include "qgsrectangle.h"
20 #include "qgis.h"
21 
23  : mGroupIndex( group ), mDatasetIndex( dataset )
24 {}
25 
27 {
28  return mGroupIndex;
29 }
30 
32 {
33  return mDatasetIndex;
34 }
35 
37 {
38  return ( group() > -1 ) && ( dataset() > -1 );
39 }
40 
42 {
43  if ( isValid() && other.isValid() )
44  return other.group() == group() && other.dataset() == dataset();
45  else
46  return isValid() == other.isValid();
47 }
48 
50 {
51  return !( operator==( other ) );
52 }
53 
55  : mX( x ), mY( y )
56 {}
57 
59  : mX( scalar )
60 {}
61 
63 {
64  if ( std::isnan( mY ) )
65  {
66  return mX;
67  }
68  else if ( std::isnan( mX ) )
69  {
70  return std::numeric_limits<double>::quiet_NaN();
71  }
72  else
73  {
74  return std::sqrt( ( mX ) * ( mX ) + ( mY ) * ( mY ) );
75  }
76 }
77 
78 void QgsMeshDatasetValue::set( double scalar )
79 {
80  setX( scalar );
81 }
82 
83 void QgsMeshDatasetValue::setX( double x )
84 {
85  mX = x;
86 }
87 
88 void QgsMeshDatasetValue::setY( double y )
89 {
90  mY = y;
91 }
92 
93 double QgsMeshDatasetValue::x() const
94 {
95  return mX;
96 }
97 
98 double QgsMeshDatasetValue::y() const
99 {
100  return mY;
101 }
102 
104 {
105  bool equal = std::isnan( mX ) == std::isnan( other.x() );
106  equal &= std::isnan( mY ) == std::isnan( other.y() );
107 
108  if ( equal )
109  {
110  if ( std::isnan( mY ) )
111  {
112  equal &= qgsDoubleNear( other.x(), mX, 1E-8 );
113  }
114  else
115  {
116  equal &= qgsDoubleNear( other.x(), mX, 1E-8 );
117  equal &= qgsDoubleNear( other.y(), mY, 1E-8 );
118  }
119  }
120  return equal;
121 }
122 
124  const QString uri,
125  bool isScalar,
126  DataType dataType,
127  double minimum,
128  double maximum,
129  int maximumVerticalLevels,
130  const QDateTime &referenceTime,
131  bool isTemporal,
132  const QMap<QString, QString> &extraOptions )
133  : mName( name )
134  , mUri( uri )
135  , mIsScalar( isScalar )
136  , mDataType( dataType )
137  , mMinimumValue( minimum )
138  , mMaximumValue( maximum )
139  , mExtraOptions( extraOptions )
140  , mMaximumVerticalLevelsCount( maximumVerticalLevels )
141  , mReferenceTime( referenceTime )
142  , mIsTemporal( isTemporal )
143 {
144 }
145 
146 QMap<QString, QString> QgsMeshDatasetGroupMetadata::extraOptions() const
147 {
148  return mExtraOptions;
149 }
150 
152 {
153  return !mIsScalar;
154 }
155 
157 {
158  return mIsScalar;
159 }
160 
162 {
163  return mIsTemporal;
164 }
165 
167 {
168  return mName;
169 }
170 
172 {
173  return mDataType;
174 }
175 
177 {
178  return mMinimumValue;
179 }
180 
182 {
183  return mMaximumValue;
184 }
185 
187 {
188  return mMaximumVerticalLevelsCount;
189 }
190 
192 {
193  return mReferenceTime;
194 }
195 
197 {
198  return mUri;
199 }
200 
202  double time,
203  bool isValid,
204  double minimum,
205  double maximum,
206  int maximumVerticalLevels )
207  : mTime( time )
208  , mIsValid( isValid )
209  , mMinimumValue( minimum )
210  , mMaximumValue( maximum )
211  , mMaximumVerticalLevelsCount( maximumVerticalLevels )
212 {
213 }
214 
216 {
217  return mTime;
218 }
219 
221 {
222  return mIsValid;
223 }
224 
226 {
227  return mMinimumValue;
228 }
229 
231 {
232  return mMaximumValue;
233 }
234 
236 {
237  return mMaximumVerticalLevelsCount;
238 }
239 
241  : mType( ActiveFlagInteger )
242 {
243 }
244 
246  : mType( type ),
247  mSize( count )
248 {
249 }
250 
252 {
253  return mType;
254 }
255 
257 {
258  return mSize;
259 }
260 
262 {
263  return ( count() > 0 ) && ( mIsValid );
264 }
265 
267 {
268  if ( !isValid() )
269  return QgsMeshDatasetValue();
270 
271  Q_ASSERT( mType != ActiveFlagInteger );
272 
273  if ( mType == ScalarDouble )
274  return QgsMeshDatasetValue( mDoubleBuffer[index] );
275 
276  return QgsMeshDatasetValue(
277  mDoubleBuffer[2 * index],
278  mDoubleBuffer[2 * index + 1]
279  );
280 }
281 
282 bool QgsMeshDataBlock::active( int index ) const
283 {
284  if ( !isValid() )
285  return false;
286 
287  Q_ASSERT( mType == ActiveFlagInteger );
288 
289  if ( mIntegerBuffer.empty() )
290  return true;
291  else
292  return bool( mIntegerBuffer[index] );
293 }
294 
295 void QgsMeshDataBlock::setActive( const QVector<int> &vals )
296 {
297  Q_ASSERT( mType == ActiveFlagInteger );
298  Q_ASSERT( vals.size() == count() );
299 
300  mIntegerBuffer = vals;
301  setValid( true );
302 }
303 
304 QVector<int> QgsMeshDataBlock::active() const
305 {
306  Q_ASSERT( mType == ActiveFlagInteger );
307  return mIntegerBuffer;
308 }
309 
310 QVector<double> QgsMeshDataBlock::values() const
311 {
312  Q_ASSERT( mType != ActiveFlagInteger );
313 
314  return mDoubleBuffer;
315 }
316 
317 void QgsMeshDataBlock::setValues( const QVector<double> &vals )
318 {
319  Q_ASSERT( mType != ActiveFlagInteger );
320  Q_ASSERT( mType == ScalarDouble ? vals.size() == count() : vals.size() == 2 * count() );
321 
322  mDoubleBuffer = vals;
323  setValid( true );
324 }
325 
326 void QgsMeshDataBlock::setValid( bool valid )
327 {
328  mIsValid = valid;
329 }
330 
332 
334 
335 QgsMesh3dDataBlock::QgsMesh3dDataBlock( int count, bool isVector )
336  : mSize( count )
337  , mIsVector( isVector )
338 {
339 }
340 
342 {
343  return mIsValid;
344 }
345 
347 {
348  return mIsVector;
349 }
350 
352 {
353  return mSize;
354 }
355 
357 {
358  if ( mFaceToVolumeIndex.empty() )
359  return -1;
360  return mFaceToVolumeIndex[0];
361 }
362 
364 {
365  if ( mFaceToVolumeIndex.empty() || mVerticalLevelsCount.empty() )
366  return -1;
367  const int lastVolumeStartIndex = mFaceToVolumeIndex[mFaceToVolumeIndex.size() - 1];
368  const int volumesCountInLastRow = mVerticalLevelsCount[mVerticalLevelsCount.size() - 1];
369  return lastVolumeStartIndex + volumesCountInLastRow;
370 }
371 
373 {
374  return lastVolumeIndex() - firstVolumeIndex();
375 }
376 
378 {
379  Q_ASSERT( isValid() );
380  return mVerticalLevelsCount;
381 }
382 
383 void QgsMesh3dDataBlock::setFaceToVolumeIndex( const QVector<int> &faceToVolumeIndex )
384 {
385  Q_ASSERT( faceToVolumeIndex.size() == count() );
386  mFaceToVolumeIndex = faceToVolumeIndex;
387 }
388 
389 void QgsMesh3dDataBlock::setVerticalLevelsCount( const QVector<int> &verticalLevelsCount )
390 {
391  Q_ASSERT( verticalLevelsCount.size() == count() );
392  mVerticalLevelsCount = verticalLevelsCount;
393 }
394 
395 QVector<double> QgsMesh3dDataBlock::verticalLevels() const
396 {
397  Q_ASSERT( isValid() );
398  return mVerticalLevels;
399 }
400 
401 void QgsMesh3dDataBlock::setVerticalLevels( const QVector<double> &verticalLevels )
402 {
403  Q_ASSERT( verticalLevels.size() == volumesCount() + count() );
404  mVerticalLevels = verticalLevels;
405 }
406 
408 {
409  Q_ASSERT( isValid() );
410  return mFaceToVolumeIndex;
411 }
412 
413 QVector<double> QgsMesh3dDataBlock::values() const
414 {
415  Q_ASSERT( isValid() );
416  return mDoubleBuffer;
417 }
418 
420 {
421  if ( !isValid() )
422  return QgsMeshDatasetValue();
423 
424  if ( !mIsVector )
425  return QgsMeshDatasetValue( mDoubleBuffer[volumeIndex] );
426 
427  return QgsMeshDatasetValue(
428  mDoubleBuffer[2 * volumeIndex],
429  mDoubleBuffer[2 * volumeIndex + 1]
430  );
431 }
432 
433 void QgsMesh3dDataBlock::setValues( const QVector<double> &doubleBuffer )
434 {
435  Q_ASSERT( doubleBuffer.size() == ( isVector() ? 2 * volumesCount() : volumesCount() ) );
436  mDoubleBuffer = doubleBuffer;
437 }
438 
440 {
441  mIsValid = valid;
442 }
443 
445 
446 QgsMeshDatasetGroupTreeItem::QgsMeshDatasetGroupTreeItem( const QString &defaultName, const QString &sourceName,
447  bool isVector,
448  int index )
449  : mOriginalName( defaultName )
450  , mSourceName( sourceName )
451  , mIsVector( isVector )
452  , mDatasetGroupIndex( index )
453 {
454 }
455 
456 QgsMeshDatasetGroupTreeItem::QgsMeshDatasetGroupTreeItem( const QDomElement &itemElement, const QgsReadWriteContext &context )
457 {
458  Q_UNUSED( context );
459  if ( itemElement.hasAttribute( QStringLiteral( "display-name" ) ) )
460  mUserName = itemElement.attribute( QStringLiteral( "display-name" ), mUserName );
461 
462  if ( itemElement.hasAttribute( QStringLiteral( "original-name" ) ) )
463  mOriginalName = itemElement.attribute( QStringLiteral( "original-name" ), mOriginalName );
464 
465  if ( itemElement.hasAttribute( QStringLiteral( "source-name" ) ) )
466  mSourceName = itemElement.attribute( QStringLiteral( "source-name" ), mSourceName );
467 
468  if ( itemElement.hasAttribute( QStringLiteral( "is-vector" ) ) )
469  mIsVector = itemElement.attribute( QStringLiteral( "is-vector" ) ).toInt();
470 
471  if ( itemElement.hasAttribute( QStringLiteral( "dataset-index" ) ) )
472  mDatasetGroupIndex = itemElement.attribute( QStringLiteral( "dataset-index" ) ).toInt();
473 
474  if ( itemElement.hasAttribute( QStringLiteral( "is-enabled" ) ) )
475  mIsEnabled = itemElement.attribute( QStringLiteral( "is-enabled" ) ).toInt();
476 
477  if ( itemElement.hasAttribute( QStringLiteral( "dataset-group-type" ) ) )
478  mDatasetGroupType = static_cast<QgsMeshDatasetGroup::Type>( itemElement.attribute( QStringLiteral( "dataset-group-type" ) ) .toInt() ) ;
479 
480  if ( itemElement.hasAttribute( QStringLiteral( "description" ) ) )
481  mDescription = itemElement.attribute( QStringLiteral( "description" ) );
482 
483  QDomElement dependOnElement = itemElement.firstChildElement( QStringLiteral( "dependent-on-item" ) );
484  while ( !dependOnElement.isNull() )
485  {
486  if ( dependOnElement.hasAttribute( QStringLiteral( "dataset-index" ) ) )
487  mDatasetGroupDependentOn.append( dependOnElement.attribute( QStringLiteral( "dataset-index" ) ).toInt() );
488  dependOnElement = dependOnElement.nextSiblingElement( QStringLiteral( "dependent-on-item" ) );
489  }
490 
491  QDomElement dependencieElement = itemElement.firstChildElement( QStringLiteral( "dependency-item" ) );
492  while ( !dependencieElement.isNull() )
493  {
494  if ( dependencieElement.hasAttribute( QStringLiteral( "dataset-index" ) ) )
495  mDatasetGroupDependencies.append( dependencieElement.attribute( QStringLiteral( "dataset-index" ) ).toInt() );
496  dependencieElement = dependencieElement.nextSiblingElement( QStringLiteral( "dependency-item" ) );
497  }
498 
499  QDomElement childElement = itemElement.firstChildElement( QStringLiteral( "mesh-dataset-group-tree-item" ) );
500  while ( !childElement.isNull() )
501  {
502  appendChild( new QgsMeshDatasetGroupTreeItem( childElement, context ) );
503  childElement = childElement.nextSiblingElement( QStringLiteral( "mesh-dataset-group-tree-item" ) );
504  }
505 }
506 
508 {
509  // Remove from where this item is linked
510 
511  freeAsDependency();
512  freeFromDependencies();
513  qDeleteAll( mChildren );
514  if ( mParent )
515  {
516  mParent->mDatasetGroupIndexToChild.remove( mDatasetGroupIndex );
517  mParent->mChildren.removeOne( this );
518  }
519 }
520 
522 {
523  QgsMeshDatasetGroupTreeItem *other = new QgsMeshDatasetGroupTreeItem( mOriginalName, mSourceName, mIsVector, mDatasetGroupIndex );
524  *other = *this;
525 
526  other->mChildren.clear();
527  other->mDatasetGroupIndexToChild.clear();
528  if ( !mChildren.empty() )
529  for ( int i = 0; i < mChildren.count(); ++i )
530  other->appendChild( mChildren.at( i )->clone() );
531 
532  return other;
533 }
534 
536 {
537  mChildren.append( item );
538  item->mParent = this;
539  mDatasetGroupIndexToChild[item->datasetGroupIndex()] = item;
540 }
541 
543 {
544  delete item;
545 }
546 
548 {
549  if ( row < mChildren.count() )
550  return mChildren.at( row );
551  else
552  return nullptr;
553 }
554 
556 {
557  if ( mDatasetGroupIndexToChild.empty() )
558  return nullptr;
559 
560  QMap<int, QgsMeshDatasetGroupTreeItem *>::iterator it = mDatasetGroupIndexToChild.find( index );
561 
562  if ( it != mDatasetGroupIndexToChild.end() )
563  return it.value();
564  else
565  {
566  QgsMeshDatasetGroupTreeItem *item = nullptr;
567  for ( int i = 0; i < mChildren.count(); ++i )
568  {
569  item = mChildren.at( i )->childFromDatasetGroupIndex( index );
570  if ( item )
571  break;
572  }
573  return item;
574  }
575 }
576 
578 {
579  return mChildren.count();
580 }
581 
583 {
584  int count = 0;
585  for ( int i = 0; i < mChildren.count(); ++i )
586  {
587  count++;
588  count += mChildren.at( i )->totalChildCount();
589  }
590  return count;
591 }
592 
594 {
595  QList<int> indexesList;
596 
597  for ( int i = 0; i < mChildren.count(); ++i )
598  {
599  if ( mChildren.at( i )->isEnabled() )
600  indexesList.append( mChildren.at( i )->datasetGroupIndex() );
601  indexesList.append( mChildren.at( i )->enabledDatasetGroupIndexes() );
602  }
603 
604  return indexesList;
605 }
606 
608 {
609  return mParent;
610 }
611 
613 {
614  if ( mParent )
615  return mParent->mChildren.indexOf( const_cast<QgsMeshDatasetGroupTreeItem *>( this ) );
616 
617  return 0;
618 }
619 
621 {
622  if ( mUserName.isEmpty() )
623  return mOriginalName;
624  else
625  return mUserName;
626 }
627 
629 {
630  return mIsVector;
631 }
632 
634 {
635  return mDatasetGroupIndex;
636 }
637 
639 {
640  return mIsEnabled;
641 }
642 
644 {
645  mIsEnabled = enabled;
646 }
647 
649 {
650  return mOriginalName;
651 }
652 
654 {
655  return mDatasetGroupType;
656 }
657 
659 {
660  return mDescription;
661 }
662 
664 {
665  if ( datasetGroup )
666  {
667  mDescription = datasetGroup->description();
668  mDatasetGroupType = datasetGroup->type();
669  const QStringList &datasetGroupNames = datasetGroup->datasetGroupNamesDependentOn();
670  for ( const QString &varName : datasetGroupNames )
671  {
672  QgsMeshDatasetGroupTreeItem *varItem = searchItemBySourceName( varName );
673  if ( varItem )
674  {
675  varItem->mDatasetGroupDependencies.append( this->datasetGroupIndex() );
676  mDatasetGroupDependentOn.append( varItem->datasetGroupIndex() );
677  }
678  }
679  }
680 }
681 
683 {
684  mDatasetGroupType = QgsMeshDatasetGroup::Persistent;
685  mDatasetGroupDependentOn.clear();
686  mDescription = uri;
687 }
688 
689 QDomElement QgsMeshDatasetGroupTreeItem::writeXml( QDomDocument &doc, const QgsReadWriteContext &context )
690 {
691  Q_UNUSED( context );
692 
693  QDomElement itemElement = doc.createElement( QStringLiteral( "mesh-dataset-group-tree-item" ) );
694  itemElement.setAttribute( QStringLiteral( "display-name" ), mUserName );
695  itemElement.setAttribute( QStringLiteral( "source-name" ), mSourceName );
696  itemElement.setAttribute( QStringLiteral( "original-name" ), mOriginalName );
697  itemElement.setAttribute( QStringLiteral( "is-vector" ), mIsVector ? true : false );
698  itemElement.setAttribute( QStringLiteral( "dataset-index" ), mDatasetGroupIndex );
699  itemElement.setAttribute( QStringLiteral( "is-enabled" ), mIsEnabled ? true : false );
700  itemElement.setAttribute( QStringLiteral( "dataset-group-type" ), mDatasetGroupType );
701  itemElement.setAttribute( QStringLiteral( "description" ), mDescription );
702 
703  for ( int index : mDatasetGroupDependentOn )
704  {
705  QDomElement dependOnElement = doc.createElement( QStringLiteral( "dependent-on-item" ) );
706  dependOnElement.setAttribute( QStringLiteral( "dataset-index" ), index );
707  itemElement.appendChild( dependOnElement );
708  }
709 
710  for ( int index : mDatasetGroupDependencies )
711  {
712  QDomElement dependencieElement = doc.createElement( QStringLiteral( "dependency-item" ) );
713  dependencieElement.setAttribute( QStringLiteral( "dataset-index" ), index );
714  itemElement.appendChild( dependencieElement );
715  }
716 
717  for ( int i = 0; i < mChildren.count(); ++i )
718  itemElement.appendChild( mChildren.at( i )->writeXml( doc, context ) );
719 
720  return itemElement;
721 }
722 
724 {
725  QList<int> dependencies;
726  QgsMeshDatasetGroupTreeItem *root = rootItem();
727  for ( int index : mDatasetGroupDependencies )
728  {
729  if ( !dependencies.contains( index ) )
730  dependencies.append( index );
732  if ( item )
733  dependencies.append( item->groupIndexDependencies() );
734  }
735 
736  for ( int i = 0; i < childCount(); ++i )
737  {
738  dependencies.append( child( i )->groupIndexDependencies() );
739  }
740 
741  return dependencies;
742 }
743 
744 QgsMeshDatasetGroupTreeItem *QgsMeshDatasetGroupTreeItem::searchItemBySourceName( const QString &sourceName ) const
745 {
746  QgsMeshDatasetGroupTreeItem *baseItem = rootItem();
747 
748  QList<QgsMeshDatasetGroupTreeItem *> itemToCheck;
749  itemToCheck.append( baseItem );
750  while ( baseItem && baseItem->providerName() != sourceName && !itemToCheck.isEmpty() )
751  {
752  for ( int i = 0; i < baseItem->childCount(); ++i )
753  itemToCheck.append( baseItem->child( i ) );
754  itemToCheck.removeOne( baseItem );
755  if ( !itemToCheck.empty() )
756  baseItem = itemToCheck.first();
757  else
758  baseItem = nullptr;
759  }
760 
761  return baseItem;
762 }
763 
764 QgsMeshDatasetGroupTreeItem *QgsMeshDatasetGroupTreeItem::rootItem() const
765 {
766  const QgsMeshDatasetGroupTreeItem *baseItem = this;
767  while ( baseItem->parentItem() != nullptr )
768  baseItem = baseItem->parentItem();
769 
770  return const_cast<QgsMeshDatasetGroupTreeItem *>( baseItem );
771 }
772 
773 void QgsMeshDatasetGroupTreeItem::freeAsDependency()
774 {
775  QgsMeshDatasetGroupTreeItem *root = rootItem();
776  for ( int index : mDatasetGroupDependentOn )
777  {
779  if ( item )
780  item->mDatasetGroupDependencies.removeOne( this->datasetGroupIndex() );
781  }
782 }
783 
784 void QgsMeshDatasetGroupTreeItem::freeFromDependencies()
785 {
786  QgsMeshDatasetGroupTreeItem *root = rootItem();
787  for ( int index : mDatasetGroupDependencies )
788  {
790  if ( item )
791  item->mDatasetGroupDependentOn.removeOne( this->datasetGroupIndex() );
792  }
793 }
794 
796 {
797  return mSourceName;
798 }
799 
800 void QgsMeshDatasetGroupTreeItem::setName( const QString &name )
801 {
802  mUserName = name;
803 }
804 
805 
807 {
808  if ( valueIndex >= 0 && valueIndex < values.count() )
809  return values[valueIndex];
810  else
811  return QgsMeshDatasetValue();
812 }
813 
814 QgsMeshDataBlock QgsMeshMemoryDataset::datasetValues( bool isScalar, int valueIndex, int count ) const
815 {
817  QVector<double> buf( isScalar ? count : 2 * count );
818  for ( int i = 0; i < count; ++i )
819  {
820  int idx = valueIndex + i;
821  if ( ( idx < 0 ) || ( idx >= values.size() ) )
822  return ret;
823 
824  QgsMeshDatasetValue val = values[ valueIndex + i ];
825  if ( isScalar )
826  buf[i] = val.x();
827  else
828  {
829  buf[2 * i] = val.x();
830  buf[2 * i + 1] = val.y();
831  }
832  }
833  ret.setValues( buf );
834  return ret;
835 }
836 
838 {
840  if ( active.isEmpty() ||
841  ( faceIndex < 0 ) ||
842  ( faceIndex + count > active.size() )
843  )
844  ret.setValid( true );
845  else
846  ret.setActive( active );
847  return ret;
848 }
849 
851 {
853 }
854 
856 {
857  double min = std::numeric_limits<double>::max();
858  double max = std::numeric_limits<double>::min();
859 
860  if ( !valid )
861  return;
862 
863 
864  bool firstIteration = true;
865  for ( int i = 0; i < values.size(); ++i )
866  {
867  double v = values[i].scalar();
868 
869  if ( std::isnan( v ) )
870  continue;
871  if ( firstIteration )
872  {
873  firstIteration = false;
874  min = v;
875  max = v;
876  }
877  else
878  {
879  if ( v < min )
880  min = v;
881  if ( v > max )
882  max = v;
883  }
884  }
885 
886  minimum = min;
887  maximum = max;
888 }
889 
890 bool QgsMeshMemoryDataset::isActive( int faceIndex ) const
891 {
892  if ( active.isEmpty() || faceIndex >= active.count() )
893  return true;
894  else
895  return active.at( faceIndex );
896 }
897 
899 {
900  return values.count();
901 }
902 
904  QgsMeshDatasetGroup( name, dataType )
905 {
906 }
907 
909  QgsMeshDatasetGroup( name )
910 {
911 }
912 
914 {
916  name(),
917  QString(),
918  isScalar(),
919  dataType(),
920  minimum(),
921  maximum(),
922  0,
923  mReferenceTime,
924  datasetCount() > 1,
925  extraMetadata()
926  );
927 }
928 
930 {
931  return memoryDatasets.size();
932 }
933 
935 {
936  if ( datasetIndex >= 0 && datasetIndex < memoryDatasets.count() )
937  return memoryDatasets[datasetIndex]->metadata();
938  else
939  return QgsMeshDatasetMetadata();
940 }
941 
943 {
944  return memoryDatasets[index].get();
945 }
946 
947 void QgsMeshMemoryDatasetGroup::addDataset( std::shared_ptr<QgsMeshMemoryDataset> dataset )
948 {
949  dataset->calculateMinMax();
950  memoryDatasets.push_back( dataset );
951 }
952 
954 {
955  memoryDatasets.clear();
956 }
957 
959 {
961 }
962 
963 std::shared_ptr<const QgsMeshMemoryDataset> QgsMeshMemoryDatasetGroup::constDataset( int index ) const
964 {
965  return memoryDatasets[index];
966 }
967 
968 QDomElement QgsMeshMemoryDatasetGroup::writeXml( QDomDocument &doc, const QgsReadWriteContext &context ) const
969 {
970  Q_UNUSED( doc )
971  Q_UNUSED( context )
972  return QDomElement();
973 }
974 
976 {
977  double min = std::numeric_limits<double>::max();
978  double max = std::numeric_limits<double>::min();
979 
980  int count = datasetCount();
981  for ( int i = 0; i < count; ++i )
982  {
983  min = std::min( min, datasetMetadata( i ).minimum() );
984  max = std::max( max, datasetMetadata( i ).maximum() );
985  }
986  mMinimum = min;
987  mMaximum = max;
988 }
989 
991 {
992  return QStringList();
993 }
994 
996 {
997  return QString();
998 }
999 
1000 void QgsMeshDatasetGroup::setReferenceTime( const QDateTime &referenceTime )
1001 {
1002  mReferenceTime = referenceTime;
1003 }
1004 
1006 {
1007  for ( int i = 0; i < datasetCount(); ++i )
1008  if ( dataset( i )->valuesCount() != count )
1009  return false;
1010  return true;
1011 }
1012 
1013 QgsMeshDatasetGroup::QgsMeshDatasetGroup( const QString &name, QgsMeshDatasetGroupMetadata::DataType dataType ): mName( name ), mDataType( dataType ) {}
1014 
1016 
1017 QgsMeshDatasetGroup::QgsMeshDatasetGroup( const QString &name ): mName( name ) {}
1018 
1020 {
1021  return mMinimum;
1022 }
1023 
1025 {
1026  return mMaximum;
1027 }
1028 
1029 void QgsMeshDatasetGroup::setMinimumMaximum( double min, double max )
1030 {
1031  mMinimum = min;
1032  mMaximum = max;
1033 }
1034 
1036 {
1037  return mName;
1038 }
1039 
1040 void QgsMeshDatasetGroup::setName( const QString &name )
1041 {
1042  mName = name;
1043 }
1044 
1046 {
1047  return mDataType;
1048 }
1049 
1051 {
1052  mDataType = type;
1053 }
1054 
1055 void QgsMeshDatasetGroup::addExtraMetadata( QString key, QString value )
1056 {
1057  mMetadata.insert( key, value );
1058 }
1059 
1060 QMap<QString, QString> QgsMeshDatasetGroup::extraMetadata() const
1061 {
1062  return mMetadata;
1063 }
1064 
1066 {
1067  return mIsScalar;
1068 }
1069 
1071 {
1072  mIsScalar = isScalar;
1073 }
void setVerticalLevelsCount(const QVector< int > &verticalLevelsCount)
Sets the vertical level counts.
void setValid(bool valid)
Sets block validity.
QgsMesh3dDataBlock()
Constructs an invalid block.
int lastVolumeIndex() const
Index of the last volume stored in the buffer (absolute)
QVector< int > faceToVolumeIndex() const
Returns the indexing between faces and volumes.
bool isValid() const
Whether the block is valid.
int firstVolumeIndex() const
Index of the first volume stored in the buffer (absolute)
int volumesCount() const
Returns number of volumes stored in the buffer.
bool isVector() const
Whether we store vector values.
QVector< int > verticalLevelsCount() const
Returns number of vertical level above 2d faces.
int count() const
Number of 2d faces for which the volume data is stored in the block.
QVector< double > verticalLevels() const
Returns the vertical levels height.
void setFaceToVolumeIndex(const QVector< int > &faceToVolumeIndex)
Sets the indexing between faces and volumes.
QVector< double > values() const
Returns the values at volume centers.
void setVerticalLevels(const QVector< double > &verticalLevels)
Sets the vertical levels height.
void setValues(const QVector< double > &doubleBuffer)
Sets the values at volume centers.
QgsMeshDatasetValue value(int volumeIndex) const
Returns the value at volume centers.
QgsMeshDataBlock is a block of integers/doubles that can be used to retrieve: active flags (e....
QgsMeshDatasetValue value(int index) const
Returns a value represented by the index For active flag the behavior is undefined.
QVector< double > values() const
Returns buffer to the array with values For vector it is pairs (x1, y1, x2, y2, .....
void setActive(const QVector< int > &vals)
Sets active flag values.
QVector< int > active() const
Returns active flag array.
bool isValid() const
Whether the block is valid.
QgsMeshDataBlock()
Constructs an invalid block.
DataType type() const
Type of data stored in the block.
DataType
Type of data stored in the block.
@ ScalarDouble
Scalar double values.
@ Vector2DDouble
Vector double pairs (x1, y1, x2, y2, ... )
@ ActiveFlagInteger
Integer boolean flag whether face is active.
int count() const
Number of items stored in the block.
void setValues(const QVector< double > &vals)
Sets values.
void setValid(bool valid)
Sets block validity.
QgsMeshDatasetGroupMetadata is a collection of dataset group metadata such as whether the data is vec...
bool isTemporal() const
Returns whether the dataset group is temporal (contains time-related dataset)
QMap< QString, QString > extraOptions() const
Returns extra metadata options, for example description.
bool isVector() const
Returns whether dataset group has vector data.
QString name() const
Returns name of the dataset group.
bool isScalar() const
Returns whether dataset group has scalar data.
int maximumVerticalLevelsCount() const
Returns maximum number of vertical levels for 3d stacked meshes.
QgsMeshDatasetGroupMetadata()=default
Constructs an empty metadata object.
DataType dataType() const
Returns whether dataset group data is defined on vertices or faces or volumes.
QDateTime referenceTime() const
Returns the reference time.
double minimum() const
Returns minimum scalar value/vector magnitude present for whole dataset group.
double maximum() const
Returns maximum scalar value/vector magnitude present for whole dataset group.
DataType
Location of where data is specified for datasets in the dataset group.
QString uri() const
Returns the uri of the source.
Tree item for display of the mesh dataset groups.
void setName(const QString &name)
Overrides the default name with the name to display.
QgsMeshDatasetGroupTreeItem * clone() const
Clones the item.
QList< int > groupIndexDependencies() const
Returns a list of group index corresponding to dataset group that depends on the dataset group repres...
QDomElement writeXml(QDomDocument &doc, const QgsReadWriteContext &context)
Writes the item and its children in a DOM document.
void setPersistentDatasetGroup(const QString &uri)
Set parameters of the item in accordance with the persistent dataset group with uri.
int childCount() const
Returns the count of children.
~QgsMeshDatasetGroupTreeItem()
Destructor, destructs also the children.
QgsMeshDatasetGroupTreeItem * parentItem() const
Returns the parent item, nullptr if it is root item.
QgsMeshDatasetGroupTreeItem * childFromDatasetGroupIndex(int index)
Returns the child with dataset group index Searches as depper as needed on the child hierarchy.
void removeChild(QgsMeshDatasetGroupTreeItem *item)
Removes a item child if exists.
void setIsEnabled(bool isEnabled)
Sets whether the item is enabled, that is if it is displayed in view.
int totalChildCount() const
Returns the total count of children, that is included deeper children and disabled items.
void setDatasetGroup(QgsMeshDatasetGroup *datasetGroup)
Set parameters of the item in accordance with the dataset group.
QList< int > enabledDatasetGroupIndexes() const
Returns a list of enabled dataset group indexes, included deeper children.
QgsMeshDatasetGroupTreeItem()
Constructor for an empty dataset group tree item.
QString providerName() const
Returns the name used by the provider to identify the dataset.
void appendChild(QgsMeshDatasetGroupTreeItem *item)
Appends a item child.
QgsMeshDatasetGroupTreeItem * child(int row) const
Returns a child.
QString description() const
Returns description about the dataset group (URI, formula,...)
int row() const
Returns the position of the item in the parent.
QString name() const
Returns the name of the item This name is the default name if the name has not been overridden (.
QgsMeshDatasetGroup::Type datasetGroupType() const
Abstract class that represents a dataset group.
bool isScalar() const
Returns whether the group contain scalar values.
void addExtraMetadata(QString key, QString value)
Adds extra metadata to the group.
bool checkValueCountPerDataset(int count) const
Returns whether all the datasets contain count values.
virtual QgsMeshDatasetMetadata datasetMetadata(int datasetIndex) const =0
Returns the metadata of the dataset with index datasetIndex.
void setIsScalar(bool isScalar)
Sets whether the group contain scalar values.
QgsMeshDatasetGroup()=default
Default constructor.
void setDataType(const QgsMeshDatasetGroupMetadata::DataType &dataType)
Sets the data type of the dataset group.
QString name() const
Returns the name of the dataset group.
virtual QgsMeshDataset * dataset(int index) const =0
Returns the dataset with index.
QgsMeshDatasetGroupMetadata::DataType dataType() const
Returns the data type of the dataset group.
virtual ~QgsMeshDatasetGroup()
virtual QStringList datasetGroupNamesDependentOn() const
Returns the dataset group variable name which this dataset group depends on.
virtual QString description() const
Returns some information about the dataset group.
QMap< QString, QString > mMetadata
void calculateStatistic()
Calculates the statistics (minimum and maximum)
Type
Type of the dataset group.
@ Persistent
Generic type used for non typed dataset group.
void setReferenceTime(const QDateTime &referenceTime)
Sets the reference time of the dataset group.
double maximum() const
Returns the maximum value of the whole dataset group.
virtual QgsMeshDatasetGroup::Type type() const =0
Returns the type of dataset group.
void setMinimumMaximum(double min, double max)
Overrides the minimum and the maximum value of the whole dataset group.
QgsMeshDatasetGroupMetadata groupMetadata() const
Returns the metadata of the dataset group.
double minimum() const
Returns the minimum value of the whole dataset group.
QMap< QString, QString > extraMetadata() const
Returns all the extra metadata of the group.
void setName(const QString &name)
Sets the name of the dataset group.
virtual int datasetCount() const =0
Returns the count of datasets in the group.
QgsMeshDatasetGroupMetadata::DataType mDataType
QgsMeshDatasetIndex is index that identifies the dataset group (e.g.
QgsMeshDatasetIndex(int group=-1, int dataset=-1)
Creates an index. -1 represents invalid group/dataset.
bool operator==(QgsMeshDatasetIndex other) const
Equality operator.
bool operator!=(QgsMeshDatasetIndex other) const
Inequality operator.
bool isValid() const
Returns whether index is valid, ie at least groups is set.
int group() const
Returns a group index.
int dataset() const
Returns a dataset index within group()
QgsMeshDatasetMetadata is a collection of mesh dataset metadata such as whether the data is valid or ...
double maximum() const
Returns maximum scalar value/vector magnitude present for the dataset.
int maximumVerticalLevelsCount() const
Returns maximum number of vertical levels for 3d stacked meshes.
double minimum() const
Returns minimum scalar value/vector magnitude present for the dataset.
double time() const
Returns the time value for this dataset.
bool isValid() const
Returns whether dataset is valid.
QgsMeshDatasetMetadata()=default
Constructs an empty metadata object.
QgsMeshDatasetValue represents single dataset value.
void setY(double y)
Sets Y value.
void set(double scalar)
Sets scalar value.
double y() const
Returns y value.
bool operator==(QgsMeshDatasetValue other) const
QgsMeshDatasetValue()=default
Default Ctor, initialize to NaN.
double scalar() const
Returns magnitude of vector for vector data or scalar value for scalar data.
double x() const
Returns x value.
void setX(double x)
Sets X value.
Abstract class that represents a dataset.
virtual int valuesCount() const =0
Returns the values count.
void addDataset(std::shared_ptr< QgsMeshMemoryDataset > dataset)
Adds a memory dataset to the group.
QgsMeshMemoryDatasetGroup()=default
Constructor.
QgsMeshDatasetMetadata datasetMetadata(int datasetIndex) const override
Returns the metadata of the dataset with index datasetIndex.
void clearDatasets()
Removes all the datasets from the group.
void initialize() override
Initialize the dataset group.
std::shared_ptr< const QgsMeshMemoryDataset > constDataset(int index) const
Returns the dataset with index.
QVector< std::shared_ptr< QgsMeshMemoryDataset > > memoryDatasets
Contains all the memory datasets.
QDomElement writeXml(QDomDocument &doc, const QgsReadWriteContext &context) const override
Returns a invalid DOM element.
QgsMeshDataset * dataset(int index) const override
Returns the dataset with index.
int datasetCount() const override
Returns the count of datasets in the group.
QgsMeshDataBlock areFacesActive(int faceIndex, int count) const override
Returns whether faces are active.
bool isActive(int faceIndex) const override
Returns whether the face is active.
QVector< QgsMeshDatasetValue > values
QgsMeshDatasetValue datasetValue(int valueIndex) const override
Returns the value with index valueIndex.
QgsMeshDatasetMetadata metadata() const override
Returns the metadata of the dataset.
QgsMeshDataBlock datasetValues(bool isScalar, int valueIndex, int count) const override
Returns count values from valueIndex.
int valuesCount() const override
Returns the values count.
QVector< int > active
void calculateMinMax()
Calculates the minimum and the maximum of this group.
The class is used as a container of context for various read/write operations on other objects.
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference)
Definition: qgis.h:316