vbl_sparse_array_3d.h
Go to the documentation of this file.
1 // This is core/vbl/vbl_sparse_array_3d.h
2 #ifndef vbl_sparse_array_3d_h_
3 #define vbl_sparse_array_3d_h_
4 //:
5 // \file
6 // \brief a space efficient 3d array
7 // \author Andrew W. Fitzgibbon, Oxford RRG
8 // \date 02 Oct 96
9 //
10 // vbl_sparse_array_3d is a sparse 3D array allowing space
11 // efficient access of the form s(300,700,900) = 2.
12 //
13 // \verbatim
14 // Modifications
15 // 26 March 2001 cjb updated documentation
16 // 10 April 2001 IMS (Manchester ISBE) modified to use vbl_sparse_array_base
17 // 11 April 2001 Peter Vanroose - vbl_index_3d moved to separate file
18 // 25 June 2001 IMS - vbl_index_3d replaced with vbl_triple
19 // \endverbatim
20 //---------------------------------------------------------------------------
21 
22 
23 #include <iosfwd>
24 #ifdef _MSC_VER
25 # include <vcl_msvc_warnings.h>
26 #endif
28 #include <vbl/vbl_triple.h>
29 
30 
31 //: Sparse 3d array allowing space efficient access
32 // You can use this as e.g. s(300,700,900) = T(2).
33 template <class T>
34 class vbl_sparse_array_3d : public vbl_sparse_array_base<T, vbl_triple<unsigned, unsigned, unsigned> >
35 {
36  public:
37 
38  //: Put a value into location (i,j,k).
39  bool put(unsigned i, unsigned j, unsigned k, const T& t)
40  {
41  return vbl_sparse_array_base<T,
43  put(vbl_make_triple(i, j, k), t);
44  }
45 
46  //: Return contents of location (i,j,k).
47  // Returns an undefined value (in fact
48  // a T()) if location (i,j,k) has not been filled with a value.
49  T& operator () (unsigned i, unsigned j, unsigned k)
50  {
51  return vbl_sparse_array_base<T,
53  operator() (vbl_make_triple(i, j, k));
54  }
55 
56  //: Return contents of (i,j,k). Assertion failure if not yet filled.
57  const T& operator () (unsigned i, unsigned j, unsigned k) const
58  {
59  return vbl_sparse_array_base<T,
61  operator() (vbl_make_triple(i, j, k));
62  }
63 
64  //: Return true if location (i,j,k) has been filled.
65  bool fullp(unsigned i, unsigned j, unsigned k) const
66  {
67  return vbl_sparse_array_base<T,
69  fullp(vbl_make_triple(i, j, k));
70  }
71 
72  //: Return the address of location (i,j,k). 0 if not yet filled.
73  T* get_addr(unsigned i, unsigned j, unsigned k)
74  {
75  return vbl_sparse_array_base<T,
77  get_addr(vbl_make_triple(i, j, k));
78  }
79 
80  //: Print the Array to a stream in "(i,j,k): value" format.
81  std::ostream& print(std::ostream&) const;
82 };
83 
84 //: Stream operator - print the Array to a stream in "(i,j,k): value" format.
85 template <class T>
86 inline std::ostream& operator <<
87 (std::ostream& s, const vbl_sparse_array_3d<T>& a)
88 {
89  return a.print(s);
90 }
91 
92 
93 #ifndef VBL_SPARSE_ARRAY_BASE_INSTANTIATE
94 #define VBL_SPARSE_ARRAY_BASE_INSTANTIATE(T) \
95 extern "please include vbl/vbl_sparse_array_base.hxx instead"
96 #endif // VBL_SPARSE_ARRAY_BASE_INSTANTIATE
97 #define VBL_SPARSE_ARRAY_3D_INSTANTIATE(T) \
98 extern "please include vbl/vbl_sparse_array_3d.hxx instead"
99 
100 #endif // vbl_sparse_array_3d_h_
T * get_addr(unsigned i, unsigned j, unsigned k)
Return the address of location (i,j,k). 0 if not yet filled.
a templated 3-tuple.
Definition: vbl_fwd.h:22
vbl_triple< T1, T2, T3 > vbl_make_triple(T1 const &x, T2 const &y, T3 const &z)
Definition: vbl_triple.h:61
std::ostream & print(std::ostream &) const
Print the Array to a stream in "(i,j,k): value" format.
bool put(unsigned i, unsigned j, unsigned k, const T &t)
Put a value into location (i,j,k).
base class for sparse arrays.
a templated 3-tuple
T & operator()(unsigned i, unsigned j, unsigned k)
Return contents of location (i,j,k).
Sparse 3d array allowing space efficient access.
Definition: vbl_fwd.h:10
A fully featured sparse array which devolves indexing to its templated type.
bool fullp(unsigned i, unsigned j, unsigned k) const
Return true if location (i,j,k) has been filled.