iLab Neuromorphic Robotics Toolkit  0.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ImageSet.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_IMAGESET_H
37 #define INCLUDE_NRT_CORE_IMAGE_IMAGESET_H
38 
39 #include <nrt/Core/Image/Image.H>
41 #include <nrt/External/cereal/cereal.hpp>
42 
43 #include <deque>
44 
45 #include <nrt/External/cereal/access.hpp>
46 #include <nrt/External/cereal/types/deque.hpp>
47 #include <nrt/External/cereal/types/memory.hpp>
48 
49 namespace nrt
50 {
51  // ######################################################################
52  //! A set of images, often used as a dyadic pyramid
53  /*! Provides a richer interface than just an std::vector of Image.
54  \ingroup imagerel */
55  template <class T>
56  class ImageSet
57  {
58  public:
59  //! Construct with a given number of empty images.
60  ImageSet(size_t const n = 0);
61 
62  //! Construct with a given number of images of the given size.
63  ImageSet(size_t const n, Dims<int32> const & dims,
64  nrt::ImageInitPolicy const init = nrt::ImageInitPolicy::Zeros);
65 
66  //! Copy-conversion constructor
67  template <class TT> ImageSet(ImageSet<TT> const & iset);
68 
69  //! Converting assignment
70  template <class TT> ImageSet<T> & operator=(ImageSet<TT> const & iset);
71 
72  //! Swap contents with another ImageSet
73  void swap(ImageSet<T> & that);
74 
75  //! Keep the same number of images, but make all images empty (0-by-0 size).
76  /*! This returns the ImageSet to a state where empty() is true. */
77  void clear();
78 
79  //! Reset to a new number of images, all images will be empty (0-by-0 size).
80  void reset(size_t const newDepth = 0);
81 
82  //! Return number of images in image set.
83  size_t size() const;
84 
85  //! Get image from a given level
86  Image<T> const at(size_t const lev) const;
87 
88  //! Get mutable image from a given level
89  /*! If you modify the returned image, it will affect the contents of the ImageSet, i.e., the Image stored in the
90  set will be modified. */
91  Image<T> & operator()(size_t const lev);
92 
93  //! push an image to the back of the set
94  void push_back(Image<T> const img);
95 
96  //! push an image to the front of the set
97  void push_front(Image<T> const img);
98 
99  //! Pop off the last image in the set
100  void pop_back();
101 
102  //! Pop off the first image in the set
103  void pop_front();
104 
105  //! return the last image in the set (without popping it off)
106  Image<T> const front() const;
107 
108  //! return the first image in the set (without popping it off)
109  Image<T> const back() const;
110 
111  //! Return true if the pyramid has no non-empty images (width*height > 0).
112  bool empty() const;
113 
114  //! Return a new ImageSet with images in the half-open range [a,b[
115  ImageSet<T> subset(size_t const a, size_t const b) const;
116 
117  //! Iterator over the images in the set
118  typedef typename std::deque< Image<T> >::iterator iterator;
119 
120  //! Iterator to the first image
121  iterator begin();
122 
123  //! Iterator to one past the last image
124  iterator end();
125 
126  //! Constant iterator over the images in the set
127  typedef typename std::deque< Image<T> >::const_iterator const_iterator;
128 
129  //! Constant iterator to the first image
130  const_iterator begin() const;
131 
132  //! Constant iterator to one past the last image
133  const_iterator end() const;
134 
135  private:
136  std::shared_ptr<std::deque< Image<T> > > itsLevels;
137 
138  friend class cereal::access;
139  template<class Archive> void serialize(Archive & ar)
140  {
141  ar( itsLevels );
142  }
143  };
144 
145 } // namespace nrt
146 
148 
149 #endif // INCLUDE_NRT_CORE_IMAGE_IMAGESET_H