[ VIGRA Homepage | Function Index | Class Index | Namespaces | File List | Main Page ]
Access to HDF5 files. More...
#include <vigra/hdf5impex.hxx>
Public Types | |
enum | OpenMode |
Set how a file is opened. OpenMode::New creates a new file. If the file already exists, overwrite it. More... | |
Public Member Functions | |
void | cd (std::string groupName) |
Change the current group. Both absolute and relative group names are allowed. | |
void | cd_mk (std::string groupName) |
Change the current group; create it if necessary. If the first character is a "/", the path will be interpreted as absolute path, otherwise it will be interpreted as path relative to the current group. | |
bool | cd_up () |
Change the current group to its parent group. returns true if successful, false otherwise. | |
template<unsigned int N, class T > | |
void | createDataset (std::string datasetName, typename MultiArrayShape< N >::type shape, T init=T(), int iChunkSize=0, int compressionParameter=0) |
Create a new dataset. This function can be used to create a dataset filled with a default value, for example before writing data into it using writeBlock(). Attention: only atomic datatypes are provided. For spectral data, add an dimension (case RGB: add one dimension of size 3). | |
bool | existsAttribute (std::string object_name, std::string attribute_name) |
Test if attribute exists. | |
std::string | filename () |
Get the name of the associated file. | |
void | flushToDisk () |
Immediately write all data to disk. | |
std::string | get_absolute_path (std::string path) |
takes any path and converts it into an absolute path in the current file. | |
hid_t | getAttributeHandle (std::string dataset_name, std::string attribute_name) |
Obtain the HDF5 handle of a attribute. | |
hssize_t | getDatasetDimensions (std::string datasetName) |
Get the number of dimensions of a certain dataset If the first character is a "/", the path will be interpreted as absolute path, otherwise it will be interpreted as path relative to the current group. | |
hid_t | getDatasetHandle (std::string dataset_name) |
Obtain the HDF5 handle of a dataset. | |
ArrayVector< hsize_t > | getDatasetShape (std::string datasetName) |
Get the shape of each dimension of a certain dataset. Normally, this function is called after determining the dimension of the dataset using getDatasetDimensions(). If the first character is a "/", the path will be interpreted as absolute path, otherwise it will be interpreted as path relative to the current group. | |
hid_t | getGroupHandle (std::string group_name) |
Obtain the HDF5 handle of a group. | |
HDF5File (std::string filename, OpenMode mode, int track_creation_times=0) | |
Create an HDF5File object. | |
template<class Container > | |
void | ls (Container &cont) |
List the contents of the current group into a container-like object via insert(). Only datasets and groups are inserted, other objects (e.g., datatypes) are ignored. Group names always have an ending "/". | |
std::vector< std::string > | ls () |
List the contents of the current group. The function returns a vector of strings holding the entries of the current group. Only datasets and groups are listed, other objects (e.g. datatypes) are ignored. Group names always have an ending "/". | |
void | mkdir (std::string groupName) |
Create a new group. If the first character is a "/", the path will be interpreted as absolute path, otherwise it will be interpreted as path relative to the current group. | |
std::string | pwd () |
Get the path of the current group. | |
void | read (std::string datasetName, char &data) |
Read a single value. Specialization of the read function for simple datatypes. | |
template<class T > | |
void | read (const std::string &datasetName, ArrayVectorView< T > &array) |
Read data into an array vector. If the first character of datasetName is a "/", the path will be interpreted as absolute path, otherwise it will be interpreted as path relative to the current group. | |
template<unsigned int N, class T > | |
void | read (std::string datasetName, MultiArrayView< N, T, UnstridedArrayTag > &array) |
Read data into a multi array. If the first character of datasetName is a "/", the path will be interpreted as absolute path, otherwise it will be interpreted as path relative to the current group. | |
template<class T > | |
void | readAndResize (std::string datasetName, ArrayVector< T > &array) |
Read data into an array vector. Resize the array vector to the correct size. If the first character of datasetName is a "/", the path will be interpreted as absolute path, otherwise it will be interpreted as path relative to the current group. | |
template<unsigned int N, class T > | |
void | readAndResize (std::string datasetName, MultiArray< N, T > &array) |
Read data into a MultiArray. Resize MultiArray to the correct size. If the first character of datasetName is a "/", the path will be interpreted as absolute path, otherwise it will be interpreted as path relative to the current group. | |
void | readAttribute (std::string object_name, std::string attribute_name, char &data) |
Read a single value. Specialization of the read function for simple datatypes. | |
template<unsigned int N, class T > | |
void | readAttribute (std::string object_name, std::string attribute_name, const MultiArrayView< N, T, UnstridedArrayTag > &array) |
Read MultiArray Attributes. In contrast to datasets, subarray access is not available. | |
template<unsigned int N, class T > | |
void | readBlock (std::string datasetName, typename MultiArrayShape< N >::type blockOffset, typename MultiArrayShape< N >::type blockShape, MultiArrayView< N, T, UnstridedArrayTag > &array) |
Read a block of data into a multi array. This function allows to read a small block out of a larger volume stored in an HDF5 dataset. | |
void | root () |
Change current group to "/". | |
void | write (std::string datasetName, char data) |
Write a single value. Specialization of the write function for simple datatypes. | |
template<class T > | |
void | write (const std::string &datasetName, const ArrayVectorView< T > &array, int compression=0) |
Write array vectors. | |
template<unsigned int N, class T > | |
void | write (std::string datasetName, const MultiArrayView< N, T, UnstridedArrayTag > &array, typename MultiArrayShape< N >::type chunkSize, int compression=0) |
Write multi arrays. Chunks can be activated by providing a MultiArrayShape as chunkSize. chunkSize must have equal dimension as array. | |
template<unsigned int N, class T > | |
void | write (std::string datasetName, const MultiArrayView< N, T, UnstridedArrayTag > &array, int iChunkSize=0, int compression=0) |
Write multi arrays. | |
void | writeAttribute (std::string object_name, std::string attribute_name, char data) |
Write a single value. Specialization of the write function for simple datatypes. | |
template<unsigned int N, class T > | |
void | writeAttribute (std::string object_name, std::string attribute_name, const MultiArrayView< N, T, UnstridedArrayTag > &array) |
Write MultiArray Attributes. In contrast to datasets, subarray access, chunks and compression are not available. | |
template<unsigned int N, class T > | |
void | writeBlock (std::string datasetName, typename MultiArrayShape< N >::type blockOffset, const MultiArrayView< N, T, UnstridedArrayTag > &array) |
Write a multi array into a larger volume. blockOffset determines the position, where array is written. | |
~HDF5File () | |
Destructor to make sure that all data is flushed before closing the file. |
Access to HDF5 files.
HDF5File provides a convenient way of accessing data in HDF5 files. vigra::MultiArray structures of any dimension can be stored to / loaded from HDF5 files. Typical HDF5 features like subvolume access, chunks and data compression are available, string attributes can be attached to any dataset or group. Group- or dataset-handles are encapsulated in the class and managed automatically. The internal file-system like structure can be accessed by functions like "cd()" or "mkdir()".
Example: Write the MultiArray out_multi_array to file. Change the current directory to "/group" and read in the same MultiArray as in_multi_array.
HDF5File file("/path/to/file",HDF5File::New); file.mkdir("group"); file.write("/group/dataset", out_multi_array); file.cd("/group"); file.read("dataset", in_multi_array);
#include <vigra/hdf5impex.hxx>
Namespace: vigra
enum OpenMode |
Set how a file is opened. OpenMode::New creates a new file. If the file already exists, overwrite it.
OpenMode::Open opens a file for reading/writing. The file will be created, if necessary.
Create an HDF5File object.
Creates or opens HDF5 file at position filename. The current group is set to "/".
void ls | ( | Container & | cont | ) |
List the contents of the current group into a container-like object via insert(). Only datasets and groups are inserted, other objects (e.g., datatypes) are ignored. Group names always have an ending "/".
The argument cont is presumably an associative container, however, only its member function cont.insert(std::string)
will be called.
cont | reference to a container supplying a member function insert(const i_type &) , where i_type is convertible to std::string . |
bool existsAttribute | ( | std::string | object_name, | |
std::string | attribute_name | |||
) |
Test if attribute exists.
void write | ( | std::string | datasetName, | |
const MultiArrayView< N, T, UnstridedArrayTag > & | array, | |||
int | iChunkSize = 0 , |
|||
int | compression = 0 | |||
) |
Write multi arrays.
Chunks can be activated by setting
iChunkSize = size; //size > 0
. The chunks will be hypercubes with edge length size.
Compression can be activated by setting
compression = parameter; // 0 < parameter <= 9
where 0 stands for no compression and 9 for maximum compression.
If the first character of datasetName is a "/", the path will be interpreted as absolute path, otherwise it will be interpreted as path relative to the current group.
void write | ( | std::string | datasetName, | |
const MultiArrayView< N, T, UnstridedArrayTag > & | array, | |||
typename MultiArrayShape< N >::type | chunkSize, | |||
int | compression = 0 | |||
) |
Write multi arrays. Chunks can be activated by providing a MultiArrayShape as chunkSize. chunkSize must have equal dimension as array.
Compression can be activated by setting
compression = parameter; // 0 < parameter <= 9
where 0 stands for no compression and 9 for maximum compression.
If the first character of datasetName is a "/", the path will be interpreted as absolute path, otherwise it will be interpreted as path relative to the current group.
void writeBlock | ( | std::string | datasetName, | |
typename MultiArrayShape< N >::type | blockOffset, | |||
const MultiArrayView< N, T, UnstridedArrayTag > & | array | |||
) |
Write a multi array into a larger volume. blockOffset determines the position, where array is written.
Chunks can be activated by providing a MultiArrayShape as chunkSize. chunkSize must have equal dimension as array.
Compression can be activated by setting
compression = parameter; // 0 < parameter <= 9
where 0 stands for no compression and 9 for maximum compression.
If the first character of datasetName is a "/", the path will be interpreted as absolute path, otherwise it will be interpreted as path relative to the current group.
void write | ( | const std::string & | datasetName, | |
const ArrayVectorView< T > & | array, | |||
int | compression = 0 | |||
) |
Write array vectors.
Compression can be activated by setting
compression = parameter; // 0 < parameter <= 9
where 0 stands for no compression and 9 for maximum compression.
If the first character of datasetName is a "/", the path will be interpreted as absolute path, otherwise it will be interpreted as path relative to the current group.
void readBlock | ( | std::string | datasetName, | |
typename MultiArrayShape< N >::type | blockOffset, | |||
typename MultiArrayShape< N >::type | blockShape, | |||
MultiArrayView< N, T, UnstridedArrayTag > & | array | |||
) |
Read a block of data into a multi array. This function allows to read a small block out of a larger volume stored in an HDF5 dataset.
blockOffset determines the position of the block. blockSize determines the size in each dimension of the block.
If the first character of datasetName is a "/", the path will be interpreted as absolute path, otherwise it will be interpreted as path relative to the current group.
void createDataset | ( | std::string | datasetName, | |
typename MultiArrayShape< N >::type | shape, | |||
T | init = T() , |
|||
int | iChunkSize = 0 , |
|||
int | compressionParameter = 0 | |||
) |
Create a new dataset. This function can be used to create a dataset filled with a default value, for example before writing data into it using writeBlock(). Attention: only atomic datatypes are provided. For spectral data, add an dimension (case RGB: add one dimension of size 3).
shape determines the dimension and the size of the dataset.
Chunks can be activated by providing a MultiArrayShape as chunkSize. chunkSize must have equal dimension as array.
Compression can be activated by setting
compression = parameter; // 0 < parameter <= 9
where 0 stands for no compression and 9 for maximum compression.
If the first character of datasetName is a "/", the path will be interpreted as absolute path, otherwise it will be interpreted as path relative to the current group.
std::string get_absolute_path | ( | std::string | path | ) |
takes any path and converts it into an absolute path in the current file.
Elements like "." and ".." are treated as expected. Links are not supported or resolved.
© Ullrich Köthe (ullrich.koethe@iwr.uni-heidelberg.de) |
html generated using doxygen and Python
|