Skip to content

Commit

Permalink
DOC: Update docs, add comments to source codes. Adjust human name of …
Browse files Browse the repository at this point in the history
…filter

Signed-off-by: Michael Jackson <[email protected]>
  • Loading branch information
imikejackson committed Oct 17, 2023
1 parent a852211 commit 6efcdc4
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 72 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,32 +8,18 @@ Sampling (Resolution)

This **Filter** will convert TSL .ang files on hexagonal grids to TSL .ang files on square grids by means of interpolation between points. Note that the resulting square grid .ang files may have more or less rows of data and that some data may be interpolated based on its neighbor data. By default, the spacing of the square grid will be the spacing between columns in the hexagonal grid.

This **Filter** is useful since most DREAM.3D routines for analyzing Ebsd data require a square grid. After using this **Filter** to bulk convert the TSL .ang files to square grids, it is suggested to use the [Import Orientation File(s) to H5Ebsd](EbsdToH5Ebsd.html "") **Filter** to convert the square grid .ang files to the H5Ebsd format. The user can then use the [Read H5Ebsd File](ReadH5Ebsd.html "") **Filter** to import the H5Ebsd file into DREAM.3D for analysis.
This **Filter** is useful since most DREAM3D-NX routines for analyzing Ebsd data require a square grid. After using this **Filter** to bulk convert the EDAX/TSL .ang files to square grids, it is suggested to use the {ref}`Import Orientation File(s) to H5Ebsd <OrientationAnalysis/EbsdToH5EbsdFilter:Description>` **Filter** to convert the square grid .ang files to the H5Ebsd format. The user can then use the {ref}`Read H5Ebsd File <OrientationAnalysis/ReadH5EbsdFilter:Description>` **Filter** to import the H5Ebsd file into DREAM.3D for analysis.

The use of this **Filter** is similar to the use of the [Import Orientation File(s) to H5Ebsd](EbsdToH5Ebsd.html "") **Filter**. Please consult that **Filter's** documentation for a detailed description of the various user interface elements. Note that unlike the [Import Orientation File(s) to H5Ebsd](EbsdToH5Ebsd.html "") **Filter**, this **Filter** does not require either the _Stacking Order_ or the _Reference Frame_ to be modified.
The use of this **Filter** is similar to the use of the {ref}`Import Orientation File(s) to H5Ebsd <OrientationAnalysis/EbsdToH5EbsdFilter:Description>` **Filter**. Please consult that **Filter's** documentation for a detailed description of the various user interface elements. Note that unlike the {ref}`Import Orientation File(s) to H5Ebsd <OrientationAnalysis/EbsdToH5EbsdFilter:Description>` **Filter**, this **Filter** does not require either the *Stacking Order* or the *Reference Frame* to be modified.

## Parameters

See Description

## Required Geometry

Not Applicable

## Required Objects

None

## Created Objects

None
% Auto generated parameter table will be inserted here

## Example Pipelines

## License & Copyright

Please see the description file distributed with this **Plugin**

## DREAM3DNX Help
## DREAM3D-NX Help

