Computer Assited Medical Intervention Tool Kit
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Component.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 CAMITK_COMPONENT_H
27 #define CAMITK_COMPONENT_H
28 
29 // -- Core stuff
30 #include "InterfaceNode.h"
31 #include "InterfaceGeometry.h"
32 #include "InterfaceBitMap.h"
33 #include "InterfaceProperty.h"
34 #include "AbortException.h"
35 
36 // -- QT stuff
37 #include <QPixmap>
38 #include <QMenu>
39 
40 // -- vtk stuff
41 #include <vtkWindowLevelLookupTable.h>
42 #include <vtkImageData.h>
43 #include <vtkPointSet.h>
44 #include <vtkSmartPointer.h>
45 #include <vtkAlgorithmOutput.h>
46 #include <vtkActor.h>
47 #include <vtkActor2D.h>
48 #include <vtkImageActor.h>
49 
50 // -- vtk stuff Classes
51 class vtkTexture;
52 class vtkPointSet;
53 class vtkUnstructuredGridAlgorithm;
54 class vtkDataSetToUnstructuredGridFilter;
55 class vtkWindowLevelLookupTable;
56 
57 // -----------------------------------------------------------------------
58 //
59 // Delegation macros
60 // (And your dream comes true)
61 //
62 // -----------------------------------------------------------------------
63 
68 #define invoke0(HANDLER,METHOD) \
69 if (HANDLER) \
70  HANDLER->METHOD();
71 
72 #define invoke1(HANDLER,METHOD,PARAM) \
73 if (HANDLER) \
74  HANDLER->METHOD(PARAM);
75 
76 #define invoke2(HANDLER,METHOD,PARAM1,PARAM2) \
77 if (HANDLER) \
78  HANDLER->METHOD(PARAM1,PARAM2);
79 
80 #define invoke3(HANDLER,METHOD,PARAM1,PARAM2,PARAM3) \
81 if (HANDLER) \
82  HANDLER->METHOD(PARAM1,PARAM2,PARAM3);
83 
84 #define invoke4(HANDLER,METHOD,PARAM1,PARAM2,PARAM3,PARAM4) \
85 if (HANDLER) \
86  HANDLER->METHOD(PARAM1,PARAM2,PARAM3,PARAM4);
87 
92 #define invokeGet0(HANDLER,METHOD) \
93 if (HANDLER) \
94  return HANDLER->METHOD();
95 
96 #define invokeGet1(HANDLER,METHOD,PARAM) \
97 if (HANDLER) \
98  return HANDLER->METHOD(PARAM);
99 
100 #define invokeGet2(HANDLER,METHOD,PARAM1,PARAM2) \
101 if (HANDLER) \
102  return HANDLER->METHOD(PARAM1,PARAM2);
103 
104 #define invokeGet3(HANDLER,METHOD,PARAM1,PARAM2,PARAM3) \
105 if (HANDLER) \
106  return HANDLER->METHOD(PARAM1,PARAM2,PARAM3);
107 
108 #define invokeGet4(HANDLER,METHOD,PARAM1,PARAM2,PARAM3,PARAM4) \
109 if (HANDLER) \
110  return HANDLER->METHOD(PARAM1,PARAM2,PARAM3,PARAM4);
111 
115 #define invokeChildren0(METHOD) \
116 foreach (Component *child, childrenComponent) { \
117  child->METHOD(); \
118  }
119 
120 #define invokeChildren1(METHOD,PARAM) \
121 foreach (Component *child, childrenComponent) { \
122  child->METHOD(PARAM); \
123  }
124 
125 #define invokeChildren2(METHOD,PARAM1,PARAM2) \
126 foreach (Component *child, childrenComponent) { \
127  child->METHOD(PARAM1,PARAM2); \
128  }
129 
130 #define invokeChildren3(METHOD,PARAM1,PARAM2,PARAM3) \
131 foreach (Component *child, childrenComponent) { \
132  child->METHOD(PARAM1,PARAM2,PARAM3); \
133  }
134 
135 #define invokeChildren4(METHOD,PARAM1,PARAM2,PARAM3,PARAM4) \
136 foreach (Component *child, childrenComponent) { \
137  child->METHOD(PARAM1,PARAM2,PARAM3,PARAM4); \
138  }
139 
145 #define delegate0(HANDLER,METHOD) \
146 virtual void METHOD() { \
147  invoke0(HANDLER,METHOD) \
148  }
149 
150 #define delegate1(HANDLER,METHOD,PARAM_TYPE) \
151 virtual void METHOD(PARAM_TYPE param) { \
152  invoke1(HANDLER,METHOD,param) \
153  }
154 
155 #define delegate2(HANDLER,METHOD,PARAM_TYPE1,PARAM_TYPE2) \
156 virtual void METHOD(PARAM_TYPE1 param1, PARAM_TYPE2 param2) { \
157  invoke2(HANDLER,METHOD,param1,param2) \
158  }
159 
160 #define delegate3(HANDLER,METHOD,PARAM_TYPE1,PARAM_TYPE2,PARAM_TYPE3) \
161 virtual void METHOD(PARAM_TYPE1 param1, PARAM_TYPE2 param2, PARAM_TYPE3 param3) { \
162  invoke3(HANDLER,METHOD,param1,param2,param3) \
163  }
164 
165 #define delegate4(HANDLER,METHOD,PARAM_TYPE1,PARAM_TYPE2,PARAM_TYPE3, PARAM_TYPE4) \
166 virtual void METHOD(PARAM_TYPE1 param1, PARAM_TYPE2 param2, PARAM_TYPE3 param3, PARAM_TYPE4 param4) { \
167  invoke4(HANDLER,METHOD,param1,param2,param3,param4) \
168  }
169 
176 #define delegateGet0(HANDLER,METHOD,TYPE) \
177 virtual TYPE METHOD() { \
178  invokeGet0(HANDLER,METHOD) \
179  else \
180  return 0; \
181  }
182 
183 #define delegateGet1(HANDLER,METHOD,TYPE,PARAM_TYPE) \
184 virtual TYPE METHOD(PARAM_TYPE param) { \
185  invokeGet1(HANDLER,METHOD,param) \
186  else \
187  return 0; \
188  }
189 
190 #define delegateGet2(HANDLER,METHOD,TYPE,PARAM1_TYPE,PARAM2_TYPE) \
191 virtual TYPE METHOD(PARAM1_TYPE param1, PARAM2_TYPE param2) { \
192  invokeGet2(HANDLER,METHOD,param1,param2) \
193  else \
194  return 0; \
195  }
196 
199 #define delegateConstGet0(HANDLER,METHOD,TYPE) \
200 virtual TYPE METHOD() const { \
201  invokeGet0(HANDLER,METHOD) \
202  else \
203  return 0; \
204  }
205 
206 #define delegateConstGet1(HANDLER,METHOD,TYPE,PARAM_TYPE) \
207 virtual TYPE METHOD(PARAM_TYPE param) const { \
208  invokeGet1(HANDLER,METHOD,param) \
209  else \
210  return 0; \
211  }
212 
217 #define delegateAndInvokeChildren1(HANDLER,METHOD,PARAM_TYPE) \
218 virtual void METHOD(PARAM_TYPE param) { \
219  invoke1(HANDLER,METHOD,param) \
220  invokeChildren1(METHOD,param) \
221  }
222 
223 #define delegateAndInvokeChildren2(HANDLER,METHOD,PARAM_TYPE1,PARAM_TYPE2) \
224 virtual void METHOD(PARAM_TYPE1 param1, PARAM_TYPE2 param2) { \
225  invoke2(HANDLER,METHOD,param1,param2) \
226  invokeChildren2(METHOD,param1,param2) \
227  }
228 
229 #define delegateAndInvokeChildren1Array(HANDLER,METHOD,PARAM_TYPE1,PARAM_TYPE2,DIM) \
230 virtual void METHOD(PARAM_TYPE1 param1, PARAM_TYPE2 param2[DIM]) { \
231  invoke2(HANDLER,METHOD,param1,param2) \
232  invokeChildren2(METHOD,param1,param2) \
233  }
234 
235 #define delegateAndInvokeChildren3(HANDLER,METHOD,PARAM_TYPE1,PARAM_TYPE2,PARAM_TYPE3) \
236 virtual void METHOD(PARAM_TYPE1 param1, PARAM_TYPE2 param2, PARAM_TYPE3 param3) { \
237  invoke3(HANDLER,METHOD,param1,param2,param3) \
238  invokeChildren3(METHOD,param1,param2,param3) \
239  }
240 
241 #define delegateAndInvokeChildren4(HANDLER,METHOD,PARAM_TYPE1,PARAM_TYPE2,PARAM_TYPE3,PARAM_TYPE4) \
242 virtual void METHOD(PARAM_TYPE1 param1, PARAM_TYPE2 param2, PARAM_TYPE3 param3,PARAM_TYPE4 param4) { \
243  invoke4(HANDLER,METHOD,param1,param2,param3,param4) \
244  invokeChildren4(METHOD,param1,param2,param3,param4) \
245  }
246 
247 
248 namespace camitk {
249 // -- Core stuff classes
250 class Geometry;
251 class Slice;
252 class Viewer;
253 
254 
288  Q_OBJECT
289 
290 public:
299  NO_REPRESENTATION
300  };
301 
305 
306 
313  Component(const QString & file, const QString & name, Representation rep = NO_REPRESENTATION);
314 
322  Component(Component *parentComponent, const QString & name, Representation rep = NO_REPRESENTATION) throw(AbortException);
323 
325  virtual ~Component();
326 
330  Representation getRepresentation() const;
331 
333  bool isTopLevel() const;
334 
336  virtual Component * getParentComponent();
337 
339  virtual Component * getTopLevelComponent();
340 
342  virtual void setModified(bool modified = true);
343 
345  virtual bool getModified() const;
346 
348  virtual void setVisibility(Viewer *, bool);
349 
351  virtual bool getVisibility(Viewer *) const;
352 
354  virtual void refresh() const;
355 
362  virtual void refreshInterfaceNode();
363 
365  virtual bool isSelected() const;
366 
371  virtual void setSelected(const bool, const bool recursive = true);
372 
374  const QString getFileName() const;
375 
377  void setFileName(const QString &);
378 
380  bool event(QEvent* e);
381 
386  QMenu * getActionAndPopupMenu();
388 
393 
394 
395  QStringList getHierarchy();
396 
398  bool isInstanceOf(QString className);
399 
404  virtual QWidget * getPropertyWidget(QWidget* parent = 0) {
405  return NULL;
406  }
407 
415  virtual QObject * getPropertyObject() {
416  return this;
417  }
418 
425  void updateProperty(QString name, QVariant value);
426 
428 
433 
434  //-- the methods below are commented because the default comment in InterfaceNode lacks some information...
435  virtual void addChild(InterfaceNode *);
436  virtual void attachChild(InterfaceNode *);
440  virtual void removeChild(InterfaceNode *);
441 
443  virtual void setParent(InterfaceNode *);
444 
445  //--not commented because Doxygen automatically use the inherited documentation (set INHERIT_DOCS flag to YES in the Doxyfile)
446  virtual void deleteChildren();
447  virtual QString getName() const;
448  virtual void setName(const QString&);
449  virtual const ComponentList & getChildren();
450  virtual bool doubleClicked();
451  virtual InterfaceNode * getParent();
452  virtual QPixmap getIcon();
453 
457  virtual bool inItalic() const;
458 
460  virtual QMenu * getPopupMenu(QWidget* parent = 0) {
461  return NULL;
462  }
464 
469 
470 
471  const QString getLabel() const;
472 
474  void setLabel(QString newName);
475 
476  delegateGet0(myGeometry, getPointSet, vtkSmartPointer<vtkPointSet> )
477 
478  delegate1(myGeometry, setPointSet, vtkSmartPointer<vtkPointSet> )
479 
480  delegate1(myGeometry, setPointData, vtkSmartPointer<vtkDataArray> )
481 
482  delegateConstGet0(myGeometry, getDataPort, vtkSmartPointer<vtkAlgorithmOutput> )
483 
484  delegate1(myGeometry, setDataConnection, vtkSmartPointer<vtkAlgorithmOutput> )
485 
486  delegateGet1(myGeometry, getActor, vtkSmartPointer<vtkActor>, const RenderingModes)
487 
488  // TODO : uses an object myRepresentation (which is a Geometry or a Slice)
489  // to use a single delegate macro
490  virtual vtkSmartPointer<vtkProp> getProp(const QString &param)
491  {
492  if (myGeometry)
493  return myGeometry->getProp(param);
494  else if(mySlice)
495  return mySlice->getProp(param);
496  return NULL;
497  }
498 
499  virtual unsigned int getNumberOfProp() const {
500  if (myGeometry)
501  return myGeometry->getNumberOfProp();
502  else if (mySlice)
503  return mySlice->getNumberOfProp();
504  return 0;
505  }
506 
507  virtual vtkSmartPointer<vtkProp> getProp(unsigned int index) {
508  if (myGeometry)
509  return myGeometry->getProp(index);
510  else if (mySlice)
511  return mySlice->getProp(index);
512  return 0;
513  }
514 
515  virtual bool addProp(const QString &name, vtkSmartPointer<vtkProp> prop) {
516  if (myGeometry)
517  return myGeometry->addProp(name, prop);
518  else if (mySlice)
519  return mySlice->addProp(name, prop);
520  return false;
521  }
522 
523 
524  virtual bool removeProp(const QString & name) {
525  if (myGeometry)
526  return myGeometry->removeProp(name);
527  else if (mySlice)
528  return mySlice->removeProp(name);
529  return false;
530  }
531  // END TODO
532 
533 
537  virtual void pointPicked(vtkIdType, bool) {};
538 
542  virtual void cellPicked(vtkIdType, bool) {};
543 
544  // --
545 
547  virtual void getBounds(double bounds[6]);
548 
552  virtual double getBoundingRadius();
553 
554  delegate4(myGeometry, setPointPosition, const unsigned int, const double, const double, const double);
555 
556  delegateAndInvokeChildren1(myGeometry, setRenderingModes, const RenderingModes)
557 
558 
559  virtual const RenderingModes getRenderingModes() const;
560 
561  delegateAndInvokeChildren1(myGeometry, setEnhancedModes, const EnhancedModes)
562 
563  delegateConstGet0(myGeometry, getEnhancedModes, const EnhancedModes)
564 
565  delegateAndInvokeChildren1Array(myGeometry, setActorColor, const RenderingModes, double, 4)
566 
567  delegateAndInvokeChildren4(myGeometry, setActorColor, const RenderingModes, const double, const double, const double)
568 
570  virtual void getActorColor(const RenderingModes, double [4]);
571 
572  delegateAndInvokeChildren3(myGeometry, setColor, const double, const double, const double)
573 
574  delegateAndInvokeChildren4(myGeometry, setColor, const double, const double, const double, const double)
575 
576  delegateAndInvokeChildren2(myGeometry, setActorOpacity, const RenderingModes, const double)
577 
578  delegateConstGet1(myGeometry, getActorOpacity, double, const RenderingModes)
579 
580  delegateAndInvokeChildren1(myGeometry, setOpacity, const double)
581 
582  delegate1(myGeometry, setTexture, vtkSmartPointer<vtkTexture>)
583 
584  virtual void setGlyphType(const GlyphTypes type, const double size = 0.0);
585 
586  delegate1(myGeometry, setLinesAsTubes, bool)
587 
589 
594 
595  delegateConstGet0(mySlice, getImageData, vtkSmartPointer<vtkImageData>)
596 
597  delegate1(mySlice, setOriginalVolume, vtkSmartPointer<vtkImageData>)
598 
599  delegateConstGet0(mySlice, get2DImageActor, vtkSmartPointer<vtkImageActor>)
600 
601  delegateConstGet0(mySlice, get3DImageActor, vtkSmartPointer<vtkImageActor>)
602 
603  delegateConstGet0(mySlice, getPickPlaneActor, vtkSmartPointer<vtkActor>)
604 
605  delegateGet0(mySlice, getPixelActor, vtkSmartPointer<vtkActor>)
606 
607  delegate3(mySlice, pixelPicked, double, double, double)
608 
609  delegate0(mySlice, updatePickPlane)
610 
611  delegate1(mySlice, setSlice, int)
612 
613  delegate3(mySlice, setSlice, double, double, double)
614 
615  delegate1(mySlice, setRotationX, double)
616 
617  delegate1(mySlice, setRotationY, double)
618 
619  delegate1(mySlice, setRotationZ, double)
620 
621  delegateConstGet0(mySlice, getNumberOfColors, int)
622 
623  delegate3(mySlice, setPixelRealPosition, double, double, double)
624 
626  virtual double getRotationX() const;
627 
629  virtual double getRotationY() const;
630 
632  virtual double getRotationZ() const;
633 
635  virtual int getNumberOfSlices() const;
636 
638  virtual int getSlice() const;
640 
641 
642 protected:
644  InterfaceGeometry * myGeometry;
645 
647  InterfaceBitMap * mySlice;
648 
650  InterfaceNode * myParentNode;
651 
653  ComponentList childrenComponent;
654 
656  bool isSelectedFlag;
657 
659  bool modifiedFlag;
660 
662  QString myFileName;
663 
664 
665 private:
668 
669 
671  void init();
672 
674  Representation myService;
675 
677  QString myName;
678 
683  virtual void initRepresentation() = 0;
684 
686  QMap<Viewer *, bool> myViewers;
687 
689  QMenu * actionsMenu;
691 
695 
696 
697  static QSet<Viewer*> allViewers;
699 
700 };
701 
702 
703 // -------------------- isSelected --------------------
704 inline bool Component::isSelected() const {
705  return isSelectedFlag;
706 }
707 
708 // -------------------- doubleClicked --------------------
710  // always false by default. You must overload this method in Components to change its behaviour.
711  return false;
712 }
713 
714 // -------------------- getChildren --------------------
716  return childrenComponent;
717 }
718 
719 // -------------------- getName --------------------
720 inline QString Component::getName() const {
721  return myName;
722 }
723 
724 // -------------------- getParent --------------------
726  return ((Component*) myParentNode);
727 }
728 
729 // -------------------- getPixmap ------------------
730 inline QPixmap Component::getIcon() {
731  return NULL;
732 }
733 
734 // -------------------- inItalic --------------------
735 inline bool Component::inItalic() const {
736  return false;
737 }
738 
739 // -------------------- setName --------------------
740 inline void Component::setName(const QString & n) {
741  myName = n;
742  if (myGeometry)
743  myGeometry->setLabel(n);
744 }
745 
746 // -------------------- setModified --------------------
747 inline void Component::setModified(bool modification) {
748  modifiedFlag = modification;
749 }
750 
751 // -------------------- getModified --------------------
752 inline bool Component::getModified() const {
753  return modifiedFlag;
754 }
755 
756 // -------------------- getModified --------------------
757 inline const QString Component::getLabel() const {
758  return getName();
759 }
760 // -------------------- getModified --------------------
761 inline void Component::setLabel(QString newName) {
762  setLabel(newName);
763 }
764 
765 }
766 
767 #endif
768