DiffractionExperiment: Save ROI

This commit is contained in:
2023-06-23 21:04:15 +02:00
parent 9089794d46
commit 2caba97bb2
5 changed files with 189 additions and 105 deletions

View File

@@ -1202,3 +1202,31 @@ float DiffractionExperiment::GetPolarizationFactor() const {
return dataset.rad_int_polarization_factor();
}
DiffractionExperiment &DiffractionExperiment::ApplyROI(bool input) {
internal.set_roi_apply(input);
return *this;
}
DiffractionExperiment &DiffractionExperiment::AddROIRectangle(int32_t x, int32_t y, int32_t width, int32_t height) {
auto *tmp = internal.add_roi_rectangle();
tmp->set_x0(x);
tmp->set_y0(y);
tmp->set_width(width);
tmp->set_height(height);
return *this;
}
DiffractionExperiment &DiffractionExperiment::ClearROI() {
internal.clear_roi_rectangle();
return *this;
}
bool DiffractionExperiment::GetApplyROI() const {
return internal.roi_apply();
}
void DiffractionExperiment::SetupROIFilter(ROIFilter &filter) {
for (const auto& i: internal.roi_rectangle())
filter.SetRectangle(i.x0(), i.y0(), i.width(), i.height());
}

View File

@@ -18,6 +18,7 @@
#include "../frame_serialize/StartMessage.h"
#include "../frame_serialize/EndMessage.h"
#include "DetectorSetup.h"
#include "ROIFilter.h"
enum class DetectorMode : int {
Conversion, Raw, PedestalG0, PedestalG1, PedestalG2
@@ -221,6 +222,12 @@ public:
bool GetApplySolidAngleCorr() const;
bool GetApplyPolarizationCorr() const;
float GetPolarizationFactor() const;
DiffractionExperiment& ApplyROI(bool input);
DiffractionExperiment& AddROIRectangle(int32_t x, int32_t y, int32_t width, int32_t height);
DiffractionExperiment& ClearROI();
bool GetApplyROI() const;
void SetupROIFilter(ROIFilter& filter);
};
inline int64_t CalculateStride(const std::chrono::microseconds &frame_time, const std::chrono::microseconds &preview_time) {

View File

@@ -70,6 +70,13 @@ message Plot {
repeated float y = 2;
}
message ROIRectangle {
int32 x0 = 1;
int32 y0 = 2;
int32 width = 3;
int32 height = 4;
}
// DiffractionExperiment
message DatasetSettings {
@@ -183,6 +190,8 @@ message InternalSettings {
string instrument_name = 34;
string instrument_name_short = 35;
repeated ROIRectangle roi_rectangle = 36;
bool roi_apply = 37;
}

File diff suppressed because one or more lines are too long

View File

@@ -4,6 +4,7 @@
#include <catch2/catch.hpp>
#include "../common/ROIFilter.h"
#include "../common/DiffractionExperiment.h"
TEST_CASE("ROIFilter") {
int32_t width = 4;
@@ -135,4 +136,41 @@ TEST_CASE("ROIFilter_negative_start") {
CHECK(v[4 * width + 1] == 55);
CHECK(v[4 * width + 2] == 55);
CHECK(v[4 * width + 3] == 55);
}
TEST_CASE("ROIFilter_DiffractionExperiment_ApplyROI") {
DiffractionExperiment x(DetectorGeometry(1));
REQUIRE(!x.GetApplyROI());
x.ApplyROI(true);
REQUIRE(x.GetApplyROI());
}
TEST_CASE("ROIFilter_DiffractionExperiment") {
DiffractionExperiment x(DetectorGeometry(1));
x.Mode(DetectorMode::Raw);
x.AddROIRectangle(0, 0, 1024, 1024);
x.ClearROI();
x.AddROIRectangle(0, 0, 256, 256);
x.AddROIRectangle(768, 0, 256, 256);
std::vector<uint32_t> v(x.GetPixelsNum(), 1);
ROIFilter filter(x.GetXPixelsNum(), x.GetYPixelsNum());
x.SetupROIFilter(filter);
filter.Apply(v, (uint32_t) 55);
CHECK(v[ 0*1024 + 0] == 1);
CHECK(v[ 0*1024 + 255] == 1);
CHECK(v[ 0*1024 + 256] == 55);
CHECK(v[ 0*1024 + 767] == 55);
CHECK(v[ 0*1024 + 768] == 1);
CHECK(v[128*1024 + 255] == 1);
CHECK(v[128*1024 + 256] == 55);
CHECK(v[255*1024 + 255] == 1);
CHECK(v[256*1024 + 255] == 55);
CHECK(v[255*1024 + 767] == 55);
CHECK(v[255*1024 + 768] == 1);
}