Wayverb
mesh_descriptor.h
1 #pragma once
2 
3 #include "core/cl/representation.h"
4 #include "core/cl/traits.h"
5 #include "core/geo/box.h"
6 
7 #include "glm/glm.hpp"
8 
9 #include <array>
10 
11 namespace wayverb {
12 namespace waveguide {
13 
14 struct alignas(1 << 4) mesh_descriptor final {
15  static constexpr auto no_neighbor = ~cl_uint{0};
16 
17  cl_float3 min_corner;
18  cl_int3 dimensions;
19  cl_float spacing;
20 };
21 
22 constexpr auto to_tuple(const mesh_descriptor& x) {
23  return std::tie(x.min_corner, x.dimensions, x.spacing);
24 }
25 
26 constexpr bool operator==(const mesh_descriptor& a, const mesh_descriptor& b) {
27  return to_tuple(a) == to_tuple(b);
28 }
29 
30 constexpr bool operator!=(const mesh_descriptor& a, const mesh_descriptor& b) {
31  return !(a == b);
32 }
33 
34 size_t compute_index(const mesh_descriptor& d, const glm::ivec3& pos);
35 size_t compute_index(const mesh_descriptor& d, const glm::vec3& pos);
36 
37 glm::ivec3 compute_locator(const mesh_descriptor& d, size_t index);
38 glm::ivec3 compute_locator(const mesh_descriptor& d, const glm::vec3& v);
39 
40 glm::vec3 compute_position(const mesh_descriptor& d, const glm::ivec3& locator);
41 glm::vec3 compute_position(const mesh_descriptor& d, size_t index);
42 
43 void compute_neighbors(const mesh_descriptor& d, size_t index, cl_uint* output);
44 std::array<cl_uint, 6> compute_neighbors(const mesh_descriptor& d,
45  size_t index);
46 
47 core::geo::box compute_aabb(const mesh_descriptor& d);
48 
49 double compute_sample_rate(const mesh_descriptor& d, double speed_of_sound);
50 
51 size_t compute_num_nodes(const mesh_descriptor& d);
52 
53 util::aligned::vector<glm::vec3> compute_node_positions(
54  const mesh_descriptor& d);
55 
56 } // namespace waveguide
57 
58 template <>
59 struct core::cl_representation<waveguide::mesh_descriptor> final {
60  static constexpr auto value = R"(
61 typedef struct {
62  float3 min_corner;
63  int3 dimensions;
64  float spacing;
65 } mesh_descriptor;
66 )";
67 };
68 
69 } // namespace wayverb
Definition: representation.h:7
Definition: range.h:12
Definition: capsule_base.h:9
Definition: mesh_descriptor.h:14