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
00033
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
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 }
00052 #endif