Skip to content

Commit c0ebd95

Browse files
committed
Refactor target management to use TargetsManager
Replaces direct vector usage of Target objects with the new TargetsManager container in LiDAR and RCS simulation modules. Updates Cython and C++ interface definitions to support TargetsManager, improving target handling and extensibility for radar simulations.
1 parent f0b5813 commit c0ebd95

File tree

6 files changed

+55
-42
lines changed

6 files changed

+55
-42
lines changed

src/radarsimcpp

src/radarsimpy/includes/radarsimc.pxd

Lines changed: 33 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,36 @@ cdef extern from "target.hpp":
117117
const Vec3[T] & rotation_rate,
118118
const bool & skip_diffusion) except +
119119

120+
#------------------------------------------------------------------------------
121+
# Targets Manager
122+
# Container for managing multiple 3D mesh targets in radar simulation
123+
#------------------------------------------------------------------------------
124+
cdef extern from "targets_manager.hpp":
125+
cdef cppclass TargetsManager[T]:
126+
TargetsManager() except +
127+
# Add a new target
128+
void AddTarget(const T * points, # Vertex coordinates array
129+
const int_t * cells, # Cell connectivity array
130+
const int_t & cell_size, # Number of cells in mesh
131+
const Vec3[T] & origin, # Target reference origin
132+
const vector[Vec3[T]] & location_array, # Time-varying locations
133+
const vector[Vec3[T]] & speed_array, # Time-varying velocities
134+
const vector[Vec3[T]] & rotation_array, # Time-varying rotations
135+
const vector[Vec3[T]] & rotation_rate_array, # Time-varying rotation rates
136+
const cpp_complex[T] & ep, # Relative permittivity (material property)
137+
const cpp_complex[T] & mu, # Relative permeability (material property)
138+
const bool & skip_diffusion) except +
139+
140+
void AddTargetSimple(const T * points,
141+
const int_t * cells,
142+
const int_t & cell_size,
143+
const Vec3[T] & origin,
144+
const Vec3[T] & location,
145+
const Vec3[T] & speed,
146+
const Vec3[T] & rotation,
147+
const Vec3[T] & rotation_rate,
148+
const bool & skip_diffusion) except +
149+
120150
#------------------------------------------------------------------------------
121151
# Ray Tracing Primitives
122152
# Ray representation for LiDAR and ray tracing operations
@@ -137,7 +167,7 @@ cdef extern from "simulator_rcs.hpp":
137167
RcsSimulator() except +
138168

