-
Notifications
You must be signed in to change notification settings - Fork 12
/
bag_layerdescriptor.cpp
236 lines (207 loc) · 5.12 KB
/
bag_layerdescriptor.cpp
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
#include "bag_dataset.h"
#include "bag_hdfhelper.h"
#include "bag_layer.h"
#include "bag_layerdescriptor.h"
#include "bag_private.h"
#include <H5Cpp.h>
namespace BAG {
//! Constructor.
/*!
\parm id
The unique identifier of the layer.
\parm internalPath
The HDF5 path of the layer.
\parm name
The name of the layer.
\parm type
The type of layer.
\param chunkSize
The chunk size the HDF5 DataSet will use.
\param compressionLevel
The compression level the HDF5 DataSet will use.
*/
LayerDescriptor::LayerDescriptor(
uint32_t id,
std::string internalPath,
std::string name,
LayerType type,
uint64_t chunkSize,
int compressionLevel)
: m_id(id)
, m_layerType(type)
, m_internalPath(std::move(internalPath))
, m_name(std::move(name))
, m_compressionLevel(compressionLevel)
, m_chunkSize(chunkSize)
, m_minMax(std::numeric_limits<float>::max(), std::numeric_limits<float>::lowest())
{
}
//! Constructor.
/*!
\param dataset
The BAG Dataset this layer belongs to.
\parm type
The type of layer.
\parm internalPath
The HDF5 path of the layer.
\parm name
The name of the layer.
*/
LayerDescriptor::LayerDescriptor(
const Dataset& dataset,
LayerType type,
std::string internalPath,
std::string name)
: m_id(dataset.getNextId())
, m_layerType(type)
, m_minMax(std::numeric_limits<float>::max(), std::numeric_limits<float>::lowest())
{
m_internalPath = internalPath.empty()
? Layer::getInternalPath(type)
: std::move(internalPath);
m_name = name.empty()
? kLayerTypeMapString.at(type)
: std::move(name);
const auto& h5file = dataset.getH5file();
m_compressionLevel = BAG::getCompressionLevel(h5file, m_internalPath);
m_chunkSize = BAG::getChunkSize(h5file, m_internalPath);
}
//! Retrieve the chunk size.
/*!
\return
The chunk size.
*/
uint64_t LayerDescriptor::getChunkSize() const noexcept
{
return m_chunkSize;
}
//! Retrieve the compression level.
/*!
\return
The compression level of the layer.
*/
int LayerDescriptor::getCompressionLevel() const noexcept
{
return m_compressionLevel;
}
//! Retrieve the data type.
/*!
\return
The data type the layer contains.
*/
DataType LayerDescriptor::getDataType() const noexcept
{
return this->getDataTypeProxy();
}
//! Retrieve the element size.
/*!
\return
The element size of the layer.
*/
uint8_t LayerDescriptor::getElementSize() const noexcept
{
return this->getElementSizeProxy();
}
//! Retrieve the unique id.
/*!
\return
The id of the layer.
*/
uint32_t LayerDescriptor::getId() const noexcept
{
return m_id;
}
//! Retrieve the HDF5 path.
/*!
\return
The HDF5 path of the layer. In the case of a GeorefMetadataLayer, the path to
the unique group name is returned. To read a DataSet using this path, add
'/keys', '/varres_keys', or '/values'.
*/
const std::string& LayerDescriptor::getInternalPath() const & noexcept
{
return m_internalPath;
}
//! Retrieve the type this layer contains.
/*!
\return
The type this layer contains.
*/
LayerType LayerDescriptor::getLayerType() const noexcept
{
return m_layerType;
}
//! Retrieve the minimum and maximum values.
/*!
\return
The minimum and maximum values this layer contains.
*/
std::tuple<float, float> LayerDescriptor::getMinMax() const noexcept
{
return m_minMax;
}
//! Retrieve the name.
/*!
\return
The name of the layer.
*/
const std::string& LayerDescriptor::getName() const & noexcept
{
return m_name;
}
//! Get the size of a buffer for reading a specified number rows and columns.
/*!
\param rows
The number of rows that will be allocated for.
\param columns
The number of columns that will be allocated for.
\return
A buffer that can hold rows x columns of values of this layer.
*/
size_t LayerDescriptor::getReadBufferSize(
uint32_t rows,
uint32_t columns) const noexcept
{
return rows * columns * this->getElementSize();
}
//! Set the minimum and maximum values that are found in the layer.
/*!
\param min
The minimum value that is stored in this layer.
\param max
The maximum value that is stored in this layer.
\return
The descriptor. Useful for chaining set calls.
*/
LayerDescriptor& LayerDescriptor::setMinMax(
float min,
float max) & noexcept
{
m_minMax = {min, max};
return *this;
}
//! Set the HDF5 path of the layer.
/*!
\param inPath
The new HDF5 path of the layer.
\return
The descriptor. Useful for chaining set calls.
*/
LayerDescriptor& LayerDescriptor::setInternalPath(std::string inPath) & noexcept
{
m_internalPath = std::move(inPath);
return *this;
}
//! Set the name of the layer.
/*!
\param inName
The new name of the layer.
\return
The descriptor. Useful for chaining set calls.
*/
LayerDescriptor& LayerDescriptor::setName(std::string inName) & noexcept
{
m_name = std::move(inName);
return *this;
}
} // namespace BAG