core/vbl/vbl_sparse_array_3d.h
Go to the documentation of this file.
00001 // This is core/vbl/vbl_sparse_array_3d.h
00002 #ifndef vbl_sparse_array_3d_h_
00003 #define vbl_sparse_array_3d_h_
00004 #ifdef VCL_NEEDS_PRAGMA_INTERFACE
00005 #pragma interface
00006 #endif
00007 //:
00008 // \file
00009 // \brief a space efficient 3d array
00010 // \author Andrew W. Fitzgibbon, Oxford RRG
00011 // \date   02 Oct 96
00012 //
00013 //    vbl_sparse_array_3d is a sparse 3D array allowing space
00014 //    efficient access of the form s(300,700,900) = 2.
00015 //
00016 // \verbatim
00017 //  Modifications
00018 //   26 March 2001 cjb updated documentation
00019 //   10 April 2001 IMS (Manchester ISBE) modified to use vbl_sparse_array_base
00020 //   11 April 2001 Peter Vanroose - vbl_index_3d moved to separate file
00021 //   25 June  2001 IMS - vbl_index_3d replaced with vbl_triple
00022 // \endverbatim
00023 //---------------------------------------------------------------------------
00024 
00025 
00026 #include <vcl_iosfwd.h>
00027 #include <vbl/vbl_sparse_array_base.h>
00028 #include <vbl/vbl_triple.h>
00029 
00030 
00031 //: Sparse 3d array allowing space efficient access
00032 // You can use this as e.g. s(300,700,900) = T(2).
00033 template <class T>
00034 class vbl_sparse_array_3d : public vbl_sparse_array_base<T, vbl_triple<unsigned, unsigned, unsigned> >
00035 {
00036  public:
00037 
00038   //: Put a value into location (i,j,k).
00039   bool put(unsigned i, unsigned j, unsigned k, const T& t)
00040   {
00041     return vbl_sparse_array_base<T,
00042       vbl_triple<unsigned, unsigned, unsigned> >::
00043       put(vbl_make_triple(i, j, k), t);
00044   }
00045 
00046   //: Return contents of location (i,j,k).
00047   //  Returns an undefined value (in fact
00048   //  a T()) if location (i,j,k) has not been filled with a value.
00049   T& operator () (unsigned i, unsigned j, unsigned k)
00050   {
00051     return vbl_sparse_array_base<T,
00052       vbl_triple<unsigned, unsigned, unsigned> >::
00053       operator() (vbl_make_triple(i, j, k));
00054   }
00055 
00056   //: Return contents of (i,j,k).  Assertion failure if not yet filled.
00057   const T& operator () (unsigned i, unsigned j, unsigned k) const
00058   {
00059     return vbl_sparse_array_base<T,
00060       vbl_triple<unsigned, unsigned, unsigned> >::
00061       operator() (vbl_make_triple(i, j, k));
00062   }
00063 
00064   //: Return true if location (i,j,k) has been filled.
00065   bool fullp(unsigned i, unsigned j, unsigned k) const
00066   {
00067     return vbl_sparse_array_base<T,
00068       vbl_triple<unsigned, unsigned, unsigned> >::
00069       fullp(vbl_make_triple(i, j, k));
00070   }
00071 
00072   //: Return the address of location (i,j,k).  0 if not yet filled.
00073   T* get_addr(unsigned i, unsigned j, unsigned k)
00074   {
00075     return vbl_sparse_array_base<T,
00076       vbl_triple<unsigned, unsigned, unsigned> >::
00077       get_addr(vbl_make_triple(i, j, k));
00078   }
00079 
00080   //: Print the Array to a stream in "(i,j,k): value" format.
00081   vcl_ostream& print(vcl_ostream&) const;
00082 };
00083 
00084 //: Stream operator - print the Array to a stream in "(i,j,k): value" format.
00085 template <class T>
00086 inline vcl_ostream& operator <<
00087 (vcl_ostream& s, const vbl_sparse_array_3d<T>& a)
00088 {
00089   return a.print(s);
00090 }
00091 
00092 
00093 #ifndef VBL_SPARSE_ARRAY_BASE_INSTANTIATE
00094 #define VBL_SPARSE_ARRAY_BASE_INSTANTIATE(T) \
00095 extern "please include vbl/vbl_sparse_array_base.txx instead"
00096 #endif // VBL_SPARSE_ARRAY_BASE_INSTANTIATE
00097 #define VBL_SPARSE_ARRAY_3D_INSTANTIATE(T) \
00098 extern "please include vbl/vbl_sparse_array_3d.txx instead"
00099 
00100 #endif // vbl_sparse_array_3d_h_