Skip to content

Commit

Permalink
[Compiling|Functional][UNIT TESTS NEEDED]
Browse files Browse the repository at this point in the history
- Correct human name for combing scans parameter
- put oweness on subclass to define the update origin (case by case problem)
- add nullptr checks and Error messaging
  • Loading branch information
nyoungbq committed Nov 15, 2024
1 parent dc7c131 commit 3bb1f28
Show file tree
Hide file tree
Showing 8 changed files with 60 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,19 @@ Result<> ReadH5EspritData::operator()()
return execute();
}

// -----------------------------------------------------------------------------
Result<> ReadH5EspritData::updateOrigin(const std::string& scanName)
{
/*
* Unfortunately, the file does not have the correct data to find an origin.
* This means that the origin will remain {0,0,0}.
*
* Down the line, if a solution crops up, look to ReadH5Oina.cpp for an example
* implementation.
*/
return {};
}

// -----------------------------------------------------------------------------
Result<> ReadH5EspritData::copyRawEbsdData(int index)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ class ORIENTATIONANALYSIS_EXPORT ReadH5EspritData : public IEbsdOemReader<H5Espr

Result<> operator()();

Result<> updateOrigin(const std::string& scanName) override;

Result<> copyRawEbsdData(int index) override;
Result<> copyRawEbsdData(const std::string& scanName) override;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,33 @@ Result<> ReadH5OinaData::operator()()
return execute();
}

// -----------------------------------------------------------------------------
Result<> ReadH5OinaData::updateOrigin(const std::string& scanName)
{
const DataPath imagePath({scanName});

auto& imageGeom = m_DataStructure.getDataRefAs<ImageGeom>(imagePath);
const usize totalCells = imageGeom.getNumberOfCells();

const auto* xPos = reinterpret_cast<float32*>(m_Reader->getPointerByName(EbsdLib::Ctf::X));
if(xPos == nullptr)
{
return MakeErrorResult(-9970, fmt::format("{}({}): Function {}: Error. Cannot find {} in supplied scan file ({})", "IEbsdOemReader", __FILE__, __LINE__, EbsdLib::Ctf::X, m_Reader->getFileName()));
}
const auto* yPos = reinterpret_cast<float32*>(m_Reader->getPointerByName(EbsdLib::Ctf::Y));
if(yPos == nullptr)
{
return MakeErrorResult(-9971, fmt::format("{}({}): Function {}: Error. Cannot find {} in supplied scan file ({})", "IEbsdOemReader", __FILE__, __LINE__, EbsdLib::Ctf::Y, m_Reader->getFileName()));
}

float32 minX = *std::min_element(xPos, xPos + totalCells);
float32 minY = *std::min_element(yPos, yPos + totalCells);

imageGeom.setOrigin(minX, minY, 0.0f);

return {};
}

// -----------------------------------------------------------------------------
Result<> ReadH5OinaData::copyRawEbsdData(int index)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class ORIENTATIONANALYSIS_EXPORT ReadH5OinaData : public IEbsdOemReader<H5OINARe

Result<> operator()();

Result<> updateOrigin(const std::string& scanName) override;
Result<> copyRawEbsdData(int index) override;
Result<> copyRawEbsdData(const std::string& scanName) override;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ Parameters ReadH5EspritDataFilter::parameters() const
/* OEMEbsdScanSelectionParameter::AllowedManufacturers{EbsdLib::OEM::Bruker, EbsdLib::OEM::DREAM3D},*/
OEMEbsdScanSelectionParameter::EbsdReaderType::Esprit, OEMEbsdScanSelectionParameter::ExtensionsType{".h5", ".hdf5"}));
params.insertLinkableParameter(std::make_unique<BoolParameter>(

Check failure on line 73 in src/Plugins/OrientationAnalysis/src/OrientationAnalysis/Filters/ReadH5EspritDataFilter.cpp

View workflow job for this annotation

GitHub Actions / clang_format_pr

code should be clang-formatted [-Wclang-format-violations]

Check failure on line 73 in src/Plugins/OrientationAnalysis/src/OrientationAnalysis/Filters/ReadH5EspritDataFilter.cpp

View workflow job for this annotation

GitHub Actions / clang_format_pr

code should be clang-formatted [-Wclang-format-violations]
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));
k_CombineScans_Key, "Stack Scans Along Z Axis", "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));

Check failure on line 74 in src/Plugins/OrientationAnalysis/src/OrientationAnalysis/Filters/ReadH5EspritDataFilter.cpp

View workflow job for this annotation

GitHub Actions / clang_format_pr

