FERS 1.0.0
The Flexible Extensible Radar Simulator
Loading...
Searching...
No Matches
target.h
Go to the documentation of this file.
1// SPDX-License-Identifier: GPL-2.0-only
2//
3// Copyright (c) 2006-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.h
10 * @brief Defines classes for radar targets and their Radar Cross-Section (RCS) models.
11 */
12
13#pragma once
14
15#include <memory>
16#include <random>
17#include <string>
18#include <utility>
19
20#include "core/config.h"
23#include "object.h"
24
25namespace math
26{
27 class SVec3;
28}
29
30namespace radar
31{
32 class Platform;
33
34 /**
35 * @class RcsModel
36 * @brief Base class for RCS fluctuation models.
37 */
39 {
40 public:
41 virtual ~RcsModel() = default;
42
43 RcsModel() = default;
44
45 RcsModel(const RcsModel&) = delete;
46
47 RcsModel& operator=(const RcsModel&) = delete;
48
49 RcsModel(RcsModel&&) = delete;
50
52
53 /**
54 * @brief Samples the RCS model to produce a value.
55 *
56 * @return The sampled RCS value.
57 */
58 virtual RealType sampleModel() = 0;
59 };
60
61 /**
62 * @class RcsConst
63 * @brief Constant RCS model.
64 */
65 class RcsConst final : public RcsModel
66 {
67 public:
68 /**
69 * @brief Samples the constant RCS model.
70 *
71 * @return The RCS value (always 1.0).
72 */
73 RealType sampleModel() override { return 1.0; }
74 };
75
76 /**
77 * @class RcsChiSquare
78 * @brief Chi-square distributed RCS model.
79 */
80 class RcsChiSquare final : public RcsModel
81 {
82 public:
83 /**
84 * @brief Constructs an RcsChiSquare model.
85 *
86 * @param rngEngine The random number engine to use.
87 * @param k The degrees of freedom for the chi-square distribution.
88 */
89 explicit RcsChiSquare(std::mt19937& rngEngine, RealType k) :
90 _gen(std::make_unique<noise::GammaGenerator>(rngEngine, k)), _k(k)
91 {
92 }
93
94 /**
95 * @brief Gets the 'k' parameter (degrees of freedom) of the distribution.
96 * @return The k value.
97 */
98 [[nodiscard]] RealType getK() const noexcept { return _k; }
99
100 /**
101 * @brief Samples the chi-square RCS model.
102 *
103 * @return The sampled RCS value.
104 */
105 RealType sampleModel() override { return _gen->getSample(); }
106
107 private:
108 std::unique_ptr<noise::GammaGenerator> _gen; ///< The gamma generator for sampling the chi-square distribution.
109 RealType _k; ///< The 'k' parameter (degrees of freedom).
110 };
111
112 /**
113 * @class Target
114 * @brief Base class for radar targets.
115 */
116 class Target : public Object
117 {
118 public:
119 /**
120 * @brief Constructs a radar target.
121 *
122 * @param platform Pointer to the platform associated with the target.
123 * @param name The name of the target.
124 * @param seed The seed for the target's internal random number generator.
125 */
126 Target(Platform* platform, std::string name, const unsigned seed) :
127 Object(platform, std::move(name)), _rng(seed)
128 {
129 }
130
131 /**
132 * @brief Gets the RCS value for the target.
133 *
134 * @param inAngle The incoming angle of the radar wave.
135 * @param outAngle The outgoing angle of the reflected radar wave.
136 * @param time The current simulation time (default is 0.0).
137 * @return The RCS value.
138 */
139 virtual RealType getRcs(math::SVec3& inAngle, math::SVec3& outAngle, RealType time) const = 0;
140
141 /**
142 * @brief Gets the target's internal random number generator engine.
143 * @return A mutable reference to the RNG engine.
144 */
145 [[nodiscard]] std::mt19937& getRngEngine() noexcept { return _rng; }
146
147 /**
148 * @brief Sets the RCS fluctuation model.
149 *
150 * Assigns a new RCS fluctuation model to the target.
151 * @param in Unique pointer to the new RCS fluctuation model.
152 */
153 void setFluctuationModel(std::unique_ptr<RcsModel> in) { _model = std::move(in); }
154
155 /**
156 * @brief Gets the RCS fluctuation model.
157 * @return A const pointer to the RcsModel.
158 */
159 [[nodiscard]] const RcsModel* getFluctuationModel() const { return _model.get(); }
160
161 protected:
162 std::unique_ptr<RcsModel> _model{nullptr}; ///< The RCS fluctuation model for the target.
163 std::mt19937 _rng; ///< Per-object random number generator for statistical independence.
164 };
165
166 /**
167 * @class IsoTarget
168 * @brief Isotropic radar target.
169 *
170 */
171 class IsoTarget final : public Target
172 {
173 public:
174 /**
175 * @brief Constructs an isotropic radar target.
176 *
177 * @param platform Pointer to the platform associated with the target.
178 * @param name The name of the target.
179 * @param rcs The constant RCS value for the target.
180 * @param seed The seed for the target's internal random number generator.
181 */
182 IsoTarget(Platform* platform, std::string name, const RealType rcs, const unsigned seed) :
183 Target(platform, std::move(name), seed), _rcs(rcs)
184 {
185 }
186
187 /**
188 * @brief Gets the constant RCS value.
189 *
190 * @return The constant RCS value, possibly modified by the fluctuation model.
191 */
192 RealType getRcs(math::SVec3& /*inAngle*/, math::SVec3& /*outAngle*/, RealType /*time*/) const noexcept override;
193
194 /**
195 * @brief Gets the constant RCS value (without fluctuation model applied).
196 *
197 * @return The constant RCS value.
198 */
199 [[nodiscard]] RealType getConstRcs() const noexcept { return _rcs; }
200
201 private:
202 RealType _rcs; ///< The constant RCS value for the target.
203 };
204
205 /**
206 * @class FileTarget
207 * @brief File-based radar target.
208 */
209 class FileTarget final : public Target
210 {
211 public:
212 /**
213 * @brief Constructs a file-based radar target.
214 *
215 * @param platform Pointer to the platform associated with the target.
216 * @param name The name of the target.
217 * @param filename The name of the file containing RCS data.
218 * @param seed The seed for the target's internal random number generator.
219 * @throws std::runtime_error If the file cannot be loaded or parsed.
220 */
221 FileTarget(Platform* platform, std::string name, const std::string& filename, unsigned seed);
222
223 /**
224 * @brief Gets the RCS value from file-based data for a specific bistatic geometry and time.
225 * @param inAngle The incoming angle of the radar wave in the global frame.
226 * @param outAngle The outgoing angle of the reflected radar wave in the global frame.
227 * @param time The simulation time at which the interaction occurs.
228 * @return The Radar Cross Section (RCS) value in meters squared (m²).
229 * @throws std::runtime_error If RCS data cannot be retrieved.
230 *
231 * This function calculates the target's aspect-dependent RCS. The key steps are:
232 * 1. Calculate the bistatic angle bisector in the global simulation coordinate system.
233 * 2. Retrieve the target's own orientation (rotation) at the specified 'time'.
234 * 3. Transform the global bistatic angle into the target's local, body-fixed frame by subtracting
235 * the target's rotation. This is critical, as RCS patterns are defined relative to the target itself.
236 * 4. Use this local aspect angle to look up the azimuthal and elevation RCS values from the loaded data.
237 *
238 * NOTE: This function returns the raw RCS value (σ), which is linearly proportional to scattered power.
239 * The calling physics engine is responsible for converting this to a signal amplitude by taking the
240 * square root.
241 */
242 RealType getRcs(math::SVec3& inAngle, math::SVec3& outAngle, RealType time) const override;
243
244 /**
245 * @brief Gets the filename associated with this target's RCS data.
246 * @return The source filename.
247 */
248 [[nodiscard]] const std::string& getFilename() const noexcept { return _filename; }
249
250 private:
251 std::unique_ptr<interp::InterpSet> _azi_samples; ///< The azimuthal RCS samples.
252 std::unique_ptr<interp::InterpSet> _elev_samples; ///< The elevation RCS samples.
253 std::string _filename; ///< The original filename for the RCS data.
254 };
255
256 /**
257 * @brief Creates an isotropic target.
258 *
259 * @param platform Pointer to the platform associated with the target.
260 * @param name The name of the target.
261 * @param rcs The constant RCS value for the target.
262 * @param seed The seed for the target's internal random number generator.
263 * @return A unique pointer to the newly created IsoTarget.
264 */
265 inline std::unique_ptr<Target> createIsoTarget(Platform* platform, std::string name, RealType rcs, unsigned seed)
266 {
267 return std::make_unique<IsoTarget>(platform, std::move(name), rcs, seed);
268 }
269
270 /**
271 * @brief Creates a file-based target.
272 *
273 * @param platform Pointer to the platform associated with the target.
274 * @param name The name of the target.
275 * @param filename The name of the file containing RCS data.
276 * @param seed The seed for the target's internal random number generator.
277 * @return A unique pointer to the newly created FileTarget.
278 */
279 inline std::unique_ptr<Target> createFileTarget(Platform* platform, std::string name, const std::string& filename,
280 unsigned seed)
281 {
282 return std::make_unique<FileTarget>(platform, std::move(name), filename, seed);
283 }
284}
A class representing a vector in spherical coordinates.
File-based radar target.
Definition target.h:210
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:75
const std::string & getFilename() const noexcept
Gets the filename associated with this target's RCS data.
Definition target.h:248
Isotropic radar target.
Definition target.h:172
RealType getRcs(math::SVec3 &, math::SVec3 &, RealType) const noexcept override
Gets the constant RCS value.
Definition target.cpp:54
RealType getConstRcs() const noexcept
Gets the constant RCS value (without fluctuation model applied).
Definition target.h:199
IsoTarget(Platform *platform, std::string name, const RealType rcs, const unsigned seed)
Constructs an isotropic radar target.
Definition target.h:182
Represents a physical object in the radar system.
Definition object.h:24
Represents a simulation platform with motion and rotation paths.
Definition platform.h:31
Chi-square distributed RCS model.
Definition target.h:81
RealType sampleModel() override
Samples the chi-square RCS model.
Definition target.h:105
RealType getK() const noexcept
Gets the 'k' parameter (degrees of freedom) of the distribution.
Definition target.h:98
RcsChiSquare(std::mt19937 &rngEngine, RealType k)
Constructs an RcsChiSquare model.
Definition target.h:89
Constant RCS model.
Definition target.h:66
RealType sampleModel() override
Samples the constant RCS model.
Definition target.h:73
Base class for RCS fluctuation models.
Definition target.h:39
virtual ~RcsModel()=default
RcsModel(const RcsModel &)=delete
RcsModel & operator=(const RcsModel &)=delete
RcsModel & operator=(RcsModel &&)=delete
RcsModel()=default
RcsModel(RcsModel &&)=delete
virtual RealType sampleModel()=0
Samples the RCS model to produce a value.
Base class for radar targets.
Definition target.h:117
std::mt19937 & getRngEngine() noexcept
Gets the target's internal random number generator engine.
Definition target.h:145
Target(Platform *platform, std::string name, const unsigned seed)
Constructs a radar target.
Definition target.h:126
const RcsModel * getFluctuationModel() const
Gets the RCS fluctuation model.
Definition target.h:159
virtual RealType getRcs(math::SVec3 &inAngle, math::SVec3 &outAngle, RealType time) const =0
Gets the RCS value for the target.
std::mt19937 _rng
Per-object random number generator for statistical independence.
Definition target.h:163
std::unique_ptr< RcsModel > _model
The RCS fluctuation model for the target.
Definition target.h:162
void setFluctuationModel(std::unique_ptr< RcsModel > in)
Sets the RCS fluctuation model.
Definition target.h:153
Global configuration file for the project.
double RealType
Type for real numbers.
Definition config.h:27
Header file for the interpolation of sets of data.
Definition coord.h:18
std::unique_ptr< Target > createIsoTarget(Platform *platform, std::string name, RealType rcs, unsigned seed)
Creates an isotropic target.
Definition target.h:265
std::unique_ptr< Target > createFileTarget(Platform *platform, std::string name, const std::string &filename, unsigned seed)
Creates a file-based target.
Definition target.h:279
Header file for noise generator classes.
Base class for all physical objects in the radar system.