Skip to content

Commit d280acd

Browse files
committed
Refactor the IPF Coloring algorithm to share algorithm
All Laue classes now call a protected member method of LaueClass to compute the IPF Color Signed-off-by: Michael Jackson <mike.jackson@bluequartz.net>
1 parent fe84d21 commit d280acd

25 files changed

+365
-829
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ set(CMAKE_CXX_EXTENSIONS OFF)
1515
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
1616

1717
# set project's name
18-
project(EbsdLibProj VERSION 1.0.31)
18+
project(EbsdLibProj VERSION 1.0.32)
1919

2020
# ---------- Setup output Directories -------------------------
2121
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY

Source/EbsdLib/LaueOps/CubicLowOps.cpp

Lines changed: 23 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@
5050
#include "EbsdLib/Math/EbsdLibMath.h"
5151
#include "EbsdLib/Utilities/ColorTable.h"
5252
#include "EbsdLib/Utilities/ComputeStereographicProjection.h"
53-
#include "EbsdLib/Utilities/ModifiedLambertProjection.h"
5453
#include "EbsdLib/Utilities/EbsdStringUtils.hpp"
54+
#include "EbsdLib/Utilities/ModifiedLambertProjection.h"
5555

5656
namespace CubicLow
5757
{
@@ -155,6 +155,8 @@ static const double MatSym[k_SymOpsCount][3][3] = {
155155

156156
};
157157
// clang-format on
158+
static const double k_EtaMin = 0.0;
159+
static const double k_EtaMax = 45.0;
158160
} // namespace CubicLow
159161

160162
// -----------------------------------------------------------------------------
@@ -867,11 +869,8 @@ void _TripletSort(T a, T b, T c, T& x, T& y, T& z)
867869
z = c;
868870
}
869871
}
870-
871872
// -----------------------------------------------------------------------------
872-
//
873-
// -----------------------------------------------------------------------------
874-
bool CubicLowOps::inUnitTriangle(double eta, double chi) const
873+
std::array<double, 3> CubicLowOps::getIpfColorAngleLimits(double eta) const
875874
{
876875
double etaDeg = eta * EbsdLib::Constants::k_180OverPiD;
877876
double chiMax;
@@ -885,62 +884,14 @@ bool CubicLowOps::inUnitTriangle(double eta, double chi) const
885884
}
886885
EbsdLibMath::bound(chiMax, -1.0, 1.0);
887886
chiMax = acos(chiMax);
888-
return !(eta < 0.0 || eta > (90.0 * EbsdLib::Constants::k_PiOver180D) || chi < 0.0 || chi > chiMax);
889-
}
890-
891-
// -----------------------------------------------------------------------------
892-
//
893-
// -----------------------------------------------------------------------------
894-
EbsdLib::Rgb CubicLowOps::generateIPFColor(double* eulers, double* refDir, bool convertDegrees) const
895-
{
896-
return generateIPFColor(eulers[0], eulers[1], eulers[2], refDir[0], refDir[1], refDir[2], convertDegrees);
887+
return {CubicLow::k_EtaMin * EbsdLib::Constants::k_DegToRadD, CubicLow::k_EtaMax * EbsdLib::Constants::k_DegToRadD, chiMax};
897888
}
898889

