------------------------------------------------------------------------------
| 1336 | |
| 1337 | //------------------------------------------------------------------------------ |
| 1338 | hsize_t vtkHDFWriter::Implementation::GetSubfileNumberOf(const std::string& base, |
| 1339 | const std::string& qualifier, std::size_t subfileId, hsize_t part, char primitive) |
| 1340 | { |
| 1341 | const std::string fullPath = base + "/" + qualifier; |
| 1342 | bool isPolyData = H5Lexists(this->OpenExistingGroup(this->Root, this->GetBasePath(base).c_str()), |
| 1343 | "Lines", H5P_DEFAULT) > 0; |
| 1344 | std::stringstream ss; |
| 1345 | ss << fullPath << " for subfile " << subfileId << " for part " << part << " with primitive " |
| 1346 | << static_cast<int>(primitive); |
| 1347 | const std::string debugInfo = ss.str(); |
| 1348 | |
| 1349 | vtkDebugWithObjectMacro(this->Writer, << "Fetching " << debugInfo); |
| 1350 | |
| 1351 | if (!this->DatasetAndGroupExist(fullPath, this->Subfiles[subfileId])) |
| 1352 | { |
| 1353 | // In composite structure, not all subfiles may have a valid block |
| 1354 | return 0; |
| 1355 | } |
| 1356 | vtkHDF::ScopedH5DHandle sourceDataset = |
| 1357 | H5Dopen(this->Subfiles[subfileId], fullPath.c_str(), H5P_DEFAULT); |
| 1358 | if (sourceDataset == H5I_INVALID_HID) |
| 1359 | { |
| 1360 | vtkErrorWithObjectMacro(this->Writer, << "Could not open dataset " << debugInfo); |
| 1361 | return 0; |
| 1362 | } |
| 1363 | |
| 1364 | std::vector<hsize_t> start{ static_cast<unsigned long>(part) }, count{ 1 }, result{ 0 }; |
| 1365 | int dimension = 1; |
| 1366 | constexpr char INVALID_PRIMITIVE = 0xff; |
| 1367 | |
| 1368 | if (isPolyData && primitive != INVALID_PRIMITIVE) |
| 1369 | { |
| 1370 | start.emplace_back(static_cast<hsize_t>(primitive)); |
| 1371 | count.emplace_back(1); |
| 1372 | dimension++; |
| 1373 | } |
| 1374 | |
| 1375 | vtkHDF::ScopedH5SHandle sourceSpace = H5Dget_space(sourceDataset); |
| 1376 | |
| 1377 | vtkHDF::ScopedH5SHandle destSpace = H5Screate_simple(dimension, count.data(), nullptr); |
| 1378 | if (sourceSpace == H5I_INVALID_HID || sourceSpace == H5I_INVALID_HID) |
| 1379 | { |
| 1380 | vtkErrorWithObjectMacro(this->Writer, << "Could not create destination space " << debugInfo); |
| 1381 | return 0; |
| 1382 | } |
| 1383 | |
| 1384 | if (H5Sselect_hyperslab( |
| 1385 | sourceSpace, H5S_SELECT_SET, start.data(), nullptr, count.data(), nullptr) < 0) |
| 1386 | { |
| 1387 | vtkErrorWithObjectMacro(this->Writer, << "Could not select hyperslab " << debugInfo); |
| 1388 | return 0; |
| 1389 | } |
| 1390 | |
| 1391 | if (H5Dread(sourceDataset, H5T_STD_I64LE, destSpace, sourceSpace, H5P_DEFAULT, result.data()) < 0) |
| 1392 | { |
| 1393 | vtkErrorWithObjectMacro(this->Writer, << "Could not read dataset " << debugInfo); |
| 1394 | return 0; |
| 1395 | } |
no test coverage detected