QGIS/external/mdal/frmts/mdal_xmdf.hpp

118 lines
3.4 KiB
C++
Raw Normal View History

/*
MDAL - Mesh Data Abstraction Library (MIT License)
Copyright (C) 2018 Peter Petrik (zilolv at gmail dot com)
*/
#ifndef MDAL_XMDF_HPP
#define MDAL_XMDF_HPP
#include <string>
#include <vector>
#include <memory>
#include <iosfwd>
#include <iostream>
#include <fstream>
2018-07-18 09:00:34 +02:00
#include "mdal_data_model.hpp"
#include "mdal.h"
#include "mdal_hdf5.hpp"
2018-12-14 14:59:53 +01:00
#include "mdal_driver.hpp"
namespace MDAL
{
2018-12-04 17:28:05 +01:00
/**
* The XmdfDataset reads the data directly from HDF5 file
* by usage of hyperslabs retrieval. This format is used by TUFLOW and HYDRO_AS-2D
2018-12-04 17:28:05 +01:00
* basically all (timesteps) data for one particular dataset groups
* are stored in single
* 3D arrays (time, x, y) for vector datasets
* 2D arrays (time, x) for scalar datasets
* 2D arrays (time, active) for active flags (optional, supported by default)
*
* For TUFLOW, the dataset groups are structured with a tree starting from a unique group and datasets support active flag value.
*
* For HYDRO_AS-2D, all the groups are on the root of the file and the datasets don't support active flag value.
*
2018-12-04 17:28:05 +01:00
*/
class XmdfDataset: public Dataset2D
2018-12-04 17:28:05 +01:00
{
public:
XmdfDataset( DatasetGroup *grp,
const HdfDataset &valuesDs,
const HdfDataset &activeDs,
hsize_t timeIndex );
~XmdfDataset() override;
size_t scalarData( size_t indexStart, size_t count, double *buffer ) override;
size_t vectorData( size_t indexStart, size_t count, double *buffer ) override;
size_t activeData( size_t indexStart, size_t count, int *buffer ) override;
const HdfDataset &dsValues() const;
const HdfDataset &dsActive() const;
hsize_t timeIndex() const;
private:
HdfDataset mHdf5DatasetValues;
HdfDataset mHdf5DatasetActive;
// index or row where the data for this timestep begins
hsize_t mTimeIndex;
};
2018-12-14 14:59:53 +01:00
class DriverXmdf: public Driver
{
public:
/**
* Driver for XMDF Files
*
* Structure of the TUFLOW file. Groups are optional since it depends
* on tools which groups are created.
* - root
* - Temporal
* - Depth
* - Velocity
* - ..
* - Maximums
* - Depth
* - Velocity
* - ..
* - Difference (res_to_res.exe TUFLOW utility tool)
* - ..
* - Times (e.g. time of peak velocity)
* - ..
* - ...
*/
2018-12-14 14:59:53 +01:00
DriverXmdf();
~DriverXmdf( ) override = default;
DriverXmdf *create() override;
bool canReadDatasets( const std::string &uri ) override;
void load( const std::string &datFile, Mesh *mesh ) override;
private:
2018-12-04 17:28:05 +01:00
MDAL::Mesh *mMesh = nullptr;
std::string mDatFile;
2018-07-18 09:00:34 +02:00
std::shared_ptr<MDAL::DatasetGroup> readXmdfGroupAsDatasetGroup(
const HdfGroup &rootGroup,
const std::string &groupName,
size_t vertexCount,
size_t faceCount ) const;
2018-07-18 09:00:34 +02:00
void addDatasetGroupsFromXmdfGroup(
DatasetGroups &groups,
const HdfGroup &rootGroup,
const std::string &nameSuffix,
size_t vertexCount,
size_t faceCount ) const;
void readGroupsTree( HdfFile &file,
const std::string &name,
MDAL::DatasetGroups &groups,
size_t vertexCount,
size_t faceCount ) const;
};
} // namespace MDAL
#endif //MDAL_ASCII_DAT_HPP