Use smart pointers for detector/tracker

This commit is contained in:
30hours 2024-09-10 13:12:59 +00:00
parent 904a8381f8
commit 03fcf0cc18
9 changed files with 26 additions and 28 deletions

View file

@ -32,6 +32,7 @@
#include <sys/time.h>
#include <signal.h>
#include <atomic>
#include <memory>
#include <iostream>
Capture *CAPTURE_POINTER = NULL;
@ -102,10 +103,10 @@ int main(int argc, char **argv)
IqData *x = new IqData(nSamples);
IqData *y = new IqData(nSamples);
Map<std::complex<double>> *map;
Detection *detection;
Detection *detection1;
Detection *detection2;
Track *track;
std::unique_ptr<Detection> detection;
std::unique_ptr<Detection> detection1;
std::unique_ptr<Detection> detection2;
std::unique_ptr<Track> track;
// setup fftw multithread
if (fftw_init_threads() == 0)
@ -265,15 +266,15 @@ int main(int argc, char **argv)
if (isDetection)
{
detection1 = cfarDetector1D->process(map);
detection2 = centroid->process(detection1);
detection = interpolate->process(detection2, map);
detection2 = centroid->process(detection1.get());
detection = interpolate->process(detection2.get(), map);
timing_helper(timing_name, timing_time, time, "detector");
}
// tracker process
if (isTracker)
{
track = tracker->process(detection, time[0]/1000);
track = tracker->process(detection.get(), time[0]/1000);
timing_helper(timing_name, timing_time, time, "tracker");
}
@ -296,9 +297,6 @@ int main(int argc, char **argv)
detectionJson = detection->to_json(time[0]/1000);
detectionJson = detection->delay_bin_to_km(detectionJson, fs);
socket_detection.sendData(detectionJson);
delete detection;
delete detection1;
delete detection2;
}
// output tracker data

View file

@ -16,7 +16,7 @@ Centroid::~Centroid()
{
}
Detection *Centroid::process(Detection *x)
std::unique_ptr<Detection> Centroid::process(Detection *x)
{
// store detections temporarily
std::vector<double> delay, doppler, snr;
@ -69,7 +69,5 @@ Detection *Centroid::process(Detection *x)
}
// create detection
Detection *detection = new Detection(delay2, doppler2, snr2);
return detection;
return std::make_unique<Detection>(delay2, doppler2, snr2);
}

View file

@ -9,6 +9,7 @@
#include "data/Detection.h"
#include <stdint.h>
#include <memory>
class Centroid
{
@ -40,7 +41,7 @@ public:
/// @brief Implement the 1D CFAR detector.
/// @param x Detections from the 1D CFAR detector.
/// @return Centroided detections.
Detection *process(Detection *x);
std::unique_ptr<Detection> process(Detection *x);
};
#endif

View file

@ -20,7 +20,7 @@ CfarDetector1D::~CfarDetector1D()
{
}
Detection *CfarDetector1D::process(Map<std::complex<double>> *x)
std::unique_ptr<Detection> CfarDetector1D::process(Map<std::complex<double>> *x)
{
int32_t nDelayBins = x->get_nCols();
int32_t nDopplerBins = x->get_nRows();
@ -96,7 +96,5 @@ Detection *CfarDetector1D::process(Map<std::complex<double>> *x)
}
// create detection
Detection *detection = new Detection(delay, doppler, snr);
return detection;
return std::make_unique<Detection>(delay, doppler, snr);
}

View file

@ -12,6 +12,7 @@
#include "data/Detection.h"
#include <stdint.h>
#include <complex>
#include <memory>
class CfarDetector1D
{
@ -51,7 +52,7 @@ public:
/// @brief Implement the 1D CFAR detector.
/// @param x Ambiguity map data of IQ samples.
/// @return Detections from the 1D CFAR detector.
Detection *process(Map<std::complex<double>> *x);
std::unique_ptr<Detection> process(Map<std::complex<double>> *x);
};
#endif

View file

@ -17,7 +17,7 @@ Interpolate::~Interpolate()
{
}
Detection *Interpolate::process(Detection *x, Map<std::complex<double>> *y)
std::unique_ptr<Detection> Interpolate::process(Detection *x, Map<std::complex<double>> *y)
{
// store detections temporarily
std::vector<double> delay, doppler, snr;
@ -87,7 +87,5 @@ Detection *Interpolate::process(Detection *x, Map<std::complex<double>> *y)
}
// create detection
Detection *detection = new Detection(delay2, doppler2, snr2);
return detection;
return std::make_unique<Detection>(delay2, doppler2, snr2);
}

View file

@ -14,6 +14,8 @@
#include "data/Map.h"
#include "data/Detection.h"
#include <memory>
class Interpolate
{
private:
@ -40,7 +42,7 @@ public:
/// @brief Implement the 1D CFAR detector.
/// @param x Detections from the 1D CFAR detector.
/// @return Interpolated detections.
Detection *process(Detection *x, Map<std::complex<double>> *y);
std::unique_ptr<Detection> process(Detection *x, Map<std::complex<double>> *y);
};
#endif

View file

@ -28,7 +28,7 @@ Tracker::~Tracker()
{
}
Track *Tracker::process(Detection *detection, uint64_t currentTime)
std::unique_ptr<Track> Tracker::process(Detection *detection, uint64_t currentTime)
{
doNotInitiate.clear();
for (size_t i = 0; i < detection->get_nDetections(); i++)
@ -46,7 +46,7 @@ Track *Tracker::process(Detection *detection, uint64_t currentTime)
}
initiate(detection);
return &track;
return std::make_unique<Track>(track);
}
void Tracker::update(Detection *detection, uint64_t current)

View file

@ -13,7 +13,9 @@
#include "data/Detection.h"
#include "data/Track.h"
#include <stdint.h>
#include <memory>
class Tracker
{
@ -72,7 +74,7 @@ public:
/// @param detection Detection data for last CPI.
/// @param timestamp POSIX timestamp (ms).
/// @return Pointer to track data.
Track *process(Detection *detection, uint64_t timestamp);
std::unique_ptr<Track> process(Detection *detection, uint64_t timestamp);
/// @brief Update tracks by associating detections.
/// @param detection Detection data for last CPI.