Fleet  0.0.9
Inference in the LOT
Vector3D.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <vector>
4 
12 template<typename T>
13 struct Vector3D {
14  int xsize = 0;
15  int ysize = 0;
16  int zsize = 0;
17  std::vector<T> value;
18 
19  Vector3D() { }
20 
21  Vector3D(int x, int y, int z) {
22  resize(x,y,z);
23  }
24 
25  Vector3D(int x, int y, int z, T b) {
26  resize(x,y,z);
27  fill(b);
28  }
29 
30 
31  void fill(T x){
32  std::fill(value.begin(), value.end(), x);
33  }
34 
35  void resize(const int x, const int y, const int z) {
36  xsize = x; ysize=y; zsize=z;
37  value.resize(x*y*z);
38  }
39 
40  void reserve(const int x, const int y, const int z) {
41  xsize = x; ysize=y; zsize=z;
42  value.reserve(x*y*z);
43  }
44 
45  T& at(const int x, const int y, const int z) {
46  return value.at((x*ysize + y)*zsize + z);
47  }
48 
49  T& operator()(const int x, const int y, const int z) {
50  // NOTE: this indexing makes iteration over z the fastest
51  return value.at((x*ysize + y)*zsize + z);
52  }
53 
54  template<typename X>
55  void operator[](X x) {
56  assert(false && "**** Cannot use [] with Vector2d, use .at()");
57  }
58 };
void reserve(const int x, const int y, const int z)
Definition: Vector3D.h:40
Vector3D()
Definition: Vector3D.h:19
Vector3D(int x, int y, int z)
Definition: Vector3D.h:21
T & at(const int x, const int y, const int z)
Definition: Vector3D.h:45
T & operator()(const int x, const int y, const int z)
Definition: Vector3D.h:49
int ysize
Definition: Vector3D.h:15
int zsize
Definition: Vector3D.h:16
Like Vector2D, but one dimension bigger. TODO: Replace this and Vector2D with a template please...
Definition: Vector3D.h:13
void fill(T x)
Definition: Vector3D.h:31
Vector3D(int x, int y, int z, T b)
Definition: Vector3D.h:25
std::vector< T > value
Definition: Vector3D.h:17
int xsize
Definition: Vector3D.h:14
void operator[](X x)
Definition: Vector3D.h:55
void resize(const int x, const int y, const int z)
Definition: Vector3D.h:35