Computer Assited Medical Intervention Tool Kit  version 3.2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups 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-2013 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 
36 // -- VTK stuff classes
37 class vtkRenderer;
38 class vtkInteractorStyle;
39 class vtkPicker;
40 class vtkProp;
41 class vtkActor;
42 class vtkActor2D;
43 class vtkScalarBarActor;
44 class vtkEventQtSlotConnect;
45 class vtkCallbackCommand;
46 class vtkCamera;
47 class vtkAxesActor;
48 class vtkAnnotatedCubeActor;
49 class vtkScalarBarWidget;
50 
51 namespace camitk
52 {
53  // -- Core stuff classes
54 class GeometricObject;
55 
72 class CAMITK_API RendererWidget : public QVTKWidget
73 {
74  Q_OBJECT
75  Q_ENUMS(ControlMode CameraOrientation); // so that it can be used in property editor
76 
77 public :
78 
90  enum CameraOrientation {
93  RIGHT_UP
94  };
95 
97  enum ControlMode {
101  NONE
102  };
103 
109  RIGHT_BUTTON
110  };
111 
114  PNG = 0,
115  JPG,
116  BMP,
117  PS,
118  EPS,
119  PDF,
120  TEX,
121  SVG,
122  OBJ,
123  RIB,
125  NOT_SUPPORTED
126  };
127 
130  public:
134  QString extension;
136  QString description;
138  ScreenshotFormatInfo(ScreenshotFormat t, QString e, QString d) : type(t), extension(e), description(d) {}
140  ScreenshotFormatInfo() : type(NOT_SUPPORTED), extension(""), description("Not supported") {}
141  };
142 
155  RendererWidget(QWidget* parent = 0, ControlMode mode = RendererWidget::TRACKBALL);
156 
158  ~RendererWidget();
159 
163  ControlMode getControlMode() const;
164 
166  void setControlMode(ControlMode mode);
167 
171  void setPicker(vtkSmartPointer<vtkPicker> woodyWood);
172 
174  void pick();
175 
177  void pickActor(int x, int y);
178 
180  void keyPressEvent(QKeyEvent* e);
181 
184  static const ScreenshotFormatInfo * getScreenshotFormatInfo(unsigned int);
185 
188  static const ScreenshotFormatInfo * getScreenshotFormatInfo(ScreenshotFormat);
189 
193  void screenshot(QString filename);
194 
196  void refresh();
198 
202  void setBackfaceCulling(bool);
203 
205  bool getBackfaceCulling() const;
206 
208  void setCameraOrientation( RendererWidget::CameraOrientation );
209 
211  RendererWidget::CameraOrientation getCameraOrientation( ) const;
212 
214  void setLightFollowCamera(bool);
215 
217  bool getLightFollowCamera() const;
218 
220  void setPointSize(double size);
221 
223  double getPointSize() const;
224 
226  void rotateCamera(double angle, int axe);
227 
232  void resetCamera();
233 
235  void resetCamera(double bounds[6]);
236 
238  void getCameraSettings(double position[3], double focalPoint[3], double viewUp[3]);
239 
241  void setActiveCamera( vtkCamera * cam );
242 
244  vtkCamera * getActiveCamera();
245 
247  void getMouse3DCoordinates(double & x, double & y, double & z);
248 
250  void setBackgroundColor(double, double, double);
251 
253  void getBackgroundColor(double&, double&, double&);
254 
256  bool getGradientBackground();
257 
259  void setGradientBackground(bool);
260 
262  void toogle3DRedBlue();
263 
265  void toggleCopyright(bool);
266 
268  void toggleAxes(bool);
269 
271  void updateAxes();
272 
274  void setColorScale(bool);
275 
277  bool getColorScale() const;
278 
283  void setColorScaleMinMax(double m, double M);
284 
288  void setColorScaleTitle(QString t);
289 
291  void computeVisiblePropBounds(double bounds[6]);
293 
294 
297 
306  void addProp(vtkSmartPointer<vtkProp> p, bool refresh=false);
307 
309  bool containsProp(vtkSmartPointer<vtkProp>);
310 
315  void removeProp(vtkSmartPointer<vtkProp> p, bool refresh=false);
316 
318  void actorTransform(vtkSmartPointer<vtkActor>, double *, int , double **, double *, double *);
320 
321 
322 
323 protected slots:
327  void leftClick();
328 
330  void rightClick();
331 
333 
334 signals :
335 
339  void actorPicked(vtkSmartPointer<vtkPicker>);
340 
342  void rightButtonPressed();
344 
345 
346 
347 protected:
349  virtual void mouseReleaseEvent(QMouseEvent* event);
350 
352  virtual void mouseMoveEvent(QMouseEvent* event);
353 
354  protected :
355 
359  vtkSmartPointer<QVTKInteractor> interactor;
360 
362  vtkSmartPointer<vtkInteractorStyle> interactorStyle;
363 
366 
368 
372  void resetCameraSettings();
373 
375  vtkSmartPointer<vtkRenderer> renderer;
376 
379 
381  CameraOrientation cameraOrientation;
382 
385 
387  double pointSize;
388 
392 
396  vtkSmartPointer<vtkEventQtSlotConnect> connector;
397 
399  static void divertionCallback(vtkObject * caller, unsigned long eid, void *clientdata, void *calldata) {};
400 
402  vtkSmartPointer<vtkCallbackCommand> pickingButtonDiverter;
403 
406 
408 
412  static void buildScreenshotMap();
413 
415  static const ScreenshotFormatInfo * getScreenshotFormatInfo(QString);
417 
422 
425 
427  vtkSmartPointer<vtkActor2D> copyrightTextActor;
428 
431 
433  vtkSmartPointer<vtkScalarBarActor> colorScale;
434 
436  vtkSmartPointer<vtkScalarBarWidget> colorBarWidget;
437 
439  vtkSmartPointer<vtkAxesActor> axes;
440 
442  vtkSmartPointer<vtkAnnotatedCubeActor> annotatedCube;
444 
445 };
446 
447 }
448 
449 #endif //RENDERERWIDGET_H
450