UsTK : Ultrasound ToolKit  version 2.0.1 under development (2024-09-20)
usImageDisplayWidgetRobotControl.cpp
1 /****************************************************************************
2  *
3  * This file is part of the ustk software.
4  * Copyright (C) 2016 - 2017 by Inria. All rights reserved.
5  *
6  * This software is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * ("GPL") version 2 as published by the Free Software Foundation.
9  * See the file LICENSE.txt at the root directory of this source
10  * distribution for additional information about the GNU GPL.
11  *
12  * For using ustk with software that can not be combined with the GNU
13  * GPL, please contact Inria about acquiring a ViSP Professional
14  * Edition License.
15  *
16  * This software was developed at:
17  * Inria Rennes - Bretagne Atlantique
18  * Campus Universitaire de Beaulieu
19  * 35042 Rennes Cedex
20  * France
21  *
22  * If you have questions regarding the use of this file, please contact
23  * Inria at ustk@inria.fr
24  *
25  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
26  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
27  *
28  * Authors:
29  * Marc Pouliquen
30  *
31  *****************************************************************************/
32 
38 #include <visp3/ustk_gui/usImageDisplayWidgetRobotControl.h>
39 
40 #if (defined(USTK_HAVE_VTK_QT) || defined(USTK_HAVE_QT5))
41 
46  : usImageDisplayWidget(), m_controlArrowsActivated(false), m_leftArrow(), m_rightArrow(),
47  m_confidenceServoingButton(), m_useFeatureDisplay(false), m_confidence(), m_plot(), m_startTime()
48 {
49  this->setMinimumSize(200, 200);
50 
51  m_controlArrowsActivated = false;
52  m_leftArrow.setParent(this);
53  m_rightArrow.setParent(this);
54  m_confidenceServoingButton.setParent(this);
55 
56  m_leftArrow.setText(QString("\u25C0"));
57  m_rightArrow.setText(QString("\u25B6"));
58  m_leftArrow.setVisible(false);
59  m_rightArrow.setVisible(false);
60 
61  m_confidenceServoingButton.setText(QString("\u21BB"));
62  m_confidenceServoingButton.setVisible(true);
63  m_confidenceServoingButton.setCheckable(true);
64  m_confidenceServoingButton.setChecked(false);
65  m_confidenceServoingButton.setAutoFillBackground(true);
66  QPalette pal = m_confidenceServoingButton.palette();
67  pal.setColor(QPalette::Button, QColor(Qt::green));
68  m_confidenceServoingButton.setPalette(pal);
69  m_confidenceServoingButton.update();
70 
71 #if defined(VISP_HAVE_GDI)
72  m_display = new vpDisplayGDI;
73 #elif defined(VISP_HAVE_OPENCV)
74  m_display = new vpDisplayOpenCV;
75 #endif
76 
77  connect(&m_leftArrow, SIGNAL(pressed()), this, SIGNAL(moveLeft()));
78  connect(&m_rightArrow, SIGNAL(pressed()), this, SIGNAL(moveRight()));
79  connect(&m_leftArrow, SIGNAL(released()), this, SIGNAL(stopMove()));
80  connect(&m_rightArrow, SIGNAL(released()), this, SIGNAL(stopMove()));
81 
82  connect(&m_confidenceServoingButton, SIGNAL(toggled(bool)), this, SLOT(updateConfidenceServoingStatus(bool)));
83 }
84 
89 
94 void usImageDisplayWidgetRobotControl::updateFrame(const vpImage<unsigned char> img)
95 {
96  m_QImage = QImage(img.bitmap, img.getWidth(), img.getHeight(), img.getWidth(), QImage::Format_Indexed8);
97  QImage I = m_QImage.convertToFormat(QImage::Format_RGB888);
98  I = I.scaled(this->width(), this->height());
99  m_pixmap = QPixmap::fromImage(I);
100  m_label->setPixmap(m_pixmap);
101  m_label->update();
102 
103  if (m_controlArrowsActivated)
105 }
106 
112 {
113  if (m_useScanConversion) {
115  m_QImage = QImage(m_postScan.bitmap, m_postScan.getWidth(), m_postScan.getHeight(), m_postScan.getWidth(),
116  QImage::Format_Indexed8);
117  } else
118  m_QImage = QImage(img.bitmap, img.getWidth(), img.getHeight(), img.getWidth(), QImage::Format_Indexed8);
119 
120  QImage I = m_QImage.convertToFormat(QImage::Format_RGB888);
121  I = I.scaled(this->width(), this->height());
122  m_pixmap = QPixmap::fromImage(I);
123  m_label->setPixmap(m_pixmap);
124  m_label->update();
125 
126  if (m_controlArrowsActivated)
128 
129  // update feature display
130  if (m_useFeatureDisplay) {
131 #if (defined(VISP_HAVE_GDI) || defined(VISP_HAVE_OPENCV))
132  if (m_confidence.getSize() > 0) {
133  if (m_confidence.display == NULL)
134  m_display->init(m_confidence);
135  vpDisplay::display(m_confidence);
136  }
137 #endif
138  }
139 }
140 
142 {
143  m_label->resize(event->size());
144  QImage I = m_QImage.convertToFormat(QImage::Format_RGB888);
145  I = I.scaled(this->width(), this->height());
146  m_pixmap = QPixmap::fromImage(I);
147  m_label->setPixmap(m_pixmap);
148  m_label->update();
149 
150  m_confidenceServoingButton.setGeometry((this->width() / 2) - m_confidenceServoingButton.size().width() / 2, 10, 40,
151  40);
152  m_confidenceServoingButton.raise();
153 
154  if (m_controlArrowsActivated)
156 }
157 
159 {
160  m_controlArrowsActivated = true;
161 
162  m_leftArrow.setVisible(true);
163  m_rightArrow.setVisible(true);
164  m_leftArrow.setGeometry(10, (this->height() / 2) - m_leftArrow.size().height() / 2, 40, 40);
165  m_rightArrow.setGeometry(this->width() - 50, (this->height() / 2) - m_rightArrow.size().height() / 2, 40, 40);
166  m_leftArrow.raise();
167  m_rightArrow.raise();
168 }
169 
171 {
172  m_controlArrowsActivated = false;
173  m_leftArrow.hide();
174  m_rightArrow.hide();
175 }
176 
178 {
179  if (activate) {
180  QPalette pal = m_confidenceServoingButton.palette();
181  pal.setColor(QPalette::Button, QColor(Qt::red));
182  m_confidenceServoingButton.setPalette(pal);
183  m_confidenceServoingButton.update();
184  } else {
185  QPalette pal = m_confidenceServoingButton.palette();
186  pal.setColor(QPalette::Button, QColor(Qt::green));
187  m_confidenceServoingButton.setPalette(pal);
188  m_confidenceServoingButton.update();
189  }
190 
191  emit(confidenceServoing(activate));
192 }
193 
195 {
196  m_useFeatureDisplay = true;
197 
198  m_plot.init(1);
199  m_plot.initGraph(0, 1);
200  m_plot.setTitle(0, "confidence barycenter error");
201  m_plot.setUnitY(0, "error");
202  m_plot.setLegend(0, 0, "time");
203  m_startTime = vpTime::measureTimeMs();
204 }
205 
206 void usImageDisplayWidgetRobotControl::disableFeaturesDisplay() { m_useFeatureDisplay = false; }
207 
209 {
210 #if (defined(VISP_HAVE_GDI) || defined(VISP_HAVE_OPENCV))
211  if (m_useFeatureDisplay) {
212  vpImagePoint p0 = vpImagePoint(0, sanline);
213  vpImagePoint p1 = vpImagePoint(m_confidence.getHeight() - 1, sanline);
214  vpImagePoint p2 = vpImagePoint(0, m_confidence.getWidth() / 2);
215  vpImagePoint p3 = vpImagePoint(m_confidence.getHeight() - 1, m_confidence.getWidth() / 2);
216  vpDisplay::displayLine(m_confidence, p0, p1, vpColor::red);
217  vpDisplay::displayLine(m_confidence, p2, p3, vpColor::green);
218  vpDisplay::flush(m_confidence);
219 
220  // plot errors
221  m_plot.plot(0, 0, vpTime::measureTimeMs() - m_startTime,
222  vpMath::deg(sanline * m_confidence.getScanLinePitch() - m_confidence.getFieldOfView() / 2.0));
223  }
224 #endif
225 }
226 
228 {
229  m_confidence = confidence;
230 }
231 #endif
void updateFrame(const vpImage< unsigned char > img)
void updateConfidenceMap(usImagePreScan2D< unsigned char > confidence)
Qt widget class for 2D ultrasound image display.
usPreScanToPostScan2DConverter m_scanConverter
usImagePostScan2D< unsigned char > m_postScan
void convert(const usImagePreScan2D< unsigned char > &preScanImage, usImagePostScan2D< unsigned char > &postScanImage, double xResolution=0., double yResolution=0.)