FERS 0.1.0
The Flexible Extensible Radar Simulator
Loading...
Searching...
No Matches
target.cpp
Go to the documentation of this file.
1// SPDX-License-Identifier: GPL-2.0-only
2//
3// Copyright (c) 2007-2008 Marc Brooker and Michael Inggs
4// Copyright (c) 2008-present FERS Contributors (see AUTHORS.md).
5//
6// See the GNU GPLv2 LICENSE file in the FERS project root for more information.
7
8/**
9 * @file target.cpp
10 * @brief Defines classes for radar targets and their Radar Cross-Section (RCS) models.
11 */
12
13#include "target.h"
14
15#include <cmath>
16#include <optional>
17#include <stdexcept>
18
19#include "core/logging.h"
20#include "math/geometry_ops.h"
22
23using math::SVec3;
24
25namespace
26{
27 /**
28 * @brief Load the target gain axis from an XML element.
29 *
30 * @param set The interpolation set to insert the samples into.
31 * @param axisXml The XML element containing the gain samples.
32 */
33 void loadTargetGainAxis(const interp::InterpSet* set, const XmlElement& axisXml) noexcept
34 {
35 XmlElement tmp = axisXml.childElement("rcssample");
36 while (tmp.isValid())
37 {
38 XmlElement const angle_element = tmp.childElement("angle", 0);
39
40 if (XmlElement const gain_element = tmp.childElement("rcs", 0);
41 angle_element.isValid() && gain_element.isValid())
42 {
43 const RealType angle = std::stof(angle_element.getText());
44 const RealType gain = std::stof(gain_element.getText());
45 set->insertSample(angle, gain);
46 }
47
48 tmp = XmlElement(tmp.getNode()->next);
49 }
50 }
51}
52
53namespace radar
54{
55 RealType IsoTarget::getRcs(SVec3& /*inAngle*/, SVec3& /*outAngle*/, RealType /*time*/) const noexcept
56 {
57 return _model ? _rcs * _model->sampleModel() : _rcs;
58 }
59
60 FileTarget::FileTarget(Platform* platform, std::string name, const std::string& filename, const unsigned seed,
61 const SimId id) :
62 Target(platform, std::move(name), seed, id), _azi_samples(std::make_unique_for_overwrite<interp::InterpSet>()),
63 _elev_samples(std::make_unique_for_overwrite<interp::InterpSet>()), _filename(filename)
64 {
66 if (!doc.loadFile(filename))
67 {
68 throw std::runtime_error("Could not load target description from " + filename);
69 }
70
71 const XmlElement root(doc.getRootElement());
72
73 loadTargetGainAxis(_elev_samples.get(), root.childElement("elevation", 0));
74 loadTargetGainAxis(_azi_samples.get(), root.childElement("azimuth", 0));
75 }
76
78 {
79 // TODO: the handling of arbitrary rcs models needs to be validated and expanded to cover edge cases.
80 // 1. Calculate the bistatic angle bisector in the GLOBAL frame.
82
83 // 2. Get the target's own rotation at the current time.
84 const SVec3 target_rotation = getRotation(time);
85
86 // 3. Transform the global angle into the target's LOCAL frame for lookup.
88
89 // 4. Use the local aspect angle (bisector is halved) to look up RCS.
90 const auto azi_value = _azi_samples->getValueAt(local_aspect_angle.azimuth / 2.0);
91
92 if (const auto elev_value = _elev_samples->getValueAt(local_aspect_angle.elevation / 2.0);
94 {
95 // Return the raw RCS value (proportional to power), not its square root.
96 const RealType rcs = *azi_value * *elev_value;
97 return _model ? rcs * _model->sampleModel() : rcs;
98 }
99
100 LOG(logging::Level::FATAL, "Could not get RCS value for target");
101 throw std::runtime_error("Could not get RCS value for target");
102 }
103}
Class for managing XML documents.
Class representing a node in an XML document.
Wrapper class for managing interpolation sets using smart pointers.
A class representing a vector in spherical coordinates.
RealType getRcs(math::SVec3 &inAngle, math::SVec3 &outAngle, RealType time) const override
Gets the RCS value from file-based data for a specific bistatic geometry and time.
Definition target.cpp:77
FileTarget(Platform *platform, std::string name, const std::string &filename, unsigned seed, const SimId id=0)
Constructs a file-based radar target.
Definition target.cpp:60
RealType getRcs(math::SVec3 &, math::SVec3 &, RealType) const noexcept override
Gets the constant RCS value.
Definition target.cpp:55
math::SVec3 getRotation(const RealType time) const
Retrieves the rotation of the object.
Definition object.h:58
Represents a simulation platform with motion and rotation paths.
Definition platform.h:32
Base class for radar targets.
Definition target.h:118
std::unique_ptr< RcsModel > _model
The RCS fluctuation model for the target.
Definition target.h:177
double RealType
Type for real numbers.
Definition config.h:27
Classes and operations for 3D geometry.
Wrapper for managing XML documents and elements using libxml2.
Header file for the logging system.
#define LOG(level,...)
Definition logging.h:19
@ FATAL
Fatal level for severe error events.
uint64_t SimId
64-bit Unique Simulation ID.
Definition sim_id.h:18
math::Vec3 max
Defines classes for radar targets and their Radar Cross-Section (RCS) models.