FERS 0.1.0
The Flexible Extensible Radar Simulator
Loading...
Searching...
No Matches
kml_generator.cpp
Go to the documentation of this file.
1// SPDX-License-Identifier: GPL-2.0-only
2//
3// Copyright (c) 2023-present FERS Contributors (see AUTHORS.md).
4//
5// See the GNU GPLv2 LICENSE file in the FERS project root for more information.
6
7/**
8 * @file kml_generator.cpp
9 * @brief Source file for KML file generation from FERS simulation scenarios.
10 */
11
13
14#include <GeographicLib/Geocentric.hpp>
15#include <GeographicLib/LocalCartesian.hpp>
16#include <GeographicLib/UTMUPS.hpp>
17#include <expected>
18#include <fstream>
19#include <limits>
20#include <memory>
21
22#include "core/logging.h"
23#include "core/parameters.h"
25
26namespace serial
27{
28 std::expected<void, std::string> KmlGenerator::generateKml(const core::World& world,
29 const std::string& outputKmlPath)
30 {
31 try
32 {
34 ctx.parameters = params::params;
35
36 switch (ctx.parameters.coordinate_frame)
37 {
39 {
40 auto proj = std::make_shared<GeographicLib::LocalCartesian>(ctx.parameters.origin_latitude,
41 ctx.parameters.origin_longitude,
42 ctx.parameters.origin_altitude);
43 ctx.converter = [proj](const math::Vec3& pos, double& lat, double& lon, double& alt)
44 { proj->Reverse(pos.x, pos.y, pos.z, lat, lon, alt); };
45 break;
46 }
48 {
49 const int zone = ctx.parameters.utm_zone;
50 const bool northp = ctx.parameters.utm_north_hemisphere;
51 ctx.converter = [zone, northp](const math::Vec3& pos, double& lat, double& lon, double& alt)
52 {
53 double gamma = std::numeric_limits<double>::quiet_NaN();
54 double k = std::numeric_limits<double>::quiet_NaN();
55 GeographicLib::UTMUPS::Reverse(zone, northp, pos.x, pos.y, lat, lon, gamma, k);
56 alt = pos.z;
57 };
58 break;
59 }
61 {
62 const auto& earth = GeographicLib::Geocentric::WGS84();
63 ctx.converter = [&earth](const math::Vec3& pos, double& lat, double& lon, double& alt)
64 { earth.Reverse(pos.x, pos.y, pos.z, lat, lon, alt); };
65 break;
66 }
67 }
68
69 std::ofstream kml_file(outputKmlPath.c_str());
70 if (!kml_file.is_open())
71 {
72 const std::string message = "Error opening output KML file " + outputKmlPath;
74 return std::unexpected(message);
75 }
76
78 kml_file.close();
79 }
80 catch (const std::exception& e)
81 {
82 const std::string message = "Error generating KML file: " + std::string(e.what());
84 return std::unexpected(message);
85 }
86 catch (...)
87 {
88 const std::string message = "Unknown error occurred while generating KML file.";
90 return std::unexpected(message);
91 }
92 return {};
93 }
94}
The World class manages the simulator environment.
Definition world.h:39
A class representing a vector in rectangular coordinates.
RealType x
The x component of the vector.
RealType z
The z component of the vector.
RealType y
The y component of the vector.
static std::expected< void, std::string > generateKml(const core::World &world, const std::string &outputKmlPath)
Generates a KML file from a pre-built simulation world.
KML file generator for geographical visualization of FERS scenarios.
Utility definitions and functions for generating KML files from simulation scenarios.
Header file for the logging system.
#define LOG(level,...)
Definition logging.h:19
@ ERROR
Error level for error events.
@ UTM
Universal Transverse Mercator.
@ ENU
East-North-Up local tangent plane (default)
@ ECEF
Earth-Centered, Earth-Fixed.
Parameters params
Global simulation parameter state.
Definition parameters.h:85
void generateKmlToStream(std::ostream &out, const core::World &world, const KmlContext &ctx)
Master entry point designed to convert the comprehensive simulation world state into a valid KML docu...
Defines the Parameters struct and provides methods for managing simulation parameters.
math::Vec3 max
Context data required during KML generation.