Computer Assited Medical Intervention Tool Kit  version 3.2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
InteractiveViewer.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 
27 #ifndef INTERACTIVE_VIEWER_H
28 #define INTERACTIVE_VIEWER_H
29 
30 // -- Core stuff
31 #include "CamiTKAPI.h"
32 #include "Component.h"
33 #include "Viewer.h"
34 
35 //-- QT stuff
36 #include <QFrame>
37 #include <QPushButton>
38 
39 //-- vtk stuff
40 #include <vtkType.h>
41 #include <vtkSmartPointer.h>
42 
43 //-- vtk stuff classes
44 class vtkActor;
45 class vtkPicker;
46 class vtkProp;
47 class vtkObject;
48 class vtkCamera;
49 
50 namespace camitk {
51 // -- Core stuff classes
52 class RendererWidget;
53 class SliderSpinBoxWidget;
54 class GeometricObject;
55 class InterfaceGeometry;
56 class InterfaceBitMap;
58 
59 typedef vtkSmartPointer<vtkCamera> vtkSmartPointerCamera;
60 
62 class InteractiveViewerFrame : public QFrame {
63 public:
65  InteractiveViewerFrame ( QWidget* parent, InteractiveViewer* s3D ) : QFrame ( parent ), myInteractiveViewer ( s3D ) {};
66 
68  void keyPressEvent ( QKeyEvent* );
69 
70 protected:
72 };
73 
132  Q_OBJECT
133  Q_ENUMS ( HighlightMode RendererWidget::ControlMode RendererWidget::CameraOrientation ) // so that it can be used in property editor
134  Q_PROPERTY ( HighlightMode highlightMode READ getHighlightMode WRITE setHighlightMode )
135  Q_PROPERTY ( QColor backgroundColor READ getBackgroundColor WRITE setBackgroundColor )
136  Q_PROPERTY ( bool gradientBackground READ getGradientBackground WRITE setGradientBackground )
137  Q_PROPERTY ( bool linesAsTubes READ getLinesAsTubes WRITE setLinesAsTubes )
138  Q_PROPERTY ( bool backfaceCulling READ getBackfaceCulling WRITE setBackfaceCulling )
139  Q_PROPERTY ( double pointSize READ getPointSize WRITE setPointSize )
140 
141 public:
143  enum ViewerType {
144  SLICE_VIEWER,
145  GEOMETRY_VIEWER
146  };
147 
150  enum PickingMode {
154  NO_PICKING
155  };
156 
162  OFF,
164  SELECTION_ONLY
165  };
166 
170 
176  static InteractiveViewer * getNewViewer ( QString , ViewerType type );
177 
179  static InteractiveViewer *getViewer ( QString );
180 
182  static InteractiveViewer * get3DViewer();
183 
185  static InteractiveViewer * getAxialViewer();
186 
188  static InteractiveViewer * getCoronalViewer();
189 
191  static InteractiveViewer * getSagittalViewer();
192 
194  static InteractiveViewer * getArbitraryViewer();
195 
197  virtual ~InteractiveViewer();
198 
200  QString getName() const;
202 
205  virtual unsigned int numberOfViewedComponent();
208 
210  virtual void refresh ( Viewer *whoIsAsking = NULL );
211 
213  virtual QWidget * getWidget ( QWidget * parent );
214 
216  virtual QObject * getPropertyObject();
217 
219  virtual QMenu * getMenu();
220 
222  virtual QToolBar * getToolBar();
224 
227 
230  void refreshRenderer();
231 
233  void resetCamera();
234 
236  void setActiveCamera ( QString cameraName );
237 
241  vtkSmartPointer<vtkCamera> getCamera ( QString cameraName = "default" );
242 
244  void screenshot ( QString );
245 
246 public slots:
248  void screenshot();
250 
253 
255 public:
257  virtual void setGradientBackground ( bool );
258 
260  bool getGradientBackground() const;
261 
263  virtual void setBackgroundColor ( QColor );
264 
266  QColor getBackgroundColor() const;
267 
268 public slots:
270  void setBackfaceCulling ( bool );
271 
272 public:
274  bool getBackfaceCulling() const;
275 
276 public slots:
284  void setLinesAsTubes ( bool tubes );
285 
286 public:
288  void keyPressEvent ( QKeyEvent* e );
289 
291  bool getLinesAsTubes() const;
292 
300  void setPointSize ( double size );
301 
303  double getPointSize() const;
304 
306  virtual void setHighlightMode ( InteractiveViewer::HighlightMode );
307 
309  InteractiveViewer::HighlightMode getHighlightMode() const;
310 
313  return rendererWidget;
314  }
315 
316 
318 
321  void setColorScale ( bool );
324 
326  bool getColorScale() const;
327 
333  void setColorScaleMinMax ( double m, double M );
334 
338  void setColorScaleTitle ( QString t );
339 
341  void initPicking ( PickingMode );
342 
344  void getBoundsOfSelected ( double bound[6] );
345 
347  void getBounds ( double bound[6] );
348 
350  void setSideFrameVisible(bool);
352 
353 public slots:
354 
359  void actorPicked ( vtkSmartPointer<vtkPicker> );
360 
363  void sliderChanged ( int );
364 
366  void xAngleChanged ( double angle );
367 
369  void yAngleChanged ( double angle );
370 
372  void zAngleChanged ( double angle );
373 
375  void toggleCopyright ( bool );
376 
377 protected:
380 
385  InteractiveViewer ( QString & name, ViewerType type );
386 
388  static QMap<QString, InteractiveViewer*> viewers;
389 
391  static QString defaultNames[5];
392 
394 
395 
406 
409  void initSettings();
410 
412  ViewerType myType;
413 
416 
418  void toggleInterpolation();
419 
422 
424  void updateSelectionDisplay ( Component * );
425 
427  QMultiMap<Component*, vtkSmartPointer<vtkProp> > actorMap;
428 
430  void addActor ( Component *, vtkSmartPointer<vtkProp> );
431 
433  void removeAllActors ( Component * );
434 
437 
439  QMap<QString, vtkSmartPointerCamera> cameraMap;
441 
444  RendererWidget * rendererWidget;
447 
451 
454 
456  QFrame *sideFrame;
457 
459  friend void InteractiveViewerFrame::keyPressEvent ( QKeyEvent* e );
460 
462  QMenu* viewerMenu;
463 
465  QToolBar *viewerToolBar;
466 
468  void initActions();
469 
471  void updateActions();
472 
475 
478  QAction *surfaceAction;
479  QAction *wireframeAction;
480  QAction *pointsAction;
481  QAction *colorAction;
482  QAction *glyphAction;
483 
488 
492 
497 
500 
503 
506 
509 
512 
515 
517  QAction *pickPointAction;
518  QAction *pickCellAction;
519  //TODO QAction *pickRegionAction; /// to pick a region by selecting top left / bottom right corners
520 
522 
525 
530  std::vector <Component *> pickedComponent;
531 
534 
537 
541 
542 
545  QString whatsThis;
548 
551 
553  void initWhatsThis();
554 
556  void startWhatsThisSection ( const QString & title = "" );
557 
559  void endWhatsThisSection();
560 
562  void addWhatsThisItem ( const QString & key, const QString & description );
564 
565 protected slots:
568  void renderingActorsChanged();
570 
571  void highlightModeChanged ( QAction *selectedAction );
572 
573  void cameraOrientationChanged ( QAction *selectedAction );
574 
575  void viewControlModeChanged ( QAction* );
576 
577  void backgroundColor();
578 
579  void toggleAxes ( bool );
580 
581  void pickingModeChanged ( QAction* );
582 
583  void rightClick();
584 
586  void setLabel (bool);
587 
588  void setGlyph(bool);
589 
591 };
592 
593 }
594 
595 
596 #endif
597 
598 //**************************************************************************