899890
// -----------------------------------------------------------------------------
900891
//
901892
// -----------------------------------------------------------------------------
902-
EbsdLib::Rgb CubicLowOps::generateIPFColor(double phi1, double phi, double phi2, double refDir0, double refDir1, double refDir2, bool degToRad) const
893+
bool CubicLowOps::inUnitTriangle(double eta, double chi) const
903894
{
904-
if(degToRad)
905-
{
906-
phi1 = phi1 * EbsdLib::Constants::k_DegToRadD;
907-
phi = phi * EbsdLib::Constants::k_DegToRadD;
908-
phi2 = phi2 * EbsdLib::Constants::k_DegToRadD;
909-
}
910-
911-
EbsdLib::Matrix3X1D refDirection = {refDir0, refDir1, refDir2};
912-
double chi = 0.0f;
913-
double eta = 0.0f;
914-
double _rgb[3] = {0.0, 0.0, 0.0};
915-
916-
OrientationType eu(phi1, phi, phi2);
917-
OrientationType om(9); // Reusable for the loop
918-
QuatD q1 = OrientationTransformation::eu2qu<OrientationType, QuatD>(eu);
919-
920-
for(int j = 0; j < CubicLow::k_SymOpsCount; j++)
921-
{
922-
QuatD qu = getQuatSymOp(j) * q1;
923-
EbsdLib::Matrix3X3D g(OrientationTransformation::qu2om<QuatD, OrientationType>(qu).data());
924-
EbsdLib::Matrix3X1D p = (g * refDirection).normalize();
925-
926-
if(!getHasInversion() && p[2] < 0)
927-
{
928-
continue;
929-
}
930-
if(getHasInversion() && p[2] < 0)
931-
{
932-
p = p * -1.0;
933-
}
934-
chi = std::acos(p[2]);
935-
eta = std::atan2(p[1], p[0]);
936-
if(!inUnitTriangle(eta, chi))
937-
{
938-
continue;
939-
}
940-
break;
941-
}
942-
double etaMin = 0.0;
943-
double etaMax = 90.0;
944895
double etaDeg = eta * EbsdLib::Constants::k_180OverPiD;
945896
double chiMax;
946897
if(etaDeg > 45.0)
@@ -953,31 +904,25 @@ EbsdLib::Rgb CubicLowOps::generateIPFColor(double phi1, double phi, double phi2,
953904
}
954905
EbsdLibMath::bound(chiMax, -1.0, 1.0);
955906
chiMax = acos(chiMax);
907+
return !(eta < CubicLow::k_EtaMin || eta > (CubicLow::k_EtaMax * EbsdLib::Constants::k_PiOver180D) || chi < 0.0 || chi > chiMax);
908+
}
956909

957-
_rgb[0] = 1.0 - chi / chiMax;
958-
_rgb[2] = std::fabs(etaDeg - etaMin) / (etaMax - etaMin);
959-
_rgb[1] = 1 - _rgb[2];
960-
_rgb[1] *= chi / chiMax;
961-
_rgb[2] *= chi / chiMax;
962-
_rgb[0] = sqrt(_rgb[0]);
963-
_rgb[1] = sqrt(_rgb[1]);
964-
_rgb[2] = sqrt(_rgb[2]);
965-
966-
double max = _rgb[0];
967-
if(_rgb[1] > max)
968-
{
969-
max = _rgb[1];
970-
}
971-
if(_rgb[2] > max)
972-
{
973-
max = _rgb[2];
974-
}
975-
976-
_rgb[0] = _rgb[0] / max;
977-
_rgb[1] = _rgb[1] / max;
978-
_rgb[2] = _rgb[2] / max;
910+
// -----------------------------------------------------------------------------
911+
//
912+
// -----------------------------------------------------------------------------
913+
EbsdLib::Rgb CubicLowOps::generateIPFColor(double* eulers, double* refDir, bool degToRad) const
914+
{
915+
return computeIPFColor(eulers, refDir, degToRad);
916+
}
979917

980-
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);
918+
// -----------------------------------------------------------------------------
919+
//
920+
// -----------------------------------------------------------------------------
921+
EbsdLib::Rgb CubicLowOps::generateIPFColor(double phi1, double phi, double phi2, double refDir0, double refDir1, double refDir2, bool degToRad) const
922+
{
923+
double eulers[3] = {phi1, phi, phi2};
924+
double refDir[3] = {refDir0, refDir1, refDir2};
925+
return computeIPFColor(eulers, refDir, degToRad);
981926
}
982927

983928
// -----------------------------------------------------------------------------

Source/EbsdLib/LaueOps/CubicLowOps.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,12 @@ class EbsdLib_EXPORT CubicLowOps : public LaueOps
179179
double getF7(const QuatD& q1, const QuatD& q2, double LD[3], bool maxSF) const override;
180180

