60 Grid3D(
unsigned int dim1,
unsigned int dim2,
unsigned int dim3) :
61 dim1_(dim1), dim2_(dim2), dim3_(dim3) {
62 data_.resize(dim1_ * dim2_ * dim3_);
65 Elem& operator()(
unsigned int i,
unsigned int j,
unsigned int k) {
66 int index = isValidGrid(i, j, k);
71 const Elem& operator()(
unsigned int i,
unsigned int j,
72 unsigned int k)
const {
73 int index = isValidGrid(i, j, k);
78 std::vector<Elem> getAllNeighbors(
unsigned int i,
unsigned int j,
80 std::vector<Elem> result;
82 index = isValidGrid(i - 1, j, k);
83 if (index != -1) result.push_back(data_[index]);
85 index = isValidGrid(i + 1, j, k);
86 if (index != -1) result.push_back(data_[index]);
88 index = isValidGrid(i, j - 1, k);
89 if (index != -1) result.push_back(data_[index]);
91 index = isValidGrid(i, j + 1, k);
92 if (index != -1) result.push_back(data_[index]);
94 index = isValidGrid(i, j, k - 1);
95 if (index != -1) result.push_back(data_[index]);
97 index = isValidGrid(i, j, k + 1);
98 if (index != -1) result.push_back(data_[index]);
104 int isValidGrid(
unsigned int i,
unsigned int j,
unsigned int k)
const {
105 unsigned int index = i * dim2_ * dim3_ + j * dim3_ + k;
106 return index < data_.size() ? int(index) : -1;
112 std::vector<Elem> data_;