GteImage3.h
Go to the documentation of this file.
1 // David Eberly, Geometric Tools, Redmond WA 98052
2 // Copyright (c) 1998-2017
3 // Distributed under the Boost Software License, Version 1.0.
4 // http://www.boost.org/LICENSE_1_0.txt
5 // http://www.geometrictools.com/License/Boost/LICENSE_1_0.txt
6 // File Version: 3.0.0 (2016/06/19)
7 
8 #pragma once
9 
10 #include <Imagics/GteImage.h>
11 #include <array>
12 
13 namespace gte
14 {
15 
16 template <typename PixelType>
17 class Image3 : public Image<PixelType>
18 {
19 public:
20  // Construction and destruction. The last constructor must have positive
21  // dimensions; otherwise, the image is empty.
22  virtual ~Image3();
23  Image3();
24  Image3(int dimension0, int dimension1, int dimension2);
25 
26  // Support for copy semantics.
27  Image3(Image3 const& image);
28  Image3& operator= (Image3 const& image);
29 
30  // Support for move semantics.
31  Image3(Image3&& image);
32  Image3& operator= (Image3&& image);
33 
34  // Support for changing the image dimensions. All pixel data is lost by
35  // this operation.
36  void Reconstruct(int dimension0, int dimension1, int dimension2);
37 
38  // Conversion between 1-dimensional indices and 3-dimensional coordinates.
39  inline size_t GetIndex(int x, int y, int z) const;
40  inline size_t GetIndex(std::array<int, 3> const& coord) const;
41  inline void GetCoordinates(size_t index, int& x, int& y, int& z) const;
42  inline std::array<int, 3> GetCoordinates(size_t index) const;
43 
44  // Access the data as a 3-dimensional array. The operator() functions
45  // test for valid (x,y,z) when iterator checking is enabled and assert on
46  // invalid (x,y,z). The Get() functions test for valid (x,y,z) and clamp
47  // when invalid; these functions cannot fail.
48  inline PixelType& operator() (int x, int y, int z);
49  inline PixelType const& operator() (int x, int y, int z) const;
50  inline PixelType& operator() (std::array<int, 3> const& coord);
51  inline PixelType const& operator() (std::array<int,3> const& coord) const;
52  inline PixelType& Get(int x, int y, int z);
53  inline PixelType const& Get(int x, int y, int z) const;
54  inline PixelType& Get(std::array<int, 3> coord);
55  inline PixelType const& Get(std::array<int, 3> coord) const;
56 
57  // In the following discussion, u, v and w are in {-1,1}. Given a voxel
58  // (x,y,z), the 6-connected neighbors have relative offsets (u,0,0),
59  // (0,v,0), and (0,0,w). The 18-connected neighbors include the
60  // 6-connected neighbors and have additional relative offsets (u,v,0),
61  // (u,0,w), and (0,v,w). The 26-connected neighbors include the
62  // 18-connected neighbors and have additional relative offsets (u,v,w).
63  // The corner neighbors have offsets (0,0,0), (1,0,0), (0,1,0), (1,1,0),
64  // (0,0,1), (1,0,1), (0,1,1), and (1,1,1) in that order. The full
65  // neighborhood is the set of 3x3x3 pixels centered at (x,y).
66 
67  // The neighborhoods can be accessed as 1-dimensional indices using these
68  // functions. The first five functions provide 1-dimensional indices
69  // relative to any voxel location; these depend only on the image
70  // dimensions. The last five functions provide 1-dimensional indices
71  // for the actual voxels in the neighborhood; no clamping is used when
72  // (x,y,z) is on the boundary.
73  void GetNeighborhood(std::array<int, 6>& nbr) const;
74  void GetNeighborhood(std::array<int, 18>& nbr) const;
75  void GetNeighborhood(std::array<int, 26>& nbr) const;
76  void GetCorners(std::array<int, 8>& nbr) const;
77  void GetFull(std::array<int, 27>& nbr) const;
78  void GetNeighborhood(int x, int y, int z, std::array<size_t, 6>& nbr) const;
79  void GetNeighborhood(int x, int y, int z, std::array<size_t, 18>& nbr) const;
80  void GetNeighborhood(int x, int y, int z, std::array<size_t, 26>& nbr) const;
81  void GetCorners(int x, int y, int z, std::array<size_t, 8>& nbr) const;
82  void GetFull(int x, int y, int z, std::array<size_t, 27>& nbr) const;
83 
84  // The neighborhoods can be accessed as 3-tuples using these functions.
85  // The first five functions provide 3-tuples relative to any voxel
86  // location; these depend only on the image dimensions. The last five
87  // functions provide 3-tuples for the actual voxels in the neighborhood;
88  // no clamping is used when (x,y,z) is on the boundary.
89  void GetNeighborhood(std::array<std::array<int, 3>, 6>& nbr) const;
90  void GetNeighborhood(std::array<std::array<int, 3>, 18>& nbr) const;
91  void GetNeighborhood(std::array<std::array<int, 3>, 26>& nbr) const;
92  void GetCorners(std::array<std::array<int, 3>, 8>& nbr) const;
93  void GetFull(std::array<std::array<int, 3>, 27>& nbr) const;
94  void GetNeighborhood(int x, int y, int z, std::array<std::array<size_t, 3>, 6>& nbr) const;
95  void GetNeighborhood(int x, int y, int z, std::array<std::array<size_t, 3>, 18>& nbr) const;
96  void GetNeighborhood(int x, int y, int z, std::array<std::array<size_t, 3>, 26>& nbr) const;
97  void GetCorners(int x, int y, int z, std::array<std::array<size_t, 3>, 8>& nbr) const;
98  void GetFull(int x, int y, int z, std::array<std::array<size_t, 3>, 27>& nbr) const;
99 };
100 
101 
102 template <typename PixelType>
104 {
105 }
106 
107 template <typename PixelType>
109 {
110 }
111 
112 template <typename PixelType>
113 Image3<PixelType>::Image3(int dimension0, int dimension1, int dimension2)
114  :
115  Image<PixelType>(std::vector<int>{ dimension0, dimension1, dimension2 })
116 {
117 }
118 
119 template <typename PixelType>
121  :
122  Image<PixelType>(image)
123 {
124 }
125 
126 template <typename PixelType>
128 {
130  return *this;
131 }
132 
133 template <typename PixelType>
135 {
136  *this = std::move(image);
137 }
138 
139 template <typename PixelType>
141 {
143  return *this;
144 }
145 
146 template <typename PixelType>
147 void Image3<PixelType>::Reconstruct(int dimension0, int dimension1, int dimension2)
148 {
149  Image<PixelType>::Reconstruct(std::vector<int>{ dimension0, dimension1, dimension2 });
150 }
151 
152 template <typename PixelType> inline
153 size_t Image3<PixelType>::GetIndex(int x, int y, int z) const
154 {
155 #if defined(GTE_IMAGICS_ASSERT_ON_INVALID_INDEX)
156  if (0 <= x && x < this->mDimensions[0]
157  && 0 <= y && y < this->mDimensions[1]
158  && 0 <= z && z < this->mDimensions[2])
159  {
160  return static_cast<size_t>(x) +
161  static_cast<size_t>(this->mDimensions[0]) * (static_cast<size_t>(y) +
162  static_cast<size_t>(this->mDimensions[1]) * static_cast<size_t>(z));
163  }
164  LogError("Invalid coordinates (" + std::to_string(x) + "," +
165  std::to_string(y) + "," + std::to_string(z) + ").");
166  return 0;
167 #else
168  return static_cast<size_t>(x) +
169  static_cast<size_t>(this->mDimensions[0]) * (static_cast<size_t>(y) +
170  static_cast<size_t>(this->mDimensions[1]) * static_cast<size_t>(z));
171 #endif
172 }
173 
174 template <typename PixelType> inline
175 size_t Image3<PixelType>::GetIndex(std::array<int, 3> const& coord) const
176 {
177 #if defined(GTE_IMAGICS_ASSERT_ON_INVALID_INDEX)
178  if (0 <= coord[0] && coord[0] < this->mDimensions[0]
179  && 0 <= coord[1] && coord[1] < this->mDimensions[1]
180  && 0 <= coord[2] && coord[2] < this->mDimensions[2])
181  {
182  return static_cast<size_t>(coord[0]) +
183  static_cast<size_t>(this->mDimensions[0]) * (static_cast<size_t>(coord[1]) +
184  static_cast<size_t>(this->mDimensions[1]) * static_cast<size_t>(coord[2]));
185  }
186  LogError("Invalid coordinates (" + std::to_string(coord[0]) + "," +
187  std::to_string(coord[1]) + "," + std::to_string(coord[2]) + ").");
188  return 0;
189 #else
190  return static_cast<size_t>(coord[0]) +
191  static_cast<size_t>(this->mDimensions[0]) * (static_cast<size_t>(coord[1]) +
192  static_cast<size_t>(this->mDimensions[1]) * static_cast<size_t>(coord[2]));
193 #endif
194 }
195 
196 template <typename PixelType> inline
197 void Image3<PixelType>::GetCoordinates(size_t index, int& x, int& y, int& z) const
198 {
199 #if defined(GTE_IMAGICS_ASSERT_ON_INVALID_INDEX)
200  if (index < mNumPixels)
201  {
202  x = static_cast<int>(index % this->mDimensions[0]);
203  index /= this->mDimensions[0];
204  y = static_cast<int>(index % this->mDimensions[1]);
205  z = static_cast<int>(index / this->mDimensions[1]);
206  }
207  else
208  {
209  LogError("Invalid index " + std::to_string(index) + ".");
210  x = 0;
211  y = 0;
212  z = 0;
213  }
214 #else
215  x = static_cast<int>(index % this->mDimensions[0]);
216  index /= this->mDimensions[0];
217  y = static_cast<int>(index % this->mDimensions[1]);
218  z = static_cast<int>(index / this->mDimensions[1]);
219 #endif
220 }
221 
222 template <typename PixelType> inline
223 std::array<int, 3> Image3<PixelType>::GetCoordinates(size_t index) const
224 {
225  std::array<int, 3> coord;
226 #if defined(GTE_IMAGICS_ASSERT_ON_INVALID_INDEX)
227  if (index < mNumPixels)
228  {
229  coord[0] = static_cast<int>(index % this->mDimensions[0]);
230  index /= this->mDimensions[0];
231  coord[1] = static_cast<int>(index % this->mDimensions[1]);
232  coord[2] = static_cast<int>(index / this->mDimensions[1]);
233  }
234  else
235  {
236  LogError("Invalid index " + std::to_string(index) + ".");
237  coord[0] = 0;
238  coord[1] = 0;
239  coord[2] = 0;
240  }
241 #else
242  coord[0] = static_cast<int>(index % this->mDimensions[0]);
243  index /= this->mDimensions[0];
244  coord[1] = static_cast<int>(index % this->mDimensions[1]);
245  coord[2] = static_cast<int>(index / this->mDimensions[1]);
246 #endif
247  return coord;
248 }
249 
250 template <typename PixelType> inline
251 PixelType& Image3<PixelType>::operator() (int x, int y, int z)
252 {
253 #if defined(GTE_IMAGICS_ASSERT_ON_INVALID_INDEX)
254  if (0 <= x && x < this->mDimensions[0]
255  && 0 <= y && y < this->mDimensions[1]
256  && 0 <= z && z < this->mDimensions[2])
257  {
258  size_t i = static_cast<size_t>(x) +
259  static_cast<size_t>(this->mDimensions[0]) * (static_cast<size_t>(y) +
260  static_cast<size_t>(this->mDimensions[1]) * static_cast<size_t>(z));
261  return this->mPixels[i];
262  }
263  LogError("Invalid coordinates (" + std::to_string(x) + "," +
264  std::to_string(y) + "," + std::to_string(z) + ").");
265  return this->mPixels[0];
266 #else
267  size_t i = static_cast<size_t>(x) +
268  static_cast<size_t>(this->mDimensions[0]) * (static_cast<size_t>(y) +
269  static_cast<size_t>(this->mDimensions[1]) * static_cast<size_t>(z));
270  return this->mPixels[i];
271 #endif
272 }
273 
274 template <typename PixelType> inline
275 PixelType const& Image3<PixelType>::operator() (int x, int y, int z) const
276 {
277 #if defined(GTE_IMAGICS_ASSERT_ON_INVALID_INDEX)
278  if (0 <= x && x < this->mDimensions[0]
279  && 0 <= y && y < this->mDimensions[1]
280  && 0 <= z && z < this->mDimensions[2])
281  {
282  size_t i = static_cast<size_t>(x) +
283  static_cast<size_t>(this->mDimensions[0]) * (static_cast<size_t>(y) +
284  static_cast<size_t>(this->mDimensions[1]) * static_cast<size_t>(z));
285  return this->mPixels[i];
286  }
287  LogError("Invalid coordinates (" + std::to_string(x) + "," +
288  std::to_string(y) + "," + std::to_string(z) + ").");
289  return this->mPixels[0];
290 #else
291  size_t i = static_cast<size_t>(x) +
292  static_cast<size_t>(this->mDimensions[0]) * (static_cast<size_t>(y) +
293  static_cast<size_t>(this->mDimensions[1]) * static_cast<size_t>(z));
294  return this->mPixels[i];
295 #endif
296 }
297 
298 template <typename PixelType> inline
299 PixelType& Image3<PixelType>::operator() (std::array<int, 3> const& coord)
300 {
301 #if defined(GTE_IMAGICS_ASSERT_ON_INVALID_INDEX)
302  if (0 <= coord[0] && coord[0] < this->mDimensions[0]
303  && 0 <= coord[1] && coord[1] < this->mDimensions[1]
304  && 0 <= coord[2] && coord[2] < this->mDimensions[2])
305  {
306  size_t i = static_cast<size_t>(coord[0]) +
307  static_cast<size_t>(this->mDimensions[0]) * (static_cast<size_t>(coord[1]) +
308  static_cast<size_t>(this->mDimensions[1]) * static_cast<size_t>(coord[2]));
309  return this->mPixels[i];
310  }
311  LogError("Invalid coordinates (" + std::to_string(coord[0]) + "," +
312  std::to_string(coord[1]) + "," + std::to_string(coord[2]) + ").");
313  return mPixel[0];
314 #else
315  size_t i = static_cast<size_t>(coord[0]) +
316  static_cast<size_t>(this->mDimensions[0]) * (static_cast<size_t>(coord[1]) +
317  static_cast<size_t>(this->mDimensions[1] * coord[2]));
318  return this->mPixels[i];
319 #endif
320 }
321 
322 template <typename PixelType> inline
323 PixelType const& Image3<PixelType>::operator() (std::array<int, 3> const& coord) const
324 {
325 #if defined(GTE_IMAGICS_ASSERT_ON_INVALID_INDEX)
326  if (0 <= coord[0] && coord[0] < this->mDimensions[0]
327  && 0 <= coord[1] && coord[1] < this->mDimensions[1]
328  && 0 <= coord[2] && coord[2] < this->mDimensions[2])
329  {
330  size_t i = static_cast<size_t>(coord[0]) +
331  static_cast<size_t>(this->mDimensions[0]) * (static_cast<size_t>(coord[1]) +
332  static_cast<size_t>(this->mDimensions[1]) * static_cast<size_t>(coord[2]));
333  return this->mPixels[i];
334  }
335  LogError("Invalid coordinates (" + std::to_string(coord[0]) + "," +
336  std::to_string(coord[1]) + "," + std::to_string(coord[2]) + ").");
337  return mPixel[0];
338 #else
339  size_t i = static_cast<size_t>(coord[0]) +
340  static_cast<size_t>(this->mDimensions[0]) * (static_cast<size_t>(coord[1]) +
341  static_cast<size_t>(this->mDimensions[1] * coord[2]));
342  return this->mPixels[i];
343 #endif
344 }
345 
346 template <typename PixelType>
347 PixelType& Image3<PixelType>::Get(int x, int y, int z)
348 {
349  // Clamp to valid (x,y,z).
350  if (x < 0)
351  {
352  x = 0;
353  }
354  else if (x >= this->mDimensions[0])
355  {
356  x = this->mDimensions[0] - 1;
357  }
358 
359  if (y < 0)
360  {
361  y = 0;
362  }
363  else if (y >= this->mDimensions[1])
364  {
365  y = this->mDimensions[1] - 1;
366  }
367 
368  if (z < 0)
369  {
370  z = 0;
371  }
372  else if (z >= this->mDimensions[2])
373  {
374  z = this->mDimensions[2] - 1;
375  }
376 
377  size_t i = static_cast<size_t>(x) +
378  static_cast<size_t>(this->mDimensions[0]) * (static_cast<size_t>(y) +
379  static_cast<size_t>(this->mDimensions[1]) * static_cast<size_t>(z));
380  return this->mPixels[i];
381 }
382 
383 template <typename PixelType>
384 PixelType const& Image3<PixelType>::Get(int x, int y, int z) const
385 {
386  // Clamp to valid (x,y,z).
387  if (x < 0)
388  {
389  x = 0;
390  }
391  else if (x >= this->mDimensions[0])
392  {
393  x = this->mDimensions[0] - 1;
394  }
395 
396  if (y < 0)
397  {
398  y = 0;
399  }
400  else if (y >= this->mDimensions[1])
401  {
402  y = this->mDimensions[1] - 1;
403  }
404 
405  if (z < 0)
406  {
407  z = 0;
408  }
409  else if (z >= this->mDimensions[2])
410  {
411  z = this->mDimensions[2] - 1;
412  }
413 
414  size_t i = static_cast<size_t>(x) +
415  static_cast<size_t>(this->mDimensions[0]) * (static_cast<size_t>(y) +
416  static_cast<size_t>(this->mDimensions[1]) * static_cast<size_t>(z));
417  return this->mPixels[i];
418 }
419 
420 template <typename PixelType>
421 PixelType& Image3<PixelType>::Get(std::array<int, 3> coord)
422 {
423  // Clamp to valid (x,y,z).
424  for (int d = 0; d < 3; ++d)
425  {
426  if (coord[d] < 0)
427  {
428  coord[d] = 0;
429  }
430  else if (coord[d] >= this->mDimensions[d])
431  {
432  coord[d] = this->mDimensions[d] - 1;
433  }
434  }
435 
436  size_t i = static_cast<size_t>(coord[0]) +
437  static_cast<size_t>(this->mDimensions[0]) * (static_cast<size_t>(coord[1]) +
438  static_cast<size_t>(this->mDimensions[1] * coord[2]));
439  return this->mPixels[i];
440 }
441 
442 template <typename PixelType>
443 PixelType const& Image3<PixelType>::Get(std::array<int, 3> coord) const
444 {
445  // Clamp to valid (x,y,z).
446  for (int d = 0; d < 3; ++d)
447  {
448  if (coord[d] < 0)
449  {
450  coord[d] = 0;
451  }
452  else if (coord[d] >= this->mDimensions[d])
453  {
454  coord[d] = this->mDimensions[d] - 1;
455  }
456  }
457 
458  size_t i = static_cast<size_t>(coord[0]) +
459  static_cast<size_t>(this->mDimensions[0]) * (static_cast<size_t>(coord[1]) +
460  static_cast<size_t>(this->mDimensions[1] * coord[2]));
461  return this->mPixels[i];
462 }
463 
464 template <typename PixelType>
465 void Image3<PixelType>::GetNeighborhood(std::array<int, 6>& nbr) const
466 {
467  int dim0 = this->mDimensions[0];
468  int dim01 = this->mDimensions[0] * this->mDimensions[1];
469  nbr[0] = -1; // (x-1,y,z)
470  nbr[1] = +1; // (x+1,y,z)
471  nbr[2] = -dim0; // (x,y-1,z)
472  nbr[3] = +dim0; // (x,y+1,z)
473  nbr[4] = -dim01; // (x,y,z-1)
474  nbr[5] = +dim01; // (x,y,z+1)
475 }
476 
477 template <typename PixelType>
478 void Image3<PixelType>::GetNeighborhood(std::array<int, 18>& nbr) const
479 {
480  int dim0 = this->mDimensions[0];
481  int dim01 = this->mDimensions[0] * this->mDimensions[1];
482  nbr[0] = -1; // (x-1,y,z)
483  nbr[1] = +1; // (x+1,y,z)
484  nbr[2] = -dim0; // (x,y-1,z)
485  nbr[3] = +dim0; // (x,y+1,z)
486  nbr[4] = -dim01; // (x,y,z-1)
487  nbr[5] = +dim01; // (x,y,z+1)
488  nbr[6] = -1 - dim0; // (x-1,y-1,z)
489  nbr[7] = +1 - dim0; // (x+1,y-1,z)
490  nbr[8] = -1 + dim0; // (x-1,y+1,z)
491  nbr[9] = +1 + dim0; // (x+1,y+1,z)
492  nbr[10] = -1 + dim01; // (x-1,y,z+1)
493  nbr[11] = +1 + dim01; // (x+1,y,z+1)
494  nbr[12] = -dim0 + dim01; // (x,y-1,z+1)
495  nbr[13] = +dim0 + dim01; // (x,y+1,z+1)
496  nbr[14] = -1 - dim01; // (x-1,y,z-1)
497  nbr[15] = +1 - dim01; // (x+1,y,z-1)
498  nbr[16] = -dim0 - dim01; // (x,y-1,z-1)
499  nbr[17] = +dim0 - dim01; // (x,y+1,z-1)
500 }
501 
502 template <typename PixelType>
503 void Image3<PixelType>::GetNeighborhood(std::array<int, 26>& nbr) const
504 {
505  int dim0 = this->mDimensions[0];
506  int dim01 = this->mDimensions[0] * this->mDimensions[1];
507  nbr[0] = -1; // (x-1,y,z)
508  nbr[1] = +1; // (x+1,y,z)
509  nbr[2] = -dim0; // (x,y-1,z)
510  nbr[3] = +dim0; // (x,y+1,z)
511  nbr[4] = -dim01; // (x,y,z-1)
512  nbr[5] = +dim01; // (x,y,z+1)
513  nbr[6] = -1 - dim0; // (x-1,y-1,z)
514  nbr[7] = +1 - dim0; // (x+1,y-1,z)
515  nbr[8] = -1 + dim0; // (x-1,y+1,z)
516  nbr[9] = +1 + dim0; // (x+1,y+1,z)
517  nbr[10] = -1 + dim01; // (x-1,y,z+1)
518  nbr[11] = +1 + dim01; // (x+1,y,z+1)
519  nbr[12] = -dim0 + dim01; // (x,y-1,z+1)
520  nbr[13] = +dim0 + dim01; // (x,y+1,z+1)
521  nbr[14] = -1 - dim01; // (x-1,y,z-1)
522  nbr[15] = +1 - dim01; // (x+1,y,z-1)
523  nbr[16] = -dim0 - dim01; // (x,y-1,z-1)
524  nbr[17] = +dim0 - dim01; // (x,y+1,z-1)
525  nbr[18] = -1 - dim0 - dim01; // (x-1,y-1,z-1)
526  nbr[19] = +1 - dim0 - dim01; // (x+1,y-1,z-1)
527  nbr[20] = -1 + dim0 - dim01; // (x-1,y+1,z-1)
528  nbr[21] = +1 + dim0 - dim01; // (x+1,y+1,z-1)
529  nbr[22] = -1 - dim0 + dim01; // (x-1,y-1,z+1)
530  nbr[23] = +1 - dim0 + dim01; // (x+1,y-1,z+1)
531  nbr[24] = -1 + dim0 + dim01; // (x-1,y+1,z+1)
532  nbr[25] = +1 + dim0 + dim01; // (x+1,y+1,z+1)
533 }
534 
535 template <typename PixelType>
536 void Image3<PixelType>::GetCorners(std::array<int, 8>& nbr) const
537 {
538  int dim0 = this->mDimensions[0];
539  int dim01 = this->mDimensions[0] * this->mDimensions[1];
540  nbr[0] = 0; // (x,y,z)
541  nbr[1] = 1; // (x+1,y,z)
542  nbr[2] = dim0; // (x,y+1,z)
543  nbr[3] = dim0 + 1; // (x+1,y+1,z)
544  nbr[4] = dim01; // (x,y,z+1)
545  nbr[5] = dim01 + 1; // (x+1,y,z+1)
546  nbr[6] = dim01 + dim0; // (x,y+1,z+1)
547  nbr[7] = dim01 + dim0 + 1; // (x+1,y+1,z+1)
548 }
549 
550 template <typename PixelType>
551 void Image3<PixelType>::GetFull(std::array<int, 27>& nbr) const
552 {
553  int dim0 = this->mDimensions[0];
554  int dim01 = this->mDimensions[0] * this->mDimensions[1];
555  nbr[0] = -1 - dim0 - dim01; // (x-1,y-1,z-1)
556  nbr[1] = -dim0 - dim01; // (x, y-1,z-1)
557  nbr[2] = +1 - dim0 - dim01; // (x+1,y-1,z-1)
558  nbr[3] = -1 - dim01; // (x-1,y, z-1)
559  nbr[4] = -dim01; // (x, y, z-1)
560  nbr[5] = +1 - dim01; // (x+1,y, z-1)
561  nbr[6] = -1 + dim0 - dim01; // (x-1,y+1,z-1)
562  nbr[7] = +dim0 - dim01; // (x, y+1,z-1)
563  nbr[8] = +1 + dim0 - dim01; // (x+1,y+1,z-1)
564  nbr[9] = -1 - dim0; // (x-1,y-1,z)
565  nbr[10] = -dim0; // (x, y-1,z)
566  nbr[11] = +1 - dim0; // (x+1,y-1,z)
567  nbr[12] = -1; // (x-1,y, z)
568  nbr[13] = 0; // (x, y, z)
569  nbr[14] = +1; // (x+1,y, z)
570  nbr[15] = -1 + dim0; // (x-1,y+1,z)
571  nbr[16] = +dim0; // (x, y+1,z)
572  nbr[17] = +1 + dim0; // (x+1,y+1,z)
573  nbr[18] = -1 - dim0 + dim01; // (x-1,y-1,z+1)
574  nbr[19] = -dim0 + dim01; // (x, y-1,z+1)
575  nbr[20] = +1 - dim0 + dim01; // (x+1,y-1,z+1)
576  nbr[21] = -1 + dim01; // (x-1,y, z+1)
577  nbr[22] = +dim01; // (x, y, z+1)
578  nbr[23] = +1 + dim01; // (x+1,y, z+1)
579  nbr[24] = -1 + dim0 + dim01; // (x-1,y+1,z+1)
580  nbr[25] = +dim0 + dim01; // (x, y+1,z+1)
581  nbr[26] = +1 + dim0 + dim01; // (x+1,y+1,z+1)
582 }
583 
584 template <typename PixelType>
585 void Image3<PixelType>::GetNeighborhood(int x, int y, int z, std::array<size_t, 6>& nbr) const
586 {
587  size_t index = GetIndex(x, y, z);
588  std::array<int, 6> inbr;
589  GetNeighborhood(inbr);
590  for (int i = 0; i < 6; ++i)
591  {
592  nbr[i] = index + inbr[i];
593  }
594 }
595 
596 template <typename PixelType>
597 void Image3<PixelType>::GetNeighborhood(int x, int y, int z, std::array<size_t, 18>& nbr) const
598 {
599  size_t index = GetIndex(x, y, z);
600  std::array<int, 18> inbr;
601  GetNeighborhood(inbr);
602  for (int i = 0; i < 18; ++i)
603  {
604  nbr[i] = index + inbr[i];
605  }
606 }
607 
608 template <typename PixelType>
609 void Image3<PixelType>::GetNeighborhood(int x, int y, int z, std::array<size_t, 26>& nbr) const
610 {
611  size_t index = GetIndex(x, y, z);
612  std::array<int, 26> inbr;
613  GetNeighborhood(inbr);
614  for (int i = 0; i < 26; ++i)
615  {
616  nbr[i] = index + inbr[i];
617  }
618 }
619 
620 template <typename PixelType>
621 void Image3<PixelType>::GetCorners(int x, int y, int z, std::array<size_t, 8>& nbr) const
622 {
623  size_t index = GetIndex(x, y, z);
624  std::array<int, 8> inbr;
625  GetCorners(inbr);
626  for (int i = 0; i < 8; ++i)
627  {
628  nbr[i] = index + inbr[i];
629  }
630 }
631 
632 template <typename PixelType>
633 void Image3<PixelType>::GetFull(int x, int y, int z, std::array<size_t, 27>& nbr) const
634 {
635  size_t index = GetIndex(x, y, z);
636  std::array<int, 27> inbr;
637  GetFull(inbr);
638  for (int i = 0; i < 27; ++i)
639  {
640  nbr[i] = index + inbr[i];
641  }
642 }
643 
644 template <typename PixelType>
645 void Image3<PixelType>::GetNeighborhood(std::array<std::array<int, 3>, 6>& nbr) const
646 {
647  nbr[0] = { { -1, 0, 0 } };
648  nbr[1] = { { +1, 0, 0 } };
649  nbr[2] = { { 0, -1, 0 } };
650  nbr[3] = { { 0, +1, 0 } };
651  nbr[4] = { { 0, 0, -1 } };
652  nbr[5] = { { 0, 0, +1 } };
653 }
654 
655 template <typename PixelType>
656 void Image3<PixelType>::GetNeighborhood(std::array<std::array<int, 3>, 18>& nbr) const
657 {
658  nbr[0] = { { -1, 0, 0 } };
659  nbr[1] = { { +1, 0, 0 } };
660  nbr[2] = { { 0, -1, 0 } };
661  nbr[3] = { { 0, +1, 0 } };
662  nbr[4] = { { 0, 0, -1 } };
663  nbr[5] = { { 0, 0, +1 } };
664  nbr[6] = { { -1, -1, 0 } };
665  nbr[7] = { { +1, -1, 0 } };
666  nbr[8] = { { -1, +1, 0 } };
667  nbr[9] = { { +1, +1, 0 } };
668  nbr[10] = { { -1, 0, +1 } };
669  nbr[11] = { { +1, 0, +1 } };
670  nbr[12] = { { 0, -1, +1 } };
671  nbr[13] = { { 0, +1, +1 } };
672  nbr[14] = { { -1, 0, -1 } };
673  nbr[15] = { { +1, 0, -1 } };
674  nbr[16] = { { 0, -1, -1 } };
675  nbr[17] = { { 0, +1, -1 } };
676 }
677 
678 template <typename PixelType>
679 void Image3<PixelType>::GetNeighborhood(std::array<std::array<int, 3>, 26>& nbr) const
680 {
681  nbr[0] = { { -1, 0, 0 } };
682  nbr[1] = { { +1, 0, 0 } };
683  nbr[2] = { { 0, -1, 0 } };
684  nbr[3] = { { 0, +1, 0 } };
685  nbr[4] = { { 0, 0, -1 } };
686  nbr[5] = { { 0, 0, +1 } };
687  nbr[6] = { { -1, -1, 0 } };
688  nbr[7] = { { +1, -1, 0 } };
689  nbr[8] = { { -1, +1, 0 } };
690  nbr[9] = { { +1, +1, 0 } };
691  nbr[10] = { { -1, 0, +1 } };
692  nbr[11] = { { +1, 0, +1 } };
693  nbr[12] = { { 0, -1, +1 } };
694  nbr[13] = { { 0, +1, +1 } };
695  nbr[14] = { { -1, 0, -1 } };
696  nbr[15] = { { +1, 0, -1 } };
697  nbr[16] = { { 0, -1, -1 } };
698  nbr[17] = { { 0, +1, -1 } };
699  nbr[18] = { { -1, -1, -1 } };
700  nbr[19] = { { +1, -1, -1 } };
701  nbr[20] = { { -1, +1, -1 } };
702  nbr[21] = { { +1, +1, -1 } };
703  nbr[22] = { { -1, -1, +1 } };
704  nbr[23] = { { +1, -1, +1 } };
705  nbr[24] = { { -1, +1, +1 } };
706  nbr[25] = { { +1, +1, +1 } };
707 }
708 
709 template <typename PixelType>
710 void Image3<PixelType>::GetCorners(std::array<std::array<int, 3>, 8>& nbr) const
711 {
712  nbr[0] = { { 0, 0, 0 } };
713  nbr[1] = { { 1, 0, 0 } };
714  nbr[2] = { { 0, 1, 0 } };
715  nbr[3] = { { 1, 1, 0 } };
716  nbr[4] = { { 0, 0, 1 } };
717  nbr[5] = { { 1, 0, 1 } };
718  nbr[6] = { { 0, 1, 1 } };
719  nbr[7] = { { 1, 1, 1 } };
720 }
721 
722 template <typename PixelType>
723 void Image3<PixelType>::GetFull(std::array<std::array<int, 3>, 27>& nbr) const
724 {
725  nbr[0] = { { -1, -1, -1 } };
726  nbr[1] = { { 0, -1, -1 } };
727  nbr[2] = { { +1, -1, -1 } };
728  nbr[3] = { { -1, 0, -1 } };
729  nbr[4] = { { 0, 0, -1 } };
730  nbr[5] = { { +1, 0, -1 } };
731  nbr[6] = { { -1, +1, -1 } };
732  nbr[7] = { { 0, +1, -1 } };
733  nbr[8] = { { +1, +1, -1 } };
734  nbr[9] = { { -1, -1, 0 } };
735  nbr[10] = { { 0, -1, 0 } };
736  nbr[11] = { { +1, -1, 0 } };
737  nbr[12] = { { -1, 0, 0 } };
738  nbr[13] = { { 0, 0, 0 } };
739  nbr[14] = { { +1, 0, 0 } };
740  nbr[15] = { { -1, +1, 0 } };
741  nbr[16] = { { 0, +1, 0 } };
742  nbr[17] = { { +1, +1, 0 } };
743  nbr[18] = { { -1, -1, +1 } };
744  nbr[19] = { { 0, -1, +1 } };
745  nbr[20] = { { +1, -1, +1 } };
746  nbr[21] = { { -1, 0, +1 } };
747  nbr[22] = { { 0, 0, +1 } };
748  nbr[23] = { { +1, 0, +1 } };
749  nbr[24] = { { -1, +1, +1 } };
750  nbr[25] = { { 0, +1, +1 } };
751  nbr[26] = { { +1, +1, +1 } };
752 }
753 
754 template <typename PixelType>
755 void Image3<PixelType>::GetNeighborhood(int x, int y, int z, std::array<std::array<size_t, 3>, 6>& nbr) const
756 {
757  std::array<std::array<int, 3>, 6> inbr;
758  GetNeighborhood(inbr);
759  for (int i = 0; i < 6; ++i)
760  {
761  nbr[i][0] = static_cast<size_t>(x) + inbr[i][0];
762  nbr[i][1] = static_cast<size_t>(y) + inbr[i][1];
763  nbr[i][2] = static_cast<size_t>(z) + inbr[i][2];
764  }
765 }
766 
767 template <typename PixelType>
768 void Image3<PixelType>::GetNeighborhood(int x, int y, int z, std::array<std::array<size_t, 3>, 18>& nbr) const
769 {
770  std::array<std::array<int, 3>, 18> inbr;
771  GetNeighborhood(inbr);
772  for (int i = 0; i < 18; ++i)
773  {
774  nbr[i][0] = static_cast<size_t>(x) + inbr[i][0];
775  nbr[i][1] = static_cast<size_t>(y) + inbr[i][1];
776  nbr[i][2] = static_cast<size_t>(z) + inbr[i][2];
777  }
778 }
779 
780 template <typename PixelType>
781 void Image3<PixelType>::GetNeighborhood(int x, int y, int z, std::array<std::array<size_t, 3>, 26>& nbr) const
782 {
783  std::array<std::array<int, 3>, 26> inbr;
784  GetNeighborhood(inbr);
785  for (int i = 0; i < 26; ++i)
786  {
787  nbr[i][0] = static_cast<size_t>(x) + inbr[i][0];
788  nbr[i][1] = static_cast<size_t>(y) + inbr[i][1];
789  nbr[i][2] = static_cast<size_t>(z) + inbr[i][2];
790  }
791 }
792 
793 template <typename PixelType>
794 void Image3<PixelType>::GetCorners(int x, int y, int z,
795  std::array<std::array<size_t, 3>, 8>& nbr) const
796 {
797  std::array<std::array<int, 3>, 8> inbr;
798  GetCorners(inbr);
799  for (int i = 0; i < 8; ++i)
800  {
801  nbr[i][0] = static_cast<size_t>(x) + inbr[i][0];
802  nbr[i][1] = static_cast<size_t>(y) + inbr[i][1];
803  nbr[i][2] = static_cast<size_t>(z) + inbr[i][2];
804  }
805 }
806 
807 template <typename PixelType>
808 void Image3<PixelType>::GetFull(int x, int y, int z,
809  std::array<std::array<size_t, 3>, 27>& nbr) const
810 {
811  std::array<std::array<int, 3>, 27> inbr;
812  GetFull(inbr);
813  for (int i = 0; i < 27; ++i)
814  {
815  nbr[i][0] = static_cast<size_t>(x) + inbr[i][0];
816  nbr[i][1] = static_cast<size_t>(y) + inbr[i][1];
817  nbr[i][2] = static_cast<size_t>(z) + inbr[i][2];
818  }
819 }
820 
821 }
std::vector< int > mDimensions
Definition: GteImage.h:68
Image & operator=(Image const &image)
Definition: GteImage.h:97
PixelType & operator()(int x, int y, int z)
Definition: GteImage3.h:251
Image3 & operator=(Image3 const &image)
Definition: GteImage3.h:127
GLenum GLenum GLsizei void * image
Definition: glext.h:2724
GLuint coord
Definition: glext.h:5871
void GetCorners(std::array< int, 8 > &nbr) const
Definition: GteImage3.h:536
GLint GLenum GLint x
Definition: glcorearb.h:404
void Reconstruct(int dimension0, int dimension1, int dimension2)
Definition: GteImage3.h:147
virtual ~Image3()
Definition: GteImage3.h:103
void GetNeighborhood(std::array< int, 6 > &nbr) const
Definition: GteImage3.h:465
PixelType & Get(int x, int y, int z)
Definition: GteImage3.h:347
typedef int(WINAPI *PFNWGLRELEASEPBUFFERDCARBPROC)(HPBUFFERARB hPbuffer
#define LogError(message)
Definition: GteLogger.h:92
void GetCoordinates(size_t index, int &x, int &y, int &z) const
Definition: GteImage3.h:197
void Reconstruct(std::vector< int > const &dimensions)
Definition: GteImage.h:121
GLdouble GLdouble GLdouble z
Definition: glcorearb.h:843
GLenum array
Definition: glext.h:6669
GLuint index
Definition: glcorearb.h:781
std::vector< PixelType > mPixels
Definition: GteImage.h:70
void GetFull(std::array< int, 27 > &nbr) const
Definition: GteImage3.h:551
GLint y
Definition: glcorearb.h:98
size_t GetIndex(int x, int y, int z) const
Definition: GteImage3.h:153


geometric_tools_engine
Author(s): Yijiang Huang
autogenerated on Thu Jul 18 2019 04:00:00