This call writes all the attributes and sets up the data space.
180 Box3i ext(field->extents()), dw(field->dataWindow());
184 int valuesPerBlock = (1 << (field->m_blockOrder * 3)) * components;
187 size[0] = dw.max.x - dw.min.x + 1;
188 size[1] = dw.max.y - dw.min.y + 1;
189 size[2] = dw.max.z - dw.min.z + 1;
192 hsize_t totalSize[1];
193 totalSize[0] = size[0] * size[1] * size[2] * components;
198 { ext.min.x, ext.min.y, ext.min.z, ext.max.x, ext.max.y, ext.max.z };
208 { dw.min.x, dw.min.y, dw.min.z, dw.max.x, dw.max.y, dw.max.z };
224 int blockOrder = field->m_blockOrder;
233 V3i &blockRes = field->m_blockRes;
234 int numBlocks = blockRes.x * blockRes.y * blockRes.z;
260 vector<char> isAllocated(numBlocks);
261 vector<char>::iterator i = isAllocated.begin();
262 typename vector<SparseBlock<Data_T> >::const_iterator b =
263 field->m_blocks.begin();
264 for (; i != isAllocated.end(); ++i, ++b)
265 *i = static_cast<char>(b->isAllocated);
266 writeSimpleData<char>(layerGroup,
"block_is_allocated_data", isAllocated);
271 vector<Data_T> emptyValue(numBlocks);
272 typename vector<Data_T>::iterator i = emptyValue.begin();
273 typename vector<SparseBlock<Data_T> >::const_iterator b =
274 field->m_blocks.begin();
275 for (; i != emptyValue.end(); ++i, ++b)
276 *i = static_cast<Data_T>(b->emptyValue);
277 writeSimpleData<Data_T>(layerGroup,
"block_empty_value_data", emptyValue);
281 int occupiedBlocks = 0;
282 typename vector<SparseBlock<Data_T> >::iterator b =
283 field->m_blocks.begin();
284 for (; b != field->m_blocks.end(); ++b) {
289 throw WriteAttributeException(
"Couldn't add attribute " +
293 if (occupiedBlocks > 0) {
297 memDims[0] = valuesPerBlock;
299 H5Sset_extent_simple(memDataSpace.id(), 1, memDims, NULL);
303 fileDims[0] = occupiedBlocks;
304 fileDims[1] = valuesPerBlock;
306 H5Sset_extent_simple(fileDataSpace.id(), 2, fileDims, NULL);
310 hid_t dcpl = H5Pcreate(H5P_DATASET_CREATE);
311 hsize_t chunkSize[2];
313 chunkSize[1] = valuesPerBlock;
315 herr_t status = H5Pset_deflate(dcpl, 9);
319 status = H5Pset_chunk(dcpl, 2, chunkSize);
329 H5P_DEFAULT, dcpl, H5P_DEFAULT);
330 if (dataSet.id() < 0)
331 throw CreateDataSetException(
"Couldn't create data set in "
332 "SparseFieldIO::writeInternal");
336 int nextBlockIdx = 0;
341 for (b = field->m_blocks.begin(); b != field->m_blocks.end(); ++b) {
342 if (b->isAllocated) {
343 offset[0] = nextBlockIdx;
346 count[1] = valuesPerBlock;
347 status = H5Sselect_hyperslab(fileDataSpace.id(), H5S_SELECT_SET,
348 offset, NULL, count, NULL);
350 throw WriteHyperSlabException(
351 "Couldn't select slab " +
352 boost::lexical_cast<std::string>(nextBlockIdx));
354 Data_T *data = &b->data[0];
357 fileDataSpace.id(), H5P_DEFAULT, data);
359 throw WriteHyperSlabException(
360 "Couldn't write slab " +
361 boost::lexical_cast<std::string>(nextBlockIdx));
Contains utility functions and classes for Hdf5 files.
static int dataDims()
Dimensions of the given data type. i.e. 3 for V3f, 1 for float.
Namespace for Exception objects.
static const std::string k_dataStr
static const std::string k_dataWindowStr
static const std::string k_numOccupiedBlocksStr
static const std::string k_extentsStr
void print(Severity severity, const std::string &message)
Sends the string to the assigned output, prefixing the message with the severity. ...
bool checkHdf5Gzip()
Checks whether gzip is available in the current hdf5 library.
static const std::string k_blockOrderStr
Namespace for sparse field specifics.
static const std::string k_numBlocksStr
static const std::string k_componentsStr
static const std::string k_blockResStr
bool writeAttribute(hid_t location, const std::string &attrName, const std::string &value)
Writes a string attribute.
Scoped object - creates a dataspace on creation and closes it on destruction.
static const std::string k_bitsPerComponentStr
Scoped object - creates a dataset on creation and closes it on destruction.