STIR 6.4.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
29
30START_NAMESPACE_STIR
31
67template <int num_dimensions>
68class IndexRange : public VectorWithOffset<IndexRange<num_dimensions - 1>>
69{
70protected:
71 typedef VectorWithOffset<IndexRange<num_dimensions - 1>> base_type;
72
73public:
75 typedef typename base_type::iterator iterator;
76 typedef typename base_type::const_iterator const_iterator;
77
79 inline IndexRange();
80
83
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
115
116private:
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
130template <>
131class IndexRange<1>
132{
133public:
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
156 inline void resize(const int min_index, const int max_index);
157
158private:
159 int min;
160 int max;
161};
162
163END_NAMESPACE_STIR
164
165#include "stir/IndexRange.inl"
166
167#endif
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
class BasicCoordinate<int num_dimensions, typename coordT> defines num_dimensions -dimensional coordi...
Definition BasicCoordinate.h:57
void resize(const int min_index, const int max_index)
resets to new index range
Definition IndexRange.inl:199
bool is_regular() const
checks if the range is 'regular' (always true for the 1d case)
Definition IndexRange.inl:180
size_t size_all() const
return the total number of elements in this range
Definition IndexRange.inl:168
bool get_regular_range(BasicCoordinate< 1, int > &min, BasicCoordinate< 1, int > &max) const
fills in min and max, and returns true
Definition IndexRange.inl:187
size_t size_all() const
return the total number of elements in this range
Definition IndexRange.inl:71
IndexRange(const BasicCoordinate< num_dimensions, int > &min, const BasicCoordinate< num_dimensions, int > &max)
Construct a regular range given by all minimum indices and all maximum indices.
Definition IndexRange.inl:51
IndexRange(const VectorWithOffset< IndexRange< num_dimensions - 1 > > &range)
Make an IndexRange from the base type.
bool is_regular() const
checks if the range is 'regular'
Definition IndexRange.inl:100
bool get_regular_range(BasicCoordinate< num_dimensions, int > &min, BasicCoordinate< num_dimensions, int > &max) const
find regular range, returns false if the range is not regular
Definition IndexRange.cxx:29
IndexRange(const IndexRange< num_dimensions > &range)
Copy constructor.
Definition IndexRange.inl:39
bool operator==(const IndexRange< num_dimensions > &) const
comparison operator
Definition IndexRange.inl:85
IndexRange()
Empty range.
Definition IndexRange.inl:33
IndexRange(const BasicCoordinate< num_dimensions, int > &sizes)
Construct a regular range given by sizes (minimum indices will be 0)
Definition IndexRange.inl:61
base_type::iterator iterator
typedefs such that we do not need to have typename wherever we use iterators
Definition IndexRange.h:75