PetaVision  Alpha
Buffer.hpp
1 #ifndef __BUFFER_HPP__
2 #define __BUFFER_HPP__
3 
4 #include <vector>
5 
6 namespace PV {
7 
8 template <class T>
9 class Buffer {
10  public:
11  enum Anchor { CENTER, NORTH, NORTHEAST, EAST, SOUTHEAST, SOUTH, SOUTHWEST, WEST, NORTHWEST };
12 
13  Buffer(int width, int height, int features);
14  Buffer();
15  Buffer(const std::vector<T> &data, int width, int height, int features);
16  Buffer(const T *data, int width, int height, int features);
17  T const at(int x, int y, int feature) const;
18  T const at(int k) const;
19  void set(int x, int y, int feature, T value);
20  void set(int k, T value);
21  void set(const std::vector<T> &vector, int width, int height, int features);
22  void set(const T *data, int width, int height, int features);
23  void set(Buffer<T> other);
24  void resize(int width, int height, int features);
25  void crop(int newWidth, int newHeight, enum Anchor anchor);
26  void grow(int newWidth, int newHeight, enum Anchor anchor);
27  void translate(int offsetX, int offsetY);
28  void flip(bool xFlip, bool yFlip);
29  std::vector<T> asVector() const { return mData; }
30  int getHeight() const { return mHeight; }
31  int getWidth() const { return mWidth; }
32  int getFeatures() const { return mFeatures; }
33  int getTotalElements() const { return mHeight * mWidth * mFeatures; }
34 
35  protected:
36  static int getAnchorX(enum Anchor anchor, int smallerWidth, int biggerWidth);
37  static int getAnchorY(enum Anchor anchor, int smallerHeight, int biggerHeight);
38  inline int index(int x, int y, int f) const { return f + (x + y * mWidth) * mFeatures; }
39 
40  std::vector<T> mData;
41  int mWidth = 0;
42  int mHeight = 0;
43  int mFeatures = 0;
44 }; // end class Buffer
45 
46 } // end namespace PV
47 
48 #include "Buffer.tpp" // template implementations file
49 
50 #endif