Improve plotting
This commit is contained in:
@@ -172,31 +172,6 @@ inline std::pair<const uint8_t *, size_t> GetCBORByteString(CborValue &value) {
|
||||
return {ptr, len};
|
||||
}
|
||||
|
||||
inline ROIRectangle GetROIRectangle(CborValue &value) {
|
||||
ROIRectangle ret{};
|
||||
CborValue map_value;
|
||||
if (GetCBORMapLen(value) != 4)
|
||||
throw JFJochException(JFJochExceptionCategory::CBORError, "ROI Rectangle must be 4 values");
|
||||
|
||||
cborErr(cbor_value_enter_container(&value, &map_value));
|
||||
while (!cbor_value_at_end(&map_value)) {
|
||||
auto key = GetCBORString(map_value);
|
||||
if (key == "x_min")
|
||||
ret.x_min = GetCBORUInt(map_value);
|
||||
else if (key == "x_max")
|
||||
ret.x_max = GetCBORUInt(map_value);
|
||||
else if (key == "y_min")
|
||||
ret.y_min = GetCBORUInt(map_value);
|
||||
else if (key == "y_max")
|
||||
ret.y_max = GetCBORUInt(map_value);
|
||||
else
|
||||
throw JFJochException(JFJochExceptionCategory::CBORError, "Unexpected entry in ROI");
|
||||
}
|
||||
cborErr(cbor_value_leave_container(&value, &map_value));
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
inline void GetCBORFloatArray(CborValue &value, std::vector<float> &v) {
|
||||
if (GetCBORTag(value) != TagFloatLE)
|
||||
throw JFJochException(JFJochExceptionCategory::CBORError, "Incorrect array type tag");
|
||||
@@ -493,8 +468,8 @@ bool CBORStream2Deserializer::ProcessImageMessageElement(CborValue &value) {
|
||||
data_message.bkg_estimate = GetCBORFloat(value);
|
||||
else if (key == "adu_histogram")
|
||||
GetCBORUInt64Array(value, data_message.adu_histogram);
|
||||
else if (key == "roi_sum")
|
||||
data_message.roi_sum = GetCBORInt(value);
|
||||
else if (key == "roi_integrals")
|
||||
ProcessROIElementMap(value);
|
||||
else {
|
||||
if (cbor_value_is_tag(&value))
|
||||
cbor_value_advance(&value);
|
||||
@@ -603,6 +578,41 @@ void CBORStream2Deserializer::ProcessUnitCellElement(CborValue &value) {
|
||||
|
||||
start_message.unit_cell = unit_cell;
|
||||
}
|
||||
void CBORStream2Deserializer::ProcessROIElementMap(CborValue &value) {
|
||||
CborValue map_value;
|
||||
cborErr(cbor_value_enter_container(&value, &map_value));
|
||||
while (! cbor_value_at_end(&map_value))
|
||||
ProcessROIElement(map_value);
|
||||
cborErr(cbor_value_leave_container(&value, &map_value));
|
||||
}
|
||||
|
||||
void CBORStream2Deserializer::ProcessROIElement(CborValue &value) {
|
||||
ROIMessage msg{};
|
||||
|
||||
// key
|
||||
const std::string roi_name = GetCBORString(value);
|
||||
|
||||
// value
|
||||
CborValue map_value;
|
||||
cborErr(cbor_value_enter_container(&value, &map_value));
|
||||
while (! cbor_value_at_end(&map_value)) {
|
||||
auto key = GetCBORString(map_value);
|
||||
|
||||
if (key == "sum")
|
||||
msg.sum = GetCBORInt(map_value);
|
||||
else if (key == "sum_square")
|
||||
msg.sum_square = GetCBORUInt(map_value);
|
||||
else if (key == "max_count")
|
||||
msg.max_count = GetCBORInt(map_value);
|
||||
else if (key == "pixels")
|
||||
msg.pixels = GetCBORUInt(map_value);
|
||||
else
|
||||
cbor_value_advance(&map_value);
|
||||
}
|
||||
cborErr(cbor_value_leave_container(&value, &map_value));
|
||||
|
||||
data_message.roi[roi_name] = msg;
|
||||
}
|
||||
|
||||
void CBORStream2Deserializer::ProcessStartUserData(CborValue &value) {
|
||||
try {
|
||||
@@ -637,6 +647,10 @@ void CBORStream2Deserializer::ProcessStartUserData(CborValue &value) {
|
||||
}
|
||||
if (j.contains("space_group_number"))
|
||||
start_message.space_group_number = j["space_group_number"];
|
||||
if (j.contains("gain_file_names"))
|
||||
start_message.gain_file_names = j["gain_file_names"];
|
||||
if (j.contains("roi_names"))
|
||||
start_message.roi_names = j["roi_names"];
|
||||
|
||||
} catch (const std::exception &e) {
|
||||
throw JFJochException(JFJochExceptionCategory::CBORError, "Cannot parse user_data as valid JSON " + std::string(e.what()));
|
||||
@@ -742,10 +756,6 @@ bool CBORStream2Deserializer::ProcessStartMessageElement(CborValue &value) {
|
||||
start_message.storage_cell_number = GetCBORUInt(value);
|
||||
else if (key == "storage_cell_delay")
|
||||
start_message.storage_cell_delay_ns = GetRational(value).first;
|
||||
else if (key == "roi_sum_area")
|
||||
start_message.roi_summation_area = GetROIRectangle(value);
|
||||
else if (key == "gain_file_names")
|
||||
GetCBORStringArray(value, start_message.gain_file_names);
|
||||
else if (key == "calibration")
|
||||
ProcessCalibration(value);
|
||||
else {
|
||||
|
||||
Reference in New Issue
Block a user