aimstil  5.0.5
Range.h
Go to the documentation of this file.
1 #ifndef TIL_RANGE_H
2 #define TIL_RANGE_H
3 
4 // includes from TIL library
5 #include "til/til_declarations.h"
6 #include "til/Box.h"
7 
8 namespace til
9 {
10 
11  template < typename T, std::size_t D >
13  {
14  private: // typedefs
15  typedef numeric_array<T,D> Vector;
16  public: // constructors
17  rectangular_range() : m_min(), m_max() {}
18  rectangular_range(const Vector & min, const Vector & max)
19  : m_min(min), m_max(max) {}
20  public: // set & get
21  Vector & min() { return m_min; }
22  Vector & max() { return m_max; }
23  const Vector & min() const { return m_min; }
24  const Vector & max() const { return m_max; }
25  private: // data
26  Vector m_min;
27  Vector m_max;
28  };
29 
30  template < typename T, std::size_t D, typename TNDIterator >
32  : public rectangular_range<T,D>
33  {
34  public: // typedef
36  typedef typename Base::Vector Vector;
37  public: // constructors
38  rectangular_range_indicator(const Base & rec) : Base(rec), m_pos() {}
39  rectangular_range_indicator(const Base & rec, const Vector & pos) : Base(rec), m_pos(pos) {}
40  rectangular_range_indicator(const Vector & min, const Vector & max) : Base(min, max), m_pos() {}
41  rectangular_range_indicator(const Vector & min, const Vector & max, const Vector & pos) : Base(min, max), m_pos(pos) {}
42  public: // set & get
43  Vector & pos() { return m_pos; }
44  public: // operator
45  void operator++()
46  {
47  if (++m_pos[0] < this->max()[0])
48  {
49  ++m_i;
50  return;
51  }
52  m_pos[0] = this->min()[0];
53  for (std::size_t i = 1; i < D; ++i)
54  {
55  if (++m_pos[i] < this->max()[i]) break;
56  m_pos[i] = this->min()[i];
57  set_coord(m_i, i, m_pos[i]);
58  }
59  m_i.from_pos(m_pos);
60  }
61  private: // data
62  Vector m_pos;
63  TNDIterator m_i;
64  };
65 
66 
69  // TODO: rename as BoxRange or RectangularRange
70  template < typename T, std::size_t D >
71  class Range
72  : public Box<T,D>
73  {
74  public: // typedefs
75  typedef Range<T,D> Self;
76  typedef Box<T, D> Base;
77 
78  public: // constructors & destructor
79 
81  Range() : Base() {};
82 
84  Range(const numeric_array<T,D> & minBounds, const numeric_array<T,D> & maxBounds)
85  : Base(minBounds, maxBounds) {};
86 
88  Range(const numeric_array<T, D> & maxBounds) : Base(numeric_array<T,D>(0,0,0), maxBounds) {}
89 
90  public: // set & get
91 
92  /*
94  void setCenterAndHalfSizes(const numeric_array<T,D> & center, const numeric_array<T,D> & halfSizes);
95 
97  void setCenterAndSizes(const numeric_array<T,D> & center, const numeric_array<T,D> & halfSizes);
98  */
99 
102  { return this->max_bounds() - this->min_bounds() + 1; }
103  };
104 
105  /*
106  template <typename T, std::size_t D>
107  void Range<T,D>::setCenterAndHalfSizes(const numeric_array<T,D> & center, const numeric_array<T,D> & halfSize)
108  {
109  this->set_bounds(center - halfSize, center + halfSize);
110  }
111 
112  template <typename T, std::size_t D>
113  void Range<T,D>::setCenterAndSizes(const numeric_array<T,D> & center, const numeric_array<T,D> & size)
114  {
115  for (int i = 0; i < D; ++i) { assert(size[i]%2); }
116  this->set_bounds(center - size/2, center + size/2);
117  }
118  */
119 
120 } // namespace til
121 
122 
123 // package include
124 #include "til/range_tools.h"
125 
126 #endif
127 
Vector & max()
Definition: Range.h:22
Range< T, D > Self
Definition: Range.h:75
rectangular_range_indicator(const Base &rec, const Vector &pos)
Definition: Range.h:39
Box< T, D > Base
Definition: Range.h:76
rectangular_range< T, D > Base
Definition: Range.h:35
rectangular_range_indicator(const Vector &min, const Vector &max, const Vector &pos)
Definition: Range.h:41
Range()
Default constructor.
Definition: Range.h:81
const Vector & min() const
Definition: Range.h:23
Belongs to package Box Do not include directly, include til/Box.h instead.
Definition: Accumulator.h:10
Describe integer cube ranges (e.g.
Definition: Range.h:71
This file contains forward declarations of classes defined in the TIL library.
Range(const numeric_array< T, D > &minBounds, const numeric_array< T, D > &maxBounds)
Set range bounds in all dimensions.
Definition: Range.h:84
rectangular_range_indicator(const Base &rec)
Definition: Range.h:38
Vector & min()
Definition: Range.h:21
Range(const numeric_array< T, D > &maxBounds)
Set max bounds, assuming min bounds are zeros.
Definition: Range.h:88
rectangular_range_indicator(const Vector &min, const Vector &max)
Definition: Range.h:40
numeric_array< T, D > dims() const
Get range size.
Definition: Range.h:101
A 3D box parallel to canonical axes.
Definition: Box.h:25
const Vector & max() const
Definition: Range.h:24
rectangular_range(const Vector &min, const Vector &max)
Definition: Range.h:18