UsTK : Ultrasound ToolKit  version 2.0.1 under development (2023-12-07)
usImageDisplayWidget.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/usImageDisplayWidget.h>
39 
40 #if (defined(USTK_HAVE_VTK_QT) || defined(USTK_HAVE_QT5))
41 
46  : m_label(NULL), m_QImage(), m_pixmap(), m_useScanConversion(true), m_scanConverter(), m_postScan(), m_image()
47 {
48  this->setMinimumSize(200, 200);
49  m_label = new QLabel(this);
50  m_label->setMinimumSize(200, 200);
51  m_label->autoFillBackground();
52 }
53 
58 {
59  if (m_label)
60  delete m_label;
61 }
62 
67 void usImageDisplayWidget::updateFrame(const vpImage<unsigned char> img)
68 {
69  m_useScanConversion = false;
70  m_image = img;
71  m_QImage = QImage(img.bitmap, img.getWidth(), img.getHeight(), img.getWidth(), QImage::Format_Indexed8);
72  QImage I = m_QImage.convertToFormat(QImage::Format_RGB888);
73  I = I.scaled(this->width(), this->height());
74  m_pixmap = QPixmap::fromImage(I);
75  m_label->setPixmap(m_pixmap);
76  m_label->update();
77 }
78 
84 {
85  m_useScanConversion = false;
86  m_image = img;
87  m_QImage = QImage(img.bitmap, img.getWidth(), img.getHeight(), img.getWidth(), QImage::Format_Indexed8);
88  QImage I = m_QImage.convertToFormat(QImage::Format_RGB888);
89  I = I.scaled(this->width(), this->height());
90  m_pixmap = QPixmap::fromImage(I);
91  m_label->setPixmap(m_pixmap);
92  m_label->update();
93 }
94 
100 {
101  if (m_useScanConversion) {
103  m_QImage = QImage(m_postScan.bitmap, m_postScan.getWidth(), m_postScan.getHeight(), m_postScan.getWidth(),
104  QImage::Format_Indexed8);
105  } else {
106  m_image = img;
107  m_QImage = QImage(img.bitmap, img.getWidth(), img.getHeight(), img.getWidth(), QImage::Format_Indexed8);
108  }
109  QImage I = m_QImage.convertToFormat(QImage::Format_RGB888);
110  I = I.scaled(this->width(), this->height());
111  m_pixmap = QPixmap::fromImage(I);
112  m_label->setPixmap(m_pixmap);
113  m_label->update();
114 }
115 
116 void usImageDisplayWidget::resizeEvent(QResizeEvent *event)
117 {
118  m_label->resize(event->size());
119  if (m_QImage.size() != QSize(0, 0)) { // excludes init case
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 }
127 
129 
130 #endif
void updateFrame(const vpImage< unsigned char > img)
vpImage< unsigned char > m_image
void useScanConversion(bool enable)
void resizeEvent(QResizeEvent *event)
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.)