Skip to content

Commit

Permalink
Refactor the IPF Coloring algorithm to share algorithm
Browse files Browse the repository at this point in the history
All Laue classes now call a protected member method of LaueClass to compute the
IPF Color

Signed-off-by: Michael Jackson <[email protected]>
  • Loading branch information
imikejackson committed Aug 29, 2024
1 parent fe84d21 commit 1903ee9
Show file tree
Hide file tree
Showing 24 changed files with 364 additions and 828 deletions.
101 changes: 23 additions & 78 deletions Source/EbsdLib/LaueOps/CubicLowOps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@
#include "EbsdLib/Math/EbsdLibMath.h"
#include "EbsdLib/Utilities/ColorTable.h"
#include "EbsdLib/Utilities/ComputeStereographicProjection.h"
#include "EbsdLib/Utilities/ModifiedLambertProjection.h"
#include "EbsdLib/Utilities/EbsdStringUtils.hpp"
#include "EbsdLib/Utilities/ModifiedLambertProjection.h"

namespace CubicLow
{
Expand Down Expand Up @@ -155,6 +155,8 @@ static const double MatSym[k_SymOpsCount][3][3] = {

};
// clang-format on
static const double k_EtaMin = 0.0;
static const double k_EtaMax = 45.0;
} // namespace CubicLow

// -----------------------------------------------------------------------------
Expand Down Expand Up @@ -867,11 +869,8 @@ void _TripletSort(T a, T b, T c, T& x, T& y, T& z)
z = c;
}
}

// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
bool CubicLowOps::inUnitTriangle(double eta, double chi) const
std::array<double, 3> CubicLowOps::getIpfColorAngleLimits(double eta) const
{
double etaDeg = eta * EbsdLib::Constants::k_180OverPiD;
double chiMax;
Expand All @@ -885,62 +884,14 @@ bool CubicLowOps::inUnitTriangle(double eta, double chi) const
}
EbsdLibMath::bound(chiMax, -1.0, 1.0);
chiMax = acos(chiMax);
return !(eta < 0.0 || eta > (90.0 * EbsdLib::Constants::k_PiOver180D) || chi < 0.0 || chi > chiMax);
}

// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
EbsdLib::Rgb CubicLowOps::generateIPFColor(double* eulers, double* refDir, bool convertDegrees) const
{
return generateIPFColor(eulers[0], eulers[1], eulers[2], refDir[0], refDir[1], refDir[2], convertDegrees);
return {CubicLow::k_EtaMin * EbsdLib::Constants::k_DegToRadD, CubicLow::k_EtaMax * EbsdLib::Constants::k_DegToRadD, chiMax};
}

// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
EbsdLib::Rgb CubicLowOps::generateIPFColor(double phi1, double phi, double phi2, double refDir0, double refDir1, double refDir2, bool degToRad) const
bool CubicLowOps::inUnitTriangle(double eta, double chi) const
{
if(degToRad)
{
phi1 = phi1 * EbsdLib::Constants::k_DegToRadD;
phi = phi * EbsdLib::Constants::k_DegToRadD;
phi2 = phi2 * EbsdLib::Constants::k_DegToRadD;
}

EbsdLib::Matrix3X1D refDirection = {refDir0, refDir1, refDir2};
double chi = 0.0f;
double eta = 0.0f;
double _rgb[3] = {0.0, 0.0, 0.0};

OrientationType eu(phi1, phi, phi2);
OrientationType om(9); // Reusable for the loop
QuatD q1 = OrientationTransformation::eu2qu<OrientationType, QuatD>(eu);

for(int j = 0; j < CubicLow::k_SymOpsCount; j++)
{
QuatD qu = getQuatSymOp(j) * q1;
EbsdLib::Matrix3X3D g(OrientationTransformation::qu2om<QuatD, OrientationType>(qu).data());
EbsdLib::Matrix3X1D p = (g * refDirection).normalize();

if(!getHasInversion() && p[2] < 0)
{
continue;
}
if(getHasInversion() && p[2] < 0)
{
p = p * -1.0;
}
chi = std::acos(p[2]);
eta = std::atan2(p[1], p[0]);
if(!inUnitTriangle(eta, chi))
{
continue;
}
break;
}
double etaMin = 0.0;
double etaMax = 90.0;
double etaDeg = eta * EbsdLib::Constants::k_180OverPiD;
double chiMax;
if(etaDeg > 45.0)
Expand All @@ -953,31 +904,25 @@ EbsdLib::Rgb CubicLowOps::generateIPFColor(double phi1, double phi, double phi2,
}
EbsdLibMath::bound(chiMax, -1.0, 1.0);
chiMax = acos(chiMax);
return !(eta < CubicLow::k_EtaMin || eta > (CubicLow::k_EtaMax * EbsdLib::Constants::k_PiOver180D) || chi < 0.0 || chi > chiMax);
}

_rgb[0] = 1.0 - chi / chiMax;
_rgb[2] = std::fabs(etaDeg - etaMin) / (etaMax - etaMin);
_rgb[1] = 1 - _rgb[2];
_rgb[1] *= chi / chiMax;
_rgb[2] *= chi / chiMax;
_rgb[0] = sqrt(_rgb[0]);
_rgb[1] = sqrt(_rgb[1]);
_rgb[2] = sqrt(_rgb[2]);

