Computer Assited Medical Intervention Tool Kit  version 5.0
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-2021 Univ. Grenoble Alpes, CNRS, Grenoble INP, 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"
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#include <QVTKWidget.h>
51#include <vtkSmartPointer.h>
52
53
54#elif VTK_MAJOR_VERSION == 8
55#include <QVTKOpenGLWidget.h>
56#include <vtkSmartPointer.h>
57
58#elif VTK_MAJOR_VERSION == 9
59#include <QVTKOpenGLStereoWidget.h>
60
61#else
62#error "Invalid VTK version: not (yet) supported."
63
64#endif
65
66// -- VTK stuff classes
67class vtkInteractorStyle;
68class vtkRenderer;
69class vtkPicker;
70class vtkProp;
71class vtkActor;
72class vtkActor2D;
73class vtkScalarBarActor;
74class vtkEventQtSlotConnect;
75class vtkCallbackCommand;
76class vtkCamera;
77class vtkAxesActor;
78class vtkAnnotatedCubeActor;
79class vtkScalarBarWidget;
80class vtkTextMapper;
81class vtkAbstractPropPicker;
82class vtkLogoWidget;
83
84namespace camitk {
85
86class vtkInteractorStylePick;
87
106#if VTK_MAJOR_VERSION == 6
107class CAMITK_API RendererWidget : public QVTKWidget2 {
108
109#elif VTK_MAJOR_VERSION == 7
110class CAMITK_API RendererWidget : public QVTKWidget {
111
112#elif VTK_MAJOR_VERSION == 8
113class CAMITK_API RendererWidget : public QVTKOpenGLWidget {
114
115#elif VTK_MAJOR_VERSION == 9
116class CAMITK_API RendererWidget : public QVTKOpenGLStereoWidget {
117
118#else
119#error "Invalid VTK version: not (yet) supported."
120#endif
121 Q_OBJECT
122
123public :
124
142 };
143 Q_ENUM(CameraOrientation) // so that it can be used in property editor
144
145
146 enum ControlMode {
147 JOYSTICK,
148 TRACKBALL,
149 TRACKBALL_2D,
150 NONE
151 };
152 Q_ENUM(ControlMode)
153
154
160 };
161
174 RendererWidget(QWidget* parent = nullptr, ControlMode mode = RendererWidget::TRACKBALL);
175
177 ~RendererWidget() override;
178
181
182 void setAreaPicking(bool areaPicking);
183
185 ControlMode getControlMode() const;
186
188 void setControlMode(ControlMode mode);
189
193 void setPicker(vtkSmartPointer<vtkAbstractPropPicker> woodyWood);
194
196 void pick();
197
199 void pickActor(int, int);
200
202 void keyPressEvent(QKeyEvent* e) override;
203
207 void screenshot(QString filename);
208
210 void refresh();
212
217
219 bool getBackfaceCulling() const;
220
223
226
229
232
234 void setPointSize(double size);
235
237 double getPointSize() const;
238
240 void rotateCamera(double angle, int axe);
241
247
249 void resetCamera(double* bounds);
250
252 void getCameraSettings(double* position, double* focalPoint, double* viewUp);
253
255 void setActiveCamera(vtkCamera* cam);
256
258 vtkCamera* getActiveCamera();
259
261 void getMouse3DCoordinates(double& x, double& y, double& z);
262
264 void setBackgroundColor(double, double, double);
265
267 void getBackgroundColor(double&, double&, double&);
268
271
274
277
279 void toggleLogo(bool);
280
282 void toggleAxes(bool);
283
286
289
291 void setOrientationDecorationsLetters(QString letters[4]);
292
294 void setColorScale(bool);
295
297 bool getColorScale() const;
298
303 void setColorScaleMinMax(double m, double M);
304
308 void setColorScaleTitle(QString t);
309
311 void computeVisiblePropBounds(double* bounds);
312
316 void resetClippingPlanes(double* bounds = nullptr);
318
321
330 void addProp(vtkSmartPointer<vtkProp> p, bool refresh = false);
331
333 bool containsProp(vtkSmartPointer<vtkProp>);
334
339 void removeProp(vtkSmartPointer<vtkProp> p, bool refresh = false);
340
342 void actorTransform(vtkSmartPointer<vtkActor>, double*, int, double**, double*, double*);
344
345protected slots:
350
353
355
356signals :
357
361 void actorPicked(vtkSmartPointer<vtkPicker>);
362
366
367protected:
368
370 void mousePressEvent(QMouseEvent* event) override;
371
373 void mouseReleaseEvent(QMouseEvent* event) override;
374
376 void mouseMoveEvent(QMouseEvent* event) override;
377
378protected :
379
383 vtkSmartPointer<QVTKInteractor> renderWindowInteractor;
384
386 vtkSmartPointer<vtkInteractorStyle> controlInteractorStyle;
387
389 ControlMode controlMode;
390
392
397
399 vtkSmartPointer<vtkRenderer> renderer;
400
402 bool backfaceCulling;
403
406
409
411 double pointSize;
412
416
420 //vtkSmartPointer<vtkEventQtSlotConnect> connector;
421
423 static void divertionCallback(vtkObject*, unsigned long, void*, void*) {};
424
426 vtkSmartPointer<vtkCallbackCommand> pickingButtonDiverter;
427
429 bool pickingDiverter;
430
432 vtkSmartPointer<vtkInteractorStylePick> pickInteractorStyle;
433
435
439 bool displayGradient;
440
442 bool displayLogo;
443
445 vtkSmartPointer<vtkLogoWidget> logoWidget;
446
449
451 vtkSmartPointer<vtkScalarBarActor> colorScale;
452
454 vtkSmartPointer<vtkScalarBarWidget> colorBarWidget;
455
457 vtkSmartPointer<vtkAxesActor> axes;
458
460 vtkSmartPointer<vtkAnnotatedCubeActor> annotatedCube;
461
463 vtkSmartPointer<vtkActor2D> orientationDecorationActors[4];
464
466 vtkSmartPointer<vtkTextMapper> orientationDecorationsTextMapper[4];
467
469
470};
471
472}
473
474#endif //RENDERERWIDGET_H
475
#define CAMITK_API
Definition: CamiTKAPI.h:49
CameraOrientation
RendererWidget implements all support methods to use camiTK with Qt interface.
Definition: RendererWidget.h:136
Definition: Action.cpp:35
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:314
void setAreaPicking(bool areaPicking)
RendererWidget::CameraOrientation getCameraOrientation() const
Return the current axes mode.
logoWidget
logo widget
Definition: RendererWidget.cpp:494
rendering3DRedBlue
is rendering in 3D stereo red/blue
Definition: RendererWidget.cpp:285
bool getBackfaceCulling() const
Get the current state of backface culling.
vtkSmartPointer< vtkActor2D > orientationDecorationActors[4]
annotated cube text actors
Definition: RendererWidget.h:463
void actorPicked(vtkSmartPointer< vtkPicker >)
ControlMode getControlMode() const
get the current control mode
pickInteractorStyle
picking interactor
Definition: RendererWidget.cpp:317
void setPointSize(double size)
set the default point size
vtkSmartPointer< vtkScalarBarActor > colorScale
the color scale displaying the lookup table + values
Definition: RendererWidget.h:451
pickingButtonDiverter
the callback to remove left button interaction while in picking mode
Definition: RendererWidget.cpp:330
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]
renderer
The current renderer.
Definition: RendererWidget.cpp:290
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:533
setBackgroundColor(0.0, 0.0, 0.0)
void toggleLogo(bool)
toggle logo
void toggleOrientationDecorations(bool)
display orientation decorations
cameraOrientation
state of the initial camera orientation
Definition: RendererWidget.cpp:324
annotatedCube
annotated cube actor
Definition: RendererWidget.cpp:380
void mouseMoveEvent(QMouseEvent *event) override
mouse move handler overriden to manage different version of VTK
void toggleAxes(bool)
display the axes
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:286
~RendererWidget() override
destructor
displayLogo
is the logo displayed
Definition: RendererWidget.cpp:284
double getPointSize() const
get the current value of point size
controlMode
current control mode
Definition: RendererWidget.cpp:323
void pickActor(int, int)
Perform picking from screen coordinates.
pointSize
default point size
Definition: RendererWidget.cpp:287
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:338
colorBarWidget
the scalar bar widget
Definition: RendererWidget.cpp:512
bool lightFollowCamera
Is the light following the camera.
Definition: RendererWidget.h:408
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:423
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:466
setCameraOrientation(cameraOrientation)
controlInteractorStyle
for the interaction with the scene
Definition: RendererWidget.cpp:325
void getCameraSettings(double *position, double *focalPoint, double *viewUp)
get camera settings information (position, what is looked at and how) in world coordinates
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:155
@ LEFT_BUTTON
the mouse left button is currently pressed
Definition: RendererWidget.h:157
@ RIGHT_BUTTON
the mouse right button is currently pressed
Definition: RendererWidget.h:159
@ NO_BUTTON
no buttons are currently pressed
Definition: RendererWidget.h:156
@ MIDDLE_BUTTON
the mouse middle button is currently pressed (or 3rd button emulation)
Definition: RendererWidget.h:158
void screenshot(QString filename)
save the screenshot in a file
vtkCamera * getActiveCamera()
get the active camera
bool getGradientBackground()
get the current state of the gradient background
pickingDiverter
is the picking diverter used
Definition: RendererWidget.cpp:333
backfaceCulling
Is back face culling on?
Definition: RendererWidget.cpp:283
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:139
@ RIGHT_DOWN
World axes are seen so that x points to the right, y points downward.
Definition: RendererWidget.h:137
@ BACK_DOWN
< World axes are seen so that x points to the left, y points backward. For Medical Images Coronal Vie...
Definition: RendererWidget.h:141
@ LEFT_BACK
Definition: RendererWidget.h:140
@ LEFT_UP
World axes are seen so that x points to the left, y points upward.
Definition: RendererWidget.h:138