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 <QVTKWidget.h>
34 #include <vtkSmartPointer.h>
35 #include <vtkInteractorStyle.h>
36 
37 // -- VTK stuff classes
38 class vtkRenderer;
39 class vtkInteractorStyle;
40 class vtkPicker;
41 class vtkProp;
42 class vtkActor;
43 class vtkActor2D;
44 class vtkScalarBarActor;
45 class vtkEventQtSlotConnect;
46 class vtkCallbackCommand;
47 class vtkCamera;
48 class vtkAxesActor;
49 class vtkAnnotatedCubeActor;
50 class vtkScalarBarWidget;
51 class vtkUnsignedCharArray;
52 class vtkTextMapper;
53 
54 namespace camitk {
55  // -- Core stuff classes
56  class GeometricObject;
57 
59  class vtkInteractorStylePick : public vtkInteractorStyle {
60 
61  public:
62 
63  static vtkInteractorStylePick * New();
64  vtkTypeMacro(vtkInteractorStylePick, vtkInteractorStyle);
65 
66  void PrintSelf(ostream& os, vtkIndent indent);
67 
68  void SetAreaPicking(bool b);
69 
70  virtual void OnLeftButtonDown();
71 
72  virtual void OnLeftButtonUp();
73 
74  virtual void OnMouseMove();
75 
76  protected:
77 
80 
81  virtual void Pick();
82 
83  void RedrawRubberBand();
84 
85  int StartPosition[2];
86  int EndPosition[2];
87 
88  int Moving;
89 
90  vtkUnsignedCharArray* PixelArray;
91 
93 
94  // private :
95  //
96  // vtkInteractorStylePick ( const vtkInteractorStylePick& ); // Not implemented
97  // void operator= ( const vtkInteractorStylePick& ); // Not implemented
98 
99  };
100 
101 }
102 
103 namespace camitk{
122 class CAMITK_API RendererWidget : public QVTKWidget {
123  Q_OBJECT
124  Q_ENUMS(ControlMode CameraOrientation); // so that it can be used in property editor
125 
126 public :
127 
139  enum CameraOrientation {
145 
146  };
147 
149  enum ControlMode {
153  NONE
154  };
155 
157 // enum InteractionMode {
158 // CONTROL, ///< mouse interaction mode (\see ControlMode)
159 // PICKING, ///< picking mode
160 // AREA_PICKING ///< area picking mode
161 // };
162 
168  RIGHT_BUTTON
169  };
170 
173  PNG = 0,
174  JPG,
175  BMP,
176  PS,
177  EPS,
178  PDF,
179  TEX,
180  SVG,
181  OBJ,
182  RIB,
184  NOT_SUPPORTED
185  };
186 
189  public:
193  QString extension;
195  QString description;
197  ScreenshotFormatInfo(ScreenshotFormat t, QString e, QString d) : type(t), extension(e), description(d) {}
199  ScreenshotFormatInfo() : type(NOT_SUPPORTED), extension(""), description("Not supported") {}
200  };
201 
214  RendererWidget(QWidget* parent = 0, ControlMode mode = RendererWidget::TRACKBALL);
215 
217  ~RendererWidget();
218 
221 
223  //InteractionMode getInteractionMode() const;
224 
226  //void setInteractionMode(InteractionMode mode);
227 
228  void setAreaPicking(bool areaPicking);
229 
231  ControlMode getControlMode() const;
232 
234  void setControlMode(ControlMode mode);
235 
239  void setPicker(vtkSmartPointer<vtkAbstractPropPicker> woodyWood);
240 
242  void pick();
243 
245  void pickActor(int x, int y);
246 
248  void keyPressEvent(QKeyEvent* e);
249 
252  static const ScreenshotFormatInfo * getScreenshotFormatInfo(unsigned int);
253 
256  static const ScreenshotFormatInfo * getScreenshotFormatInfo(ScreenshotFormat);
257 
261  void screenshot(QString filename);
262 
264  void refresh();
266 
270  void setBackfaceCulling(bool);
271 
273  bool getBackfaceCulling() const;
274 
276  void setCameraOrientation( RendererWidget::CameraOrientation );
277 
279  RendererWidget::CameraOrientation getCameraOrientation( ) const;
280 
282  void setLightFollowCamera(bool);
283 
285  bool getLightFollowCamera() const;
286 
288  void setPointSize(double size);
289 
291  double getPointSize() const;
292 
294  void rotateCamera(double angle, int axe);
295 
300  void resetCamera();
301 
303  void resetCamera(double *bounds);
304 
306  void getCameraSettings(double *position, double *focalPoint, double *viewUp);
307 
309  void setActiveCamera( vtkCamera * cam );
310 
312  vtkCamera * getActiveCamera();
313 
315  void getMouse3DCoordinates(double & x, double & y, double & z);
316 
318  void setBackgroundColor(double, double, double);
319 
321  void getBackgroundColor(double&, double&, double&);
322 
324  bool getGradientBackground();
325 
327  void setGradientBackground(bool);
328 
330  void toogle3DRedBlue();
331 
333  void toggleCopyright(bool);
334 
336  void toggleAxes(bool);
337 
339  void updateAxes();
340 
342  void toggleOrientationDecorations(bool);
343 
345  void setOrientationDecorationsLetters(QString letters[4]);
346 
347 
349  void setColorScale(bool);
350 
352  bool getColorScale() const;
353 
358  void setColorScaleMinMax(double m, double M);
359 
363  void setColorScaleTitle(QString t);
364 
366  void computeVisiblePropBounds(double *bounds);
368 
369 
372 
381  void addProp(vtkSmartPointer<vtkProp> p, bool refresh=false);
382 
384  bool containsProp(vtkSmartPointer<vtkProp>);
385 
390  void removeProp(vtkSmartPointer<vtkProp> p, bool refresh=false);
391 
393  void actorTransform(vtkSmartPointer<vtkActor>, double *, int , double **, double *, double *);
395 
396 
397 
398 protected slots:
402  //void leftClick();
403 
405  //void leftRelease();
406 
408  //void rightClick();
409 
411  void startPicking();
412 
414  void endPicking();
415 
417 
418 signals :
419 
423  void actorPicked(vtkSmartPointer<vtkPicker>);
424 
426  void rightButtonPressed();
428 
429 
430 
431 protected:
432 
433  virtual void mousePressEvent(QMouseEvent* event);
434 
436  virtual void mouseReleaseEvent(QMouseEvent* event);
437 
439  virtual void mouseMoveEvent(QMouseEvent* event);
440 
441 protected :
442 
446  vtkSmartPointer<QVTKInteractor> interactor;
447 
449  vtkSmartPointer<vtkInteractorStyle> controlInteractorStyle;
450 
452  //InteractionMode interactionMode;
453 
456 
458 
462  void resetCameraSettings();
463 
465  vtkSmartPointer<vtkRenderer> renderer;
466 
469 
471  CameraOrientation cameraOrientation;
472 
475 
477  double pointSize;
478 
482 
486  //vtkSmartPointer<vtkEventQtSlotConnect> connector;
487 
489  static void divertionCallback(vtkObject * caller, unsigned long eid, void *clientdata, void *calldata) {};
490 
492  vtkSmartPointer<vtkCallbackCommand> pickingButtonDiverter;
493 
496 
498  vtkSmartPointer<vtkInteractorStylePick> pickInteractorStyle;
499 
501 
505  static void buildScreenshotMap();
506 
508  static const ScreenshotFormatInfo * getScreenshotFormatInfo(QString);
510 
515 
518 
520  vtkSmartPointer<vtkActor2D> copyrightTextActor;
521 
524 
526  vtkSmartPointer<vtkScalarBarActor> colorScale;
527 
529  vtkSmartPointer<vtkScalarBarWidget> colorBarWidget;
530 
532  vtkSmartPointer<vtkAxesActor> axes;
533 
535  vtkSmartPointer<vtkAnnotatedCubeActor> annotatedCube;
536 
537  vtkSmartPointer<vtkActor2D> orientationDecorationActors[4];
538  vtkSmartPointer<vtkTextMapper> orientationDecorationsTextMapper[4];
539 
541 
542 };
543 
544 }
545 
546 #endif //RENDERERWIDGET_H
547 
bool pickingDiverter
is the picking diverter used
Definition: RendererWidget.h:495
bool displayGradient
Definition: RendererWidget.h:514
Alias Wavefront .OBJ.
Definition: RendererWidget.h:181
< World axes are seen so that x points to the left, y points backward. For Medical Images Coronal Vie...
Definition: RendererWidget.h:144
Encapsulated PostScript.
Definition: RendererWidget.h:177
bool backfaceCulling
Is back face culling on?
Definition: RendererWidget.h:468
ControlMode
list of possible user interaction control mode
Definition: RendererWidget.h:149
void PrintSelf(ostream &os, vtkIndent indent)
Definition: RendererWidget.cpp:357
vtkSmartPointer< QVTKInteractor > interactor
Definition: RendererWidget.h:446
vtkUnsignedCharArray * PixelArray
Definition: RendererWidget.h:90
bool displayColorScale
is the color scale currently displayed
Definition: RendererWidget.h:523
ScreenshotFormatInfo(ScreenshotFormat t, QString e, QString d)
Constructor.
Definition: RendererWidget.h:197
LaTeX (only the text is exported)
Definition: RendererWidget.h:179
void SetAreaPicking(bool b)
Definition: RendererWidget.cpp:115
vtkSmartPointer< vtkScalarBarWidget > colorBarWidget
the scalar bar widget
Definition: RendererWidget.h:529
PostScript.
Definition: RendererWidget.h:176
vtkSmartPointer< vtkScalarBarActor > colorScale
the color scale displaying the lookup table + values
Definition: RendererWidget.h:526
JPEG.
Definition: RendererWidget.h:174
virtual void OnLeftButtonDown()
Definition: RendererWidget.cpp:120
RendererWidget implements all support methods to use camiTK with Qt interface.
Definition: RendererWidget.h:122
vtkSmartPointer< vtkRenderer > renderer
The current renderer.
Definition: RendererWidget.h:465
bool displayCopyright
is the copyright text displayed
Definition: RendererWidget.h:517
ScreenshotFormat type
the corresponding type (key)
Definition: RendererWidget.h:191
vtkTypeMacro(vtkInteractorStylePick, vtkInteractorStyle)
Definition: Action.cpp:40
double pointSize
default point size
Definition: RendererWidget.h:477
vtkSmartPointer< vtkActor2D > copyrightTextActor
copyright text vtk actor
Definition: RendererWidget.h:520
ScreenshotFormatInfo()
default constructor
Definition: RendererWidget.h:199
VRML 2.0.
Definition: RendererWidget.h:183
same as TRACKBALL but does not allow rotation using left button (but zoom and displacement parallel t...
Definition: RendererWidget.h:152
virtual void OnMouseMove()
Definition: RendererWidget.cpp: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:142
static vtkInteractorStylePick * New()
void RedrawRubberBand()
Definition: RendererWidget.cpp:206
CameraOrientation cameraOrientation
state of the initial camera orientation
Definition: RendererWidget.h:471
the mouse left button is currently pressed
Definition: RendererWidget.h:166
QString extension
file extension (suffix)
Definition: RendererWidget.h:193
World axes are seen so that x points to the left, y points upward.
Definition: RendererWidget.h:141
the mouse middle button is currently pressed (or 3rd button emulation)
Definition: RendererWidget.h:167
bool AreaPicking
Definition: RendererWidget.h:92
int Moving
Definition: RendererWidget.h:88
the mouse is used as a trackball (default)
Definition: RendererWidget.h:151
int StartPosition[2]
Definition: RendererWidget.h:85
vtkSmartPointer< vtkCallbackCommand > pickingButtonDiverter
the callback to remove left button interaction while in picking mode
Definition: RendererWidget.h:489
Interactor used when we are in picking mode.
Definition: RendererWidget.h:59
bool lightFollowCamera
Is the light following the camera.
Definition: RendererWidget.h:474
the mouse is used a joystick
Definition: RendererWidget.h:150
Portable Document Format.
Definition: RendererWidget.h:178
vtkSmartPointer< vtkAnnotatedCubeActor > annotatedCube
annotated cube actor
Definition: RendererWidget.h:535
bool rendering3DRedBlue
is rendering in 3D stereo red/blue
Definition: RendererWidget.h:480
World axes are seen so that x points to the right, y points downward.
Definition: RendererWidget.h:140
virtual void OnLeftButtonUp()
Definition: RendererWidget.cpp:190
MouseButtonState
state of the pressed button (for 3 buttons mouse)
Definition: RendererWidget.h:164
ScreenshotFormat
list of supported screenshot export formats
Definition: RendererWidget.h:172
CameraOrientation
describes the initial position and orientation of the default camera.
Definition: RendererWidget.h:139
Scalable Vector Graphics.
Definition: RendererWidget.h:180
vtkInteractorStylePick()
Definition: RendererWidget.cpp:101
vtkSmartPointer< vtkAxesActor > axes
axes actor
Definition: RendererWidget.h:532
QString description
file format description
Definition: RendererWidget.h:195
no buttons are currently pressed
Definition: RendererWidget.h:165
vtkSmartPointer< vtkInteractorStyle > controlInteractorStyle
for the interaction with the scene
Definition: RendererWidget.h:449
int EndPosition[2]
Definition: RendererWidget.h:86
~vtkInteractorStylePick()
Definition: RendererWidget.cpp:110
Definition: RendererWidget.h:143
sub-class containing all information concerning exporting images (screenshot)
Definition: RendererWidget.h:188
vtkSmartPointer< vtkInteractorStylePick > pickInteractorStyle
picking interactor
Definition: RendererWidget.h:498
virtual void Pick()
Definition: RendererWidget.cpp:277
Bitmap.
Definition: RendererWidget.h:175
ControlMode controlMode
current control mode
Definition: RendererWidget.h:455
RenderMan/BMRT .RIB.
Definition: RendererWidget.h:182