rl_raylib  1.1.10
rl_Polarization.h
1 #ifndef rl_Polarization_h_INCLUDED
2 #define rl_Polarization_h_INCLUDED
3 
4 // File: rl_Polarization.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 #include <dvm3/dvm3.h> // dvm3_Vector dvm3_RotMat
32 #include <rl_raylib/rl_Traits.h> // rl_Traits::complex
33 
34 class rl_ReflectionCoefPOD; // forward declaration
35 
36 #include <cstdio>
37 
38 //########################################################################
39 //
40 // rl_PolCSPOD
41 //
42 // A class to encapuslate OSAC-style polarization amplitudes.
43 //
44 // Relation to OSAC polarization amplitudes:
45 //
46 // c2_.q1 <--> c2comp(1), c2_.q2 <--> c2comp(2),
47 // s2_.q1 <--> s2comp(1), s2_.q2 <--> s2comp(2)
48 //
49 // random polarization:
50 // wt = c2_.q1.r^2 + c2_.q2.r^2 + c2_.q1.i^2 + c2_.q2.i^2
51 // + s2_.q1.r^2 + s2_.q2.r^2 + s2_.q1.i^2 + s2_.q2.i^2
52 //
53 // wt = |c2[0]|^2 + |s2[0]|^2 + |c2[1]|^2 + |s2[1]|^2
54 //
55 // discrete polarization:
56 // wt = c2_.q1.r^2 + c2_.q2.r^2 + c2_.q1.i^2 + c2_.q2.i^2
57 // + s2_.q1.r^2 + s2_.q2.r^2 + s2_.q1.i^2 + s2_.q2.i^2
58 // * 2.0 * (c2_.q1.i s2_.q1.r + c2_.q2.i s2_.q2.r
59 // - c2_.q1.r s2_.q1.i - c2_.q2.r s2_.q2.i)
60 //
61 // wt = |c2[0]|^2 + |s2[0]|^2 + |c2[1]|^2 + |s2[1]|^2
62 // + 2 ( c2[0] s2[0]^* + c2[1] s2[1]^* )
63 //
64 //########################################################################
65 
107 {
112 
120  void init( double b_over_a = 1.0,
121  double psi = 0.0
122  );
123 
130  void attenuate( double factor );
131 
137  double intensity() const;
138 
145  std::ostream& print_on( std::ostream& os ) const;
146 
153  void cprint_on( FILE* of ) const;
154 };
155 
163 inline std::ostream&
164 operator<<( std::ostream& os, rl_PolCSPOD const& polcs )
165  // The state is written as "[(r,i)(r,i)][(r,i)(r,i)]".
166 {
167  return polcs.print_on( os );
168 }
169 
170 //########################################################################
171 // rl_Polarization
172 //########################################################################
173 //
187 {
188 public:
189 
192 
193 private:
194 
196  dvm3_Vector C_r_;
198  dvm3_Vector C_i_;
200  dvm3_Vector S_r_;
202  dvm3_Vector S_i_;
203 
205  rl_Polarization& operator=( rl_Polarization const& );
206 
207 public:
208 
213 
217  rl_Polarization();
218 
224  rl_Polarization( rl_Polarization const& rhs );
225 
233  rl_Polarization( rl_PolCSPOD const& cs, dvm3_Vector const& dir );
234 
241  void init( rl_PolCSPOD const& cs, dvm3_Vector const& dir );
242 
249  void get_PolCSPOD( rl_PolCSPOD& cs, dvm3_Vector const& dir ) const;
250 
256  double intensity() const;
257 
265  void rotate( rl_Polarization& rotated, dvm3_RotMat const& rot_mtx );
266 
274  void derotate( rl_Polarization& derotated, dvm3_RotMat const& rot_mtx );
275 
281  void attenuate( double factor );
282 
294  void reflect(
295  dvm3_Vector const& normal,
296  dvm3_Vector const& dir_in,
297  dvm3_Vector const& dir_out,
298  rl_ReflectionCoefPOD const& rflcoef
299  );
300 
302  dvm3_Vector const& C_r() const;
304  dvm3_Vector const& C_i() const;
306  dvm3_Vector const& S_r() const;
308  dvm3_Vector const& S_i() const;
309 
316  std::ostream& print_on( std::ostream& os ) const;
317 
324  void cprint_on( std::FILE* of ) const;
325 };
326 
327 //########################################################################
328 //########################################################################
329 //
330 // # # # # # # # ###### ####
331 // # ## # # # ## # # #
332 // # # # # # # # # # ##### ####
333 // # # # # # # # # # # #
334 // # # ## # # # ## # # #
335 // # # # ###### # # # ###### ####
336 //
337 //########################################################################
338 //########################################################################
339 
340 //-------------------------------------------------------------------------
341 inline
344 {}
345 
346 //-------------------------------------------------------------------------
347 inline
350 {}
351 
352 //-------------------------------------------------------------------------
353 inline rl_Polarization::
354 rl_Polarization( rl_PolCSPOD const& cs, dvm3_Vector const& dir )
355 { init( cs, dir ); }
356 
357 //-------------------------------------------------------------------------
358 inline rl_Polarization::
360  : C_r_( rhs.C_r_ ),
361  C_i_( rhs.C_i_ ),
362  S_r_( rhs.S_r_ ),
363  S_i_( rhs.S_i_ )
364 {}
365 
366 //-------------------------------------------------------------------------
367 inline void rl_Polarization::
368 rotate( rl_Polarization& rotated, dvm3_RotMat const& rot_mtx )
369 {
370  rot_mtx.mvmult( rotated.C_r_, C_r_ );
371  rot_mtx.mvmult( rotated.C_i_, C_i_ );
372  rot_mtx.mvmult( rotated.S_r_, S_r_ );
373  rot_mtx.mvmult( rotated.S_i_, S_i_ );
374 }
375 
376 //-------------------------------------------------------------------------
377 inline void rl_Polarization::
378 derotate( rl_Polarization& derotated, dvm3_RotMat const& rot_mtx )
379 {
380  rot_mtx.mtvmult( derotated.C_r_, C_r_ );
381  rot_mtx.mtvmult( derotated.C_i_, C_i_ );
382  rot_mtx.mtvmult( derotated.S_r_, S_r_ );
383  rot_mtx.mtvmult( derotated.S_i_, S_i_ );
384 }
385 
386 //-------------------------------------------------------------------------
387 inline dvm3_Vector const& rl_Polarization::
388 C_r() const
389 {
390  return C_r_;
391 }
392 
393 //-------------------------------------------------------------------------
394 inline dvm3_Vector const& rl_Polarization::
395 C_i() const
396 {
397  return C_i_;
398 }
399 
400 //-------------------------------------------------------------------------
401 inline dvm3_Vector const& rl_Polarization::
402 S_r() const
403 {
404  return S_r_;
405 }
406 
407 //-------------------------------------------------------------------------
408 inline dvm3_Vector const& rl_Polarization::
409 S_i() const
410 {
411  return S_i_;
412 }
413 
414 //-------------------------------------------------------------------------
422 inline std::ostream&
423 operator<<( std::ostream& os, rl_Polarization const& polvec )
424 {
425  return polvec.print_on( os );
426 }
427 
428 // rl_Polarization_h_INCLUDED
429 #endif
dvm3_Vector const & S_r() const
return the real `‘sine’ polarization vector
std::complex< double > complex
Typedef for the complex type.
Definition: rl_Traits.h:61
void cprint_on(std::FILE *of) const
Write the polarization amplitude to FILE* of.
rl_Traits::complex c2_[2]
polarization amplitude (cosine component)
void derotate(rl_Polarization &derotated, dvm3_RotMat const &rot_mtx)
Rotate polarization state back from frame described by rot_mtx.
void init(double b_over_a=1.0, double psi=0.0)
Initialization method.
void cprint_on(FILE *of) const
Write the polarization amplitude to FILE* of.
double intensity() const
Evaluate the intensity.
void rotate(rl_Polarization &rotated, dvm3_RotMat const &rot_mtx)
Rotate polarization state to frame described by rot_mtx.
std::ostream & print_on(std::ostream &os) const
Write the polarization vectors to stream os.
std::ostream & print_on(std::ostream &os) const
Write the polarization amplitude to stream os.
rl_Traits::complex s2_[2]
polarization amplitude (sine component)
A Plain Ol' Data class representing complex reflection coefficients.
A Plain Ol' Data struct (POD) encapsulating the OSAC-style complex polarization amplitudes.
void attenuate(double factor)
Attenuate intensity by a factor.
dvm3_Vector const & C_i() const
return the imaginary `‘cosine’ polarization vector
void attenuate(double factor)
Attenuate reflectivity by a factor.
void init(rl_PolCSPOD const &cs, dvm3_Vector const &dir)
Initialize the polarization state.
void get_PolCSPOD(rl_PolCSPOD &cs, dvm3_Vector const &dir) const
Evaluate rl_PolCSPOD corresponding to this polarization state.
Encapsulates the polarization state of a ray.
~rl_Polarization()
Destructor (NON-VIRTUAL)
dvm3_Vector const & S_i() const
return the imaginary `‘sine’ polarization vector
dvm3_Vector const & C_r() const
return the real `‘cosine’ polarization vector
double intensity() const
Evaluate intensity.
void reflect(dvm3_Vector const &normal, dvm3_Vector const &dir_in, dvm3_Vector const &dir_out, rl_ReflectionCoefPOD const &rflcoef)
Evaluate the reflected polarization vectors.
rl_Polarization()
Default constructor; constructs rl_Polarization with INVALID fields.
rl_Traits::complex complex
complex type