181181
void generateSphereCoordsFromEulers(EbsdLib::FloatArrayType* eulers, EbsdLib::FloatArrayType* xyz001, EbsdLib::FloatArrayType* xyz011, EbsdLib::FloatArrayType* xyz111) const override;
182-
182+
/**
183+
* @brief
184+
* @param eta Optional input value only needed for the "Cubic" Laue classes
185+
* @return Triplet of etaMin, etaMax, chiMax
186+
*/
187+
std::array<double, 3> getIpfColorAngleLimits(double eta) const override;
183188
/**
184189
* @brief generateIPFColor Generates an RGB Color from a Euler Angle and Reference Direction
185190
* @param eulers Pointer to the 3 component Euler Angle

Source/EbsdLib/LaueOps/CubicOps.cpp

Lines changed: 28 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,10 @@
4949
#include "EbsdLib/Core/Orientation.hpp"
5050
#include "EbsdLib/Math/EbsdLibMath.h"
5151
#include "EbsdLib/Math/GeometryMath.h"
52+
#include "EbsdLib/Utilities/ColorTable.h"
5253
#include "EbsdLib/Utilities/ColorUtilities.h"
5354
#include "EbsdLib/Utilities/ComputeStereographicProjection.h"
5455
#include "EbsdLib/Utilities/EbsdStringUtils.hpp"
55-
#include "EbsdLib/Utilities/ColorTable.h"
5656

5757
namespace CubicHigh
5858
{
@@ -235,6 +235,9 @@ static const double MatSym[k_SymOpsCount][3][3] = {
235235

236236
};
237237
// clang-format on
238+
static const double k_EtaMin = 0.0;
239+
static const double k_EtaMax = 45.0;
240+
238241
} // namespace CubicHigh
239242

240243
// -----------------------------------------------------------------------------
@@ -1678,13 +1681,11 @@ bool inUnitTriangleD(double eta, double chi)
16781681
}
16791682

16801683
// -----------------------------------------------------------------------------
1681-
//
1682-
// -----------------------------------------------------------------------------
1683-
bool CubicOps::inUnitTriangle(double eta, double chi) const
1684+
std::array<double, 3> CubicOps::getIpfColorAngleLimits(double eta) const
16841685
{
16851686
double etaDeg = eta * EbsdLib::Constants::k_180OverPiD;
16861687
double chiMax;
1687-
if(etaDeg > 45.0)
1688+
if(etaDeg > CubicHigh::k_EtaMax)
16881689
{
16891690
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)));
16901691
}
@@ -1693,66 +1694,18 @@ bool CubicOps::inUnitTriangle(double eta, double chi) const
16931694
chiMax = std::sqrt(1.0 / (2.0 + std::tan(eta) * std::tan(eta)));
16941695
}
16951696
EbsdLibMath::bound(chiMax, -1.0, 1.0);
1696-
chiMax = acos(chiMax);
1697-
return !(eta < 0.0 || eta > (45.0 * EbsdLib::Constants::k_PiOver180D) || chi < 0.0 || chi > chiMax);
1698-
}
1699-
1700-
// -----------------------------------------------------------------------------
1701-
//
1702-
// -----------------------------------------------------------------------------
1703-
EbsdLib::Rgb CubicOps::generateIPFColor(double* eulers, double* refDir, bool convertDegrees) const
1704-
{
1705-
return generateIPFColor(eulers[0], eulers[1], eulers[2], refDir[0], refDir[1], refDir[2], convertDegrees);
1697+
chiMax = std::acos(chiMax);
1698+
return {CubicHigh::k_EtaMin * EbsdLib::Constants::k_DegToRadD, CubicHigh::k_EtaMax * EbsdLib::Constants::k_DegToRadD, chiMax};
17061699
}
17071700

17081701
// -----------------------------------------------------------------------------
17091702
//
17101703
// -----------------------------------------------------------------------------
1711-
EbsdLib::Rgb CubicOps::generateIPFColor(double phi1, double phi, double phi2, double refDir0, double refDir1, double refDir2, bool degToRad) const
1704+
bool CubicOps::inUnitTriangle(double eta, double chi) const
17121705
{
1713-
if(degToRad)
1714-
{
1715-
phi1 = phi1 * EbsdLib::Constants::k_DegToRadD;
1716-
phi = phi * EbsdLib::Constants::k_DegToRadD;
1717-
phi2 = phi2 * EbsdLib::Constants::k_DegToRadD;
1718-
}
1719-
1720-
EbsdLib::Matrix3X1D refDirection = {refDir0, refDir1, refDir2};
1721-
double chi = 0.0f;
1722-
double eta = 0.0f;
1723-
double _rgb[3] = {0.0, 0.0, 0.0};
1724-
1725-
OrientationType eu(phi1, phi, phi2);
1726-
OrientationType om(9); // Reusable for the loop
1727-
QuatD q1 = OrientationTransformation::eu2qu<OrientationType, QuatD>(eu);
1728-
1729-
for(int j = 0; j < CubicHigh::k_SymOpsCount; j++)
1730-
{
1731-
QuatD qu = getQuatSymOp(j) * q1;
1732-
EbsdLib::Matrix3X3D g(OrientationTransformation::qu2om<QuatD, OrientationType>(qu).data());
1733-
EbsdLib::Matrix3X1D p = (g * refDirection).normalize();
1734-
1735-
if(!getHasInversion() && p[2] < 0)
1736-
{
1737-
continue;
1738-
}
1739-
if(getHasInversion() && p[2] < 0)
1740-
{
1741-
p = p * -1.0;
1742-
}
1743-
chi = std::acos(p[2]);
1744-
eta = std::atan2(p[1], p[0]);
1745-
if(!inUnitTriangleD(eta, chi))
1746-
{
1747-
continue;
1748-
}
1749-
break;
1750-
}
1751-
double etaMin = 0.0;
1752-
double etaMax = 45.0;
17531706
double etaDeg = eta * EbsdLib::Constants::k_180OverPiD;
17541707
double chiMax;
1755-
if(etaDeg > 45.0)
1708+
if(etaDeg > CubicHigh::k_EtaMax)
17561709
{
17571710
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)));
17581711
}
@@ -1761,32 +1714,26 @@ EbsdLib::Rgb CubicOps::generateIPFColor(double phi1, double phi, double phi2, do
17611714
chiMax = std::sqrt(1.0 / (2.0 + std::tan(eta) * std::tan(eta)));
17621715
}
17631716
EbsdLibMath::bound(chiMax, -1.0, 1.0);
1764-
chiMax = std::acos(chiMax);
1765-
1766-
_rgb[0] = 1.0 - chi / chiMax;
1767-
_rgb[2] = std::fabs(etaDeg - etaMin) / (etaMax - etaMin);
1768-
_rgb[1] = 1 - _rgb[2];
1769-
_rgb[1] *= chi / chiMax;
1770-
_rgb[2] *= chi / chiMax;
1771-
_rgb[0] = std::sqrt(_rgb[0]);
1772-
_rgb[1] = std::sqrt(_rgb[1]);
1773-
_rgb[2] = std::sqrt(_rgb[2]);
1774-
1775-
double max = _rgb[0];
1776-
if(_rgb[1] > max)
1777-
{
1778-
max = _rgb[1];
1779-
}
1780-
if(_rgb[2] > max)
1781-
{
1782-
max = _rgb[2];
1783-
}
1717+
chiMax = acos(chiMax);
1718+
return !(eta < CubicHigh::k_EtaMin || eta > (CubicHigh::k_EtaMax * EbsdLib::Constants::k_PiOver180D) || chi < 0.0 || chi > chiMax);
1719+
}
17841720

1785-
_rgb[0] = _rgb[0] / max;
1786-
_rgb[1] = _rgb[1] / max;
1787-
_rgb[2] = _rgb[2] / max;
1721+
// -----------------------------------------------------------------------------
1722+
//
1723+
// -----------------------------------------------------------------------------
1724+
EbsdLib::Rgb CubicOps::generateIPFColor(double* eulers, double* refDir, bool degToRad) const
1725+
{
1726+
return computeIPFColor(eulers, refDir, degToRad);
1727+
}
17881728

1789-
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);
1729+
// -----------------------------------------------------------------------------
1730+
//
1731+
// -----------------------------------------------------------------------------
1732+
EbsdLib::Rgb CubicOps::generateIPFColor(double phi1, double phi, double phi2, double refDir0, double refDir1, double refDir2, bool degToRad) const
1733+
{
1734+
double eulers[3] = {phi1, phi, phi2};
1735+
double refDir[3] = {refDir0, refDir1, refDir2};
1736+
return computeIPFColor(eulers, refDir, degToRad);
17901737
}
17911738

17921739
// -----------------------------------------------------------------------------

Source/EbsdLib/LaueOps/CubicOps.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,12 @@ class EbsdLib_EXPORT CubicOps : public LaueOps
226226
double getF7(const QuatD& q1, const QuatD& q2, double LD[3], bool maxSF) const override;
227227

228228
void generateSphereCoordsFromEulers(EbsdLib::FloatArrayType* eulers, EbsdLib::FloatArrayType* xyz001, EbsdLib::FloatArrayType* xyz011, EbsdLib::FloatArrayType* xyz111) const override;
229-
229+
/**
230+
* @brief
231+
* @param eta Optional input value only needed for the "Cubic" Laue classes
232+
* @return Triplet of etaMin, etaMax, chiMax
233+
*/
234+
std::array<double, 3> getIpfColorAngleLimits(double eta) const override;
230235
/**
231236
* @brief generateIPFColor Generates an RGB Color from a Euler Angle and Reference Direction
232237
* @param eulers Pointer to the 3 component Euler Angle

0 commit comments

Comments
 (0)