GCC Code Coverage Report


./
File: modules/ui/qt/image/image_info.cpp
Date: 2025-01-21 16:21:04
Lines:
0/57
0.0%
Functions:
0/9
0.0%
Branches:
0/104
0.0%

Line Branch Exec Source
1 /************************************************************************
2 *
3 * Copyright (C) 2009-2025 IRCAD France
4 * Copyright (C) 2012-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 #include "modules/ui/qt/image/image_info.hpp"
24
25 #include <core/base.hpp>
26 #include <core/com/slot.hpp>
27 #include <core/com/slot.hxx>
28 #include <core/com/slots.hpp>
29 #include <core/com/slots.hxx>
30
31 #include <data/helper/medical_image.hpp>
32
33 #include <ui/qt/container/widget.hpp>
34
35 #include <QHBoxLayout>
36 #include <QLabel>
37 #include <QWidget>
38
39 namespace sight::module::ui::qt::image
40 {
41
42 static const core::com::slots::key_t GET_INTERACTION_SLOT = "get_interaction";
43
44 image_info::image_info() noexcept
45 {
46 new_slot(GET_INTERACTION_SLOT, &image_info::get_interaction, this);
47 }
48
49 //------------------------------------------------------------------------------
50
51 image_info::~image_info() noexcept =
52 default;
53
54 //------------------------------------------------------------------------------
55
56 void image_info::starting()
57 {
58 this->sight::ui::service::create();
59
60 auto qt_container = std::dynamic_pointer_cast<sight::ui::qt::container::widget>(this->get_container());
61
62 auto* h_layout = new QHBoxLayout();
63
64 auto* static_text = new QLabel(QObject::tr("intensity:"));
65 h_layout->addWidget(static_text, 0, Qt::AlignVCenter);
66
67 m_value_text = new QLineEdit();
68 m_value_text->setReadOnly(true);
69 h_layout->addWidget(m_value_text, 1, Qt::AlignVCenter);
70
71 qt_container->set_layout(h_layout);
72 }
73
74 //------------------------------------------------------------------------------
75
76 void image_info::stopping()
77 {
78 this->destroy();
79 }
80
81 //------------------------------------------------------------------------------
82
83 void image_info::configuring()
84 {
85 this->sight::ui::service::initialize();
86 }
87
88 //------------------------------------------------------------------------------
89
90 void image_info::updating()
91 {
92 const auto image = m_image.lock();
93 SIGHT_ASSERT("The input '" << IMAGE << "' is not defined", image);
94 const bool image_is_valid = data::helper::medical_image::check_image_validity(image.get_shared());
95 m_value_text->setEnabled(image_is_valid);
96 }
97
98 //------------------------------------------------------------------------------
99
100 void image_info::get_interaction(data::tools::picking_info _info)
101 {
102 if(_info.m_event_id == data::tools::picking_info::event::mouse_move)
103 {
104 const auto image = m_image.lock();
105 SIGHT_ASSERT("The input '" << IMAGE << "' is not defined", image);
106
107 const bool image_is_valid = data::helper::medical_image::check_image_validity(image.get_shared());
108 m_value_text->setEnabled(image_is_valid);
109 if(image_is_valid)
110 {
111 const std::array<double, 3>& point = _info.m_world_pos;
112 const data::image::size_t size = image->size();
113
114 if(point[0] < 0 || point[1] < 0 || point[2] < 0)
115 {
116 SIGHT_ERROR(
117 "The received coordinates are not in image space, maybe you used the wrong picker "
118 "interactor (see ::visuVTKAdaptor::imagePickerInteractor)"
119 );
120 return;
121 }
122
123 const data::image::size_t coords =
124 {{static_cast<data::image::size_t::value_type>(point[0]),
125 static_cast<data::image::size_t::value_type>(point[1]),
126 static_cast<data::image::size_t::value_type>(point[2])
127 }
128 };
129
130 bool is_inside = (coords[0] < size[0] && coords[1] < size[1]);
131 if(image->num_dimensions() < 3)
132 {
133 is_inside = (is_inside && coords[2] == 0);
134 }
135 else
136 {
137 is_inside = (is_inside && coords[2] < size[2]);
138 }
139
140 if(!is_inside)
141 {
142 SIGHT_ERROR(
143 "The received coordinates are not in image space, maybe you used the wrong picker "
144 "interactor (see ::visuVTKAdaptor::imagePickerInteractor)"
145 );
146 return;
147 }
148
149 const auto dump_lock = image->dump_lock();
150
151 const std::string intensity = image->get_pixel_as_string(coords[0], coords[1], coords[2]);
152 m_value_text->setText(QString::fromStdString(intensity));
153 }
154 }
155 }
156
157 //------------------------------------------------------------------------------
158
159 void image_info::info(std::ostream& _sstream)
160 {
161 _sstream << "image Info Editor";
162 }
163
164 //------------------------------------------------------------------------------
165
166 service::connections_t image_info::auto_connections() const
167 {
168 connections_t connections;
169
170 connections.push(IMAGE, data::image::MODIFIED_SIG, service::slots::UPDATE);
171 connections.push(IMAGE, data::image::BUFFER_MODIFIED_SIG, service::slots::UPDATE);
172
173 return connections;
174 }
175
176 //------------------------------------------------------------------------------
177
178 } // namespace sight::module::ui::qt::image
179