double max = _rgb[0];
if(_rgb[1] > max)
{
max = _rgb[1];
}
if(_rgb[2] > max)
{
max = _rgb[2];
}

_rgb[0] = _rgb[0] / max;
_rgb[1] = _rgb[1] / max;
_rgb[2] = _rgb[2] / max;
// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
EbsdLib::Rgb CubicLowOps::generateIPFColor(double* eulers, double* refDir, bool degToRad) const
{
return computeIPFColor(eulers, refDir, degToRad);
}

return EbsdLib::RgbColor::dRgb(static_cast<int32_t>(_rgb[0] * 255), static_cast<int32_t>(_rgb[1] * 255), static_cast<int32_t>(_rgb[2] * 255), 255);
// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
EbsdLib::Rgb CubicLowOps::generateIPFColor(double phi1, double phi, double phi2, double refDir0, double refDir1, double refDir2, bool degToRad) const
{
double eulers[3] = {phi1, phi, phi2};
double refDir[3] = {refDir0, refDir1, refDir2};
return computeIPFColor(eulers, refDir, degToRad);
}

// -----------------------------------------------------------------------------
Expand Down
7 changes: 6 additions & 1 deletion Source/EbsdLib/LaueOps/CubicLowOps.h
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,12 @@ class EbsdLib_EXPORT CubicLowOps : public LaueOps
double getF7(const QuatD& q1, const QuatD& q2, double LD[3], bool maxSF) const override;

void generateSphereCoordsFromEulers(EbsdLib::FloatArrayType* eulers, EbsdLib::FloatArrayType* xyz001, EbsdLib::FloatArrayType* xyz011, EbsdLib::FloatArrayType* xyz111) const override;

