STIR  6.2.0
IndexRange.h
Go to the documentation of this file.
1 //
2 //
3 /*
4  Copyright (C) 2000 PARAPET partners
5  Copyright (C) 2000- 2011, Hammersmith Imanet Ltd
6  This file is part of STIR.
7 
8  SPDX-License-Identifier: Apache-2.0 AND License-ref-PARAPET-license
9 
10  See STIR/LICENSE.txt for details
11 */
12 
13 #ifndef __IndexRange_H__
14 #define __IndexRange_H__
15 
27 #include "stir/VectorWithOffset.h"
28 #include "stir/BasicCoordinate.h"
29 
30 START_NAMESPACE_STIR
31 
67 template <int num_dimensions>
68 class IndexRange : public VectorWithOffset<IndexRange<num_dimensions - 1>>
69 {
70 protected:
71  typedef VectorWithOffset<IndexRange<num_dimensions - 1>> base_type;
72 
73 public:
75  typedef typename base_type::iterator iterator;
77 
79  inline IndexRange();
80 
83 
85  inline IndexRange(const IndexRange<num_dimensions>& range);
86 
89 
92 
94  inline size_t size_all() const;
95 
96  // these are derived from VectorWithOffset
97  // TODO these should be overloaded, to set regular_range as well.
98  /*
99  const IndexRange<num_dimensions-1>& operator[](int i) const
100  { return range[i]; }
101 
102  IndexRange<num_dimensions-1>& operator[](int i)
103  { return range[i]; }
104  */
105 
107  inline bool operator==(const IndexRange<num_dimensions>&) const;
108  inline bool operator!=(const IndexRange<num_dimensions>&) const;
109 
111  inline bool is_regular() const;
112 
114  bool get_regular_range(BasicCoordinate<num_dimensions, int>& min, BasicCoordinate<num_dimensions, int>& max) const;
115 
116 private:
118  enum is_regular_type
119  {
120  regular_true,
121  regular_false,
122  regular_to_do
123  };
124 
126  mutable is_regular_type is_regular_range;
127 };
128 
130 template <>
131 class IndexRange<1>
132 {
133 public:
134  inline IndexRange();
135  inline IndexRange(const int min, const int max);
136 
137  inline IndexRange(const BasicCoordinate<1, int>& min, const BasicCoordinate<1, int>& max);
138 
139  inline IndexRange(const int length);
140  inline IndexRange(const BasicCoordinate<1, int>& size);
141 
142  inline int get_min_index() const;
143  inline int get_max_index() const;
144  inline int get_length() const;
146  inline size_t size_all() const;
147 
148  inline bool operator==(const IndexRange<1>& range2) const;
149 
151  inline bool is_regular() const;
152 
154  inline bool get_regular_range(BasicCoordinate<1, int>& min, BasicCoordinate<1, int>& max) const;
156  inline void resize(const int min_index, const int max_index);
157 
158 private:
159  int min;
160  int max;
161 };
162 
163 END_NAMESPACE_STIR
164 
165 #include "stir/IndexRange.inl"
166 
167 #endif
A templated class for vectors, but with indices starting not from 0.
Definition: ArrayFilter1DUsingConvolution.h:31
base_type::iterator iterator
typedefs such that we do not need to have typename wherever we use iterators
Definition: IndexRange.h:75
This file declares class stir::BasicCoordinate and some functions acting on stir::BasicCoordinate obj...
inline definitions for the IndexRange class
defines the stir::VectorWithOffset class
The (simple) 1 dimensional specialisation of IndexRange.
Definition: IndexRange.h:131