Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
LimaGroup
Lima2
Commits
2fd67ecf
Commit
2fd67ecf
authored
Feb 24, 2022
by
Alejandro Homs Puron
Browse files
[SIM] Add loader image source
parent
6041c2c4
Changes
10
Hide whitespace changes
Inline
Side-by-side
detectors/simulator/include/lima/detectors/simulator/hw/enums.describe.hpp
View file @
2fd67ecf
...
...
@@ -17,6 +17,8 @@ namespace lima
{
namespace
detectors
::
simulator
::
hw
{
BOOST_DESCRIBE_ENUM
(
image_source_enum
,
generator
,
loader
)
using
boost
::
describe
::
operator
<<
;
using
boost
::
describe
::
operator
>>
;
...
...
detectors/simulator/include/lima/detectors/simulator/hw/enums.hpp
View file @
2fd67ecf
...
...
@@ -7,3 +7,17 @@
#pragma once
#include
<lima/detectors/simulator/hw/generator/enums.hpp>
namespace
lima
{
namespace
detectors
::
simulator
::
hw
{
/// Image source type
enum
class
image_source_enum
:
int
{
generator
,
loader
};
}
// namespace detectors::simulator::hw
}
// namespace lima
detectors/simulator/include/lima/detectors/simulator/hw/loader.hpp
0 → 100644
View file @
2fd67ecf
// Copyright (C) 2020 Alejandro Homs Puron, ESRF.
// Use, modification and distribution is subject to the Boost Software
// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
#pragma once
#include
<boost/gil/extension/dynamic_image/apply_operation.hpp>
#include
<lima/core/pixel.hpp>
#include
<lima/io/multi.hpp>
#include
<lima/io/hdf5.hpp>
#include
<lima/detectors/simulator/hw/loader/params.hpp>
namespace
lima
{
namespace
detectors
::
simulator
::
hw
::
loader
{
struct
loader
{
using
reader_t
=
io
::
multi
<
io
::
h5
::
reader
>
;
loader
(
exec_params
const
&
exec_pars
,
int
rank
,
int
nb_frames
)
:
m_reader
(
exec_pars
,
rank
,
nb_frames
),
m_dimensions
(
m_reader
.
dimensions
()),
m_pixel_type
(
m_reader
.
pixel_type
())
{
}
point_t
dimensions
()
{
return
m_dimensions
;
}
pixel_enum
pixel_type
()
{
return
m_pixel_type
;
}
// visitor will be called with generated image view
template
<
typename
Visitor
>
void
frame_getter_visit
(
int
frame_nr
,
Visitor
&&
visitor
)
{
auto
frame
=
m_reader
.
read_frame
(
frame_nr
);
boost
::
gil
::
apply_operation
(
const_view
(
frame
),
visitor
);
}
reader_t
m_reader
;
point_t
m_dimensions
;
pixel_enum
m_pixel_type
;
};
}
// namespace detectors::simulator::hw::loader
}
// namespace lima
detectors/simulator/include/lima/detectors/simulator/hw/loader/params.describe.hpp
0 → 100644
View file @
2fd67ecf
// Copyright (C) 2020 Alejandro Homs Puron, ESRF.
// Use, modification and distribution is subject to the Boost Software
// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
#pragma once
#include
<boost/describe/annotations.hpp>
#include
<boost/describe/io_structs.hpp>
#include
<lima/io/h5/params.describe.hpp>
#include
<lima/detectors/simulator/hw/loader/params.hpp>
namespace
lima
{
namespace
detectors
::
simulator
::
hw
::
loader
{
BOOST_DESCRIBE_STRUCT
(
exec_params
,
(
io
::
h5
::
reader
::
params_t
),
())
using
boost
::
describe
::
operator
<<
;
}
// namespace detectors::simulator::hw::loader
}
// namespace lima
detectors/simulator/include/lima/detectors/simulator/hw/loader/params.hpp
0 → 100644
View file @
2fd67ecf
// Copyright (C) 2020 Alejandro Homs Puron, ESRF.
// Use, modification and distribution is subject to the Boost Software
// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
#pragma once
#include
<vector>
#include
<lima/io/h5/reader.hpp>
namespace
lima
{
namespace
detectors
::
simulator
::
hw
::
loader
{
using
namespace
std
::
string_literals
;
/// Execution parameters: defined each time the loader is instantiated
struct
exec_params
:
io
::
h5
::
reader
::
params_t
// loading_params
{
};
}
// namespace detectors::simulator::hw::loader
}
// namespace lima
detectors/simulator/include/lima/detectors/simulator/hw/params.describe.hpp
View file @
2fd67ecf
...
...
@@ -12,6 +12,7 @@
#include
<lima/hw/params.describe.hpp>
#include
<lima/detectors/simulator/hw/generator/params.describe.hpp>
#include
<lima/detectors/simulator/hw/loader/params.describe.hpp>
#include
<lima/detectors/simulator/hw/enums.describe.hpp>
#include
<lima/detectors/simulator/hw/params.hpp>
...
...
@@ -27,13 +28,21 @@ namespace detectors::simulator::hw
(
doc
,
"Generator initialization parameters: defined once in the application"
))
// clang-format on
BOOST_DESCRIBE_STRUCT
(
detector_params
,
(),
(
generato
r
,
nb_prefetch_frames
))
BOOST_DESCRIBE_STRUCT
(
detector_params
,
(),
(
image_source
,
generator
,
loade
r
,
nb_prefetch_frames
))
// clang-format off
BOOST_ANNOTATE_MEMBER
(
detector_params
,
image_source
,
(
desc
,
"simulator image source"
),
(
doc
,
"The image source: [generator, loader]"
))
BOOST_ANNOTATE_MEMBER
(
detector_params
,
generator
,
(
desc
,
"generator exec params"
),
(
doc
,
"Generator execution paramaters: defined on each instantiation"
))
BOOST_ANNOTATE_MEMBER
(
detector_params
,
loader
,
(
desc
,
"loader exec params"
),
(
doc
,
"Loader execution paramaters: defined on each instantiation"
))
BOOST_ANNOTATE_MEMBER
(
detector_params
,
nb_prefetch_frames
,
(
desc
,
"nb prefetched frames"
),
(
doc
,
"Number of frames prefetched in the simulator circular buffer"
))
...
...
detectors/simulator/include/lima/detectors/simulator/hw/params.hpp
View file @
2fd67ecf
...
...
@@ -15,6 +15,7 @@
#include
<lima/detectors/simulator/hw/enums.hpp>
#include
<lima/detectors/simulator/hw/generator/params.hpp>
#include
<lima/detectors/simulator/hw/loader/params.hpp>
namespace
lima
{
...
...
@@ -29,7 +30,9 @@ namespace detectors::simulator::hw
/// Acquisition parameters specific to the detector
struct
detector_params
{
generator
::
exec_params
generator
;
//!< The generator parameters
image_source_enum
image_source
=
image_source_enum
::
generator
;
//!< The image source: [generator, loader]
generator
::
exec_params
generator
;
//!< The generator parameters
loader
::
exec_params
loader
;
//!< The loader parameters
std
::
size_t
nb_prefetch_frames
=
1
;
//!< The number of frames pre-computed (ring buffer)
};
...
...
detectors/simulator/python/simulator.cpp
View file @
2fd67ecf
...
...
@@ -11,6 +11,7 @@
#include
<fmt/format.h>
#include
<fmt/chrono.h>
#include
<fmt/filesystem.hpp>
#include
<fmt/ranges.h>
#include
<fmt/describe.hpp>
...
...
detectors/simulator/src/hw_acquisition.cpp
View file @
2fd67ecf
...
...
@@ -11,6 +11,7 @@
#include
<stdexcept>
#include
<thread>
#include
<vector>
#include
<optional>
#include
<boost/gil/typedefs.hpp>
#include
<boost/gil/algorithm.hpp>
...
...
@@ -21,6 +22,7 @@
#include
<lima/detectors/simulator/hw/acquisition.hpp>
#include
<lima/detectors/simulator/hw/generator.hpp>
#include
<lima/detectors/simulator/hw/loader.hpp>
//#include <lima/detectors/simulator/hw/detail/format_support.hpp>
using
namespace
std
::
string_literals
;
...
...
@@ -90,9 +92,21 @@ namespace detectors::simulator::hw
acquisition
::
acq_info_t
acquisition
::
impl
::
hw_prepare
(
acquisition
::
acq_params_t
const
&
params
)
{
generator
::
generator
gen
(
m_init_params
.
generator
,
params
.
det
.
generator
);
using
any_source_t
=
std
::
variant
<
generator
::
generator
,
loader
::
loader
>
;
auto
create_src
=
[
init_params
=
m_init_params
,
params
]()
->
any_source_t
{
if
(
params
.
det
.
image_source
==
image_source_enum
::
generator
)
{
return
generator
::
generator
(
init_params
.
generator
,
params
.
det
.
generator
);
}
else
{
int
rank
=
boost
::
mpi
::
communicator
().
rank
()
-
1
;
return
loader
::
loader
(
params
.
det
.
loader
,
rank
,
params
.
det
.
nb_prefetch_frames
);
}
};
auto
src
=
create_src
();
point_t
image_dims
;
std
::
visit
([
&
image_dims
](
auto
&
src
)
{
image_dims
=
src
.
dimensions
();
},
src
);
auto
image_dims
=
gen
.
dimensions
();
rectangle_t
roi
{{
0
,
0
},
image_dims
};
// A full frame ROI by default
//Preconditions for ROI
...
...
@@ -136,19 +150,24 @@ namespace detectors::simulator::hw
return
f
;
};
auto
generator_visitor
=
[
&
](
auto
const
&
view
)
{
gen
.
frame_getter_visit
(
get_next_frame
(),
[
&
](
auto
&&
src
)
{
apply_hw_image_proc
(
src
,
view
);
});
};
pixel_enum
pixel_type
;
auto
pixel_type
=
gen
.
pixel_type
();
auto
src_visitor
=
[
&
](
auto
&&
src
)
{
pixel_type
=
src
.
pixel_type
();
for
(
auto
&&
frame
:
m_buffer
)
{
// Resize the frame
frame
.
recreate
(
roi
.
dimensions
,
pixel_type
)
;
auto
visitor
=
[
&
](
auto
const
&
view
)
{
src
.
frame_getter_visit
(
get_next_frame
(),
[
&
](
auto
&&
src
)
{
apply_hw_image_proc
(
src
,
view
);
});
}
;
// Fill the frame
gil
::
apply_operation
(
lima
::
view
(
frame
),
generator_visitor
);
}
for
(
auto
&&
frame
:
m_buffer
)
{
// Resize the frame
frame
.
recreate
(
roi
.
dimensions
,
pixel_type
);
// Fill the frame
gil
::
apply_operation
(
lima
::
view
(
frame
),
visitor
);
}
};
std
::
visit
(
src_visitor
,
src
);
// Reset the current frame iterator
m_current_frame
=
m_buffer
.
begin
();
...
...
include/lima/processing.hpp
View file @
2fd67ecf
...
...
@@ -12,6 +12,7 @@
#include
<vector>
#include
<fmt/chrono.h>
#include
<fmt/filesystem.hpp>
#include
<fmt/describe.hpp>
#include
<fmt/ranges.h>
#include
<fmt/uuid.hpp>
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment