Lagrange
create_ray_caster.h
1/*
2 * Copyright 2017 Adobe. All rights reserved.
3 * This file is licensed to you under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License. You may obtain a copy
5 * of the License at http://www.apache.org/licenses/LICENSE-2.0
6 *
7 * Unless required by applicable law or agreed to in writing, software distributed under
8 * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9 * OF ANY KIND, either express or implied. See the License for the specific language
10 * governing permissions and limitations under the License.
11 */
12#pragma once
13
14#include <lagrange/Mesh.h>
15#include <lagrange/raycasting/EmbreeRayCaster.h>
16
17#include <sstream>
18
19namespace lagrange {
20namespace raycasting {
21
27};
28
33};
34
35template <typename Scalar>
36std::unique_ptr<EmbreeRayCaster<Scalar>> create_ray_caster(
37 RayCasterType engine,
39{
40 if (engine & 0b1111) {
41 // Translate scene flags for embree ray casters
42 int flags = static_cast<int>(RTC_SCENE_FLAG_NONE);
43 if (engine & EMBREE_DYNAMIC) {
44 flags |= static_cast<int>(RTC_SCENE_FLAG_DYNAMIC);
45 }
46 if (engine & EMBREE_ROBUST) {
47 flags |= static_cast<int>(RTC_SCENE_FLAG_ROBUST);
48 }
49 if (engine & EMBREE_COMPACT) {
50 flags |= static_cast<int>(RTC_SCENE_FLAG_COMPACT);
51 }
52
53 // Translate build quality settings
54 RTCBuildQuality build = RTC_BUILD_QUALITY_LOW;
55 switch (quality) {
56 case BUILD_QUALITY_LOW: build = RTC_BUILD_QUALITY_LOW; break;
57 case BUILD_QUALITY_MEDIUM: build = RTC_BUILD_QUALITY_MEDIUM; break;
58 case BUILD_QUALITY_HIGH: build = RTC_BUILD_QUALITY_HIGH; break;
59 default: break;
60 }
61
62 return std::make_unique<EmbreeRayCaster<Scalar>>(static_cast<RTCSceneFlags>(flags), build);
63 } else {
64 std::stringstream err_msg;
65 err_msg << "Unknown ray caster engine: " << engine;
66 throw std::runtime_error(err_msg.str());
67 }
68}
69} // namespace raycasting
70} // namespace lagrange
RayCasterType
Definition: create_ray_caster.h:22
@ EMBREE_DYNAMIC
Corresponds to RTC_SCENE_FLAG_DYNAMIC.
Definition: create_ray_caster.h:24
@ EMBREE_DEFAULT
Corresponds to RTC_SCENE_FLAG_NONE.
Definition: create_ray_caster.h:23
@ EMBREE_COMPACT
Corresponds to RTC_SCENE_FLAG_COMPACT.
Definition: create_ray_caster.h:26
@ EMBREE_ROBUST
Corresponds to RTC_SCENE_FLAG_ROBUST.
Definition: create_ray_caster.h:25
RayCasterQuality
Definition: create_ray_caster.h:29
@ BUILD_QUALITY_MEDIUM
Corresponds to RTC_BUILD_QUALITY_MEDIUM.
Definition: create_ray_caster.h:31
@ BUILD_QUALITY_HIGH
Corresponds to RTC_BUILD_QUALITY_HIGH.
Definition: create_ray_caster.h:32
@ BUILD_QUALITY_LOW
Corresponds to RTC_BUILD_QUALITY_LOW.
Definition: create_ray_caster.h:30
Main namespace for Lagrange.
Definition: AABBIGL.h:30