RayZaler 0.1
The free opto-mechanical simulation framework
EMInterface.h
1//
2// Copyright (c) 2025 Gonzalo José Carracedo Carballal
3//
4// This program is free software: you can redistribute it and/or modify
5// it under the terms of the GNU Lesser General Public License as
6// published by the Free Software Foundation, either version 3 of the
7// License, or (at your option) any later version.
8//
9// This program is distributed in the hope that it will be useful, but
10// WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12// GNU Lesser General Public License for more details.
13//
14// You should have received a copy of the GNU Lesser General Public
15// License along with this program. If not, see
16// <http://www.gnu.org/licenses/>
17//
18
19#ifndef _EM_INTERFACE_H
20#define _EM_INTERFACE_H
21
22#include <string>
23#include "RayBeam.h"
24#include "Random.h"
25
26namespace RZ {
27 class ReferenceFrame;
28
29 //
30 // It is important to remark that the EMInterface works in the reference
31 // frame of the capture surface. We do not need to convert things back
32 // to the absolute reference frames until all transfer took place.
33 //
35 ExprRandomState m_randState;
36 Real m_transmission = 1.;
37 std::vector<Real> const *m_txMap = nullptr;
38 bool m_fullyOpaque = false;
39 bool m_fullyTransparent = true;
40
41 // Only relevant if m_txMap is non-null
42 unsigned int m_cols = 0;
43 unsigned int m_rows = 0;
44 unsigned int m_stride = 0;
45 Real m_hx = 0;
46 Real m_hy = 0;
47
48 protected:
49 static inline void
50 snell(Vec3 &u, Vec3 const &normal, Real muIORatio)
51 {
52 Vec3 nXu = muIORatio * normal.cross(u);
53 u = -normal.cross(nXu) - normal * sqrt(1 - nXu * nXu);
54 }
55
56 static inline Vec3
57 snell(Vec3 const &u, Vec3 const &normal, Real muIORatio)
58 {
59 Vec3 nXu = muIORatio * normal.cross(u);
60
61 return -normal.cross(nXu) - normal * sqrt(1 - nXu * nXu);
62 }
63
64 static inline void
65 reflection(Vec3 &u, Vec3 const &normal)
66 {
67 u -= 2 * (u * normal) * normal;
68 }
69
70 static inline Vec3
71 reflection(Vec3 const &u, Vec3 const &normal)
72 {
73 return u - 2 * (u * normal) * normal;
74 }
75
76 inline ExprRandomState const &
77 constRandState() const
78 {
79 return m_randState;
80 }
81
82 inline ExprRandomState &
83 randState() const
84 {
85 return const_cast<ExprRandomState &>(m_randState);
86 }
87
88 static inline bool
89 mustTransmitRay(const RayBeam *beam, uint64_t i)
90 {
91 return beam->hasRay(i) && beam->isIntercepted(i);
92 }
93
94 void blockLight(RayBeamSlice const &slice);
95
96 public:
97 void setTransmission(Real);
98 void setTransmission(
99 Real width,
100 Real height,
101 std::vector<Real> const &map,
102 unsigned int cols,
103 unsigned int rows,
104 unsigned int stride);
105
106 virtual std::string name() const = 0;
107 virtual void transmit(RayBeamSlice const &beam) = 0;
108 virtual ~EMInterface();
109 };
110}
111
112#endif // _EM_INTERFACE_H
Definition: EMInterface.h:34
Definition: Random.h:28
Definition: RayBeam.h:88
Definition: RayBeam.h:261
Definition: Vector.h:66