Skip to content

Commit e084926

Browse files
committed
ENH: H5OINA Reader Implementation
Signed-off-by: Michael Jackson <mike.jackson@bluequartz.net>
1 parent 4c85341 commit e084926

File tree

9 files changed

+1399
-11
lines changed

9 files changed

+1399
-11
lines changed

Source/EbsdLib/IO/EbsdReader.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ class EbsdLib_EXPORT EbsdReader
143143
* Different manufacturers call this value different thingsl. TSL = NumRows | NumCols,
144144
* HKL=XCells. These methods should be implemented by subclasses to return the proper value.
145145
*/
146+
146147
/**
147148
* @brief Returns the X Dimension of the data. This method is pure virtual
148149
* and should be implemented by subclasses.

Source/EbsdLib/IO/HKL/CtfConstants.h

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,4 +192,82 @@ const std::string MaterialName("MaterialName");
192192
const std::string LatticeConstants("LatticeConstants");
193193
const std::string BravaisLattice("BravaisLattice");
194194
} // namespace CtfFile
195+
196+
197+
//-----------------------------------------------------------------------------
198+
// https://github.com/oinanoanalysis/h5oina/blob/master/H5OINAFile.md#ebsd-data
199+
//-----------------------------------------------------------------------------
200+
namespace H5OINA
201+
{
202+
203+
const std::string H5FileExt("h5oina");
204+
const std::string Index("Index");
205+
const std::string FormatVersion("Format Version"); // String 2.0 is the earliest that I seem to have
206+
const std::string Manufacturer("Manufacturer"); // String
207+
const std::string SoftwareVersion("Software Version"); // String
208+
209+
const std::string FormatVersion_2("2.0");
210+
const std::string FormatVersion_3("3.0");
211+
const std::string FormatVersion_4("4.0");
212+
const std::string FormatVersion_5("5.0");
213+
214+
//-----------------------------------------------------------------------------
215+
// These are for header names in the hdf5 file
216+
// Format Version: 2
217+
//-----------------------------------------------------------------------------
218+
const std::string Header("Header");
219+
const std::string AcquisitionData("Acquisition Date");
220+
const std::string AcquisitionSpeed("Acquisition Speed");
221+
const std::string AcquisitionTime("Acquisition Time");
222+
const std::string BeamVoltage("Beam Voltage");
223+
const std::string DetectorOrientationEuler("Detector Orientation Euler");
224+
const std::string Magnification("Magnification");
225+
const std::string ProjectFile("Project File");
226+
const std::string ProjectLabel("Project Label");
227+
const std::string ProjectNotes("Project Notes");
228+
const std::string ScanningRotationAngle("Scanning Rotation Angle");
229+
const std::string SiteNotes("Site Notes");
230+
const std::string SpecimenOrientationEuler("Specimen Orientation Euler");
231+
const std::string TiltAngle("Tilt Angle");
232+
const std::string TiltAxis("Tilt Axis");
233+
const std::string XCells("X Cells");
234+
const std::string XStep("X Step");
235+
const std::string YCells("Y Cells");
236+
const std::string YStep("Y Step");
237+
// Phase Headers: Format Version 2
238+
const std::string Phases("Phases");
239+
const std::string Color("Color");
240+
const std::string LatticeAngles("Lattice Angles");
241+
const std::string LatticeDimensions("Lattice Dimensions");
242+
const std::string LaueGroup("Laue Group");
243+
const std::string NumberReflectors("Number Reflectors");
244+
const std::string PhaseName("Phase Name");
245+
const std::string Reference("Reference");
246+
const std::string SpaceGroup("Space Group");
247+
// Data: Format Version 2
248+
const std::string EBSD("EBSD");
249+
const std::string Data("Data");
250+
const std::string BandContrast("Band Contrast"); // uint8
251+
const std::string BandSlope("Band Slope"); // uint8
252+
const std::string Bands("Bands"); // uint8
253+
const std::string Error("Error"); // uint8
254+
const std::string Euler("Euler"); // 3xFloat32
255+
const std::string MeanAngularDeviation("Mean Angular Deviation"); // Float
256+
const std::string Phase("Phase"); // uint8
257+
const std::string X("X"); // uint8
258+
const std::string Y("Y"); // uint8
259+
260+
261+
// Data Format Version 5
262+
263+
const std::string UnprocessedPatterns("Unprocessed Patterns");
264+
const std::string ProcessedPatterns("Processed Patterns");
265+
266+
267+
268+
269+
270+
271+
}
272+
195273
} // namespace EbsdLib

Source/EbsdLib/IO/HKL/DataParser.hpp

Lines changed: 210 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,111 @@ class DataParser
116116
DataParser& operator=(const DataParser&) = delete; // Copy Assignment Not Implemented
117117
DataParser& operator=(DataParser&&) = delete; // Move Assignment Not Implemented
118118
};
119+
// -----------------------------------------------------------------------------
120+
//
121+
// -----------------------------------------------------------------------------
122+
class UInt8Parser : public DataParser
123+
{
124+
public:
125+
using Self = UInt8Parser;
126+
using Pointer = std::shared_ptr<Self>;
127+
using ConstPointer = std::shared_ptr<const Self>;
128+
using WeakPointer = std::weak_ptr<Self>;
129+
using ConstWeakPointer = std::weak_ptr<Self>;
130+
static Pointer NullPointer()
131+
{
132+
return Pointer(static_cast<Self*>(nullptr));
133+
}
134+
135+
/**
136+
* @brief Returns the name of the class for AbstractMessage
137+
*/
138+
std::string getNameOfClass() const
139+
{
140+
return std::string("UInt8Parser");
141+
}
142+
/**
143+
* @brief Returns the name of the class for AbstractMessage
144+
*/
145+
static std::string ClassName()
146+
{
147+
return std::string("UInt8Parser");
148+
}
149+
150+
int32_t IsA() const override
151+
{
152+
return 1;
153+
}
154+
155+
static Pointer New(uint8_t* ptr, size_t size, const std::string& name, int index)
156+
{
157+
Pointer sharedPtr(new UInt8Parser(ptr, size, name, index));
158+
return sharedPtr;
159+
}
160+
161+
~UInt8Parser() override
162+
{
163+
if(m_Ptr != nullptr && getManageMemory())
164+
{
165+
delete[] m_Ptr;
166+
m_Ptr = nullptr;
167+
}
168+
}
169+
170+
void setPtr(uint8_t* value)
171+
{
172+
this->m_Ptr = value;
173+
}
174+
uint8_t* getPtr()
175+
{
176+
return m_Ptr;
177+
}
178+
179+
bool allocateArray(size_t numberOfElements) override
180+
{
181+
m_Ptr = new(std::nothrow) uint8_t[numberOfElements]();
182+
return (m_Ptr != nullptr);
183+
}
184+
185+
void* getVoidPointer() override
186+
{
187+
return reinterpret_cast<void*>(m_Ptr);
188+
}
189+
void setVoidPointer(void* p) override
190+
{
191+
m_Ptr = reinterpret_cast<uint8_t*>(p);
192+
}
193+
194+
uint8_t* getPointer(size_t offset)
195+
{
196+
return m_Ptr + offset;
197+
}
198+
199+
void parse(const std::string& token, size_t index) override
200+
{
201+
EBSD_INDEX_OUT_OF_RANGE(index < getSize());
202+
m_Ptr[index] = std::stoi(token);
203+
}
204+
205+
protected:
206+
UInt8Parser(uint8_t* ptr, size_t size, const std::string& name, int index)
207+
: m_Ptr(ptr)
208+
{
209+
setManageMemory(true);
210+
setSize(size);
211+
setColumnName(name);
212+
setColumnIndex(index);
213+
}
214+
215+
private:
216+
uint8_t* m_Ptr;
217+
218+
public:
219+
UInt8Parser(const UInt8Parser&) = delete; // Copy Constructor Not Implemented
220+
UInt8Parser(UInt8Parser&&) = delete; // Move Constructor Not Implemented
221+
UInt8Parser& operator=(const UInt8Parser&) = delete; // Copy Assignment Not Implemented
222+
UInt8Parser& operator=(UInt8Parser&&) = delete; // Move Assignment Not Implemented
223+
};
119224

