Biomedical Image Analysis Library
The Biomedical Image Analysis Library is a poweful tool for developers, physicians, researchers, engineers, and so on.
imagewidget.cpp
Go to the documentation of this file.
1 #include "graphicsscene.h"
2 #include "imagewidget.h"
3 #include "ui_imagewidget.h"
4 #include <Common.hpp>
5 
6 ImageWidget::ImageWidget( QWidget *parent ) : QWidget( parent ), ui( new Ui::ImageWidget ) {
7  ui->setupUi( this );
8  m_scene = new GraphicsScene( this );
9  ui->graphicsView->setScene( m_scene );
10  setViewBgColor( Qt::black );
11  QPalette p( palette( ) );
12  p.setColor( QPalette::Background, Qt::lightGray );
13  setAutoFillBackground( true );
14  setPalette( p );
15  connect( ui->graphicsView, &GraphicsView::dropImage, this, &ImageWidget::dropImage );
16  connect( ui->graphicsView, &GraphicsView::dropFolder, this, &ImageWidget::dropFolder );
17 }
18 
20  delete ui;
21 }
22 
24  ui->frameControls->hide( );
25 }
26 
28  ui->frameControls->show( );
29 }
30 
31 void ImageWidget::setViewBgColor( const QColor &color ) {
32  if( ui->graphicsView->scene( ) ) {
33  ui->graphicsView->scene( )->setBackgroundBrush( color );
34  }
35 }
36 
38  return( m_scene );
39 }
40 
41 QGraphicsView* ImageWidget::graphicsView( ) {
42  return( ui->graphicsView );
43 }
44 
45 size_t ImageWidget::viewNumber( ) const {
46  return( m_viewNumber );
47 }
48 
49 void ImageWidget::setViewNumber( const size_t &viewNumber ) {
50  m_viewNumber = viewNumber;
51 }
52 
53 void ImageWidget::setRange( int start, int end ) {
54  if( start > end ) {
55  throw std::invalid_argument( BIAL_ERROR( "start should be smaller than end" ) );
56  }
57  ui->spinBox->setMinimum( start );
58  ui->spinBox->setMaximum( end );
59 
60  ui->horizontalSlider->setMinimum( start );
61  ui->horizontalSlider->setMaximum( end );
62  if( start == end ) {
63  ui->spinBox->setEnabled( false );
64  ui->horizontalSlider->setEnabled( false );
65  }
66 }
67 
68 void ImageWidget::setSlice( int slice ) {
69  if( ui->spinBox->value( ) != slice ) {
70  ui->spinBox->setValue( slice );
71  }
72  if( ui->horizontalSlider->value( ) != slice ) {
73  ui->horizontalSlider->setValue( slice );
74  }
75 }
76 
78  QWidget::show( );
79 }
80 
81 void ImageWidget::on_spinBox_valueChanged( int position ) {
82  emit sliceChanged( m_viewNumber, position );
83 }
84 
85 void ImageWidget::on_rotateButton_clicked( ) {
86  emit rotate( m_viewNumber );
87 }
88 
89 void ImageWidget::on_horizontalSlider_valueChanged( int position ) {
90  emit sliceChanged( m_viewNumber, position );
91 }
92 
93 void ImageWidget::on_flip_h_button_clicked( ) {
94  emit fliph( m_viewNumber );
95 }
96 
97 void ImageWidget::on_flip_v_button_clicked( ) {
98  emit flipv( m_viewNumber );
99 }
AdjacencyIterator end(const Adjacency &adj, const Vector< D > &vct, size_t pixel_index)
Returns an iterator to position after the end of elements.
void dropFolder(const QString &folderPath)
virtual void setViewBgColor(const QColor &color)
Definition: imagewidget.cpp:31
void flipv(size_t viewNbr)
void sliceChanged(size_t viewNbr, size_t slice)
#define BIAL_ERROR(exp)
Use BIAL_ERROR to compose runtime error messages. Note that ERROR generates a string, instead of a stream, because it is better to throw an exception, rather than exiting the program. This way, the exception may be threated by a higher level program, like an user IDE.
Definition: Common.hpp:161
Content: Commonly used macros, types, static variables and functions. Description: Some macros used...
void dropImage(const QString &filePath)
QGraphicsView * graphicsView()
Definition: imagewidget.cpp:41
void fliph(size_t viewNbr)
Image< D > Background(const Image< D > &img)
Segments the darker clusters of the image, supposedly belonging to the background.
void hideControls()
Definition: imagewidget.cpp:23
GraphicsScene * scene() const
Definition: imagewidget.cpp:37
void setRange(int start, int end)
Definition: imagewidget.cpp:53
void showControls()
Definition: imagewidget.cpp:27
size_t viewNumber() const
Definition: imagewidget.cpp:45
void setSlice(int slice)
Definition: imagewidget.cpp:68
void dropImage(const QString &filePath)
ImageWidget(QWidget *parent=0)
Definition: imagewidget.cpp:6
void rotate(size_t viewNbr)
void setViewNumber(const size_t &viewNumber)
Definition: imagewidget.cpp:49
void dropFolder(const QString &folderPath)