diff --git a/Source/EbsdLib/LaueOps/CubicLowOps.cpp b/Source/EbsdLib/LaueOps/CubicLowOps.cpp index 8fb12d2..16b9032 100644 --- a/Source/EbsdLib/LaueOps/CubicLowOps.cpp +++ b/Source/EbsdLib/LaueOps/CubicLowOps.cpp @@ -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 { @@ -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 // ----------------------------------------------------------------------------- @@ -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 CubicLowOps::getIpfColorAngleLimits(double eta) const { double etaDeg = eta * EbsdLib::Constants::k_180OverPiD; double chiMax; @@ -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(eu); - - for(int j = 0; j < CubicLow::k_SymOpsCount; j++) - { - QuatD qu = getQuatSymOp(j) * q1; - EbsdLib::Matrix3X3D g(OrientationTransformation::qu2om(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) @@ -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(_rgb[0] * 255), static_cast(_rgb[1] * 255), static_cast(_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); } // ----------------------------------------------------------------------------- diff --git a/Source/EbsdLib/LaueOps/CubicLowOps.h b/Source/EbsdLib/LaueOps/CubicLowOps.h index c640263..47ec451 100644 --- a/Source/EbsdLib/LaueOps/CubicLowOps.h +++ b/Source/EbsdLib/LaueOps/CubicLowOps.h @@ -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 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 diff --git a/Source/EbsdLib/LaueOps/CubicOps.cpp b/Source/EbsdLib/LaueOps/CubicOps.cpp index 4aab0e6..b8e8bc2 100644 --- a/Source/EbsdLib/LaueOps/CubicOps.cpp +++ b/Source/EbsdLib/LaueOps/CubicOps.cpp @@ -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 { @@ -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 // ----------------------------------------------------------------------------- @@ -1678,13 +1681,11 @@ bool inUnitTriangleD(double eta, double chi) } // ----------------------------------------------------------------------------- -// -// ----------------------------------------------------------------------------- -bool CubicOps::inUnitTriangle(double eta, double chi) const +std::array 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))); } @@ -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(eu); - - for(int j = 0; j < CubicHigh::k_SymOpsCount; j++) - { - QuatD qu = getQuatSymOp(j) * q1; - EbsdLib::Matrix3X3D g(OrientationTransformation::qu2om(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))); } @@ -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(_rgb[0] * 255), static_cast(_rgb[1] * 255), static_cast(_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); } // ----------------------------------------------------------------------------- diff --git a/Source/EbsdLib/LaueOps/CubicOps.h b/Source/EbsdLib/LaueOps/CubicOps.h index 28d2dfe..5edea17 100644 --- a/Source/EbsdLib/LaueOps/CubicOps.h +++ b/Source/EbsdLib/LaueOps/CubicOps.h @@ -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 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 diff --git a/Source/EbsdLib/LaueOps/HexagonalLowOps.cpp b/Source/EbsdLib/LaueOps/HexagonalLowOps.cpp index 381bca6..f3fcd8a 100644 --- a/Source/EbsdLib/LaueOps/HexagonalLowOps.cpp +++ b/Source/EbsdLib/LaueOps/HexagonalLowOps.cpp @@ -50,8 +50,8 @@ #include "EbsdLib/Math/EbsdLibMath.h" #include "EbsdLib/Utilities/ColorTable.h" #include "EbsdLib/Utilities/ComputeStereographicProjection.h" -#include "EbsdLib/Utilities/PoleFigureUtilities.h" #include "EbsdLib/Utilities/EbsdStringUtils.hpp" +#include "EbsdLib/Utilities/PoleFigureUtilities.h" namespace HexagonalLow { @@ -122,6 +122,9 @@ static const double MatSym[k_SymOpsCount][3][3] = { }; // clang-format on +static const double k_EtaMin = 0.0; +static const double k_EtaMax = 60.0; +static const double k_ChiMax = 90.0; } // namespace HexagonalLow // ----------------------------------------------------------------------------- @@ -1186,20 +1189,27 @@ void HexagonalLowOps::generateSphereCoordsFromEulers(EbsdLib::FloatArrayType* eu } } +// ----------------------------------------------------------------------------- +std::array HexagonalLowOps::getIpfColorAngleLimits(double eta) const +{ + return {HexagonalLow::k_EtaMin * EbsdLib::Constants::k_DegToRadD, HexagonalLow::k_EtaMax * EbsdLib::Constants::k_DegToRadD, HexagonalLow::k_ChiMax * EbsdLib::Constants::k_DegToRadD}; +} + // ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- bool HexagonalLowOps::inUnitTriangle(double eta, double chi) const { - return !(eta < 0 || eta > (60.0 * EbsdLib::Constants::k_PiOver180D) || chi < 0 || chi > (90.0 * EbsdLib::Constants::k_PiOver180D)); + return !(eta < (HexagonalLow::k_EtaMin * EbsdLib::Constants::k_PiOver180D) || eta > (HexagonalLow::k_EtaMax * EbsdLib::Constants::k_PiOver180D) || chi < 0 || + chi > (HexagonalLow::k_ChiMax * EbsdLib::Constants::k_PiOver180D)); } // ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- -EbsdLib::Rgb HexagonalLowOps::generateIPFColor(double* eulers, double* refDir, bool convertDegrees) const +EbsdLib::Rgb HexagonalLowOps::generateIPFColor(double* eulers, double* refDir, bool degToRad) const { - return generateIPFColor(eulers[0], eulers[1], eulers[2], refDir[0], refDir[1], refDir[2], convertDegrees); + return computeIPFColor(eulers, refDir, degToRad); } // ----------------------------------------------------------------------------- @@ -1207,75 +1217,9 @@ EbsdLib::Rgb HexagonalLowOps::generateIPFColor(double* eulers, double* refDir, b // ----------------------------------------------------------------------------- EbsdLib::Rgb HexagonalLowOps::generateIPFColor(double phi1, double phi, double phi2, double refDir0, double refDir1, double refDir2, bool degToRad) 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, eta = 0.0; - 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(eu); - - for(int j = 0; j < HexagonalLow::k_SymOpsCount; j++) - { - QuatD qu = getQuatSymOp(j) * q1; - EbsdLib::Matrix3X3D g(OrientationTransformation::qu2om(qu).data()); - EbsdLib::Matrix3X1D p = (g * refDirection).normalize(); - - if(!getHasInversion() && p[2] < 0) - { - continue; - } - if(getHasInversion() && p[2] < 0) - { - p[0] = -p[0], p[1] = -p[1], p[2] = -p[2]; - } - chi = std::acos(p[2]); - eta = std::atan2(p[1], p[0]); - if(!inUnitTriangle(eta, chi)) - { - continue; - } - - break; - } - - double etaMin = 0.0; - double etaMax = 60.0; - double chiMax = 90.0; - double etaDeg = eta * EbsdLib::Constants::k_180OverPiD; - double chiDeg = chi * EbsdLib::Constants::k_180OverPiD; - - _rgb[0] = 1.0 - chiDeg / chiMax; - _rgb[2] = fabs(etaDeg - etaMin) / (etaMax - etaMin); - _rgb[1] = 1 - _rgb[2]; - _rgb[1] *= chiDeg / chiMax; - _rgb[2] *= chiDeg / 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; - - return EbsdLib::RgbColor::dRgb(static_cast(_rgb[0] * 255), static_cast(_rgb[1] * 255), static_cast(_rgb[2] * 255), 255); + double eulers[3] = {phi1, phi, phi2}; + double refDir[3] = {refDir0, refDir1, refDir2}; + return computeIPFColor(eulers, refDir, degToRad); } // ----------------------------------------------------------------------------- diff --git a/Source/EbsdLib/LaueOps/HexagonalLowOps.h b/Source/EbsdLib/LaueOps/HexagonalLowOps.h index 57a13b7..1837b23 100644 --- a/Source/EbsdLib/LaueOps/HexagonalLowOps.h +++ b/Source/EbsdLib/LaueOps/HexagonalLowOps.h @@ -180,7 +180,12 @@ class EbsdLib_EXPORT HexagonalLowOps : public LaueOps double getF7(const QuatD& q1, const QuatD& q2, double LD[3], bool maxSF) const override; void generateSphereCoordsFromEulers(EbsdLib::FloatArrayType* eulers, EbsdLib::FloatArrayType* c1, EbsdLib::FloatArrayType* c2, EbsdLib::FloatArrayType* c3) const override; - + /** + * @brief + * @param eta Optional input value only needed for the "Cubic" Laue classes + * @return Triplet of etaMin, etaMax, chiMax + */ + std::array 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 diff --git a/Source/EbsdLib/LaueOps/HexagonalOps.cpp b/Source/EbsdLib/LaueOps/HexagonalOps.cpp index 96eac02..793e0de 100644 --- a/Source/EbsdLib/LaueOps/HexagonalOps.cpp +++ b/Source/EbsdLib/LaueOps/HexagonalOps.cpp @@ -44,8 +44,8 @@ #include "EbsdLib/Math/EbsdLibMath.h" #include "EbsdLib/Utilities/ColorUtilities.h" #include "EbsdLib/Utilities/ComputeStereographicProjection.h" -#include "EbsdLib/Utilities/PoleFigureUtilities.h" #include "EbsdLib/Utilities/EbsdStringUtils.hpp" +#include "EbsdLib/Utilities/PoleFigureUtilities.h" #ifdef EbsdLib_USE_PARALLEL_ALGORITHMS #include @@ -158,7 +158,9 @@ static const double MatSym[k_SymOpsCount][3][3] = { }; // clang-format on - +static const double k_EtaMin = 0.0; +static const double k_EtaMax = 30.0; +static const double k_ChiMax = 90.0; // Use a namespace for some detail that only this class needs } // namespace HexagonalHigh @@ -1256,20 +1258,27 @@ void HexagonalOps::generateSphereCoordsFromEulers(EbsdLib::FloatArrayType* euler } } +// ----------------------------------------------------------------------------- +std::array HexagonalOps::getIpfColorAngleLimits(double eta) const +{ + return {HexagonalHigh::k_EtaMin * EbsdLib::Constants::k_DegToRadD, HexagonalHigh::k_EtaMax * EbsdLib::Constants::k_DegToRadD, HexagonalHigh::k_ChiMax * EbsdLib::Constants::k_DegToRadD}; +} + // ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- bool HexagonalOps::inUnitTriangle(double eta, double chi) const { - return !(eta < 0 || eta > (30.0 * EbsdLib::Constants::k_PiOver180D) || chi < 0 || chi > (90.0 * EbsdLib::Constants::k_PiOver180D)); + return !(eta < (HexagonalHigh::k_EtaMin * EbsdLib::Constants::k_PiOver180D) || eta > (HexagonalHigh::k_EtaMax * EbsdLib::Constants::k_PiOver180D) || chi < 0 || + chi > (HexagonalHigh::k_ChiMax * EbsdLib::Constants::k_PiOver180D)); } // ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- -EbsdLib::Rgb HexagonalOps::generateIPFColor(double* eulers, double* refDir, bool convertDegrees) const +EbsdLib::Rgb HexagonalOps::generateIPFColor(double* eulers, double* refDir, bool degToRad) const { - return generateIPFColor(eulers[0], eulers[1], eulers[2], refDir[0], refDir[1], refDir[2], convertDegrees); + return computeIPFColor(eulers, refDir, degToRad); } // ----------------------------------------------------------------------------- @@ -1277,76 +1286,9 @@ EbsdLib::Rgb HexagonalOps::generateIPFColor(double* eulers, double* refDir, bool // ----------------------------------------------------------------------------- EbsdLib::Rgb HexagonalOps::generateIPFColor(double phi1, double phi, double phi2, double refDir0, double refDir1, double refDir2, bool degToRad) 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(eu); - - for(int j = 0; j < HexagonalHigh::k_SymOpsCount; j++) - { - QuatD qu = getQuatSymOp(j) * q1; - EbsdLib::Matrix3X3D g(OrientationTransformation::qu2om(qu).data()); - EbsdLib::Matrix3X1D p = (g * refDirection).normalize(); - - if(!getHasInversion() && p[2] < 0) - { - continue; - } - if(getHasInversion() && p[2] < 0) - { - p[0] = -p[0], p[1] = -p[1], p[2] = -p[2]; - } - chi = std::acos(p[2]); - eta = std::atan2(p[1], p[0]); - if(!inUnitTriangle(eta, chi)) - { - continue; - } - - break; - } - - double etaMin = 0.0; - double etaMax = 30.0; - double chiMax = 90.0; - double etaDeg = eta * EbsdLib::Constants::k_180OverPiD; - double chiDeg = chi * EbsdLib::Constants::k_180OverPiD; - - _rgb[0] = 1.0 - chiDeg / chiMax; - _rgb[2] = fabs(etaDeg - etaMin) / (etaMax - etaMin); - _rgb[1] = 1 - _rgb[2]; - _rgb[1] *= chiDeg / chiMax; - _rgb[2] *= chiDeg / 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; - - return EbsdLib::RgbColor::dRgb(static_cast(_rgb[0] * 255), static_cast(_rgb[1] * 255), static_cast(_rgb[2] * 255), 255); + double eulers[3] = {phi1, phi, phi2}; + double refDir[3] = {refDir0, refDir1, refDir2}; + return computeIPFColor(eulers, refDir, degToRad); } // ----------------------------------------------------------------------------- diff --git a/Source/EbsdLib/LaueOps/HexagonalOps.h b/Source/EbsdLib/LaueOps/HexagonalOps.h index f477c47..5db2b78 100644 --- a/Source/EbsdLib/LaueOps/HexagonalOps.h +++ b/Source/EbsdLib/LaueOps/HexagonalOps.h @@ -180,7 +180,12 @@ class EbsdLib_EXPORT HexagonalOps : public LaueOps double getF7(const QuatD& q1, const QuatD& q2, double LD[3], bool maxSF) const override; void generateSphereCoordsFromEulers(EbsdLib::FloatArrayType* eulers, EbsdLib::FloatArrayType* c1, EbsdLib::FloatArrayType* c2, EbsdLib::FloatArrayType* c3) const override; - + /** + * @brief + * @param eta Optional input value only needed for the "Cubic" Laue classes + * @return Triplet of etaMin, etaMax, chiMax + */ + std::array 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 diff --git a/Source/EbsdLib/LaueOps/LaueOps.cpp b/Source/EbsdLib/LaueOps/LaueOps.cpp index 6ac2202..aeafac7 100644 --- a/Source/EbsdLib/LaueOps/LaueOps.cpp +++ b/Source/EbsdLib/LaueOps/LaueOps.cpp @@ -101,6 +101,76 @@ LaueOps::LaueOps() = default; // ----------------------------------------------------------------------------- LaueOps::~LaueOps() = default; +// ----------------------------------------------------------------------------- +EbsdLib::Rgb LaueOps::computeIPFColor(double* eulers, double* refDir, bool degToRad) const +{ + + EbsdLib::Matrix3X1D refDirection(refDir); + double chi = 0.0f; + double eta = 0.0f; + double _rgb[3] = {0.0, 0.0, 0.0}; + + OrientationType eu(eulers, 3); + if(degToRad) + { + eu[0] = eu[0] * EbsdLib::Constants::k_DegToRadD; + eu[1] = eu[1] * EbsdLib::Constants::k_DegToRadD; + eu[2] = eu[2] * EbsdLib::Constants::k_DegToRadD; + } + OrientationType om(9); // Reusable for the loop + QuatD q1 = OrientationTransformation::eu2qu(eu); + + for(int j = 0; j < getNumSymOps(); j++) + { + QuatD qu = getQuatSymOp(j) * q1; + EbsdLib::Matrix3X3D g(OrientationTransformation::qu2om(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; + } + + std::array angleLimits = getIpfColorAngleLimits(eta); + + _rgb[0] = 1.0 - chi / angleLimits[2]; + _rgb[2] = std::fabs(eta - angleLimits[0]) / (angleLimits[1] - angleLimits[0]); + _rgb[1] = 1 - _rgb[2]; + _rgb[1] *= chi / angleLimits[2]; + _rgb[2] *= chi / angleLimits[2]; + _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]; + } + + _rgb[0] = _rgb[0] / max; + _rgb[1] = _rgb[1] / max; + _rgb[2] = _rgb[2] / max; + + return EbsdLib::RgbColor::dRgb(static_cast(_rgb[0] * 255), static_cast(_rgb[1] * 255), static_cast(_rgb[2] * 255), 255); +} + // ----------------------------------------------------------------------------- QuatD LaueOps::getFZQuat(const QuatD& qr) const { diff --git a/Source/EbsdLib/LaueOps/LaueOps.h b/Source/EbsdLib/LaueOps/LaueOps.h index 504eff8..ba7e8b5 100644 --- a/Source/EbsdLib/LaueOps/LaueOps.h +++ b/Source/EbsdLib/LaueOps/LaueOps.h @@ -243,6 +243,13 @@ class EbsdLib_EXPORT LaueOps virtual void generateSphereCoordsFromEulers(EbsdLib::FloatArrayType* eulers, EbsdLib::FloatArrayType* c1, EbsdLib::FloatArrayType* c2, EbsdLib::FloatArrayType* c3) const = 0; + /** + * @brief + * @param eta Optional input value only needed for the "Cubic" Laue classes + * @return Triplet of etaMin, etaMax, chiMax + */ + virtual std::array getIpfColorAngleLimits(double eta) const = 0; + /** * @brief generateIPFColor Generates an RGB Color from a Euler Angle and Reference Direction * @param eulers Pointer to the 3 component Euler Angle @@ -328,6 +335,19 @@ class EbsdLib_EXPORT LaueOps void _calcDetermineHomochoricValues(double random[3], double init[3], double step[3], int32_t phi[3], double& r1, double& r2, double& r3) const; int _calcODFBin(double dim[3], double bins[3], double step[3], const OrientationType& homochoric) const; + /** + * @brief Generates an IPF Color for a given Euler and Reference Direction. This should be called from the subclass so the + * specific etaMin, etaMax and ChiMax can be passed in. + * @param eulers + * @param refDir + * @param deg2Rad + * @param etaMin + * @param etaMax + * @param chiMax + * @return + */ + EbsdLib::Rgb computeIPFColor(double* eulers, double* refDir, bool deg2Rad) const; + public: LaueOps(const LaueOps&) = delete; // Copy Constructor Not Implemented LaueOps(LaueOps&&) = delete; // Move Constructor Not Implemented diff --git a/Source/EbsdLib/LaueOps/MonoclinicOps.cpp b/Source/EbsdLib/LaueOps/MonoclinicOps.cpp index ba5f8a9..e78c6b0 100644 --- a/Source/EbsdLib/LaueOps/MonoclinicOps.cpp +++ b/Source/EbsdLib/LaueOps/MonoclinicOps.cpp @@ -94,6 +94,10 @@ static const double MatSym[k_SymOpsCount][3][3] = { }; // clang-format on + +static const double k_EtaMin = 0.0; +static const double k_EtaMax = 180.0; +static const double k_ChiMax = 90.0; } // namespace Monoclinic // ----------------------------------------------------------------------------- @@ -576,20 +580,27 @@ void MonoclinicOps::generateSphereCoordsFromEulers(EbsdLib::FloatArrayType* eule #endif } +// ----------------------------------------------------------------------------- +std::array MonoclinicOps::getIpfColorAngleLimits(double eta) const +{ + return {Monoclinic::k_EtaMin * EbsdLib::Constants::k_DegToRadD, Monoclinic::k_EtaMax * EbsdLib::Constants::k_DegToRadD, Monoclinic::k_ChiMax * EbsdLib::Constants::k_DegToRadD}; +} + // ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- bool MonoclinicOps::inUnitTriangle(double eta, double chi) const { - return !(eta < 0 || eta > (180.0 * EbsdLib::Constants::k_PiOver180D) || chi < 0 || chi > (90.0 * EbsdLib::Constants::k_PiOver180D)); + return !(eta < (Monoclinic::k_EtaMin * EbsdLib::Constants::k_PiOver180D) || eta > (Monoclinic::k_EtaMax * EbsdLib::Constants::k_PiOver180D) || chi < 0 || + chi > (Monoclinic::k_ChiMax * EbsdLib::Constants::k_PiOver180D)); } // ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- -EbsdLib::Rgb MonoclinicOps::generateIPFColor(double* eulers, double* refDir, bool convertDegrees) const +EbsdLib::Rgb MonoclinicOps::generateIPFColor(double* eulers, double* refDir, bool degToRad) const { - return generateIPFColor(eulers[0], eulers[1], eulers[2], refDir[0], refDir[1], refDir[2], convertDegrees); + return computeIPFColor(eulers, refDir, degToRad); } // ----------------------------------------------------------------------------- @@ -597,76 +608,9 @@ EbsdLib::Rgb MonoclinicOps::generateIPFColor(double* eulers, double* refDir, boo // ----------------------------------------------------------------------------- EbsdLib::Rgb MonoclinicOps::generateIPFColor(double phi1, double phi, double phi2, double refDir0, double refDir1, double refDir2, bool degToRad) 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(eu); - - for(int j = 0; j < Monoclinic::k_SymOpsCount; j++) - { - QuatD qu = getQuatSymOp(j) * q1; - EbsdLib::Matrix3X3D g(OrientationTransformation::qu2om(qu).data()); - EbsdLib::Matrix3X1D p = (g * refDirection).normalize(); - - if(!getHasInversion() && p[2] < 0) - { - continue; - } - if(getHasInversion() && p[2] < 0) - { - p[0] = -p[0], p[1] = -p[1], p[2] = -p[2]; - } - chi = std::acos(p[2]); - eta = std::atan2(p[1], p[0]); - if(!inUnitTriangle(eta, chi)) - { - continue; - } - - break; - } - - double etaMin = 0.0; - double etaMax = 180.0; - double chiMax = 90.0; - double etaDeg = eta * EbsdLib::Constants::k_180OverPiD; - double chiDeg = chi * EbsdLib::Constants::k_180OverPiD; - - _rgb[0] = 1.0 - chiDeg / chiMax; - _rgb[2] = fabs(etaDeg - etaMin) / (etaMax - etaMin); - _rgb[1] = 1 - _rgb[2]; - _rgb[1] *= chiDeg / chiMax; - _rgb[2] *= chiDeg / 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; - - return EbsdLib::RgbColor::dRgb(static_cast(_rgb[0] * 255), static_cast(_rgb[1] * 255), static_cast(_rgb[2] * 255), 255); + double eulers[3] = {phi1, phi, phi2}; + double refDir[3] = {refDir0, refDir1, refDir2}; + return computeIPFColor(eulers, refDir, degToRad); } // ----------------------------------------------------------------------------- diff --git a/Source/EbsdLib/LaueOps/MonoclinicOps.h b/Source/EbsdLib/LaueOps/MonoclinicOps.h index 9f7fc0f..a0d8dbe 100644 --- a/Source/EbsdLib/LaueOps/MonoclinicOps.h +++ b/Source/EbsdLib/LaueOps/MonoclinicOps.h @@ -178,7 +178,12 @@ class EbsdLib_EXPORT MonoclinicOps : public LaueOps double getF7(const QuatD& q1, const QuatD& q2, double LD[3], bool maxSF) const override; void generateSphereCoordsFromEulers(EbsdLib::FloatArrayType* eulers, EbsdLib::FloatArrayType* c1, EbsdLib::FloatArrayType* c2, EbsdLib::FloatArrayType* c3) const override; - + /** + * @brief + * @param eta Optional input value only needed for the "Cubic" Laue classes + * @return Triplet of etaMin, etaMax, chiMax + */ + std::array 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 diff --git a/Source/EbsdLib/LaueOps/OrthoRhombicOps.cpp b/Source/EbsdLib/LaueOps/OrthoRhombicOps.cpp index 3e02e2c..d33bcc2 100644 --- a/Source/EbsdLib/LaueOps/OrthoRhombicOps.cpp +++ b/Source/EbsdLib/LaueOps/OrthoRhombicOps.cpp @@ -49,8 +49,8 @@ #include "EbsdLib/Math/EbsdLibMath.h" #include "EbsdLib/Utilities/ColorTable.h" #include "EbsdLib/Utilities/ComputeStereographicProjection.h" -#include "EbsdLib/Utilities/PoleFigureUtilities.h" #include "EbsdLib/Utilities/EbsdStringUtils.hpp" +#include "EbsdLib/Utilities/PoleFigureUtilities.h" namespace OrthoRhombic { @@ -105,6 +105,9 @@ static const double MatSym[k_SymOpsCount][3][3] = { }; // clang-format on +static const double k_EtaMin = 0.0; +static const double k_EtaMax = 90.0; +static const double k_ChiMax = 90.0; } // namespace OrthoRhombic // ----------------------------------------------------------------------------- @@ -587,20 +590,27 @@ void OrthoRhombicOps::generateSphereCoordsFromEulers(EbsdLib::FloatArrayType* eu #endif } +// ----------------------------------------------------------------------------- +std::array OrthoRhombicOps::getIpfColorAngleLimits(double eta) const +{ + return {OrthoRhombic::k_EtaMin * EbsdLib::Constants::k_DegToRadD, OrthoRhombic::k_EtaMax * EbsdLib::Constants::k_DegToRadD, OrthoRhombic::k_ChiMax * EbsdLib::Constants::k_DegToRadD}; +} + // ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- bool OrthoRhombicOps::inUnitTriangle(double eta, double chi) const { - return !(eta < 0 || eta > (90.0 * EbsdLib::Constants::k_PiOver180D) || chi < 0 || chi > (90.0 * EbsdLib::Constants::k_PiOver180D)); + return !(eta < (OrthoRhombic::k_EtaMin * EbsdLib::Constants::k_PiOver180D) || eta > (OrthoRhombic::k_EtaMax * EbsdLib::Constants::k_PiOver180D) || chi < 0 || + chi > (OrthoRhombic::k_ChiMax * EbsdLib::Constants::k_PiOver180D)); } // ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- -EbsdLib::Rgb OrthoRhombicOps::generateIPFColor(double* eulers, double* refDir, bool convertDegrees) const +EbsdLib::Rgb OrthoRhombicOps::generateIPFColor(double* eulers, double* refDir, bool degToRad) const { - return generateIPFColor(eulers[0], eulers[1], eulers[2], refDir[0], refDir[1], refDir[2], convertDegrees); + return computeIPFColor(eulers, refDir, degToRad); } // ----------------------------------------------------------------------------- @@ -608,76 +618,9 @@ EbsdLib::Rgb OrthoRhombicOps::generateIPFColor(double* eulers, double* refDir, b // ----------------------------------------------------------------------------- EbsdLib::Rgb OrthoRhombicOps::generateIPFColor(double phi1, double phi, double phi2, double refDir0, double refDir1, double refDir2, bool degToRad) 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(eu); - - for(int j = 0; j < OrthoRhombic::k_SymOpsCount; j++) - { - QuatD qu = getQuatSymOp(j) * q1; - EbsdLib::Matrix3X3D g(OrientationTransformation::qu2om(qu).data()); - EbsdLib::Matrix3X1D p = (g * refDirection).normalize(); - - if(!getHasInversion() && p[2] < 0) - { - continue; - } - if(getHasInversion() && p[2] < 0) - { - p[0] = -p[0], p[1] = -p[1], p[2] = -p[2]; - } - 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 chiMax = 90.0; - double etaDeg = eta * EbsdLib::Constants::k_180OverPiD; - double chiDeg = chi * EbsdLib::Constants::k_180OverPiD; - - _rgb[0] = 1.0 - chiDeg / chiMax; - _rgb[2] = fabs(etaDeg - etaMin) / (etaMax - etaMin); - _rgb[1] = 1 - _rgb[2]; - _rgb[1] *= chiDeg / chiMax; - _rgb[2] *= chiDeg / 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; - - return EbsdLib::RgbColor::dRgb(static_cast(_rgb[0] * 255), static_cast(_rgb[1] * 255), static_cast(_rgb[2] * 255), 255); + double eulers[3] = {phi1, phi, phi2}; + double refDir[3] = {refDir0, refDir1, refDir2}; + return computeIPFColor(eulers, refDir, degToRad); } // ----------------------------------------------------------------------------- diff --git a/Source/EbsdLib/LaueOps/OrthoRhombicOps.h b/Source/EbsdLib/LaueOps/OrthoRhombicOps.h index fac4292..bc7e26c 100644 --- a/Source/EbsdLib/LaueOps/OrthoRhombicOps.h +++ b/Source/EbsdLib/LaueOps/OrthoRhombicOps.h @@ -181,6 +181,12 @@ class EbsdLib_EXPORT OrthoRhombicOps : public LaueOps void generateSphereCoordsFromEulers(EbsdLib::FloatArrayType* eulers, EbsdLib::FloatArrayType* c1, EbsdLib::FloatArrayType* c2, EbsdLib::FloatArrayType* c3) const override; + /** + * @brief + * @param eta Optional input value only needed for the "Cubic" Laue classes + * @return Triplet of etaMin, etaMax, chiMax + */ + std::array 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 diff --git a/Source/EbsdLib/LaueOps/TetragonalLowOps.cpp b/Source/EbsdLib/LaueOps/TetragonalLowOps.cpp index a021c03..80fd4b4 100644 --- a/Source/EbsdLib/LaueOps/TetragonalLowOps.cpp +++ b/Source/EbsdLib/LaueOps/TetragonalLowOps.cpp @@ -49,8 +49,8 @@ #include "EbsdLib/Math/EbsdLibMath.h" #include "EbsdLib/Utilities/ColorTable.h" #include "EbsdLib/Utilities/ComputeStereographicProjection.h" -#include "EbsdLib/Utilities/PoleFigureUtilities.h" #include "EbsdLib/Utilities/EbsdStringUtils.hpp" +#include "EbsdLib/Utilities/PoleFigureUtilities.h" namespace TetragonalLow { @@ -105,6 +105,10 @@ static const double MatSym[k_SymOpsCount][3][3] = { }; // clang-format on + +static const double k_EtaMin = 0.0; +static const double k_EtaMax = 90.0; +static const double k_ChiMax = 90.0; } // namespace TetragonalLow // ----------------------------------------------------------------------------- @@ -578,20 +582,27 @@ void TetragonalLowOps::generateSphereCoordsFromEulers(EbsdLib::FloatArrayType* e #endif } +// ----------------------------------------------------------------------------- +std::array TetragonalLowOps::getIpfColorAngleLimits(double eta) const +{ + return {TetragonalLow::k_EtaMin * EbsdLib::Constants::k_DegToRadD, TetragonalLow::k_EtaMax * EbsdLib::Constants::k_DegToRadD, TetragonalLow::k_ChiMax * EbsdLib::Constants::k_DegToRadD}; +} + // ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- bool TetragonalLowOps::inUnitTriangle(double eta, double chi) const { - return !(eta < 0 || eta > (90.0 * EbsdLib::Constants::k_PiOver180D) || chi < 0 || chi > (90.0 * EbsdLib::Constants::k_PiOver180D)); + return !(eta < (TetragonalLow::k_EtaMin * EbsdLib::Constants::k_PiOver180D) || eta > (TetragonalLow::k_EtaMax * EbsdLib::Constants::k_PiOver180D) || chi < 0 || + chi > (TetragonalLow::k_ChiMax * EbsdLib::Constants::k_PiOver180D)); } // ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- -EbsdLib::Rgb TetragonalLowOps::generateIPFColor(double* eulers, double* refDir, bool convertDegrees) const +EbsdLib::Rgb TetragonalLowOps::generateIPFColor(double* eulers, double* refDir, bool degToRad) const { - return generateIPFColor(eulers[0], eulers[1], eulers[2], refDir[0], refDir[1], refDir[2], convertDegrees); + return computeIPFColor(eulers, refDir, degToRad); } // ----------------------------------------------------------------------------- @@ -599,76 +610,9 @@ EbsdLib::Rgb TetragonalLowOps::generateIPFColor(double* eulers, double* refDir, // ----------------------------------------------------------------------------- EbsdLib::Rgb TetragonalLowOps::generateIPFColor(double phi1, double phi, double phi2, double refDir0, double refDir1, double refDir2, bool degToRad) 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(eu); - - for(int j = 0; j < TetragonalLow::k_SymOpsCount; j++) - { - QuatD qu = getQuatSymOp(j) * q1; - EbsdLib::Matrix3X3D g(OrientationTransformation::qu2om(qu).data()); - EbsdLib::Matrix3X1D p = (g * refDirection).normalize(); - - if(!getHasInversion() && p[2] < 0) - { - continue; - } - if(getHasInversion() && p[2] < 0) - { - p[0] = -p[0], p[1] = -p[1], p[2] = -p[2]; - } - 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 chiMax = 90.0; - double etaDeg = eta * EbsdLib::Constants::k_180OverPiD; - double chiDeg = chi * EbsdLib::Constants::k_180OverPiD; - - _rgb[0] = 1.0 - chiDeg / chiMax; - _rgb[2] = fabs(etaDeg - etaMin) / (etaMax - etaMin); - _rgb[1] = 1 - _rgb[2]; - _rgb[1] *= chiDeg / chiMax; - _rgb[2] *= chiDeg / 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; - - return EbsdLib::RgbColor::dRgb(static_cast(_rgb[0] * 255), static_cast(_rgb[1] * 255), static_cast(_rgb[2] * 255), 255); + double eulers[3] = {phi1, phi, phi2}; + double refDir[3] = {refDir0, refDir1, refDir2}; + return computeIPFColor(eulers, refDir, degToRad); } // ----------------------------------------------------------------------------- diff --git a/Source/EbsdLib/LaueOps/TetragonalLowOps.h b/Source/EbsdLib/LaueOps/TetragonalLowOps.h index a75ac73..464fa35 100644 --- a/Source/EbsdLib/LaueOps/TetragonalLowOps.h +++ b/Source/EbsdLib/LaueOps/TetragonalLowOps.h @@ -180,6 +180,12 @@ class EbsdLib_EXPORT TetragonalLowOps : public LaueOps void generateSphereCoordsFromEulers(EbsdLib::FloatArrayType* eulers, EbsdLib::FloatArrayType* c1, EbsdLib::FloatArrayType* c2, EbsdLib::FloatArrayType* c3) const override; + /** + * @brief + * @param eta Optional input value only needed for the "Cubic" Laue classes + * @return Triplet of etaMin, etaMax, chiMax + */ + std::array 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 diff --git a/Source/EbsdLib/LaueOps/TetragonalOps.cpp b/Source/EbsdLib/LaueOps/TetragonalOps.cpp index 3d50784..eb3e62f 100644 --- a/Source/EbsdLib/LaueOps/TetragonalOps.cpp +++ b/Source/EbsdLib/LaueOps/TetragonalOps.cpp @@ -50,8 +50,8 @@ #include "EbsdLib/Math/EbsdLibMath.h" #include "EbsdLib/Utilities/ColorTable.h" #include "EbsdLib/Utilities/ComputeStereographicProjection.h" -#include "EbsdLib/Utilities/PoleFigureUtilities.h" #include "EbsdLib/Utilities/EbsdStringUtils.hpp" +#include "EbsdLib/Utilities/PoleFigureUtilities.h" namespace TetragonalHigh { @@ -131,6 +131,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; +static const double k_ChiMax = 90.0; } // namespace TetragonalHigh // ----------------------------------------------------------------------------- @@ -627,20 +630,27 @@ void TetragonalOps::generateSphereCoordsFromEulers(EbsdLib::FloatArrayType* eule } } +// ----------------------------------------------------------------------------- +std::array TetragonalOps::getIpfColorAngleLimits(double eta) const +{ + return {TetragonalHigh::k_EtaMin * EbsdLib::Constants::k_DegToRadD, TetragonalHigh::k_EtaMax * EbsdLib::Constants::k_DegToRadD, TetragonalHigh::k_ChiMax * EbsdLib::Constants::k_DegToRadD}; +} + // ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- bool TetragonalOps::inUnitTriangle(double eta, double chi) const { - return !(eta < 0 || eta > (45.0 * EbsdLib::Constants::k_PiOver180D) || chi < 0 || chi > (90.0 * EbsdLib::Constants::k_PiOver180D)); + return !(eta < (TetragonalHigh::k_EtaMin * EbsdLib::Constants::k_PiOver180D) || eta > (TetragonalHigh::k_EtaMax * EbsdLib::Constants::k_PiOver180D) || chi < 0 || + chi > (TetragonalHigh::k_ChiMax * EbsdLib::Constants::k_PiOver180D)); } // ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- -EbsdLib::Rgb TetragonalOps::generateIPFColor(double* eulers, double* refDir, bool convertDegrees) const +EbsdLib::Rgb TetragonalOps::generateIPFColor(double* eulers, double* refDir, bool degToRad) const { - return generateIPFColor(eulers[0], eulers[1], eulers[2], refDir[0], refDir[1], refDir[2], convertDegrees); + return computeIPFColor(eulers, refDir, degToRad); } // ----------------------------------------------------------------------------- @@ -648,76 +658,9 @@ EbsdLib::Rgb TetragonalOps::generateIPFColor(double* eulers, double* refDir, boo // ----------------------------------------------------------------------------- EbsdLib::Rgb TetragonalOps::generateIPFColor(double phi1, double phi, double phi2, double refDir0, double refDir1, double refDir2, bool degToRad) 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(eu); - - for(int j = 0; j < TetragonalHigh::k_SymOpsCount; j++) - { - QuatD qu = getQuatSymOp(j) * q1; - EbsdLib::Matrix3X3D g(OrientationTransformation::qu2om(qu).data()); - EbsdLib::Matrix3X1D p = (g * refDirection).normalize(); - - if(!getHasInversion() && p[2] < 0) - { - continue; - } - if(getHasInversion() && p[2] < 0) - { - p[0] = -p[0], p[1] = -p[1], p[2] = -p[2]; - } - chi = std::acos(p[2]); - eta = std::atan2(p[1], p[0]); - if(!inUnitTriangle(eta, chi)) - { - continue; - } - - break; - } - - double etaMin = 0.0; - double etaMax = 45.0; - double chiMax = 90.0; - double etaDeg = eta * EbsdLib::Constants::k_180OverPiD; - double chiDeg = chi * EbsdLib::Constants::k_180OverPiD; - - _rgb[0] = 1.0 - chiDeg / chiMax; - _rgb[2] = fabs(etaDeg - etaMin) / (etaMax - etaMin); - _rgb[1] = 1 - _rgb[2]; - _rgb[1] *= chiDeg / chiMax; - _rgb[2] *= chiDeg / 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; - - return EbsdLib::RgbColor::dRgb(static_cast(_rgb[0] * 255), static_cast(_rgb[1] * 255), static_cast(_rgb[2] * 255), 255); + double eulers[3] = {phi1, phi, phi2}; + double refDir[3] = {refDir0, refDir1, refDir2}; + return computeIPFColor(eulers, refDir, degToRad); } // ----------------------------------------------------------------------------- diff --git a/Source/EbsdLib/LaueOps/TetragonalOps.h b/Source/EbsdLib/LaueOps/TetragonalOps.h index 1682055..f2fa29b 100644 --- a/Source/EbsdLib/LaueOps/TetragonalOps.h +++ b/Source/EbsdLib/LaueOps/TetragonalOps.h @@ -180,6 +180,12 @@ class EbsdLib_EXPORT TetragonalOps : public LaueOps void generateSphereCoordsFromEulers(EbsdLib::FloatArrayType* eulers, EbsdLib::FloatArrayType* c1, EbsdLib::FloatArrayType* c2, EbsdLib::FloatArrayType* c3) const override; + /** + * @brief + * @param eta Optional input value only needed for the "Cubic" Laue classes + * @return Triplet of etaMin, etaMax, chiMax + */ + std::array 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 diff --git a/Source/EbsdLib/LaueOps/TriclinicOps.cpp b/Source/EbsdLib/LaueOps/TriclinicOps.cpp index 019236c..8501c09 100644 --- a/Source/EbsdLib/LaueOps/TriclinicOps.cpp +++ b/Source/EbsdLib/LaueOps/TriclinicOps.cpp @@ -50,8 +50,8 @@ #include "EbsdLib/Math/EbsdLibMath.h" #include "EbsdLib/Utilities/ColorTable.h" #include "EbsdLib/Utilities/ComputeStereographicProjection.h" -#include "EbsdLib/Utilities/PoleFigureUtilities.h" #include "EbsdLib/Utilities/EbsdStringUtils.hpp" +#include "EbsdLib/Utilities/PoleFigureUtilities.h" namespace Triclinic { @@ -88,6 +88,11 @@ static const double MatSym[k_SymOpsCount][3][3] = { }; // clang-format on + +static const double k_EtaMin = 0.0; +static const double k_EtaMax = 180.0; +static const double k_ChiMax = 90.0; + } // namespace Triclinic // ----------------------------------------------------------------------------- @@ -567,20 +572,27 @@ void TriclinicOps::generateSphereCoordsFromEulers(EbsdLib::FloatArrayType* euler } } +// ----------------------------------------------------------------------------- +std::array TriclinicOps::getIpfColorAngleLimits(double eta) const +{ + return {Triclinic::k_EtaMin * EbsdLib::Constants::k_DegToRadD, Triclinic::k_EtaMax * EbsdLib::Constants::k_DegToRadD, Triclinic::k_ChiMax * EbsdLib::Constants::k_DegToRadD}; +} + // ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- bool TriclinicOps::inUnitTriangle(double eta, double chi) const { - return !(eta < 0 || eta > (180.0 * EbsdLib::Constants::k_PiOver180D) || chi < 0 || chi > (90.0 * EbsdLib::Constants::k_PiOver180D)); + return !(eta < (Triclinic::k_EtaMin * EbsdLib::Constants::k_PiOver180D) || eta > (Triclinic::k_EtaMax * EbsdLib::Constants::k_PiOver180D) || chi < 0 || + chi > (Triclinic::k_ChiMax * EbsdLib::Constants::k_PiOver180D)); } // ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- -EbsdLib::Rgb TriclinicOps::generateIPFColor(double* eulers, double* refDir, bool convertDegrees) const +EbsdLib::Rgb TriclinicOps::generateIPFColor(double* eulers, double* refDir, bool degToRad) const { - return generateIPFColor(eulers[0], eulers[1], eulers[2], refDir[0], refDir[1], refDir[2], convertDegrees); + return computeIPFColor(eulers, refDir, degToRad); } // ----------------------------------------------------------------------------- @@ -588,76 +600,9 @@ EbsdLib::Rgb TriclinicOps::generateIPFColor(double* eulers, double* refDir, bool // ----------------------------------------------------------------------------- EbsdLib::Rgb TriclinicOps::generateIPFColor(double phi1, double phi, double phi2, double refDir0, double refDir1, double refDir2, bool degToRad) 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(eu); - - for(int j = 0; j < Triclinic::k_SymOpsCount; j++) - { - QuatD qu = getQuatSymOp(j) * q1; - EbsdLib::Matrix3X3D g(OrientationTransformation::qu2om(qu).data()); - EbsdLib::Matrix3X1D p = (g * refDirection).normalize(); - - if(!getHasInversion() && p[2] < 0) - { - continue; - } - if(getHasInversion() && p[2] < 0) - { - p[0] = -p[0], p[1] = -p[1], p[2] = -p[2]; - } - chi = std::acos(p[2]); - eta = std::atan2(p[1], p[0]); - if(!inUnitTriangle(eta, chi)) - { - continue; - } - - break; - } - - double etaMin = 0.0; - double etaMax = 180.0; - double chiMax = 90.0; - double etaDeg = eta * EbsdLib::Constants::k_180OverPiD; - double chiDeg = chi * EbsdLib::Constants::k_180OverPiD; - - _rgb[0] = 1.0 - chiDeg / chiMax; - _rgb[2] = fabs(etaDeg - etaMin) / (etaMax - etaMin); - _rgb[1] = 1 - _rgb[2]; - _rgb[1] *= chiDeg / chiMax; - _rgb[2] *= chiDeg / 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; - - return EbsdLib::RgbColor::dRgb(static_cast(_rgb[0] * 255), static_cast(_rgb[1] * 255), static_cast(_rgb[2] * 255), 255); + double eulers[3] = {phi1, phi, phi2}; + double refDir[3] = {refDir0, refDir1, refDir2}; + return computeIPFColor(eulers, refDir, degToRad); } // ----------------------------------------------------------------------------- diff --git a/Source/EbsdLib/LaueOps/TriclinicOps.h b/Source/EbsdLib/LaueOps/TriclinicOps.h index b59c8f8..3ae5ec2 100644 --- a/Source/EbsdLib/LaueOps/TriclinicOps.h +++ b/Source/EbsdLib/LaueOps/TriclinicOps.h @@ -180,6 +180,12 @@ class EbsdLib_EXPORT TriclinicOps : public LaueOps void generateSphereCoordsFromEulers(EbsdLib::FloatArrayType* eulers, EbsdLib::FloatArrayType* c1, EbsdLib::FloatArrayType* c2, EbsdLib::FloatArrayType* c3) const override; + /** + * @brief + * @param eta Optional input value only needed for the "Cubic" Laue classes + * @return Triplet of etaMin, etaMax, chiMax + */ + std::array 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 diff --git a/Source/EbsdLib/LaueOps/TrigonalLowOps.cpp b/Source/EbsdLib/LaueOps/TrigonalLowOps.cpp index 8c7436f..2db60af 100644 --- a/Source/EbsdLib/LaueOps/TrigonalLowOps.cpp +++ b/Source/EbsdLib/LaueOps/TrigonalLowOps.cpp @@ -104,6 +104,9 @@ static const double MatSym[k_SymOpsCount][3][3] = { }; // clang-format on +static const double k_EtaMin = -120.0; +static const double k_EtaMax = 0.0; +static const double k_ChiMax = 90.0; } // namespace TrigonalLow // ----------------------------------------------------------------------------- @@ -616,20 +619,27 @@ void TrigonalLowOps::generateSphereCoordsFromEulers(EbsdLib::FloatArrayType* eul } } +// ----------------------------------------------------------------------------- +std::array TrigonalLowOps::getIpfColorAngleLimits(double eta) const +{ + return {TrigonalLow::k_EtaMin * EbsdLib::Constants::k_DegToRadD, TrigonalLow::k_EtaMax * EbsdLib::Constants::k_DegToRadD, TrigonalLow::k_ChiMax * EbsdLib::Constants::k_DegToRadD}; +} + // ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- bool TrigonalLowOps::inUnitTriangle(double eta, double chi) const { - return !(eta < (-120.0 * EbsdLib::Constants::k_PiOver180D) || eta > 0.0 || chi < 0 || chi > (90.0 * EbsdLib::Constants::k_PiOver180D)); + return !(eta < (TrigonalLow::k_EtaMin * EbsdLib::Constants::k_PiOver180D) || eta > (TrigonalLow::k_EtaMax * EbsdLib::Constants::k_PiOver180D) || chi < 0 || + chi > (TrigonalLow::k_ChiMax * EbsdLib::Constants::k_PiOver180D)); } // ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- -EbsdLib::Rgb TrigonalLowOps::generateIPFColor(double* eulers, double* refDir, bool convertDegrees) const +EbsdLib::Rgb TrigonalLowOps::generateIPFColor(double* eulers, double* refDir, bool degToRad) const { - return generateIPFColor(eulers[0], eulers[1], eulers[2], refDir[0], refDir[1], refDir[2], convertDegrees); + return computeIPFColor(eulers, refDir, degToRad); } // ----------------------------------------------------------------------------- @@ -637,76 +647,9 @@ EbsdLib::Rgb TrigonalLowOps::generateIPFColor(double* eulers, double* refDir, bo // ----------------------------------------------------------------------------- EbsdLib::Rgb TrigonalLowOps::generateIPFColor(double phi1, double phi, double phi2, double refDir0, double refDir1, double refDir2, bool degToRad) 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(eu); - - for(int j = 0; j < TrigonalLow::k_SymOpsCount; j++) - { - QuatD qu = getQuatSymOp(j) * q1; - EbsdLib::Matrix3X3D g(OrientationTransformation::qu2om(qu).data()); - EbsdLib::Matrix3X1D p = (g * refDirection).normalize(); - - if(!getHasInversion() && p[2] < 0) - { - continue; - } - if(getHasInversion() && p[2] < 0) - { - p[0] = -p[0], p[1] = -p[1], p[2] = -p[2]; - } - chi = std::acos(p[2]); - eta = std::atan2(p[1], p[0]); - if(!inUnitTriangle(eta, chi)) - { - continue; - } - - break; - } - - double etaMin = -120.0; - double etaMax = 0.0; - double chiMax = 90.0; - double etaDeg = eta * EbsdLib::Constants::k_180OverPiD; - double chiDeg = chi * EbsdLib::Constants::k_180OverPiD; - - _rgb[0] = 1.0 - chiDeg / chiMax; - _rgb[2] = fabs(etaDeg - etaMin) / (etaMax - etaMin); - _rgb[1] = 1 - _rgb[2]; - _rgb[1] *= chiDeg / chiMax; - _rgb[2] *= chiDeg / 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; - - return EbsdLib::RgbColor::dRgb(static_cast(_rgb[0] * 255), static_cast(_rgb[1] * 255), static_cast(_rgb[2] * 255), 255); + double eulers[3] = {phi1, phi, phi2}; + double refDir[3] = {refDir0, refDir1, refDir2}; + return computeIPFColor(eulers, refDir, degToRad); } // ----------------------------------------------------------------------------- diff --git a/Source/EbsdLib/LaueOps/TrigonalLowOps.h b/Source/EbsdLib/LaueOps/TrigonalLowOps.h index 8ec66ae..6f64c52 100644 --- a/Source/EbsdLib/LaueOps/TrigonalLowOps.h +++ b/Source/EbsdLib/LaueOps/TrigonalLowOps.h @@ -181,6 +181,13 @@ class EbsdLib_EXPORT TrigonalLowOps : public LaueOps void generateSphereCoordsFromEulers(EbsdLib::FloatArrayType* eulers, EbsdLib::FloatArrayType* c1, EbsdLib::FloatArrayType* c2, EbsdLib::FloatArrayType* c3) const override; + /** + * @brief + * @param eta Optional input value only needed for the "Cubic" Laue classes + * @return Triplet of etaMin, etaMax, chiMax + */ + std::array 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 diff --git a/Source/EbsdLib/LaueOps/TrigonalOps.cpp b/Source/EbsdLib/LaueOps/TrigonalOps.cpp index 5e1f072..96cf474 100644 --- a/Source/EbsdLib/LaueOps/TrigonalOps.cpp +++ b/Source/EbsdLib/LaueOps/TrigonalOps.cpp @@ -50,8 +50,8 @@ #include "EbsdLib/Math/EbsdLibMath.h" #include "EbsdLib/Utilities/ColorTable.h" #include "EbsdLib/Utilities/ComputeStereographicProjection.h" -#include "EbsdLib/Utilities/PoleFigureUtilities.h" #include "EbsdLib/Utilities/EbsdStringUtils.hpp" +#include "EbsdLib/Utilities/PoleFigureUtilities.h" namespace TrigonalHigh { @@ -120,6 +120,9 @@ static const double MatSym[k_SymOpsCount][3][3] = { }; // clang-format on +static const double k_EtaMin = -90.0; +static const double k_EtaMax = -30.0; +static const double k_ChiMax = 90.0; } // namespace TrigonalHigh // ----------------------------------------------------------------------------- @@ -634,20 +637,27 @@ void TrigonalOps::generateSphereCoordsFromEulers(EbsdLib::FloatArrayType* eulers } } +// ----------------------------------------------------------------------------- +std::array TrigonalOps::getIpfColorAngleLimits(double eta) const +{ + return {TrigonalHigh::k_EtaMin * EbsdLib::Constants::k_DegToRadD, TrigonalHigh::k_EtaMax * EbsdLib::Constants::k_DegToRadD, TrigonalHigh::k_ChiMax * EbsdLib::Constants::k_DegToRadD}; +} + // ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- bool TrigonalOps::inUnitTriangle(double eta, double chi) const { - return !(eta < (-90.0 * EbsdLib::Constants::k_PiOver180D) || eta > (-30.0 * EbsdLib::Constants::k_PiOver180D) || chi < 0 || chi > (90.0 * EbsdLib::Constants::k_PiOver180D)); + return !(eta < (TrigonalHigh::k_EtaMin * EbsdLib::Constants::k_PiOver180D) || eta > (TrigonalHigh::k_EtaMax * EbsdLib::Constants::k_PiOver180D) || chi < 0 || + chi > (TrigonalHigh::k_ChiMax * EbsdLib::Constants::k_PiOver180D)); } // ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- -EbsdLib::Rgb TrigonalOps::generateIPFColor(double* eulers, double* refDir, bool convertDegrees) const +EbsdLib::Rgb TrigonalOps::generateIPFColor(double* eulers, double* refDir, bool degToRad) const { - return generateIPFColor(eulers[0], eulers[1], eulers[2], refDir[0], refDir[1], refDir[2], convertDegrees); + return computeIPFColor(eulers, refDir, degToRad); } // ----------------------------------------------------------------------------- @@ -655,76 +665,9 @@ EbsdLib::Rgb TrigonalOps::generateIPFColor(double* eulers, double* refDir, bool // ----------------------------------------------------------------------------- EbsdLib::Rgb TrigonalOps::generateIPFColor(double phi1, double phi, double phi2, double refDir0, double refDir1, double refDir2, bool degToRad) 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(eu); - - for(int j = 0; j < TrigonalHigh::k_SymOpsCount; j++) - { - QuatD qu = getQuatSymOp(j) * q1; - EbsdLib::Matrix3X3D g(OrientationTransformation::qu2om(qu).data()); - EbsdLib::Matrix3X1D p = (g * refDirection).normalize(); - - if(!getHasInversion() && p[2] < 0) - { - continue; - } - if(getHasInversion() && p[2] < 0) - { - p[0] = -p[0], p[1] = -p[1], p[2] = -p[2]; - } - chi = std::acos(p[2]); - eta = std::atan2(p[1], p[0]); - if(!inUnitTriangle(eta, chi)) - { - continue; - } - - break; - } - - double etaMin = -90.0; - double etaMax = -30.0; - double chiMax = 90.0; - double etaDeg = eta * EbsdLib::Constants::k_180OverPiD; - double chiDeg = chi * EbsdLib::Constants::k_180OverPiD; - - _rgb[0] = 1.0 - chiDeg / chiMax; - _rgb[2] = fabs(etaDeg - etaMin) / (etaMax - etaMin); - _rgb[1] = 1 - _rgb[2]; - _rgb[1] *= chiDeg / chiMax; - _rgb[2] *= chiDeg / 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; - - return EbsdLib::RgbColor::dRgb(static_cast(_rgb[0] * 255), static_cast(_rgb[1] * 255), static_cast(_rgb[2] * 255), 255); + double eulers[3] = {phi1, phi, phi2}; + double refDir[3] = {refDir0, refDir1, refDir2}; + return computeIPFColor(eulers, refDir, degToRad); } // ----------------------------------------------------------------------------- diff --git a/Source/EbsdLib/LaueOps/TrigonalOps.h b/Source/EbsdLib/LaueOps/TrigonalOps.h index 18ff595..7f7546c 100644 --- a/Source/EbsdLib/LaueOps/TrigonalOps.h +++ b/Source/EbsdLib/LaueOps/TrigonalOps.h @@ -180,6 +180,13 @@ class EbsdLib_EXPORT TrigonalOps : public LaueOps void generateSphereCoordsFromEulers(EbsdLib::FloatArrayType* eulers, EbsdLib::FloatArrayType* c1, EbsdLib::FloatArrayType* c2, EbsdLib::FloatArrayType* c3) const override; + /** + * @brief + * @param eta Optional input value only needed for the "Cubic" Laue classes + * @return Triplet of etaMin, etaMax, chiMax + */ + std::array 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