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 <QVTKWidget2.h>
38 #include <vtkSmartPointer.h>
39 #include <vtkInteractorStyle.h>
40 // additional needed headers for QVTKWidget2
41 #include <vtkGenericOpenGLRenderWindow.h>
42 #include <vtkRenderWindowInteractor.h>
43 #include <QVTKInteractor.h>
44 
45 #include <utility>
46 
47 // -- VTK stuff classes
48 class vtkRenderer;
49 class vtkInteractorStyle;
50 class vtkPicker;
51 class vtkProp;
52 class vtkActor;
53 class vtkActor2D;
54 class vtkScalarBarActor;
55 class vtkEventQtSlotConnect;
56 class vtkCallbackCommand;
57 class vtkCamera;
58 class vtkAxesActor;
59 class vtkAnnotatedCubeActor;
60 class vtkScalarBarWidget;
61 class vtkUnsignedCharArray;
62 class vtkTextMapper;
63 
64 namespace camitk {
65 // -- Core stuff classes
66 class GeometricObject;
67 
69 class vtkInteractorStylePick : public vtkInteractorStyle {
70 
71 public:
72 
73  static vtkInteractorStylePick* New();
74  vtkTypeMacro(vtkInteractorStylePick, vtkInteractorStyle);
75 
76  void PrintSelf(ostream& os, vtkIndent indent) override;
77 
78  void SetAreaPicking(bool b);
79 
80  void OnLeftButtonDown() override;
81 
82  void OnLeftButtonUp() override;
83 
84  void OnMouseMove() override;
85 
86 protected:
87 
89  ~vtkInteractorStylePick() override = default;
90 
91  virtual void Pick();
92 
93  void RedrawRubberBand();
94 
95  int startPosition[2];
96  int endPosition[2];
97 
98  int moving;
99 
100  vtkSmartPointer<vtkUnsignedCharArray> pixelArray;
101 
103 };
104 
105 }
106 
107 namespace camitk {
126 class CAMITK_API RendererWidget : public QVTKWidget2 {
127  Q_OBJECT
128  Q_ENUMS(ControlMode CameraOrientation); // so that it can be used in property editor
129 
130 public :
131 
143  enum CameraOrientation {
149 
150  };
151 
153  enum ControlMode {
157  NONE
158  };
159 
165  RIGHT_BUTTON
166  };
167 
170  PNG = 0,
171  JPG,
172  BMP,
173  PS,
174  EPS,
175  PDF,
176  TEX,
177  SVG,
178  OBJ,
179  RIB,
181  NOT_SUPPORTED
182  };
183 
186  public:
188  ScreenshotFormat type{NOT_SUPPORTED};
190  QString extension;
192  QString description;
194  ScreenshotFormatInfo(ScreenshotFormat t, QString e, QString d) : type(t), extension(std::move(e)), description(std::move(d)) {}
196  ScreenshotFormatInfo() : extension(""), description("Not supported") {}
197  };
198 
211  RendererWidget(QWidget* parent = nullptr, ControlMode mode = RendererWidget::TRACKBALL);
212 
214  ~RendererWidget() override;
215 
218 
220  //InteractionMode getInteractionMode() const;
221 
223  //void setInteractionMode(InteractionMode mode);
224 
225  void setAreaPicking(bool areaPicking);
226 
228  ControlMode getControlMode() const;
229 
231  void setControlMode(ControlMode mode);
232 
236  void setPicker(vtkSmartPointer<vtkAbstractPropPicker> woodyWood);
237 
239  void pick();
240 
242  void pickActor(int x, int y);
243 
245  void keyPressEvent(QKeyEvent* e) override;
246 
249  static const ScreenshotFormatInfo* getScreenshotFormatInfo(unsigned int);
250 
253  static const ScreenshotFormatInfo* getScreenshotFormatInfo(ScreenshotFormat);
254 
258  void screenshot(QString filename);
259 
261  void refresh();
263 
267  void setBackfaceCulling(bool);
268 
270  bool getBackfaceCulling() const;
271 
273  void setCameraOrientation(RendererWidget::CameraOrientation);
274 
276  RendererWidget::CameraOrientation getCameraOrientation() const;
277 
279  void setLightFollowCamera(bool);
280 
282  bool getLightFollowCamera() const;
283 
285  void setPointSize(double size);
286 
288  double getPointSize() const;
289 
291  void rotateCamera(double angle, int axe);
292 
297  void resetCamera();
298 
300  void resetCamera(double* bounds);
301 
303  void getCameraSettings(double* position, double* focalPoint, double* viewUp);
304 
306  void setActiveCamera(vtkCamera* cam);
307 
309  vtkCamera* getActiveCamera();
310 
312  void getMouse3DCoordinates(double& x, double& y, double& z);
313 
315  void setBackgroundColor(double, double, double);
316 
318  void getBackgroundColor(double&, double&, double&);
319 
321  bool getGradientBackground();
322 
324  void setGradientBackground(bool);
325 
327  void toogle3DRedBlue();
328 
330  void toggleCopyright(bool);
331 
333  void toggleAxes(bool);
334 
336  void updateAxes();
337 
339  void toggleOrientationDecorations(bool);
340 
342  void setOrientationDecorationsLetters(QString letters[4]);
343 
344 
346  void setColorScale(bool);
347 
349  bool getColorScale() const;
350 
355  void setColorScaleMinMax(double m, double M);
356 
360  void setColorScaleTitle(QString t);
361 
363  void computeVisiblePropBounds(double* bounds);
365 
369  void resetClippingPlanes(double* bounds = nullptr);
370 
373 
382  void addProp(vtkSmartPointer<vtkProp> p, bool refresh = false);
383 
385  bool containsProp(vtkSmartPointer<vtkProp>);
386 
391  void removeProp(vtkSmartPointer<vtkProp> p, bool refresh = false);
392 
394  void actorTransform(vtkSmartPointer<vtkActor>, double*, int, double**, double*, double*);
396 
397 
398 
399 protected slots:
403  //void leftClick();
404 
406  //void leftRelease();
407 
409  //void rightClick();
410 
412  void startPicking();
413 
415  void endPicking();
416 
418 
419 signals :
420 
424  void actorPicked(vtkSmartPointer<vtkPicker>);
425 
427  void rightButtonPressed();
429 
430 
431 
432 protected:
433 
434  void mousePressEvent(QMouseEvent* event) override;
435 
437  void mouseReleaseEvent(QMouseEvent* event) override;
438 
440  void mouseMoveEvent(QMouseEvent* event) override;
441 
442 protected :
443 
447  vtkSmartPointer<QVTKInteractor> interactor;
448 
450  vtkSmartPointer<vtkInteractorStyle> controlInteractorStyle;
451 
453  //InteractionMode interactionMode;
454 
457 
459 
463  void resetCameraSettings();
464 
466  vtkSmartPointer<vtkRenderer> renderer;
467 
470 
472  CameraOrientation cameraOrientation;
473 
476 
478  double pointSize;
479 
483 
487  //vtkSmartPointer<vtkEventQtSlotConnect> connector;
488 
490  static void divertionCallback(vtkObject* caller, unsigned long eid, void* clientdata, void* calldata) {};
491 
493  vtkSmartPointer<vtkCallbackCommand> pickingButtonDiverter;
494 
497 
499  vtkSmartPointer<vtkInteractorStylePick> pickInteractorStyle;
500 
502 
506  static void buildScreenshotMap();
507 
509  static const ScreenshotFormatInfo* getScreenshotFormatInfo(QString);
511 
516 
519 
521  vtkSmartPointer<vtkActor2D> copyrightTextActor;
522 
525 
527  vtkSmartPointer<vtkScalarBarActor> colorScale;
528 
530  vtkSmartPointer<vtkScalarBarWidget> colorBarWidget;
531 
533  vtkSmartPointer<vtkAxesActor> axes;
534 
536  vtkSmartPointer<vtkAnnotatedCubeActor> annotatedCube;
537 
538  vtkSmartPointer<vtkActor2D> orientationDecorationActors[4];
539  vtkSmartPointer<vtkTextMapper> orientationDecorationsTextMapper[4];
540 
542 
543 };
544 
545 }
546 
547 #endif //RENDERERWIDGET_H
548 
vtkSmartPointer< vtkUnsignedCharArray > pixelArray
Definition: RendererWidget.h:100
bool pickingDiverter
is the picking diverter used
Definition: RendererWidget.h:496
bool displayGradient
Definition: RendererWidget.h:515
Alias Wavefront .OBJ.
Definition: RendererWidget.h:178
< World axes are seen so that x points to the left, y points backward. For Medical Images Coronal Vie...
Definition: RendererWidget.h:148
Encapsulated PostScript.
Definition: RendererWidget.h:174
bool backfaceCulling
Is back face culling on?
Definition: RendererWidget.h:469
ControlMode
list of possible user interaction control mode
Definition: RendererWidget.h:153
vtkSmartPointer< QVTKInteractor > interactor
Definition: RendererWidget.h:447
bool displayColorScale
is the color scale currently displayed
Definition: RendererWidget.h:524
ScreenshotFormatInfo(ScreenshotFormat t, QString e, QString d)
Constructor.
Definition: RendererWidget.h:194
LaTeX (only the text is exported)
Definition: RendererWidget.h:176
void SetAreaPicking(bool b)
Definition: RendererWidget.cpp:112
vtkSmartPointer< vtkScalarBarWidget > colorBarWidget
the scalar bar widget
Definition: RendererWidget.h:530
void OnLeftButtonDown() override
Definition: RendererWidget.cpp:117
PostScript.
Definition: RendererWidget.h:173
vtkSmartPointer< vtkScalarBarActor > colorScale
the color scale displaying the lookup table + values
Definition: RendererWidget.h:527
JPEG.
Definition: RendererWidget.h:171
STL namespace.
RendererWidget implements all support methods to use camiTK with Qt interface.
Definition: RendererWidget.h:126
vtkSmartPointer< vtkRenderer > renderer
The current renderer.
Definition: RendererWidget.h:466
bool displayCopyright
is the copyright text displayed
Definition: RendererWidget.h:518
vtkTypeMacro(vtkInteractorStylePick, vtkInteractorStyle)
Definition: Action.cpp:36
int endPosition[2]
Definition: RendererWidget.h:96
double pointSize
default point size
Definition: RendererWidget.h:478
vtkSmartPointer< vtkActor2D > copyrightTextActor
copyright text vtk actor
Definition: RendererWidget.h:521
ScreenshotFormatInfo()
default constructor
Definition: RendererWidget.h:196
VRML 2.0.
Definition: RendererWidget.h:180
same as TRACKBALL but does not allow rotation using left button (but zoom and displacement parallel t...
Definition: RendererWidget.h:156
#define CAMITK_API
Definition: CamiTKAPI.h:49
World axes are seen so that x points to the right, y points upward.
Definition: RendererWidget.h:146
static vtkInteractorStylePick * New()
void RedrawRubberBand()
Definition: RendererWidget.cpp:205
void PrintSelf(ostream &os, vtkIndent indent) override
Definition: RendererWidget.cpp:358
CameraOrientation cameraOrientation
state of the initial camera orientation
Definition: RendererWidget.h:472
the mouse left button is currently pressed
Definition: RendererWidget.h:163
QString extension
file extension (suffix)
Definition: RendererWidget.h:190
World axes are seen so that x points to the left, y points upward.
Definition: RendererWidget.h:145
the mouse middle button is currently pressed (or 3rd button emulation)
Definition: RendererWidget.h:164
int moving
Definition: RendererWidget.h:98
the mouse is used as a trackball (default)
Definition: RendererWidget.h:155
void OnMouseMove() override
Definition: RendererWidget.cpp:154
vtkSmartPointer< vtkCallbackCommand > pickingButtonDiverter
the callback to remove left button interaction while in picking mode
Definition: RendererWidget.h:490
Interactor used when we are in picking mode.
Definition: RendererWidget.h:69
bool lightFollowCamera
Is the light following the camera.
Definition: RendererWidget.h:475
the mouse is used a joystick
Definition: RendererWidget.h:154
Portable Document Format.
Definition: RendererWidget.h:175
~vtkInteractorStylePick() override=default
void OnLeftButtonUp() override
Definition: RendererWidget.cpp:189
vtkSmartPointer< vtkAnnotatedCubeActor > annotatedCube
annotated cube actor
Definition: RendererWidget.h:536
bool rendering3DRedBlue
is rendering in 3D stereo red/blue
Definition: RendererWidget.h:481
World axes are seen so that x points to the right, y points downward.
Definition: RendererWidget.h:144
MouseButtonState
state of the pressed button (for 3 buttons mouse)
Definition: RendererWidget.h:161
ScreenshotFormat
list of supported screenshot export formats
Definition: RendererWidget.h:169
CameraOrientation
describes the initial position and orientation of the default camera.
Definition: RendererWidget.h:143
Scalable Vector Graphics.
Definition: RendererWidget.h:177
bool areaPicking
Definition: RendererWidget.h:102
vtkInteractorStylePick()
Definition: RendererWidget.cpp:103
vtkSmartPointer< vtkAxesActor > axes
axes actor
Definition: RendererWidget.h:533
QString description
file format description
Definition: RendererWidget.h:192
no buttons are currently pressed
Definition: RendererWidget.h:162
vtkSmartPointer< vtkInteractorStyle > controlInteractorStyle
for the interaction with the scene
Definition: RendererWidget.h:450
int startPosition[2]
Definition: RendererWidget.h:95
Definition: RendererWidget.h:147
sub-class containing all information concerning exporting images (screenshot)
Definition: RendererWidget.h:185
vtkSmartPointer< vtkInteractorStylePick > pickInteractorStyle
picking interactor
Definition: RendererWidget.h:499
virtual void Pick()
Definition: RendererWidget.cpp:276
Bitmap.
Definition: RendererWidget.h:172
ControlMode controlMode
current control mode
Definition: RendererWidget.h:456
RenderMan/BMRT .RIB.
Definition: RendererWidget.h:179