Line |
Branch |
Exec |
Source |
1 |
|
|
/************************************************************************ |
2 |
|
|
* |
3 |
|
|
* Copyright (C) 2014-2024 IRCAD France |
4 |
|
|
* Copyright (C) 2014-2020 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 <data/point_list.hpp> |
26 |
|
|
|
27 |
|
|
#include <viz/scene3d/adaptor.hpp> |
28 |
|
|
#include <viz/scene3d/texture.hpp> |
29 |
|
|
#include <viz/scene3d/transfer_function.hpp> |
30 |
|
|
|
31 |
|
|
#include <OGRE/OgreTexture.h> |
32 |
|
|
|
33 |
|
|
namespace sight::module::viz::scene3d::adaptor |
34 |
|
|
{ |
35 |
|
|
|
36 |
|
|
/** |
37 |
|
|
* @brief This adaptor renders a video frame from a 2D-image. |
38 |
|
|
* |
39 |
|
|
* @section Slots Slots |
40 |
|
|
* - \b update_visibility(bool): sets whether the video is visible or not. |
41 |
|
|
* - \b toggle_visibility(): toggle whether the video is visible or not. |
42 |
|
|
* - \b show(): shows the video. |
43 |
|
|
* - \b hide(): hides the video. |
44 |
|
|
* - \b update_tf(): updates the displayed transfer function. |
45 |
|
|
* - \b update_pl(): updates the displayed point list. |
46 |
|
|
* - \b set_filtering(bool): toggles between nearest (false) and bilinear (true) filtering. |
47 |
|
|
* - \b scale(bool): displays the video at its original size (false) or scales the video to the viewport size (true). |
48 |
|
|
* |
49 |
|
|
* @section XML XML Configuration |
50 |
|
|
* @code{.xml} |
51 |
|
|
<service type="sight::module::viz::scene3d::adaptor::video" auto_connect="true" > |
52 |
|
|
<in key="image" uid="..." /> |
53 |
|
|
<in key="tf" uid="..." /> |
54 |
|
|
<config textureName="videoFrame" /> |
55 |
|
|
</service> |
56 |
|
|
@endcode |
57 |
|
|
* |
58 |
|
|
* @subsection Input Input: |
59 |
|
|
* - \b image [sight::data::image]: frame displayed. |
60 |
|
|
* - \b tf [sight::data::transfer_function] (optional): a transfer function that can be applied to the video. |
61 |
|
|
* - \b pointList [sight::data::point_list] (optional): point list to display (coordinates must be in the image space). |
62 |
|
|
* |
63 |
|
|
* @subsection Configuration Configuration: |
64 |
|
|
* - \b visible (optional, bool, default=true): the visibility of the adaptor. |
65 |
|
|
* - \b materialTemplate (optional, string, default='Billboard_Default'): the name of the base Ogre material for the |
66 |
|
|
* internally created material. |
67 |
|
|
* - \b textureName (optional, string, default=""): the name of the Ogre texture the mesh will use. |
68 |
|
|
* - \b filtering (optional, bool, default=false): whether to use or not bilinear filtering for the texture. |
69 |
|
|
* - \b scaling (optional, bool, default=true): whether to scale the video to the viewport or |
70 |
|
|
* keep it at its original resolution. |
71 |
|
|
* - \b radius (optional, float, default=1.f): billboard radius. |
72 |
|
|
* - \b displayLabel (optional, bool, default=false): display the label points (default = false). |
73 |
|
|
* - \b labelColor (optional, hexadecimal, default=0xFFFFFF): color of the label in hexadecimal. |
74 |
|
|
* - \b color (optional, hexadecimal, default=#FFFFFFFF): color of the texture in hexadecimal. |
75 |
|
|
* - \b fixedSize (optional, bool, default=false): if true, the billboard will have a fixed size in screen space. |
76 |
|
|
* - \b queryFlags (optional, uint32, default=0x40000000): Picking flags. Points can be picked by pickers with a |
77 |
|
|
* matching mask. |
78 |
|
|
* - \b fontSource (optional, string, default=DejaVuSans.ttf): true_t font (*.ttf) source file. |
79 |
|
|
* - \b fontSize (optional, unsigned int, default=16): font size in points. |
80 |
|
|
*/ |
81 |
|
|
class video final : public sight::viz::scene3d::adaptor |
82 |
|
|
{ |
83 |
|
|
public: |
84 |
|
|
|
85 |
|
|
/// Generates default methods as New, dynamicCast, ... |
86 |
4/9
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 4 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 4 times.
✗ Branch 7 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
|
18 |
SIGHT_DECLARE_SERVICE(video, sight::viz::scene3d::adaptor); |
87 |
|
|
|
88 |
|
|
struct slots |
89 |
|
|
{ |
90 |
|
|
inline static const core::com::slots::key_t UPDATE_IMAGE = "update_image"; |
91 |
|
|
inline static const core::com::slots::key_t UPDATE_TF = "update_tf"; |
92 |
|
|
inline static const core::com::slots::key_t UPDATE_PL = "update_pl"; |
93 |
|
|
inline static const core::com::slots::key_t SET_FILTERING = "set_filtering"; |
94 |
|
|
inline static const core::com::slots::key_t SCALE = "scale"; |
95 |
|
|
}; |
96 |
|
|
|
97 |
|
|
/// Creates the adaptor an initialize slots. |
98 |
|
|
video() noexcept; |
99 |
|
|
|
100 |
|
|
/// Destroys the adaptor. |
101 |
5/10
✗ Branch 13 not taken.
✓ Branch 14 taken 4 times.
✗ Branch 15 not taken.
✓ Branch 16 taken 4 times.
✗ Branch 18 not taken.
✓ Branch 19 taken 4 times.
✗ Branch 20 not taken.
✓ Branch 21 taken 4 times.
✗ Branch 22 not taken.
✓ Branch 23 taken 4 times.
|
8 |
~video() noexcept final = default; |
102 |
|
|
|
103 |
|
|
protected: |
104 |
|
|
|
105 |
|
|
/// Configures the adaptor. |
106 |
|
|
void configuring() final; |
107 |
|
|
|
108 |
|
|
/// Creates the Ogre texture and mapper used to show the video frame. |
109 |
|
|
void starting() final; |
110 |
|
|
|
111 |
|
|
/** |
112 |
|
|
* @brief Proposals to connect service slots to associated object signals. |
113 |
|
|
* @return A map of each proposed connection. |
114 |
|
|
* |
115 |
|
|
* Connect data::image::MODIFIED_SIG of s_IMAGE_INPUT to service::slots::UPDATE |
116 |
|
|
* Connect data::image::BUFFER_MODIFIED_SIG of s_IMAGE_INPUT to service::slots::UPDATE |
117 |
|
|
* Connect data::transfer_function::MODIFIED_SIG of s_TF_INPUT to :UPDATE_TF_SLOT |
118 |
|
|
* Connect data::transfer_function::POINTS_MODIFIED_SIG of s_TF_INPUT to UPDATE_TF_SLOT |
119 |
|
|
* Connect data::transfer_function::WINDOWING_MODIFIED_SIG of s_TF_INPUT to UPDATE_TF_SLOT |
120 |
|
|
*/ |
121 |
|
|
service::connections_t auto_connections() const final; |
122 |
|
|
|
123 |
|
|
/// Updates the frame from the current image. |
124 |
|
|
void updating() final; |
125 |
|
|
|
126 |
|
|
/// Removes the actor from the renderer |
127 |
|
|
void stopping() final; |
128 |
|
|
|
129 |
|
|
/** |
130 |
|
|
* @brief Sets the video visibility. |
131 |
|
|
* @param _visible the visibility status of the video. |
132 |
|
|
*/ |
133 |
|
|
void set_visible(bool _visible) final; |
134 |
|
|
|
135 |
|
|
private: |
136 |
|
|
|
137 |
|
|
///@brief Internal wrapper holding config defines. |
138 |
|
|
struct config |
139 |
|
|
{ |
140 |
|
|
static inline const std::string VISIBLE = CONFIG + "visible"; |
141 |
|
|
static inline const std::string MATERIAL_TEMPLATE = CONFIG + "materialTemplate"; |
142 |
|
|
static inline const std::string TEXTURE_NAME = CONFIG + "textureName"; |
143 |
|
|
static inline const std::string FILTERING = CONFIG + "filtering"; |
144 |
|
|
static inline const std::string SCALING = CONFIG + "scaling"; |
145 |
|
|
static inline const std::string RADIUS = CONFIG + "radius"; |
146 |
|
|
static inline const std::string DISPLAY_LABEL = CONFIG + "displayLabel"; |
147 |
|
|
static inline const std::string LABEL_COLOR = CONFIG + "labelColor"; |
148 |
|
|
static inline const std::string COLOR = CONFIG + "color"; |
149 |
|
|
static inline const std::string FIXED_SIZE = CONFIG + "fixedSize"; |
150 |
|
|
static inline const std::string QUERY = CONFIG + "queryFlags"; |
151 |
|
|
static inline const std::string FONT_SOURCE = CONFIG + "fontSource"; |
152 |
|
|
static inline const std::string FONT_SIZE = CONFIG + "fontSize"; |
153 |
|
|
}; |
154 |
|
|
|
155 |
|
|
/// SLOTS: updates the displayed transfer function. |
156 |
|
|
void update_tf(); |
157 |
|
|
|
158 |
|
|
/// SLOTS: updates 2D coordinates of the pointlist from image space (bottom left) to video space (center center). |
159 |
|
|
void update_pl(); |
160 |
|
|
|
161 |
|
|
/// SLOTS: whether to use or not bilinear filtering |
162 |
|
|
void set_filtering(bool /*filtering*/); |
163 |
|
|
|
164 |
|
|
/// SLOTS: whether to scale or not the video to occupy the whole viewport |
165 |
|
|
void scale(bool /*value*/); |
166 |
|
|
|
167 |
|
|
/// Updates the current texture filtering option |
168 |
|
|
void update_texture_filtering(); |
169 |
|
|
|
170 |
|
|
/// Cleans scene entities and associated mesh. |
171 |
|
|
void clear_entity(); |
172 |
|
|
|
173 |
|
|
/// Contains the Ogre texture used to store the image. |
174 |
|
|
sight::viz::scene3d::texture::sptr m_texture; |
175 |
|
|
|
176 |
|
|
/// Contains the Ogre material used to display the video plane. |
177 |
|
|
Ogre::MaterialPtr m_material; |
178 |
|
|
|
179 |
|
|
/// Contains the Ogre mesh used to display the video plane. |
180 |
|
|
Ogre::MeshPtr m_mesh; |
181 |
|
|
|
182 |
|
|
/// Contains the node where the plane is attached. |
183 |
|
|
Ogre::SceneNode* m_scene_node {nullptr}; |
184 |
|
|
|
185 |
|
|
/// Contains the Ogre entity used to display the video plane. |
186 |
|
|
Ogre::Entity* m_entity {nullptr}; |
187 |
|
|
|
188 |
|
|
/// Contains and manages the Ogre textures used to store the transfer function (GPU point of view). |
189 |
|
|
std::unique_ptr<sight::viz::scene3d::transfer_function> m_gpu_tf; |
190 |
|
|
|
191 |
|
|
/// Defines if the texture is initialized. |
192 |
|
|
bool m_is_texture_init {false}; |
193 |
|
|
|
194 |
|
|
/// Defines the previous image size. |
195 |
|
|
std::size_t m_previous_width {0}; |
196 |
|
|
|
197 |
|
|
/// Defines the previous image spacing. |
198 |
|
|
std::size_t m_previous_height {0}; |
199 |
|
|
|
200 |
|
|
/// Defines the previous viewport width. |
201 |
|
|
int m_previous_viewport_width {0}; |
202 |
|
|
|
203 |
|
|
/// Defines the previous viewport height. |
204 |
|
|
int m_previous_viewport_height {0}; |
205 |
|
|
|
206 |
|
|
/// Defines the previous image type. |
207 |
|
|
core::type m_previous_type; |
208 |
|
|
|
209 |
|
|
/// Contains the pointlist in the video space coordinates. |
210 |
|
|
data::point_list::sptr m_point_list {nullptr}; |
211 |
|
|
|
212 |
|
|
/// Contains the adaptor used to display the 2D pointlist. |
213 |
|
|
sight::viz::scene3d::adaptor::sptr m_point_list_adaptor {nullptr}; |
214 |
|
|
|
215 |
|
|
/// Defines material's name used by the point list. |
216 |
|
|
std::string m_material_template_name; |
217 |
|
|
|
218 |
|
|
/// Defines the attached texture adaptor UID used by the point list. |
219 |
|
|
std::string m_texture_name; |
220 |
|
|
|
221 |
|
|
/// Defines whether of not the video texture will use bilinear filtering |
222 |
|
|
bool m_filtering {false}; |
223 |
|
|
|
224 |
|
|
/// Defines whether the video is scaled to the viewport or displayed at its original size. |
225 |
|
|
bool m_scaling {true}; |
226 |
|
|
|
227 |
|
|
/// Whether an update to the current plane is required due to a scaling change or not |
228 |
|
|
bool m_force_plane_update {false}; |
229 |
|
|
|
230 |
|
|
/// Defines the billboards radius. |
231 |
|
|
std::string m_radius; |
232 |
|
|
|
233 |
|
|
/// Defines if label numbers are displayed. |
234 |
|
|
std::string m_display_label; |
235 |
|
|
|
236 |
|
|
/// Defines the RGB color for the label point color. |
237 |
|
|
std::string m_label_color; |
238 |
|
|
|
239 |
|
|
/// Defines the color of points. |
240 |
|
|
std::string m_color; |
241 |
|
|
|
242 |
|
|
/// Defines if billboard will have a fixed size in screen space. |
243 |
|
|
std::string m_fixed_size; |
244 |
|
|
|
245 |
|
|
/// Defines the mask for picking requests in the point list. |
246 |
|
|
std::string m_query_flags; |
247 |
|
|
|
248 |
|
|
/// Defines the true_t font source file. |
249 |
|
|
std::string m_font_source; |
250 |
|
|
|
251 |
|
|
/// Defines the font size in points. |
252 |
|
|
std::string m_font_size; |
253 |
|
|
|
254 |
|
|
enum class update_flags : std::uint8_t |
255 |
|
|
{ |
256 |
|
|
IMAGE, |
257 |
|
|
TF, |
258 |
|
|
POINT_LIST |
259 |
|
|
}; |
260 |
|
|
|
261 |
|
|
sight::data::ptr<sight::data::image, sight::data::access::in> m_image {this, "image"}; |
262 |
|
|
sight::data::ptr<sight::data::transfer_function, sight::data::access::in> m_tf {this, "tf", true}; |
263 |
|
|
sight::data::ptr<sight::data::point_list, sight::data::access::in> m_pl {this, "pointList", true}; |
264 |
|
|
}; |
265 |
|
|
|
266 |
|
|
} // namespace sight::module::viz::scene3d::adaptor. |
267 |
|
|
|