Computer Assited Medical Intervention Tool Kit
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros 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 {
91  RIGHT_DOWN,
92  LEFT_UP,
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:
132  QString extension;
133  QString description;
134  ScreenshotFormatInfo(ScreenshotFormat t, QString e, QString d) : type(t), extension(e), description(d) {}
135  ScreenshotFormatInfo() : type(NOT_SUPPORTED), extension(""), description("Not supported") {}
136  };
137 
150  RendererWidget(QWidget* parent = 0, ControlMode mode = RendererWidget::TRACKBALL);
151 
153  ~RendererWidget();
154 
158  ControlMode getControlMode() const;
159 
161  void setControlMode(ControlMode mode);
162 
166  void setPicker(vtkSmartPointer<vtkPicker> woodyWood);
167 
169  void pick();
170 
172  void pickActor(int x, int y);
173 
175  void keyPressEvent(QKeyEvent* e);
176 
179  static const ScreenshotFormatInfo * getScreenshotFormatInfo(unsigned int);
180 
183  static const ScreenshotFormatInfo * getScreenshotFormatInfo(ScreenshotFormat);
184 
188  void screenshot(QString filename);
189 
191  void refresh();
193 
197  void setBackfaceCulling(bool);
198 
200  bool getBackfaceCulling() const;
201 
203  void setCameraOrientation( RendererWidget::CameraOrientation );
204 
206  RendererWidget::CameraOrientation getCameraOrientation( ) const;
207 
209  void setLightFollowCamera(bool);
210 
212  bool getLightFollowCamera() const;
213 
215  void setPointSize(double size);
216 
218  double getPointSize() const;
219 
221  void rotateCamera(double angle, int axe);
222 
227  void resetCamera();
228 
230  void resetCamera(double bounds[6]);
231 
233  void getCameraSettings(double position[3], double focalPoint[3], double viewUp[3]);
234 
236  void setActiveCamera( vtkCamera * cam );
237 
239  vtkCamera * getActiveCamera();
240 
242  void getMouse3DCoordinates(double & x, double & y, double & z);
243 
245  void setBackgroundColor(double, double, double);
246 
248  void getBackgroundColor(double&, double&, double&);
249 
251  bool getGradientBackground();
252 
254  void setGradientBackground(bool);
255 
257  void toogle3DRedBlue();
258 
260  void toggleCopyright(bool);
261 
263  void toggleAxes(bool);
264 
266  void updateAxes();
267 
269  void setColorScale(bool);
270 
272  bool getColorScale() const;
273 
278  void setColorScaleMinMax(double m, double M);
279 
283  void setColorScaleTitle(QString t);
284 
286  void computeVisiblePropBounds(double bounds[6]);
288 
289 
292 
301  void addProp(vtkSmartPointer<vtkProp> p, bool refresh=false);
302 
304  bool containsProp(vtkSmartPointer<vtkProp>);
305 
310  void removeProp(vtkSmartPointer<vtkProp> p, bool refresh=false);
311 
313  void actorTransform(vtkSmartPointer<vtkActor>, double *, int , double **, double *, double *);
315 
316 
317 
318 protected slots:
322  void leftClick();
323 
325  void rightClick();
326 
328 
329 signals :
330 
334  void actorPicked(vtkSmartPointer<vtkPicker>);
335 
337  void rightButtonPressed();
339 
340 
341 
342 protected:
344  virtual void mouseReleaseEvent(QMouseEvent* event);
345 
347  virtual void mouseMoveEvent(QMouseEvent* event);
348 
349  protected :
350 
354  vtkSmartPointer<QVTKInteractor> interactor;
355 
357  vtkSmartPointer<vtkInteractorStyle> interactorStyle;
358 
361 
363 
367  void resetCameraSettings();
368 
370  vtkSmartPointer<vtkRenderer> renderer;
371 
374 
376  CameraOrientation cameraOrientation;
377 
380 
382  double pointSize;
383 
387 
391  vtkSmartPointer<vtkEventQtSlotConnect> connector;
392 
394  static void divertionCallback(vtkObject * caller, unsigned long eid, void *clientdata, void *calldata) {};
395 
397  vtkSmartPointer<vtkCallbackCommand> pickingButtonDiverter;
398 
401 
403 
407  static void buildScreenshotMap();
408 
410  static const ScreenshotFormatInfo * getScreenshotFormatInfo(QString);
412 
417 
420 
422  vtkSmartPointer<vtkActor2D> copyrightTextActor;
423 
426 
428  vtkSmartPointer<vtkScalarBarActor> colorScale;
429 
431  vtkSmartPointer<vtkScalarBarWidget> colorBarWidget;
432 
434  vtkSmartPointer<vtkAxesActor> axes;
435 
437  vtkSmartPointer<vtkAnnotatedCubeActor> annotatedCube;
439 
440 };
441 
442 }
443 
444 #endif //RENDERERWIDGET_H
445