Skip to content

Commit 299561b

Browse files
nyoungbqimikejackson
authored andcommitted
preflight patches for all 3 and added filter preflight updates for Esprit [broken]
1 parent 59dadac commit 299561b

File tree

4 files changed

+123
-75
lines changed

4 files changed

+123
-75
lines changed

src/Plugins/OrientationAnalysis/src/OrientationAnalysis/Filters/ReadH5EspritDataFilter.cpp

Lines changed: 105 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,9 @@ Parameters ReadH5EspritDataFilter::parameters() const
7070
OEMEbsdScanSelectionParameter::ValueType{},
7171
/* OEMEbsdScanSelectionParameter::AllowedManufacturers{EbsdLib::OEM::Bruker, EbsdLib::OEM::DREAM3D},*/
7272
OEMEbsdScanSelectionParameter::EbsdReaderType::Esprit, OEMEbsdScanSelectionParameter::ExtensionsType{".h5", ".hdf5"}));
73+
params.insertLinkableParameter(std::make_unique<BoolParameter>(
74+
k_CombineScans_Key, "Combine Scans", "If true combines each of the multiple scans into a single image geometry along the z axis, else each will result in an individual geometry", true));
75+
params.insert(std::make_unique<Float32Parameter>(k_ZSpacing_Key, "Z Spacing (Microns)", "The spacing in microns between each layer.", 1.0f));
7376
params.insert(std::make_unique<VectorFloat32Parameter>(k_Origin_Key, "Origin", "The origin of the volume", std::vector<float32>{0.0F, 0.0F, 0.0F}, std::vector<std::string>{"x", "y", "z"}));
7477
params.insert(std::make_unique<Float32Parameter>(k_ZSpacing_Key, "Z Spacing (Microns)", "The spacing in microns between each layer.", 1.0f));
7578
params.insert(std::make_unique<BoolParameter>(k_DegreesToRadians_Key, "Convert Euler Angles to Radians", "Whether or not to convert the euler angles to radians", true));
@@ -83,13 +86,22 @@ Parameters ReadH5EspritDataFilter::parameters() const
8386
params.insert(std::make_unique<DataObjectNameParameter>(k_CellEnsembleAttributeMatrixName_Key, "Ensemble Attribute Matrix", "The Attribute Matrix where the phase information is stored.",
8487
"Cell Ensemble Data"));
8588

89+
// Link Parameters
90+
params.linkParameters(k_CombineScans_Key, k_Origin_Key, true);
91+
params.linkParameters(k_CombineScans_Key, k_CreatedImageGeometryPath_Key, true);
92+
8693
return params;
8794
}
8895

8996
//------------------------------------------------------------------------------
9097
IFilter::VersionType ReadH5EspritDataFilter::parametersVersion() const
9198
{
92-
return 1;
99+
return 2;
100+
101+
// Version 1 -> 2
102+
// Change 1:
103+
// Added - k_CombineScans_Key = "combine_scans";
104+
// Solution - default parameter value 'true' preserves backwards functionality;
93105
}
94106

