Skip to content

Commit

Permalink
Merge pull request #36 from pshriwise/embree4
Browse files Browse the repository at this point in the history
Support Embree4
  • Loading branch information
pshriwise authored Apr 13, 2023
2 parents 74ab1f9 + 7ced70e commit 7864256
Show file tree
Hide file tree
Showing 13 changed files with 71 additions and 32 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ env:
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
embree_version: ['3.6.1', '4.0.1']

steps:
- uses: actions/checkout@v2
Expand All @@ -46,7 +49,7 @@ jobs:

- name: Embree Build
shell: bash
run: $GITHUB_WORKSPACE/ci/embree-install.sh
run: $GITHUB_WORKSPACE/ci/embree-install.sh ${{ matrix.embree_version }}

- name: Configure CMake
# Use a bash shell so we can use the same syntax for environment variable
Expand Down
18 changes: 16 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,19 @@ MESSAGE ( STATUS "MOAB_INCLUDE_DIRS is " ${MOAB_INCLUDE_DIRS} )
INCLUDE_DIRECTORIES( ${MOAB_INCLUDE_DIRS} )

# Embree
FIND_PACKAGE (embree 3.6.1 REQUIRED HINTS ${EMBREE_DIR})
# this series of calls is needed to support the way that Embree indicates
# compatible versions in 3 and 4 (version 4 does it correctly, but 3 does not)
FIND_PACKAGE(embree 3.6.1 HINTS ${EMBREE_DIR} QUIET)
if (NOT ${embree_FOUND})
FIND_PACKAGE (embree REQUIRED HINTS ${EMBREE_DIR})
endif()

if (NOT ${EMBREE_VERSION} VERSION_GREATER 3.6.0)
message(FATAL_ERROR "Double-down requires Embree v3.6.1 or higher.")
endif()

# set embree version

# Set install locations
set( DD_BINARY_INSTALL_LOCATION "${CMAKE_INSTALL_PREFIX}/tools" )
set( DD_INCLUDE_INSTALL_LOCATION "${CMAKE_INSTALL_PREFIX}/include/double_down" )
Expand All @@ -57,11 +64,18 @@ set(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE)
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)

# add library
add_library( dd SHARED "src/RTI.cpp" "src/primitives.cpp" "src/MOABRay.cpp" "src/MOABDirectAccess.cpp")
add_library(dd SHARED "src/RTI.cpp" "src/primitives.cpp" "src/MOABRay.cpp" "src/MOABDirectAccess.cpp")
target_include_directories(dd PRIVATE ${CMAKE_SOURCE_DIR}/include)
set_target_properties(dd PROPERTIES INSTALL_RPATH_USE_LINK_PATH TRUE)
set_target_properties(dd PROPERTIES INSTALL_RPATH ${CMAKE_INSTALL_PREFIX}/lib )

# pass precompile definition depending on embree version
if (${EMBREE_VERSION} VERSION_GREATER_EQUAL 4.0.0)
target_compile_definitions(dd PUBLIC EMBREE4)
else()
target_compile_definitions(dd PUBLIC EMBREE3)
endif()

target_include_directories( dd INTERFACE "${CMAKE_INSTALL_PREFIX}/include" ${EMBREE_INCLUDE_DIRS})
target_link_libraries( dd ${MOAB_LIBRARIES} ${EMBREE_LIBRARY} )
set_target_properties(dd PROPERTIES INSTALL_RPATH "${MOAB_LIBRARY_DIRS};${EMBREE_LIBRARY_DIR}")
Expand Down
4 changes: 2 additions & 2 deletions ci/embree-install.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#!/bin/bash
set -ex

# Embree Variables
EMBREE_TAG='v3.6.1'
# Embree Variables -- use first argument to script as version number
EMBREE_TAG="v${1}"
EMBREE_REPO='https://github.com/embree/embree'
EMBREE_INSTALL_DIR=$HOME/EMBREE/

Expand Down
5 changes: 2 additions & 3 deletions include/double-down/MOABRay.h
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
#ifndef DD_RAY_FUNCS_H
#define DD_RAY_FUNCS_H

// Embree
#include "embree3/rtcore.h"

// MOAB
#include "moab/GeomQueryTool.hpp"

// Double-down
#include "ray.h"

#include "double-down/embree_interface.hpp"

using namespace double_down;

/*! Extension of the single/double precision ray hit to include MOAB handles */
Expand Down
8 changes: 4 additions & 4 deletions include/double-down/RTI.hpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#ifndef DD_RTI_H
#define DD_RTI_H

#include "embree3/rtcore.h"
#include "embree3/rtcore_ray.h"
#include <unordered_map>
#include <memory>

#include "moab/Core.hpp"
#include "moab/GeomQueryTool.hpp"
Expand All @@ -12,8 +12,8 @@
#include "MOABRay.h"
#include "MOABDirectAccess.h"

#include <unordered_map>
#include <memory>
#include "embree_interface.hpp"


