rl_ReflectionCoefPOD.h

00001 #ifndef rl_ReflectionCoefPOD_h_INCLUDED
00002 #define rl_ReflectionCoefPOD_h_INCLUDED
00003 
00004 // File:   rl_ReflectionCoefPOD.h
00005 // Author: Terry Gaetz
00006 
00007 /* --8<--8<--8<--8<--
00008  *
00009  * Copyright (C) 2006, 2007 Smithsonian Astrophysical Observatory
00010  *
00011  * This file is part of rl_raylib
00012  *
00013  * rl_raylib is free software; you can redistribute it and/or
00014  * modify it under the terms of the GNU General Public License
00015  * as published by the Free Software Foundation; either version 2
00016  * of the License, or (at your option) any later version.
00017  *
00018  * rl_raylib is distributed in the hope that it will be useful,
00019  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00020  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00021  * GNU General Public License for more details.
00022  *
00023  * You should have received a copy of the GNU General Public License
00024  * along with this program; if not, write to the 
00025  *       Free Software Foundation, Inc. 
00026  *       51 Franklin Street, Fifth Floor
00027  *       Boston, MA  02110-1301, USA
00028  *
00029  * -->8-->8-->8-->8-- */
00030 
00031 /****************************************************************************
00032  * Description: declare rl_ReflectionCoefPOD
00033  *
00034  * rl_ReflectionCoeff contains the in-plane and out-of-plane reflection
00035  * coefficients;
00036  *   PolPlus:    '+', or parallel      (in-plane),     reflection coefficient
00037  *   PolMinus:   '-', or perpendicular (out-of-plane), reflection coefficient
00038  *
00039  * Here, in-plane means the E-vector is in the vector in the plane 
00040  * of incidence (defined by the ray direction and the surface normal),
00041  * while out-of-plane means the E-vector is perpendicular to the 
00042  * plane of incidence.
00043  *
00044  *  NOTE:  a POD class must satisfy (Jack W. Reeves, C++Report, February 1998,
00045  *         p. 46-54):
00046  *   - no user-declared constructors, copy-assign operator, or destructor
00047  *   - no private or protected nonstatic data members
00048  *   - no base classes
00049  *   - no virtual functions
00050  *   - no nonstatic data members of type pointer to member,
00051  *        non-POD-struct/class (or array of such types) or reference
00052  *
00053  * History
00054  *--------
00055  * 1.0.1 2004-Dec-07  tjg  simplify/remove include guards
00056  * 0.2.0 1998-Jun-24  tjg  C++ version
00057  * 0.1.0 1998-Jun-23  tjg  revised notation; renamed file
00058  * 0.0.0 1995-May-18  tjg  original version
00059  */
00060 
00061 #include <rl_raylib/rl_Traits.h>
00062 #include <cstring>                   // strlen
00063 #include <cstdio>                    // FILE*
00064 #include <iostream>                  // <<
00065 
00066 //########################################################################
00067 // rl_ReflectionCoefPOD
00068 //########################################################################
00069 //
00076 class rl_ReflectionCoefPOD
00077 {
00078 private:
00079 
00081   rl_Traits::complex para_;  
00083   rl_Traits::complex perp_;  
00084 
00085 public:
00086 
00112   double reflectivity( double polarization_factor = 0.0 ) const;
00113 
00118   void init();
00119 
00127   void init( rl_Traits::complex& para,
00128              rl_Traits::complex& perp );
00129 
00133   rl_Traits::complex para() const;
00134 
00138   rl_Traits::complex& para();
00139 
00143   rl_Traits::complex perp() const;
00144 
00148   rl_Traits::complex& perp();
00149 
00157   std::ostream& print_on( std::ostream& os, char const pre[] = "",
00158                                             char const pst[] = "" ) const;
00159 
00167   void cprint_on( std::FILE* of, char const pre[] = "",
00168                                  char const pst[] = "" ) const;
00169 };
00170 
00171 inline void rl_ReflectionCoefPOD::
00172 init()
00173 {
00174   para_ = rl_Traits::complex();
00175   perp_ = rl_Traits::complex();
00176 }
00177 
00178 inline void rl_ReflectionCoefPOD::
00179 init( rl_Traits::complex& para,
00180       rl_Traits::complex& perp )
00181 {
00182   para_ = para;
00183   perp_ = perp;
00184 }
00185 
00186 inline rl_Traits::complex rl_ReflectionCoefPOD::
00187 para() const
00188 { return para_; }
00189 
00190 inline rl_Traits::complex rl_ReflectionCoefPOD::
00191 perp() const
00192 { return perp_; }
00193 
00194 inline rl_Traits::complex& rl_ReflectionCoefPOD::
00195 para()
00196 { return para_; }
00197 
00198 inline rl_Traits::complex& rl_ReflectionCoefPOD::
00199 perp()
00200 { return perp_; }
00201 
00202 inline double rl_ReflectionCoefPOD::
00203 reflectivity( double polarization_factor ) const
00204 {
00205   return ( norm( perp_ ) * (1.0 + polarization_factor ) 
00206          + norm( para_ ) * (1.0 - polarization_factor ) ) / 2.0;
00207 }
00208 
00209 inline std::ostream& rl_ReflectionCoefPOD::
00210 print_on( std::ostream& os, char const pre[], char const pst[] ) const
00211 {
00212   if ( std::strlen(pre) ) { os << pre; }
00213   os << "[" << para_ << "][" << perp_ << "]";
00214   if ( std::strlen(pst) ) { os << pst; }
00215   return os;
00216 }
00217 
00218 inline void rl_ReflectionCoefPOD::
00219 cprint_on( std::FILE* of, char const pre[], char const pst[] ) const
00220 {
00221   if ( std::strlen(pre) ) { std::fprintf(of, "%s", pre); }
00222   std::fprintf(of, "[%.15e, %.15e] [%.15e, %.15e]\n",
00223      para().real(), para().imag(), perp().real(), perp().imag());
00224   if ( std::strlen(pst) ) { std::fprintf(of, "%s", pst); }
00225 }
00226 
00227 inline std::ostream&
00228 operator<<( std::ostream& os, rl_ReflectionCoefPOD const& rfl )
00229 { rfl.print_on( os ); return os; }
00230 
00231 // rl_ReflectionCoefPOD_h_INCLUDED
00232 #endif

Generated on Mon Nov 3 18:15:05 2008 for rl_raylib by  doxygen 1.5.6