Lagrange
All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Modules Pages
create_BVH.h
1/*
2 * Copyright 2019 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 <exception>
15#include <memory>
16#include <string>
17
18#include <lagrange/Mesh.h>
19#include <lagrange/bvh/AABBIGL.h>
20#include <lagrange/bvh/BVH.h>
21#include <lagrange/bvh/BVHNanoflann.h>
22#include <lagrange/bvh/BVHType.h>
23
24namespace lagrange {
25namespace bvh {
26
33template <typename VertexArray, typename ElementArray = lagrange::Triangles>
34std::unique_ptr<BVH<VertexArray, ElementArray>> create_BVH( //
35 const BVHType engine_type,
36 const Eigen::MatrixBase<VertexArray>& vertices)
37{
38 switch (engine_type) {
39 case BVHType::NANOFLANN: {
40 using BVH_t = BVHNanoflann<VertexArray, ElementArray>;
41 auto engine = std::make_unique<BVH_t>();
42 engine->build(vertices);
43 return engine;
44 }
45 default: //
46 throw std::runtime_error("Unsupported BVH engine type: " + bvhtype_to_string(engine_type));
47 }
48}
49
56template <typename VertexArray, typename ElementArray>
57std::unique_ptr<BVH<VertexArray, ElementArray>> create_BVH( //
58 const BVHType engine_type,
59 const Eigen::MatrixBase<VertexArray>& vertices,
60 const Eigen::MatrixBase<ElementArray>& elements)
61{
62 switch (engine_type) {
63 case BVHType::NANOFLANN: {
64 using BVH_t = BVHNanoflann<VertexArray, ElementArray>;
65 auto engine = std::make_unique<BVH_t>();
66 engine->build(vertices);
67 return engine;
68 }
69 case BVHType::IGL: {
70 using BVH_t = AABBIGL<VertexArray, ElementArray>;
71 auto engine = std::make_unique<BVH_t>();
72 engine->build(vertices, elements);
73 return engine;
74 }
75 default: //
76 throw std::runtime_error("Unsupported BVH engine: " + bvhtype_to_string(engine_type));
77 }
78
79 // Don't complain dear compiler
80 return nullptr;
81}
82
89template <typename VertexArray, typename ElementArray>
90std::unique_ptr<BVH<VertexArray, ElementArray>> create_BVH( //
91 const BVHType engine_type,
93{
94 switch (engine_type) {
95 case BVHType::NANOFLANN: {
96 using BVH_t = BVHNanoflann<VertexArray, ElementArray>;
97 auto engine = std::make_unique<BVH_t>();
98 engine->build(mesh.get_vertices());
99 return engine;
100 }
101 case BVHType::IGL: {
102 using BVH_t = AABBIGL<VertexArray, ElementArray>;
103 auto engine = std::make_unique<BVH_t>();
104 engine->build(mesh.get_vertices(), mesh.get_facets());
105 return engine;
106 }
107 default: //
108 throw std::runtime_error("Unsupported BVH engine: " + bvhtype_to_string(engine_type));
109 }
110
111 // Don't complain dear compiler
112 return nullptr;
113}
114
115
116} // namespace bvh
117} // namespace lagrange
Definition: Mesh.h:48
Main namespace for Lagrange.
Definition: AABBIGL.h:30