Skip to content

Commit f8b0b32

Browse files
nyoungbqimikejackson
authored andcommitted
add origin updating to base reader class and overload in OIM where its not needed
1 parent b14fcea commit f8b0b32

File tree

3 files changed

+41
-3
lines changed

3 files changed

+41
-3
lines changed

src/Plugins/OrientationAnalysis/src/OrientationAnalysis/Filters/Algorithms/ReadH5OimData.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,18 @@ Result<> ReadH5OimData::operator()()
2020
return execute();
2121
}
2222

23+
// -----------------------------------------------------------------------------
24+
Result<> ReadH5OimData::updateOrigin(const std::string& scanName)
25+
{
26+
/*
27+
* This function intentionally has no logic in order to avoid extra calculations;
28+
* The origins were set in preflight, but this file type is an outlier in that it stores
29+
* the origin in the header. Thus, this function overrides the general need to access
30+
* the X and Y positions data as seen in the super/baseclass.
31+
*/
32+
return {};
33+
}
34+
2335
// -----------------------------------------------------------------------------
2436
Result<> ReadH5OimData::copyRawEbsdData(int index)
2537
{

src/Plugins/OrientationAnalysis/src/OrientationAnalysis/Filters/Algorithms/ReadH5OimData.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ class ORIENTATIONANALYSIS_EXPORT ReadH5OimData : public IEbsdOemReader<H5OIMRead
2626

2727
Result<> copyRawEbsdData(int index) override;
2828
Result<> copyRawEbsdData(const std::string& scanName) override;
29+
Result<> updateOrigin(const std::string& scanName) override;
2930
};
3031

3132
} // namespace nx::core

src/Plugins/OrientationAnalysis/src/OrientationAnalysis/utilities/IEbsdOemReader.hpp

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,13 @@ class ORIENTATIONANALYSIS_EXPORT IEbsdOemReader
8181
auto& imageGeom = m_DataStructure.getDataRefAs<ImageGeom>(DataPath({currentScanName}));
8282
imageGeom.setUnits(IGeometry::LengthUnit::Micrometer);
8383
copyDataResults = copyRawEbsdData(currentScanName);
84+
85+
if(copyDataResults.invalid())
86+
{
87+
return copyDataResults;
88+
}
89+
90+
copyDataResults = updateOrigin(currentScanName);
8491
}
8592

8693
if(copyDataResults.invalid())
@@ -123,10 +130,11 @@ class ORIENTATIONANALYSIS_EXPORT IEbsdOemReader
123130
}
124131

125132
// These arrays are purposely created using the AngFile constant names for BOTH the Oim and the Esprit readers!
126-
auto& crystalStructures = m_DataStructure.getDataRefAs<UInt32Array>(imagePath.createChildPath(m_InputValues->CellEnsembleAttributeMatrixName).createChildPath(EbsdLib::AngFile::CrystalStructures));
127-
auto& materialNames = m_DataStructure.getDataRefAs<StringArray>(imagePath.createChildPath(m_InputValues->CellEnsembleAttributeMatrixName).createChildPath(EbsdLib::AngFile::MaterialName));
133+
const DataPath cellEnsembleAM = imagePath.createChildPath(m_InputValues->CellEnsembleAttributeMatrixName);
134+
auto& crystalStructures = m_DataStructure.getDataRefAs<UInt32Array>(cellEnsembleAM.createChildPath(EbsdLib::AngFile::CrystalStructures));
135+
auto& materialNames = m_DataStructure.getDataRefAs<StringArray>(cellEnsembleAM.createChildPath(EbsdLib::AngFile::MaterialName));
128136
auto& latticeConstantsArray =
129-
m_DataStructure.getDataRefAs<Float32Array>(imagePath.createChildPath(m_InputValues->CellEnsembleAttributeMatrixName).createChildPath(EbsdLib::AngFile::LatticeConstants));
137+
m_DataStructure.getDataRefAs<Float32Array>(cellEnsembleAM.createChildPath(EbsdLib::AngFile::LatticeConstants));
130138
Float32Array::store_type* latticeConstants = latticeConstantsArray.getDataStore();
131139

132140
crystalStructures[0] = EbsdLib::CrystalStructure::UnknownCrystalStructure;
@@ -157,6 +165,23 @@ class ORIENTATIONANALYSIS_EXPORT IEbsdOemReader
157165

158166
virtual Result<> copyRawEbsdData(int index) = 0;
159167
virtual Result<> copyRawEbsdData(const std::string& scanName) = 0;
168+
virtual Result<> updateOrigin(const std::string& scanName)
169+
{
170+
const DataPath imagePath({scanName});
171+
172+
auto& imageGeom = m_DataStructure.getDataRefAs<ImageGeom>(imagePath);
173+
const usize totalCells = imageGeom.getNumberOfCells();
174+
175+
const auto* xPos = reinterpret_cast<float32*>(m_Reader->getPointerByName(EbsdLib::Ang::XPosition));
176+
const auto* yPos = reinterpret_cast<float32*>(m_Reader->getPointerByName(EbsdLib::Ang::YPosition));
177+
178+
float32 minX = *std::min_element(xPos, xPos + totalCells);
179+
float32 minY = *std::min_element(yPos, yPos + totalCells);
180+
181+
imageGeom.setOrigin(minX, minY, 0.0f);
182+
183+
return {};
184+
}
160185

161186
protected:
162187
std::shared_ptr<T> m_Reader;

0 commit comments

Comments
 (0)