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