#ifndef RTS_BEAM #define RTS_BEAM #include "../math/vector.h" #include "../math/function.h" #include namespace rts{ template class beam { public: enum beam_type {Uniform, Bartlett, Hamming, Hanning}; private: P na[2]; //numerical aperature of the focusing optics vec

f; //focal point vec

k; //direction vector vec

E0; //polarization direction P omega; //frequency function apod; //apodization function unsigned int apod_res; //resolution of complex apodization filters void apod_uniform() { apod = (P)1; } void apod_bartlett() { apod = (P)1; apod.insert((P)1, (P)0); } void apod_hanning() { apod = (P)0; P x, y; for(unsigned int n=0; n( (P)0.0, (P)0.0, (P)0.0 ); k = vec

( (P)0.0, (P)0.0, (P)1.0 ); E0 = vec

( (P)1.0, (P)0.0, (P)0.0 ); omega = (P)2 * (P)3.14159; apod_res = 256; //set the default resolution for apodization filters set_apod(_apod); //set the apodization function type } ///Numerical Aperature functions void NA(P _na) { na[0] = (P)0; na[1] = _na; } void NA(P _na0, P _na1) { na[0] = _na0; na[1] = _na1; } //Monte-Carlo decomposition into plane waves std::vector< planewave

> mc(unsigned int N, unsigned int seed = 0) { /*Create Monte-Carlo samples of a cassegrain objective by performing uniform sampling of a sphere and projecting these samples onto an inscribed sphere. samples = rtsPointer to sample vectors specified as normalized cartesian coordinates N = number of samples kSph = incident light direction in spherical coordinates NAin = internal obscuration NA NAout = outer cassegrain NA */ srand(seed); //seed the random number generator ///compute the rotation operator to transform (0, 0, 1) to k P cos_angle = k.dot(rts::vec

(0, 0, 1)); rts::matrix rotation; if(cos_angle != 1.0) { rts::vec

r_axis = rts::vec

(0, 0, 1).cross(k).norm(); //compute the axis of rotation P angle = acos(cos_angle); //compute the angle of rotation rts::quaternion

quat; //create a quaternion describing the rotation quat.CreateRotation(angle, r_axis); rotation = quat.toMatrix3(); //compute the rotation matrix } //find the phi values associated with the cassegrain ring P PHI[2]; PHI[0] = (P)asin(na[0]); PHI[1] = (P)asin(na[1]); //calculate the z-axis cylinder coordinates associated with these angles P Z[2]; Z[0] = cos(PHI[0]); Z[1] = cos(PHI[1]); P range = Z[0] - Z[1]; std::vector< planewave

> samples; //create a vector of plane waves planewave

beam_center(k, E0, omega); //create a plane wave representing the beam center //draw a distribution of random phi, z values P z, phi, theta; for(int i=0; i spherical(1, theta, phi); //convert from spherical to cartesian coordinates rts::vec

cart = spherical.sph2cart(); vec

k_prime = rotation * cart; //create a sample vector //store a wave refracted along the given direction samples.push_back(beam_center.refract(k_prime) * apod(phi/PHI[1])); } return samples; } }; } #endif