FERS 1.0.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 <fstream>
18#include <memory>
19
20#include "core/logging.h"
21#include "core/parameters.h"
23
24namespace serial
25{
26 bool KmlGenerator::generateKml(const core::World& world, const std::string& outputKmlPath)
27 {
28 try
29 {
32
33 switch (ctx.parameters.coordinate_frame)
34 {
36 {
37 auto proj = std::make_shared<GeographicLib::LocalCartesian>(ctx.parameters.origin_latitude,
40 ctx.converter = [proj](const math::Vec3& pos, double& lat, double& lon, double& alt)
41 { proj->Reverse(pos.x, pos.y, pos.z, lat, lon, alt); };
42 break;
43 }
45 {
46 const int zone = ctx.parameters.utm_zone;
47 const bool northp = ctx.parameters.utm_north_hemisphere;
48 ctx.converter = [zone, northp](const math::Vec3& pos, double& lat, double& lon, double& alt)
49 {
50 double gamma, k;
51 GeographicLib::UTMUPS::Reverse(zone, northp, pos.x, pos.y, lat, lon, gamma, k);
52 alt = pos.z;
53 };
54 break;
55 }
57 {
58 const auto& earth = GeographicLib::Geocentric::WGS84();
59 ctx.converter = [&earth](const math::Vec3& pos, double& lat, double& lon, double& alt)
60 { earth.Reverse(pos.x, pos.y, pos.z, lat, lon, alt); };
61 break;
62 }
63 }
64
65 std::ofstream kml_file(outputKmlPath.c_str());
66 if (!kml_file.is_open())
67 {
68 LOG(logging::Level::ERROR, "Error opening output KML file {}", outputKmlPath);
69 return false;
70 }
71
72 kml_generator_utils::generateKmlToStream(kml_file, world, ctx);
73 kml_file.close();
74 }
75 catch (const std::exception& e)
76 {
77 LOG(logging::Level::ERROR, "Error generating KML file: {}", e.what());
78 return false;
79 }
80 catch (...)
81 {
82 LOG(logging::Level::ERROR, "Unknown error occurred while generating KML file.");
83 return false;
84 }
85 return true;
86 }
87}
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 bool 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
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.
double origin_longitude
Geodetic origin longitude.
Definition parameters.h:63
double origin_altitude
Geodetic origin altitude (in meters)
Definition parameters.h:64
CoordinateFrame coordinate_frame
Scenario coordinate frame.
Definition parameters.h:65
int utm_zone
UTM zone (1-60), if applicable.
Definition parameters.h:67
bool utm_north_hemisphere
UTM hemisphere, if applicable.
Definition parameters.h:68
double origin_latitude
Geodetic origin latitude.
Definition parameters.h:62
Context data required during KML generation.
params::Parameters parameters
A copy of the global simulation parameters.
ConverterFunc converter
Function used to translate simulation Cartesian space into geographic coords.