-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_hilbert.cpp
151 lines (131 loc) · 4.23 KB
/
test_hilbert.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
/*
Copyright 2017 InitialDLab
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include <iostream>
#include <algorithm>
#include <boost/geometry/geometry.hpp>
#include <boost/geometry/geometries/point.hpp>
#include "hilbert/hilbert.h"
namespace bg = boost::geometry;
namespace bm = ::boost::mpl;
namespace bmp = ::boost::mpl::placeholders;
void test_2d()
{
hilbert::HilbertValueComputer<unsigned int, 2, 8> hvc;
/*
using point_t = bg::model::point<int, 2, bg::cs::cartesian>;
std::cerr << "here" << std::endl;
int x,y;
while(std::cin >> x >> y)
{
auto hv = hvc(point_t(x,y));
for(auto & p : hv.values)
std::cout << p << ' ';
std::cout << std::endl;
}
return 0;
*/
using point_t = bg::model::point<int, 2, bg::cs::cartesian>;
std::vector<point_t> v;
int DIM_SIZE = (1LL << 8);
for(int i = 0; i < DIM_SIZE; ++i)
{
for(int j = 0; j < DIM_SIZE; ++j)
{
v.push_back(point_t(i,j));
}
}
std::sort(v.begin(), v.end(), [&](point_t const& p1, point_t const& p2)->bool{
return hvc(p1) < hvc(p2);
});
/*
for(auto & p : v)
{
auto hv = hvc(p);
for(auto & i : hv.values)
std::cerr << i << ' ';
std::cerr << std::endl;
}
*/
for(auto iter = v.begin(); iter != --v.end(); )
{
std::cout << iter->get<0>() << ' ' << iter->get<1>() << std::endl;
++iter;
std::cout << iter->get<0>() << ' ' << iter->get<1>() << std::endl;
std::cout << std::endl;
}
}
void test_3d()
{
std::cerr << "building lookup" << std::endl;
hilbert::HilbertValueComputer<unsigned int, 3, 4> hvc;
std::cerr << "generating data" << std::endl;
using point_t = bg::model::point<int, 3, bg::cs::cartesian>;
std::vector<point_t> v;
int DIM_SIZE = (1LL << 4);
for(int i = 0; i < DIM_SIZE; ++i)
{
for(int j = 0; j < DIM_SIZE; ++j)
{
for(int k = 0; k < DIM_SIZE; ++k)
{
v.push_back(point_t(i,j,k));
}
}
}
std::cerr << "sorting data" << std::endl;
std::sort(v.begin(), v.end(), [&](point_t const& p1, point_t const& p2)->bool{
return hvc(p1) < hvc(p2);
});
/*
for(auto & p : v)
{
auto hv = hvc(p);
for(auto & i : hv.values)
std::cerr << i << ' ';
std::cerr << std::endl;
}
*/
std::cerr << "saving" << std::endl;
for(auto iter = v.begin(); iter != --v.end(); )
{
std::cout << iter->get<0>() << ' ' << iter->get<1>() << ' ' << iter->get<2>() << std::endl;
++iter;
std::cout << iter->get<0>() << ' ' << iter->get<1>() << ' ' << iter->get<2>() << std::endl;
std::cout << std::endl;
}
std::cerr << "done" << std::endl;
}
struct printer
{
template <typename V>
void operator () (V)
{
using T0 = typename bm::at_c<V, 0>::type;
std::cout << T0::dim << ' ' << T0::x << ' ' << T0::y << ' ' << T0::z << ' ';
using T = typename bm::at_c<V, 1>::type;
std::cout << T::x << ' ' << T::y << ' ' << T::z << std::endl;
}
};
int main()
{
//test_2d();
test_3d();
//bm::for_each<hilbert::three_d::HilbertRecursionBase<0, false, false, false>>(printer());
return 0;
}