code should be clang-formatted [-Wclang-format-violations]
params.insert(std::make_unique<Float32Parameter>(k_ZSpacing_Key, "Z Spacing (Microns)", "The spacing in microns between each layer.", 1.0f));
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"}));
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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,9 @@ Parameters ReadH5OimDataFilter::parameters() const
params.insert(std::make_unique<OEMEbsdScanSelectionParameter>(k_SelectedScanNames_Key, "Scan Names", "The name of the scan in the .h5 file. EDAX can store multiple scans in a single file",
OEMEbsdScanSelectionParameter::ValueType{}, OEMEbsdScanSelectionParameter::EbsdReaderType::Oim,
OEMEbsdScanSelectionParameter::ExtensionsType{".h5"}));
params.insertLinkableParameter(std::make_unique<BoolParameter>(
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));
params.insertLinkableParameter(
std::make_unique<BoolParameter>(k_CombineScans_Key, "Stack Scans Along Z Axis",
"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));
params.insert(std::make_unique<Float32Parameter>(k_ZSpacing_Key, "Z Spacing (Microns)", "The spacing in microns between each layer.", 1.0f));
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"}));
params.insert(std::make_unique<BoolParameter>(k_ReadPatternData_Key, "Import Pattern Data", "Whether or not to import the pattern data", false));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,9 @@ Parameters ReadH5OinaDataFilter::parameters() const
params.insert(std::make_unique<OEMEbsdScanSelectionParameter>(k_SelectedScanNames_Key, "Scan Names", "The name of the scan in the .h5oina file. Oxford can store multiple scans in a single file",
OEMEbsdScanSelectionParameter::ValueType{}, OEMEbsdScanSelectionParameter::EbsdReaderType::H5Oina,
OEMEbsdScanSelectionParameter::ExtensionsType{".h5oina"}));
params.insertLinkableParameter(std::make_unique<BoolParameter>(
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));
params.insertLinkableParameter(
std::make_unique<BoolParameter>(k_CombineScans_Key, "Stack Scans Along Z Axis",
"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));
params.insert(std::make_unique<BoolParameter>(k_EdaxHexagonalAlignment_Key, "Convert Hexagonal X-Axis to EDAX Standard",
"Whether or not to convert a Hexagonal phase to the EDAX standard for x-axis alignment", true));
params.insert(std::make_unique<BoolParameter>(k_ConvertPhaseToInt32_Key, "Convert Phase Data to Int32", "Native Phases data value is uint8. Convert to Int32 for better filter compatibility", true));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,6 @@ class ORIENTATIONANALYSIS_EXPORT IEbsdOemReader
auto& imageGeom = m_DataStructure.getDataRefAs<ImageGeom>(DataPath({currentScanName}));
imageGeom.setUnits(IGeometry::LengthUnit::Micrometer);
copyDataResults = copyRawEbsdData(currentScanName);

if(copyDataResults.invalid())
{
return copyDataResults;
}

copyDataResults = updateOrigin(currentScanName);
}

if(copyDataResults.invalid())
Expand Down Expand Up @@ -133,8 +126,7 @@ class ORIENTATIONANALYSIS_EXPORT IEbsdOemReader
const DataPath cellEnsembleAM = imagePath.createChildPath(m_InputValues->CellEnsembleAttributeMatrixName);
auto& crystalStructures = m_DataStructure.getDataRefAs<UInt32Array>(cellEnsembleAM.createChildPath(EbsdLib::AngFile::CrystalStructures));
auto& materialNames = m_DataStructure.getDataRefAs<StringArray>(cellEnsembleAM.createChildPath(EbsdLib::AngFile::MaterialName));
auto& latticeConstantsArray =
m_DataStructure.getDataRefAs<Float32Array>(cellEnsembleAM.createChildPath(EbsdLib::AngFile::LatticeConstants));
auto& latticeConstantsArray = m_DataStructure.getDataRefAs<Float32Array>(cellEnsembleAM.createChildPath(EbsdLib::AngFile::LatticeConstants));
Float32Array::store_type* latticeConstants = latticeConstantsArray.getDataStore();

crystalStructures[0] = EbsdLib::CrystalStructure::UnknownCrystalStructure;
Expand All @@ -160,28 +152,19 @@ class ORIENTATIONANALYSIS_EXPORT IEbsdOemReader
latticeConstants->setComponent(phaseId, 5, lc[5]);
}

return {};
if(m_InputValues->CombineScans)
{
// No need to update origin
return {};
}

return updateOrigin(scanName);
}

virtual Result<> updateOrigin(const std::string& scanName) = 0;

virtual Result<> copyRawEbsdData(int index) = 0;
virtual Result<> copyRawEbsdData(const std::string& scanName) = 0;
virtual Result<> updateOrigin(const std::string& scanName)
{
const DataPath imagePath({scanName});

auto& imageGeom = m_DataStructure.getDataRefAs<ImageGeom>(imagePath);
const usize totalCells = imageGeom.getNumberOfCells();

const auto* xPos = reinterpret_cast<float32*>(m_Reader->getPointerByName(EbsdLib::Ang::XPosition));
const auto* yPos = reinterpret_cast<float32*>(m_Reader->getPointerByName(EbsdLib::Ang::YPosition));

float32 minX = *std::min_element(xPos, xPos + totalCells);
float32 minY = *std::min_element(yPos, yPos + totalCells);

imageGeom.setOrigin(minX, minY, 0.0f);

return {};
}

protected:
std::shared_ptr<T> m_Reader;
Expand Down

0 comments on commit 3bb1f28

Please sign in to comment.