Line |
Branch |
Exec |
Source |
1 |
|
|
/************************************************************************ |
2 |
|
|
* |
3 |
|
|
* Copyright (C) 2014-2024 IRCAD France |
4 |
|
|
* Copyright (C) 2014-2019 IHU Strasbourg |
5 |
|
|
* |
6 |
|
|
* This file is part of Sight. |
7 |
|
|
* |
8 |
|
|
* Sight is free software: you can redistribute it and/or modify it under |
9 |
|
|
* the terms of the GNU Lesser General Public License as published by |
10 |
|
|
* the Free Software Foundation, either version 3 of the License, or |
11 |
|
|
* (at your option) any later version. |
12 |
|
|
* |
13 |
|
|
* Sight is distributed in the hope that it will be useful, |
14 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 |
|
|
* GNU Lesser General Public License for more details. |
17 |
|
|
* |
18 |
|
|
* You should have received a copy of the GNU Lesser General Public |
19 |
|
|
* License along with Sight. If not, see <https://www.gnu.org/licenses/>. |
20 |
|
|
* |
21 |
|
|
***********************************************************************/ |
22 |
|
|
|
23 |
|
|
#pragma once |
24 |
|
|
|
25 |
|
|
#include <sight/io/__/config.hpp> |
26 |
|
|
|
27 |
|
|
#include <core/jobs/base.hpp> |
28 |
|
|
|
29 |
|
|
#include <data/camera.hpp> |
30 |
|
|
#include <data/frame_tl.hpp> |
31 |
|
|
#include <data/point.hpp> |
32 |
|
|
|
33 |
|
|
#include <service/base.hpp> |
34 |
|
|
#include <service/notifier.hpp> |
35 |
|
|
|
36 |
|
|
#include <ui/__/parameter.hpp> |
37 |
|
|
|
38 |
|
|
namespace sight::io::service |
39 |
|
|
{ |
40 |
|
|
|
41 |
|
|
/** |
42 |
|
|
* @brief This interface defines grabber service API. |
43 |
|
|
* Must be implemented for services that grabs frames. |
44 |
|
|
* |
45 |
|
|
* @section Signals Signals |
46 |
|
|
* - \b position_modified(std::int64_t): Emitted when the position in the video is modified during playing. |
47 |
|
|
* - \b duration_modified(std::int64_t): Emitted when the duration of the video is modified. |
48 |
|
|
* - \b camera_started(): Emitted when camera is started. |
49 |
|
|
* - \b camera_stopped(): Emitted when camera is stopped. |
50 |
|
|
* - \b framePresented(): Emitted when a frame is presented. |
51 |
|
|
* - \b parameter_changed(): Emitted when a named parameter is changed. |
52 |
|
|
* - \b job_created(sight::core::jobs::base::sptr): Emitted when a long running job has been launched. |
53 |
|
|
* |
54 |
|
|
* @section Slots Slots |
55 |
|
|
* - \b start_camera(): Start playing the camera or the video. |
56 |
|
|
* - \b stop_camera(): Stop playing the camera or the video. |
57 |
|
|
* - \b pause_camera(): Pause the video, it has no effect when playing a camera. |
58 |
|
|
* - \b playPauseCamera(): Pauses or unpauses camera if it is started, if not, it starts it. |
59 |
|
|
* - \b loop_video(): Toggle the loop of the playing. |
60 |
|
|
* - \b set_position_video(int): Force the current time in the video. |
61 |
|
|
* - \b next_image(): display the next image in step by step mode. Does nothing if not overridden. |
62 |
|
|
* - \b previous_image(): display the previous image in step by step mode. Does nothing if not overridden. |
63 |
|
|
* - \b set_step(): set the step value between two images when calling nextImage/previous_image. Does nothing if not |
64 |
|
|
* overridden. |
65 |
|
|
* - \b set_parameters(parameters_t, std::string): Sets a parameters with value (variant) and key. |
66 |
|
|
* - \b request_settings(): Requests the grabber internal settings. |
67 |
|
|
* - \b optimize(): Calls grabber-specific optimization function (e.g. hardware related). |
68 |
|
|
* - \b add_roi_center(sight::data::point::sptr): Adds a new region fo interest center. |
69 |
|
|
* - \b remove_roi_center(sight::data::point::sptr): Removes a region of interest via its center. |
70 |
|
|
*/ |
71 |
|
|
class SIGHT_IO_CLASS_API grabber : public sight::service::base, |
72 |
|
|
public sight::service::notifier |
73 |
|
|
{ |
74 |
|
|
public: |
75 |
|
|
|
76 |
4/9
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 2 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 2 times.
✗ Branch 7 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
|
8 |
SIGHT_DECLARE_SERVICE(grabber, sight::service::base); |
77 |
|
|
|
78 |
|
|
/** |
79 |
|
|
* @name Slots API |
80 |
|
|
* @{ |
81 |
|
|
*/ |
82 |
|
|
SIGHT_IO_API static const core::com::slots::key_t START_CAMERA_SLOT; |
83 |
|
|
SIGHT_IO_API static const core::com::slots::key_t STOP_CAMERA_SLOT; |
84 |
|
|
SIGHT_IO_API static const core::com::slots::key_t PAUSE_CAMERA_SLOT; |
85 |
|
|
SIGHT_IO_API static const core::com::slots::key_t PLAY_PAUSE_CAMERA_SLOT; |
86 |
|
|
SIGHT_IO_API static const core::com::slots::key_t SELECT_CAMERA_SLOT; |
87 |
|
|
SIGHT_IO_API static const core::com::slots::key_t LOOP_VIDEO_SLOT; |
88 |
|
|
SIGHT_IO_API static const core::com::slots::key_t SET_POSITION_VIDEO_SLOT; |
89 |
|
|
SIGHT_IO_API static const core::com::slots::key_t PRESENT_SLOT; |
90 |
|
|
SIGHT_IO_API static const core::com::slots::key_t PREVIOUS_IMAGE_SLOT; |
91 |
|
|
SIGHT_IO_API static const core::com::slots::key_t NEXT_IMAGE_SLOT; |
92 |
|
|
SIGHT_IO_API static const core::com::slots::key_t SET_STEP_SLOT; |
93 |
|
|
SIGHT_IO_API static const core::com::slots::key_t SET_PARAMETER_SLOT; |
94 |
|
|
SIGHT_IO_API static const core::com::slots::key_t REQUEST_SETTINGS_SLOT; |
95 |
|
|
SIGHT_IO_API static const core::com::slots::key_t OPTIMIZE_SLOT; |
96 |
|
|
SIGHT_IO_API static const core::com::slots::key_t ADD_ROI_CENTER_SLOT; |
97 |
|
|
SIGHT_IO_API static const core::com::slots::key_t REMOVE_ROI_CENTER_SLOT; |
98 |
|
|
SIGHT_IO_API static const core::com::slots::key_t FORWARD_FPS_CHANGED_SLOT; |
99 |
|
|
///@} |
100 |
|
|
|
101 |
|
|
/** |
102 |
|
|
* @name Signals API |
103 |
|
|
* @{ |
104 |
|
|
*/ |
105 |
|
|
SIGHT_IO_API static const core::com::signals::key_t POSITION_MODIFIED_SIG; |
106 |
|
|
using position_modified_signal_t = core::com::signal<void (int64_t)>; |
107 |
|
|
|
108 |
|
|
SIGHT_IO_API static const core::com::signals::key_t DURATION_MODIFIED_SIG; |
109 |
|
|
using duration_modified_signal_t = core::com::signal<void (int64_t)>; |
110 |
|
|
|
111 |
|
|
SIGHT_IO_API static const core::com::signals::key_t FRAME_PRESENTED_SIG; |
112 |
|
|
using frame_presented_signal_t = core::com::signal<void ()>; |
113 |
|
|
|
114 |
|
|
SIGHT_IO_API static const core::com::signals::key_t CAMERA_STARTED_SIG; |
115 |
|
|
using camera_started_signal_t = core::com::signal<void ()>; |
116 |
|
|
|
117 |
|
|
SIGHT_IO_API static const core::com::signals::key_t CAMERA_STOPPED_SIG; |
118 |
|
|
using camera_stopped_signal_t = core::com::signal<void ()>; |
119 |
|
|
|
120 |
|
|
SIGHT_IO_API static const core::com::signals::key_t PARAMETER_CHANGED_SIG; |
121 |
|
|
using parameter_changed_t = core::com::signal<void (ui::parameter_t, std::string)>; |
122 |
|
|
|
123 |
|
|
SIGHT_IO_API static const core::com::signals::key_t JOB_CREATED_SIG; |
124 |
|
|
using job_created_signal_t = core::com::signal<void (core::jobs::base::sptr)>; |
125 |
|
|
|
126 |
|
|
SIGHT_IO_API static const core::com::signals::key_t FPS_CHANGED_SIG; |
127 |
|
|
using fps_changed_signal_t = sight::core::com::signal<void (double)>; |
128 |
|
|
/** @} */ |
129 |
|
|
|
130 |
|
|
/** |
131 |
|
|
* @name Data API |
132 |
|
|
* @{ |
133 |
|
|
*/ |
134 |
|
|
static constexpr std::string_view CAMERA_INPUT = "camera"; |
135 |
|
|
static constexpr std::string_view FRAMETL_INOUT = "frameTL"; |
136 |
|
|
/** @} */ |
137 |
|
|
/** |
138 |
|
|
* @brief Constructor. |
139 |
|
|
*/ |
140 |
|
|
SIGHT_IO_API grabber() noexcept; |
141 |
|
|
|
142 |
|
|
/** |
143 |
|
|
* @brief Destructor. |
144 |
|
|
*/ |
145 |
|
12 |
SIGHT_IO_API ~grabber() noexcept override = default; |
146 |
|
|
|
147 |
|
|
/** |
148 |
|
|
* @brief API for starting a camera. Needs to be reimplemented in child classes. |
149 |
|
|
*/ |
150 |
|
|
SIGHT_IO_API virtual void start_camera() = 0; |
151 |
|
|
|
152 |
|
|
/** |
153 |
|
|
* @brief API for stopping a camera. Needs to be reimplemented in child classes. |
154 |
|
|
*/ |
155 |
|
|
SIGHT_IO_API virtual void stop_camera() = 0; |
156 |
|
|
|
157 |
|
|
/** |
158 |
|
|
* @brief API for pausing a camera. Needs to be reimplemented in child classes. |
159 |
|
|
*/ |
160 |
|
|
SIGHT_IO_API virtual void pause_camera() = 0; |
161 |
|
|
|
162 |
|
|
/** |
163 |
|
|
* @brief API for enable/disable the loop mode in video. Needs to be reimplemented in child classes. |
164 |
|
|
*/ |
165 |
|
|
SIGHT_IO_API virtual void toggle_loop_mode() = 0; |
166 |
|
|
|
167 |
|
|
/** |
168 |
|
|
* @brief API for setting a new position in the video. Needs to be reimplemented in child classes |
169 |
|
|
*/ |
170 |
|
|
SIGHT_IO_API virtual void set_position(int64_t _position) = 0; |
171 |
|
|
|
172 |
|
|
/** |
173 |
|
|
* @brief API to get the previous image in frame by frame mode. |
174 |
|
|
*/ |
175 |
|
|
SIGHT_IO_API virtual void previous_image(); |
176 |
|
|
|
177 |
|
|
/** |
178 |
|
|
* @brief API to get the next image in frame by frame mode. |
179 |
|
|
*/ |
180 |
|
|
SIGHT_IO_API virtual void next_image(); |
181 |
|
|
|
182 |
|
|
/** |
183 |
|
|
* @brief API to set step used on readPrevious/readNext slots in frame by frame mode. |
184 |
|
|
*/ |
185 |
|
|
SIGHT_IO_API virtual void set_step(int _step, std::string _key); |
186 |
|
|
|
187 |
|
|
/// SLOT: Requests the grabber internal settings. |
188 |
|
|
SIGHT_IO_API virtual void request_settings(); |
189 |
|
|
|
190 |
|
|
/// SLOT: Calls optimization functions defined in the grabber (e.g. hardware related function). |
191 |
|
|
SIGHT_IO_API virtual void optimize(); |
192 |
|
|
|
193 |
|
|
/// SLOT: Adds a region of interest center. |
194 |
|
|
SIGHT_IO_API virtual void add_roi_center(sight::data::point::sptr _p); |
195 |
|
|
|
196 |
|
|
/// SLOT: Removes a region of interest center. |
197 |
|
|
SIGHT_IO_API virtual void remove_roi_center(sight::data::point::sptr _p); |
198 |
|
|
|
199 |
|
|
/// SLOT: Sets a parameter value with its key. |
200 |
|
|
SIGHT_IO_API virtual void set_parameter(ui::parameter_t _value, std::string _key); |
201 |
|
|
|
202 |
|
|
/// SLOT: Forward FPS data |
203 |
|
|
SIGHT_IO_API virtual void forward_fps_changed(double _fps); |
204 |
|
|
|
205 |
|
|
protected: |
206 |
|
|
|
207 |
|
|
/** |
208 |
|
|
* @brief Helper function intended to be used in derived services. Clears the supplied timeline, emits the cleared |
209 |
|
|
* signal, pushes a black frame and emits the object pushed signal. |
210 |
|
|
*/ |
211 |
|
|
SIGHT_IO_API static void clear_timeline(data::frame_tl& _tl); |
212 |
|
|
|
213 |
|
|
/** |
214 |
|
|
* @brief sets the current start state of the grabber. |
215 |
|
|
*/ |
216 |
|
|
SIGHT_IO_API void set_start_state(bool _state); |
217 |
|
|
bool started() const; |
218 |
|
|
|
219 |
|
|
data::ptr<data::frame_tl, data::access::inout> m_frame {this, FRAMETL_INOUT}; |
220 |
|
|
|
221 |
|
|
private: |
222 |
|
|
|
223 |
|
|
/** |
224 |
|
|
* @brief Pauses or unpauses camera if it is started, if not, it starts it. This slot shouldn't be used when play |
225 |
|
|
* or pause slots are used, this is why we add a boolean state, to ensure correct interaction with a GUI element. |
226 |
|
|
*/ |
227 |
|
|
SIGHT_IO_API void play_pause_camera(); |
228 |
|
|
|
229 |
|
|
/// Determines whether the grabber has been started, note : this does not mean it is playing, as it could be paused. |
230 |
|
|
bool m_is_started {false}; |
231 |
|
|
}; |
232 |
|
|
|
233 |
|
|
//------------------------------------------------------------------------------ |
234 |
|
|
|
235 |
|
3 |
inline bool grabber::started() const |
236 |
|
|
{ |
237 |
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
|
3 |
return m_is_started; |
238 |
|
|
} |
239 |
|
|
|
240 |
|
|
} //namespace sight::io::service |
241 |
|
|
|