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"
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 #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 #else
59 #error "Invalid VTK version: not (yet) supported."
60 
61 #endif
62 
63 // -- VTK stuff classes
64 class vtkInteractorStyle;
65 class vtkRenderer;
66 class vtkPicker;
67 class vtkProp;
68 class vtkActor;
69 class vtkActor2D;
70 class vtkScalarBarActor;
71 class vtkEventQtSlotConnect;
72 class vtkCallbackCommand;
73 class vtkCamera;
74 class vtkAxesActor;
75 class vtkAnnotatedCubeActor;
76 class vtkScalarBarWidget;
77 class vtkTextMapper;
78 class vtkAbstractPropPicker;
79 class vtkLogoWidget;
80 
81 namespace camitk {
82 
83 class vtkInteractorStylePick;
84 
103 #if VTK_MAJOR_VERSION == 6
104 class CAMITK_API RendererWidget : public QVTKWidget2 {
105 
106 #elif VTK_MAJOR_VERSION == 7
107 class CAMITK_API RendererWidget : public QVTKWidget {
108 
109 #elif VTK_MAJOR_VERSION == 8
110 class CAMITK_API RendererWidget : public QVTKOpenGLWidget {
111 
112 #else
113 #error "Invalid VTK version: not (yet) supported."
114 #endif
115  Q_OBJECT
116 
117 public :
118 
136  };
137  Q_ENUM(CameraOrientation) // so that it can be used in property editor
138 
139 
140  enum ControlMode {
141  JOYSTICK,
142  TRACKBALL,
143  TRACKBALL_2D,
144  NONE
145  };
146  Q_ENUM(ControlMode)
147 
148 
154  };
155 
168  RendererWidget(QWidget* parent = nullptr, ControlMode mode = RendererWidget::TRACKBALL);
169 
171  ~RendererWidget() override;
172 
175 
176  void setAreaPicking(bool areaPicking);
177 
179  ControlMode getControlMode() const;
180 
182  void setControlMode(ControlMode mode);
183 
187  void setPicker(vtkSmartPointer<vtkAbstractPropPicker> woodyWood);
188 
190  void pick();
191 
193  void pickActor(int, int);
194 
196  void keyPressEvent(QKeyEvent* e) override;
197 
201  void screenshot(QString filename);
202 
204  void refresh();
206 
210  void setBackfaceCulling(bool);
211 
213  bool getBackfaceCulling() const;
214 
217 
220 
222  void setLightFollowCamera(bool);
223 
225  bool getLightFollowCamera() const;
226 
228  void setPointSize(double size);
229 
231  double getPointSize() const;
232 
234  void rotateCamera(double angle, int axe);
235 
240  void resetCamera();
241 
243  void resetCamera(double* bounds);
244 
246  void getCameraSettings(double* position, double* focalPoint, double* viewUp);
247 
249  void setActiveCamera(vtkCamera* cam);
250 
252  vtkCamera* getActiveCamera();
253 
255  void getMouse3DCoordinates(double& x, double& y, double& z);
256 
258  void setBackgroundColor(double, double, double);
259 
261  void getBackgroundColor(double&, double&, double&);
262 
264  bool getGradientBackground();
265 
267  void setGradientBackground(bool);
268 
270  void toogle3DRedBlue();
271 
273  void toggleLogo(bool);
274 
276  void toggleAxes(bool);
277 
279  void updateAxes();
280 
282  void toggleOrientationDecorations(bool);
283 
285  void setOrientationDecorationsLetters(QString letters[4]);
286 
287 
289  void setColorScale(bool);
290 
292  bool getColorScale() const;
293 
298  void setColorScaleMinMax(double m, double M);
299 
303  void setColorScaleTitle(QString t);
304 
306  void computeVisiblePropBounds(double* bounds);
307 
311  void resetClippingPlanes(double* bounds = nullptr);
313 
316 
325  void addProp(vtkSmartPointer<vtkProp> p, bool refresh = false);
326 
328  bool containsProp(vtkSmartPointer<vtkProp>);
329 
334  void removeProp(vtkSmartPointer<vtkProp> p, bool refresh = false);
335 
337  void actorTransform(vtkSmartPointer<vtkActor>, double*, int, double**, double*, double*);
339 
340 protected slots:
344  void startPicking();
345 
347  void endPicking();
348 
350 
351 signals :
352 
356  void actorPicked(vtkSmartPointer<vtkPicker>);
357 
359  void rightButtonPressed();
361 
362 protected:
363 
365  void mousePressEvent(QMouseEvent* event) override;
366 
368  void mouseReleaseEvent(QMouseEvent* event) override;
369 
371  void mouseMoveEvent(QMouseEvent* event) override;
372 
373 protected :
374 
378  vtkSmartPointer<QVTKInteractor> interactor;
379 
381  vtkSmartPointer<vtkInteractorStyle> controlInteractorStyle;
382 
384  //InteractionMode interactionMode;
385 
387  ControlMode controlMode;
388 
390 
394  void resetCameraSettings();
395 
397  vtkSmartPointer<vtkRenderer> renderer;
398 
400  bool backfaceCulling;
401 
404 
407 
409  double pointSize;
410 
412  bool rendering3DRedBlue;
414 
418  //vtkSmartPointer<vtkEventQtSlotConnect> connector;
419 
421  static void divertionCallback(vtkObject*, unsigned long, void*, void*) {};
422 
424  vtkSmartPointer<vtkCallbackCommand> pickingButtonDiverter;
425 
427  bool pickingDiverter;
428 
430  vtkSmartPointer<vtkInteractorStylePick> pickInteractorStyle;
431 
433 
437  bool displayGradient;
438 
440  bool displayLogo;
441 
443  vtkSmartPointer<vtkLogoWidget> logoWidget;
444 
446  bool displayColorScale;
447 
449  vtkSmartPointer<vtkScalarBarActor> colorScale;
450 
452  vtkSmartPointer<vtkScalarBarWidget> colorBarWidget;
453 
455  vtkSmartPointer<vtkAxesActor> axes;
456 
458  vtkSmartPointer<vtkAnnotatedCubeActor> annotatedCube;
459 
461  vtkSmartPointer<vtkActor2D> orientationDecorationActors[4];
462 
464  vtkSmartPointer<vtkTextMapper> orientationDecorationsTextMapper[4];
465 
467 
468 };
469 
470 }
471 
472 #endif //RENDERERWIDGET_H
473 
camitk::orientationDecorationsProp
vtkSmartPointer< vtkTextProperty > orientationDecorationsProp
Definition: RendererWidget.cpp:413
camitk::imageReader
vtkSmartPointer< vtkPNGReader > imageReader
Definition: RendererWidget.cpp:452
camitk::setBackfaceCulling
void setBackfaceCulling(bool)
camitk::divertionCallback
static void divertionCallback(vtkObject *, unsigned long, void *, void *)
a diverter observer callback (to be used to divert undesired events)
Definition: RendererWidget.h:421
CAMITK_WARNING
#define CAMITK_WARNING(MSG)
Log for warning verbosity (the most common one) Will appear by default.
Definition: Log.h:266
camitk::Action::description
QString description
the descriptionof the action
Definition: Action.h:492
camitk::setGradientBackground
void setGradientBackground(bool)
set the gradient background
camitk::renderWindow
vtkSmartPointer< vtkRenderWindow > renderWindow
Definition: RendererWidget.cpp:280
camitk::annotatedCube
annotatedCube
annotated cube actor
Definition: RendererWidget.cpp:362
camitk::setAreaPicking
void setAreaPicking(bool areaPicking)
camitk::tempLogofile
QTemporaryFile * tempLogofile
Definition: RendererWidget.cpp:450
camitk::pickInteractorStyle
pickInteractorStyle
picking interactor
Definition: RendererWidget.cpp:299
camitk::getControlMode
ControlMode getControlMode() const
get the current control mode
CamiTKAPI.h
if
if(${CMAKE_VERSION} VERSION_GREATER "3.3" OR ${CMAKE_VERSION} VERSION_EQUAL "3.3") option(CAMITK_INCLUDE_WHAT_YOU_USE "Enable the header analysis on you code
camitk::rendering3DRedBlue
rendering3DRedBlue
is rendering in 3D stereo red/blue
Definition: RendererWidget.cpp:275
camitk::startPicking
void startPicking()
camitk::vtklup
vtkSmartPointer< vtkWindowLevelLookupTable > vtklup
Definition: RendererWidget.cpp:487
camitk::RIGHT_UP
@ RIGHT_UP
World axes are seen so that x points to the right, y points upward.
Definition: RendererWidget.h:133
a
#define a
camitk::setActiveCamera
void setActiveCamera(vtkCamera *cam)
set active camera
camitk::screenshot
void screenshot(QString filename)
save the screenshot in a file
camitk::getLightFollowCamera
bool getLightFollowCamera() const
Get the current state of the property.
camitk::pickActor
void pickActor(int, int)
Perform picking from screen coordinates.
CAMITK_INFO
#define CAMITK_INFO(MSG)
Log for info verbosity (the second most verbose one) The msg will appear only if the user asked for I...
Definition: Log.h:261
camitk::mousePressEvent
void mousePressEvent(QMouseEvent *event) override
mouse press handler overriden to manage different version of VTK
camitk::MouseButtonState
MouseButtonState
Definition: RendererWidget.h:149
camitk::getBackfaceCulling
bool getBackfaceCulling() const
Get the current state of backface culling.
camitk::RendererWidget
RendererWidget(QWidget *parent=nullptr, ControlMode mode=RendererWidget::TRACKBALL)
constructors.
camitk::pickingDiverter
pickingDiverter
is the picking diverter used
Definition: RendererWidget.cpp:315
camitk::getPointSize
double getPointSize() const
get the current value of point size
camitk::renderer
renderer
The current renderer.
Definition: RendererWidget.cpp:283
camitk::toggleOrientationDecorations
void toggleOrientationDecorations(bool)
display orientation decorations
camitk::LEFT_UP
@ LEFT_UP
World axes are seen so that x points to the left, y points upward.
Definition: RendererWidget.h:132
CAMITK_TRACE_ALT
#define CAMITK_TRACE_ALT(MSG)
Definition: Log.h:257
camitk::pointSize
pointSize
default point size
Definition: RendererWidget.cpp:277
camitk::backfaceCulling
backfaceCulling
Is back face culling on?
Definition: RendererWidget.cpp:273
camitk::getActiveCamera
vtkCamera * getActiveCamera()
get the active camera
camitk::displayLogo
displayLogo
is the logo displayed
Definition: RendererWidget.cpp:274
camitk::rightButtonPressed
void rightButtonPressed()
send when the mouse right button is clicked
camitk::setControlMode
setControlMode(mode)
camitk::getBackgroundColor
void getBackgroundColor(double &, double &, double &)
get the background color (rgb)
camitk::resetCameraSettings
void resetCameraSettings()
camitk::LEFT_BUTTON
@ LEFT_BUTTON
the mouse left button is currently pressed
Definition: RendererWidget.h:151
camitk::actorPicked
void actorPicked(vtkSmartPointer< vtkPicker >)
camitk::setColorScale
void setColorScale(bool)
display the color scale in the viewport, use setColorScaleMinMax to change the displayed values
camitk::lightFollowCamera
bool lightFollowCamera
Is the light following the camera.
Definition: RendererWidget.h:406
Log.h
camitk::setSizePolicy
setSizePolicy(policy)
camitk::resetCamera
void resetCamera()
reset the camera to the default position, default FOV.
camitk::logoRepresentation
vtkSmartPointer< vtkLogoRepresentation > logoRepresentation
Definition: RendererWidget.cpp:456
camitk::controlMode
controlMode
current control mode
Definition: RendererWidget.cpp:305
camitk::updateAxes
void updateAxes()
update the axes sizes
RendererWidget.h
camitk::computeVisiblePropBounds
void computeVisiblePropBounds(double *bounds)
get the bounding box of all visible actors [xmin,xmax, ymin,ymax, zmin,zmax]
camitk::toggleAxes
void toggleAxes(bool)
display the axes
camitk::orientationDecorationsTextMapper
vtkSmartPointer< vtkTextMapper > orientationDecorationsTextMapper[4]
annotated cube text
Definition: RendererWidget.h:464
camitk::orientationDecorationActors
vtkSmartPointer< vtkActor2D > orientationDecorationActors[4]
annotated cube text actors
Definition: RendererWidget.h:461
camitk::interactor
interactor
Definition: RendererWidget.cpp:296
camitk::mouseMoveEvent
void mouseMoveEvent(QMouseEvent *event) override
mouse move handler overriden to manage different version of VTK
camitk::BACK_DOWN
@ BACK_DOWN
< World axes are seen so that x points to the left, y points backward. For Medical Images Coronal Vie...
Definition: RendererWidget.h:135
camitk::setMinimumSize
setMinimumSize(150, 150)
camitk::axeYTextProp
vtkSmartPointer< vtkTextProperty > axeYTextProp
Definition: RendererWidget.cpp:340
camitk::logoWidget
logoWidget
logo widget
Definition: RendererWidget.cpp:476
camitk::Action::extension
ActionExtension * extension
the extension in which this action is declared and registered
Definition: Action.h:507
camitk::acProp
vtkSmartPointer< vtkProperty > acProp
Definition: RendererWidget.cpp:377
camitk::endPicking
void endPicking()
end picking
camitk::colorBarWidget
colorBarWidget
the scalar bar widget
Definition: RendererWidget.cpp:494
camitk::getCameraOrientation
RendererWidget::CameraOrientation getCameraOrientation() const
Return the current axes mode.
camitk::policy
QSizePolicy policy(QSizePolicy::Expanding, QSizePolicy::Expanding)
camitk::setCameraOrientation
setCameraOrientation(cameraOrientation)
camitk::axeZTextProp
vtkSmartPointer< vtkTextProperty > axeZTextProp
Definition: RendererWidget.cpp:347
camitk::setBackgroundColor
setBackgroundColor(0.0, 0.0, 0.0)
camitk::addProp
addProp(axes)
camitk::pickingButtonDiverter
pickingButtonDiverter
the callback to remove left button interaction while in picking mode
Definition: RendererWidget.cpp:312
camitk::LEFT_BACK
@ LEFT_BACK
Definition: RendererWidget.h:134
camitk::getCameraSettings
void getCameraSettings(double *position, double *focalPoint, double *viewUp)
get camera settings information (position, what is looked at and how) in world coordinates
camitk::getColorScale
bool getColorScale() const
get the color display state
camitk::actorTransform
void actorTransform(vtkSmartPointer< vtkActor >, double *, int, double **, double *, double *)
perform the transformation of the actor
camitk::transform
vtkSmartPointer< vtkTransform > transform
Definition: RendererWidget.cpp:372
camitk::cameraOrientation
cameraOrientation
state of the initial camera orientation
Definition: RendererWidget.cpp:306
camitk::keyPressEvent
void keyPressEvent(QKeyEvent *e) override
key events (do nothing but pass on e to the parent widget), please do not add any shortcut management...
ScreenshotFormatInfo.h
camitk::getGradientBackground
bool getGradientBackground()
get the current state of the gradient background
camitk::RIGHT_BUTTON
@ RIGHT_BUTTON
the mouse right button is currently pressed
Definition: RendererWidget.h:153
vtkInteractorStylePick.h
camitk::orientationDecorationLetters
QString orientationDecorationLetters[4]
Definition: RendererWidget.cpp:407
camitk::addProp
addProp(annotatedCube)
camitk::setColorScaleMinMax
void setColorScaleMinMax(double m, double M)
set the min and max values.
camitk::setOrientationDecorationsLetters
void setOrientationDecorationsLetters(QString letters[4])
give the lettres for orientation decoration: Left, Right, Top, Down
camitk::displayColorScale
displayColorScale
is the color scale currently displayed
Definition: RendererWidget.cpp:276
camitk::toogle3DRedBlue
void toogle3DRedBlue()
toggle stereo 3D red/blue rendering (you will need red/blue glasses)
camitk::setColorScaleTitle
void setColorScaleTitle(QString t)
set the color scale title.
camitk::axeXTextProp
vtkSmartPointer< vtkTextProperty > axeXTextProp
Definition: RendererWidget.cpp:326
camitk::RIGHT_DOWN
@ RIGHT_DOWN
World axes are seen so that x points to the right, y points downward.
Definition: RendererWidget.h:131
camitk::setObjectName
setObjectName("RendererWidget")
camitk::removeProp
void removeProp(vtkSmartPointer< vtkProp > p, bool refresh=false)
remove the given vtkProp (e.g.
camitk::MIDDLE_BUTTON
@ MIDDLE_BUTTON
the mouse middle button is currently pressed (or 3rd button emulation)
Definition: RendererWidget.h:152
camitk::CameraOrientation
CameraOrientation
RendererWidget implements all support methods to use camiTK with Qt interface.
Definition: RendererWidget.h:130
camitk::containsProp
bool containsProp(vtkSmartPointer< vtkProp >)
is the given vtkProp (e.g. vtkActor or vtkActor2D) in this renderer
camitk::mouseReleaseEvent
void mouseReleaseEvent(QMouseEvent *event) override
mouse release handler overriden to manage different version of VTK
camitk::pick
void pick()
Perform picking using the current mouse position.
camitk::~RendererWidget
~RendererWidget() override
destructor
camitk::axes
axes
axes actor
Definition: RendererWidget.cpp:320
CAMITK_WARNING_IF
#define CAMITK_WARNING_IF(COND, MSG)
Definition: Log.h:313
camitk::controlInteractorStyle
controlInteractorStyle
for the interaction with the scene
Definition: RendererWidget.cpp:307
camitk::resetClippingPlanes
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...
camitk::NO_BUTTON
@ NO_BUTTON
no buttons are currently pressed
Definition: RendererWidget.h:150
camitk::rep
vtkScalarBarRepresentation * rep
Definition: RendererWidget.cpp:510
camitk::setLightFollowCamera
void setLightFollowCamera(bool)
Set/unset the light to follow the camera.
camitk::refresh
void refresh()
refresh the display
camitk::colorScale
vtkSmartPointer< vtkScalarBarActor > colorScale
the color scale displaying the lookup table + values
Definition: RendererWidget.h:449
camitk::getMouse3DCoordinates
void getMouse3DCoordinates(double &x, double &y, double &z)
get the mouse coordinates in 3D
camitk::logoFile
QFile logoFile(":/camiTKIcon")
GeometricObject.h
camitk::setPicker
void setPicker(vtkSmartPointer< vtkAbstractPropPicker > woodyWood)
set the picker to handle the action
camitk::rotateCamera
void rotateCamera(double angle, int axe)
Rotate the camera around param "axe" of "angle" degrees.
camitk::displayGradient
displayGradient
Definition: RendererWidget.cpp:515
CAMITK_API
#define CAMITK_API
Definition: CamiTKAPI.h:49
camitk
Definition: Action.cpp:35
camitk::toggleLogo
void toggleLogo(bool)
toggle logo
camitk::setPointSize
void setPointSize(double size)
set the default point size