Main Page | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Class Members | File Members | Related Pages

bmrf_gamma_func.cxx

Go to the documentation of this file.
00001 // This is brl/bseg/bmrf/bmrf_gamma_func.cxx
00002 #include "bmrf_gamma_func.h"
00003 //:
00004 // \file
00005 
00006 #include "bmrf_epi_seg.h"
00007 #include "bmrf_epi_seg_compare.h"
00008 #include "bmrf_epi_point.h"
00009 #include <vcl_utility.h>
00010 
00011 
00012 //: Constructor
00013 bmrf_pwl_gamma_func::bmrf_pwl_gamma_func( const bmrf_epi_seg_sptr& ep1,
00014                                           const bmrf_epi_seg_sptr& ep2,
00015                                           double t )
00016 {
00017   double min_alpha = bmrf_min_alpha(ep1, ep2);
00018   double max_alpha = bmrf_max_alpha(ep1, ep2);
00019   //double d_alpha =   bmrf_d_alpha(ep1, ep2);
00020 
00021   for (int i=0; i<ep1->n_pts(); ++i) {
00022     double alpha = ep1->p(i)->alpha();
00023     if (alpha >= min_alpha && alpha <= max_alpha)
00024       knots_[alpha] = (1 - (ep1->s(alpha) / ep2->s(alpha)))/t;
00025   }
00026 }
00027 
00028 
00029 //: Return the average gamma value at time \p t
00030 //  Here, this value is independent of t
00031 double
00032 bmrf_pwl_gamma_func::mean(double /*t*/) const
00033 {
00034   if (knots_.empty())
00035     return 0.0;
00036 
00037   vcl_map<double,double>::const_iterator k = knots_.begin(), last_k = k;
00038   double sum = 0.0, min_alpha = k->first;
00039   for (++k; k != knots_.end();  last_k=k, ++k){
00040     sum += (k->second + last_k->second) * (k->first - last_k->first);
00041   }
00042   return sum/(2.0*(last_k->first - min_alpha));
00043 }
00044 
00045 
00046 //: Return the gamma value for any \p alpha and time \p t
00047 //  Here, this value is independent of t
00048 double
00049 bmrf_pwl_gamma_func::value(double alpha, double /*t*/) const
00050 {
00051   if ( knots_.empty() )
00052     return 0.0;
00053 
00054   typedef vcl_map<double,double>::const_iterator k_itr;
00055   vcl_pair<k_itr,k_itr> rng = knots_.equal_range(alpha);
00056 
00057   // the value is at one of the knots
00058   if (rng.first != rng.second)
00059     return rng.first->second;
00060 
00061   // the value is before the first knot
00062   if (rng.first == knots_.begin())
00063     return rng.first->second;
00064 
00065   // the value is after the last knot
00066   if (rng.first == knots_.end())
00067     return (--rng.first)->second;
00068 
00069   // the value is between knots
00070   k_itr k2 = rng.first, k1 = --rng.first;
00071   double p = (alpha - k1->first)/(k2->first - k1->first);
00072   return (1-p)*k1->second + p*k2->second;
00073 }

Generated on Thu Jan 10 14:51:53 2008 for contrib/brl/bseg/bmrf by  doxygen 1.4.4