star-uvm

Spatial structuring of unstructured volumetric meshes
git clone git://git.meso-star.fr/star-uvm.git
Log | Files | Refs | README | LICENSE

commit 6669d68db125c3e24e8d67b26e3e6521ad2dd109
parent 3166608b31663ff8ec98eb6da4950cd2189d7a46
Author: Vincent Forest <vincent.forest@meso-star.com>
Date:   Fri, 27 Oct 2023 12:31:33 +0200

Merge branch 'release_0.3'

Diffstat:
M.gitignore | 16+++++++++-------
AMakefile | 176+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
MREADME.md | 86++++++++++++++++++++++++++++++++++++++++++++-----------------------------------
Dcmake/CMakeLists.txt | 122-------------------------------------------------------------------------------
Aconfig.mk | 88+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Amake.sh | 70++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/suvm_backend.h | 34++++++++++++++++++++++++++++++++++
Msrc/suvm_c.h | 2+-
Msrc/suvm_device.h | 2+-
Msrc/suvm_volume.c | 4+++-
Msrc/suvm_volume.h | 4++--
Msrc/suvm_voxelize.c | 7+++++--
Asuvm.pc.in | 12++++++++++++
13 files changed, 449 insertions(+), 174 deletions(-)

diff --git a/.gitignore b/.gitignore @@ -1,12 +1,14 @@ .gitignore -CMakeCache.txt -CMakeFiles -Makefile -tmp [Bb]uild* *.sw[po] -*.[ao] -*.orig +*.[aod] +*.so *~ +test* +!test*.[ch] +.config +.test tags - +*.pc +*.vtk +suvm_voxelize diff --git a/Makefile b/Makefile @@ -0,0 +1,176 @@ +# Copyright (C) 2020-2023 |Méso|Star> (contact@meso-star.com) +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. */ + +.POSIX: +.SUFFIXES: # Clean up default inference rules + +include config.mk + +LIBNAME_STATIC = libsuvm.a +LIBNAME_SHARED = libsuvm.so +LIBNAME = $(LIBNAME_$(LIB_TYPE)) + +################################################################################ +# Library building +################################################################################ +SRC =\ + src/suvm_device.c\ + src/suvm_primitive.c\ + src/suvm_volume.c\ + src/suvm_volume_at.c\ + src/suvm_volume_intersect_aabb.c +OBJ = $(SRC:.c=.o) +DEP = $(SRC:.c=.d) + +build_library: .config $(DEP) + @$(MAKE) -fMakefile $$(for i in $(DEP); do echo -f $${i}; done) \ + $$(if [ -n "$(LIBNAME)" ]; then\ + echo "$(LIBNAME)";\ + else\ + echo "$(LIBNAME_SHARED)";\ + fi) + +$(DEP) $(OBJ): config.mk + +$(LIBNAME_SHARED): $(OBJ) + $(CC) -std=c99 $(CFLAGS_SO) $(DPDC_CFLAGS) -o $@ $(OBJ) $(LDFLAGS_SO) $(DPDC_LIBS) + +$(LIBNAME_STATIC): libsuvm.o + $(AR) -rc $@ $? + $(RANLIB) $@ + +libsuvm.o: $(OBJ) + $(LD) -r $(OBJ) -o $@ + $(OBJCOPY) $(OCPFLAGS) $@ + +.config: config.mk + @if ! $(PKG_CONFIG) --atleast-version $(EMBREE_VERSION) embree4; then \ + echo "embree4 $(EMBREE_VERSION) not found" >&2; exit 1; fi + @if ! $(PKG_CONFIG) --atleast-version $(RSYS_VERSION) rsys; then \ + echo "rsys $(RSYS_VERSION) not found" >&2; exit 1; fi + @echo "config done" > $@ + +.SUFFIXES: .c .d .o +.c.d: + @$(CC) -std=c99 $(CFLAGS_SO) $(DPDC_CFLAGS) -MM -MT "$(@:.d=.o) $@" $< -MF $@ + +.c.o: + $(CC) -std=c99 $(CFLAGS_SO) $(DPDC_CFLAGS) -DSUVM_SHARED_BUILD -c $< -o $@ + +################################################################################ +# Installation +################################################################################ +pkg: + sed -e 's#@PREFIX@#$(PREFIX)#g'\ + -e 's#@VERSION@#$(VERSION)#g'\ + -e 's#@EMBREE_VERSION@#$(EMBREE_VERSION)#g'\ + -e 's#@RSYS_VERSION@#$(RSYS_VERSION)#g'\ + suvm.pc.in > suvm.pc + +suvm-local.pc: suvm.pc.in + sed -e '1d'\ + -e 's#^includedir=.*#includedir=./src/#'\ + -e 's#^libdir=.*#libdir=./#'\ + -e 's#@VERSION@#$(VERSION)#g'\ + -e 's#@EMBREE_VERSION@#$(EMBREE_VERSION)#g'\ + -e 's#@RSYS_VERSION@#$(RSYS_VERSION)#g'\ + suvm.pc.in > $@ + +install: build_library pkg + @$(SHELL) make.sh install "$(DESTDIR)$(PREFIX)/lib" $(LIBNAME) + @$(SHELL) make.sh install "$(DESTDIR)$(PREFIX)/lib/pkgconfig" suvm.pc + @$(SHELL) make.sh install "$(DESTDIR)$(PREFIX)/include/star" src/suvm.h + @$(SHELL) make.sh install "$(DESTDIR)$(PREFIX)/share/doc/star-uvm" COPYING README.md + +uninstall: + rm -f "$(DESTDIR)$(PREFIX)/lib/$(LIBNAME)" + rm -f "$(DESTDIR)$(PREFIX)/lib/pkgconfig/suvm.pc" + rm -f "$(DESTDIR)$(PREFIX)/include/star/suvm.h" + rm -f "$(DESTDIR)$(PREFIX)/share/doc/star-uvm/COPYING" + rm -f "$(DESTDIR)$(PREFIX)/share/doc/star-uvm/README.md" + +################################################################################ +# Miscellaneous targets +################################################################################ +all: build_library build_tests + +clean: clean_test + rm -f $(OBJ) $(TEST_OBJ) $(LIBNAME) + rm -f .config .test libsuvm.o suvm.pc suvm-local.pc + rm -f ball.vtk box.vtk + +distclean: clean + rm -f $(DEP) $(TEST_DEP) + +lint: + shellcheck -o all make.sh + +################################################################################ +# Tests +################################################################################ +TEST_SRC =\ + src/test_suvm_device.c\ + src/test_suvm_volume.c\ + src/test_suvm_primitive_intersection.c +TEST_OBJ = $(TEST_SRC:.c=.o) +TEST_DEP = $(TEST_SRC:.c=.d) + +SMSH_FOUND = $(PKG_CONFIG) --atleast-version $(SMSH_VERSION) smsh + +PKG_CONFIG_LOCAL = PKG_CONFIG_PATH="./:$${PKG_CONFIG_PATH}" $(PKG_CONFIG) +SUVM_CFLAGS = $$($(PKG_CONFIG_LOCAL) $(PCFLAGS) --cflags suvm-local.pc) +SUVM_LIBS = $$($(PKG_CONFIG_LOCAL) $(PCFLAGS) --libs suvm-local.pc) + +build_tests: build_library $(TEST_DEP) .test + @if $(SMSH_FOUND); then $(MAKE) src/suvm_voxelize.d; fi; \ + $(MAKE) -fMakefile -f.test \ + $$(for i in $(TEST_DEP); do echo -f"$${i}"; done) \ + $$($(SMSH_FOUND) && echo "-fsrc/suvm_voxelize.d") \ + test_bin + +test: build_tests + @$(SHELL) make.sh run_test $(TEST_SRC) + +.test: Makefile + @{ $(SHELL) make.sh config_test $(TEST_SRC); \ + if $(SMSH_FOUND); then \ + $(SHELL) make.sh config_test src/suvm_voxelize.c; fi \ + } > $@ + +clean_test: + $(SHELL) make.sh clean_test $(TEST_SRC) src/suvm_voxelize.c + +$(TEST_DEP): config.mk suvm-local.pc + @$(CC) -std=c89 $(CFLAGS_EXE) $(RSYS_CFLAGS) $(SUVM_CFLAGS) \ + -MM -MT "$(@:.d=.o) $@" $(@:.d=.c) -MF $@ + +src/suvm_voxelize.d: config.mk suvm-local.pc + @$(CC) -std=c89 $(CFLAGS_EXE) $(RSYS_CFLAGS) $(SUVM_CFLAGS) $(SMSH_CFLAGS) \ + -MM -MT "$(@:.d=.o) $@" $(@:.d=.c) -MF $@ + +$(TEST_OBJ): config.mk suvm-local.pc + $(CC) -std=c89 $(CFLAGS_EXE) $(RSYS_CFLAGS) $(SUVM_CFLAGS) -c $(@:.o=.c) -o $@ + +src/suvm_voxelize.o: config.mk suvm-local.pc + $(CC) -std=c89 $(CFLAGS_EXE) $(RSYS_CFLAGS) $(SUVM_CFLAGS) $(SMSH_CFLAGS) -c $(@:.o=.c) -o $@ + +test_suvm_device \ +test_suvm_volume \ +test_suvm_primitive_intersection \ +: config.mk suvm-local.pc $(LIBNAME) + $(CC) -std=c89 $(CFLAGS_EXE) -o $@ src/$@.o $(LDFLAGS_EXE) $(SUVM_LIBS) $(RSYS_LIBS) -lm + +suvm_voxelize: config.mk suvm-local.pc $(LIBNAME) + $(CC) -std=c89 $(CFLAGS_EXE) -o $@ src/$@.o $(LDFLAGS_EXE) $(SUVM_LIBS) $(RSYS_LIBS) $(SMSH_LIBS) -lm diff --git a/README.md b/README.md @@ -1,52 +1,62 @@ -# Star-UnstructuredVolumetricMesh - -Star-UVM is a C library whose goal is to manage unstructured volumetric meshes -defined by a soup of tetrahedra. Once spatially partitioned, the user can -efficiently identify tetrahedra cut by an axis aligned box or access the -specific tetrahedron that encompasses a given position. - -Only geometric data is processed by Star-UVM. No assumption is made on their -associated properties. Either way, Star-UVM provides data, such as primitive -indices and barycentric coordinates, needed to retrieve the properties attached -to each tetrahedron. These properties can thus be managed externally without -arbitrary constraints imposed by Star-UVM on their size, alignment or type. - -## How to build - -Star-UVM relies on the [CMake](http://www.cmake.org) and the -[RCMake](https://gitlab.com/vaplv/rcmake/) packages to build. It also depends -on the [RSys](https://gitlab.com/vaplv/rsys/) and -[Embree](https://embree.github.io/) libraries. It is compatible -GNU/Linux on x86-64 architectures. - -First ensure that CMake is installed on your system. Then install the RCMake -package as well as the aforementioned prerequisites. Finally generate the -project from the `cmake/CMakeLists.txt` file by appending to the -`CMAKE_PREFIX_PATH` variable the install directories of its dependencies. The -resulting project can be edited, built, tested and installed as any CMake -project. Refer to the [CMake](https://cmake.org/documentation) for further -informations on CMake. +# Star Unstructured Volumetric Mesh + +Star-UVM is a C library whose goal is to manage unstructured volumetric +meshes defined by a soup of tetrahedra. Once spatially partitioned, the +user can efficiently identify tetrahedra cut by an axis aligned box or +access the specific tetrahedron that encompasses a given position. + +Only geometric data is processed by Star-UVM. No assumption is made on +their associated properties. Either way, Star-UVM provides data, such as +primitive indices and barycentric coordinates, needed to retrieve the +properties attached to each tetrahedron. These properties can thus be +managed externally without arbitrary constraints imposed by Star-UVM on +their size, alignment or type. + +## Requirements + +- C compiler (C99) +- POSIX make +- pkg-config +- [Embree](https://github.com/embree/embree) +- [RSys](https://gitlab.com/vaplv/rsys) +- [Star-Mesh](https://gitlab.com/meso-star/star-mesh) (optional) + +## Installation + +Edit config.mk as needed, then run: + + make clean install ## Release notes +### Version 0.3 + +- Replace CMake by Makefile as build system. +- Update compiler and linker flags to increase the security and + robustness of generated binaries. +- Provide a pkg-config file to link the library as an external + dependency. +- Fix compilation warnings. + ### Version 0.2 -Update of the acceleration data structure backend from Embree3 to Embree4 +Update of the acceleration data structure backend from Embree3 to +Embree4 ### Version 0.1 -- Add the `suvm_mesh_desc_compute_hash` function which uses sha256 encryption - to calculate a digest from the mesh data. -- Add the `suvm_get_mesh_desc` function that returns the mesh data, i.e. the - list of node positions and the list of cell indexes. +- Add the `suvm_mesh_desc_compute_hash` function which uses sha256 + encryption to calculate a digest from the mesh data. +- Add the `suvm_get_mesh_desc` function that returns the mesh data, i.e. + the list of node positions and the list of cell indexes. - Replace the obsolete Star-Tetrahedra dependency with Star-Mesh. - Work around a numerical inaccuracy of barycentric coordinates. - Fix warnings detected by gcc 11. ## License -Copyright (C) 2020-2023 [|Méso|Star>](https://www.meso-star.com) -(<contact@meso-star.com>). Star-UnstructuredVolumetricMesh is free software -released under the GPL v3+ license: GNU GPL version 3 or later. You are welcome -to redistribute it under certain conditions; refer to the COPYING file for -details. +Copyright (C) 2020-2023 |Méso|Star> (contact@meso-star.com) + +Star-UVM is free software released under the GPL v3+ license: GNU GPL +version 3 or later. You are welcome to redistribute it under certain +conditions; refer to the COPYING file for details. diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt @@ -1,122 +0,0 @@ -# Copyright (C) 2020-2023 |Méso|Star> (contact@meso-star.com) -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see <http://www.gnu.org/licenses/>. - -cmake_minimum_required(VERSION 3.1) -project(suvm C) -enable_testing() - -set(SUVM_SOURCE_DIR ${PROJECT_SOURCE_DIR}/../src) -option(NO_TEST "Do not build tests" OFF) - -################################################################################ -# Check dependencies -################################################################################ -find_package(Embree 4.0 REQUIRED) -find_package(RCMake 0.4 REQUIRED) -find_package(RSys 0.13 REQUIRED) -if(NOT NO_TEST) - find_package(StarMesh) -endif() - -set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${RCMAKE_SOURCE_DIR}) -include(rcmake) -include(rcmake_runtime) - -include_directories(${RSys_INCLUDE_DIR}) - -if(CMAKE_COMPILER_IS_GNUCC) - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c99") -endif() - -################################################################################ -# Configure and define targets -################################################################################ -set(VERSION_MAJOR 0) -set(VERSION_MINOR 2) -set(VERSION_PATCH 0) -set(VERSION ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}) - -set(SUVM_FILES_SRC - suvm_device.c - suvm_primitive.c - suvm_volume.c - suvm_volume_at.c - suvm_volume_intersect_aabb.c) -set(SUVM_FILES_INC - suvm_device.h - suvm_volume.h) -set(SUVM_FILES_INC_API - suvm.h) - -set(SUVM_FILES_DOC COPYING README.md) - -# Prepend each file in the `SUVM_FILES_<SRC|INC>' list by `SUVM_SOURCE_DIR' -rcmake_prepend_path(SUVM_FILES_SRC ${SUVM_SOURCE_DIR}) -rcmake_prepend_path(SUVM_FILES_INC ${SUVM_SOURCE_DIR}) -rcmake_prepend_path(SUVM_FILES_INC_API ${SUVM_SOURCE_DIR}) -rcmake_prepend_path(SUVM_FILES_DOC ${PROJECT_SOURCE_DIR}/../) - -add_library(suvm SHARED ${SUVM_FILES_SRC} ${SUVM_FILES_INC} ${SUVM_FILES_INC_API}) -target_link_libraries(suvm RSys ${EMBREE_LIBRARIES}) -if(CMAKE_COMPILER_IS_GNUCC) - target_link_libraries(suvm m) -endif() - -set_target_properties(suvm PROPERTIES - DEFINE_SYMBOL SUVM_SHARED_BUILD - VERSION ${VERSION} - SOVERSION ${VERSION_MAJOR}) - -rcmake_setup_devel(suvm StarUVM ${VERSION} star/suvm_version.h) - -################################################################################ -# Add tests -################################################################################ -if(NOT NO_TEST) - function(build_test _name) - add_executable(${_name} - ${SUVM_SOURCE_DIR}/${_name}.c - ${SUVM_SOURCE_DIR}/test_suvm_utils.h) - target_link_libraries(${_name} suvm RSys ${ARGN}) - endfunction() - - function(new_test _name) - build_test(${_name} ${ARGN}) - add_test(${_name} ${_name}) - endfunction() - - new_test(test_suvm_device) - new_test(test_suvm_volume) - new_test(test_suvm_primitive_intersection) - - if(StarMesh_FOUND) - add_executable(suvm_voxelize ${SUVM_SOURCE_DIR}/suvm_voxelize.c) - target_link_libraries(suvm_voxelize RSys StarMesh suvm) - else() - message(STATUS "Star-Mesh was not found. " - "The program suvm_voxelize will not be built") - endif() -endif() - -################################################################################ -# Define output & install directories -################################################################################ -install(TARGETS suvm - ARCHIVE DESTINATION bin - LIBRARY DESTINATION lib - RUNTIME DESTINATION bin) -install(FILES ${SUVM_FILES_INC_API} DESTINATION include/star) -install(FILES ${SUVM_FILES_DOC} DESTINATION share/doc/star-uvm) - diff --git a/config.mk b/config.mk @@ -0,0 +1,88 @@ +VERSION = 0.3.0 +PREFIX = /usr/local + +LIB_TYPE = SHARED +#LIB_TYPE = STATIC + +BUILD_TYPE = RELEASE +#BUILD_TYPE = DEBUG + +################################################################################ +# Tools +################################################################################ +AR = ar +CC = cc +LD = ld +OBJCOPY = objcopy +PKG_CONFIG = pkg-config +RANLIB = ranlib + +################################################################################ +# Dependencies +################################################################################ +PCFLAGS_STATIC = --static +PCFLAGS = $(PCFLAGS_$(LIB_TYPE)) + +EMBREE_VERSION = 4.0 +EMBREE_CFLAGS = $$($(PKG_CONFIG) $(PCFLAGS) --cflags embree4) +EMBREE_LIBS = $$($(PKG_CONFIG) $(PCFLAGS) --libs embree4) + +RSYS_VERSION = 0.14 +RSYS_CFLAGS = $$($(PKG_CONFIG) $(PCFLAGS) --cflags rsys) +RSYS_LIBS = $$($(PKG_CONFIG) $(PCFLAGS) --libs rsys) + +# Optional (required only by suvm_voxelize tool) +SMSH_VERSION = 0.1 +SMSH_CFLAGS = $$($(PKG_CONFIG) $(PCFLAGS) --cflags smsh) +SMSH_LIBS = $$($(PKG_CONFIG) $(PCFLAGS) --libs smsh) + +DPDC_CFLAGS = $(EMBREE_CFLAGS) $(RSYS_CFLAGS) +DPDC_LIBS = $(EMBREE_LIBS) $(RSYS_LIBS) -lm + +################################################################################ +# Compilation options +################################################################################ +WFLAGS =\ + -Wall\ + -Wcast-align\ + -Wconversion\ + -Wextra\ + -Wmissing-declarations\ + -Wmissing-prototypes\ + -Wshadow + +CFLAGS_HARDENED =\ + -D_FORTIFY_SOURCES=2\ + -fcf-protection=full\ + -fstack-clash-protection\ + -fstack-protector-strong + +CFLAGS_COMMON =\ + -pedantic\ + -fPIC\ + -fvisibility=hidden\ + -fstrict-aliasing\ + $(CFLAGS_HARDENED)\ + $(WFLAGS) + +CFLAGS_DEBUG = -g $(CFLAGS_COMMON) +CFLAGS_RELEASE = -O2 -DNDEBUG $(CFLAGS_COMMON) +CFLAGS = $(CFLAGS_$(BUILD_TYPE)) + +CFLAGS_SO = $(CFLAGS) -fPIC +CFLAGS_EXE = $(CFLAGS) -fPIE + +################################################################################ +# Linker options +################################################################################ +LDFLAGS_HARDENED = -Wl,-z,relro,-z,now +LDFLAGS_DEBUG = $(LDFLAGS_HARDENED) +LDFLAGS_RELEASE = -s $(LDFLAGS_HARDENED) +LDFLAGS = $(LDFLAGS_$(BUILD_TYPE)) + +LDFLAGS_SO = $(LDFLAGS) -shared -Wl,--no-undefined +LDFLAGS_EXE = $(LDFLAGS) -pie + +OCPFLAGS_DEBUG = --localize-hidden +OCPFLAGS_RELEASE = --localize-hidden --strip-unneeded +OCPFLAGS = $(OCPFLAGS_$(BUILD_TYPE)) diff --git a/make.sh b/make.sh @@ -0,0 +1,70 @@ +#!/bin/sh + +# Copyright (C) 2020-2023 |Méso|Star> (contact@meso-star.com) +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. */ + +set -e + +config_test() +{ + for i in "$@"; do + test=$(basename "${i}" ".c") + test_list="${test_list} ${test}" + printf "%s: %s\n" "${test}" "src/${test}.o" + done + printf "test_bin: %s\n" "${test_list}" +} + +run_test() +{ + for i in "$@"; do + test=$(basename "${i}" ".c") + + printf "%s " "${test}" + if "./${test}" > /dev/null 2>&1; then + printf "\033[1;32mOK\033[m\n" + else + printf "\033[1;31mError\033[m\n" + fi + done 2> /dev/null +} + +clean_test() +{ + for i in "$@"; do + rm -f "$(basename "${i}" ".c")" + done +} + +install() +{ + prefix=$1 + shift 1 + + mkdir -p "${prefix}" + + for i in "$@"; do + dst="${prefix}/${i##*/}" + + if cmp -s "${i}" "${dst}"; then + printf "Up to date %s\n" "${dst}" + else + printf "Installing %s\n" "${dst}" + cp "${i}" "${prefix}" + fi + done +} + +"$@" diff --git a/src/suvm_backend.h b/src/suvm_backend.h @@ -0,0 +1,34 @@ +/* Copyright (C) 2020-2023 |Méso|Star> (contact@meso-star.com) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. */ + +#ifndef SUVM_BACKEND_H +#define SUVM_BACKEND_H + +#include <rsys/rsys.h> /* COMPILER_<CL|GCC> */ + +#ifdef COMPILER_GCC + /* Disable the "ISO C restricts enumerator values to range of 'int'" compiler + * warning in rtcore_common.h, line 293 (RTC_FEATURE_FLAG_ALL = 0xffffffff) */ + #pragma GCC diagnostic push + #pragma GCC diagnostic ignored "-Wpedantic" +#endif + +#include <embree4/rtcore.h> + +#ifdef COMPILER_GCC + #pragma GCC diagnostic pop +#endif + +#endif /* SUVM_BACKEND_H */ diff --git a/src/suvm_c.h b/src/suvm_c.h @@ -16,8 +16,8 @@ #ifndef SUVM_C_H #define SUVM_C_H +#include "suvm_backend.h" #include <rsys/rsys.h> -#include <embree4/rtcore.h> static FINLINE res_T rtc_error_to_res_T(const enum RTCError err) diff --git a/src/suvm_device.h b/src/suvm_device.h @@ -16,8 +16,8 @@ #ifndef SUVM_DEVICE_H #define SUVM_DEVICE_H +#include "suvm_backend.h" #include <rsys/ref_count.h> -#include <embree4/rtcore.h> struct logger; struct mem_allocator; diff --git a/src/suvm_volume.c b/src/suvm_volume.c @@ -291,6 +291,7 @@ build_bvh(struct suvm_volume* vol) struct darray_rtc_prim rtc_prims; struct RTCBuildArguments args; size_t iprim, nprims; + int rtc_prims_is_init = 0; res_T res = RES_OK; ASSERT(vol); @@ -308,6 +309,7 @@ build_bvh(struct suvm_volume* vol) /* Allocate the array of geometric primitives */ darray_rtc_prim_init(vol->dev->allocator, &rtc_prims); + rtc_prims_is_init = 1; res = darray_rtc_prim_resize(&rtc_prims, nprims); if(res != RES_OK) goto error; @@ -383,7 +385,7 @@ build_bvh(struct suvm_volume* vol) } exit: - darray_rtc_prim_release(&rtc_prims); + if(rtc_prims_is_init) darray_rtc_prim_release(&rtc_prims); return res; error: if(vol->bvh) { diff --git a/src/suvm_volume.h b/src/suvm_volume.h @@ -16,13 +16,13 @@ #ifndef SUVM_VOLUME_H #define SUVM_VOLUME_H +#include "suvm_backend.h" + #include <rsys/dynamic_array_u32.h> #include <rsys/dynamic_array_float.h> #include <rsys/float3.h> #include <rsys/ref_count.h> -#include <embree4/rtcore.h> - /* * Tetrahedron geometric layout * diff --git a/src/suvm_voxelize.c b/src/suvm_voxelize.c @@ -72,7 +72,6 @@ print_help(const char* cmd) " -v make the program verobse.\n"); printf("\n"); printf( -"Copyright (C) 2020-2023 |Méso|Star> <contact@meso-star.com>.\n" "This is free software released under the GNU GPL license, version 3 or\n" "later. You are free to change or redistribute it under certain\n" "conditions <http://gnu.org.licenses/gpl.html>\n"); @@ -305,6 +304,7 @@ main(int argc, char** argv) const char* stream_in_name = "stdin"; struct smsh* smsh = NULL; struct smsh_create_args smsh_args = SMSH_CREATE_ARGS_DEFAULT; + struct smsh_load_stream_args load_stream_args = SMSH_LOAD_STREAM_ARGS_NULL; struct smsh_desc desc = SMSH_DESC_NULL; struct suvm_device* suvm = NULL; struct suvm_volume* vol = NULL; @@ -349,7 +349,10 @@ main(int argc, char** argv) smsh_args.verbose = args.verbose; res = smsh_create(&smsh_args, &smsh); if(res != RES_OK) goto error; - res = smsh_load_stream(smsh, stream_in, stream_in_name); + load_stream_args.stream = stream_in; + load_stream_args.name = stream_in_name; + load_stream_args.memory_mapping = stream_in != stdin; + res = smsh_load_stream(smsh, &load_stream_args); if(res != RES_OK) goto error; res = smsh_get_desc(smsh, &desc); if(res != RES_OK) goto error; diff --git a/suvm.pc.in b/suvm.pc.in @@ -0,0 +1,12 @@ +prefix=@PREFIX@ +includedir=${prefix}/include +libdir=${prefix}/lib + +Requires: rsys >= @RSYS_VERSION@ +Requires.private: embree4 >= @EMBREE_VERSION@ +Name: Star-UVM +Description: Star Unstructured Volumetric Mesh +Version: @VERSION@ +Libs: -L${libdir} -lsuvm +Libs.private: -lm +CFlags: -I${includedir}