Computer Assited Medical Intervention Tool Kit  version 3.4
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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-2014 UJF-Grenoble 1, 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  vtkTypeRevisionMacro ( 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 
120 class CAMITK_API RendererWidget : public QVTKWidget {
121  Q_OBJECT
122  Q_ENUMS(ControlMode CameraOrientation); // so that it can be used in property editor
123 
124 public :
125 
137  enum CameraOrientation {
143 
144  };
145 
147  enum ControlMode {
151  NONE
152  };
153 
155 // enum InteractionMode {
156 // CONTROL, ///< mouse interaction mode (\see ControlMode)
157 // PICKING, ///< picking mode
158 // AREA_PICKING ///< area picking mode
159 // };
160 
166  RIGHT_BUTTON
167  };
168 
171  PNG = 0,
172  JPG,
173  BMP,
174  PS,
175  EPS,
176  PDF,
177  TEX,
178  SVG,
179  OBJ,
180  RIB,
182  NOT_SUPPORTED
183  };
184 
187  public:
191  QString extension;
193  QString description;
195  ScreenshotFormatInfo(ScreenshotFormat t, QString e, QString d) : type(t), extension(e), description(d) {}
197  ScreenshotFormatInfo() : type(NOT_SUPPORTED), extension(""), description("Not supported") {}
198  };
199 
212  RendererWidget(QWidget* parent = 0, ControlMode mode = RendererWidget::TRACKBALL);
213 
215  ~RendererWidget();
216 
219 
221  //InteractionMode getInteractionMode() const;
222 
224  //void setInteractionMode(InteractionMode mode);
225 
226  void setAreaPicking(bool areaPicking);
227 
229  ControlMode getControlMode() const;
230 
232  void setControlMode(ControlMode mode);
233 
237  void setPicker(vtkSmartPointer<vtkAbstractPropPicker> woodyWood);
238 
240  void pick();
241 
243  void pickActor(int x, int y);
244 
246  void keyPressEvent(QKeyEvent* e);
247 
250  static const ScreenshotFormatInfo * getScreenshotFormatInfo(unsigned int);
251 
254  static const ScreenshotFormatInfo * getScreenshotFormatInfo(ScreenshotFormat);
255 
259  void screenshot(QString filename);
260 
262  void refresh();
264 
268  void setBackfaceCulling(bool);
269 
271  bool getBackfaceCulling() const;
272 
274  void setCameraOrientation( RendererWidget::CameraOrientation );
275 
277  RendererWidget::CameraOrientation getCameraOrientation( ) const;
278 
280  void setLightFollowCamera(bool);
281 
283  bool getLightFollowCamera() const;
284 
286  void setPointSize(double size);
287 
289  double getPointSize() const;
290 
292  void rotateCamera(double angle, int axe);
293 
298  void resetCamera();
299 
301  void resetCamera(double *bounds);
302 
304  void getCameraSettings(double *position, double *focalPoint, double *viewUp);
305 
307  void setActiveCamera( vtkCamera * cam );
308 
310  vtkCamera * getActiveCamera();
311 
313  void getMouse3DCoordinates(double & x, double & y, double & z);
314 
316  void setBackgroundColor(double, double, double);
317 
319  void getBackgroundColor(double&, double&, double&);
320 
322  bool getGradientBackground();
323 
325  void setGradientBackground(bool);
326 
328  void toogle3DRedBlue();
329 
331  void toggleCopyright(bool);
332 
334  void toggleAxes(bool);
335 
337  void updateAxes();
338 
340  void toggleOrientationDecorations(bool);
341 
343  void setOrientationDecorationsLetters(QString letters[4]);
344 
345 
347  void setColorScale(bool);
348 
350  bool getColorScale() const;
351 
356  void setColorScaleMinMax(double m, double M);
357 
361  void setColorScaleTitle(QString t);
362 
364  void computeVisiblePropBounds(double *bounds);
366 
367 
370 
379  void addProp(vtkSmartPointer<vtkProp> p, bool refresh=false);
380 
382  bool containsProp(vtkSmartPointer<vtkProp>);
383 
388  void removeProp(vtkSmartPointer<vtkProp> p, bool refresh=false);
389 
391  void actorTransform(vtkSmartPointer<vtkActor>, double *, int , double **, double *, double *);
393 
394 
395 
396 protected slots:
400  //void leftClick();
401 
403  //void leftRelease();
404 
406  //void rightClick();
407 
409  void startPicking();
410 
412  void endPicking();
413 
415 
416 signals :
417 
421  void actorPicked(vtkSmartPointer<vtkPicker>);
422 
424  void rightButtonPressed();
426 
427 
428 
429 protected:
430 
431  virtual void mousePressEvent(QMouseEvent* event);
432 
434  virtual void mouseReleaseEvent(QMouseEvent* event);
435 
437  virtual void mouseMoveEvent(QMouseEvent* event);
438 
439 protected :
440 
444  vtkSmartPointer<QVTKInteractor> interactor;
445 
447  vtkSmartPointer<vtkInteractorStyle> controlInteractorStyle;
448 
450  //InteractionMode interactionMode;
451 
454 
456 
460  void resetCameraSettings();
461 
463  vtkSmartPointer<vtkRenderer> renderer;
464 
467 
469  CameraOrientation cameraOrientation;
470 
473 
475  double pointSize;
476 
480 
484  //vtkSmartPointer<vtkEventQtSlotConnect> connector;
485 
487  static void divertionCallback(vtkObject * caller, unsigned long eid, void *clientdata, void *calldata) {};
488 
490  vtkSmartPointer<vtkCallbackCommand> pickingButtonDiverter;
491 
494 
496  vtkSmartPointer<vtkInteractorStylePick> pickInteractorStyle;
497 
499 
503  static void buildScreenshotMap();
504 
506  static const ScreenshotFormatInfo * getScreenshotFormatInfo(QString);
508 
513 
516 
518  vtkSmartPointer<vtkActor2D> copyrightTextActor;
519 
522 
524  vtkSmartPointer<vtkScalarBarActor> colorScale;
525 
527  vtkSmartPointer<vtkScalarBarWidget> colorBarWidget;
528 
530  vtkSmartPointer<vtkAxesActor> axes;
531 
533  vtkSmartPointer<vtkAnnotatedCubeActor> annotatedCube;
534 
535  vtkSmartPointer<vtkActor2D> orientationDecorationActors[4];
536  vtkSmartPointer<vtkTextMapper> orientationDecorationsTextMapper[4];
537 
539 
540 };
541 
542 }
543 
544 #endif //RENDERERWIDGET_H
545 
World axes are seen so that x points to the right, y points upward.
Definition: RendererWidget.h:140
bool pickingDiverter
is the picking diverter used
Definition: RendererWidget.h:493
bool displayGradient
Definition: RendererWidget.h:512
bool backfaceCulling
Is back face culling on?
Definition: RendererWidget.h:466
void PrintSelf(ostream &os, vtkIndent indent)
Definition: RendererWidget.cpp:356
vtkSmartPointer< QVTKInteractor > interactor
Definition: RendererWidget.h:444
vtkUnsignedCharArray * PixelArray
Definition: RendererWidget.h:90
ControlMode
list of possible user interaction control mode
Definition: RendererWidget.h:147
VRML 2.0.
Definition: RendererWidget.h:181
bool displayColorScale
is the color scale currently displayed
Definition: RendererWidget.h:521
ScreenshotFormatInfo(ScreenshotFormat t, QString e, QString d)
Constructor.
Definition: RendererWidget.h:195
void SetAreaPicking(bool b)
Definition: RendererWidget.cpp:115
vtkSmartPointer< vtkScalarBarWidget > colorBarWidget
the scalar bar widget
Definition: RendererWidget.h:527
CameraOrientation
describes the initial position and orientation of the default camera.
Definition: RendererWidget.h:137
no buttons are currently pressed
Definition: RendererWidget.h:163
the mouse left button is currently pressed
Definition: RendererWidget.h:164
the mouse is used a joystick
Definition: RendererWidget.h:148
vtkSmartPointer< vtkScalarBarActor > colorScale
the color scale displaying the lookup table + values
Definition: RendererWidget.h:524
virtual void OnLeftButtonDown()
Definition: RendererWidget.cpp:120
RendererWidget implements all support methods to use camiTK with Qt interface.
Definition: RendererWidget.h:120
vtkSmartPointer< vtkRenderer > renderer
The current renderer.
Definition: RendererWidget.h:463
bool displayCopyright
is the copyright text displayed
Definition: RendererWidget.h:515
ScreenshotFormat type
the corresponding type (key)
Definition: RendererWidget.h:189
Definition: Action.cpp:40
PostScript.
Definition: RendererWidget.h:174
World axes are seen so that x points to the left, y points upward.
Definition: RendererWidget.h:139
double pointSize
default point size
Definition: RendererWidget.h:475
vtkSmartPointer< vtkActor2D > copyrightTextActor
copyright text vtk actor
Definition: RendererWidget.h:518
ScreenshotFormatInfo()
default constructor
Definition: RendererWidget.h:197
ScreenshotFormat
list of supported screenshot export formats
Definition: RendererWidget.h:170
virtual void OnMouseMove()
Definition: RendererWidget.cpp:156
#define CAMITK_API
Definition: CamiTKAPI.h:49
same as TRACKBALL but does not allow rotation using left button (but zoom and displacement parallel t...
Definition: RendererWidget.h:150
static vtkInteractorStylePick * New()
void RedrawRubberBand()
Definition: RendererWidget.cpp:206
CameraOrientation cameraOrientation
state of the initial camera orientation
Definition: RendererWidget.h:469
Portable Document Format.
Definition: RendererWidget.h:176
QString extension
file extension (suffix)
Definition: RendererWidget.h:191
bool AreaPicking
Definition: RendererWidget.h:92
int Moving
Definition: RendererWidget.h:88
int StartPosition[2]
Definition: RendererWidget.h:85
the mouse middle button is currently pressed (or 3rd button emulation)
Definition: RendererWidget.h:165
the mouse is used as a trackball (default)
Definition: RendererWidget.h:149
LaTeX (only the text is exported)
Definition: RendererWidget.h:177
Interactor used when we are in picking mode.
Definition: RendererWidget.h:59
bool lightFollowCamera
Is the light following the camera.
Definition: RendererWidget.h:472
Encapsulated PostScript.
Definition: RendererWidget.h:175
< World axes are seen so that x points to the left, y points backward. For Medical Images Coronal Vie...
Definition: RendererWidget.h:142
RenderMan/BMRT .RIB.
Definition: RendererWidget.h:180
World axes are seen so that x points to the right, y points downward.
Definition: RendererWidget.h:138
JPEG.
Definition: RendererWidget.h:172
vtkSmartPointer< vtkAnnotatedCubeActor > annotatedCube
annotated cube actor
Definition: RendererWidget.h:533
vtkTypeRevisionMacro(vtkInteractorStylePick, vtkInteractorStyle)
Definition: RendererWidget.h:141
bool rendering3DRedBlue
is rendering in 3D stereo red/blue
Definition: RendererWidget.h:478
virtual void OnLeftButtonUp()
Definition: RendererWidget.cpp:190
MouseButtonState
state of the pressed button (for 3 buttons mouse)
Definition: RendererWidget.h:162
vtkInteractorStylePick()
Definition: RendererWidget.cpp:101
vtkSmartPointer< vtkAxesActor > axes
axes actor
Definition: RendererWidget.h:530
QString description
file format description
Definition: RendererWidget.h:193
string filename
Definition: pml2csv.cpp:109
vtkSmartPointer< vtkInteractorStyle > controlInteractorStyle
for the interaction with the scene
Definition: RendererWidget.h:447
Alias Wavefront .OBJ.
Definition: RendererWidget.h:179
int EndPosition[2]
Definition: RendererWidget.h:86
~vtkInteractorStylePick()
Definition: RendererWidget.cpp:110
sub-class containing all information concerning exporting images (screenshot)
Definition: RendererWidget.h:186
Scalable Vector Graphics.
Definition: RendererWidget.h:178
vtkSmartPointer< vtkInteractorStylePick > pickInteractorStyle
picking interactor
Definition: RendererWidget.h:496
virtual void Pick()
Definition: RendererWidget.cpp:277
ControlMode controlMode
current control mode
Definition: RendererWidget.h:453
Bitmap.
Definition: RendererWidget.h:173