rl_raylib  1.1.10
rl_TransmissionCoefPOD.h
1 #ifndef rl_TransmissionCoefPOD_h_INCLUDED
2 #define rl_TransmissionCoefPOD_h_INCLUDED
3 
4 // File: rl_transmissioncoefpod.h
5 // Author: Terry Gaetz
6 
7 /* --8<--8<--8<--8<--
8  *
9  * Copyright (C) 2006, 2007 Smithsonian Astrophysical Observatory
10  *
11  * This file is part of rl_raylib
12  *
13  * rl_raylib is free software; you can redistribute it and/or
14  * modify it under the terms of the GNU General Public License
15  * as published by the Free Software Foundation; either version 2
16  * of the License, or (at your option) any later version.
17  *
18  * rl_raylib is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21  * GNU General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License
24  * along with this program; if not, write to the
25  * Free Software Foundation, Inc.
26  * 51 Franklin Street, Fifth Floor
27  * Boston, MA 02110-1301, USA
28  *
29  * -->8-->8-->8-->8-- */
30 
31 /****************************************************************************
32  * Description: declare rl_TransmissionCoefPOD
33  *
34  * rl_TransmissionCoeff contains the in-plane and out-of-plane reflection
35  * coefficients;
36  * PolPlus: '+', or parallel (in-plane), reflection coefficient
37  * PolMinus: '-', or perpendicular (out-of-plane), reflection coefficient
38  *
39  * Here, in-plane means the E-vector is in the vector in the plane
40  * of incidence (defined by the ray direction and the surface normal),
41  * while out-of-plane means the E-vector is perpendicular to the
42  * plane of incidence.
43  *
44  * NOTE: a POD class must satisfy (Jack W. Reeves, C++Report, February 1998,
45  * p. 46-54):
46  * - no user-declared constructors, copy-assign operator, or destructor
47  * - no private or protected nonstatic data members
48  * - no base classes
49  * - no virtual functions
50  * - no nonstatic data members of type pointer to member,
51  * non-POD-struct/class (or array of such types) or reference
52  *
53  * History
54  *--------
55  * 1.0.1 2004-Dec-07 tjg simplify/remove include guards
56  * 0.2.0 1998-Jun-24 tjg C++ version
57  * 0.1.0 1998-Jun-23 tjg revised notation; renamed file
58  * 0.0.0 1995-May-18 tjg original version
59  */
60 
61 #include <rl_raylib/rl_Traits.h>
62 #include <cstring> // strlen
63 #include <iostream> // <<
64 
65 //########################################################################
66 // rl_TransmissionCoefPOD
67 //########################################################################
68 //
76 {
77 private:
78 
80  rl_Traits::complex para_;
82  rl_Traits::complex perp_;
83 
84 public:
85 
90  void init();
91 
92 
101 
127  double transmission( double polarization_factor = 0.0 ) const;
128 
132  rl_Traits::complex para() const;
133 
138 
142  rl_Traits::complex perp() const;
143 
148 
156  std::ostream& print_on( std::ostream& os, char const pre[] = "",
157  char const pst[] = "" ) const;
158 
166  void cprint_on( std::FILE* of, char const pre[] = "",
167  char const pst[] = "" ) const;
168 };
169 
170 inline void rl_TransmissionCoefPOD::
172 {
173  para_ = rl_Traits::complex();
174  perp_ = rl_Traits::complex();
175 }
176 
177 inline void rl_TransmissionCoefPOD::
179  rl_Traits::complex& perp )
180 {
181  para_ = para;
182  perp_ = perp;
183 }
184 
186 para() const
187 { return para_; }
188 
190 perp() const
191 { return perp_; }
192 
195 { return para_; }
196 
199 { return perp_; }
200 
201 inline double rl_TransmissionCoefPOD::
202 transmission( double polarization_factor ) const
203 {
204  return ( norm( perp_ ) * (1.0 + polarization_factor )
205  + norm( para_ ) * (1.0 - polarization_factor ) ) / 2.0;
206 }
207 
208 inline std::ostream& rl_TransmissionCoefPOD::
209 print_on( std::ostream& os, char const pre[], char const pst[] ) const
210 {
211  if ( std::strlen(pre) ) { os << pre; }
212  os << "[" << para_ << "][" << perp_ << "]";
213  if ( std::strlen(pst) ) { os << pst; }
214  return os;
215 }
216 
217 inline void rl_TransmissionCoefPOD::
218 cprint_on( std::FILE* of, char const pre[], char const pst[] ) const
219 {
220  if ( std::strlen(pre) ) { std::fprintf(of, "%s", pre); }
221  std::fprintf(of, "[%.15e, %.15e] [%.15e, %.15e]\n",
222  para_.real(), para_.imag(), perp_.real(), perp_.imag());
223  if ( std::strlen(pst) ) { std::fprintf(of, "%s", pst); }
224 }
225 
226 inline std::ostream&
227 operator<<( std::ostream& os, rl_TransmissionCoefPOD const& rfl )
228 { rfl.print_on( os ); return os; }
229 
230 // rl_TransmissionCoefPOD_h_INCLUDED
231 #endif
std::complex< double > complex
Typedef for the complex type.
Definition: rl_Traits.h:61
std::ostream & print_on(std::ostream &os, char const pre[]="", char const pst[]="") const
Print reflectivity information to output stream.
rl_Traits::complex para() const
void init()
Initialize perpendicular (s) and parallel (p) transmission coefficients to zero.
double transmission(double polarization_factor=0.0) const
Transmission factor.
rl_Traits::complex perp() const
void cprint_on(std::FILE *of, char const pre[]="", char const pst[]="") const
Print reflectivity information to output FILE* stream.
A Plain Ol' Data class representing complex reflection coefficients.