namespace double_down {

Expand Down
17 changes: 17 additions & 0 deletions include/double-down/embree3.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@

#include "embree3/rtcore.h"

#ifndef DD_EMBREE_WRAPPERS
#define DD_EMBREE_WRAPPERS

// provide a function signature that matches the one in embree > v4.
// the context is created internally
inline void rtcIntersect1(RTCScene scene, RTCRayHit* rayhit) {
{
RTCIntersectContext context;
rtcInitIntersectContext(&context);
rtcIntersect1(scene, &context, rayhit);
}
}

#endif // include guard
3 changes: 3 additions & 0 deletions include/double-down/embree4.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

#include "embree4/rtcore.h"
#include "embree4/rtcore_ray.h"
14 changes: 14 additions & 0 deletions include/double-down/embree_interface.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@

#ifdef EMBREE4

#include "double-down/embree4.hpp"

#elif defined(EMBREE3)

#include "double-down/embree3.hpp"

#else

#error "No embree version provided to compiler"

#endif
4 changes: 2 additions & 2 deletions include/double-down/primitives.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

#include <array>

// Embree
#include "embree3/rtcore.h"

// MOAB
#include "moab/Core.hpp"
Expand All @@ -15,6 +13,8 @@
#include "ray.h"
#include "MOABDirectAccess.h"

// Embree
#include "double-down/embree_interface.hpp"
namespace double_down {

/*! Structure with triangle information used in Embree */
Expand Down
5 changes: 2 additions & 3 deletions include/double-down/ray.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@
#ifndef DD_RAY_H
#define DD_RAY_H

// Embree
#include "embree3/rtcore_ray.h"

// Double-down
#include "Vec3da.h"

#include "double-down/embree_interface.hpp"

namespace double_down {

enum RayFireType { RF, PIV, ACCUM };
Expand Down
17 changes: 4 additions & 13 deletions src/RTI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
#include "double-down/RTI.hpp"
#include "double-down/constants.h"


namespace double_down {

void error(void* dum, RTCError code, const char* str) {
Expand Down Expand Up @@ -584,9 +583,7 @@ void RayTracingInterface::shutdown() {
void RayTracingInterface::fire(moab::EntityHandle volume, RTCDRayHit &rayhit)
{
{
RTCIntersectContext context;
rtcInitIntersectContext(&context);
rtcIntersect1(scene_map[volume],&context,(RTCRayHit*)&rayhit);
rtcIntersect1(scene_map[volume], (RTCRayHit*)&rayhit);
rayhit.hit.Ng_x = -rayhit.hit.Ng_x;
rayhit.hit.Ng_y = -rayhit.hit.Ng_y;
rayhit.hit.Ng_z = -rayhit.hit.Ng_z;
Expand Down Expand Up @@ -740,9 +737,7 @@ RayTracingInterface::point_in_volume(const moab::EntityHandle volume,

// fire ray
{
RTCIntersectContext context;
rtcInitIntersectContext(&context);
rtcIntersect1(scene,&context,(RTCRayHit*)&mbrayhit);
rtcIntersect1(scene,(RTCRayHit*)&mbrayhit);
// triangle normal conventions are the flipped in Embree compared to MOAB
// TODO: reverse the initial triangle normals so we don't have to do these ops here.
mbhit.Ng_x = -mbhit.Ng_x;
Expand Down Expand Up @@ -890,9 +885,7 @@ RayTracingInterface::ray_fire(const moab::EntityHandle volume,

// fire ray
{
RTCIntersectContext context;
rtcInitIntersectContext(&context);
rtcIntersect1(scene,&context,(RTCRayHit*)&rayhit);
rtcIntersect1(scene, (RTCRayHit*)&rayhit);
mbhit.Ng_x = -mbhit.Ng_x;
mbhit.Ng_y = -mbhit.Ng_y;
mbhit.Ng_z = -mbhit.Ng_z;
Expand All @@ -917,9 +910,7 @@ RayTracingInterface::ray_fire(const moab::EntityHandle volume,

// fire ray in negative direction
if (overlap_thickness > 0.0) {
RTCIntersectContext context;
rtcInitIntersectContext(&context);
rtcIntersect1(scene,&context,(RTCRayHit*)&neg_ray);
rtcIntersect1(scene,(RTCRayHit*)&neg_ray);
neg_hit.Ng_x = -neg_hit.Ng_x;
neg_hit.Ng_y = -neg_hit.Ng_y;
neg_hit.Ng_z = -neg_hit.Ng_z;
Expand Down
2 changes: 1 addition & 1 deletion test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

add_executable(test_mb test_mb.cpp test_utils.cpp)
target_include_directories(test_mb PUBLIC ${MOAB_INCLUDE_DIRS} ${CMAKE_SOURCE_DIR}/include/)
target_link_libraries(test_mb ${MOAB_LIBRARIES})
target_link_libraries(test_mb ${MOAB_LIBRARIES} dd)
set_target_properties(test_mb PROPERTIES BUILD_RPATH "${MOAB_LIBRARY_DIRS}")
set_target_properties(test_mb PROPERTIES BUILD_RPATH_USE_LINK_PATH TRUE)

Expand Down
1 change: 0 additions & 1 deletion tools/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
add_executable(ray_fire ray_fire.cpp)
target_include_directories(ray_fire PUBLIC ${MOAB_INCLUDE_DIRS} ${CMAKE_SOURCE_DIR}/include/)
target_link_libraries(ray_fire ${MOAB_LIBRARIES} ${EMBREE_LIBRARY} dd)
target_link_libraries(ray_fire ${EMBREE_LIBRARY})
install(TARGETS ray_fire DESTINATION ${DD_BINARY_INSTALL_LOCATION})

add_executable(closest_to_location closest_to_location.cpp)
Expand Down

0 comments on commit 7864256

Please sign in to comment.