/src/bag/api/bag_layerdescriptor.cpp
Line | Count | Source |
1 | | |
2 | | #include "bag_dataset.h" |
3 | | #include "bag_hdfhelper.h" |
4 | | #include "bag_layer.h" |
5 | | #include "bag_layerdescriptor.h" |
6 | | #include "bag_private.h" |
7 | | |
8 | | #include <H5Cpp.h> |
9 | | |
10 | | |
11 | | namespace BAG { |
12 | | |
13 | | //! Constructor. |
14 | | /*! |
15 | | \param id |
16 | | The unique identifier of the layer. |
17 | | \param internalPath |
18 | | The HDF5 path of the layer. |
19 | | \param name |
20 | | The name of the layer. |
21 | | \param type |
22 | | The type of layer. |
23 | | \param chunkSize |
24 | | The chunk size the HDF5 DataSet will use. |
25 | | \param compressionLevel |
26 | | The compression level the HDF5 DataSet will use. |
27 | | */ |
28 | | LayerDescriptor::LayerDescriptor( |
29 | | uint32_t id, |
30 | | std::string internalPath, |
31 | | std::string name, |
32 | | LayerType type, |
33 | | uint64_t rows, uint64_t cols, |
34 | | uint64_t chunkSize, |
35 | | int compressionLevel) |
36 | 73 | : m_id(id) |
37 | 73 | , m_layerType(type) |
38 | 73 | , m_internalPath(std::move(internalPath)) |
39 | 73 | , m_name(std::move(name)) |
40 | 73 | , m_compressionLevel(compressionLevel) |
41 | 73 | , m_chunkSize(chunkSize) |
42 | 73 | , m_minMax(std::numeric_limits<float>::max(), std::numeric_limits<float>::lowest()) |
43 | 73 | , m_dims({rows, cols}) |
44 | 73 | { |
45 | 73 | } |
46 | | |
47 | | //! Constructor. |
48 | | /*! |
49 | | \param dataset |
50 | | The BAG Dataset this layer belongs to. |
51 | | \param type |
52 | | The type of layer. |
53 | | \param internalPath |
54 | | The HDF5 path of the layer. |
55 | | \param name |
56 | | The name of the layer. |
57 | | */ |
58 | | LayerDescriptor::LayerDescriptor( |
59 | | const Dataset& dataset, |
60 | | LayerType type, |
61 | | uint64_t rows, uint64_t cols, |
62 | | std::string internalPath, |
63 | | std::string name) |
64 | 122 | : m_id(dataset.getNextId()) |
65 | 122 | , m_layerType(type) |
66 | 122 | , m_minMax(std::numeric_limits<float>::max(), std::numeric_limits<float>::lowest()) |
67 | 122 | , m_dims({rows, cols}) |
68 | 122 | { |
69 | 122 | m_internalPath = internalPath.empty() |
70 | 122 | ? Layer::getInternalPath(type) |
71 | 122 | : std::move(internalPath); |
72 | | |
73 | 122 | m_name = name.empty() |
74 | 122 | ? kLayerTypeMapString.at(type) |
75 | 122 | : std::move(name); |
76 | | |
77 | 122 | const auto& h5file = dataset.getH5file(); |
78 | | |
79 | 122 | m_compressionLevel = BAG::getCompressionLevel(h5file, m_internalPath); |
80 | 122 | m_chunkSize = BAG::getChunkSize(h5file, m_internalPath); |
81 | 122 | } |
82 | | |
83 | | |
84 | | //! Retrieve the chunk size. |
85 | | /*! |
86 | | \return |
87 | | The chunk size. |
88 | | */ |
89 | | uint64_t LayerDescriptor::getChunkSize() const noexcept |
90 | 45 | { |
91 | 45 | return m_chunkSize; |
92 | 45 | } |
93 | | |
94 | | //! Retrieve the compression level. |
95 | | /*! |
96 | | \return |
97 | | The compression level of the layer. |
98 | | */ |
99 | | int LayerDescriptor::getCompressionLevel() const noexcept |
100 | 45 | { |
101 | 45 | return m_compressionLevel; |
102 | 45 | } |
103 | | |
104 | | //! Retrieve the data type. |
105 | | /*! |
106 | | \return |
107 | | The data type the layer contains. |
108 | | */ |
109 | | DataType LayerDescriptor::getDataType() const noexcept |
110 | 45 | { |
111 | 45 | return this->getDataTypeProxy(); |
112 | 45 | } |
113 | | |
114 | | //! Retrieve the element size. |
115 | | /*! |
116 | | \return |
117 | | The element size of the layer. |
118 | | */ |
119 | | uint8_t LayerDescriptor::getElementSize() const noexcept |
120 | 45 | { |
121 | 45 | return this->getElementSizeProxy(); |
122 | 45 | } |
123 | | |
124 | | //! Retrieve the unique id. |
125 | | /*! |
126 | | \return |
127 | | The id of the layer. |
128 | | */ |
129 | | uint32_t LayerDescriptor::getId() const noexcept |
130 | 45 | { |
131 | 45 | return m_id; |
132 | 45 | } |
133 | | |
134 | | //! Retrieve the HDF5 path. |
135 | | /*! |
136 | | \return |
137 | | The HDF5 path of the layer. In the case of a GeorefMetadataLayer, the path to |
138 | | the unique group name is returned. To read a DataSet using this path, add |
139 | | '/keys', '/varres_keys', or '/values'. |
140 | | */ |
141 | | const std::string& LayerDescriptor::getInternalPath() const & noexcept |
142 | 240 | { |
143 | 240 | return m_internalPath; |
144 | 240 | } |
145 | | |
146 | | //! Retrieve the type this layer contains. |
147 | | /*! |
148 | | \return |
149 | | The type this layer contains. |
150 | | */ |
151 | | LayerType LayerDescriptor::getLayerType() const noexcept |
152 | 534 | { |
153 | 534 | return m_layerType; |
154 | 534 | } |
155 | | |
156 | | //! Retrieve the minimum and maximum values. |
157 | | /*! |
158 | | \return |
159 | | The minimum and maximum values this layer contains. |
160 | | */ |
161 | | std::tuple<float, float> LayerDescriptor::getMinMax() const noexcept |
162 | 45 | { |
163 | 45 | return m_minMax; |
164 | 45 | } |
165 | | |
166 | | //! Retrieve the name. |
167 | | /*! |
168 | | \return |
169 | | The name of the layer. |
170 | | */ |
171 | | const std::string& LayerDescriptor::getName() const & noexcept |
172 | 209 | { |
173 | 209 | return m_name; |
174 | 209 | } |
175 | | |
176 | | //! Retrieve the dimensions (shape) of the layer. |
177 | | //! Return dimensions as uint32_t rather than the underlying uint64_t to maintain compatibility with the rest of the |
178 | | //! BAG API, which assumes rows and cols are uint32_t. |
179 | | /*! |
180 | | \return |
181 | | The row and column spacing/resolution of the grid |
182 | | */ |
183 | | std::tuple<uint32_t, uint32_t> LayerDescriptor::getDims() const & noexcept |
184 | 0 | { |
185 | 0 | return std::tuple<uint32_t, uint32_t>{ |
186 | 0 | static_cast<uint32_t>(std::get<0>(m_dims)), |
187 | 0 | static_cast<uint32_t>(std::get<1>(m_dims)) |
188 | 0 | }; |
189 | 0 | } |
190 | | |
191 | | //! Get the size of a buffer for reading a specified number rows and columns. |
192 | | /*! |
193 | | \param rows |
194 | | The number of rows that will be allocated for. |
195 | | \param columns |
196 | | The number of columns that will be allocated for. |
197 | | |
198 | | \return |
199 | | A buffer that can hold rows x columns of values of this layer. |
200 | | */ |
201 | | size_t LayerDescriptor::getReadBufferSize( |
202 | | uint64_t rows, |
203 | | uint64_t columns) const noexcept |
204 | 0 | { |
205 | 0 | return rows * columns * this->getElementSize(); |
206 | 0 | } |
207 | | |
208 | | //! Set the minimum and maximum values that are found in the layer. |
209 | | /*! |
210 | | \param min |
211 | | The minimum value that is stored in this layer. |
212 | | \param max |
213 | | The maximum value that is stored in this layer. |
214 | | |
215 | | \return |
216 | | The descriptor. Useful for chaining set calls. |
217 | | */ |
218 | | LayerDescriptor& LayerDescriptor::setMinMax( |
219 | | float min, |
220 | | float max) & noexcept |
221 | 120 | { |
222 | 120 | m_minMax = {min, max}; |
223 | 120 | return *this; |
224 | 120 | } |
225 | | |
226 | | LayerDescriptor& LayerDescriptor::setDims(uint64_t rows, uint64_t cols) & noexcept |
227 | 195 | { |
228 | 195 | m_dims = {rows, cols}; |
229 | 195 | return *this; |
230 | 195 | } |
231 | | |
232 | | //! Set the HDF5 path of the layer. |
233 | | /*! |
234 | | \param inPath |
235 | | The new HDF5 path of the layer. |
236 | | |
237 | | \return |
238 | | The descriptor. Useful for chaining set calls. |
239 | | */ |
240 | | LayerDescriptor& LayerDescriptor::setInternalPath(std::string inPath) & noexcept |
241 | 0 | { |
242 | 0 | m_internalPath = std::move(inPath); |
243 | 0 | return *this; |
244 | 0 | } |
245 | | |
246 | | //! Set the name of the layer. |
247 | | /*! |
248 | | \param inName |
249 | | The new name of the layer. |
250 | | |
251 | | \return |
252 | | The descriptor. Useful for chaining set calls. |
253 | | */ |
254 | | LayerDescriptor& LayerDescriptor::setName(std::string inName) & noexcept |
255 | 0 | { |
256 | 0 | m_name = std::move(inName); |
257 | 0 | return *this; |
258 | 0 | } |
259 | | |
260 | | } // namespace BAG |
261 | | |