aimstil  5.0.5
Box.h
Go to the documentation of this file.
1 #ifndef TIL_BOX_H
2 #define TIL_BOX_H
3 
4 // Standard library includes
5 #include <stdexcept>
6 
7 // Local includes
8 #include "til/til_common.h"
9 #include "til/til_declarations.h"
10 #include "til/numeric_array.h"
11 
12 // Ignore specific warnings
13 #ifdef _MSC_VER
14 #pragma warning (push)
15 #pragma warning (disable : 4231) // nonstandard extension used : 'extern' before template explicit instantiation
16 #endif // _MSC_VER
17 
18 // Namespace
19 
20 namespace til {
21 
22 
24  template < typename T, std::size_t D >
25  class Box
26  {
27  public: // typedefs
28  typedef Box<T,D> Self;
29 
30  public: // constructors & destructor
31 
33  Box();
34 
36  Box(const numeric_array<T,D> & posMin, const numeric_array<T,D> & posMax);
37 
38  public: // functions
39 
41  const numeric_array<T,D> & min_bounds() const { return m_minBounds; }
43  const numeric_array<T,D> & max_bounds() const { return m_maxBounds; }
44 
45  // Set bounds
46  // NB: box bounds have to be consistent at all time, e.g. one cannot
47  // set a min x that is greater than the current max x.
48  // This is why there is not direct writable access to bounds, we have to go through
49  // those set functions
50 
54  void set_max_bounds(const numeric_array<T,D> & min);
56  void set_min_bound(std::size_t i, T value);
58  void set_max_bound(std::size_t i, T value);
60  void set_bounds(const numeric_array<T,D> & minBounds, const numeric_array<T,D> & maxBounds);
62  void set_bounds(std::size_t i, T min, T max);
63 
64  private: // data
65 
66  numeric_array<T,D> m_minBounds;
67  numeric_array<T,D> m_maxBounds;
68  };
69 
70 #ifdef TIL_EXPORT_SOME_CLASSES
71  EXPIMP_TEMPLATE template class TIL_API Box<int,3>;
72 #endif
73 
74  template < typename T, std::size_t D >
75  // This is naturally assuming that default constructor initialize stuff
76  Box<T,D>::Box() : m_minBounds(), m_maxBounds()
77  {
78  }
79 
80  template < typename T, std::size_t D >
81  Box<T,D>::Box(const numeric_array<T,D> & minBounds, const numeric_array<T,D> & maxBounds)
82  {
83  this->set_bounds(minBounds, maxBounds);
84  }
85 
86  template < typename T, std::size_t D >
87  void Box<T,D>::set_bounds(const numeric_array<T,D> & minBounds, const numeric_array<T,D> & maxBounds)
88  {
89  for (std::size_t i = 0; i < D; ++i) assert(minBounds[i] <= maxBounds[i]);
90  m_minBounds = minBounds;
91  m_maxBounds = maxBounds;
92  }
93 
94  template < typename T, std::size_t D >
95  void Box<T,D>::set_bounds(std::size_t i, T minBound, T maxBound)
96  {
97  assert(minBound <= maxBound);
98  m_minBounds[i] = minBound;
99  m_maxBounds[i] = maxBound;
100  }
101 
102  template < typename T, std::size_t D >
104  {
105  for (int i = 0; i < D; ++i) assert(minBounds[i] <= m_maxBounds[i]);
106  m_minBounds = minBounds;
107  }
108 
109  template < typename T, std::size_t D >
111  {
112  for (int i = 0; i < D; ++i) assert(maxBounds[i] >= m_minBounds[i]);
113  m_maxBounds = maxBounds;
114  }
115 
116  template < typename T, std::size_t D >
117  void Box<T,D>::set_min_bound(std::size_t i, T value)
118  {
119  assert(value <= m_maxBounds[i]);
120  m_minBounds[i] = value;
121  }
122 
123  template < typename T, std::size_t D >
124  void Box<T,D>::set_max_bound(std::size_t i, T value)
125  {
126  assert(value >= m_minBounds[i]);
127  m_maxBounds[i] = value;
128  }
129 
130 } // namespace til
131 
132 #ifdef _MSC_VER
133 #pragma warning (pop)
134 #endif
135 
136 // Package includes
137 #include "til/boxTools.h"
138 
139 #endif
140 
boost::enable_if< is_Image< TImage >, typename TImage::value_type >::type min(const TImage &im)
void set_bounds(const numeric_array< T, D > &minBounds, const numeric_array< T, D > &maxBounds)
Set min and max bounds.
Definition: Box.h:87
void set_min_bound(std::size_t i, T value)
Set min bound on axis i.
Definition: Box.h:117
void set_max_bound(std::size_t i, T value)
Set max bound on axis i.
Definition: Box.h:124
Box< T, D > Self
Definition: Box.h:28
Belongs to package Box Do not include directly, include til/Box.h instead.
Definition: Accumulator.h:10
General macros, definitions and functions.
#define TIL_API
Definition: til_common.h:42
void set_min_bounds(const numeric_array< T, D > &min)
Set min bounds.
Definition: Box.h:103
const numeric_array< T, D > & min_bounds() const
Get min bounds.
Definition: Box.h:41
void set_max_bounds(const numeric_array< T, D > &min)
Set max bounds.
Definition: Box.h:110
This file contains forward declarations of classes defined in the TIL library.
const numeric_array< T, D > & max_bounds() const
Get max bounds.
Definition: Box.h:43
Box()
Default constructor. All coordinates are set to zero.
Definition: Box.h:76
TImage::value_type max(const TImage &im)
Returns the maximum intensity of the input image.
A 3D box parallel to canonical axes.
Definition: Box.h:25
#define EXPIMP_TEMPLATE
Definition: til_common.h:43