Skip to content

Commit

Permalink
Finish deserialization without duality
Browse files Browse the repository at this point in the history
Signed-off-by: Kunlin Yu <yukunlin@syriusrobotics.com>
  • Loading branch information
kunlinyu committed Dec 28, 2023
1 parent f2524ad commit 6324d0e
Show file tree
Hide file tree
Showing 12 changed files with 284 additions and 27 deletions.
7 changes: 7 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ project(indoorjson-cpp)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED True)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -Wall --coverage")

# json-schema-validator
find_package(nlohmann_json_schema_validator REQUIRED)

Expand Down Expand Up @@ -70,8 +72,13 @@ set(TEST_CASES
test_node
test_edge
test_serialization
test_deserialization
)

file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/tests/resources DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
set(TEST_RESOURCES "${CMAKE_CURRENT_BINARY_DIR}/resources")
add_definitions(-DTEST_RESOURCES="${TEST_RESOURCES}")

foreach(CASE ${TEST_CASES})
add_executable(${CASE} tests/${CASE}.cpp)
add_test(NAME ${CASE} COMMAND ${CASE})
Expand Down
1 change: 1 addition & 0 deletions src/serialization/cell_boundary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ void from_json(const json &j, CellBoundary &boundary) {
j.at("spaces").get_to(boundary.spaces);
}
void from_json(const json &j, CellBoundaryPtr &boundary) {
boundary = std::make_shared<CellBoundary>();
from_json(j, *boundary.get());
}
void from_json(const json &j, CellBoundaryWPtr &boundary) {}
Expand Down
1 change: 1 addition & 0 deletions src/serialization/cell_space.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ void from_json(const json &j, CellSpace &space) {
j.at("node").get_to(space.node);
}
void from_json(const json &j, CellSpacePtr &space) {
space = std::make_shared<CellSpace>();
from_json(j, *space.get());
}
void from_json(const json &j, CellSpaceWPtr &space) {}
Expand Down
1 change: 1 addition & 0 deletions src/serialization/connection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ void from_json(const json &j, Connection &connection) {
}

void from_json(const json &j, ConnectionPtr &connection) {
connection = std::make_shared<Connection>();
from_json(j, *connection.get());
}
} // namespace indoor_json
1 change: 1 addition & 0 deletions src/serialization/dual_space_layer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ void from_json(const json &j, DualSpaceLayer &layer) {
j.at("edges").get_to(layer.edges);
}
void from_json(const json &j, DualSpaceLayerPtr &layer) {
layer = std::make_shared<DualSpaceLayer>();
from_json(j, *layer.get());
}
} // namespace indoor_json
5 changes: 4 additions & 1 deletion src/serialization/edge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,10 @@ void from_json(const json &j, Edge &edge) {
j.at("boundary").get_to(edge.boundary);
}

void from_json(const json &j, EdgePtr &edge) { from_json(j, *edge.get()); }
void from_json(const json &j, EdgePtr &edge) {
edge = std::make_shared<Edge>();
from_json(j, *edge.get());
}
void from_json(const json &j, EdgeWPtr &edge) {}

} // namespace indoor_json
1 change: 1 addition & 0 deletions src/serialization/indoor_features.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ void from_json(const json& j, IndoorFeatures& indoor_features) {
j.at("connections").get_to(indoor_features.connections);
}
void from_json(const json& j, IndoorFeaturesPtr& indoor_features) {
indoor_features = std::make_shared<IndoorFeatures>();
from_json(j, *indoor_features.get());
}

Expand Down
5 changes: 4 additions & 1 deletion src/serialization/node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,10 @@ void from_json(const json &j, Node &node) {

}

void from_json(const json &j, NodePtr &node) { from_json(j, *node.get()); }
void from_json(const json &j, NodePtr &node) {
node = std::make_shared<Node>();
from_json(j, *node.get());
}

void from_json(const json &j, NodeWPtr &node) {}

Expand Down
1 change: 1 addition & 0 deletions src/serialization/primal_space_layer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ void from_json(const json &j, PrimalSpaceLayer &layer) {
j.at("boundaries").get_to(layer.boundaries);
}
void from_json(const json &j, PrimalSpaceLayerPtr &layer) {
layer = std::make_shared<PrimalSpaceLayer>();
from_json(j, *layer.get());
}

