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

matrixhistogram.h

Go to the documentation of this file.
00001 
00007 #ifndef __MATRIXHISTOGRAM_H__
00008 #define __MATRIXHISTOGRAM_H__
00009 
00010 #include "../src/histogram.h"
00011 #include "../src/matrix.h"
00012 #include "../src/genericalgs.h"
00013 
00014 namespace  Histo {
00015 
00016 
00024 template <class BinMatrix, class ValueMatrix, class ScaleType>
00025 Histo::OneDHistogram<> matrix_histogram(const BinMatrix& mb, const ValueMatrix& mv,
00026                                         const typename BinMatrix::size_type num_bins,
00027                                         const ScaleType& binscale,
00028                                         bool wrap=false)
00029 {
00030   Histo::OneDHistogram<> h(num_bins);
00031   
00032   /* Uses matrix interface rather than a 1D-iterator to ensure that
00033      corresponding elements match. */
00034   typedef typename BinMatrix::size_type  size_type;
00035   typedef typename BinMatrix::value_type value_type;
00036   for   (size_type r=0; r<mb.nrows(); r++)
00037     for (size_type c=0; c<mb.ncols(); c++) {
00038       const value_type binval = binscale(mat::elem(mb,r,c));
00039       const size_type  binnum = size_type(binval);
00040       //const size_type  binnum = size_type(floor(binval+0.5)); /* Rounds */ //////
00041       const size_type  bin    = (wrap? Generic::wrap(size_type(0),size_type(num_bins),  size_type(binnum))
00042                                  :     Generic::crop(size_type(0),size_type(num_bins-1),size_type(binnum)));
00043       h.add(bin,mat::elem(mv,r,c));
00044     }
00045   
00046   return h;
00047 }
00048 
00049 
00050 
00051 } /* namespace Histo */
00052 #endif /* __MATRIXHISTOGRAM_H__ */

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