Check out our GitHub community page at [DREAM3DNX-Issues](https://github.com/BlueQuartzSoftware/DREAM3DNX-Issues) to report bugs, ask the community for help, discuss features, or get help from the developers.
If you need help, need to file a bug report or want to request a new feature, please head over to the [DREAM3DNX-Issues](https://github.com/BlueQuartzSoftware/DREAM3DNX-Issues) GItHub site where the community of DREAM3D-NX users can help answer your questions.
10 changes: 10 additions & 0 deletions src/Plugins/OrientationAnalysis/docs/ReadAngDataFilter.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,16 @@ If the data has come from a TSL acquisition system and the settings of the acqui

The user also may want to assign un-indexed pixels to be ignored by flagging them as "bad". The Threshold Objects **Filter** can be used to define this *mask* by thresholding on values such as *Confidence Index* > 0.1 or *Image Quality* > desired quality.

### Note About Sample Grid

OIMAnalysis can create EBSD data sampled on a hexagonal grid. The user can look in the .ang file into the header (those lines starting with the "#" character) for a line that is:

```text
# GRID: HexGrid
```

If the user's .ang files are hexagonal grid files then they will need to run the {ref}`Convert EDAX Hex Grid to Square Grid (.ang)<OrientationAnalysis/ConvertHexGridToSquareGridFilter:Description>` filter to first convert the input files square gridded files.

% Auto generated parameter table will be inserted here

## Example Pipelines
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ class Converter
: m_ShouldCancel(shouldCancel)
, m_OutputPath(outputDirPath)
, m_FilePrefix(outputFilePrefix)
, m_XResolution(spacingXY.at(0))
, m_YResolution(spacingXY.at(1))
, m_SqrXStep(spacingXY.at(0))
, m_SqrYStep(spacingXY.at(1))
{
}
~Converter() noexcept = default;
Expand Down Expand Up @@ -63,7 +63,7 @@ class Converter
std::string origHeader = reader.getOriginalHeader();
if(origHeader.empty())
{
return MakeErrorResult(-55001, fmt::format("Header could not be retrieved: {}", inputPath.string()));
return MakeErrorResult(-55001, fmt::format("Header for input hex grid file was empty: {}", inputPath.string()));
}

std::istringstream headerStream(origHeader, std::ios_base::in | std::ios_base::binary);
Expand All @@ -88,17 +88,15 @@ class Converter

m_HeaderIsComplete = false;

float32 HexXStep = reader.getXStep();
float32 HexYStep = reader.getYStep();
int32 HexNumColsOdd = reader.getNumOddCols();
int32 HexNumColsEven = reader.getNumEvenCols();
int32 HexNumRows = reader.getNumRows();
m_NumCols = static_cast<int32>((static_cast<float32>(HexNumColsOdd) * HexXStep) / m_XResolution);
m_NumRows = static_cast<int32>((static_cast<float32>(HexNumRows) * HexYStep) / m_YResolution);
float32 xSqr, ySqr, xHex1, yHex1, xHex2, yHex2;
int32 point, point1, point2;
int32 row1, row2, col1, col2;
float32 dist1, dist2;
float32 hexXStep = reader.getXStep();
float32 hexYStep = reader.getYStep();
int32 hexNumColsOdd = reader.getNumOddCols();
int32 hexNumColsEven = reader.getNumEvenCols();
int32 hexNumRows = reader.getNumRows();
m_SqrNumCols = static_cast<int32>((static_cast<float32>(hexNumColsOdd) * hexXStep) / m_SqrXStep);
m_SqrNumRows = static_cast<int32>((static_cast<float32>(hexNumRows) * hexYStep) / m_SqrYStep);

// Get the hex grid data from the input file
float32* phi1 = reader.getPhi1Pointer();
float32* PHI = reader.getPhiPointer();
float32* phi2 = reader.getPhi2Pointer();
Expand All @@ -107,6 +105,9 @@ class Converter
float32* semSig = reader.getSEMSignalPointer();
float32* fit = reader.getFitPointer();
int32* phase = reader.getPhaseDataPointer();

// Loop on the header part of the file and modify the header while writing to the output file
// the updated information
while(!headerStream.eof())
{
std::string buf;
Expand All @@ -121,50 +122,69 @@ class Converter
outFile << line << "\n";
}
}
for(int32 j = 0; j < m_NumRows; j++)

// Reusable variables for the loop
int32 hexGridIndex, hexGridIndex1, hexGridIndex2;
float32 xHex1, xHex2;

// Now loop on every cell in the replacement square grid
for(int32 j = 0; j < m_SqrNumRows; j++)
{
if(m_ShouldCancel)
{
return {};
}
for(int32 i = 0; i < m_NumCols; i++)
for(int32 i = 0; i < m_SqrNumCols; i++)
{
xSqr = static_cast<float32>(static_cast<float32>(i) * m_XResolution);
ySqr = static_cast<float32>(static_cast<float32>(j) * m_YResolution);
row1 = static_cast<int32>(ySqr / (HexYStep));
yHex1 = static_cast<float32>(row1) * HexYStep;
row2 = row1 + 1;
yHex2 = static_cast<float32>(row2) * HexYStep;
if(row1 % 2 == 0)
// Calculate the center point of the current Square grid cell
float32 xSqr = static_cast<float32>(i) * m_SqrXStep;
float32 ySqr = static_cast<float32>(j) * m_SqrYStep;

// Calculate hex grid rows that will be used to for the conversion for this square grid point
int32 hexRowIndex1 = static_cast<int32>(ySqr / hexYStep);
float32 yHex1 = static_cast<float32>(hexRowIndex1) * hexYStep;

int32 hexRowIndex2 = hexRowIndex1 + 1;
float32 yHex2 = static_cast<float32>(hexRowIndex2) * hexYStep;

// If we are on an even row
if(hexRowIndex1 % 2 == 0)
{
col1 = static_cast<int32>(xSqr / (HexXStep));
xHex1 = static_cast<float32>(col1) * HexXStep;
point1 = ((row1 / 2) * HexNumColsEven) + ((row1 / 2) * HexNumColsOdd) + col1;
col2 = static_cast<int32>((xSqr - (HexXStep / 2.0)) / (HexXStep));
xHex2 = static_cast<float32>(static_cast<float32>(col2) * HexXStep + (HexXStep / 2.0));
point2 = ((row1 / 2) * HexNumColsEven) + (((row1 / 2) + 1) * HexNumColsOdd) + col2;
int32 hexGridColIndex1 = static_cast<int32>(xSqr / (hexXStep)); // Compute the hex column index that the square grid coord falls into
xHex1 = static_cast<float32>(hexGridColIndex1) * hexXStep; // Compute the X Hex Grid coordinate
hexGridIndex1 = ((hexRowIndex1 / 2) * hexNumColsEven) + ((hexRowIndex1 / 2) * hexNumColsOdd) + hexGridColIndex1; // Compute the index into hex grid data

int32 hexGridColIndex2 = static_cast<int32>((xSqr - (hexXStep / 2.0)) / (hexXStep));
xHex2 = static_cast<float32>(static_cast<float32>(hexGridColIndex2) * hexXStep + (hexXStep / 2.0));
hexGridIndex2 = ((hexRowIndex1 / 2) * hexNumColsEven) + (((hexRowIndex1 / 2) + 1) * hexNumColsOdd) + hexGridColIndex2;
}
else
else // If we are on an odd row
{
col1 = static_cast<int32>((xSqr - (HexXStep / 2.0)) / (HexXStep));
xHex1 = static_cast<float32>(static_cast<float32>(col1) * HexXStep + (HexXStep / 2.0));
point1 = ((row1 / 2) * HexNumColsEven) + (((row1 / 2) + 1) * HexNumColsOdd) + col1;
col2 = static_cast<int32>(xSqr / HexXStep);
xHex2 = static_cast<float32>(col2) * HexXStep;
point2 = (((row1 / 2) + 1) * HexNumColsEven) + (((row1 / 2) + 1) * HexNumColsOdd) + col2;
int32 hexGridColIndex1 = static_cast<int32>((xSqr - (hexXStep / 2.0)) / (hexXStep));
xHex1 = static_cast<float32>(static_cast<float32>(hexGridColIndex1) * hexXStep + (hexXStep / 2.0));
hexGridIndex1 = ((hexRowIndex1 / 2) * hexNumColsEven) + (((hexRowIndex1 / 2) + 1) * hexNumColsOdd) + hexGridColIndex1;

int32 hexGridColIndex2 = static_cast<int32>(xSqr / hexXStep);
xHex2 = static_cast<float32>(hexGridColIndex2) * hexXStep;
hexGridIndex2 = (((hexRowIndex1 / 2) + 1) * hexNumColsEven) + (((hexRowIndex1 / 2) + 1) * hexNumColsOdd) + hexGridColIndex2;
}
dist1 = ((xSqr - xHex1) * (xSqr - xHex1)) + ((ySqr - yHex1) * (ySqr - yHex1));
dist2 = ((xSqr - xHex2) * (xSqr - xHex2)) + ((ySqr - yHex2) * (ySqr - yHex2));
if(dist1 <= dist2 || row1 == (HexNumRows - 1))

// Compute the distance from the square grid coordinate to the hex grid coordinate.
float32 dist1 = ((xSqr - xHex1) * (xSqr - xHex1)) + ((ySqr - yHex1) * (ySqr - yHex1));
float32 dist2 = ((xSqr - xHex2) * (xSqr - xHex2)) + ((ySqr - yHex2) * (ySqr - yHex2));
// Select the closest hex grid point.
if(dist1 <= dist2 || hexRowIndex1 == (hexNumRows - 1))
{
point = point1;
hexGridIndex = hexGridIndex1;
}
else
{
point = point2;
hexGridIndex = hexGridIndex2;
}
outFile << " " << phi1[point] << " " << PHI[point] << " " << phi2[point] << " " << xSqr << " " << ySqr << " " << iq[point] << " " << ci[point] << " " << phase[point] << " "
<< semSig[point] << " " << fit[point] << " "

// Write to the output file
outFile << " " << phi1[hexGridIndex] << " " << PHI[hexGridIndex] << " " << phi2[hexGridIndex] << " " << xSqr << " " << ySqr << " " << iq[hexGridIndex] << " " << ci[hexGridIndex]
<< " " << phase[hexGridIndex] << " " << semSig[hexGridIndex] << " " << fit[hexGridIndex] << " "
<< "\n";
}
}
Expand All @@ -177,11 +197,11 @@ class Converter
const std::atomic_bool& m_ShouldCancel;
const fs::path& m_OutputPath;
const std::string& m_FilePrefix;
const float32 m_XResolution;
const float32 m_YResolution;

int32 m_NumCols = 0;
int32 m_NumRows = 0;
const float32 m_SqrXStep;
const float32 m_SqrYStep;
int32 m_SqrNumCols = 0;
int32 m_SqrNumRows = 0;
bool m_HeaderIsComplete = false;

// -----------------------------------------------------------------------------
Expand Down Expand Up @@ -232,23 +252,23 @@ class Converter
}
else if(StringUtilities::contains(buf, EbsdLib::Ang::XStep))
{
line = "# " + EbsdLib::Ang::XStep + ": " + StringUtilities::number(m_XResolution);
line = "# " + EbsdLib::Ang::XStep + ": " + StringUtilities::number(m_SqrXStep);
}
else if(StringUtilities::contains(buf, EbsdLib::Ang::YStep))
{
line = "# " + EbsdLib::Ang::YStep + ": " + StringUtilities::number(m_YResolution);
line = "# " + EbsdLib::Ang::YStep + ": " + StringUtilities::number(m_SqrYStep);
}
else if(StringUtilities::contains(buf, EbsdLib::Ang::NColsOdd))
{
line = "# " + EbsdLib::Ang::NColsOdd + ": " + StringUtilities::number(m_NumCols);
line = "# " + EbsdLib::Ang::NColsOdd + ": " + StringUtilities::number(m_SqrNumCols);
}
else if(StringUtilities::contains(buf, EbsdLib::Ang::NColsEven))
{
line = "# " + EbsdLib::Ang::NColsEven + ": " + StringUtilities::number(m_NumCols);
line = "# " + EbsdLib::Ang::NColsEven + ": " + StringUtilities::number(m_SqrNumCols);
}
else if(StringUtilities::contains(buf, EbsdLib::Ang::NRows))
{
line = "# " + EbsdLib::Ang::NRows + ": " + StringUtilities::number(m_NumRows);
line = "# " + EbsdLib::Ang::NRows + ": " + StringUtilities::number(m_SqrNumRows);
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ Uuid ConvertHexGridToSquareGridFilter::uuid() const
//------------------------------------------------------------------------------
std::string ConvertHexGridToSquareGridFilter::humanName() const
{
return "Convert Hexagonal Grid Data to Square Grid Data (TSL - .ang)";
return "Convert EDAX Hex Grid to Square Grid (.ang)";
}

//------------------------------------------------------------------------------
Expand Down

0 comments on commit 6efcdc4

Please sign in to comment.