UsTK : Ultrasound ToolKit  version 2.0.1 under development (2024-05-17)
us2DSceneWidget.h
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 #ifndef __us2DSceneWidget_h_
39 #define __us2DSceneWidget_h_
40 
41 // VISP includes
42 #include <visp3/ustk_core/usConfig.h>
43 
44 #ifdef USTK_HAVE_VTK_QT
45 
46 #include <visp3/core/vpException.h>
47 #include <visp3/core/vpHomogeneousMatrix.h>
48 
49 #include <visp3/ustk_core/us.h>
50 #include <visp3/ustk_gui/usVTKConverter.h>
51 #include <visp3/ustk_gui/usViewerWidget.h>
52 
53 // VTK includes
54 #include <vtkImageActor.h>
55 #include <vtkImageData.h>
56 #include <vtkImageMapToColors.h>
57 #include <vtkImageReslice.h>
58 #include <vtkImageResliceMapper.h>
59 #include <vtkImageSlice.h>
60 #include <vtkInteractorStyleImage.h>
61 #include <vtkLookupTable.h>
62 #include <vtkPlane.h>
63 #include <vtkRenderWindow.h>
64 #include <vtkRenderer.h>
65 #include <vtkSmartPointer.h>
66 
67 #include <vtkAnnotatedCubeActor.h>
68 #include <vtkCellArray.h>
69 #include <vtkCommand.h>
70 #include <vtkCoordinate.h>
71 #include <vtkImageActor.h>
72 #include <vtkImageData.h>
73 #include <vtkImageMapToColors.h>
74 #include <vtkImageMapper3D.h>
75 #include <vtkImageReader2.h>
76 #include <vtkImageReslice.h>
77 #include <vtkInformation.h>
78 #include <vtkInteractorStyleImage.h>
79 #include <vtkLine.h>
80 #include <vtkLookupTable.h>
81 #include <vtkMatrix4x4.h>
82 #include <vtkMetaImageReader.h>
83 #include <vtkPNGWriter.h>
84 #include <vtkPointPicker.h>
85 #include <vtkPoints.h>
86 #include <vtkPolyData.h>
87 #include <vtkPolyDataMapper.h>
88 #include <vtkPolygon.h>
89 #include <vtkPropPicker.h>
90 #include <vtkProperty.h>
91 #include <vtkRenderWindow.h>
92 #include <vtkRenderWindowInteractor.h>
93 #include <vtkRenderer.h>
94 #include <vtkResliceCursor.h>
95 #include <vtkResliceCursorWidget.h>
96 #include <vtkSTLReader.h>
97 #include <vtkSmartPointer.h>
98 #include <vtkStreamingDemandDrivenPipeline.h>
99 
100 // Qt includes
101 #if defined(USTK_HAVE_VTK_QT4)
102 #include <QApplication>
103 #include <QtCore/QPoint>
104 #include <QtGui/QGridLayout>
105 #include <QtGui/QMainWindow>
106 #include <QtGui/QPainter>
107 #include <QtGui/QPushButton>
108 #include <QtGui/QWheelEvent>
109 #elif defined USTK_HAVE_VTK_QT5
110 #include <QApplication>
111 #include <QWheelEvent>
112 #include <QtWidgets/QGridLayout>
113 #include <QtWidgets/QMainWindow>
114 #include <QtWidgets/QPushButton>
115 #endif
116 
117 #if USTK_HAVE_VTK_VERSION < 0x090000
118 #include <QVTKWidget.h>
119 #else
120 #include <QVTKOpenGLStereoWidget.h>
121 #endif
122 
129 class VISP_EXPORT us2DSceneWidget : public usViewerWidget
130 {
131  Q_OBJECT
132 public:
133  // Constructor/Destructor
134  us2DSceneWidget(QWidget *parent = NULL, Qt::WindowFlags f = Qt::WindowFlags());
136 
137  void drawLine(double u1, double v1, double w1, double u2, double v2, double w2);
138 
139  void getClick(vpColVector &vec);
140 
141  void getCurrentSlice(usImagePostScan2D<unsigned char> &image2D);
142 
143  vtkImageData *getImageData();
144 
145  vtkMatrix4x4 *getResliceMatrix();
146 
147  vtkPlane *getReslicePlane();
148 
149  void init();
150 
151  // get key pressed/released (to make rotations of the plane)
152  void keyPressEvent(QKeyEvent *event);
153  void keyReleaseEvent(QKeyEvent *event);
154 
155  void mouseMoveEvent(QMouseEvent *event);
156  void mousePressEvent(QMouseEvent *event);
157 
158  // Catch paint events, in case we want to display some informations (writing in this widget) over the vtk scene
159  void paintEvent(QPaintEvent *event);
160 
161  // Set view color
162  void setColor(double r, double g, double b);
163 
164  // Set image to display
165  void setImageData(vtkImageData *imageData);
166 
167  // Set planes
168  void setResliceMatrix(vtkMatrix4x4 *matrix);
169 
170  void setPolyDataPlaneContour(vtkPolyData *polyData);
171  void setPolyDataMeshContour(vtkPolyData *polyData);
172 
173  // catch scroll events to slice in image
174  void wheelEvent(QWheelEvent *event);
175 
176 public slots:
177  void updateImageData(vtkImageData *imageData);
178 
179  void changeMatrix(vpHomogeneousMatrix matrix);
180 
181  void saveViewSlot();
182  void updateView();
183 
184 signals:
185  void matrixChanged(vtkMatrix4x4 *matrix);
186  void voxelPicked(vpColVector vector);
187 
188 private:
189  // image
190  vtkImageData *m_imageData;
191 
192  // R T matrix
193  vtkMatrix4x4 *m_resliceMatrix;
194 
195  // image reslice
196  vtkImageReslice *m_reslice;
197 
198  // LUT
199  vtkLookupTable *m_table;
200 
201  // color mapper
202  vtkImageMapToColors *m_color;
203 
204  // actor
205  vtkImageActor *m_actor;
206 
207  // vtk renderer
208  vtkRenderer *m_renderer;
209  vtkRenderer *m_polyDataRenderer;
210 
211  // polydata of plane contour
212  vtkPolyData *m_polydataPlaneContour;
213  vtkPolyDataMapper *m_polyDataPlaneContourMapper;
214  vtkActor *m_polydataPlaneContourActor;
215 
216  // polydata of mesh contour in the plane
217  vtkPolyData *m_polydataMeshContour;
218  vtkPolyDataMapper *m_polyDataMeshContourMapper;
219  vtkActor *m_polydataMeshContourActor;
220 
221  // vtk picker
222  vtkPropPicker *m_propPicker;
223 
224  // to know if r key is currently pressed
225  bool m_rPressed;
226  bool m_pPressed;
227 
228  // mouse button pressed
229  bool m_mousePressed;
230 
231  // for rotations
232  int m_lastmouserPosX;
233  int m_lastmouserPosY;
234 
235  // for getClick blocking
236  bool m_pickingState;
237  vpColVector m_pickedVoxel;
238 };
239 #endif
240 #endif // __us2DSceneWidget_h_
Class used to render a 2D slice of a vtkImageData in a vtk scene in a QWidget (based on QVTKWidget)
vtkPlane * getReslicePlane()
void voxelPicked(vpColVector vector)
void matrixChanged(vtkMatrix4x4 *matrix)
View used to render a vtk scene in a QWidget (based on QVTKWidget for Qt4, QVTKOpenGLWidget for Qt5)
void paintEvent(QPaintEvent *event)