hermespy-rt

Minimalistic signal processing ray-tracer in C
git clone https://git.ea.contact/hermespy-rt
Log | Files | Refs

commit 00ea7ef0221c473f83c89f35a8f2ff5ab6f23e37
parent d60ec29215f9830370268f13416b86804c68a5ca
Author: Egor Achkasov <eaachkasov@edu.hse.ru>
Date:   Wed, 14 May 2025 18:49:12 +0200

MSVC compatibility tweaks

Diffstat:
MCMakeLists.txt | 15++++++++-------
Mcompute_paths_pybind11.cpp | 4++--
Minc/common.h | 4+++-
Minc/vec3.h | 15++++++++++-----
Msrc/compute_paths.c | 1+
Msrc/scene.c | 4++--
Mtest/test.py | 2+-
7 files changed, 27 insertions(+), 18 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt @@ -1,4 +1,4 @@ -set(CMAKE_CXX_STANDARD 14) +set(CMAKE_CXX_STANDARD 20) set(CMAKE_CXX_STANDARD_REQUIRED ON) set(PYBIND11_NEWPYTHON ON) @@ -7,12 +7,13 @@ project(hermespy-rt) find_package(Python REQUIRED COMPONENTS Interpreter Development.Module) find_package(pybind11 CONFIG REQUIRED) -# Configure the C++ library -add_library(hermespy-rt-static STATIC compute_paths.c) -target_include_directories(hermespy-rt-static PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}) +# Configure the C library +add_library(hermespy-rt-static STATIC ${CMAKE_CURRENT_SOURCE_DIR}/src/scompute_paths.c ${CMAKE_CURRENT_SOURCE_DIR}/src/materials.c ${CMAKE_CURRENT_SOURCE_DIR}/src/materials.c ${CMAKE_CURRENT_SOURCE_DIR}/src/scene.c) +target_include_directories(hermespy-rt-static PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/inc) +set_target_properties(hermespy-rt-static PROPERTIES LINKER_LANGUAGE C) -# Configure the python module +# Configure the C++ binding module pybind11_add_module(hermespy-rt-binding MODULE compute_paths_pybind11.cpp) -set_target_properties(hermespy-rt-binding PROPERTIES OUTPUT_NAME "rt") +set_target_properties(hermespy-rt-binding PROPERTIES OUTPUT_NAME "hermespy-rt" LINKER_LANGUAGE CXX) target_link_libraries(hermespy-rt-binding PRIVATE hermespy-rt-static pybind11::headers) -target_include_directories(hermespy-rt-binding PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}) +target_include_directories(hermespy-rt-binding PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/inc) diff --git a/compute_paths_pybind11.cpp b/compute_paths_pybind11.cpp @@ -185,8 +185,8 @@ compute_paths_wrapper( ); } -PYBIND11_MODULE(rt, m) { - py::class_<ChannelInfoPython>(m, "PathsInfo") +PYBIND11_MODULE(hermespy_rt, m) { + py::class_<ChannelInfoPython>(m, "ChannelInfo") .def_readonly("num_paths", &ChannelInfoPython::num_paths) .def_readonly("directions_rx", &ChannelInfoPython::directions_rx) .def_readonly("directions_tx", &ChannelInfoPython::directions_tx) diff --git a/inc/common.h b/inc/common.h @@ -8,10 +8,12 @@ #define FREE_POINTERS(...) \ do { \ + if (sizeof((int[]){__VA_ARGS__}) > 0) { \ void *ptrs[] = {__VA_ARGS__};\ size_t cnt = sizeof(ptrs) / sizeof(ptrs[0]); \ for (size_t i = 0; i < cnt; i++) \ free(ptrs[i]); \ + } \ } while (0) /* Variadic arguments after rc are the pointers to free */ @@ -22,4 +24,4 @@ exit(rc); \ } while (0) -#endif +#endif /* COMMON_H */ diff --git a/inc/vec3.h b/inc/vec3.h @@ -9,19 +9,22 @@ typedef struct { static inline Vec3 vec3_sub(const Vec3 *a, const Vec3 *b) { - return (Vec3){a->x - b->x, a->y - b->y, a->z - b->z}; + Vec3 result = {a->x - b->x, a->y - b->y, a->z - b->z}; + return result; } static inline Vec3 vec3_add(const Vec3 *a, const Vec3 *b) { - return (Vec3){a->x + b->x, a->y + b->y, a->z + b->z}; + Vec3 result = {a->x + b->x, a->y + b->y, a->z + b->z}; + return result; } static inline Vec3 vec3_cross(const Vec3 *a, const Vec3 *b) { - return (Vec3){ + Vec3 result = { a->y * b->z - a->z * b->y, a->z * b->x - a->x * b->z, a->x * b->y - a->y * b->x }; + return result; } static inline float vec3_dot(const Vec3 *a, const Vec3 *b) { @@ -29,12 +32,14 @@ static inline float vec3_dot(const Vec3 *a, const Vec3 *b) } static inline Vec3 vec3_scale(const Vec3 *a, float s) { - return (Vec3){a->x * s, a->y * s, a->z * s}; + Vec3 result = {a->x * s, a->y * s, a->z * s}; + return result; } static inline Vec3 vec3_normalize(const Vec3 *a) { float norm = sqrtf(a->x * a->x + a->y * a->y + a->z * a->z); - return (Vec3){a->x / norm, a->y / norm, a->z / norm}; + Vec3 result = {a->x / norm, a->y / norm, a->z / norm}; + return result; } #endif /* VEC3_H */ \ No newline at end of file diff --git a/src/compute_paths.c b/src/compute_paths.c @@ -11,6 +11,7 @@ #include <stdio.h> /* for fopen, FILE, fclose */ #include <math.h> /* for sin, cos, sqrt */ #include <stdint.h> /* for int32_t, uint8_t */ +#include <float.h> /* for __FLT_EPSILON__ */ /* ==== CONSTANTS ==== */ diff --git a/src/scene.c b/src/scene.c @@ -10,7 +10,7 @@ void scene_save( ) { FILE *fp = fopen(filepath, "wb"); - if (!fp) + if (fp == NULL) PERROR_CLEANUP_EXIT("Error: cannot open file", 8); /* MAGIC */ @@ -37,7 +37,7 @@ Scene scene_load(IN const char *filepath) { /* Open the HRT file */ FILE *f = fopen(filepath, "rb"); - if (!f) + if (f == NULL) PERROR_CLEANUP_EXIT("Could not open scene file", 8); /* Parse the file */ diff --git a/test/test.py b/test/test.py @@ -2,7 +2,7 @@ import numpy as np import sys, os sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))) -import rt +import hermespy_rt as rt # Define inputs mesh_filepath = __file__[:__file__.rfind('/') + 1] + '../scenes/simple_reflector.hrt'