This call writes all the attributes and sets up the data space.
182 Box3i ext(field->extents()), dw(field->dataWindow());
186 int valuesPerBlock = (1 << (field->m_blockOrder * 3)) * components;
191 { ext.min.x, ext.min.y, ext.min.z, ext.max.x, ext.max.y, ext.max.z };
201 { dw.min.x, dw.min.y, dw.min.z, dw.max.x, dw.max.y, dw.max.z };
217 int blockOrder = field->m_blockOrder;
226 V3i &blockRes = field->m_blockRes;
227 int numBlocks = blockRes.x * blockRes.y * blockRes.z;
255 vector<char> isAllocated(numBlocks);
256 for (
int i = 0; i < numBlocks; ++i) {
257 isAllocated[i] =
static_cast<char>(blocks[i].
isAllocated);
259 writeSimpleData<char>(layerGroup,
"block_is_allocated_data", isAllocated);
264 vector<Data_T> emptyValue(numBlocks);
265 for (
int i = 0; i < numBlocks; ++i) {
266 emptyValue[i] =
static_cast<Data_T
>(blocks[i].
emptyValue);
268 writeSimpleData<Data_T>(layerGroup,
"block_empty_value_data", emptyValue);
272 int occupiedBlocks = 0;
273 for (
int i = 0; i < numBlocks; ++i) {
274 if (blocks[i].isAllocated) {
280 throw WriteAttributeException(
"Couldn't add attribute " +
284 if (occupiedBlocks > 0) {
288 memDims[0] = valuesPerBlock;
290 H5Sset_extent_simple(memDataSpace.id(), 1, memDims, NULL);
294 fileDims[0] = occupiedBlocks;
295 fileDims[1] = valuesPerBlock;
297 H5Sset_extent_simple(fileDataSpace.id(), 2, fileDims, NULL);
301 hid_t dcpl = H5Pcreate(H5P_DATASET_CREATE);
302 hsize_t chunkSize[2];
304 chunkSize[1] = valuesPerBlock;
306 herr_t status = H5Pset_deflate(dcpl, 9);
310 status = H5Pset_chunk(dcpl, 2, chunkSize);
320 H5P_DEFAULT, dcpl, H5P_DEFAULT);
321 if (dataSet.id() < 0)
322 throw CreateDataSetException(
"Couldn't create data set in "
323 "SparseFieldIO::writeInternal");
327 int nextBlockIdx = 0;
332 for (
int i = 0; i < numBlocks; ++i) {
333 if (blocks[i].isAllocated) {
334 offset[0] = nextBlockIdx;
337 count[1] = valuesPerBlock;
338 status = H5Sselect_hyperslab(fileDataSpace.id(), H5S_SELECT_SET,
339 offset, NULL, count, NULL);
341 throw WriteHyperSlabException(
342 "Couldn't select slab " +
343 boost::lexical_cast<std::string>(nextBlockIdx));
345 Data_T *data = field->m_blocks[i].data;
348 fileDataSpace.id(), H5P_DEFAULT, data);
350 throw WriteHyperSlabException(
351 "Couldn't write slab " +
352 boost::lexical_cast<std::string>(nextBlockIdx));
Contains utility functions and classes for Hdf5 files.
FIELD3D_API bool writeAttribute(hid_t location, const std::string &attrName, const std::string &value)
Writes a string attribute.
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
boost::recursive_mutex::scoped_lock GlobalLock
FIELD3D_API void print(Severity severity, const std::string &message)
Sends the string to the assigned output, prefixing the message with the severity. ...
Data_T emptyValue
The value to use if the block isn't allocated. We allow setting this per block so that we for example...
FIELD3D_API 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 isAllocated
Whether the block is allocated or not.
FIELD3D_NAMESPACE_OPEN boost::recursive_mutex g_hdf5Mutex
Storage for one individual block of a SparseField.
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.