Skip to content

Commit

Permalink
Added: JSON parser (with example)
Browse files Browse the repository at this point in the history
  • Loading branch information
denizdiktas committed Jul 24, 2023
1 parent db132c3 commit 39504e5
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
7 changes: 7 additions & 0 deletions Arrangement_on_surface_2/demo/earth/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ if ( NOT Boost_FOUND )

endif()

################################################################################
include(FetchContent)
FetchContent_Declare(json URL https://github.com/nlohmann/json/releases/download/v3.11.2/json.tar.xz)
FetchContent_MakeAvailable(json)
# find_package(nlohmann_json 3.2.0 REQUIRED)
################################################################################

set(SHAPELIB_INCLUDE_DIR "" CACHE PATH "DEFINE ME!!!")
#target_include_directories(earth PRIVATE ${SHAPELIB_INCLUDE_DIR})
Expand Down Expand Up @@ -127,6 +133,7 @@ target_link_libraries(earth PRIVATE
Qt6::Xml
CGAL::CGAL
shp
nlohmann_json::nlohmann_json
)

file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/shaders
Expand Down
31 changes: 31 additions & 0 deletions Arrangement_on_surface_2/demo/earth/Main_widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,40 @@ void Main_widget::init_problematic_nodes()

std::unique_ptr<Line_strips> new_faces;

#include <nlohmann/json.hpp>
using json = nlohmann::json;

void Main_widget::initializeGL()
{
json js;
auto& ja = js["vertices"] = json::array();
json json_v1 = R"(
{
"location": "0",
"dx": {"num": "123","den": "1"},
"dy": {"num": "456","den": "5"},
"dz": {"num": "789","den": "9"}
}
)"_json;
json json_v2 = R"(
{
"location": "0",
"dx": {"num": "111","den": "2"},
"dy": {"num": "333","den": "4"},
"dz": {"num": "555","den": "6"}
}
)"_json;
json jv2;
jv2["location"] = "0";
jv2["dx"]["num"] = "111"; jv2["dx"]["den"] = "2";
jv2["dy"]["num"] = "333"; jv2["dy"]["den"] = "4";
jv2["dz"]["num"] = "555"; jv2["dz"]["den"] = "6";

ja.push_back(json_v1);
ja.push_back(jv2);
ja.size();
std::cout << js << std::endl;

// verify that the node (180.0, -84.71338) in Antarctica is redundant
verify_antarctica_node_is_redundant();

Expand Down

0 comments on commit 39504e5

Please sign in to comment.