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