Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,49 @@ option(RAYX_REQUIRE_H5 "If option 'RAYX_ENABLE_H5' is ON, this option will add t
option(RAYX_STATIC_LIB "This option builds 'rayx-core' as a static library." OFF)
# ------------------

# ---- Specific macos compiler options and flags concerning OpenMP ----
if(APPLE)
# Detect architecture and package manager
if(CMAKE_SYSTEM_PROCESSOR MATCHES "arm64")
set(HOMEBREW_PREFIX "/opt/homebrew")
else()
set(HOMEBREW_PREFIX "/usr/local")
endif()

# MacPorts detection
if(EXISTS "/opt/local/include/libomp")
set(OpenMP_INCLUDE_DIR "/opt/local/include/libomp")
set(OpenMP_LIBRARY "/opt/local/lib/libomp.dylib")
message(STATUS "Using MacPorts OpenMP installation")
else()
# Homebrew fallback
set(OpenMP_INCLUDE_DIR "${HOMEBREW_PREFIX}/opt/libomp/include")
set(OpenMP_LIBRARY "${HOMEBREW_PREFIX}/opt/libomp/lib/libomp.dylib")
message(STATUS "Using Homebrew OpenMP installation")
endif()

# Common OpenMP settings
set(OpenMP_C_FLAGS "-Xpreprocessor -fopenmp -I${OpenMP_INCLUDE_DIR}")
set(OpenMP_CXX_FLAGS "-Xpreprocessor -fopenmp -I${OpenMP_INCLUDE_DIR}")
set(OpenMP_C_LIB_NAMES "omp")
set(OpenMP_CXX_LIB_NAMES "omp")
set(OpenMP_omp_LIBRARY "${OpenMP_LIBRARY}")
set(OpenMP_omp_INCLUDE_DIRS "${OpenMP_INCLUDE_DIR}")

if(RAYX_ENABLE_OPENMP)
find_package(OpenMP REQUIRED)
if(OpenMP_CXX_FOUND)
message(STATUS "OpenMP found:")
message(STATUS " Include dirs: ${OpenMP_CXX_INCLUDE_DIRS}")
message(STATUS " Libraries: ${OpenMP_CXX_LIBRARIES}")

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
include_directories(${OpenMP_omp_INCLUDE_DIRS})
link_libraries(${OpenMP_omp_LIBRARY})
endif()
endif()
endif()


# ---- Build options ----
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE ${CMAKE_BINARY_DIR}/bin/release)
Expand Down
15 changes: 14 additions & 1 deletion Intern/rayx-core/src/Rml/Locate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
#include <windows.h>
#elif defined(__APPLE__)
#include <cassert>
#include <libproc.h>
#include <unistd.h>
#else
#include <limits.h>
#include <unistd.h>
Expand Down Expand Up @@ -63,6 +65,17 @@ std::filesystem::path ResourceHandler::getExecutablePath() {
// If the buffer was too small, increase size and retry
buffer.resize(buffer.size() * 2);
}
#elif defined(__APPLE__)
std::vector<char> buffer(PROC_PIDPATHINFO_MAXSIZE);
pid_t pid = getpid();
int ret = proc_pidpath(pid, buffer.data(), buffer.size());
if (ret <= 0) {
// Fehler beim Auslesen des Pfads
return std::filesystem::path();
}
buffer[ret] = '\0'; // Null-terminieren, falls nicht bereits geschehen
// Optional: buffer kann länger als der Pfad sein, daher String kürzen
return std::filesystem::path(buffer.data());

#else
static_assert(false, "macOS support is not implemented yet");
Expand All @@ -80,7 +93,7 @@ std::filesystem::path ResourceHandler::getFullPath(const std::filesystem::path&
}
}

#if defined(__linux__)
#if defined(__linux__) || defined(__APPLE__)
// Check in /usr (package install)
std::filesystem::path path = std::filesystem::path("/usr") / baseDir / relativePath;
if (fileExists(path)) return path;
Expand Down
46 changes: 31 additions & 15 deletions Intern/rayx-core/src/Shader/Diffraction.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "Diffraction.h"

#include <boost/math/special_functions/bessel.hpp>
#include "Approx.h"
#include "Constants.h"
#include "Rand.h"
Expand All @@ -20,24 +21,38 @@ double RAYX_API fact(int a) {

/**returns first bessel function of parameter v*/
RAYX_FN_ACC
double RAYX_API bessel1(double v) {
if (v < 0.0 || v > 20.0) {
return 0.0;
}
double RAYX_API bessel1(double x) {
// if (v < 0.0 || v > 20.0) {
// return 0.0;
// }

// double sum = 0;
// int large = 80;

double sum = 0;
int large = 30;
// double PO1;
// double PO2;
// double FA1;
// for (int small = 0; small <= large; small++) {
// PO1 = dpow(-1.0, small);
// PO2 = dpow(v / 2.0, 2 * small + 1);
// FA1 = fact(small);
// sum += (PO1 / (FA1 * FA1 * (small + 1))) * PO2;
// }
// return sum;

double PO1;
double PO2;
double FA1;
for (int small = 0; small <= large; small++) {
PO1 = dpow(-1.0, small);
PO2 = dpow(v / 2.0, 2 * small + 1);
FA1 = fact(small);
sum += (PO1 / (FA1 * FA1 * (small + 1))) * PO2;
if (x < 0) {
// x = std::abs(x); // Nur anwendbar, wenn Jᵥ(-x) = (-1)ᵛ Jᵥ(x)
}
return sum;
if (std::isnan(x) || std::isinf(x)) {
return std::numeric_limits<double>::quiet_NaN();
}
//try {
return boost::math::cyl_bessel_j(1.0, x);
//}
//catch (...) {
// return std::numeric_limits<double>::signaling_NaN();
//}

}

/**
Expand Down Expand Up @@ -67,6 +82,7 @@ void bessel_diff(double radius, double wl, double& __restrict dphi, double& __re
double u = 2.0 * PI * b * xi / wl;
double wd = 1;
if (u != 0) {
std::cout << "u: " << u << std::endl;
wd = 2.0 * bessel1(u) / u;
wd = wd * wd;
}
Expand Down
Loading
Loading