95107
//------------------------------------------------------------------------------
@@ -103,6 +115,7 @@ IFilter::PreflightResult ReadH5EspritDataFilter::preflightImpl(const DataStructu
103115
const std::atomic_bool& shouldCancel) const
104116
{
105117
auto pSelectedScanNamesValue = filterArgs.value<OEMEbsdScanSelectionParameter::ValueType>(k_SelectedScanNames_Key);
118+
auto pCombineScansValue = filterArgs.value<bool>(k_CombineScans_Key); // V2 Param
106119
auto pZSpacingValue = filterArgs.value<float32>(k_ZSpacing_Key);
107120
auto pOriginValue = filterArgs.value<VectorFloat32Parameter::ValueType>(k_Origin_Key);
108121
auto pDegreesToRadiansValue = filterArgs.value<bool>(k_DegreesToRadians_Key);
@@ -111,10 +124,9 @@ IFilter::PreflightResult ReadH5EspritDataFilter::preflightImpl(const DataStructu
111124
auto pCellAttributeMatrixNameValue = filterArgs.value<std::string>(k_CellAttributeMatrixName_Key);
112125
auto pCellEnsembleAttributeMatrixNameValue = filterArgs.value<std::string>(k_CellEnsembleAttributeMatrixName_Key);
113126

114-
DataPath cellEnsembleAMPath = pImageGeometryNameValue.createChildPath(pCellEnsembleAttributeMatrixNameValue);
115-
DataPath cellAMPath = pImageGeometryNameValue.createChildPath(pCellAttributeMatrixNameValue);
127+
DataPath cellEnsembleAMPath = {};
128+
DataPath cellAMPath = {};
116129

117-
PreflightResult preflightResult;
118130
nx::core::Result<OutputActions> resultOutputActions;
119131
std::vector<PreflightValue> preflightUpdatedValues;
120132

@@ -131,81 +143,107 @@ IFilter::PreflightResult ReadH5EspritDataFilter::preflightImpl(const DataStructu
131143
H5EspritReader::Pointer reader = H5EspritReader::New();
132144
reader->setFileName(pSelectedScanNamesValue.inputFilePath.string());
133145
reader->setReadPatternData(pReadPatternDataValue);
134-
reader->setHDF5Path(pSelectedScanNamesValue.scanNames.front());
135-
if(const int err = reader->readHeaderOnly(); err < 0)
136-
{
137-
return MakePreflightErrorResult(-9682, fmt::format("An error occurred while reading the header data\n{} : {}", err, reader->getErrorMessage()));
138-
}
139146

140-
// create the Image Geometry and it's attribute matrices
141-
const CreateImageGeometryAction::DimensionType dims = {static_cast<usize>(reader->getXDimension()), static_cast<usize>(reader->getYDimension()), pSelectedScanNamesValue.scanNames.size()};
142-
const std::vector<usize> tupleDims = {dims[2], dims[1], dims[0]};
147+
for(const auto& name : pSelectedScanNamesValue.scanNames)
143148
{
144-
CreateImageGeometryAction::SpacingType spacing = {static_cast<float32>(reader->getXStep()), static_cast<float32>(reader->getYStep()), pZSpacingValue};
145-
for(float& value : spacing)
149+
reader->setHDF5Path(name);
150+
if(const int err = reader->readHeaderOnly(); err < 0)
146151
{
147-
value = (value == 0.0f ? 1.0f : value);
152+
return MakePreflightErrorResult(-9682, fmt::format("An error occurred while reading the header data\n{} : {}", err, reader->getErrorMessage()));
148153
}
149-
auto createDataGroupAction = std::make_unique<CreateImageGeometryAction>(pImageGeometryNameValue, dims, pOriginValue, spacing, pCellAttributeMatrixNameValue);
150-
resultOutputActions.value().appendAction(std::move(createDataGroupAction));
151-
}
152-
const auto phases = reader->getPhaseVector();
153-
std::vector<usize> ensembleTupleDims{phases.size() + 1};
154-
{
155-
auto createAttributeMatrixAction = std::make_unique<CreateAttributeMatrixAction>(cellEnsembleAMPath, ensembleTupleDims);
156-
resultOutputActions.value().appendAction(std::move(createAttributeMatrixAction));
157-
}
158154

159-
// create the cell ensemble arrays : these arrays are purposely created using the AngFile constant names to match the corresponding Oim import filter!
160-
{
161-
auto createArrayAction = std::make_unique<CreateArrayAction>(DataType::uint32, ensembleTupleDims, std::vector<usize>{1}, cellEnsembleAMPath.createChildPath(EbsdLib::AngFile::CrystalStructures));
162-
resultOutputActions.value().appendAction(std::move(createArrayAction));
163-
}
164-
{
165-
auto createArrayAction = std::make_unique<CreateArrayAction>(DataType::float32, ensembleTupleDims, std::vector<usize>{6}, cellEnsembleAMPath.createChildPath(EbsdLib::AngFile::LatticeConstants));
166-
resultOutputActions.value().appendAction(std::move(createArrayAction));
167-
}
168-
{
169-
auto createArrayAction = std::make_unique<CreateStringArrayAction>(ensembleTupleDims, cellEnsembleAMPath.createChildPath(EbsdLib::AngFile::MaterialName));
170-
resultOutputActions.value().appendAction(std::move(createArrayAction));
171-
}
155+
CreateImageGeometryAction::SpacingType spacing = {static_cast<CreateImageGeometryAction::SpacingType::value_type>(reader->getXStep()),
156+
static_cast<CreateImageGeometryAction::SpacingType::value_type>(reader->getYStep()), pZSpacingValue};
157+
std::transform(spacing.cbegin(), spacing.cend(), spacing.begin(), [](CreateImageGeometryAction::SpacingType::value_type value) { return (value == 0.0f ? 1.0f : value); });
172158

173-
// create the cell data arrays
174-
H5EspritFields espritFeatures;
175-
const auto names = espritFeatures.getFilterFeatures<std::vector<std::string>>();
176-
for(const auto& name : names)
177-
{
178-
if(name == EbsdLib::H5Esprit::phi1 || name == EbsdLib::H5Esprit::PHI || name == EbsdLib::H5Esprit::phi2)
159+
CreateImageGeometryAction::DimensionType dims = {static_cast<CreateImageGeometryAction::DimensionType::value_type>(reader->getXDimension()),
160+
static_cast<CreateImageGeometryAction::DimensionType::value_type>(reader->getYDimension()),
161+
pCombineScansValue ? pSelectedScanNamesValue.scanNames.size() : static_cast<CreateImageGeometryAction::DimensionType::value_type>(1)};
162+
const std::vector<CreateImageGeometryAction::DimensionType::value_type> tupleDims = {dims[2], dims[1], dims[0]};
163+
164+
if(pCombineScansValue)
165+
{
166+
cellEnsembleAMPath = pImageGeometryNameValue.createChildPath(pCellEnsembleAttributeMatrixNameValue);
167+
cellAMPath = pImageGeometryNameValue.createChildPath(pCellAttributeMatrixNameValue);
168+
169+
auto createDataGroupAction = std::make_unique<CreateImageGeometryAction>(pImageGeometryNameValue, dims, pOriginValue, spacing, pCellAttributeMatrixNameValue);
170+
resultOutputActions.value().appendAction(std::move(createDataGroupAction));
171+
}
172+
else
173+
{
174+
DataPath imagePath = DataPath({name});
175+
cellEnsembleAMPath = imagePath.createChildPath(pCellEnsembleAttributeMatrixNameValue);
176+
cellAMPath = imagePath.createChildPath(pCellAttributeMatrixNameValue);
177+
CreateImageGeometryAction::OriginType origin = {reader->getXStar(), reader->getYStar(), reader->getZStar()};
178+
179+
auto createDataGroupAction = std::make_unique<CreateImageGeometryAction>(imagePath, dims, origin, spacing, pCellAttributeMatrixNameValue);
180+
resultOutputActions.value().appendAction(std::move(createDataGroupAction));
181+
}
182+
183+
const auto phases = reader->getPhaseVector();
184+
std::vector<usize> ensembleTupleDims{phases.size() + 1};
179185
{
180-
continue;
186+
auto createAttributeMatrixAction = std::make_unique<CreateAttributeMatrixAction>(cellEnsembleAMPath, ensembleTupleDims);
187+
resultOutputActions.value().appendAction(std::move(createAttributeMatrixAction));
181188
}
182189

183-
if(reader->getPointerType(name) == EbsdLib::NumericTypes::Type::Int32)
190+
// create the cell ensemble arrays : these arrays are purposely created using the AngFile constant names to match the corresponding Oim import filter!
184191
{
185-
auto createArrayAction = std::make_unique<CreateArrayAction>(DataType::int32, tupleDims, std::vector<usize>{1}, cellAMPath.createChildPath(name));
192+
auto createArrayAction = std::make_unique<CreateArrayAction>(DataType::uint32, ensembleTupleDims, std::vector<usize>{1}, cellEnsembleAMPath.createChildPath(EbsdLib::AngFile::CrystalStructures));
186193
resultOutputActions.value().appendAction(std::move(createArrayAction));
187194
}
188-
else if(reader->getPointerType(name) == EbsdLib::NumericTypes::Type::Float)
189195
{
190-
auto createArrayAction = std::make_unique<CreateArrayAction>(DataType::float32, tupleDims, std::vector<usize>{1}, cellAMPath.createChildPath(name));
196+
auto createArrayAction = std::make_unique<CreateArrayAction>(DataType::float32, ensembleTupleDims, std::vector<usize>{6}, cellEnsembleAMPath.createChildPath(EbsdLib::AngFile::LatticeConstants));
191197
resultOutputActions.value().appendAction(std::move(createArrayAction));
192198
}
193-
}
194-
{
195-
auto createArrayAction = std::make_unique<CreateArrayAction>(DataType::float32, tupleDims, std::vector<usize>{3}, cellAMPath.createChildPath(EbsdLib::Esprit::EulerAngles));
196-
resultOutputActions.value().appendAction(std::move(createArrayAction));
197-
}
198-
if(pReadPatternDataValue)
199-
{
200-
std::array<int32, 2> patternDims = {{0, 0}};
201-
reader->getPatternDims(patternDims);
202-
if(patternDims[0] == 0 || patternDims[1] == 0)
203199
{
204-
return MakePreflightErrorResult(-9683, fmt::format("The parameter 'Read Pattern Data' has been enabled but there does not seem to be any pattern data in the file for the scan name selected"));
200+
auto createArrayAction = std::make_unique<CreateStringArrayAction>(ensembleTupleDims, cellEnsembleAMPath.createChildPath(EbsdLib::AngFile::MaterialName));
201+
resultOutputActions.value().appendAction(std::move(createArrayAction));
202+
}
203+
204+
// create the cell data arrays
205+
H5EspritFields espritFeatures;
206+
const auto names = espritFeatures.getFilterFeatures<std::vector<std::string>>();
207+
for(const auto& featureName : names)
208+
{
209+
if(featureName == EbsdLib::H5Esprit::phi1 || featureName == EbsdLib::H5Esprit::PHI || featureName == EbsdLib::H5Esprit::phi2)
210+
{
211+
continue;
212+
}
213+
214+
if(reader->getPointerType(featureName) == EbsdLib::NumericTypes::Type::Int32)
215+
{
216+
auto createArrayAction = std::make_unique<CreateArrayAction>(DataType::int32, tupleDims, std::vector<usize>{1}, cellAMPath.createChildPath(featureName));
217+
resultOutputActions.value().appendAction(std::move(createArrayAction));
218+
}
219+
else if(reader->getPointerType(featureName) == EbsdLib::NumericTypes::Type::Float)
220+
{
221+
auto createArrayAction = std::make_unique<CreateArrayAction>(DataType::float32, tupleDims, std::vector<usize>{1}, cellAMPath.createChildPath(featureName));
222+
resultOutputActions.value().appendAction(std::move(createArrayAction));
223+
}
224+
}
225+
226+
{
227+
auto createArrayAction = std::make_unique<CreateArrayAction>(DataType::float32, tupleDims, std::vector<usize>{3}, cellAMPath.createChildPath(EbsdLib::Esprit::EulerAngles));
228+
resultOutputActions.value().appendAction(std::move(createArrayAction));
229+
}
230+
if(pReadPatternDataValue)
231+
{
232+
std::array<int32, 2> patternDims = {{0, 0}};
233+
reader->getPatternDims(patternDims);
234+
if(patternDims[0] == 0 || patternDims[1] == 0)
235+
{
236+
return MakePreflightErrorResult(-9683, fmt::format("The parameter 'Read Pattern Data' has been enabled but there does not seem to be any pattern data in the file for the scan name selected"));
237+
}
238+
auto createArrayAction = std::make_unique<CreateArrayAction>(DataType::uint8, tupleDims, std::vector<usize>{static_cast<usize>(patternDims[0]), static_cast<usize>(patternDims[1])},
239+
cellAMPath.createChildPath(EbsdLib::H5Esprit::RawPatterns));
240+
resultOutputActions.value().appendAction(std::move(createArrayAction));
241+
}
242+
243+
if(pCombineScansValue)
244+
{
245+
break;
205246
}
206-
auto createArrayAction = std::make_unique<CreateArrayAction>(DataType::uint8, tupleDims, std::vector<usize>{static_cast<usize>(patternDims[0]), static_cast<usize>(patternDims[1])},
207-
cellAMPath.createChildPath(EbsdLib::H5Esprit::RawPatterns));
208-
resultOutputActions.value().appendAction(std::move(createArrayAction));
209247
}
210248

211249
return {std::move(resultOutputActions), std::move(preflightUpdatedValues)};
@@ -216,13 +254,15 @@ Result<> ReadH5EspritDataFilter::executeImpl(DataStructure& dataStructure, const
216254
const std::atomic_bool& shouldCancel) const
217255
{
218256
ReadH5DataInputValues inputValues;
219-
ReadH5EspritDataInputValues espritInputValues;
220257

221258
inputValues.SelectedScanNames = filterArgs.value<OEMEbsdScanSelectionParameter::ValueType>(k_SelectedScanNames_Key);
259+
inputValues.CombineScans = filterArgs.value<bool>(k_CombineScans_Key);
222260
inputValues.ReadPatternData = filterArgs.value<bool>(k_ReadPatternData_Key);
223261
inputValues.ImageGeometryPath = filterArgs.value<DataPath>(k_CreatedImageGeometryPath_Key);
224-
inputValues.CellEnsembleAttributeMatrixPath = inputValues.ImageGeometryPath.createChildPath(filterArgs.value<std::string>(k_CellEnsembleAttributeMatrixName_Key));
225-
inputValues.CellAttributeMatrixPath = inputValues.ImageGeometryPath.createChildPath(filterArgs.value<std::string>(k_CellAttributeMatrixName_Key));
262+
inputValues.CellEnsembleAttributeMatrixName = filterArgs.value<std::string>(k_CellEnsembleAttributeMatrixName_Key);
263+
inputValues.CellAttributeMatrixName = filterArgs.value<std::string>(k_CellAttributeMatrixName_Key);
264+
265+
ReadH5EspritDataInputValues espritInputValues;
226266
espritInputValues.DegreesToRadians = filterArgs.value<bool>(k_DegreesToRadians_Key);
227267

228268
return ReadH5EspritData(dataStructure, messageHandler, shouldCancel, &inputValues, &espritInputValues)();

src/Plugins/OrientationAnalysis/src/OrientationAnalysis/Filters/ReadH5EspritDataFilter.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ class ORIENTATIONANALYSIS_EXPORT ReadH5EspritDataFilter : public IFilter
2424
ReadH5EspritDataFilter& operator=(ReadH5EspritDataFilter&&) noexcept = delete;
2525

2626
// Parameter Keys
27+
// V1 Keys
2728
static inline constexpr StringLiteral k_SelectedScanNames_Key = "selected_scan_names";
2829
static inline constexpr StringLiteral k_ZSpacing_Key = "z_spacing";
2930
static inline constexpr StringLiteral k_Origin_Key = "origin";
@@ -33,6 +34,9 @@ class ORIENTATIONANALYSIS_EXPORT ReadH5EspritDataFilter : public IFilter
3334
static inline constexpr StringLiteral k_CellAttributeMatrixName_Key = "cell_attribute_matrix_name";
3435
static inline constexpr StringLiteral k_CellEnsembleAttributeMatrixName_Key = "cell_ensemble_attribute_matrix_name";
3536

37+
// V2 Keys
38+
static inline constexpr StringLiteral k_CombineScans_Key = "combine_scans";
39+
3640
/**
3741
* @brief Reads SIMPL json and converts it simplnx Arguments.
3842
* @param json

src/Plugins/OrientationAnalysis/src/OrientationAnalysis/Filters/ReadH5OimDataFilter.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -153,14 +153,14 @@ IFilter::PreflightResult ReadH5OimDataFilter::preflightImpl(const DataStructure&
153153
H5OIMReader::Pointer reader = H5OIMReader::New();
154154
reader->setFileName(pSelectedScanNamesValue.inputFilePath.string());
155155
reader->setReadPatternData(pReadPatternDataValue);
156-
if(const int err = reader->readHeaderOnly(); err < 0)
157-
{
158-
return MakePreflightErrorResult(-9582, fmt::format("An error occurred while reading the header data\n{} : {}", err, reader->getErrorMessage()));
159-
}
160156

161157
for(const auto& name : pSelectedScanNamesValue.scanNames)
162158
{
163159
reader->setHDF5Path(name);
160+
if(const int err = reader->readHeaderOnly(); err < 0)
161+
{
162+
return MakePreflightErrorResult(-9582, fmt::format("An error occurred while reading the header data\n{} : {}", err, reader->getErrorMessage()));
163+
}
164164

165165
CreateImageGeometryAction::SpacingType spacing = {reader->getXStep(), reader->getYStep(), pZSpacingValue};
166166
CreateImageGeometryAction::DimensionType dims = {static_cast<usize>(reader->getXDimension()), static_cast<usize>(reader->getYDimension()),
@@ -260,8 +260,8 @@ Result<> ReadH5OimDataFilter::executeImpl(DataStructure& dataStructure, const Ar
260260
{
261261
ReadH5DataInputValues inputValues;
262262

263-
inputValues.CombineScans = filterArgs.value<bool>(k_CombineScans_Key);
264263
inputValues.SelectedScanNames = filterArgs.value<OEMEbsdScanSelectionParameter::ValueType>(k_SelectedScanNames_Key);
264+
inputValues.CombineScans = filterArgs.value<bool>(k_CombineScans_Key);
265265
inputValues.ReadPatternData = filterArgs.value<bool>(k_ReadPatternData_Key);
266266
inputValues.ImageGeometryPath = filterArgs.value<DataPath>(k_CreatedImageGeometryPath_Key);
267267
inputValues.CellEnsembleAttributeMatrixName = filterArgs.value<std::string>(k_CellEnsembleAttributeMatrixName_Key);

src/Plugins/OrientationAnalysis/src/OrientationAnalysis/Filters/ReadH5OinaDataFilter.cpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -142,15 +142,14 @@ IFilter::PreflightResult ReadH5OinaDataFilter::preflightImpl(const DataStructure
142142
H5OINAReader reader;
143143
reader.setFileName(pSelectedScanNamesValue.inputFilePath.string());
144144
reader.setReadPatternData(pReadPatternDataValue);
145-
reader.setHDF5Path(pSelectedScanNamesValue.scanNames.front());
146-
if(const int err = reader.readHeaderOnly(); err < 0)
147-
{
148-
return MakePreflightErrorResult(-9582, fmt::format("An error occurred while reading the header data\n{} : {}", err, reader.getErrorMessage()));
149-
}
150145

151146
for(const auto& name : pSelectedScanNamesValue.scanNames)
152147
{
153148
reader.setHDF5Path(name);
149+
if(const int err = reader.readHeaderOnly(); err < 0)
150+
{
151+
return MakePreflightErrorResult(-9582, fmt::format("An error occurred while reading the header data\n{} : {}", err, reader.getErrorMessage()));
152+
}
154153

155154
CreateImageGeometryAction::SpacingType spacing = {reader.getXStep(), reader.getYStep(), pZSpacingValue};
156155
CreateImageGeometryAction::DimensionType dims = {static_cast<usize>(reader.getXDimension()), static_cast<usize>(reader.getYDimension()),
@@ -228,6 +227,11 @@ IFilter::PreflightResult ReadH5OinaDataFilter::preflightImpl(const DataStructure
228227
cellAMPath.createChildPath(EbsdLib::H5OINA::UnprocessedPatterns));
229228
resultOutputActions.value().appendAction(std::move(createArrayAction));
230229
}
230+
231+
if(pCombineScansValue)
232+
{
233+
break;
234+
}
231235
}
232236

233237
return {std::move(resultOutputActions), std::move(preflightUpdatedValues)};

0 commit comments

Comments
 (0)