Biomedical Image Analysis Library
The Biomedical Image Analysis Library is a poweful tool for developers, physicians, researchers, engineers, and so on.
defaulttool.cpp
Go to the documentation of this file.
1 #include "controller.h"
2 #include "defaulttool.h"
3 #include <QDebug>
4 #include <QPointF>
5 
6 DefaultTool::DefaultTool( GuiImage *guiImage, ImageViewer *viewer ) : Tool( guiImage, viewer ) {
7  setObjectName( "DefaultTool" );
8 }
9 
11  return( DefaultTool::Type );
12 }
13 
14 void DefaultTool::mouseReleased( QPointF pt, Qt::MouseButtons buttons, size_t axis ) {
15  COMMENT( "Mouse released.", 2 );
16  if( buttons & Qt::LeftButton ) {
17  changeOtherSlices( pt, axis );
18  updateOverlay( viewer->getScene( axis )->overlayPos( ), axis );
19  }
20 }
21 
22 void DefaultTool::mouseClicked( QPointF pt, Qt::MouseButtons buttons, size_t axis ) {
23  COMMENT( "Mouse clicked.", 2 );
24  if( buttons & Qt::LeftButton ) {
25  changeOtherSlices( pt, axis );
26  updateOverlay( viewer->getScene( axis )->overlayPos( ), axis );
27  }
28 }
29 
30 void DefaultTool::mouseDragged( QPointF pt, Qt::MouseButtons buttons, size_t axis ) {
31  COMMENT( "Mouse dragged.", 2 );
32  if( buttons & Qt::LeftButton ) {
33  changeOtherSlices( pt, axis );
34  updateOverlay( viewer->getScene( axis )->overlayPos( ), axis );
35  }
36 }
37 
38 void DefaultTool::mouseMoved( QPointF pt, size_t axis ) {
39  COMMENT( "Mouse moved.", 2 );
40  Q_UNUSED( pt )
41  Q_UNUSED( axis )
42 }
43 
44 void DefaultTool::changeOtherSlices( QPointF posF, size_t view ) {
45  COMMENT( "Changing slice position of other frames based on image position.", 2 );
46  if( ( guiImage->modality( ) == Modality::BW3D ) ) {
47  Bial::FastTransform transform = guiImage->getTransform( view );
48  Bial::Point3D pt =
49  transform( ( double ) posF.x( ), ( double ) posF.y( ), ( double ) guiImage->currentSlice( view ) );
50  for( size_t other = 0; other < 3; ++other ) {
51  if( other != view ) {
52  Bial::FastTransform otherTransf = guiImage->getTransform( other ).Inverse( );
53  Bial::Point3D otherPt = otherTransf( pt );
54  size_t pos = static_cast< size_t >( round( otherPt.z ) );
55  if( pos < guiImage->depth( other ) ) {
56  guiImage->setCurrentSlice( other, pos );
57  }
58  }
59  }
60  }
61 }
62 
63 void DefaultTool::updateOverlay( QPointF pt, size_t axis ) {
64  /* qDebug() << "Overlaypos = " << pt; */
65  COMMENT( "ImageViewer::updateOverlay", 0 );
66  pt.setX( qMin( qMax( pt.x( ), 0.0 ), ( double ) guiImage->width( axis ) ) );
67  pt.setY( qMin( qMax( pt.y( ), 0.0 ), ( double ) guiImage->heigth( axis ) ) );
68  viewer->getScene( axis )->setOverlayPos( pt );
69  Controller *controller = viewer->controller( );
70 
71  Bial::FastTransform transform = guiImage->getTransform( axis );
72  Bial::Point3D pt3d = transform( ( double ) pt.x( ), ( double ) pt.y( ), ( double ) guiImage->currentSlice( axis ) );
73  size_t size = controller->currentFormat( )->getMaximumNumberOfViews( );
74  for( size_t other = 0; other < size; ++other ) {
75  if( controller->currentFormat( )->overlay( ) ) {
76  viewer->getScene( other )->setOverlay( true );
77  if( other != axis ) {
78  Bial::FastTransform otherTransf = guiImage->getTransform( other ).Inverse( );
79  Bial::Point3D otherPt = otherTransf( pt3d );
80  viewer->getScene( other )->setOverlayPos( QPointF( otherPt.x, otherPt.y ) );
81  }
82  }
83  }
84 }
85 
86 void DefaultTool::sliceChanged( size_t axis, size_t slice ) {
87  Q_UNUSED( slice )
88  updateOverlay( viewer->getScene( axis )->overlayPos( ), axis );
89 }
double z
Point position in z.
Definition: Geometrics.hpp:227
void mouseMoved(QPointF pt, size_t axis)
Definition: defaulttool.cpp:38
GuiImage * guiImage
Definition: tool.h:13
Definition: tool.h:10
size_t getMaximumNumberOfViews() const
DisplayFormat * currentFormat()
currentFormat returns the modality of current image.
Definition: controller.cpp:230
ImageViewer * viewer
Definition: tool.h:14
The GuiImage class is a bridge to the Bial::Image data structure to the QImage data structure...
Definition: guiimage.h:20
size_t heigth(size_t view)
heigth is the view heigth.
Definition: guiimage.cpp:322
The Point3D class is a Geometric representation of a point in 3D space. A point is a zero­dimension...
Definition: Geometrics.hpp:218
static size_t size
Definition: enough.c:173
void setOverlayPos(QPointF pos)
Controller * controller() const
Definition: imageviewer.cpp:63
Modality modality()
modality is the image modality getter.
Definition: guiimage.cpp:160
void mouseReleased(QPointF pt, Qt::MouseButtons buttons, size_t axis)
Definition: defaulttool.cpp:14
double y
Point position in y.
Definition: Geometrics.hpp:225
size_t width(size_t view)
width is the view width.
Definition: guiimage.cpp:318
void setCurrentSlice(size_t view, size_t slice)
currentSlice sets the view&#39;s current slice.
Definition: guiimage.cpp:330
The Controller class is one of the most important classes of the User Interface, and is responsible t...
Definition: controller.h:17
GraphicsScene * getScene(size_t axis)
Bial::FastTransform getTransform(size_t axis)
getTransform returns the transform matrix of the views.
Definition: guiimage.cpp:350
void sliceChanged(size_t axis, size_t slice)
Definition: defaulttool.cpp:86
void updateOverlay(QPointF pt, size_t axis)
Definition: defaulttool.cpp:63
DefaultTool(GuiImage *guiImage, ImageViewer *viewer)
Definition: defaulttool.cpp:6
bool overlay() const
void mouseClicked(QPointF pt, Qt::MouseButtons buttons, size_t axis)
Definition: defaulttool.cpp:22
size_t currentSlice(size_t view)
currentSlice is the view&#39;s current slice.
Definition: guiimage.cpp:447
FastTransform Inverse()
QPointF overlayPos() const
void mouseDragged(QPointF pt, Qt::MouseButtons buttons, size_t axis)
Definition: defaulttool.cpp:30
void setOverlay(bool overlay)