@@ -1955,11 +1955,47 @@ ebsdlib::UInt8ArrayType::Pointer CreateIPFLegend(const CubicOps* ops, int imageD
19551955} // namespace
19561956
19571957// -----------------------------------------------------------------------------
1958- std::array<float , 2 > CubicOps::adjustFigureOrigin (
1959- std::array<float , 2 > figureOrigin,
1960- int legendWidth, int legendHeight,
1961- const std::vector<float >& margins, float fontPtSize,
1962- bool generateEntirePlane) const
1958+ bool CubicOps::mapPixelToSphereSST (int xPixel, int yPixel, int imageDim, std::array<float , 3 >& sphereDir) const
1959+ {
1960+ double indexConst1 = 0.414 / static_cast <double >(imageDim);
1961+ double indexConst2 = 0.207 / static_cast <double >(imageDim);
1962+
1963+ double x = xPixel * indexConst1 + indexConst2;
1964+ double y = yPixel * indexConst1 + indexConst2;
1965+
1966+ double sumSquares = (x * x) + (y * y);
1967+ if (sumSquares > 1.0 )
1968+ {
1969+ return false ;
1970+ }
1971+ if (y < 0.0 || x < 0.0 )
1972+ {
1973+ return false ;
1974+ }
1975+
1976+ auto sc = stereographic::utils::StereoToSpherical (x, y).normalize ();
1977+
1978+ double k_RootOfHalf = std::sqrt (0.5 );
1979+ double red1 = sc[0 ] * (-k_RootOfHalf) + sc[2 ] * k_RootOfHalf;
1980+ double phi = std::acos (red1);
1981+ double x1alt = sc[0 ] / k_RootOfHalf;
1982+ x1alt = x1alt / std::sqrt ((x1alt * x1alt) + (sc[1 ] * sc[1 ]));
1983+ double theta = std::acos (x1alt);
1984+
1985+ if (phi <= (45.0 * ebsdlib::constants::k_PiOver180D) || phi >= (90.0 * ebsdlib::constants::k_PiOver180D) || theta >= (35.26 * ebsdlib::constants::k_PiOver180D))
1986+ {
1987+ return false ;
1988+ }
1989+
1990+ sphereDir[0 ] = static_cast <float >(sc[0 ]);
1991+ sphereDir[1 ] = static_cast <float >(sc[1 ]);
1992+ sphereDir[2 ] = static_cast <float >(sc[2 ]);
1993+ return true ;
1994+ }
1995+
1996+ // -----------------------------------------------------------------------------
1997+ std::array<float , 2 > CubicOps::adjustFigureOrigin (std::array<float , 2 > figureOrigin, int legendWidth, int legendHeight, const std::vector<float >& margins, float fontPtSize,
1998+ bool generateEntirePlane) const
19631999{
19642000 if (!generateEntirePlane)
19652001 {
@@ -2104,12 +2140,7 @@ ebsdlib::UInt8ArrayType::Pointer CubicOps::generateIPFTriangleLegend(int canvasD
21042140{
21052141 // Compute legend dimensions (same formula as annotateIPFImage uses)
21062142 const float fontPtSize = static_cast <float >(canvasDim) / 24 .0f ;
2107- const std::vector<float > margins = {
2108- fontPtSize * 3 ,
2109- static_cast <float >(canvasDim / 7 .0f ),
2110- fontPtSize * 2 ,
2111- static_cast <float >(canvasDim / 7 .0f )
2112- };
2143+ const std::vector<float > margins = {fontPtSize * 3 , static_cast <float >(canvasDim / 7 .0f ), fontPtSize * 2 , static_cast <float >(canvasDim / 7 .0f )};
21132144 int legendHeight = canvasDim - static_cast <int >(margins[0 ]) - static_cast <int >(margins[2 ]);
21142145 int legendWidth = canvasDim - static_cast <int >(margins[1 ]) - static_cast <int >(margins[3 ]);
21152146 if (legendHeight > legendWidth)
0 commit comments