Lagrange
Loading...
Searching...
No Matches
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/legacy/inline.h>
16#include <lagrange/raycasting/EmbreeRayCaster.h>
17
18#include <sstream>
19
20namespace lagrange {
21namespace raycasting {
22LAGRANGE_LEGACY_INLINE
23namespace legacy {
24
25enum RayCasterType {
26 EMBREE_DEFAULT = 1,
27 EMBREE_DYNAMIC = 2,
28 EMBREE_ROBUST = 4,
29 EMBREE_COMPACT = 8,
30};
31
32enum RayCasterQuality {
33 BUILD_QUALITY_LOW,
34 BUILD_QUALITY_MEDIUM,
35 BUILD_QUALITY_HIGH,
36};
37
38template <typename Scalar>
39std::unique_ptr<EmbreeRayCaster<Scalar>> create_ray_caster(
40 RayCasterType engine,
41 RayCasterQuality quality = BUILD_QUALITY_LOW)
42{
43 if (engine & 0b1111) {
44 // Translate scene flags for embree ray casters
45 int flags = static_cast<int>(RTC_SCENE_FLAG_NONE);
46 if (engine & EMBREE_DYNAMIC) {
47 flags |= static_cast<int>(RTC_SCENE_FLAG_DYNAMIC);
48 }
49 if (engine & EMBREE_ROBUST) {
50 flags |= static_cast<int>(RTC_SCENE_FLAG_ROBUST);
51 }
52 if (engine & EMBREE_COMPACT) {
53 flags |= static_cast<int>(RTC_SCENE_FLAG_COMPACT);
54 }
55
56 // Translate build quality settings
57 RTCBuildQuality build = RTC_BUILD_QUALITY_LOW;
58 switch (quality) {
59 case BUILD_QUALITY_LOW: build = RTC_BUILD_QUALITY_LOW; break;
60 case BUILD_QUALITY_MEDIUM: build = RTC_BUILD_QUALITY_MEDIUM; break;
61 case BUILD_QUALITY_HIGH: build = RTC_BUILD_QUALITY_HIGH; break;
62 default: break;
63 }
64
65 return std::make_unique<EmbreeRayCaster<Scalar>>(static_cast<RTCSceneFlags>(flags), build);
66 } else {
67 std::stringstream err_msg;
68 err_msg << "Unknown ray caster engine: " << engine;
69 throw std::runtime_error(err_msg.str());
70 }
71}
72} // namespace legacy
73} // namespace raycasting
74} // namespace lagrange
Raycasting operations.
Definition ClosestPointResult.h:22
Main namespace for Lagrange.