120225
// -----------------------------------------------------------------------------
121226
//
@@ -223,8 +328,7 @@ class Int32Parser : public DataParser
223328
Int32Parser& operator=(Int32Parser&&) = delete; // Move Assignment Not Implemented
224329
};
225330

226-
// -----------------------------------------------------------------------------
227-
//
331+
228332
// -----------------------------------------------------------------------------
229333
class FloatParser : public DataParser
230334
{
@@ -327,3 +431,107 @@ class FloatParser : public DataParser
327431
FloatParser& operator=(const FloatParser&) = delete; // Copy Assignment Not Implemented
328432
FloatParser& operator=(FloatParser&&) = delete; // Move Assignment Not Implemented
329433
};
434+
435+
template<typename T>
436+
class NumericParser : public DataParser
437+
{
438+
public:
439+
using Self = NumericParser<T>;
440+
using Pointer = std::shared_ptr<Self>;
441+
using ConstPointer = std::shared_ptr<const Self>;
442+
using WeakPointer = std::weak_ptr<Self>;
443+
using ConstWeakPointer = std::weak_ptr<Self>;
444+
static Pointer NullPointer()
445+
{
446+
return Pointer(static_cast<Self*>(nullptr));
447+
}
448+
449+
/**
450+
* @brief Returns the name of the class for AbstractMessage
451+
*/
452+
const std::string getNameOfClass() const
453+
{
454+
return std::string("NumericParser");
455+
}
456+
/**
457+
* @brief Returns the name of the class for AbstractMessage
458+
*/
459+
static std::string ClassName()
460+
{
461+
return std::string("NumericParser");
462+
}
463+
464+
int32_t IsA() const override
465+
{
466+
return 2;
467+
}
468+
469+
static Pointer New(T* ptr, size_t size, const std::string& name, int index)
470+
{
471+
Pointer sharedPtr(new NumericParser<T>(ptr, size, name, index));
472+
return sharedPtr;
473+
}
474+
475+
~NumericParser() override
476+
{
477+
if(m_Ptr != nullptr && getManageMemory())
478+
{
479+
delete[] m_Ptr;
480+
m_Ptr = nullptr;
481+
}
482+
}
483+
484+
void setPtr(T* value)
485+
{
486+
this->m_Ptr = value;
487+
}
488+
T* getPtr()
489+
{
490+
return m_Ptr;
491+
}
492+
493+
bool allocateArray(size_t numberOfElements) override
494+
{
495+
m_Ptr = new(std::nothrow) T[numberOfElements]();
496+
return (m_Ptr != nullptr);
497+
}
498+
499+
void* getVoidPointer() override
500+
{
501+
return reinterpret_cast<void*>(m_Ptr);
502+
}
503+
void setVoidPointer(void* p) override
504+
{
505+
m_Ptr = reinterpret_cast<T*>(p);
506+
}
507+
508+
T* getPointer(size_t offset)
509+
{
510+
return m_Ptr + offset;
511+
}
512+
513+
void parse(const std::string& token, size_t index) override
514+
{
515+
m_Ptr[index] = std::stof(token);
516+
}
517+
518+
protected:
519+
NumericParser<T>(T* ptr, size_t size, const std::string& name, int index)
520+
: m_Ptr(ptr)
521+
{
522+
setManageMemory(true);
523+
setSize(size);
524+
setColumnName(name);
525+
setColumnIndex(index);
526+
}
527+
528+
private:
529+
T* m_Ptr;
530+
531+
public:
532+
NumericParser<T>(const NumericParser<T>&) = delete; // Copy Constructor Not Implemented
533+
NumericParser<T>(NumericParser<T>&&) = delete; // Move Constructor Not Implemented
534+
NumericParser<T>& operator=(const NumericParser<T>&) = delete; // Copy Assignment Not Implemented
535+
NumericParser<T>& operator=(NumericParser<T>&&) = delete; // Move Assignment Not Implemented
536+
};
537+

0 commit comments

Comments
 (0)