Expand Down
33 changes: 8 additions & 25 deletions src/serialization/thematic_layer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,28 +16,12 @@ namespace indoor_json {

using json = nlohmann::json;

void to_json(json &j, const Theme &theme) {
switch (theme) {
case Theme::Topographic:
j = "Topographic";
break;
case Theme::Sensor:
j = "Sensor";
break;
case Theme::Logical:
j = "Logical";
break;
case Theme::Unknown:
j = "Unknown";
break;
case Theme::Property:
j = "Property";
break;
case Theme::Other:
j = "Other";
break;
}
}
NLOHMANN_JSON_SERIALIZE_ENUM(Theme, {{Theme::Topographic, "Topographic"},
{Theme::Sensor, "Sensor"},
{Theme::Logical, "Logical"},
{Theme::Unknown, "Unknown"},
{Theme::Property, "Property"},
{Theme::Other, "Other"}})

void to_json(json &j, const ThematicLayer &layer) {
j = {{"theme", layer.theme},
Expand All @@ -62,11 +46,10 @@ void from_json(const json &j, ThematicLayer &layer) {
j.at("dual_space").get_to(layer.dual_space);
}
void from_json(const json &j, ThematicLayerPtr &layer) {
layer = std::make_shared<ThematicLayer>();
from_json(j, *layer.get());
}

void from_json(const json& j, ThematicLayerWPtr& layer) {

}
void from_json(const json &j, ThematicLayerWPtr &layer) {}

} // namespace indoor_json
205 changes: 205 additions & 0 deletions tests/resources/case1.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,205 @@
{
"connections": [
{
"comment": "this is a connection connect layer1 and layer2",
"id": "",
"layers": [
"layer1",
"layer2"
],
"nodes": [
"n1",
"node_2nd"
],
"spaces": [
"space1",
"space_2nd"
]
}
],
"id": "",
"layers": [
{
"dual_space": {
"edges": [
{
"boundary": "b2",
"geom": "LINESTRING (0.5 0.5, 1.5 0.5)",
"id": "e",
"nodes": [
"n1",
"n2"
],
"weight": 0.0
}
],
"id": "",
"nodes": [
{
"edges": [
"e"
],
"geom": "POINT (0.5 0.5)",
"id": "n1",
"space": "space1"
},
{
"edges": [
"e"
],
"geom": "POINT (1.5 0.5)",
"id": "n2",
"space": "space2"
}
]
},
"id": "layer1",
"primal_space": {
"boundaries": [
{
"edge": null,
"geom": "LINESTRING (0 0, 1 0)",
"id": "b1",
"spaces": [
"space1"
]
},
{
"edge": "e",
"geom": "LINESTRING (1 0, 1 1)",
"id": "b2",
"spaces": [
"space1",
"space2"
]
},
{
"edge": null,
"geom": "LINESTRING (1 1, 0 1)",
"id": "b3",
"spaces": [
"space1"
]
},
{
"edge": null,
"geom": "LINESTRING (0 1, 0 0)",
"id": "b4",
"spaces": [
"space1"
]
},
{
"edge": null,
"geom": "LINESTRING (1 0, 2 0)",
"id": "b5",
"spaces": [
"space2"
]
},
{
"edge": null,
"geom": "LINESTRING (2 0, 2 1)",
"id": "b6",
"spaces": [
"space2"
]
},
{
"edge": null,
"geom": "LINESTRING (2 1, 1 1)",
"id": "b7",
"spaces": [
"space2"
]
}
],
"id": "",
"spaces": [
{
"boundaries": [
"b1",
"b2",
"b3",
"b4"
],
"geom": "POLYGON ((0 0, 1 0, 1 1, 0 1, 0 0))",
"id": "space1",
"node": "n1"
},
{
"boundaries": [
"b2",
"b5",
"b6",
"b7"
],
"geom": "POLYGON ((1 0, 2 0, 2 1, 1 1, 1 0))",
"id": "space2",
"node": "n2"
},
{
"boundaries": [],
"geom": "POLYGON ((-1 0, 0 0, 0 1, -1 1, -1 0))",
"id": "space_2nd",
"node": null
}
]
},
"theme": "Topographic"
},
{
"dual_space": {
"edges": [],
"id": "",
"nodes": [
{
"edges": [],
"geom": "POINT (-0.5 0.5)",
"id": "node_2nd",
"space": null
}
]
},
"id": "layer2",
"primal_space": {
"boundaries": [
{
"edge": null,
"geom": "LINESTRING (-1 0, 0 0)",
"id": "b_2nd1",
"spaces": []
},
{
"edge": null,
"geom": "LINESTRING (0 0, 0 1)",
"id": "b_2nd2",
"spaces": []
},
{
"edge": null,
"geom": "LINESTRING (0 1, -1 1)",
"id": "b_2nd3",
"spaces": []
},
{
"edge": null,
"geom": "LINESTRING (-1 1, -1 0)",
"id": "b_2nd4",
"spaces": []
}
],
"id": "",
"spaces": [
{
"boundaries": [],
"geom": "POLYGON ((-1 0, 0 0, 0 1, -1 1, -1 0))",
"id": "space_2nd",
"node": null
}
]
},
"theme": "Topographic"
}
]
}
Loading

0 comments on commit 6324d0e

Please sign in to comment.