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

matrixadapter.h

Go to the documentation of this file.
00001 
00007 #ifndef __MATRIXADAPTER_H__
00008 #define __MATRIXADAPTER_H__
00009 
00010 #include "matrix.h"
00011 #include <iomanip>
00012 
00013 namespace mat {
00014 
00027 template <class M> 
00028 class matrixadapter {
00029   typedef matrixadapter<M> self;
00030 public:
00031   
00032   typedef typename M::size_type  size_type;
00033   typedef int Coordinate;
00034   typedef typename M::value_type value_type;
00035   
00037   inline matrixadapter() : alpha(0), beta(0) { }
00038   
00055   inline matrixadapter(const M& x, const value_type& a=1.0, const value_type& b=0.0,
00056                        size_type nr=0, size_type nc=0,
00057                        size_type o_r=0, size_type o_c=0,
00058                        double sr=1, double sc=1)
00059     : m(x), alpha(a), beta(b),
00060       height(size_type(sr*(nr?nr:x.nrows()))),
00061       width( size_type(sc*(nc?nc:x.ncols()))),
00062       originr(o_r), originc(o_c), div_sizer(1/sr), div_sizec(1/sc) { }
00063   
00064 
00066   inline bool inbounds(const size_type r, const size_type c) const {
00067     return (r>=0 && r<m.nrows() &&
00068             c>=0 && c<m.ncols());
00069   }
00070   
00071   
00072 
00073   inline value_type operator()(const size_type row, const size_type col) const {
00074 
00075 #ifdef USE_TNT_MATRIX
00076   /* TNT's operator() is 1-based (blame Fortran) */
00077     const size_type lower_bound=1;
00078 #else    
00079     const size_type lower_bound=0;
00080 #endif
00081     
00082     const value_type default_value=0;
00083     const Coordinate r=row-lower_bound;
00084     const Coordinate c=col-lower_bound;
00085     /* The 0.000001 is to compensate for floating point truncation
00086        errors for some common size scales, e.g. multiples of 3. */
00087     const Coordinate sr=Coordinate(floor((r*div_sizer)+0.000001))-originr;
00088     const Coordinate sc=Coordinate(floor((c*div_sizec)+0.000001))-originc;
00089 
00090     return beta + alpha*(inbounds(sr,sc)? mat::elem(m,sr,sc): default_value);
00091   }
00092     
00093   
00095   inline size_type nrows() const { return height; }
00096 
00098   inline size_type ncols() const { return width; }
00099   
00100 protected:
00101   M m;
00102 
00103   value_type alpha,beta;
00104   size_type  height,width;
00105   Coordinate originr,originc;
00106   double div_sizer,div_sizec;
00107 };
00108 
00109  
00110 
00111 } /* namespace mat */
00112 
00113 
00114 #endif /* __MATRIXADAPTER_H__ */

Generated at Mon Aug 21 00:30:54 2000 for RF-LISSOM by doxygen1.2.1 written by Dimitri van Heesch, © 1997-2000