mirror of
https://github.com/30hours/blah2.git
synced 2024-11-08 12:25:42 +00:00
Use smart pointers for detector/tracker
This commit is contained in:
parent
904a8381f8
commit
03fcf0cc18
9 changed files with 26 additions and 28 deletions
|
@ -32,6 +32,7 @@
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
#include <atomic>
|
#include <atomic>
|
||||||
|
#include <memory>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
Capture *CAPTURE_POINTER = NULL;
|
Capture *CAPTURE_POINTER = NULL;
|
||||||
|
@ -102,10 +103,10 @@ int main(int argc, char **argv)
|
||||||
IqData *x = new IqData(nSamples);
|
IqData *x = new IqData(nSamples);
|
||||||
IqData *y = new IqData(nSamples);
|
IqData *y = new IqData(nSamples);
|
||||||
Map<std::complex<double>> *map;
|
Map<std::complex<double>> *map;
|
||||||
Detection *detection;
|
std::unique_ptr<Detection> detection;
|
||||||
Detection *detection1;
|
std::unique_ptr<Detection> detection1;
|
||||||
Detection *detection2;
|
std::unique_ptr<Detection> detection2;
|
||||||
Track *track;
|
std::unique_ptr<Track> track;
|
||||||
|
|
||||||
// setup fftw multithread
|
// setup fftw multithread
|
||||||
if (fftw_init_threads() == 0)
|
if (fftw_init_threads() == 0)
|
||||||
|
@ -265,15 +266,15 @@ int main(int argc, char **argv)
|
||||||
if (isDetection)
|
if (isDetection)
|
||||||
{
|
{
|
||||||
detection1 = cfarDetector1D->process(map);
|
detection1 = cfarDetector1D->process(map);
|
||||||
detection2 = centroid->process(detection1);
|
detection2 = centroid->process(detection1.get());
|
||||||
detection = interpolate->process(detection2, map);
|
detection = interpolate->process(detection2.get(), map);
|
||||||
timing_helper(timing_name, timing_time, time, "detector");
|
timing_helper(timing_name, timing_time, time, "detector");
|
||||||
}
|
}
|
||||||
|
|
||||||
// tracker process
|
// tracker process
|
||||||
if (isTracker)
|
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");
|
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->to_json(time[0]/1000);
|
||||||
detectionJson = detection->delay_bin_to_km(detectionJson, fs);
|
detectionJson = detection->delay_bin_to_km(detectionJson, fs);
|
||||||
socket_detection.sendData(detectionJson);
|
socket_detection.sendData(detectionJson);
|
||||||
delete detection;
|
|
||||||
delete detection1;
|
|
||||||
delete detection2;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// output tracker data
|
// output tracker data
|
||||||
|
|
|
@ -16,7 +16,7 @@ Centroid::~Centroid()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
Detection *Centroid::process(Detection *x)
|
std::unique_ptr<Detection> Centroid::process(Detection *x)
|
||||||
{
|
{
|
||||||
// store detections temporarily
|
// store detections temporarily
|
||||||
std::vector<double> delay, doppler, snr;
|
std::vector<double> delay, doppler, snr;
|
||||||
|
@ -69,7 +69,5 @@ Detection *Centroid::process(Detection *x)
|
||||||
}
|
}
|
||||||
|
|
||||||
// create detection
|
// create detection
|
||||||
Detection *detection = new Detection(delay2, doppler2, snr2);
|
return std::make_unique<Detection>(delay2, doppler2, snr2);
|
||||||
|
|
||||||
return detection;
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
|
|
||||||
#include "data/Detection.h"
|
#include "data/Detection.h"
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
class Centroid
|
class Centroid
|
||||||
{
|
{
|
||||||
|
@ -40,7 +41,7 @@ public:
|
||||||
/// @brief Implement the 1D CFAR detector.
|
/// @brief Implement the 1D CFAR detector.
|
||||||
/// @param x Detections from the 1D CFAR detector.
|
/// @param x Detections from the 1D CFAR detector.
|
||||||
/// @return Centroided detections.
|
/// @return Centroided detections.
|
||||||
Detection *process(Detection *x);
|
std::unique_ptr<Detection> process(Detection *x);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -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 nDelayBins = x->get_nCols();
|
||||||
int32_t nDopplerBins = x->get_nRows();
|
int32_t nDopplerBins = x->get_nRows();
|
||||||
|
@ -96,7 +96,5 @@ Detection *CfarDetector1D::process(Map<std::complex<double>> *x)
|
||||||
}
|
}
|
||||||
|
|
||||||
// create detection
|
// create detection
|
||||||
Detection *detection = new Detection(delay, doppler, snr);
|
return std::make_unique<Detection>(delay, doppler, snr);
|
||||||
|
|
||||||
return detection;
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,6 +12,7 @@
|
||||||
#include "data/Detection.h"
|
#include "data/Detection.h"
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <complex>
|
#include <complex>
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
class CfarDetector1D
|
class CfarDetector1D
|
||||||
{
|
{
|
||||||
|
@ -51,7 +52,7 @@ public:
|
||||||
/// @brief Implement the 1D CFAR detector.
|
/// @brief Implement the 1D CFAR detector.
|
||||||
/// @param x Ambiguity map data of IQ samples.
|
/// @param x Ambiguity map data of IQ samples.
|
||||||
/// @return Detections from the 1D CFAR detector.
|
/// @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
|
#endif
|
||||||
|
|
|
@ -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
|
// store detections temporarily
|
||||||
std::vector<double> delay, doppler, snr;
|
std::vector<double> delay, doppler, snr;
|
||||||
|
@ -87,7 +87,5 @@ Detection *Interpolate::process(Detection *x, Map<std::complex<double>> *y)
|
||||||
}
|
}
|
||||||
|
|
||||||
// create detection
|
// create detection
|
||||||
Detection *detection = new Detection(delay2, doppler2, snr2);
|
return std::make_unique<Detection>(delay2, doppler2, snr2);
|
||||||
|
|
||||||
return detection;
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,6 +14,8 @@
|
||||||
#include "data/Map.h"
|
#include "data/Map.h"
|
||||||
#include "data/Detection.h"
|
#include "data/Detection.h"
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
class Interpolate
|
class Interpolate
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
|
@ -40,7 +42,7 @@ public:
|
||||||
/// @brief Implement the 1D CFAR detector.
|
/// @brief Implement the 1D CFAR detector.
|
||||||
/// @param x Detections from the 1D CFAR detector.
|
/// @param x Detections from the 1D CFAR detector.
|
||||||
/// @return Interpolated detections.
|
/// @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
|
#endif
|
||||||
|
|
|
@ -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();
|
doNotInitiate.clear();
|
||||||
for (size_t i = 0; i < detection->get_nDetections(); i++)
|
for (size_t i = 0; i < detection->get_nDetections(); i++)
|
||||||
|
@ -46,7 +46,7 @@ Track *Tracker::process(Detection *detection, uint64_t currentTime)
|
||||||
}
|
}
|
||||||
initiate(detection);
|
initiate(detection);
|
||||||
|
|
||||||
return &track;
|
return std::make_unique<Track>(track);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Tracker::update(Detection *detection, uint64_t current)
|
void Tracker::update(Detection *detection, uint64_t current)
|
||||||
|
|
|
@ -13,7 +13,9 @@
|
||||||
|
|
||||||
#include "data/Detection.h"
|
#include "data/Detection.h"
|
||||||
#include "data/Track.h"
|
#include "data/Track.h"
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
class Tracker
|
class Tracker
|
||||||
{
|
{
|
||||||
|
@ -72,7 +74,7 @@ public:
|
||||||
/// @param detection Detection data for last CPI.
|
/// @param detection Detection data for last CPI.
|
||||||
/// @param timestamp POSIX timestamp (ms).
|
/// @param timestamp POSIX timestamp (ms).
|
||||||
/// @return Pointer to track data.
|
/// @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.
|
/// @brief Update tracks by associating detections.
|
||||||
/// @param detection Detection data for last CPI.
|
/// @param detection Detection data for last CPI.
|
||||||
|
|
Loading…
Reference in a new issue