rl_raylib  1.1.10
rl_ReflectionCoefPOD.h
1 #ifndef rl_ReflectionCoefPOD_h_INCLUDED
2 #define rl_ReflectionCoefPOD_h_INCLUDED
3 
4 // File: rl_ReflectionCoefPOD.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_ReflectionCoefPOD
33  *
34  * rl_ReflectionCoeff 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 <cstdio> // FILE*
64 #include <iostream> // <<
65 
66 //########################################################################
67 // rl_ReflectionCoefPOD
68 //########################################################################
69 //
77 {
78 private:
79 
81  rl_Traits::complex para_;
83  rl_Traits::complex perp_;
84 
85 public:
86 
112  double reflectivity( double polarization_factor = 0.0 ) const;
113 
118  void init();
119 
129 
133  rl_Traits::complex para() const;
134 
139 
143  rl_Traits::complex perp() const;
144 
149 
157  std::ostream& print_on( std::ostream& os, char const pre[] = "",
158  char const pst[] = "" ) const;
159 
167  void cprint_on( std::FILE* of, char const pre[] = "",
168  char const pst[] = "" ) const;
169 };
170 
171 inline void rl_ReflectionCoefPOD::
173 {
174  para_ = rl_Traits::complex();
175  perp_ = rl_Traits::complex();
176 }
177 
178 inline void rl_ReflectionCoefPOD::
180  rl_Traits::complex& perp )
181 {
182  para_ = para;
183  perp_ = perp;
184 }
185 
187 para() const
188 { return para_; }
189 
191 perp() const
192 { return perp_; }
193 
196 { return para_; }
197 
200 { return perp_; }
201 
202 inline double rl_ReflectionCoefPOD::
203 reflectivity( double polarization_factor ) const
204 {
205  return ( norm( perp_ ) * (1.0 + polarization_factor )
206  + norm( para_ ) * (1.0 - polarization_factor ) ) / 2.0;
207 }
208 
209 inline std::ostream& rl_ReflectionCoefPOD::
210 print_on( std::ostream& os, char const pre[], char const pst[] ) const
211 {
212  if ( std::strlen(pre) ) { os << pre; }
213  os << "[" << para_ << "][" << perp_ << "]";
214  if ( std::strlen(pst) ) { os << pst; }
215  return os;
216 }
217 
218 inline void rl_ReflectionCoefPOD::
219 cprint_on( std::FILE* of, char const pre[], char const pst[] ) const
220 {
221  if ( std::strlen(pre) ) { std::fprintf(of, "%s", pre); }
222  std::fprintf(of, "[%.15e, %.15e] [%.15e, %.15e]\n",
223  para().real(), para().imag(), perp().real(), perp().imag());
224  if ( std::strlen(pst) ) { std::fprintf(of, "%s", pst); }
225 }
226 
227 inline std::ostream&
228 operator<<( std::ostream& os, rl_ReflectionCoefPOD const& rfl )
229 { rfl.print_on( os ); return os; }
230 
231 // rl_ReflectionCoefPOD_h_INCLUDED
232 #endif
std::complex< double > complex
Typedef for the complex type.
Definition: rl_Traits.h:61
void init()
initialize perpendicular (s) and parallel (p) reflection coefficients to zero.
A Plain Ol' Data class representing complex reflection coefficients.
double reflectivity(double polarization_factor=0.0) const
evaluate the reflectivity.
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
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.