139169
# Calculate RCS for multiple targets and observation angles
140-
vector[T] Run(vector[Target[float]] targets, # Array of target objects
170+
vector[T] Run(const shared_ptr[TargetsManager[float]] & targets_manager, # Targets manager
141171
vector[Vec3[T]] inc_dir_array, # Incident wave directions
142172
vector[Vec3[T]] obs_dir_array, # Observation directions
143173
Vec3[cpp_complex[T]] inc_polarization, # Incident wave polarization
@@ -154,7 +184,7 @@ cdef extern from "simulator_lidar.hpp":
154184
LidarSimulator() except +
155185

156186
# Generate point cloud by ray casting
157-
void Run(vector[Target[T]] targets,
187+
void Run(const shared_ptr[TargetsManager[T]] & targets_manager, # Targets manager
158188
const vector[T] & phi, # Azimuth angles (radians)
159189
const vector[T] & theta, # Elevation angles (radians)
160190
const Vec3[T] & position) # LiDAR sensor position
@@ -285,24 +315,6 @@ cdef extern from "simulator_point.hpp":
285315
void Run(Radar[H, L] & radar, # Radar configuration
286316
vector[Point[L]] & points) # Array of point targets
287317

288-
# Targets Manager
289-
# Manager class for handling multiple mesh targets in simulations
290-
cdef extern from "targets_manager.hpp":
291-
cdef cppclass TargetsManager[T]:
292-
TargetsManager() except +
293-
# Add a new target
294-
void AddTarget(const T * points, # Vertex coordinates array
295-
const int_t * cells, # Cell connectivity array
296-
const int_t & cell_size, # Number of cells in mesh
297-
const Vec3[T] & origin, # Target reference origin
298-
const vector[Vec3[T]] & location_array, # Time-varying locations
299-
const vector[Vec3[T]] & speed_array, # Time-varying velocities
300-
const vector[Vec3[T]] & rotation_array, # Time-varying rotations
301-
const vector[Vec3[T]] & rotation_rate_array, # Time-varying rotation rates
302-
const cpp_complex[T] & ep, # Relative permittivity (material property)
303-
const cpp_complex[T] & mu, # Relative permeability (material property)
304-
const bool & skip_diffusion) except +
305-
306318
# Mesh-based Ray Tracing Simulation
307319
# Physics-based 3D mesh target simulation using ray tracing and physical optics
308320
# Usage: For realistic simulation of complex targets with detailed geometry.
@@ -313,7 +325,7 @@ cdef extern from "simulator_mesh.hpp":
313325

314326
# Run mesh simulation with configurable fidelity
315327
RadarSimErrorCode Run(Radar[H, L] & radar, # Radar configuration
316-
const shared_ptr[TargetsManager[L]] & targets_manager, # Array of mesh targets
328+
const shared_ptr[TargetsManager[L]] & targets_manager, # Targets manager
317329
int level, # Simulation level (0=LOW, 1=MEDIUM, 2=HIGH)
318330
L density, # Ray density for physical optics
319331
Vec2[int_t] ray_filter, # Ray index filter [min, max]

src/radarsimpy/lib/cp_radarsimc.pxd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ cdef Target[float_t] cp_Target(radar, target, timestamp, mesh_module) except *
6161
# Create a Target object specifically optimized for RCS calculations
6262
# Simplified target object without full dynamic simulation requirements
6363
# Raises ValueError for invalid params, RuntimeError for mesh/FreeTier issues
64-
cdef Target[float_t] cp_RCS_Target(target, mesh_module) except *
64+
cdef void cp_RCS_Target(target, mesh_module, TargetsManager[float_t] * targets_manager) except *
6565

6666
cdef void cp_AddTarget(radar,
6767
target,

src/radarsimpy/lib/cp_radarsimc.pyx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1041,7 +1041,7 @@ cdef void cp_AddTarget(radar,
10411041
@cython.cdivision(True)
10421042
@cython.boundscheck(False)
10431043
@cython.wraparound(False)
1044-
cdef Target[float_t] cp_RCS_Target(target, mesh_module):
1044+
cdef void cp_RCS_Target(target, mesh_module, TargetsManager[float_t] * targets_manager):
10451045
"""
10461046
cp_RCS_Target(target, mesh_module)
10471047
@@ -1115,7 +1115,7 @@ cdef Target[float_t] cp_RCS_Target(target, mesh_module):
11151115
target["skip_diffusion"] = target["is_ground"]
11161116
_warn_deprecated_parameter("is_ground", "skip_diffusion")
11171117

1118-
return Target[float_t](&points_mv[0, 0],
1118+
targets_manager[0].AddTarget(&points_mv[0, 0],
11191119
&cells_mv[0, 0],
11201120
<int_t> cells_mv.shape[0],
11211121
Vec3[float_t](&origin_mv[0]),

src/radarsimpy/simulator_lidar.pyx

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,14 @@ This module provides tools for simulating a lidar system in complex 3D environme
2222
"""
2323

2424
# Core imports
25+
from libcpp.memory cimport shared_ptr, make_shared
2526
from libcpp cimport bool
2627
import numpy as np
2728
cimport numpy as np
2829
cimport cython
2930

3031
# RadarSimX imports
31-
from radarsimpy.includes.radarsimc cimport Target, LidarSimulator
32+
from radarsimpy.includes.radarsimc cimport Target, LidarSimulator, TargetsManager
3233
from radarsimpy.includes.radarsimc cimport Mem_Copy
3334
from radarsimpy.includes.rsvector cimport Vec3
3435
from radarsimpy.includes.type_def cimport float_t, int_t, vector
@@ -98,7 +99,7 @@ cpdef sim_lidar(lidar, targets, frame_time=0):
9899
"""
99100
cdef LidarSimulator[float_t] lidar_sim_c
100101

101-
cdef vector[Target[float_t]] targets_vt
102+
cdef shared_ptr[TargetsManager[float_t]] targets_manager = make_shared[TargetsManager[float_t]]()
102103

103104
# Memory view declarations
104105
cdef float_t[:, :] points_mv
@@ -134,16 +135,15 @@ cpdef sim_lidar(lidar, targets, frame_time=0):
134135
np.array(targets[idx_c].get("rotation_rate", (0, 0, 0)), dtype=np_float)
135136
)
136137

137-
# Add target to pointcloud
138-
targets_vt.emplace_back(Target[float_t](&points_mv[0, 0],
139-
&cells_mv[0, 0],
140-
<int_t> cells_mv.shape[0],
141-
Vec3[float_t](&origin_mv[0]),
142-
Vec3[float_t](&location_mv[0]),
143-
Vec3[float_t](&speed_mv[0]),
144-
Vec3[float_t](&rotation_mv[0]),
145-
Vec3[float_t](&rotation_rate_mv[0]),
146-
<bool> targets[idx_c].get("skip_diffusion", False)))
138+
targets_manager.get()[0].AddTargetSimple(&points_mv[0, 0],
139+
&cells_mv[0, 0],
140+
<int_t> cells_mv.shape[0],
141+
Vec3[float_t](&origin_mv[0]),
142+
Vec3[float_t](&location_mv[0]),
143+
Vec3[float_t](&speed_mv[0]),
144+
Vec3[float_t](&rotation_mv[0]),
145+
Vec3[float_t](&rotation_rate_mv[0]),
146+
<bool> targets[idx_c].get("skip_diffusion", False))
147147

148148
# Lidar parameters
149149
cdef float_t[:] phi_mv = np.radians(np.array(lidar["phi"], dtype=np_float))
@@ -157,7 +157,7 @@ cpdef sim_lidar(lidar, targets, frame_time=0):
157157
Mem_Copy(&theta_mv[0], <int_t>(theta_mv.shape[0]), theta_vt)
158158

159159
# Perform ray tracing
160-
lidar_sim_c.Run(targets_vt,
160+
lidar_sim_c.Run(targets_manager,
161161
phi_vt,
162162
theta_vt,
163163
Vec3[float_t](&position_mv[0]))

src/radarsimpy/simulator_rcs.pyx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ This module provides tools for simulating and calculating the Radar Cross Sectio
2222
2323
"""
2424

25+
from libcpp.memory cimport shared_ptr, make_shared
2526
# Standard library imports
2627
import numpy as np
2728

@@ -32,7 +33,7 @@ cimport numpy as np
3233
# Local imports
3334
from radarsimpy.includes.rsvector cimport Vec3
3435
from radarsimpy.includes.type_def cimport vector
35-
from radarsimpy.includes.radarsimc cimport Target, RcsSimulator, IsFreeTier
36+
from radarsimpy.includes.radarsimc cimport Target, RcsSimulator, IsFreeTier, TargetsManager
3637
from radarsimpy.lib.cp_radarsimc cimport cp_RCS_Target
3738
from libcpp.complex cimport complex as cpp_complex
3839

@@ -128,7 +129,7 @@ cpdef sim_rcs(
128129
.format(len(targets))
129130
)
130131

131-
cdef vector[Target[float]] targets_vt
132+
cdef shared_ptr[TargetsManager[float]] targets_manager = make_shared[TargetsManager[float]]()
132133
cdef Vec3[cpp_complex[double]] inc_pol_cpp
133134
cdef Vec3[cpp_complex[double]] obs_pol_cpp
134135

@@ -188,7 +189,7 @@ cpdef sim_rcs(
188189
# Process targets
189190
mesh_module = import_mesh_module()
190191
for idx_c in range(0, len(targets)):
191-
targets_vt.push_back(cp_RCS_Target(targets[idx_c], mesh_module))
192+
cp_RCS_Target(targets[idx_c], mesh_module, targets_manager.get())
192193

193194
# Convert angles to radians
194195
inc_phi_rad = np.radians(inc_phi)
@@ -226,7 +227,7 @@ cpdef sim_rcs(
226227
cdef RcsSimulator[double] rcs_sim_c
227228

228229
cdef vector[double] rcs_vect = rcs_sim_c.Run(
229-
targets_vt,
230+
targets_manager,
230231
inc_dir,
231232
obs_dir,
232233
inc_pol_cpp,

0 commit comments

Comments
 (0)