Wayverb
scene_data.h
1 #pragma once
2 
3 #include "core/cl/triangle.h"
4 
5 #include "utilities/aligned/vector.h"
6 
7 #include <numeric>
8 
9 namespace wayverb {
10 namespace core {
11 
12 template <typename Vertex, typename Surface>
13 class generic_scene_data final {
14 public:
15  using vertex_type = Vertex;
16  using surface_type = Surface;
17 
18  generic_scene_data() = default;
19  generic_scene_data(util::aligned::vector<triangle> triangles,
20  util::aligned::vector<vertex_type> vertices,
21  util::aligned::vector<surface_type> surfaces)
22  : triangles_{triangles}
23  , vertices_{vertices}
24  , surfaces_{surfaces} {
25  const auto check_surface = [&](auto s) {
26  if (s < 0 || surfaces_.size() <= s) {
27  throw std::runtime_error{"Surface index is out of range."};
28  }
29  };
30  const auto check_vertex = [&](auto v) {
31  if (v < 0 || vertices_.size() <= v) {
32  throw std::runtime_error{"Vertex index is out of range."};
33  }
34  };
35 
36  for (const auto& tri : triangles_) {
37  check_surface(tri.surface);
38  check_vertex(tri.v0);
39  check_vertex(tri.v1);
40  check_vertex(tri.v2);
41  }
42  }
43 
44  const util::aligned::vector<triangle>& get_triangles() const {
45  return triangles_;
46  }
47  const util::aligned::vector<vertex_type>& get_vertices() const {
48  return vertices_;
49  }
50  const util::aligned::vector<surface_type>& get_surfaces() const {
51  return surfaces_;
52  }
53 
54  void swap(generic_scene_data& rhs) noexcept {
55  using std::swap;
56  swap(triangles_, rhs.triangles_);
57  swap(vertices_, rhs.vertices_);
58  swap(surfaces_, rhs.surfaces_);
59  }
60 
63  template <typename It>
64  void set_surfaces(It begin, It end) {
65  generic_scene_data copy{
66  triangles_,
67  vertices_,
68  util::aligned::vector<surface_type>{begin, end}};
69  swap(copy);
70  }
71 
75  std::fill(surfaces_.begin(), surfaces_.end(), surface);
76  }
77 
78 private:
79  util::aligned::vector<triangle> triangles_;
80  util::aligned::vector<vertex_type> vertices_;
81  util::aligned::vector<surface_type> surfaces_;
82 };
83 
84 template <typename Vertex, typename Surface>
85 auto make_scene_data(util::aligned::vector<triangle> triangles,
86  util::aligned::vector<Vertex> vertices,
87  util::aligned::vector<Surface> surfaces) {
89  std::move(triangles), std::move(vertices), std::move(surfaces)};
90 }
91 
92 } // namespace core
93 } // namespace wayverb
Definition: scene_data.h:13
Definition: traits.cpp:2
void set_surfaces(It begin, It end)
Definition: scene_data.h:64
void set_surfaces(const surface_type &surface)
Definition: scene_data.h:74
Definition: capsule_base.h:9