APSF.h

00001 
00002 // File : APSF.h
00004 //
00005 // Copyright 2006
00006 // The University of North Carolina at Chapel Hill
00007 // 
00009 //
00010 // Permission to use, copy, modify, distribute and sell this software and its 
00011 // documentation for any purpose is hereby granted without fee, provided that 
00012 // the above copyright notice appear in all copies and that both that copyright 
00013 // notice and this permission notice appear in supporting documentation. 
00014 // Binaries may be compiled with this software without any royalties or 
00015 // restrictions. 
00016 //
00017 // The University of North Carolina at Chapel Hill makes no representations 
00018 // about the suitability of this software for any purpose. It is provided 
00019 // "as is" without express or implied warranty.
00020 //
00021 
00022 #ifndef APSF_H
00023 #define APSF_H
00024 
00025 #include <cmath>
00026 #include <gl/glut.h>
00027 #include <vector>
00028 #include "ppm\ppm.hpp"
00029 
00030 using namespace std;
00031 
00032 #ifndef M_PI
00033 #define M_PI 3.1415926535897931f
00034 #endif
00035 
00039 class APSF  
00040 {
00041 public:
00043         APSF(int res = 512);
00045         virtual ~APSF();
00046 
00048   void read(const char* filename);
00050   void write(const char* filename);
00052   void writePPM(const char* filename);
00053   
00055   void generateKernelFast();
00056 
00058   int res() { return _res; };
00059   
00061   float* kernel() { return _kernel; };
00062   
00063 private:
00065   int     _res;
00067   float*  _kernel;
00068 
00070   // APSF components
00072 
00073   // scattering parameters
00074   float _q;
00075   float _T;
00076   float _I0;
00077   float _sigma;
00078   float _R;
00079   float _D;
00080 
00081   float _retinaSize;
00082   float _eyeSize;
00083   
00085   int _maxTerms;
00086   
00088   float pointAPSF(float mu);
00089   
00091   // auxiliary functions
00093   float legendreM(int m, float mu);
00094   float gM(float I0, int m) {
00095     return (m == 0) ? 0.0f : exp(-(betaM(m, _q) * _T + alphaM(m) * log(_T)));
00096   };
00097   float alphaM(float m) { 
00098     return m + 1.0f;
00099   };
00100   float betaM(float m, float q) {
00101     return ((2.0f * m + 1.0f) / m) * (1.0f - pow(q, (int)m - 1));
00102   };
00103   float factorial(float x) {
00104     return (x <= 1.0f) ? 1.0f : x * factorial(x - 1.0f);
00105   };
00106   float choose(float x, float y) {
00107     return factorial(x) / (factorial(y) * factorial(x - y));
00108   };
00109 };
00110 
00111 #endif

Generated on Wed Oct 25 03:19:42 2006 for Lumos by  doxygen 1.4.6