-
Notifications
You must be signed in to change notification settings - Fork 0
/
nodes_cityfb.cpp
139 lines (117 loc) · 4.06 KB
/
nodes_cityfb.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
#include "nodes.hpp"
#include "CityJSONFeature_generated.h"
namespace geoflow::nodes::basic3d {
std::vector<flatbuffers::Offset<CityFB::Surface>> create_surfaces_vector(flatbuffers::FlatBufferBuilder& builder, const nlohmann::json& json) {
std::vector<flatbuffers::Offset<CityFB::Surface>> surfaces_vector;
for(auto& cjsurface : json) {
std::vector<flatbuffers::Offset<CityFB::Ring>> rings_vector;
for(auto& cjring : cjsurface) {
std::vector<uint32_t> indices_vector;
for(auto& idx : cjring) {
indices_vector.push_back(idx);
}
rings_vector.push_back(
CityFB::CreateRing(builder,
builder.CreateVector(indices_vector)
)
);
}
surfaces_vector.push_back(
CityFB::CreateSurface(builder,
builder.CreateVector(rings_vector)
)
);
}
return surfaces_vector;
}
std::vector<flatbuffers::Offset<CityFB::Shell>> create_shells_vector(flatbuffers::FlatBufferBuilder& builder, const nlohmann::json& json) {
std::vector<flatbuffers::Offset<CityFB::Shell>> shells_vector;
for(auto& cjshell : json) {
auto surfaces_vector = create_surfaces_vector(builder, cjshell);
shells_vector.push_back(
CityFB::CreateShell(builder,
builder.CreateVector(surfaces_vector)
)
);
};
return shells_vector;
}
void CityFBFeatureWriterNode::process() {
auto& feature = input("CityJSONFeature").get<nlohmann::json>();
if(feature["type"] != "CityJSONFeature") {
throw(gfException("input is not CityJSONFeature"));
}
// Create ID
flatbuffers::FlatBufferBuilder builder;
auto id = builder.CreateString(feature["id"].get<std::string>());
// Create vertices
std::vector<CityFB::Vertex> vertices_vector;
for (auto&v : feature["vertices"]) {
vertices_vector.push_back(
CityFB::Vertex(v[0], v[1], v[2])
);
}
// Create city objects
std::vector<flatbuffers::Offset<CityFB::CityObject>> city_objects_vector;
for( auto& [id_, cobject] : feature["CityObjects"].items() ) {
// type
CityFB::CityObjectType type;
if(cobject["type"] == "Building") {
type = CityFB::CityObjectType_Building;
} else if(cobject["type"] == "BuildingPart") {
type = CityFB::CityObjectType_BuildingPart;
}
// id
auto id = builder.CreateString(id_);
// attributes
// geometry
std::vector<flatbuffers::Offset<CityFB::Geometry>> geometries_vector;
for (auto& cjgeometry : cobject["geometry"]) {
CityFB::Boundaries boundaries_type;
flatbuffers::Offset<void> boundaries;
auto lod = builder.CreateString(cjgeometry["lod"].get<std::string>());
if(cjgeometry["type"] == "MultiSurface") {
auto surfaces_vector = create_surfaces_vector(builder, cjgeometry["boundaries"]);
boundaries_type = CityFB::Boundaries_MultiSurface;
boundaries = CityFB::CreateMultiSurface(builder,
builder.CreateVector(surfaces_vector)
).Union();
} else if(cjgeometry["type"] == "Solid") {
auto shells_vector = create_shells_vector(builder, cjgeometry["boundaries"]);
boundaries_type = CityFB::Boundaries_Solid;
boundaries = CityFB::CreateSolid(builder,
builder.CreateVector(shells_vector)
).Union();
}
geometries_vector.push_back(
CityFB::CreateGeometry(
builder,
lod,
boundaries_type,
boundaries,
0 // semantics
)
);
}
// children
// parent
city_objects_vector.push_back(
CityFB::CreateCityObject(
builder,
type,
id,
0, //attributes
builder.CreateVector(geometries_vector),
0, //children
0 //parent
)
);
}
CityFB::CreateCityJSONFeature(
builder,
id,
builder.CreateVector(city_objects_vector),
builder.CreateVectorOfStructs(vertices_vector)
);
}
}