-
Notifications
You must be signed in to change notification settings - Fork 8
/
write_top.cpp
125 lines (93 loc) · 3.25 KB
/
write_top.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
#include <iostream>
#include <fstream>
#include <string>
#include <math.h>
#include <map>
#include <iomanip>
#include <algorithm>
#include <MinecraftWorld.h>
#include <parse_bedrock.h>
#include <compute_mst.h>
#include <compute_ore_stats.h>
void
write_cluster_vtk(std::vector<std::set<int> > &clusters,
std::vector<std::tuple<int, int, int> > &ores,
std::string filename)
{
std::ofstream outfile;
outfile.open(filename);
outfile << "# vtk DataFile Version 1.0\n";
outfile << "3D triangulation data\n";
outfile << "ASCII\n";
outfile << std::endl;
outfile << "DATASET POLYDATA\n";
std::vector<std::string> points;
for (auto cluster : clusters) {
float x=0;
float y=0;
float z=0;
for (auto loc : cluster) {
x += std::get<0>(ores[loc]);
y += std::get<1>(ores[loc]);
z += std::get<2>(ores[loc]);
}
std::stringstream ss;
ss << x/cluster.size() << " " << y/cluster.size() << " " << z/cluster.size() << "\n";
points.push_back(ss.str());
}
outfile << "POINTS " << points.size() << " float\n";
for (auto str : points) {
outfile << str;
}
outfile.close();
}
int
main(int argc,char* argv[])
{
MinecraftWorld world;
//std::string dbpath = "/bubba/electronicsDS/minecraft/sampledata/2019.11.26.04.00.53/worlds/Bedrock level/db";
std::string dbpath = "/bubba/electronicsDS/minecraft/gfhtx2/gfHTXZk9AQA/db";
parse_bedrock(dbpath, world);
int num_chunks = world.num_chunks();
// 16 subchunks/chunk and 16*16*16 per subchunk
std::cout << "num chunks " << num_chunks << "\n";
std::cout << "num blocks in world " << num_chunks*16*16*16*16 << "\n";
int air_id = BlockType::get_block_type_id_by_name("minecraft:air ()");
int stairs_id = BlockType::get_block_type_id_by_name("minecraft:mossy_cobblestone_stairs ()");
std::map<std::pair<int, int>, int > top_height;
for (auto scix : world.theworld) {
//int chunkx = scix.first;
for (auto sciy : scix.second) {
//int chunky = sciy.first;
for (auto sciz : sciy.second) {
//int chunkz = sciz.first;
auto sc = sciz.second;
for (auto iter=sc->begin(); iter!=sc->end(); ++iter) {
auto loc = *iter;
uint8_t blocktype = loc.type;
if (blocktype == stairs_id) {
std::cout << "stairs at: " << loc.x << ", " << loc.y << ", " << loc.z << "\n";
}
if (blocktype == air_id) { continue; }
auto point = std::make_pair(loc.x, loc.z);
top_height[point] = std::max(top_height[point], loc.y);
}
}
}
}
std::string filename = "tops.vtk";
std::ofstream outfile;
outfile.open(filename);
outfile << "# vtk DataFile Version 1.0\n";
outfile << "3D triangulation data\n";
outfile << "ASCII\n";
outfile << std::endl;
outfile << "DATASET POLYDATA\n";
outfile << "POINTS " << top_height.size() << " float\n";
for (auto iter : top_height) {
std::stringstream ss;
ss << iter.first.first << " " << iter.first.second << " " << iter.second << "\n";
outfile << ss.str();
}
outfile.close();
}