star-3d

Surface structuring for efficient 3D geometric queries
git clone git://git.meso-star.fr/star-3d.git
Log | Files | Refs | README | LICENSE

commit a066df19fd96fa4ded0f8096813380abfd665c09
parent f9096b25a9bb7a4ccc71f98d32e692da12b1fa2b
Author: Vincent Forest <vincent.forest@meso-star.com>
Date:   Tue, 10 Mar 2015 11:36:49 +0100

Begin the integration of Embree as the Star-3D back-end

Diffstat:
MREADME.md | 14++++++++------
Mcmake/CMakeLists.txt | 15++++++++++-----
Acmake/EmbreeConfig.cmake | 60++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/s3d_c.h | 54++++++++++++++++++++++++++++++++++++++++++++++++++++++
Msrc/s3d_device.c | 16+++++++++++++++-
Msrc/s3d_scene.c | 3++-
Msrc/s3d_shape.c | 4+++-
7 files changed, 152 insertions(+), 14 deletions(-)

diff --git a/README.md b/README.md @@ -8,14 +8,16 @@ triangular meshes only. The *Star-3D* library uses [CMake](http://www.cmake.org) and the [RCMake](https://gitorious.org/code-plot/rcmake/) package to build. It also -depends on the [RSys](https://gitorious.org/code-plot/rsys/) library. +depends on the [RSys](https://gitorious.org/code-plot/rsys/) and +[Embree](https://embree.github.io/) libraries. First ensure that CMake is installed on your system. Then install the RCMake -package and the RSys library. Finally generate the project from the -`cmake/CMakeLists.txt` file by appending to the `CMAKE_PREFIX_PATH` variable -the `<RCMAKE_INSTALL_DIR>/lib/cmake` and `<RSYS_INSTALL_DIR>` directories, -where `<RCMAKE_INSTALL_DIR>` and `<RSYS_INSTALL_DIR>` are the install -directories of the RCMake package and the RSys library, respectively. The +package as well as the RSys and Embree libraries. Finally generate the project +from the `cmake/CMakeLists.txt` file by appending to the `CMAKE_PREFIX_PATH` +variable the `<RCMAKE_INSTALL_DIR>/lib/cmake`, `<RSYS_INSTALL_DIR>` and +`<EMBREE_INSTALL_DIR>` directories, where `<RCMAKE_INSTALL_DIR>`, +`<RSYS_INSTALL_DIR>` and `<EMBREE_INSTALL_DIR`> are the install directories of +the RCMake package, the RSys and the Embree libraries, respectively. The generated project can be edited, built, tested and installed as any CMake project. diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt @@ -40,11 +40,16 @@ option(NO_TEST "Disable the test" OFF) ################################################################################ # Check dependencies ################################################################################ +get_filename_component(_current_source_dir ${CMAKE_CURRENT_LIST_FILE} PATH) +set(Embree_DIR ${_current_source_dir}/) + +find_package(Embree REQUIRED) find_package(RCMake 0.1 REQUIRED) -find_package(RSys 0.1 REQUIRED) -set(CMAKE_MODULE_PATH ${RCMAKE_SOURCE_DIR}) +find_package(RSys 0.1.1 REQUIRED) +set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${RCMAKE_SOURCE_DIR}) include(rcmake) -include_directories(${RSys_INCLUDE_DIR}) + +include_directories(${Embree_INCLUDE_DIR} ${RSys_INCLUDE_DIR}) ################################################################################ # Configure and define targets @@ -60,15 +65,15 @@ set(S3D_FILES_INC s3d.h) # Prepend each file in the `S3D_FILES_<SRC|INC>' list by `S3D_SOURCE_DIR' rcmake_prepend_path(S3D_FILES_SRC ${S3D_SOURCE_DIR}) rcmake_prepend_path(S3D_FILES_INC ${S3D_SOURCE_DIR}) +set_source_files_properties(${S3D_FILES_SRC} PROPERTIES LANGUAGE CXX) add_library(s3d SHARED ${S3D_FILES_SRC} ${S3D_FILES_INC}) -target_link_libraries(s3d m) +target_link_libraries(s3d Embree) set_target_properties(s3d PROPERTIES DEFINE_SYMBOL S3D_SHARED_BUILD LINKER_LANGUAGE CXX VERSION ${VERSION} SOVERSION ${VERSION_MAJOR}) - rcmake_setup_devel(s3d s3d ${VERSION} se/s3d_version.h) ################################################################################ diff --git a/cmake/EmbreeConfig.cmake b/cmake/EmbreeConfig.cmake @@ -0,0 +1,60 @@ +# Copyright (C) |Meso|Star> 2015 (contact@meso-star.com) +# +# This software is a computer program whose purpose is to generate files used +# to build the Star-3D library. +# +# This software is governed by the CeCILL license under French law and +# abiding by the rules of distribution of free software. You can use, +# modify and/or redistribute the software under the terms of the CeCILL +# license as circulated by CEA, CNRS and INRIA at the following URL +# "http://www.cecill.info". +# +# As a counterpart to the access to the source code and rights to copy, +# modify and redistribute granted by the license, users are provided only +# with a limited warranty and the software's author, the holder of the +# economic rights, and the successive licensors have only limited +# liability. +# +# In this respect, the user's attention is drawn to the risks associated +# with loading, using, modifying and/or developing or reproducing the +# software by the user in light of its specific status of free software, +# that may mean that it is complicated to manipulate, and that also +# therefore means that it is reserved for developers and experienced +# professionals having in-depth computer knowledge. Users are therefore +# encouraged to load and test the software's suitability as regards their +# requirements in conditions enabling the security of their systems and/or +# data to be ensured and, more generally, to use and operate it in the +# same conditions as regards security. +# +# The fact that you are presently reading this means that you have had +# knowledge of the CeCILL license and that you accept its terms. + +cmake_minimum_required(VERSION 2.6) + +# Try to find the RSys devel. Once done this will define: +# - Embree_FOUND: system has RSys +# - Embree_INCLUDE_DIR: the include directory +# - Embree: Link this to use rsys + +find_path(Embree_INCLUDE_DIR embree2/rtcore.h) +unset(Embree_LIBRARY CACHE) +unset(Embree_LIBRARY_DEBUG CACHE) +unset(Embree_LIBRARY_RELWITHDEBINFO CACHE) +unset(Embree_LIBRARY_MINSIZEREL CACHE) +find_library(Embree_LIBRARY embree DOC "Path to the library embree.") + +# Create the imported library target +if(CMAKE_HOST_WIN32) + set(_property IMPORTED_IMPLIB) +else(CMAKE_HOST_WIN32) + set(_property IMPORTED_LOCATION) +endif(CMAKE_HOST_WIN32) +add_library(Embree SHARED IMPORTED) +set_target_properties(Embree PROPERTIES ${_property} ${Embree_LIBRARY}) + +# Check the package +include(FindPackageHandleStandardArgs) +FIND_PACKAGE_HANDLE_STANDARD_ARGS(Embree DEFAULT_MSG + Embree_INCLUDE_DIR + Embree_LIBRARY) + diff --git a/src/s3d_c.h b/src/s3d_c.h @@ -0,0 +1,54 @@ +/* Copyright (C) |Meso|Star> 2015 (contact@meso-star.com) + * + * This software is a computer program whose purpose is to describe a + * virtual 3D environment that can be ray-traced and sampled both robustly + * and efficiently. + * + * This software is governed by the CeCILL license under French law and + * abiding by the rules of distribution of free software. You can use, + * modify and/or redistribute the software under the terms of the CeCILL + * license as circulated by CEA, CNRS and INRIA at the following URL + * "http://www.cecill.info". + * + * As a counterpart to the access to the source code and rights to copy, + * modify and redistribute granted by the license, users are provided only + * with a limited warranty and the software's author, the holder of the + * economic rights, and the successive licensors have only limited + * liability. + * + * In this respect, the user's attention is drawn to the risks associated + * with loading, using, modifying and/or developing or reproducing the + * software by the user in light of its specific status of free software, + * that may mean that it is complicated to manipulate, and that also + * therefore means that it is reserved for developers and experienced + * professionals having in-depth computer knowledge. Users are therefore + * encouraged to load and test the software's suitability as regards their + * requirements in conditions enabling the security of their systems and/or + * data to be ensured and, more generally, to use and operate it in the + * same conditions as regards security. + * + * The fact that you are presently reading this means that you have had + * knowledge of the CeCILL license and that you accept its terms. */ + +#ifndef S3D_C_H +#define S3D_C_H + +#include <embree2/rtcore.h> +#include <rsys/rsys.h> + +static FINLINE res_T +rtc_error_to_res_T(const enum RTCError err) +{ + switch(err) { + case RTC_NO_ERROR: return RES_OK; + case RTC_UNSUPPORTED_ERROR: return RES_UNKNOWN_ERR; + case RTC_INVALID_ARGUMENT: return RES_BAD_ARG; + case RTC_INVALID_OPERATION: return RES_BAD_ARG; + case RTC_OUT_OF_MEMORY: return RES_MEM_ERR; + case RTC_UNSUPPORTED_CPU: return RES_BAD_ARG; + default: FATAL("Unreachable code\n"); break; + } +} + +#endif /* S3D_C_H */ + diff --git a/src/s3d_device.c b/src/s3d_device.c @@ -33,9 +33,14 @@ #include "s3d.h" #include "s3d_device_c.h" +#include <embree2/rtcore.h> #include <rsys/logger.h> #include <rsys/mem_allocator.h> +/* Only one instance of embree can be launched. This global variable register + * whether an Embree instance is running or not */ +static int g_EmbreeIsInitialized = 0; + /******************************************************************************* * Helper functions ******************************************************************************/ @@ -46,6 +51,8 @@ device_release(ref_T* ref) ASSERT(ref); dev = CONTAINER_OF(ref, struct s3d_device, ref); MEM_FREE(dev->allocator, dev); + rtcExit(); + ATOMIC_SET(&g_EmbreeIsInitialized, 0); } /******************************************************************************* @@ -59,15 +66,20 @@ s3d_device_create { struct s3d_device* dev = NULL; struct mem_allocator* allocator; + enum RTCError err; res_T res = RES_OK; if(!out_dev) { res = RES_BAD_ARG; goto error; } + if(ATOMIC_GET(&g_EmbreeIsInitialized)) { + res = RES_BAD_ARG; + goto error; + } allocator = mem_allocator ? mem_allocator : &mem_default_allocator; - dev = MEM_CALLOC(allocator, 1, sizeof(struct s3d_device)); + dev = (struct s3d_device*)MEM_CALLOC(allocator, 1, sizeof(struct s3d_device)); if(!dev) { res = RES_MEM_ERR; goto error; @@ -75,6 +87,8 @@ s3d_device_create dev->logger = logger ? logger : LOGGER_DEFAULT; dev->allocator = allocator; ref_init(&dev->ref); + rtcInit(); + ATOMIC_SET(&g_EmbreeIsInitialized, 1); exit: if(out_dev) *out_dev = dev; diff --git a/src/s3d_scene.c b/src/s3d_scene.c @@ -71,7 +71,8 @@ s3d_scene_create(struct s3d_device* dev, struct s3d_scene** out_scn) res = RES_BAD_ARG; goto error; } - scn = MEM_CALLOC(dev->allocator, 1, sizeof(struct s3d_scene)); + scn = (struct s3d_scene*)MEM_CALLOC + (dev->allocator, 1, sizeof(struct s3d_scene)); if(!scn) { res = RES_MEM_ERR; goto error; diff --git a/src/s3d_shape.c b/src/s3d_shape.c @@ -66,7 +66,8 @@ s3d_shape_create(struct s3d_device* dev, struct s3d_shape** out_shape) res = RES_BAD_ARG; goto error; } - shape = MEM_CALLOC(dev->allocator, 1, sizeof(struct s3d_shape)); + shape = (struct s3d_shape*)MEM_CALLOC + (dev->allocator, 1, sizeof(struct s3d_shape)); if(!shape) { res = RES_MEM_ERR; goto error; @@ -114,3 +115,4 @@ s3d_shape_detach(struct s3d_shape* shape) S3D(shape_ref_put(shape)); return RES_OK; } +