Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   File Members  

histogramimage.h

Go to the documentation of this file.
00001 
00012 #ifndef __HISTOGRAM_IMAGE_H__
00013 #define __HISTOGRAM_IMAGE_H__
00014 
00015 // Uses roundabout paths to the current directory to avoid Cray C bug
00016 #include "../src/image.h"
00017 #include "../src/pixel.h"
00018 #include "../src/colorlookup.h"
00019 #include "../src/histogram.h"
00020 
00021 namespace  Plot {
00022 
00023 
00030 template<class PixelType=RGBPixel<>, class PixelMatrix= typename MatrixType<PixelType>::rectangular >
00031 class OneDHistogramImage : public AARImage<PixelType,PixelMatrix> {
00032 private:
00033 
00035   typedef typename AARImage<PixelType,PixelMatrix>::PixelSubscript PixelSubscript;
00036 
00038   typedef int Subscript;
00039   
00041   PixelSubscript border;
00042   
00044   double num_bins;
00045   
00047   double size_scale;
00048   
00050   bool vertical;
00051   
00053   Bounded::Magnitude bin_fullness_range;
00054   
00056   PixelSubscript min_pixelnum;
00057   
00059   PixelSubscript zero_pixelnum;
00060   
00062   PixelSubscript max_pixelnum;
00063 
00065   PixelType bg;
00066 
00068   PixelType fg;
00069 
00071   bool markzero;
00072   
00074   inline PixelSubscript bin_number_pixelnum(const Subscript b) const
00075     {  return PixelSubscript(b*size_scale+border);  }
00076   
00078   /* Will need to be modified for a symmetric plot */
00079   inline PixelSubscript bin_fullness_pixelnum(const Bounded::Magnitude bin_fullness) const {
00080     return Generic::crop(min_pixelnum,max_pixelnum,
00081                          min_pixelnum+Subscript((1+max_pixelnum-min_pixelnum)*
00082                                                 (bin_fullness/bin_fullness_range)));
00083   }
00084   
00085   void draw_element(const Subscript bin_number, const Bounded::Magnitude bin_fullness, PixelType p=default_fg);
00086   void draw_element_vertical(const Subscript bin_number, const Bounded::Magnitude bin_fullness, PixelType p=default_fg);
00087 
00088   
00089 public:
00092   
00094   OneDHistogramImage()
00095     : border(0), num_bins(0), size_scale(1.0), vertical(false),
00096       bin_fullness_range(0), min_pixelnum(0), zero_pixelnum(0), 
00097       max_pixelnum(0), markzero(false) { }
00098   
00099   template <class Histogram>
00100   OneDHistogramImage(const Histogram &h, bool vertical=false,
00101                      double size_scale_i=1.0, double aspect_ratio_i=1.0, 
00102                      Bounded::Magnitude bin_fullness_range_i=1.0, int borderwidth=0,
00103                      const ColorLookup<PixelType>& L=HueColorLookup<PixelType>(),
00104                      const PixelType& bordercolor=default_border, 
00105                      const PixelType& bg_=default_bg,
00106                      const PixelType& fg_=default_fg);
00107   
00109 };
00110 
00111 
00112 
00121 template<class PixelType, class PixelMatrix>
00122 template <class Histogram>
00123 OneDHistogramImage<PixelType,PixelMatrix>::OneDHistogramImage
00124   (const Histogram &h, bool vertical_i, double size_scale_i, double aspect_ratio_i, 
00125    Bounded::Magnitude bin_fullness_range_i, int borderwidth, const ColorLookup<PixelType>& L,
00126    const PixelType& bordercolor, const PixelType& bg_, const PixelType& fg_)
00127   : AARImage<PixelType>(2*borderwidth+Subscript(h.num_bins()*size_scale_i*(vertical_i?1.0:aspect_ratio_i)),
00128                         2*borderwidth+Subscript(h.num_bins()*size_scale_i*(vertical_i?aspect_ratio_i:1.0))),
00129   border(borderwidth), num_bins(h.num_bins()), size_scale(size_scale_i), vertical(vertical_i),
00130   bin_fullness_range(bin_fullness_range_i), min_pixelnum(borderwidth), zero_pixelnum(borderwidth), 
00131   max_pixelnum(borderwidth+PixelSubscript(h.num_bins()*size_scale_i*aspect_ratio_i)),
00132   bg(bg_), fg(fg_), markzero(false) {
00133 
00134   draw_border(borderwidth,bordercolor);
00135   typedef typename Histogram::size_type Subscript;
00136 
00137   if (vertical)
00138     for (Subscript b=0; b<h.num_bins(); b++)
00139       draw_element_vertical(b,h.value_mag(b),L((b*1.0)/h.num_bins()));
00140   else
00141     for (Subscript b=0; b<h.num_bins(); b++)
00142       draw_element(b,h.value_mag(b),L((b*1.0)/h.num_bins()));
00143 }
00144 
00145 
00146 
00153 template<class PixelType, class PixelMatrix>
00154 void OneDHistogramImage<PixelType,PixelMatrix>::draw_element_vertical
00155   (const Subscript bin_number, const Bounded::Magnitude bin_fullness, PixelType p)
00156 {
00157   const PixelSubscript pivot = bin_fullness_pixelnum(bin_fullness);
00158   const PixelSubscript binpl = bin_number_pixelnum(bin_number);
00159   const PixelSubscript binph = bin_number_pixelnum(bin_number+1);
00160     
00161   /* Representation consists of three boxes: bar, background, and (optional) origin */
00162   draw_rectangle(  binpl,   zero_pixelnum, binph, pivot,           p );
00163   draw_rectangle(  binpl,   pivot,         binph, max_pixelnum,    bg);
00164   if (markzero)
00165     draw_rectangle(binpl,   zero_pixelnum, binph, zero_pixelnum+1, fg);
00166 }
00167 
00168 
00169  
00176 template<class PixelType, class PixelMatrix>
00177 void OneDHistogramImage<PixelType,PixelMatrix>::draw_element
00178   (const Subscript bin_number, const Bounded::Magnitude bin_fullness, PixelType p)
00179 {
00180   const PixelSubscript pivot = bin_fullness_pixelnum(bin_fullness);
00181   const PixelSubscript binpl = bin_number_pixelnum(bin_number);
00182   const PixelSubscript binph = bin_number_pixelnum(bin_number+1);
00183     
00184   /* Representation consists of three boxes: bar, background, and (optional) origin */
00185   draw_rectangle(  nrows()-zero_pixelnum, binpl,   nrows()-pivot,           binph, p );
00186   draw_rectangle(  nrows()-pivot,         binpl,   nrows()-max_pixelnum,    binph, bg);
00187   if (markzero)                                                    
00188     draw_rectangle(nrows()-zero_pixelnum, binpl,   nrows()-zero_pixelnum+1, binph, fg);
00189 }
00190 
00191 
00192 } /* namespace Plot */
00193 #endif /* __HISTOGRAM_IMAGE_H__ */

Generated on Mon Jan 20 02:35:44 2003 for RF-LISSOM by doxygen1.3-rc2