diff --git a/src/simplnx/Utilities/Parsing/DREAM3D/Dream3dIO.cpp b/src/simplnx/Utilities/Parsing/DREAM3D/Dream3dIO.cpp index f6e272adc9..fbe2b5bda8 100644 --- a/src/simplnx/Utilities/Parsing/DREAM3D/Dream3dIO.cpp +++ b/src/simplnx/Utilities/Parsing/DREAM3D/Dream3dIO.cpp @@ -835,7 +835,7 @@ Result<> readLegacyDataArrayDims(const nx::core::HDF5::DatasetReader& dataArrayR return nx::core::MakeWarningVoidResult(Legacy::k_FailedReadingTupleDims_Code, ss); } tDims = tupleAttrib.readAsVector(); - std::reverse(tDims.begin(), tDims.end()); // SIMPL writes the Tuple Dimensions in reverse order to this attribute + // std::reverse(tDims.begin(), tDims.end()); // SIMPL writes the Tuple Dimensions in reverse order to this attribute } return {}; @@ -868,7 +868,17 @@ Result<> readLegacyStringArray(DataStructure& dataStructure, const nx::core::HDF return {}; } -Result readLegacyDataArray(DataStructure& dataStructure, const nx::core::HDF5::DatasetReader& dataArrayReader, DataObject::IdType parentId, bool preflight = false) +/** + * @brief + * @param dataStructure + * @param dataArrayReader + * @param parentId + * @param amTDims + * @param preflight + * @return + */ +Result readLegacyDataArray(DataStructure& dataStructure, const nx::core::HDF5::DatasetReader& dataArrayReader, DataObject::IdType parentId, std::vector& amTDims, + bool preflight = false) { auto size = H5Dget_storage_size(dataArrayReader.getId()); auto typeId = dataArrayReader.getTypeId(); @@ -882,6 +892,38 @@ Result readLegacyDataArray(DataStructure& dataStructure, const nx:: return MakeErrorResult(error.code, error.message); } + // Let's do some sanity checking of the tuple dims and the comp dims + // This is here because some 3rd party apps are trying to write .dream3d + // files but are getting confused about the Tuple Dims and the component + // dims. This bit of code will try to fix the specific issue where the + // .dream3d file essentially had _all_ the dimensions shoved in the + // tuple dimensions. + if(!amTDims.empty()) // If the amTDims are empty we are just reading a Data Array without an Attribute Matrix so skip. + { + // + if(tDims.size() > amTDims.size() && cDims.size() == 1 && cDims[0] == 1) + { + cDims.clear(); + // Find the index of the first non-matching dimension value. + for(size_t idx = 0; idx < tDims.size(); idx++) + { + // If we are past the end of the AM Dimensions, then copy the value to the component dimensions + if(idx >= amTDims.size()) + { + cDims.push_back(tDims[idx]); + } + else if(amTDims[idx] != tDims[idx]) // something went wrong here. Each vector should have the same exact values at the start of the vector + { + // This should not happen at all. If so, bail out now. + cDims.clear(); // just put things back the way they were and fail. + cDims.push_back(1ULL); + break; // The first parts of the dimensions should MATCH for this algorithm to work. + } + } + tDims.resize(amTDims.size()); + } + } + Result daResult; if(H5Tequal(typeId, H5T_NATIVE_FLOAT) > 0) { @@ -1092,7 +1134,7 @@ Result<> readLegacyAttributeMatrix(DataStructure& dataStructure, const nx::core: } else { - Result<> result = ConvertResult(std::move(readLegacyDataArray(dataStructure, dataArraySet, attributeMatrix->getId(), preflight))); + Result<> result = ConvertResult(std::move(readLegacyDataArray(dataStructure, dataArraySet, attributeMatrix->getId(), tDims, preflight))); daResults.push_back(result); } } @@ -1154,7 +1196,8 @@ void readGenericGeomDims(IGeometry* geom, const nx::core::HDF5::GroupReader& geo Result readLegacyGeomArray(DataStructure& dataStructure, IGeometry* geometry, const nx::core::HDF5::GroupReader& geomGroup, const std::string& arrayName, bool preflight) { auto dataArraySet = geomGroup.openDataset(arrayName); - return readLegacyDataArray(dataStructure, dataArraySet, geometry->getId(), preflight); + std::vector tDims; + return readLegacyDataArray(dataStructure, dataArraySet, geometry->getId(), tDims, preflight); } template