SourceXtractorPlusPlus  0.15
Please provide a description of the project.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
HilbertCurve.h
Go to the documentation of this file.
1 
18 #ifndef _SEUTILS_HILBERTCURVE_H_
19 #define _SEUTILS_HILBERTCURVE_H_
20 
21 #include <vector>
22 
23 #include "SEUtils/Misc.h"
25 
26 namespace SourceXtractor {
27 
28 class HilbertCurve {
29 public:
30  HilbertCurve(unsigned int size) {
31  m_size = nextPowerOfTwo(size);
32  }
33 
35  std::vector<PixelCoordinate> hilbert_curve;
36  for (unsigned int i = 0; i < m_size * m_size; i++) {
37  hilbert_curve.emplace_back(get2DCoordinate(i));
38  }
39  return hilbert_curve;
40  }
41 
42  PixelCoordinate get2DCoordinate(unsigned int index) const {
43  unsigned int x = 0;
44  unsigned int y = 0;
45  for (unsigned int s=1; s<m_size; s*=2) {
46  unsigned int rx = 1 & (index >> 1);
47  unsigned int ry = 1 & (index ^ rx);
48 
49  if (ry == 0) {
50  if (rx == 1) {
51  x = s-1 - x;
52  y = s-1 - y;
53  }
54 
55  std::swap(x, y);
56  }
57 
58  x += s * rx;
59  y += s * ry;
60  index >>= 2;
61  }
62 
63  return {(int) x, (int) y};
64  }
65 
66 private:
67  unsigned int m_size;
68 };
69 
70 }
71 
72 #endif /* _SEUTILS_HILBERTCURVE_H_ */
T nextPowerOfTwo(T v)
Definition: Misc.h:26
T swap(T...args)
std::shared_ptr< DependentParameter< std::shared_ptr< EngineParameter > > > x
constexpr double s
PixelCoordinate get2DCoordinate(unsigned int index) const
Definition: HilbertCurve.h:42
std::shared_ptr< DependentParameter< std::shared_ptr< EngineParameter > > > y
HilbertCurve(unsigned int size)
Definition: HilbertCurve.h:30
std::vector< PixelCoordinate > getCurve() const
Definition: HilbertCurve.h:34
A pixel coordinate made of two integers m_x and m_y.
STL class.
T emplace_back(T...args)