Biomedical Image Analysis Library
The Biomedical Image Analysis Library is a poweful tool for developers, physicians, researchers, engineers, and so on.
controller.cpp
Go to the documentation of this file.
1 #include "controller.h"
2 #include "thumbswidget.h"
3 
4 #include <QDebug>
5 #include <QFile>
6 #include <qsettings.h>
7 
8 Controller::Controller( int views, QObject *parent )
9  : QObject( parent ), bw2dFormat( new BW2DFormat( this ) ), rgb2dFormat( new RGB2DFormat( this ) ),
10  bw3dFormat( new BW3DFormat( this ) ) {
11  for( int item = 0; item < views; ++item ) {
12  m_pixmapItems.append( new QGraphicsPixmapItem( ) );
13  m_labelItems.append( new QGraphicsPixmapItem( ) );
14  }
15  m_currentImagePos = -1;
16  connect( rgb2dFormat, &DisplayFormat::updated, this, &Controller::currentImageChanged );
17  connect( bw3dFormat, &DisplayFormat::updated, this, &Controller::currentImageChanged );
18  connect( bw2dFormat, &DisplayFormat::updated, this, &Controller::currentImageChanged );
19  connect( rgb2dFormat, &DisplayFormat::updated, this, &Controller::update );
20  connect( bw3dFormat, &DisplayFormat::updated, this, &Controller::update );
21  connect( bw2dFormat, &DisplayFormat::updated, this, &Controller::update );
22 }
23 
25  return( imageAt( currentImagePos( ) ) );
26 }
27 
29  if( ( pos >= 0 ) && ( pos < m_images.size( ) ) ) {
30  return( m_images.at( pos ) );
31  }
32  return( nullptr );
33 }
34 
36  return( m_currentImagePos );
37 }
38 
39 bool Controller::addImage( QString fname ) {
40  qDebug( ) << "addimage.";
41  COMMENT( "Loading file " << fname.toStdString( ), 0 );
42  GuiImage *img = nullptr;
43  try {
44  img = new GuiImage( fname, this );
45  }
46  catch( std::bad_alloc e ) {
47  BIAL_WARNING( e.what( ) );
48  }
49  catch( std::runtime_error e ) {
50  BIAL_WARNING( e.what( ) );
51  }
52  catch( std::out_of_range e ) {
53  BIAL_WARNING( e.what( ) );
54  }
55  catch( std::logic_error e ) {
56  BIAL_WARNING( e.what( ) );
57  }
58  catch( ... ) {
59  }
60  if( img == nullptr ) {
61  emit containerUpdated( );
62  return( false );
63  }
64  m_images.append( img );
65 
66  m_thumbsWidget->addThumbnail( img );
67  if( currentImagePos( ) == -1 ) {
68  setCurrentImagePos( 0 );
69  }
70  setRecentFile( fname );
71 
72  emit containerUpdated( );
73  emit currentImageChanged( );
74 
75  return( true );
76 }
77 
78 bool Controller::addLabel( QString label ) {
79  Q_UNUSED( label );
80  /* TODO Controller::addLabel( QString label ) */
81  return( false );
82 }
83 
85  /* TODO Controller::removeCurrentLabel( ) */
86  return( false );
87 }
88 
90  m_images.removeAt( currentImagePos( ) );
91  m_thumbsWidget->removeAt( currentImagePos( ) );
92  if( currentImagePos( ) == 0 ) {
93  setCurrentImagePos( 0 );
94  }
95  else {
97  }
98  emit containerUpdated( );
99 }
100 
102  return( m_images.isEmpty( ) );
103 }
104 
106  COMMENT( "Reseting images.", 1 );
107  qDeleteAll( m_images );
108  m_images.clear( );
109  setCurrentImagePos( -1 );
110  m_thumbsWidget->clear( );
111  emit containerUpdated( );
112 }
113 
115  return( m_images.size( ) );
116 }
117 
119  COMMENT( "UPDATING IMAGE!", 2 );
120 
121  GuiImage *img = currentImage( );
122  if( img ) {
123  std::array< bool, 4 > showItens = currentFormat( )->getViews( );
124  for( int axis = 0; axis < 4; ++axis ) {
125  if( showItens[ axis ] ) {
126  m_labelItems.at( axis )->setPixmap( QPixmap( ) );
127  const QPixmap &pix = img->getSlice( axis );
128  m_pixmapItems.at( axis )->setPixmap( pix );
129  Tool *tool = img->currentTool( );
130  if( tool && tool->hasLabel( ) ) {
131  m_labelItems.at( axis )->setPixmap( tool->getLabel( axis ) );
132  }
133  }
134  }
135  }
136  else {
137  for( int axis = 0; axis < m_pixmapItems.size( ); ++axis ) {
138  m_pixmapItems[ axis ]->setPixmap( QPixmap( ) );
139  }
140  }
141  emit imageUpdated( );
142 }
143 
144 void Controller::setCurrentImagePos( int position ) {
145  m_currentImagePos = position;
146  if( currentImage( ) != nullptr ) {
147  disconnect( currentImage( ), &GuiImage::imageUpdated, this, &Controller::update );
148  }
149  if( currentImage( ) != nullptr ) {
150  emit currentImageChanged( );
151  update( );
153  }
154 }
155 
157  if( currentImagePos( ) == ( m_images.count( ) - 1 ) ) {
158  setCurrentImagePos( 0 );
159  }
160  else {
162  }
163 }
164 
165 void Controller::setCurrentSlice( size_t view, size_t slice ) {
166  currentImage( )->setCurrentSlice( view, slice );
167 }
168 
169 void Controller::setZoom( int value ) {
170  /* FIXME Zoom doesn't work yet. */
171  scale = 1.0 + value / 100.0;
172  update( );
173 }
174 
175 void Controller::setInterpolation( bool isSmooth ) {
176  for( int view = 0; view < m_pixmapItems.size( ); ++view ) {
177  if( isSmooth ) {
178  m_pixmapItems[ view ]->setTransformationMode( Qt::SmoothTransformation );
179  }
180  else {
181  m_pixmapItems[ view ]->setTransformationMode( Qt::FastTransformation );
182  }
183  }
184 }
185 
187  currentImage( )->rotateAll90( );
188  emit currentImageChanged( );
189 }
190 
191 void Controller::rotate90( size_t view ) {
192  currentImage( )->rotate90( view );
193  emit currentImageChanged( );
194 }
195 
196 void Controller::flipH( size_t view ) {
197  currentImage( )->flipH( view );
198  emit currentImageChanged( );
199 }
200 
201 void Controller::flipV( size_t view ) {
202  currentImage( )->flipV( view );
203  emit currentImageChanged( );
204 }
205 
206 void Controller::setRecentFile( QString fname ) {
207  COMMENT( "Setting recent file to : \"" << fname.toStdString( ) << "\"", 1 );
208  if( !QFile( fname ).exists( ) ) {
209  return;
210  }
211  QSettings settings;
212  QStringList files = settings.value( "recentFileList" ).toStringList( );
213 
214  files.removeAll( fname );
215 
216  files.prepend( fname );
217  while( files.size( ) > MaxRecentFiles ) {
218  files.removeLast( );
219  }
220  settings.setValue( "recentFileList", files );
221 
222  emit recentFilesUpdated( );
223 }
224 
226  m_thumbsWidget = thumbsWidget;
227  m_thumbsWidget->setController( this );
228 }
229 
231  Modality mod = currentImage( )->modality( );
232  if( mod == Modality::RGB2D ) {
233  return( rgb2dFormat );
234  }
235  else if( mod == Modality::BW3D ) {
236  return( bw3dFormat );
237  }
238  else {
239  return( bw2dFormat );
240  }
241 }
242 
243 QGraphicsPixmapItem* Controller::getPixmapItem( size_t view ) {
244  return( m_pixmapItems.at( view ) );
245 }
246 
247 QGraphicsPixmapItem* Controller::getLabelItem( size_t view ) {
248  return( m_labelItems.at( view ) );
249 }
void setCurrentImagePos(int position)
setCurrentImagePos
Definition: controller.cpp:144
GuiImage * imageAt(int pos)
currentImage
Definition: controller.cpp:28
Modality
Definition: displayformat.h:9
Tool * currentTool()
currentTool returns the current Tool.
Definition: guiimage.cpp:150
void recentFilesUpdated()
recentFilesUpdated
Definition: tool.h:10
void rotateAll90()
rotateAll90 rotates all views in 90 degrees.
Definition: guiimage.cpp:433
void update()
update updates the image pixmaps.
Definition: controller.cpp:118
void setController(Controller *value)
DisplayFormat * currentFormat()
currentFormat returns the modality of current image.
Definition: controller.cpp:230
void flipH(size_t view)
flipH mirrors the current view on X axis.
Definition: guiimage.cpp:415
The GuiImage class is a bridge to the Bial::Image data structure to the QImage data structure...
Definition: guiimage.h:20
void setCurrentSlice(size_t view, size_t slice)
setCurrentSlice is called by the imageViewer when the slider or the spinbox have theis values updated...
Definition: controller.cpp:165
void setInterpolation(bool isSmooth)
setInterpolation switches between smoot and fast interpolation.
Definition: controller.cpp:175
void rotate90(size_t view)
rotate90 rotates a view in 90 degrees.
Definition: controller.cpp:191
Controller(int views, QObject *parent=0)
Controller&#39;s constructor.
Definition: controller.cpp:8
void flipH(size_t view)
flipH mirrors the current view on X axis.
Definition: controller.cpp:196
Modality modality()
modality is the image modality getter.
Definition: guiimage.cpp:160
bool removeCurrentLabel()
removeCurrentLabel removes the current label from current image.
Definition: controller.cpp:84
void setZoom(int value)
setZoom updates the zoom factor.
Definition: controller.cpp:169
void removeCurrentImage()
removeCurrentImage removes the current image from vector.
Definition: controller.cpp:89
void flipV(size_t view)
flipV mirrors the current view on Y axis.
Definition: guiimage.cpp:424
QPixmap getSlice(size_t view)
getSlice calculates and returns a QImage with the current slice of the view.
Definition: guiimage.cpp:175
void setCurrentSlice(size_t view, size_t slice)
currentSlice sets the view&#39;s current slice.
Definition: guiimage.cpp:330
void removeAt(int pos)
void addThumbnail(GuiImage *image)
std::array< bool, 4 > getViews()
void rotateAll90()
rotateAll90 rotates all views in 90 degrees.
Definition: controller.cpp:186
void flipV(size_t view)
flipV mirrors the current view on Y axis.
Definition: controller.cpp:201
int size()
size
Definition: controller.cpp:114
virtual QPixmap getLabel(size_t axis)
Definition: tool.cpp:18
bool isEmpty()
isEmpty
Definition: controller.cpp:101
void loadNextImage()
loadNextImage is a slot called from controlsdock that loads the next image ( like an circular list )...
Definition: controller.cpp:156
void imageUpdated()
imageUpdated is called each time a internal property is updated, after that the image views are updat...
void clear()
clear Clears the image vector, and resets thumbnails.
Definition: controller.cpp:105
QGraphicsPixmapItem * getLabelItem(size_t view)
getLabelItem returns the LabelItem of the view.
Definition: controller.cpp:247
QGraphicsPixmapItem * getPixmapItem(size_t view)
getPixmapItem returns the PixmapItem of the view.
Definition: controller.cpp:243
GuiImage * currentImage()
currentImage
Definition: controller.cpp:24
int currentImagePos() const
currentImagePos
Definition: controller.cpp:35
void currentImageChanged()
This signal is emmited every time the current image changes.
void rotate90(size_t view)
rotate90 rotates a view in 90 degrees.
Definition: guiimage.cpp:406
bool addLabel(QString label)
addLabel Adds a label to the current image.
Definition: controller.cpp:78
void setThumbsWidget(ThumbsWidget *thumbsWidget)
setThumbsWidget setThumbsWidget sets the pointer to the thumbnails dock.
Definition: controller.cpp:225
bool hasLabel() const
Definition: tool.cpp:3
#define BIAL_WARNING(exp)
Use BIAL_WARNING to print a message to the output stream warn the user that something bad may have ha...
Definition: Common.hpp:158
void containerUpdated()
This signal is emmited avery time the m_images vector is updated.
void imageUpdated()
This signal is emmited every time the current image is updated.
bool addImage(QString fname)
addImage Adds an image to vector m_images.
Definition: controller.cpp:39