//
// Created by zx on 23-11-28.
//

#include "transitData.h"

TransitData::TransitData() {
}

void TransitData::setImage(cv::Mat image, int id) {
    if (id < 0 || id >= DeviceAzimuth::DEVICE_AZIMUTH_MAX) return;
    mutex_.lock();
    image_[id] = image.clone();
    mutex_.unlock();
}

void TransitData::setImageCL(cv::Mat &image, int id) {
    if (id < 0 || id >= DeviceAzimuth::DEVICE_AZIMUTH_MAX) return;
    mutex_.lock();
    imageCL_[id] = image.clone();
    mutex_.unlock();
}

void TransitData::setMask(std::vector<cv::Point> mask, int id) {
    if (id < 0 || id >= DeviceAzimuth::DEVICE_AZIMUTH_MAX) return;
    mutex_.lock();
    mask_[id] = mask;
    mutex_.unlock();
}

void TransitData::setMeasureInfo(MeasureInfo info) {
    mutex_.lock();
    measureInfo_ = info;
    mutex_.unlock();
}

bool TransitData::getImage(cv::Mat &image, int id, float timeout) {
    if (id < 0 || id >= DeviceAzimuth::DEVICE_AZIMUTH_MAX) return false;
    if (image_[id].timeout(timeout))
        return false;
    mutex_.lock();
    image = image_[id]();
    mutex_.unlock();
    return true;
}

bool TransitData::getImageCL(cv::Mat &image, int id, float timeout) {
    if (id < 0 || id >= DeviceAzimuth::DEVICE_AZIMUTH_MAX) return false;
    if (imageCL_[id].timeout(timeout))
        return false;
    mutex_.lock();
    image = imageCL_[id]().clone();
    mutex_.unlock();
    return true;
}

bool TransitData::getMask(std::vector<cv::Point> &mask, int id, float timeout) {
    if (id < 0 || id >= DeviceAzimuth::DEVICE_AZIMUTH_MAX) return false;
    if (mask_[id].timeout(timeout))
        return false;
    mask = mask_[id]();
    return true;
}

bool TransitData::getMeasureInfo(MeasureInfo &info, float timeout) {
    if (measureInfo_.timeout(timeout))
        return false;
    mutex_.lock();
    info = measureInfo_();
    mutex_.unlock();
    return true;
}
