Computer Assited Medical Intervention Tool Kit  version 4.1
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-2018 Univ. Grenoble Alpes, CNRS, TIMC-IMAG UMR 5525 (GMCAO)
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 
36 // -- VTK stuff
37 #include <vtkVersion.h>
38 
39 #if VTK_MAJOR_VERSION == 6
40 #include <QVTKWidget2.h>
41 // additional needed headers for QVTKWidget2
42 #include <vtkGenericOpenGLRenderWindow.h>
43 
44 #elif VTK_MAJOR_VERSION == 7
45 #include <QVTKWidget.h>
46 // additional needed headers for QVTKWidget
47 #include <QWindow>
48 #else
49 #error "Invalid VTK version: not (yet) supported."
50 // for VTK8, check for instance https://www.slicer.org/wiki/Documentation/Labs/Qt5-and-VTK8#Qt5:_QVTKOpenGLWidget
51 #endif
52 
53 #include <vtkSmartPointer.h>
54 #include <vtkInteractorStyle.h>
55 #include <vtkRenderWindowInteractor.h>
56 #include <QVTKInteractor.h>
57 
58 #include <utility>
59 
60 // -- VTK stuff classes
61 class vtkRenderer;
62 class vtkInteractorStyle;
63 class vtkPicker;
64 class vtkProp;
65 class vtkActor;
66 class vtkActor2D;
67 class vtkScalarBarActor;
68 class vtkEventQtSlotConnect;
69 class vtkCallbackCommand;
70 class vtkCamera;
71 class vtkAxesActor;
72 class vtkAnnotatedCubeActor;
73 class vtkScalarBarWidget;
74 class vtkUnsignedCharArray;
75 class vtkTextMapper;
76 
77 namespace camitk {
78 // -- Core stuff classes
79 class GeometricObject;
80 
82 class vtkInteractorStylePick : public vtkInteractorStyle {
83 
84 public:
85 
86  static vtkInteractorStylePick* New();
87  vtkTypeMacro(vtkInteractorStylePick, vtkInteractorStyle);
88 
89  void PrintSelf(ostream& os, vtkIndent indent) override;
90 
91  void SetAreaPicking(bool b);
92 
93  void OnLeftButtonDown() override;
94 
95  void OnLeftButtonUp() override;
96 
97  void OnMouseMove() override;
98 
99 protected:
100 
102  ~vtkInteractorStylePick() override = default;
103 
104  virtual void Pick();
105 
106  void RedrawRubberBand();
107 
109  int endPosition[2];
110 
111  int moving;
112 
113  vtkSmartPointer<vtkUnsignedCharArray> pixelArray;
114 
116 };
117 
118 }
119 
120 namespace camitk {
139 #if VTK_MAJOR_VERSION == 6
140 class CAMITK_API RendererWidget : public QVTKWidget2 {
141 
142 #elif VTK_MAJOR_VERSION == 7
143 class CAMITK_API RendererWidget : public QVTKWidget {
144 
145 #else
146 #error "Invalid VTK version: not (yet) supported."
147 #endif
148  Q_OBJECT
149  Q_ENUMS(ControlMode CameraOrientation); // so that it can be used in property editor
150 
151 public :
152 
164  enum CameraOrientation {
170 
171  };
172 
174  enum ControlMode {
179  };
180 
187  };
188 
191  PNG = 0,
192  JPG,
193  BMP,
194  PS,
195  EPS,
196  PDF,
197  TEX,
198  SVG,
199  OBJ,
200  RIB,
203  };
204 
207  public:
211  QString extension;
213  QString description;
215  ScreenshotFormatInfo(ScreenshotFormat t, QString e, QString d) : type(t), extension(std::move(e)), description(std::move(d)) {}
217  ScreenshotFormatInfo() : extension(""), description("Not supported") {}
218  };
219 
232  RendererWidget(QWidget* parent = nullptr, ControlMode mode = RendererWidget::TRACKBALL);
233 
235  ~RendererWidget() override;
236 
239 
241  //InteractionMode getInteractionMode() const;
242 
244  //void setInteractionMode(InteractionMode mode);
245 
246  void setAreaPicking(bool areaPicking);
247 
249  ControlMode getControlMode() const;
250 
252  void setControlMode(ControlMode mode);
253 
257  void setPicker(vtkSmartPointer<vtkAbstractPropPicker> woodyWood);
258 
260  void pick();
261 
263  void pickActor(int x, int y);
264 
266  void keyPressEvent(QKeyEvent* e) override;
267 
270  static const ScreenshotFormatInfo* getScreenshotFormatInfo(unsigned int);
271 
275 
279  void screenshot(QString filename);
280 
282  void refresh();
284 
288  void setBackfaceCulling(bool);
289 
291  bool getBackfaceCulling() const;
292 
295 
298 
300  void setLightFollowCamera(bool);
301 
303  bool getLightFollowCamera() const;
304 
306  void setPointSize(double size);
307 
309  double getPointSize() const;
310 
312  void rotateCamera(double angle, int axe);
313 
318  void resetCamera();
319 
321  void resetCamera(double* bounds);
322 
324  void getCameraSettings(double* position, double* focalPoint, double* viewUp);
325 
327  void setActiveCamera(vtkCamera* cam);
328 
330  vtkCamera* getActiveCamera();
331 
333  void getMouse3DCoordinates(double& x, double& y, double& z);
334 
336  void setBackgroundColor(double, double, double);
337 
339  void getBackgroundColor(double&, double&, double&);
340 
342  bool getGradientBackground();
343 
345  void setGradientBackground(bool);
346 
348  void toogle3DRedBlue();
349 
351  void toggleCopyright(bool);
352 
354  void toggleAxes(bool);
355 
357  void updateAxes();
358 
360  void toggleOrientationDecorations(bool);
361 
363  void setOrientationDecorationsLetters(QString letters[4]);
364 
365 
367  void setColorScale(bool);
368 
370  bool getColorScale() const;
371 
376  void setColorScaleMinMax(double m, double M);
377 
381  void setColorScaleTitle(QString t);
382 
384  void computeVisiblePropBounds(double* bounds);
386 
390  void resetClippingPlanes(double* bounds = nullptr);
391 
394 
403  void addProp(vtkSmartPointer<vtkProp> p, bool refresh = false);
404 
406  bool containsProp(vtkSmartPointer<vtkProp>);
407 
412  void removeProp(vtkSmartPointer<vtkProp> p, bool refresh = false);
413 
415  void actorTransform(vtkSmartPointer<vtkActor>, double*, int, double**, double*, double*);
417 
418 
419 
420 protected slots:
424  //void leftClick();
425 
427  //void leftRelease();
428 
430  //void rightClick();
431 
433  void startPicking();
434 
436  void endPicking();
437 
439 
440 signals :
441 
445  void actorPicked(vtkSmartPointer<vtkPicker>);
446 
448  void rightButtonPressed();
450 
451 
452 
453 protected:
454 
455  void mousePressEvent(QMouseEvent* event) override;
456 
458  void mouseReleaseEvent(QMouseEvent* event) override;
459 
461  void mouseMoveEvent(QMouseEvent* event) override;
462 
463 protected :
464 
468  vtkSmartPointer<QVTKInteractor> interactor;
469 
471  vtkSmartPointer<vtkInteractorStyle> controlInteractorStyle;
472 
474  //InteractionMode interactionMode;
475 
478 
480 
484  void resetCameraSettings();
485 
487  vtkSmartPointer<vtkRenderer> renderer;
488 
490  bool backfaceCulling;
491 
493  CameraOrientation cameraOrientation;
494 
497 
499  double pointSize;
500 
502  bool rendering3DRedBlue;
504 
508  //vtkSmartPointer<vtkEventQtSlotConnect> connector;
509 
511  static void divertionCallback(vtkObject* caller, unsigned long eid, void* clientdata, void* calldata) {};
512 
514  vtkSmartPointer<vtkCallbackCommand> pickingButtonDiverter;
515 
517  bool pickingDiverter;
518 
520  vtkSmartPointer<vtkInteractorStylePick> pickInteractorStyle;
521 
523 
527  static void buildScreenshotMap();
528 
530  static const ScreenshotFormatInfo* getScreenshotFormatInfo(QString);
532 
536  bool displayGradient;
537 
539  bool displayCopyright;
540 
542  vtkSmartPointer<vtkActor2D> copyrightTextActor;
543 
545  bool displayColorScale;
546 
548  vtkSmartPointer<vtkScalarBarActor> colorScale;
549 
551  vtkSmartPointer<vtkScalarBarWidget> colorBarWidget;
552 
554  vtkSmartPointer<vtkAxesActor> axes;
555 
557  vtkSmartPointer<vtkAnnotatedCubeActor> annotatedCube;
558 
559  vtkSmartPointer<vtkActor2D> orientationDecorationActors[4];
560  vtkSmartPointer<vtkTextMapper> orientationDecorationsTextMapper[4];
561 
563 
564 };
565 
566 }
567 
568 #endif //RENDERERWIDGET_H
569 
void pickActor(int x, int y)
Perform picking from screen coordinates.
vtkSmartPointer< vtkUnsignedCharArray > pixelArray
Definition: RendererWidget.h:113
void removeProp(vtkSmartPointer< vtkProp > p, bool refresh=false)
remove the given vtkProp (e.g.
ControlMode
list of possible user interaction control mode
Definition: RendererWidget.h:174
renderer
The current renderer.
Definition: RendererWidget.cpp:486
pickInteractorStyle
picking interactor
Definition: RendererWidget.cpp:493
ScreenshotFormat
list of supported screenshot export formats
Definition: RendererWidget.h:190
sub-class containing all information concerning exporting images (screenshot)
Definition: RendererWidget.h:206
axes
axes actor
Definition: RendererWidget.cpp:520
setBackgroundColor(0.0, 0.0, 0.0)
backfaceCulling
Is back face culling on?
Definition: RendererWidget.cpp:476
RenderMan/BMRT .RIB.
Definition: RendererWidget.h:200
cameraOrientation
state of the initial camera orientation
Definition: RendererWidget.cpp:500
Alias Wavefront .OBJ.
Definition: RendererWidget.h:199
World axes are seen so that x points to the right, y points downward.
Definition: RendererWidget.h:165
bool getGradientBackground()
get the current state of the gradient background
static const ScreenshotFormatInfo * getScreenshotFormatInfo(unsigned int)
return the information concerning the supporting format using an index corresponding to the enum (che...
RendererWidget(QWidget *parent=nullptr, ControlMode mode=RendererWidget::TRACKBALL)
constructors.
bool containsProp(vtkSmartPointer< vtkProp >)
is the given vtkProp (e.g. vtkActor or vtkActor2D) in this renderer
Portable Document Format.
Definition: RendererWidget.h:196
void screenshot(QString filename)
save the screenshot in a file
void toogle3DRedBlue()
toggle stereo 3D red/blue rendering (you will need red/blue glasses)
Scalable Vector Graphics.
Definition: RendererWidget.h:198
void SetAreaPicking(bool b)
Definition: RendererWidget.cpp:112
the mouse is used a joystick
Definition: RendererWidget.h:175
void OnLeftButtonDown() override
Definition: RendererWidget.cpp:117
the mouse middle button is currently pressed (or 3rd button emulation)
Definition: RendererWidget.h:185
void getBackgroundColor(double &, double &, double &)
get the background color (rgb)
the mouse left button is currently pressed
Definition: RendererWidget.h:184
controlMode
current control mode
Definition: RendererWidget.cpp:499
void refresh()
refresh the display
QString extension
file extension (suffix)
Definition: RendererWidget.h:211
STL namespace.
void toggleOrientationDecorations(bool)
display orientation decorations
void mouseReleaseEvent(QMouseEvent *event) override
overloaded mouse release handler because a potentialbug in vtk 5.2.1
void pick()
Perform picking using the current mouse position.
QString description
file format description
Definition: RendererWidget.h:213
void mouseMoveEvent(QMouseEvent *event) override
overloaded mouse move handler because a potentialbug in vtk 5.2.1
void setBackfaceCulling(bool)
displayColorScale
is the color scale currently displayed
Definition: RendererWidget.cpp:479
World axes are seen so that x points to the right, y points upward.
Definition: RendererWidget.h:167
MouseButtonState
state of the pressed button (for 3 buttons mouse)
Definition: RendererWidget.h:182
vtkTypeMacro(vtkInteractorStylePick, vtkInteractorStyle)
Definition: Action.cpp:36
vtkSmartPointer< vtkTextMapper > orientationDecorationsTextMapper[4]
Definition: RendererWidget.h:560
colorBarWidget
the scalar bar widget
Definition: RendererWidget.cpp:680
int endPosition[2]
Definition: RendererWidget.h:109
void actorPicked(vtkSmartPointer< vtkPicker >)
void getMouse3DCoordinates(double &x, double &y, double &z)
get the mouse coordinates in 3D
Definition: RendererWidget.h:168
void resetCamera()
reset the camera to the default position, default FOV.
static void buildScreenshotMap()
void updateAxes()
update the axes sizes
void actorTransform(vtkSmartPointer< vtkActor >, double *, int, double **, double *, double *)
perform the transformation of the actor
ScreenshotFormatInfo(ScreenshotFormat t, QString e, QString d)
Constructor.
Definition: RendererWidget.h:215
bool getBackfaceCulling() const
Get the current state of backface culling.
Q_ENUMS(ControlMode CameraOrientation)
RendererWidget implements all support methods to use camiTK with Qt interface.
void getCameraSettings(double *position, double *focalPoint, double *viewUp)
get camera settings information (position, what is looked at and how) in world coordinates ...
#define CAMITK_API
Definition: CamiTKAPI.h:49
static vtkInteractorStylePick * New()
Definition: RendererWidget.h:178
same as TRACKBALL but does not allow rotation using left button (but zoom and displacement parallel t...
Definition: RendererWidget.h:177
void RedrawRubberBand()
Definition: RendererWidget.cpp:205
void setAreaPicking(bool areaPicking)
Set the interaction mode like picking or control.
interactor
Definition: RendererWidget.cpp:490
the mouse is used as a trackball (default)
Definition: RendererWidget.h:176
void PrintSelf(ostream &os, vtkIndent indent) override
Definition: RendererWidget.cpp:358
void setLightFollowCamera(bool)
Set/unset the light to follow the camera.
void toggleCopyright(bool)
toggle copyright text
< World axes are seen so that x points to the left, y points backward. For Medical Images Coronal Vie...
Definition: RendererWidget.h:169
ScreenshotFormatInfo()
default constructor
Definition: RendererWidget.h:217
void resetCameraSettings()
bool lightFollowCamera
Is the light following the camera.
Definition: RendererWidget.h:496
vtkSmartPointer< vtkActor2D > orientationDecorationActors[4]
Definition: RendererWidget.h:559
rendering3DRedBlue
is rendering in 3D stereo red/blue
Definition: RendererWidget.cpp:478
double getPointSize() const
get the current value of point size
displayGradient
Definition: RendererWidget.cpp:701
Bitmap.
Definition: RendererWidget.h:193
void keyPressEvent(QKeyEvent *e) override
key events (do nothing but pass on e to the parent widget), please do not add any shortcut management...
CameraOrientation
describes the initial position and orientation of the default camera.
Definition: RendererWidget.h:164
int moving
Definition: RendererWidget.h:111
addProp(axes)
void OnMouseMove() override
Definition: RendererWidget.cpp:154
bool getColorScale() const
get the color display state
LaTeX (only the text is exported)
Definition: RendererWidget.h:197
void rightButtonPressed()
send when the mouse right button is clicked
ControlMode getControlMode() const
get the current control mode
Interactor used when we are in picking mode.
Definition: RendererWidget.h:82
void setOrientationDecorationsLetters(QString letters[4])
give the lettres for orientation decoration: Left, Right, Top, Down
no buttons are currently pressed
Definition: RendererWidget.h:183
void computeVisiblePropBounds(double *bounds)
get the bounding box of all visible actors [xmin,xmax, ymin,ymax, zmin,zmax]
the mouse right button is currently pressed
Definition: RendererWidget.h:186
~vtkInteractorStylePick() override=default
bool getLightFollowCamera() const
Get the current state of the property.
Definition: RendererWidget.h:202
void OnLeftButtonUp() override
Definition: RendererWidget.cpp:189
void setColorScaleTitle(QString t)
set the color scale title.
void setPicker(vtkSmartPointer< vtkAbstractPropPicker > woodyWood)
set the picker to handle the action
Portable Network Graphics.
Definition: RendererWidget.h:191
void setColorScale(bool)
display the color scale in the viewport, use setColorScaleMinMax to change the displayed values ...
PostScript.
Definition: RendererWidget.h:194
VRML 2.0.
Definition: RendererWidget.h:201
void rotateCamera(double angle, int axe)
Rotate the camera around param "axe" of "angle" degrees.
World axes are seen so that x points to the left, y points upward.
Definition: RendererWidget.h:166
copyrightTextActor
copyright text vtk actor
Definition: RendererWidget.cpp:658
vtkSmartPointer< vtkScalarBarActor > colorScale
the color scale displaying the lookup table + values
Definition: RendererWidget.h:548
pickingDiverter
is the picking diverter used
Definition: RendererWidget.cpp:515
Encapsulated PostScript.
Definition: RendererWidget.h:195
bool areaPicking
Definition: RendererWidget.h:115
vtkInteractorStylePick()
Definition: RendererWidget.cpp:103
void setPointSize(double size)
set the default point size
void endPicking()
end picking
pointSize
default point size
Definition: RendererWidget.cpp:480
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...
displayCopyright
is the copyright text displayed
Definition: RendererWidget.cpp:477
setCameraOrientation(cameraOrientation)
annotatedCube
annotated cube actor
Definition: RendererWidget.cpp:562
void setColorScaleMinMax(double m, double M)
set the min and max values.
pickingButtonDiverter
the callback to remove left button interaction while in picking mode
Definition: RendererWidget.cpp:512
int startPosition[2]
Definition: RendererWidget.h:108
void setActiveCamera(vtkCamera *cam)
set active camera
RendererWidget::CameraOrientation getCameraOrientation() const
Return the current axes mode.
static void divertionCallback(vtkObject *caller, unsigned long eid, void *clientdata, void *calldata)
a diverter observer callback (to be used to divert undesired events)
Definition: RendererWidget.h:511
void startPicking()
manage left mouse release interactions
controlInteractorStyle
for the interaction with the scene
Definition: RendererWidget.cpp:501
vtkCamera * getActiveCamera()
get the active camera
void setGradientBackground(bool)
set the gradient background
virtual void Pick()
Definition: RendererWidget.cpp:276
~RendererWidget() override
destructor
setControlMode(mode)
void mousePressEvent(QMouseEvent *event) override
JPEG.
Definition: RendererWidget.h:192
void toggleAxes(bool)
display the axes