/**
* @brief
* @param eta Optional input value only needed for the "Cubic" Laue classes
* @return Triplet of etaMin, etaMax, chiMax
*/
std::array<double, 3> getIpfColorAngleLimits(double eta) const override;
/**
* @brief generateIPFColor Generates an RGB Color from a Euler Angle and Reference Direction
* @param eulers Pointer to the 3 component Euler Angle
Expand Down
109 changes: 28 additions & 81 deletions Source/EbsdLib/LaueOps/CubicOps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@
#include "EbsdLib/Core/Orientation.hpp"
#include "EbsdLib/Math/EbsdLibMath.h"
#include "EbsdLib/Math/GeometryMath.h"
#include "EbsdLib/Utilities/ColorTable.h"
#include "EbsdLib/Utilities/ColorUtilities.h"
#include "EbsdLib/Utilities/ComputeStereographicProjection.h"
#include "EbsdLib/Utilities/EbsdStringUtils.hpp"
#include "EbsdLib/Utilities/ColorTable.h"

namespace CubicHigh
{
Expand Down Expand Up @@ -235,6 +235,9 @@ static const double MatSym[k_SymOpsCount][3][3] = {

};
// clang-format on
static const double k_EtaMin = 0.0;
static const double k_EtaMax = 45.0;

} // namespace CubicHigh

// -----------------------------------------------------------------------------
Expand Down Expand Up @@ -1678,13 +1681,11 @@ bool inUnitTriangleD(double eta, double chi)
}

// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
bool CubicOps::inUnitTriangle(double eta, double chi) const
std::array<double, 3> CubicOps::getIpfColorAngleLimits(double eta) const
{
double etaDeg = eta * EbsdLib::Constants::k_180OverPiD;
double chiMax;
if(etaDeg > 45.0)
if(etaDeg > CubicHigh::k_EtaMax)
{
chiMax = std::sqrt(1.0 / (2.0 + std::tan(0.5 * EbsdLib::Constants::k_PiD - eta) * std::tan(0.5 * EbsdLib::Constants::k_PiD - eta)));
}
Expand All @@ -1693,66 +1694,18 @@ bool CubicOps::inUnitTriangle(double eta, double chi) const
chiMax = std::sqrt(1.0 / (2.0 + std::tan(eta) * std::tan(eta)));
}
EbsdLibMath::bound(chiMax, -1.0, 1.0);
chiMax = acos(chiMax);
return !(eta < 0.0 || eta > (45.0 * EbsdLib::Constants::k_PiOver180D) || chi < 0.0 || chi > chiMax);
}

// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
EbsdLib::Rgb CubicOps::generateIPFColor(double* eulers, double* refDir, bool convertDegrees) const
{
return generateIPFColor(eulers[0], eulers[1], eulers[2], refDir[0], refDir[1], refDir[2], convertDegrees);
chiMax = std::acos(chiMax);
return {CubicHigh::k_EtaMin * EbsdLib::Constants::k_DegToRadD, CubicHigh::k_EtaMax * EbsdLib::Constants::k_DegToRadD, chiMax};
}

// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
EbsdLib::Rgb CubicOps::generateIPFColor(double phi1, double phi, double phi2, double refDir0, double refDir1, double refDir2, bool degToRad) const
bool CubicOps::inUnitTriangle(double eta, double chi) const
{
if(degToRad)
{
phi1 = phi1 * EbsdLib::Constants::k_DegToRadD;
phi = phi * EbsdLib::Constants::k_DegToRadD;
phi2 = phi2 * EbsdLib::Constants::k_DegToRadD;
}

EbsdLib::Matrix3X1D refDirection = {refDir0, refDir1, refDir2};
double chi = 0.0f;
double eta = 0.0f;
double _rgb[3] = {0.0, 0.0, 0.0};

OrientationType eu(phi1, phi, phi2);
OrientationType om(9); // Reusable for the loop
QuatD q1 = OrientationTransformation::eu2qu<OrientationType, QuatD>(eu);

for(int j = 0; j < CubicHigh::k_SymOpsCount; j++)
{
QuatD qu = getQuatSymOp(j) * q1;
EbsdLib::Matrix3X3D g(OrientationTransformation::qu2om<QuatD, OrientationType>(qu).data());
EbsdLib::Matrix3X1D p = (g * refDirection).normalize();

if(!getHasInversion() && p[2] < 0)
{
continue;
}
if(getHasInversion() && p[2] < 0)
{
p = p * -1.0;
}
chi = std::acos(p[2]);
eta = std::atan2(p[1], p[0]);
if(!inUnitTriangleD(eta, chi))
{
continue;
}
break;
}
double etaMin = 0.0;
double etaMax = 45.0;
double etaDeg = eta * EbsdLib::Constants::k_180OverPiD;
double chiMax;
if(etaDeg > 45.0)
if(etaDeg > CubicHigh::k_EtaMax)
{
chiMax = std::sqrt(1.0 / (2.0 + std::tan(0.5 * EbsdLib::Constants::k_PiD - eta) * std::tan(0.5 * EbsdLib::Constants::k_PiD - eta)));
}
Expand All @@ -1761,32 +1714,26 @@ EbsdLib::Rgb CubicOps::generateIPFColor(double phi1, double phi, double phi2, do
chiMax = std::sqrt(1.0 / (2.0 + std::tan(eta) * std::tan(eta)));
}
EbsdLibMath::bound(chiMax, -1.0, 1.0);
chiMax = std::acos(chiMax);

_rgb[0] = 1.0 - chi / chiMax;
_rgb[2] = std::fabs(etaDeg - etaMin) / (etaMax - etaMin);
_rgb[1] = 1 - _rgb[2];
_rgb[1] *= chi / chiMax;
_rgb[2] *= chi / chiMax;
_rgb[0] = std::sqrt(_rgb[0]);
_rgb[1] = std::sqrt(_rgb[1]);
_rgb[2] = std::sqrt(_rgb[2]);

double max = _rgb[0];
if(_rgb[1] > max)
{
max = _rgb[1];
}
if(_rgb[2] > max)
{
max = _rgb[2];
}
chiMax = acos(chiMax);
return !(eta < CubicHigh::k_EtaMin || eta > (CubicHigh::k_EtaMax * EbsdLib::Constants::k_PiOver180D) || chi < 0.0 || chi > chiMax);
}

_rgb[0] = _rgb[0] / max;
_rgb[1] = _rgb[1] / max;
_rgb[2] = _rgb[2] / max;
// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
EbsdLib::Rgb CubicOps::generateIPFColor(double* eulers, double* refDir, bool degToRad) const
{
return computeIPFColor(eulers, refDir, degToRad);
}

return EbsdLib::RgbColor::dRgb(static_cast<int32_t>(_rgb[0] * 255), static_cast<int32_t>(_rgb[1] * 255), static_cast<int32_t>(_rgb[2] * 255), 255);
// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
EbsdLib::Rgb CubicOps::generateIPFColor(double phi1, double phi, double phi2, double refDir0, double refDir1, double refDir2, bool degToRad) const
{
double eulers[3] = {phi1, phi, phi2};
double refDir[3] = {refDir0, refDir1, refDir2};
return computeIPFColor(eulers, refDir, degToRad);
}

// -----------------------------------------------------------------------------
Expand Down
7 changes: 6 additions & 1 deletion Source/EbsdLib/LaueOps/CubicOps.h
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,12 @@ class EbsdLib_EXPORT CubicOps : public LaueOps
double getF7(const QuatD& q1, const QuatD& q2, double LD[3], bool maxSF) const override;

void generateSphereCoordsFromEulers(EbsdLib::FloatArrayType* eulers, EbsdLib::FloatArrayType* xyz001, EbsdLib::FloatArrayType* xyz011, EbsdLib::FloatArrayType* xyz111) const override;

/**
* @brief
* @param eta Optional input value only needed for the "Cubic" Laue classes
* @return Triplet of etaMin, etaMax, chiMax
*/
std::array<double, 3> getIpfColorAngleLimits(double eta) const override;
/**
* @brief generateIPFColor Generates an RGB Color from a Euler Angle and Reference Direction
* @param eulers Pointer to the 3 component Euler Angle
Expand Down
Loading

0 comments on commit 1903ee9

Please sign in to comment.