Computer Assited Medical Intervention Tool Kit  version 4.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-2016 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 // -- Core stuff
30 #include "CamiTKAPI.h"
31 
32 // -- VTK stuff
33 #include <QVTKWidget2.h>
34 #include <vtkSmartPointer.h>
35 #include <vtkInteractorStyle.h>
36 // additional needed headers for QVTKWidget2
37 #include <vtkGenericOpenGLRenderWindow.h>
38 #include <vtkRenderWindowInteractor.h>
39 #include <QVTKInteractor.h>
40 
41 // -- VTK stuff classes
42 class vtkRenderer;
43 class vtkInteractorStyle;
44 class vtkPicker;
45 class vtkProp;
46 class vtkActor;
47 class vtkActor2D;
48 class vtkScalarBarActor;
49 class vtkEventQtSlotConnect;
50 class vtkCallbackCommand;
51 class vtkCamera;
52 class vtkAxesActor;
53 class vtkAnnotatedCubeActor;
54 class vtkScalarBarWidget;
55 class vtkUnsignedCharArray;
56 class vtkTextMapper;
57 
58 namespace camitk {
59  // -- Core stuff classes
60  class GeometricObject;
61 
63  class vtkInteractorStylePick : public vtkInteractorStyle {
64 
65  public:
66 
67  static vtkInteractorStylePick * New();
68  vtkTypeMacro(vtkInteractorStylePick, vtkInteractorStyle);
69 
70  void PrintSelf(ostream& os, vtkIndent indent);
71 
72  void SetAreaPicking(bool b);
73 
74  virtual void OnLeftButtonDown();
75 
76  virtual void OnLeftButtonUp();
77 
78  virtual void OnMouseMove();
79 
80  protected:
81 
84 
85  virtual void Pick();
86 
87  void RedrawRubberBand();
88 
89  int StartPosition[2];
90  int EndPosition[2];
91 
92  int Moving;
93 
94  vtkUnsignedCharArray* PixelArray;
95 
97 
98  // private :
99  //
100  // vtkInteractorStylePick ( const vtkInteractorStylePick& ); // Not implemented
101  // void operator= ( const vtkInteractorStylePick& ); // Not implemented
102 
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 
161 // enum InteractionMode {
162 // CONTROL, ///< mouse interaction mode (\see ControlMode)
163 // PICKING, ///< picking mode
164 // AREA_PICKING ///< area picking mode
165 // };
166 
172  RIGHT_BUTTON
173  };
174 
177  PNG = 0,
178  JPG,
179  BMP,
180  PS,
181  EPS,
182  PDF,
183  TEX,
184  SVG,
185  OBJ,
186  RIB,
188  NOT_SUPPORTED
189  };
190 
193  public:
197  QString extension;
199  QString description;
201  ScreenshotFormatInfo(ScreenshotFormat t, QString e, QString d) : type(t), extension(e), description(d) {}
203  ScreenshotFormatInfo() : type(NOT_SUPPORTED), extension(""), description("Not supported") {}
204  };
205 
218  RendererWidget(QWidget* parent = 0, ControlMode mode = RendererWidget::TRACKBALL);
219 
221  ~RendererWidget();
222 
225 
227  //InteractionMode getInteractionMode() const;
228 
230  //void setInteractionMode(InteractionMode mode);
231 
232  void setAreaPicking(bool areaPicking);
233 
235  ControlMode getControlMode() const;
236 
238  void setControlMode(ControlMode mode);
239 
243  void setPicker(vtkSmartPointer<vtkAbstractPropPicker> woodyWood);
244 
246  void pick();
247 
249  void pickActor(int x, int y);
250 
252  void keyPressEvent(QKeyEvent* e);
253 
256  static const ScreenshotFormatInfo * getScreenshotFormatInfo(unsigned int);
257 
260  static const ScreenshotFormatInfo * getScreenshotFormatInfo(ScreenshotFormat);
261 
265  void screenshot(QString filename);
266 
268  void refresh();
270 
274  void setBackfaceCulling(bool);
275 
277  bool getBackfaceCulling() const;
278 
280  void setCameraOrientation( RendererWidget::CameraOrientation );
281 
283  RendererWidget::CameraOrientation getCameraOrientation( ) const;
284 
286  void setLightFollowCamera(bool);
287 
289  bool getLightFollowCamera() const;
290 
292  void setPointSize(double size);
293 
295  double getPointSize() const;
296 
298  void rotateCamera(double angle, int axe);
299 
304  void resetCamera();
305 
307  void resetCamera(double *bounds);
308 
310  void getCameraSettings(double *position, double *focalPoint, double *viewUp);
311 
313  void setActiveCamera( vtkCamera * cam );
314 
316  vtkCamera * getActiveCamera();
317 
319  void getMouse3DCoordinates(double & x, double & y, double & z);
320 
322  void setBackgroundColor(double, double, double);
323 
325  void getBackgroundColor(double&, double&, double&);
326 
328  bool getGradientBackground();
329 
331  void setGradientBackground(bool);
332 
334  void toogle3DRedBlue();
335 
337  void toggleCopyright(bool);
338 
340  void toggleAxes(bool);
341 
343  void updateAxes();
344 
346  void toggleOrientationDecorations(bool);
347 
349  void setOrientationDecorationsLetters(QString letters[4]);
350 
351 
353  void setColorScale(bool);
354 
356  bool getColorScale() const;
357 
362  void setColorScaleMinMax(double m, double M);
363 
367  void setColorScaleTitle(QString t);
368 
370  void computeVisiblePropBounds(double *bounds);
372 
373 
376 
385  void addProp(vtkSmartPointer<vtkProp> p, bool refresh=false);
386 
388  bool containsProp(vtkSmartPointer<vtkProp>);
389 
394  void removeProp(vtkSmartPointer<vtkProp> p, bool refresh=false);
395 
397  void actorTransform(vtkSmartPointer<vtkActor>, double *, int , double **, double *, double *);
399 
400 
401 
402 protected slots:
406  //void leftClick();
407 
409  //void leftRelease();
410 
412  //void rightClick();
413 
415  void startPicking();
416 
418  void endPicking();
419 
421 
422 signals :
423 
427  void actorPicked(vtkSmartPointer<vtkPicker>);
428 
430  void rightButtonPressed();
432 
433 
434 
435 protected:
436 
437  virtual void mousePressEvent(QMouseEvent* event);
438 
440  virtual void mouseReleaseEvent(QMouseEvent* event);
441 
443  virtual void mouseMoveEvent(QMouseEvent* event);
444 
445 protected :
446 
450  vtkSmartPointer<QVTKInteractor> interactor;
451 
453  vtkSmartPointer<vtkInteractorStyle> controlInteractorStyle;
454 
456  //InteractionMode interactionMode;
457 
460 
462 
466  void resetCameraSettings();
467 
469  vtkSmartPointer<vtkRenderer> renderer;
470 
473 
475  CameraOrientation cameraOrientation;
476 
479 
481  double pointSize;
482 
486 
490  //vtkSmartPointer<vtkEventQtSlotConnect> connector;
491 
493  static void divertionCallback(vtkObject * caller, unsigned long eid, void *clientdata, void *calldata) {};
494 
496  vtkSmartPointer<vtkCallbackCommand> pickingButtonDiverter;
497 
500 
502  vtkSmartPointer<vtkInteractorStylePick> pickInteractorStyle;
503 
505 
509  static void buildScreenshotMap();
510 
512  static const ScreenshotFormatInfo * getScreenshotFormatInfo(QString);
514 
519 
522 
524  vtkSmartPointer<vtkActor2D> copyrightTextActor;
525 
528 
530  vtkSmartPointer<vtkScalarBarActor> colorScale;
531 
533  vtkSmartPointer<vtkScalarBarWidget> colorBarWidget;
534 
536  vtkSmartPointer<vtkAxesActor> axes;
537 
539  vtkSmartPointer<vtkAnnotatedCubeActor> annotatedCube;
540 
541  vtkSmartPointer<vtkActor2D> orientationDecorationActors[4];
542  vtkSmartPointer<vtkTextMapper> orientationDecorationsTextMapper[4];
543 
545 
546 };
547 
548 }
549 
550 #endif //RENDERERWIDGET_H
551 
bool pickingDiverter
is the picking diverter used
Definition: RendererWidget.h:499
bool displayGradient
Definition: RendererWidget.h:518
Alias Wavefront .OBJ.
Definition: RendererWidget.h:185
< 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:181
bool backfaceCulling
Is back face culling on?
Definition: RendererWidget.h:472
ControlMode
list of possible user interaction control mode
Definition: RendererWidget.h:153
void PrintSelf(ostream &os, vtkIndent indent)
Definition: RendererWidget.cpp:359
vtkSmartPointer< QVTKInteractor > interactor
Definition: RendererWidget.h:450
vtkUnsignedCharArray * PixelArray
Definition: RendererWidget.h:94
bool displayColorScale
is the color scale currently displayed
Definition: RendererWidget.h:527
ScreenshotFormatInfo(ScreenshotFormat t, QString e, QString d)
Constructor.
Definition: RendererWidget.h:201
LaTeX (only the text is exported)
Definition: RendererWidget.h:183
void SetAreaPicking(bool b)
Definition: RendererWidget.cpp:117
vtkSmartPointer< vtkScalarBarWidget > colorBarWidget
the scalar bar widget
Definition: RendererWidget.h:533
PostScript.
Definition: RendererWidget.h:180
vtkSmartPointer< vtkScalarBarActor > colorScale
the color scale displaying the lookup table + values
Definition: RendererWidget.h:530
JPEG.
Definition: RendererWidget.h:178
virtual void OnLeftButtonDown()
Definition: RendererWidget.cpp:122
RendererWidget implements all support methods to use camiTK with Qt interface.
Definition: RendererWidget.h:126
vtkSmartPointer< vtkRenderer > renderer
The current renderer.
Definition: RendererWidget.h:469
bool displayCopyright
is the copyright text displayed
Definition: RendererWidget.h:521
ScreenshotFormat type
the corresponding type (key)
Definition: RendererWidget.h:195
vtkTypeMacro(vtkInteractorStylePick, vtkInteractorStyle)
Definition: Action.cpp:40
double pointSize
default point size
Definition: RendererWidget.h:481
vtkSmartPointer< vtkActor2D > copyrightTextActor
copyright text vtk actor
Definition: RendererWidget.h:524
ScreenshotFormatInfo()
default constructor
Definition: RendererWidget.h:203
VRML 2.0.
Definition: RendererWidget.h:187
same as TRACKBALL but does not allow rotation using left button (but zoom and displacement parallel t...
Definition: RendererWidget.h:156
virtual void OnMouseMove()
Definition: RendererWidget.cpp:158
#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:208
CameraOrientation cameraOrientation
state of the initial camera orientation
Definition: RendererWidget.h:475
the mouse left button is currently pressed
Definition: RendererWidget.h:170
QString extension
file extension (suffix)
Definition: RendererWidget.h:197
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:171
bool AreaPicking
Definition: RendererWidget.h:96
int Moving
Definition: RendererWidget.h:92
the mouse is used as a trackball (default)
Definition: RendererWidget.h:155
int StartPosition[2]
Definition: RendererWidget.h:89
vtkSmartPointer< vtkCallbackCommand > pickingButtonDiverter
the callback to remove left button interaction while in picking mode
Definition: RendererWidget.h:493
Interactor used when we are in picking mode.
Definition: RendererWidget.h:63
bool lightFollowCamera
Is the light following the camera.
Definition: RendererWidget.h:478
the mouse is used a joystick
Definition: RendererWidget.h:154
Portable Document Format.
Definition: RendererWidget.h:182
vtkSmartPointer< vtkAnnotatedCubeActor > annotatedCube
annotated cube actor
Definition: RendererWidget.h:539
bool rendering3DRedBlue
is rendering in 3D stereo red/blue
Definition: RendererWidget.h:484
World axes are seen so that x points to the right, y points downward.
Definition: RendererWidget.h:144
virtual void OnLeftButtonUp()
Definition: RendererWidget.cpp:192
MouseButtonState
state of the pressed button (for 3 buttons mouse)
Definition: RendererWidget.h:168
ScreenshotFormat
list of supported screenshot export formats
Definition: RendererWidget.h:176
CameraOrientation
describes the initial position and orientation of the default camera.
Definition: RendererWidget.h:143
Scalable Vector Graphics.
Definition: RendererWidget.h:184
vtkInteractorStylePick()
Definition: RendererWidget.cpp:103
vtkSmartPointer< vtkAxesActor > axes
axes actor
Definition: RendererWidget.h:536
QString description
file format description
Definition: RendererWidget.h:199
no buttons are currently pressed
Definition: RendererWidget.h:169
vtkSmartPointer< vtkInteractorStyle > controlInteractorStyle
for the interaction with the scene
Definition: RendererWidget.h:453
int EndPosition[2]
Definition: RendererWidget.h:90
~vtkInteractorStylePick()
Definition: RendererWidget.cpp:112
Definition: RendererWidget.h:147
sub-class containing all information concerning exporting images (screenshot)
Definition: RendererWidget.h:192
vtkSmartPointer< vtkInteractorStylePick > pickInteractorStyle
picking interactor
Definition: RendererWidget.h:502
virtual void Pick()
Definition: RendererWidget.cpp:279
Bitmap.
Definition: RendererWidget.h:179
ControlMode controlMode
current control mode
Definition: RendererWidget.h:459
RenderMan/BMRT .RIB.
Definition: RendererWidget.h:186