A header only library to compute spherical harmonic function.
The algorithm is taken from the article below.
Peter-Pike Sloan, Efficient Spherical Harmonic Evaluation, Journal of Computer Graphics Techniques (JCGT), vol. 2, no. 2, 84-90, 2013 Available online http://jcgt.org/published/0002/02/06/
The original code included in the article uses meta-programming technique which generates C source code as characters by a program written in C++.
ConstexprSHEval.hpp
uses compile-time calculation in modern C++ feature and it can be called directly from other C++ codes without compilation in advance.
#include "ConstexprSHEval.hpp"
namespace cshe = novonotes::constexprsheval
constexpr int ORDER = 7;
auto res = cshe::SHEvalExec<ORDER>(x,y,z);
--std=gnu++17
is needed to use constexpr feature.-fconstexpr-depth=-1
-fconstexpr-steps=-1
are also necessary to disable a limit of maximum loop in computation (To compute sqrt on compile-time, Newton-Method is used to approximate).
SIMD-compatible version, which is originally contained is not implemented yet.
- codegen - contains original implementation using meta-programming
- generated - contains actual evaluation C codes generated by SHEvalCodeGen
- test
- minimaltest.cpp - simple test program for ConstExprSHEval.hpp to inspect assembly or LLVM IR
- ConstexprSHEvalTest.cpp - test program which compares the functions between Codegen and Constexpr.
- ConstexprSHEval.hpp - A main library code.
- removed unused windows dependency
- uses std::filesystem to open files
- added sign flip option to match an axis coordinate which is used in IEM Plugin Suite.
- added cmake configuration
The test programs (and original code generator program) can be compiled with CMake.
mkdir build && cd build
cmake ..
cmake --build . -j
uncomment the line below in CMakeLists.txt
# set if you want to use SIMD for x86 arch code
# target_compile_definitions(shevalcodegen PRIVATE GENSSE)