Computer Assisted Medical Intervention Tool Kit  version 5.2
RendererWidget.h
Go to the documentation of this file.
1 /*****************************************************************************
2  * $CAMITK_LICENCE_BEGIN$
3  *
4  * CamiTK - Computer Assisted Medical Intervention ToolKit
5  * (c) 2001-2024 Univ. Grenoble Alpes, CNRS, Grenoble INP - UGA, TIMC, 38000 Grenoble, France
6  *
7  * Visit http://camitk.imag.fr for more information
8  *
9  * This file is part of CamiTK.
10  *
11  * CamiTK is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * CamiTK is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU Lesser General Public License version 3 for more details.
19  *
20  * You should have received a copy of the GNU Lesser General Public License
21  * version 3 along with CamiTK. If not, see <http://www.gnu.org/licenses/>.
22  *
23  * $CAMITK_LICENCE_END$
24  ****************************************************************************/
25 
26 #ifndef RENDERERWIDGET_H
27 #define RENDERERWIDGET_H
28 
29 #ifdef CAMITK_ERROR
30 #error "Header Error: headers reordering required. Please include Log.h after including RendererWidget.h and InteractiveViewer.h or any OpenGL window based class."
31 #endif
32 
33 // -- Core stuff
34 #include "CamiTKAPI.h"
35 #include "ScreenshotFormatInfo.h"
36 
37 // -- VTK stuff
38 #include <vtkVersion.h>
39 // disable warning generated by clang about the surrounded headers
40 #include <CamiTKDisableWarnings>
41 #include <QVTKInteractor.h>
42 #include <CamiTKReEnableWarnings>
43 
44 #if VTK_MAJOR_VERSION == 6
45 #include <QVTKWidget2.h>
46 // additional needed headers for QVTKWidget2
47 #include <vtkGenericOpenGLRenderWindow.h>
48 
49 #elif VTK_MAJOR_VERSION == 7
50 // Silence depreciation warning on VTK7 in QVTKWidget constructor
51 // due to Qt::WindowFlags initialized to 0
52 // -Wno-deprecated-declarations
53 #if defined(__GNUC__) || defined(__clang__)
54 #pragma GCC diagnostic push
55 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
56 #endif
57 #ifdef QT_WARNING_DISABLE_DEPRECATED
58 QT_WARNING_PUSH QT_WARNING_DISABLE_DEPRECATED
59 #endif
60 
61 #include <QVTKWidget.h>
62 
63 #if defined(__GNUC__) || defined(__clang__)
64 #pragma GCC diagnostic pop
65 #endif
66 #ifdef QT_WARNING_DISABLE_DEPRECATED
67 QT_WARNING_POP
68 #endif
69 
70 #include <vtkSmartPointer.h>
71 
72 
73 #elif VTK_MAJOR_VERSION == 8
74 #include <QVTKOpenGLWidget.h>
75 #include <vtkSmartPointer.h>
76 
77 #elif VTK_MAJOR_VERSION == 9
78 #include <QVTKOpenGLStereoWidget.h>
79 
80 #else
81 #error "Invalid VTK version: not (yet) supported."
82 
83 #endif
84 
85 // -- VTK stuff classes
86 class vtkInteractorStyle;
87 class vtkRenderer;
88 class vtkPicker;
89 class vtkProp;
90 class vtkActor;
91 class vtkActor2D;
92 class vtkScalarBarActor;
93 class vtkEventQtSlotConnect;
94 class vtkCallbackCommand;
95 class vtkCamera;
96 class vtkAxesActor;
97 class vtkAnnotatedCubeActor;
98 class vtkScalarBarWidget;
99 class vtkTextMapper;
100 class vtkAbstractPropPicker;
101 class vtkLogoWidget;
102 
103 namespace camitk {
104 
105 class vtkInteractorStylePick;
106 
125 #if VTK_MAJOR_VERSION == 6
126 class CAMITK_API RendererWidget : public QVTKWidget2 {
127 
128 #elif VTK_MAJOR_VERSION == 7
129 class CAMITK_API RendererWidget : public QVTKWidget {
130 
131 #elif VTK_MAJOR_VERSION == 8
132 class CAMITK_API RendererWidget : public QVTKOpenGLWidget {
133 
134 #elif VTK_MAJOR_VERSION == 9
135 class CAMITK_API RendererWidget : public QVTKOpenGLStereoWidget {
136 
137 #else
138 #error "Invalid VTK version: not (yet) supported."
139 #endif
140  Q_OBJECT
141 
142 public :
143 
161  };
162  Q_ENUM(CameraOrientation) // so that it can be used in property editor
163 
164 
165  enum ControlMode {
166  JOYSTICK,
167  TRACKBALL,
168  TRACKBALL_2D,
169  NONE
170  };
171  Q_ENUM(ControlMode)
172 
173 
178  RIGHT_BUTTON
179  };
180 
193  RendererWidget(QWidget* parent = nullptr, ControlMode mode = RendererWidget::TRACKBALL);
194 
196  ~RendererWidget() override;
197 
200 
201  void setAreaPicking(bool areaPicking);
202 
204  ControlMode getControlMode() const;
205 
207  void setControlMode(ControlMode mode);
208 
212  void setPicker(vtkSmartPointer<vtkAbstractPropPicker> woodyWood);
213 
215  void pick();
216 
218  void pickActor(int, int);
219 
221  void keyPressEvent(QKeyEvent* e) override;
222 
226  void screenshot(QString filename);
227 
229  void refresh();
231 
235  void setBackfaceCulling(bool);
236 
238  bool getBackfaceCulling() const;
239 
242 
244  bool getFxaaAntialiasing() const;
245 
248 
251 
254 
256  bool getLightFollowCamera() const;
257 
259  void setPointSize(double size);
260 
262  double getPointSize() const;
263 
265  void rotateCamera(double angle, int axe);
266 
271  void resetCamera();
272 
274  void resetCamera(double* bounds);
275 
277  void getCameraSettings(double* position, double* focalPoint, double* viewUp);
278 
280  void setActiveCamera(vtkCamera* cam);
281 
283  vtkCamera* getActiveCamera();
284 
286  void getMouse3DCoordinates(double& x, double& y, double& z);
287 
289  void setBackgroundColor(double, double, double);
290 
292  void getBackgroundColor(double&, double&, double&);
293 
296 
299 
302 
304  void toggleLogo(bool);
305 
307  void toggleAxes(bool);
308 
310  void updateAxes();
311 
314 
316  void setOrientationDecorationsLetters(QString letters[4]);
317 
319  void setColorScale(bool);
320 
322  bool getColorScale() const;
323 
328  void setColorScaleMinMax(double m, double M);
329 
333  void setColorScaleTitle(QString t);
334 
336  void computeVisiblePropBounds(double* bounds);
337 
341  void resetClippingPlanes(double* bounds = nullptr);
343 
346 
355  void addProp(vtkSmartPointer<vtkProp> p, bool refresh = false);
356 
358  bool containsProp(vtkSmartPointer<vtkProp>);
359 
364  void removeProp(vtkSmartPointer<vtkProp> p, bool refresh = false);
365 
367  void actorTransform(vtkSmartPointer<vtkActor>, double*, int, double**, double*, double*);
369 
370 protected slots:
374  void startPicking();
375 
377  void endPicking();
378 
380 
381 signals :
382 
386  void actorPicked(vtkSmartPointer<vtkPicker>);
387 
391 
392 protected:
393 
395  void mousePressEvent(QMouseEvent* event) override;
396 
398  void mouseReleaseEvent(QMouseEvent* event) override;
399 
401  void mouseMoveEvent(QMouseEvent* event) override;
402 
403 protected :
404 
408  vtkSmartPointer<QVTKInteractor> renderWindowInteractor;
409 
411  vtkSmartPointer<vtkInteractorStyle> controlInteractorStyle;
412 
414  ControlMode controlMode;
415 
417 
422 
424  vtkSmartPointer<vtkRenderer> renderer;
425 
427  bool backfaceCulling;
428 
429  // Is FXAA antialiasing on?
430  bool fxaaAntialiasing;
431 
434 
437 
439  double pointSize;
440 
442  bool rendering3DRedBlue;
444 
448  //vtkSmartPointer<vtkEventQtSlotConnect> connector;
449 
451  static void divertionCallback(vtkObject*, unsigned long, void*, void*) {};
452 
454  vtkSmartPointer<vtkCallbackCommand> pickingButtonDiverter;
455 
457  bool pickingDiverter;
458 
460  vtkSmartPointer<vtkInteractorStylePick> pickInteractorStyle;
461 
463 
467  bool displayGradient;
468 
470  bool displayLogo;
471 
473  vtkSmartPointer<vtkLogoWidget> logoWidget;
474 
476  bool displayColorScale;
477 
479  vtkSmartPointer<vtkScalarBarActor> colorScale;
480 
482  vtkSmartPointer<vtkScalarBarWidget> colorBarWidget;
483 
485  vtkSmartPointer<vtkAxesActor> axes;
486 
488  vtkSmartPointer<vtkAnnotatedCubeActor> annotatedCube;
489 
491  vtkSmartPointer<vtkActor2D> orientationDecorationActors[4];
492 
494  vtkSmartPointer<vtkTextMapper> orientationDecorationsTextMapper[4];
495 
497 
498 };
499 
500 }
501 
502 #endif //RENDERERWIDGET_H
503 
#define CAMITK_API
Definition: CamiTKAPI.h:49
CameraOrientation
RendererWidget implements all support methods to use camiTK with Qt interface.
Definition: RendererWidget.h:155
Definition: Action.cpp:36
void toogle3DRedBlue()
toggle stereo 3D red/blue rendering (you will need red/blue glasses)
void setBackfaceCulling(bool)
void pick()
Perform picking using the current mouse position.
void setPicker(vtkSmartPointer< vtkAbstractPropPicker > woodyWood)
set the picker to handle the action
void setColorScale(bool)
display the color scale in the viewport, use setColorScaleMinMax to change the displayed values
void resetCameraSettings()
void setGradientBackground(bool)
set the gradient background
void setColorScaleMinMax(double m, double M)
set the min and max values.
void getBackgroundColor(double &, double &, double &)
get the background color (rgb)
setControlMode(mode)
renderWindowInteractor
Definition: RendererWidget.cpp:343
void setAreaPicking(bool areaPicking)
RendererWidget::CameraOrientation getCameraOrientation() const
Return the current axes mode.
logoWidget
logo widget
Definition: RendererWidget.cpp:520
rendering3DRedBlue
is rendering in 3D stereo red/blue
Definition: RendererWidget.cpp:314
bool getBackfaceCulling() const
Get the current state of backface culling.
vtkSmartPointer< vtkActor2D > orientationDecorationActors[4]
annotated cube text actors
Definition: RendererWidget.h:491
void actorPicked(vtkSmartPointer< vtkPicker >)
ControlMode getControlMode() const
get the current control mode
pickInteractorStyle
picking interactor
Definition: RendererWidget.cpp:346
void setPointSize(double size)
set the default point size
vtkSmartPointer< vtkScalarBarActor > colorScale
the color scale displaying the lookup table + values
Definition: RendererWidget.h:479
pickingButtonDiverter
the callback to remove left button interaction while in picking mode
Definition: RendererWidget.cpp:356
void removeProp(vtkSmartPointer< vtkProp > p, bool refresh=false)
remove the given vtkProp (e.g.
void computeVisiblePropBounds(double *bounds)
get the bounding box of all visible actors [xmin,xmax, ymin,ymax, zmin,zmax]
void setFxaaAntialiasing(bool)
Set/unset FXAA Antialiasing in renderer.
renderer
The current renderer.
Definition: RendererWidget.cpp:319
void mouseReleaseEvent(QMouseEvent *event) override
mouse release handler overriden to manage different version of VTK
void setColorScaleTitle(QString t)
set the color scale title.
displayGradient
Definition: RendererWidget.cpp:559
setBackgroundColor(0.0, 0.0, 0.0)
void toggleLogo(bool)
toggle logo
bool getFxaaAntialiasing() const
Get the current state of FXAA Antialiasing in renderer.
void toggleOrientationDecorations(bool)
display orientation decorations
cameraOrientation
state of the initial camera orientation
Definition: RendererWidget.cpp:350
annotatedCube
annotated cube actor
Definition: RendererWidget.cpp:406
void mouseMoveEvent(QMouseEvent *event) override
mouse move handler overriden to manage different version of VTK
void toggleAxes(bool)
display the axes
vtkCamera * getActiveCamera()
get the active camera
void resetClippingPlanes(double *bounds=nullptr)
reset the camera clipping plane to a given bounding box If no bounds are given, reset to show all vis...
void setLightFollowCamera(bool)
Set/unset the light to follow the camera.
void rightButtonPressed()
send when the mouse right button is clicked
void keyPressEvent(QKeyEvent *e) override
key events (do nothing but pass on e to the parent widget), please do not add any shortcut management...
bool getLightFollowCamera() const
Get the current state of the property.
RendererWidget(QWidget *parent=nullptr, ControlMode mode=RendererWidget::TRACKBALL)
constructors.
bool getColorScale() const
get the color display state
void mousePressEvent(QMouseEvent *event) override
mouse press handler overriden to manage different version of VTK
displayColorScale
is the color scale currently displayed
Definition: RendererWidget.cpp:315
~RendererWidget() override
destructor
displayLogo
is the logo displayed
Definition: RendererWidget.cpp:313
double getPointSize() const
get the current value of point size
controlMode
current control mode
Definition: RendererWidget.cpp:349
void pickActor(int, int)
Perform picking from screen coordinates.
pointSize
default point size
Definition: RendererWidget.cpp:316
void rotateCamera(double angle, int axe)
Rotate the camera around param "axe" of "angle" degrees.
void refresh()
refresh the display
void startPicking()
axes
axes actor
Definition: RendererWidget.cpp:364
colorBarWidget
the scalar bar widget
Definition: RendererWidget.cpp:538
bool lightFollowCamera
Is the light following the camera.
Definition: RendererWidget.h:436
void updateAxes()
update the axes sizes
void setOrientationDecorationsLetters(QString letters[4])
give the lettres for orientation decoration: Left, Right, Top, Down
void resetCamera()
reset the camera to the default position, default FOV.
static void divertionCallback(vtkObject *, unsigned long, void *, void *)
a diverter observer callback (to be used to divert undesired events)
Definition: RendererWidget.h:451
addProp(axes)
void getMouse3DCoordinates(double &x, double &y, double &z)
get the mouse coordinates in 3D
vtkSmartPointer< vtkTextMapper > orientationDecorationsTextMapper[4]
annotated cube text
Definition: RendererWidget.h:494
setCameraOrientation(cameraOrientation)
controlInteractorStyle
for the interaction with the scene
Definition: RendererWidget.cpp:351
void getCameraSettings(double *position, double *focalPoint, double *viewUp)
get camera settings information (position, what is looked at and how) in world coordinates
fxaaAntialiasing
Definition: RendererWidget.cpp:312
void endPicking()
end picking
bool containsProp(vtkSmartPointer< vtkProp >)
is the given vtkProp (e.g. vtkActor or vtkActor2D) in this renderer
void actorTransform(vtkSmartPointer< vtkActor >, double *, int, double **, double *, double *)
perform the transformation of the actor
MouseButtonState
state of the pressed button (for 3 buttons mouse)
Definition: RendererWidget.h:174
@ LEFT_BUTTON
the mouse left button is currently pressed
Definition: RendererWidget.h:176
@ RIGHT_BUTTON
the mouse right button is currently pressed
Definition: RendererWidget.h:178
@ NO_BUTTON
no buttons are currently pressed
Definition: RendererWidget.h:175
@ MIDDLE_BUTTON
the mouse middle button is currently pressed (or 3rd button emulation)
Definition: RendererWidget.h:177
void screenshot(QString filename)
save the screenshot in a file
bool getGradientBackground()
get the current state of the gradient background
pickingDiverter
is the picking diverter used
Definition: RendererWidget.cpp:359
backfaceCulling
Is back face culling on?
Definition: RendererWidget.cpp:311
void setActiveCamera(vtkCamera *cam)
set active camera
@ RIGHT_UP
World axes are seen so that x points to the right, y points upward.
Definition: RendererWidget.h:158
@ RIGHT_DOWN
World axes are seen so that x points to the right, y points downward.
Definition: RendererWidget.h:156
@ BACK_DOWN
< World axes are seen so that x points to the left, y points backward. For Medical Images Coronal Vie...
Definition: RendererWidget.h:160
@ LEFT_BACK
Definition: RendererWidget.h:159
@ LEFT_UP
World axes are seen so that x points to the left, y points upward.
Definition: RendererWidget.h:157