------------------------------------------------------------------------------
| 702 | |
| 703 | //------------------------------------------------------------------------------ |
| 704 | void vtkADIOS2CoreImageReader::ReadImageBlocks(vtkMultiBlockDataSet* mbds) |
| 705 | { |
| 706 | try |
| 707 | { |
| 708 | // One adios block is mapped to one vtk image data. |
| 709 | size_t blockExtentI{ 0 }; |
| 710 | for (size_t blockI = this->Impl->BlockStart; |
| 711 | blockI < this->Impl->BlockStart + this->Impl->BlockCount; blockI++) |
| 712 | { |
| 713 | vtkNew<vtkImageData> outputImage; |
| 714 | outputImage->SetOrigin(this->Origin); |
| 715 | outputImage->SetSpacing(this->Spacing); |
| 716 | const auto& extents = this->Impl->BlockExtents[blockExtentI++]; |
| 717 | if (this->IsColumnMajor) |
| 718 | { |
| 719 | outputImage->SetExtent( |
| 720 | extents[0], extents[1], extents[2], extents[3], extents[4], extents[5]); |
| 721 | } |
| 722 | else |
| 723 | { |
| 724 | outputImage->SetExtent( |
| 725 | extents[4], extents[5], extents[2], extents[3], extents[0], extents[1]); |
| 726 | } |
| 727 | // The index of mbds starts from 0 |
| 728 | mbds->SetBlock(static_cast<unsigned int>(blockI - this->Impl->BlockStart), outputImage); |
| 729 | // Fetch all datas for current image |
| 730 | for (const auto& iter : this->Impl->InquiredVars) |
| 731 | { |
| 732 | std::string varName = iter.first; |
| 733 | if (this->Impl->AvailVars.find(varName) == this->Impl->AvailVars.end()) |
| 734 | { |
| 735 | vtkErrorMacro("Inquire variable " << varName << " cannot be found in the provided file"); |
| 736 | continue; |
| 737 | } |
| 738 | // TODO: Add validation for inquire variable's dimensions |
| 739 | std::string typeStr = this->FetchTypeStringFromVarName(varName); |
| 740 | if (typeStr.empty()) |
| 741 | { |
| 742 | vtkErrorMacro("Cannot find a type for " << varName << " invalid name is provided"); |
| 743 | continue; |
| 744 | } |
| 745 | |
| 746 | vtkSmartPointer<vtkAbstractArray> dataArray; |
| 747 | // Use the adios_types_map in adios2 code base to generate types |
| 748 | if (typeStr == "string") |
| 749 | { // vtkStringArray uses vtkStdString instead of std::string. So we manually |
| 750 | // do the work here |
| 751 | auto varADIOS2 = this->Impl->AdiosIO.InquireVariable<std::string>(varName); |
| 752 | varADIOS2.SetBlockSelection(blockI); |
| 753 | varADIOS2.SetStepSelection({ this->Impl->RequestStep, 1 }); |
| 754 | |
| 755 | vtkNew<vtkStringArray> array; |
| 756 | dataArray = array; |
| 757 | array->SetNumberOfComponents(1); |
| 758 | array->SetName(varName.c_str()); |
| 759 | array->SetNumberOfTuples(static_cast<vtkIdType>(varADIOS2.SelectionSize())); |
| 760 | this->Impl->BpReader.Get(varADIOS2, dynamic_cast<std::string*>(array->GetPointer(0))); |
| 761 | } |
no test coverage detected