H5FrameProvider.hpp
1.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#pragma once
#include <array>
#include "data/hdf5/H5SingleDataReader.hpp"
#include "data/provider/FrameProvider.hpp"
#include "data/provider/ProviderOpenFailureException.hpp"
class H5FrameProvider : public FrameProvider, public H5SingleDataReader {
public:
H5FrameProvider(const std::string &path, const std::string &dataSetPath,
const std::vector<unsigned long> ×tamps) try
: H5SingleDataReader(path, dataSetPath, H5SingleDataReader::UINT16, 2),
timestamps(timestamps) {
} catch (const H5::FileIException &exception) {
throw ProviderOpenFailureException(exception.getDetailMsg());
}
H5FrameProvider(const std::string &path, const std::string &dataSetPath) try
: H5SingleDataReader(path, dataSetPath, H5SingleDataReader::UINT16, 2),
timestamps(std::vector<unsigned long>(dimensions[2], 0)) {
} catch (const H5::FileIException &exception) {
throw ProviderOpenFailureException(exception.getDetailMsg());
}
bool hasNext() const override {
return current < dimensions[2] && current <= lastFrame;
}
unsigned long next(void *buffer) override {
selectImage(current);
read(buffer);
return timestamps[current++];
}
void first(void *buffer) const {
selectImage(0);
read(buffer);
}
size_t rows() const override { return dimensions[0]; }
size_t columns() const override { return dimensions[1]; }
private:
hsize_t current = 0; // 239 - 5; /* Modify to start from further frame */
static constexpr hsize_t lastFrame{258}; /* Peak */
// static constexpr hsize_t lastFrame{41}; /* Rise */
// static constexpr hsize_t lastFrame{9999}; /* Entire */
const std::vector<unsigned long> timestamps;
void selectImage(hsize_t image) const {
select({dimensions[0], dimensions[1], 1}, {0, 0, image});
}
};