-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #584 from HEXRD/inverse-distortion
Inverse distortion
- Loading branch information
Showing
11 changed files
with
1,214 additions
and
182 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
CXX = c++ | ||
CXXFLAGS = -O3 -Wall -shared -fPIC -funroll-loops -Wno-maybe-uninitialized -fopenmp | ||
INCLUDES = -I/${CONDA_PREFIX}/include/eigen3/ -I/${CONDA_PREFIX}/include/xsimd -I/${CONDA_PREFIX}/include -I/${CONDA_PREFIX}/include/python3.11/ | ||
SRCS_INVERSE_DISTORTION = src/inverse_distortion.cpp | ||
TARGET_DIR = ../../extensions/ | ||
TARGET_NAME_INVERSE_DISTORTION = inverse_distortion | ||
EXTENSION_SUFFIX = $(shell python3-config --extension-suffix) | ||
|
||
all: inverse_distortion | ||
|
||
inverse_distortion: $(TARGET_DIR)$(TARGET_NAME_INVERSE_DISTORTION)$(EXTENSION_SUFFIX) | ||
|
||
$(TARGET_DIR)$(TARGET_NAME_INVERSE_DISTORTION)$(EXTENSION_SUFFIX): $(SRCS_INVERSE_DISTORTION) | ||
$(CXX) $(CXXFLAGS) $(PYBIND_INCLUDES) $< -o $@ $(INCLUDES) | ||
|
||
.PHONY: clean inverse_distortion | ||
clean: | ||
rm -f $(TARGET_DIR)$(TARGET_NAME_INVERSE_DISTORTION)$(EXTENSION_SUFFIX) |
31 changes: 31 additions & 0 deletions
31
hexrd/transforms/cpp_sublibrary/src/inverse_distortion.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#include <pybind11/pybind11.h> | ||
#include <pybind11/eigen.h> | ||
#include <Eigen/Core> | ||
|
||
namespace py = pybind11; | ||
constexpr double FOUR_THIRDS_PI = 4.1887902; | ||
constexpr double N_THREE_HALVES_SQRT_3 = -2.59807621; | ||
constexpr double TWO_OVER_SQRT_THREE = 1.154700538; | ||
|
||
Eigen::ArrayXXd ge_41rt_inverse_distortion(const Eigen::ArrayXXd& inputs, const double rhoMax, const Eigen::ArrayXd& params) { | ||
Eigen::ArrayXd radii = inputs.matrix().rowwise().norm(); | ||
if (radii.maxCoeff() < 1e-10) { | ||
return Eigen::ArrayXXd::Zero(inputs.rows(), inputs.cols()); | ||
} | ||
Eigen::ArrayXd inverted_radii = radii.cwiseInverse(); | ||
Eigen::ArrayXd cosines = inputs.col(0) * inverted_radii; | ||
Eigen::ArrayXd cosine_double_angles = 2*cosines.square() - 1; | ||
Eigen::ArrayXd cosine_quadruple_angles = 2*cosine_double_angles.square() - 1; | ||
Eigen::ArrayXd sqrt_p_is = rhoMax / (-params[0]*cosine_double_angles - params[1]*cosine_quadruple_angles - params[2]).sqrt(); | ||
Eigen::ArrayXd solutions = TWO_OVER_SQRT_THREE*sqrt_p_is*(acos(N_THREE_HALVES_SQRT_3*radii/sqrt_p_is)/3 + FOUR_THIRDS_PI).cos(); | ||
Eigen::ArrayXXd results = solutions.rowwise().replicate(inputs.cols()).array() * inputs * inverted_radii.rowwise().replicate(inputs.cols()).array(); | ||
|
||
return results; | ||
} | ||
|
||
PYBIND11_MODULE(inverse_distortion, m) | ||
{ | ||
m.doc() = "HEXRD inverse distribution plugin"; | ||
|
||
m.def("ge_41rt_inverse_distortion", &ge_41rt_inverse_distortion, "Inverse distortion for ge_41rt"); | ||
} |
Oops, something went wrong.