Main Page   Groups   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Concepts

vnl_matrix_fixed.h

Go to the documentation of this file.
00001 #ifndef vnl_matrix_fixed_h_
00002 #define vnl_matrix_fixed_h_
00003 
00004 // This is vxl/vnl/vnl_matrix_fixed.h
00005 
00006 //:
00007 // \file
00008 // \brief Fixed Size Matrix
00009 // \author  Andrew W. Fitzgibbon, Oxford RRG, 04 Aug 96
00010 // 
00011 // A subclass of vnl_matrix_fixed_ref,
00012 // all storage is local and all vnl_matrix operations are valid.
00013 //
00014 //
00015 // Modifications:
00016 // Peter Vanroose, 23 Nov 1996:  added explicit copy constructor
00017 // LSB (Manchester) 15/03/2001:  added Binary I/O and tidied up the documentation
00018 
00019 //: Fixed size matrix
00020 //  vnl_matrix_fixed<T,m,n> - Fixed size matrix.
00021 //  A subclass of vnl_matrix_fixed_ref,
00022 //  all storage is local and all vnl_matrix operations are valid.
00023 //-----------------------------------------------------------------------------
00024 
00025 #include <vcl_cassert.h>
00026 #include <vnl/vnl_matrix_fixed_ref.h>
00027 
00028 template <class T, int m, int n>
00029 
00030 class vnl_matrix_fixed : public vnl_matrix_fixed_ref<T,m,n> {
00031   T space[m*n]; // Local storage
00032 public:
00033 
00034 //: Construct an empty m*n matrix
00035   vnl_matrix_fixed() : vnl_matrix_fixed_ref<T,m,n>(space) {}
00036 
00037 //: Construct an m*n matrix and fill with value
00038   vnl_matrix_fixed(const T& value):vnl_matrix_fixed_ref<T,m,n>(space) {
00039     int i = m*n;
00040     while (i--)
00041       space[i] = value;
00042   }
00043 
00044 //: Construct an m*n Matrix and copy data into it row-wise.
00045   vnl_matrix_fixed(const T* datablck) : vnl_matrix_fixed_ref<T,m,n>(space) {
00046     memcpy(space, datablck, m*n*sizeof(T));
00047   }
00048 
00049 //: Construct an m*n Matrix and copy rhs into it.   Abort if rhs is
00050 // not the same size.
00051   vnl_matrix_fixed(const vnl_matrix<T>& rhs) : vnl_matrix_fixed_ref<T,m,n>(space) {
00052     assert(rhs.rows() == m && rhs.columns() == n);
00053     memcpy(space, rhs.data_block(), m*n*sizeof(T));
00054   }
00055 
00056 //: Copy a vnl_matrix into this.   Abort if rhs is
00057 // not the same size.
00058   vnl_matrix_fixed<T,m,n>& operator=(const vnl_matrix<T>& rhs) {
00059     assert(rhs.rows() == m && rhs.columns() == n);
00060     memcpy(space, rhs.data_block(), m*n*sizeof(T));
00061     return *this;
00062   }
00063 
00064 //: Copy another vnl_matrix_fixed<T,m,n> into this.
00065   vnl_matrix_fixed<T,m,n>& operator=(const vnl_matrix_fixed<T, m, n>& rhs) {
00066     memcpy(space, rhs.data_block(), m*n*sizeof(T));
00067     return *this;
00068   }
00069 
00070   vnl_matrix_fixed(const vnl_matrix_fixed<T,m,n>& rhs) : vnl_matrix_fixed_ref<T,m,n>(space) {
00071     memcpy(space, rhs.data_block(), m*n*sizeof(T));
00072   }
00073 
00074 };
00075 
00076 #ifndef VCL_SUNPRO_CC
00077 
00078  template <class T, int M, int N, int O>
00079  //: Multiply two conformant vnl_matrix_fixed (M x N) times (N x O)
00080  vnl_matrix_fixed<T, M, O> operator*(const vnl_matrix_fixed<T, M, N>& a, const vnl_matrix_fixed<T, N, O>& b)
00081  {
00082   vnl_matrix_fixed<T, M, O> out;
00083   for(int i = 0; i < M; ++i)
00084     for(int j = 0; j < O; ++j) {
00085       T accum = a(i,0) * b(0,j);
00086       for(int k = 1; k < N; ++k)
00087         accum += a(i,k) * b(k,j);
00088       out(i,j) = accum;
00089     }
00090   return out;
00091  }
00092 #endif
00093 
00094 #define VNL_MATRIX_FIXED_PAIR_INSTANTIATE(T, M, N, O) \
00095 extern "please include vnl/vnl_matrix_fixed.txx instead"
00096 
00097 #endif // vnl_matrix_fixed_h_

Generated at Wed Mar 12 01:13:15 2003 for ITK by doxygen 1.2.15 written by Dimitri van Heesch, © 1997-2000