SAL
A C++ library for spatial audio.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
cuboidroom.h
Go to the documentation of this file.
1 /*
2  Spatial Audio Library (SAL)
3  Copyright (c) 2013-2018, Enzo De Sena
4  All rights reserved.
5 
6  Authors: Enzo De Sena, enzodesena@gmail.com
7  */
8 
9 #ifndef SAL_CUBOIDROOM_H
10 #define SAL_CUBOIDROOM_H
11 
12 
13 #include <vector>
14 #include "point.h"
15 #include "iirfilter.h"
16 #include "room.h"
17 #include "comparisonop.h"
18 #include "salutilities.h"
19 
20 namespace sal {
21 
23  kX1,
24  kX2,
25  kY1,
26  kY2,
27  kZ1,
29 };
30 
31 class CuboidRoom : public Room {
32 public:
33  // The room filter is *not* an injected dependency. The software will do lots
34  // of copies of the object.
36  const std::vector<mcl::IirFilter>& filter_prototypes) :
37  Room(filter_prototypes),
38  dimensions_(Triplet(x, y, z)), origin_position_(Triplet(0,0,0)) {
39  if ((Int)filter_prototypes.size() != num_faces()) { ASSERT(false); }
40  }
41 
43  const mcl::IirFilter& filter_prototype) :
44  Room(std::vector<mcl::IirFilter>(6, filter_prototype)),
45  dimensions_(Triplet(x, y, z)), origin_position_(Triplet(0,0,0)) {}
46 
54  CuboidRoom(const Triplet& room_dimensions, const Triplet& origin_position,
55  const mcl::IirFilter& filter_prototype) :
56  Room(std::vector<mcl::IirFilter>(6, filter_prototype)),
57  dimensions_(room_dimensions), origin_position_(origin_position) {}
58 
59  virtual std::vector<mcl::Point>
60  CalculateBoundaryPoints(const mcl::Point& source,
61  const mcl::Point& destination) const noexcept;
62 
63  virtual std::vector<mcl::IirFilter>
64  GetBoundaryFilters(const mcl::Point& source_point,
65  const mcl::Point& mic_point) const noexcept;
66 
67  virtual mcl::Int num_boundary_points() const noexcept;
68 
69  mcl::Point ImageSourcePosition(const mcl::Point& source_position,
70  const mcl::Int mx,
71  const mcl::Int my,
72  const mcl::Int mz,
73  const mcl::Int px,
74  const mcl::Int py,
75  const mcl::Int pz) const noexcept;
76 
77  sal::Time SabineRt60() const;
78 
79  Triplet dimensions() const noexcept { return dimensions_; }
80 
81  void SetDimensions(const Triplet& dimensions) noexcept {
82  dimensions_ = dimensions;
83  }
84 
85  void SetOriginPosition(const Triplet& position) {
86  origin_position_ = position;
87  }
88 
89  virtual sal::Int num_faces() const noexcept { return 6; }
90 
91  virtual sal::Length max_distance() const noexcept {
92  return dimensions_.norm();
93  }
94 
95  static bool Test();
96 
97  virtual bool
98  IsPointInRoom(const mcl::Point& point,
99  const sal::Length precision = VERY_SMALL) const noexcept;
100 
101  virtual std::string ShapeDescription() const noexcept;
102 
103  virtual ~CuboidRoom() {}
104 private:
105 
106  // Reference system:
107  //
108  // ^ z
109  // |
110  // ---------------
111  // |\ |\
112  // | \ 0 | \
113  // | \ | \ y
114  // ---2\-----------3-\---->
115  // \ ---------------
116  // \ | \ |
117  // \ | 1 \ |
118  // \| \|
119  // ---------------
120  // \
121  // \ x
122  //
123  // 4: floor
124  // 5: ceiling
125  mcl::Point ReflectionPoint(const CuboidWallId face_index,
126  const mcl::Point& source_pos,
127  const mcl::Point& observation_pos) const;
128 
129  // Dimensions of the cuboid
130  Triplet dimensions_;
131 
132  Triplet origin_position_;
133 
134  static mcl::Point IntersectionPoint(const CuboidWallId wall_id,
135  const Triplet dimensions,
136  const mcl::Point& observation_pos,
137  const mcl::Point& image_pos) noexcept;
138 };
139 
140 } // namespace sal
141 
142 #endif