iLab Neuromorphic Robotics Toolkit  0.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ImageSetImpl.H
Go to the documentation of this file.
1 /*! @file
2  @author Laurent Itti
3  @copyright GNU Public License (GPL v3)
4  @section License
5  @verbatim
6  // ////////////////////////////////////////////////////////////////////////
7  // The iLab Neuromorphic Robotics Toolkit (NRT) //
8  // Copyright 2010-2012 by the University of Southern California (USC) //
9  // and the iLab at USC. //
10  // //
11  // iLab - University of Southern California //
12  // Hedco Neurociences Building, Room HNB-10 //
13  // Los Angeles, Ca 90089-2520 - USA //
14  // //
15  // See http://ilab.usc.edu for information about this project. //
16  // ////////////////////////////////////////////////////////////////////////
17  // This file is part of The iLab Neuromorphic Robotics Toolkit. //
18  // //
19  // The iLab Neuromorphic Robotics Toolkit is free software: you can //
20  // redistribute it and/or modify it under the terms of the GNU General //
21  // Public License as published by the Free Software Foundation, either //
22  // version 3 of the License, or (at your option) any later version. //
23  // //
24  // The iLab Neuromorphic Robotics Toolkit is distributed in the hope //
25  // that it will be useful, but WITHOUT ANY WARRANTY; without even the //
26  // implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR //
27  // PURPOSE. See the GNU General Public License for more details. //
28  // //
29  // You should have received a copy of the GNU General Public License //
30  // along with The iLab Neuromorphic Robotics Toolkit. If not, see //
31  // <http://www.gnu.org/licenses/>. //
32  // ////////////////////////////////////////////////////////////////////////
33  @endverbatim */
34 
35 
36 #ifndef INCLUDE_NRT_CORE_IMAGE_DETAILS_IMAGESETIMPL_H
37 #define INCLUDE_NRT_CORE_IMAGE_DETAILS_IMAGESETIMPL_H
38 
40 
41 // ######################################################################
42 template <class T> inline
43 nrt::ImageSet<T>::ImageSet(size_t const n) : itsLevels(new std::deque< Image<T> >(n))
44 { }
45 
46 // ######################################################################
47 template <class T> inline
48 nrt::ImageSet<T>::ImageSet(size_t const n, nrt::Dims<nrt::int32> const & dims, nrt::ImageInitPolicy const init) :
49  itsLevels(new std::deque< Image<T> >(n, nrt::Image<T>(dims, init)))
50 { }
51 
52 // ######################################################################
53 template <class T> template <class TT> inline
55  itsLevels(new std::deque<Image<T>>())
56 {
57  for (size_t i = 0; i < iset.size(); ++i)
58  itsLevels->push_back(nrt::Image<T>(iset.at(i)));
59 }
60 
61 // ######################################################################
62 template <class T> template <class TT> inline
64 {
65  itsLevels->clear();
66  for (size_t i = 0; i < iset.size(); ++i) itsLevels->push_back(nrt::Image<T>(iset.at(i)));
67  return *this;
68 }
69 
70 // ######################################################################
71 template <class T> inline
73 {
74  this->itsLevels->swap(*that->itsLevels);
75 }
76 
77 // ######################################################################
78 template <class T> inline
80 {
81  // Reset to an empty vector of given size by swapping with a temp vector
82  std::deque< Image<T> >(itsLevels->size()).swap(*itsLevels);
83 }
84 
85 // ######################################################################
86 template <class T> inline
87 void nrt::ImageSet<T>::reset(size_t const newDepth)
88 {
89  // Reset to an empty vector of given size by swapping with a temp vector
90  std::deque< Image<T> >(newDepth).swap(*itsLevels);
91 }
92 
93 // ######################################################################
94 template <class T> inline
95 size_t nrt::ImageSet<T>::size() const
96 { return itsLevels->size(); }
97 
98 // ######################################################################
99 template <class T> inline
100 nrt::Image<T> const nrt::ImageSet<T>::at(size_t const lev) const
101 {
102  if (lev >= itsLevels->size()) throw nrt::exception::OutOfBoundsImageSetException(lev, itsLevels->size());
103  return (*itsLevels)[lev];
104 }
105 
106 // ######################################################################
107 template <class T> inline
109 {
110  if (lev >= itsLevels->size()) throw nrt::exception::OutOfBoundsImageSetException(lev, itsLevels->size());
111  return (*itsLevels)[lev];
112 }
113 
114 // ######################################################################
115 template <class T> inline
117 {
118  itsLevels->push_back(img);
119 }
120 
121 // ######################################################################
122 template <class T> inline
124 {
125  itsLevels->push_front(img);
126 }
127 
128 // ######################################################################
129 template <class T> inline
131 {
132  if (itsLevels->empty()) throw nrt::exception::OutOfBoundsImageSetException(1, 0);
133  itsLevels->pop_back();
134 }
135 
136 // ######################################################################
137 template <class T> inline
139 {
140  if (itsLevels->empty()) throw nrt::exception::OutOfBoundsImageSetException(1, 0);
141  itsLevels->pop_front();
142 }
143 
144 // ######################################################################
145 template <class T> inline
147 {
148  if (itsLevels->empty()) throw nrt::exception::OutOfBoundsImageSetException(1, 0);
149  return itsLevels->front();
150 }
151 
152 // ######################################################################
153 template <class T> inline
155 {
156  if (itsLevels->empty()) throw nrt::exception::OutOfBoundsImageSetException(1, 0);
157  return itsLevels->back();
158 }
159 
160 // ######################################################################
161 template <class T> inline
163 {
164  for (uint i = 0; i < itsLevels->size(); ++i) if ((*itsLevels)[i].size()) return false;
165 
166  return true;
167 }
168 
169 // ######################################################################
170 template <class T> inline
171 nrt::ImageSet<T> nrt::ImageSet<T>::subset(size_t const a, size_t const b) const
172 {
173  size_t aa = a, bb = b; if (aa > bb) { aa = b; bb = a; }
174 
175  if (bb > itsLevels->size()) throw nrt::exception::OutOfBoundsImageSetException(b, itsLevels->size());
176 
177  ImageSet<T> result(bb - aa);
178  for (uint i = aa; i < bb; ++i) (*result.itsLevels)[i - aa] = (*this->itsLevels)[i];
179 
180  return result;
181 }
182 
183 // ######################################################################
184 template <class T> inline
186 { return itsLevels->begin(); }
187 
188 // ######################################################################
189 template <class T> inline
191 { return itsLevels->end(); }
192 
193 // ######################################################################
194 template <class T> inline
196 { return itsLevels->begin(); }
197 
198 // ######################################################################
199 template <class T> inline
201 { return itsLevels->end(); }
202 
203 #endif // INCLUDE_NRT_CORE_IMAGE_DETAILS_IMAGESETIMPL_H
204