Skip to content

Commit 4458aaf

Browse files
committed
Refactor radar configuration to use shared_ptr
Replaces the cp_ConfigureRadar function with cp_Radar, which returns a shared_ptr to the Radar object. Updates usage in simulator_radar.pyx and related Cython interface files to improve memory management and simplify radar object creation.
1 parent 91e8161 commit 4458aaf

File tree

4 files changed

+15
-21
lines changed

4 files changed

+15
-21
lines changed

src/radarsimpy/includes/radarsimc.pxd

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -261,14 +261,6 @@ cdef extern from "radar.hpp":
261261
vector[Vec3[L]] & rotation_array, # Platform orientations
262262
Vec3[L] rotrate_array) except + # Platform rotation rates
263263

264-
void Configure(Transmitter[H, L] & tx, # Transmitter configuration
265-
Receiver[L] & rx, # Receiver configuration
266-
vector[H] & frame_start_time, # Frame timing array (s)
267-
vector[Vec3[L]] & location_array, # Platform locations
268-
Vec3[L] speed_array, # Platform velocity
269-
vector[Vec3[L]] & rotation_array, # Platform orientations
270-
Vec3[L] rotrate_array) except + # Platform rotation rates
271-
272264
# Memory management for baseband data
273265
void InitBaseband(H *bb_real, # Real baseband buffer
274266
H *bb_imag) except + # Imaginary baseband buffer

src/radarsimpy/lib/cp_radarsimc.pxd

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ from radarsimpy.includes.radarsimc cimport TargetsManager
3636
from radarsimpy.includes.radarsimc cimport PointsManager
3737
from radarsimpy.includes.type_def cimport float_t, int_t
3838
from libcpp.complex cimport complex as cpp_complex
39+
from libcpp.memory cimport shared_ptr
3940

4041

4142
# ============================================================================
@@ -48,7 +49,7 @@ cdef void cp_AddPoint(location, speed, rcs, phase, shape, PointsManager[float_t]
4849
# Create a Radar system object for simulation
4950
# Converts Python radar config to C++ with complete transmitter/receiver setup
5051
# Raises ValueError for invalid config, RuntimeError for setup failures
51-
cdef void cp_ConfigureRadar(radar, frame_start_time, Radar[double, float_t] * cptr_radar) except *
52+
cdef shared_ptr[Radar[double, float_t]] cp_Radar(radar, frame_start_time) except *
5253

5354
# Create a Target object specifically optimized for RCS calculations
5455
# Simplified target object without full dynamic simulation requirements

src/radarsimpy/lib/cp_radarsimc.pyx

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ cimport cython
2828
cimport numpy as np
2929
from libcpp.complex cimport complex as cpp_complex
3030
from libcpp cimport bool
31+
from libcpp.memory cimport shared_ptr, make_shared
3132

3233
# Local imports
3334
from radarsimpy.includes.radarsimc cimport (
@@ -530,7 +531,7 @@ cdef RxChannel[float_t] cp_RxChannel(rx,
530531
@cython.cdivision(True)
531532
@cython.boundscheck(False)
532533
@cython.wraparound(False)
533-
cdef void cp_ConfigureRadar(radar, frame_start_time, Radar[double, float_t] * cptr_radar):
534+
cdef shared_ptr[Radar[double, float_t]] cp_Radar(radar, frame_start_time):
534535
"""
535536
cp_Radar(radar, frame_start_time)
536537
@@ -666,13 +667,13 @@ cdef void cp_ConfigureRadar(radar, frame_start_time, Radar[double, float_t] * cp
666667
spd_vt = Vec3[float_t](<float_t>radar.radar_prop["speed"][0], <float_t>radar.radar_prop["speed"][1], <float_t>radar.radar_prop["speed"][2])
667668
rrt_vt = Vec3[float_t](<float_t>radar.radar_prop["rotation_rate"][0], <float_t>radar.radar_prop["rotation_rate"][1], <float_t>radar.radar_prop["rotation_rate"][2])
668669

669-
cptr_radar[0].Configure(tx_c,
670-
rx_c,
671-
t_frame_vt,
672-
loc_vt,
673-
spd_vt,
674-
rot_vt,
675-
rrt_vt)
670+
return make_shared[Radar[double, float_t]](tx_c,
671+
rx_c,
672+
t_frame_vt,
673+
loc_vt,
674+
spd_vt,
675+
rot_vt,
676+
rrt_vt)
676677

677678
@cython.cdivision(True)
678679
@cython.boundscheck(False)

src/radarsimpy/simulator_radar.pyx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ from radarsimpy.includes.radarsimc cimport (
5757

5858
# RadarSimX library components
5959
from radarsimpy.lib.cp_radarsimc cimport (
60-
cp_ConfigureRadar,
60+
cp_Radar,
6161
cp_AddTarget,
6262
cp_AddPoint
6363
)
@@ -339,7 +339,7 @@ cpdef sim_radar(radar, targets, frame_time=None, density=1, level=None, interf=N
339339

340340
cp_AddPoint(loc, spd, rcs, phs, ts_shape, points_manager.get())
341341

342-
cp_ConfigureRadar(radar, frame_start_time, radar_c.get())
342+
radar_c = cp_Radar(radar, frame_start_time)
343343

344344
cdef double[:,:,::1] bb_real = np.empty(ts_shape, order='C', dtype=np.float64)
345345
cdef double[:,:,::1] bb_imag = np.empty(ts_shape, order='C', dtype=np.float64)
@@ -446,8 +446,8 @@ cpdef sim_radar(radar, targets, frame_time=None, density=1, level=None, interf=N
446446
if interf is not None:
447447
# Use main radar frame time if interference frame time not specified
448448
interf_frame_start_time = np.array(interf.time_prop["frame_start_time"], dtype=np.float64)
449-
cp_ConfigureRadar(interf, interf_frame_start_time, interf_radar_c.get())
450-
449+
interf_radar_c = cp_Radar(interf, interf_frame_start_time)
450+
451451
# Initialize baseband for interference calculation
452452
radar_c.get()[0].InitBaseband(&bb_real[0][0][0], &bb_imag[0][0][0])
453453

0 commit comments

Comments
 (0)