SourceXtractorPlusPlus 1.0.3
SourceXtractor++, the next generation SExtractor
Loading...
Searching...
No Matches
HilbertCurve.h
Go to the documentation of this file.
1
17
18#ifndef _SEUTILS_HILBERTCURVE_H_
19#define _SEUTILS_HILBERTCURVE_H_
20
21#include <vector>
22
23#include "SEUtils/Misc.h"
25
26namespace SourceXtractor {
27
29public:
30 explicit 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
66private:
67 unsigned int m_size;
68};
69
70}
71
72#endif /* _SEUTILS_HILBERTCURVE_H_ */
HilbertCurve(unsigned int size)
std::vector< PixelCoordinate > getCurve() const
PixelCoordinate get2DCoordinate(unsigned int index) const
T emplace_back(T... args)
T nextPowerOfTwo(T v)
Definition Misc.h:26
A pixel coordinate made of two integers m_x and m_y.
T swap(T... args)