Config and Query classes
The Config
class is used to parse and store the informations contained in the config.json
configuration file. It is a simple class that contains a few member variables and a few member functions to access them.
class Config {
private:
std::string M_bbox; ///< Bounding box of the area of interest
int M_LOD; ///< Level of detail of the output mesh
std::string M_output_name; ///< Name of the output file
std::array<double, 2> M_default_height; ///< Default height range
std::array<double, 2> M_origin; ///< Origin of the coordinates
std::string M_input_building_mesh; ///< Path to the input building mesh
std::string M_output_format;
bool M_verbose, M_autorefine;
public:
Config(std::string const &filename, std::string const &gis);
~Config();
// Getters
....
};
std::ostream &operator<<(std::ostream &os, const Config &config);
//! Convert an array to a string (for printing for example)
template <typename T, std::size_t N>
std::string arrayToString(const std::array<T, N> &arr);
The Query
template class is used to perform queries to the OpenStreetMap API and to create a library of trees from the JSON data returned by the API. It contains a few member functions to perform the query, get the JSON result from file, create the library of trees and initialize the trees based on the configuration and GIS data.
template <typename Mesh_type, typename Kernel_type>
void perform_query(std::string bbox, bool verbose) {
std::string query =
"[out:json]; (node(" + bbox + ")[\"natural\"=\"tree\"];); out;";
if (verbose)
std::cout << "Query: " << query << std::endl;
cpr::Response r = cpr::Post(
cpr::Url{"http://overpass-api.de/api/interpreter"}, cpr::Body{query},
cpr::Header{{"Content-Type", "application/x-www-form-urlencoded"}},
cpr::Timeout{10000} // Set a timeout of 10 seconds
);
}
//! Get the JSON result of the query from file
inline nlohmann::json get_query_result() {...}
//! Create a library of trees from JSON data
template <typename Mesh_type, typename Kernel_type>
std::vector<Tree<Mesh_type, Kernel_type>>
createLibraryFromJson(nlohmann::json const &jsonData) {...}
//! Initialize trees based on configuration and GIS data
template <typename Mesh_type, typename Kernel_type>
std::vector<Tree<Mesh_type, Kernel_type>>
init_trees(std::string const &cfg, std::string const &gis, bool verbose) {...}