23 : mGroupIndex( group ), mDatasetIndex( dataset )
64 if ( std::isnan( mY ) )
68 else if ( std::isnan( mX ) )
70 return std::numeric_limits<double>::quiet_NaN();
74 return std::sqrt( ( mX ) * ( mX ) + ( mY ) * ( mY ) );
105 bool equal = std::isnan( mX ) == std::isnan( other.
x() );
106 equal &= std::isnan( mY ) == std::isnan( other.
y() );
110 if ( std::isnan( mY ) )
129 int maximumVerticalLevels,
130 const QDateTime &referenceTime,
132 const QMap<QString, QString> &extraOptions )
135 , mIsScalar( isScalar )
136 , mDataType( dataType )
137 , mMinimumValue( minimum )
138 , mMaximumValue( maximum )
139 , mExtraOptions( extraOptions )
140 , mMaximumVerticalLevelsCount( maximumVerticalLevels )
141 , mReferenceTime( referenceTime )
142 , mIsTemporal( isTemporal )
148 return mExtraOptions;
178 return mMinimumValue;
183 return mMaximumValue;
188 return mMaximumVerticalLevelsCount;
193 return mReferenceTime;
206 int maximumVerticalLevels )
208 , mIsValid( isValid )
209 , mMinimumValue( minimum )
210 , mMaximumValue( maximum )
211 , mMaximumVerticalLevelsCount( maximumVerticalLevels )
227 return mMinimumValue;
232 return mMaximumValue;
237 return mMaximumVerticalLevelsCount;
241 : mType( ActiveFlagInteger )
263 return (
count() > 0 ) && ( mIsValid );
277 mDoubleBuffer[2 * index],
278 mDoubleBuffer[2 * index + 1]
289 if ( mIntegerBuffer.empty() )
292 return bool( mIntegerBuffer[index] );
298 Q_ASSERT( vals.size() ==
count() );
300 mIntegerBuffer = vals;
307 return mIntegerBuffer;
314 return mDoubleBuffer;
322 mDoubleBuffer = vals;
337 , mIsVector( isVector )
358 if ( mFaceToVolumeIndex.empty() )
360 return mFaceToVolumeIndex[0];
365 if ( mFaceToVolumeIndex.empty() || mVerticalLevelsCount.empty() )
367 const int lastVolumeStartIndex = mFaceToVolumeIndex[mFaceToVolumeIndex.size() - 1];
368 const int volumesCountInLastRow = mVerticalLevelsCount[mVerticalLevelsCount.size() - 1];
369 return lastVolumeStartIndex + volumesCountInLastRow;
380 return mVerticalLevelsCount;
398 return mVerticalLevels;
410 return mFaceToVolumeIndex;
416 return mDoubleBuffer;
428 mDoubleBuffer[2 * volumeIndex],
429 mDoubleBuffer[2 * volumeIndex + 1]
436 mDoubleBuffer = doubleBuffer;
449 : mOriginalName( defaultName )
450 , mSourceName( sourceName )
451 , mIsVector( isVector )
452 , mDatasetGroupIndex( index )
459 if ( itemElement.hasAttribute( QStringLiteral(
"display-name" ) ) )
460 mUserName = itemElement.attribute( QStringLiteral(
"display-name" ), mUserName );
462 if ( itemElement.hasAttribute( QStringLiteral(
"original-name" ) ) )
463 mOriginalName = itemElement.attribute( QStringLiteral(
"original-name" ), mOriginalName );
465 if ( itemElement.hasAttribute( QStringLiteral(
"source-name" ) ) )
466 mSourceName = itemElement.attribute( QStringLiteral(
"source-name" ), mSourceName );
468 if ( itemElement.hasAttribute( QStringLiteral(
"is-vector" ) ) )
469 mIsVector = itemElement.attribute( QStringLiteral(
"is-vector" ) ).toInt();
471 if ( itemElement.hasAttribute( QStringLiteral(
"dataset-index" ) ) )
472 mDatasetGroupIndex = itemElement.attribute( QStringLiteral(
"dataset-index" ) ).toInt();
474 if ( itemElement.hasAttribute( QStringLiteral(
"is-enabled" ) ) )
475 mIsEnabled = itemElement.attribute( QStringLiteral(
"is-enabled" ) ).toInt();
477 if ( itemElement.hasAttribute( QStringLiteral(
"dataset-group-type" ) ) )
478 mDatasetGroupType =
static_cast<QgsMeshDatasetGroup::Type>( itemElement.attribute( QStringLiteral(
"dataset-group-type" ) ) .toInt() ) ;
480 if ( itemElement.hasAttribute( QStringLiteral(
"description" ) ) )
481 mDescription = itemElement.attribute( QStringLiteral(
"description" ) );
483 QDomElement dependOnElement = itemElement.firstChildElement( QStringLiteral(
"dependent-on-item" ) );
484 while ( !dependOnElement.isNull() )
486 if ( dependOnElement.hasAttribute( QStringLiteral(
"dataset-index" ) ) )
487 mDatasetGroupDependentOn.append( dependOnElement.attribute( QStringLiteral(
"dataset-index" ) ).toInt() );
488 dependOnElement = dependOnElement.nextSiblingElement( QStringLiteral(
"dependent-on-item" ) );
491 QDomElement dependencieElement = itemElement.firstChildElement( QStringLiteral(
"dependency-item" ) );
492 while ( !dependencieElement.isNull() )
494 if ( dependencieElement.hasAttribute( QStringLiteral(
"dataset-index" ) ) )
495 mDatasetGroupDependencies.append( dependencieElement.attribute( QStringLiteral(
"dataset-index" ) ).toInt() );
496 dependencieElement = dependencieElement.nextSiblingElement( QStringLiteral(
"dependency-item" ) );
499 QDomElement childElement = itemElement.firstChildElement( QStringLiteral(
"mesh-dataset-group-tree-item" ) );
500 while ( !childElement.isNull() )
503 childElement = childElement.nextSiblingElement( QStringLiteral(
"mesh-dataset-group-tree-item" ) );
512 freeFromDependencies();
513 qDeleteAll( mChildren );
516 mParent->mDatasetGroupIndexToChild.remove( mDatasetGroupIndex );
517 mParent->mChildren.removeOne(
this );
526 other->mChildren.clear();
527 other->mDatasetGroupIndexToChild.clear();
528 if ( !mChildren.empty() )
529 for (
int i = 0; i < mChildren.count(); ++i )
537 mChildren.append( item );
538 item->mParent =
this;
549 if (
row < mChildren.count() )
550 return mChildren.at(
row );
557 if ( mDatasetGroupIndexToChild.empty() )
560 QMap<int, QgsMeshDatasetGroupTreeItem *>::iterator it = mDatasetGroupIndexToChild.find( index );
562 if ( it != mDatasetGroupIndexToChild.end() )
567 for (
int i = 0; i < mChildren.count(); ++i )
569 item = mChildren.at( i )->childFromDatasetGroupIndex( index );
579 return mChildren.count();
585 for (
int i = 0; i < mChildren.count(); ++i )
588 count += mChildren.at( i )->totalChildCount();
595 QList<int> indexesList;
597 for (
int i = 0; i < mChildren.count(); ++i )
599 if ( mChildren.at( i )->isEnabled() )
600 indexesList.append( mChildren.at( i )->datasetGroupIndex() );
601 indexesList.append( mChildren.at( i )->enabledDatasetGroupIndexes() );
622 if ( mUserName.isEmpty() )
623 return mOriginalName;
635 return mDatasetGroupIndex;
645 mIsEnabled = enabled;
650 return mOriginalName;
655 return mDatasetGroupType;
668 mDatasetGroupType = datasetGroup->
type();
670 for (
const QString &varName : datasetGroupNames )
685 mDatasetGroupDependentOn.clear();
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 );
703 for (
int index : mDatasetGroupDependentOn )
705 QDomElement dependOnElement = doc.createElement( QStringLiteral(
"dependent-on-item" ) );
706 dependOnElement.setAttribute( QStringLiteral(
"dataset-index" ), index );
707 itemElement.appendChild( dependOnElement );
710 for (
int index : mDatasetGroupDependencies )
712 QDomElement dependencieElement = doc.createElement( QStringLiteral(
"dependency-item" ) );
713 dependencieElement.setAttribute( QStringLiteral(
"dataset-index" ), index );
714 itemElement.appendChild( dependencieElement );
717 for (
int i = 0; i < mChildren.count(); ++i )
718 itemElement.appendChild( mChildren.at( i )->writeXml( doc, context ) );
725 QList<int> dependencies;
727 for (
int index : mDatasetGroupDependencies )
729 if ( !dependencies.contains( index ) )
730 dependencies.append( index );
748 QList<QgsMeshDatasetGroupTreeItem *> itemToCheck;
749 itemToCheck.append( baseItem );
750 while ( baseItem && baseItem->
providerName() != sourceName && !itemToCheck.isEmpty() )
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();
773 void QgsMeshDatasetGroupTreeItem::freeAsDependency()
776 for (
int index : mDatasetGroupDependentOn )
784 void QgsMeshDatasetGroupTreeItem::freeFromDependencies()
787 for (
int index : mDatasetGroupDependencies )
808 if ( valueIndex >= 0 && valueIndex <
values.count() )
809 return values[valueIndex];
817 QVector<double> buf( isScalar ? count : 2 * count );
818 for (
int i = 0; i < count; ++i )
820 int idx = valueIndex + i;
821 if ( ( idx < 0 ) || ( idx >=
values.size() ) )
829 buf[2 * i] = val.
x();
830 buf[2 * i + 1] = val.
y();
842 ( faceIndex + count >
active.size() )
857 double min = std::numeric_limits<double>::max();
858 double max = std::numeric_limits<double>::min();
864 bool firstIteration =
true;
865 for (
int i = 0; i <
values.size(); ++i )
867 double v =
values[i].scalar();
869 if ( std::isnan( v ) )
871 if ( firstIteration )
873 firstIteration =
false;
895 return active.at( faceIndex );
972 return QDomElement();
977 double min = std::numeric_limits<double>::max();
978 double max = std::numeric_limits<double>::min();
981 for (
int i = 0; i < count; ++i )
992 return QStringList();
1002 mReferenceTime = referenceTime;
void setVerticalLevelsCount(const QVector< int > &verticalLevelsCount)
Sets the vertical level counts.
void setValid(bool valid)
Sets block validity.
QgsMesh3dDataBlock()
Constructs an invalid block.
~QgsMesh3dDataBlock()
Dtor.
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.
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...
QString defaultName() const
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.
int datasetGroupIndex() const
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()
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.
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)