Commit 774258dd authored by Alejandro Homs Puron's avatar Alejandro Homs Puron
Browse files

[SIM] Refactor hw::acquisition::hw_prepare: isolate roi/bin/flip from generator

parent c8e5b1e2
......@@ -77,10 +77,32 @@ namespace detectors::simulator::hw
}
};
struct image_flipper
{
image_flipper(flip_enum f) : flip(f) {}
template <typename S, typename D>
void operator()(S const& src, D const& dst) const
{
switch (flip) {
case flip_enum::left_right:
gil::copy_pixels(gil::flipped_left_right_view(src), dst);
break;
case flip_enum::up_down:
gil::copy_pixels(gil::flipped_up_down_view(src), dst);
break;
default:
gil::copy_pixels(src, dst);
}
}
flip_enum flip;
};
acquisition::acq_info_t acquisition::impl::hw_prepare(acquisition::acq_params_t const& params)
{
rectangle_t roi{{0, 0}, {m_init_params.width, m_init_params.height}}; // A full frame ROI by default
auto center = roi.dimensions / 2; // The center of the full frame
point_t image_dims = {m_init_params.width, m_init_params.height};
rectangle_t roi{{0, 0}, image_dims}; // A full frame ROI by default
//Preconditions for ROI
if (!params.img.roi.is_degenerated()) {
......@@ -97,19 +119,39 @@ namespace detectors::simulator::hw
m_expo_time = params.acq.expo_time;
m_latency_time = params.acq.latency_time;
// ROI -> Binning -> Flip
//
// Compute the frame dimensions
roi.dimensions.x /= params.img.binning.x;
roi.dimensions.y /= params.img.binning.y;
// Resize the circular buffer
m_buffer.resize(std::min(params.det.nb_prefetch_frames, params.xfer.time_slice.count));
auto generator_visitor = [flip = params.img.flip, generator_type = params.det.generator_type,
peaks = params.det.peaks, grow_factor = params.det.grow_factor,
frame_nr = params.xfer.time_slice.start, frame_stride = params.xfer.time_slice.stride,
roi, center](auto const& view) mutable {
auto apply_hw_image_proc = [roi, bin = params.img.binning, flip = params.img.flip](auto const& src,
auto const& dst) {
// ROI -> Binning -> Flip
//
// Compute the frame dimensions
point_t binned_roi_dims(roi.dimensions.x / bin.x, roi.dimensions.y / bin.y);
using SrcView = std::decay_t<decltype(src)>;
SrcView src_roi(binned_roi_dims, src.xy_at(roi.topleft));
// TODO: perform image binning
image_flipper flipper(flip);
flipper(src_roi, dst);
};
auto apply_hw_proc_to_generator = [image_dims, apply_hw_image_proc,
chan_conv = channel_converter_round()](auto&& gen, auto const& view) {
auto src = make_generated_view(image_dims, gen);
using PixelType = typename std::decay_t<decltype(view)>::value_type;
auto conv = boost::gil::color_converted_view<PixelType>(src, chan_conv);
apply_hw_image_proc(conv, view);
};
auto generator_visitor = [generator_type = params.det.generator_type, peaks = params.det.peaks,
grow_factor = params.det.grow_factor, frame_nr = params.xfer.time_slice.start,
frame_stride = params.xfer.time_slice.stride, image_dims,
apply_hw_proc_to_generator](auto const& view) mutable {
auto center = image_dims / 2; // The center of the full frame
// If no peak specified, add one peak in the center
if (peaks.empty())
peaks.emplace_back(center.x, center.y, 128.0, 100.0);
......@@ -118,39 +160,13 @@ namespace detectors::simulator::hw
case generator_type_enum::gauss: {
generate_gauss func(frame_nr, grow_factor);
func.m_peaks = peaks;
generate_gauss_locator_t loc(roi.topleft, gil::point_t(1, 1), func);
generate_gauss_view_t src(roi.dimensions, loc);
switch (flip) {
case flip_enum::left_right:
gil::copy_and_convert_pixels(gil::flipped_left_right_view(src), view, channel_converter_round());
break;
case flip_enum::up_down:
gil::copy_and_convert_pixels(gil::flipped_up_down_view(src), view, channel_converter_round());
break;
default:
gil::copy_and_convert_pixels(src, view, channel_converter_round());
}
apply_hw_proc_to_generator(func, view);
break;
}
case generator_type_enum::diffraction: {
generate_diffraction func(frame_nr, grow_factor, center.x, center.y);
func.m_peaks = peaks;
generate_diffraction_locator_t loc(roi.topleft, gil::point_t(1, 1), func);
generate_diffraction_view_t src(roi.dimensions, loc);
switch (flip) {
case flip_enum::left_right:
gil::copy_and_convert_pixels(gil::flipped_left_right_view(src), view, channel_converter_round());
break;
case flip_enum::up_down:
gil::copy_and_convert_pixels(gil::flipped_up_down_view(src), view, channel_converter_round());
break;
default:
gil::copy_and_convert_pixels(src, view, channel_converter_round());
}
apply_hw_proc_to_generator(func, view);
break;
}
default:
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment