]> Creatis software - bbtk.git/blob - kernel/src/bbtkVtkBlackBoxMacros.h
*** empty log message ***
[bbtk.git] / kernel / src / bbtkVtkBlackBoxMacros.h
1 /*=========================================================================
2                                                                                 
3   Program:   bbtk
4   Module:    $RCSfile: bbtkVtkBlackBoxMacros.h,v $
5   Language:  C++
6   Date:      $Date: 2008/07/29 07:31:13 $
7   Version:   $Revision: 1.6 $
8                                                                                 
9   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
10   l'Image). All rights reserved. See Doc/License.txt or
11   http://www.creatis.insa-lyon.fr/Public/bbtk/License.html for details.
12                                                                                 
13      This software is distributed WITHOUT ANY WARRANTY; without even
14      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15      PURPOSE.  See the above copyright notices for more information.
16                                                                                 
17 =========================================================================*/
18
19
20 /**
21  *  \file 
22  *  \brief Defines macros for the creation of vtk object inherited black boxes
23  */
24 #ifndef __bbtkVtkBlackBoxMacros_h__
25 #define __bbtkVtkBlackBoxMacros_h__
26 //#include <vtkGarbageCollector.h>
27 //#include <vtkObjectFactory.h>
28 #include <vtkDebugLeaks.h>
29
30
31 //===========================================================================
32 //============================================================================
33 // VTK Specific macros
34 //===========================================================================
35 //===========================================================================
36
37
38 //===========================================================================
39 #define BBTK_VTK_DELETE()                                               \
40   void bbDelete() {                                                     \
41     bbGetOutputOut()->SetSource(NULL);                                  \
42     vtkParent::Delete();                                                \
43   }
44
45 //    bbmDescriptorPointer.reset();             
46 //===========================================================================
47
48 //===========================================================================
49 #define BBTK_VTK_NEW(CLASS,VTKPARENT)                                   \
50   inline static Pointer New(const std::string& name)                    \
51   {                                                                     \
52     vtkDebugLeaks::ConstructClass(#VTKPARENT);                          \
53     bbtkDebugMessage("object",1,"##> "<<#CLASS                          \
54                      <<"::New(\""<<name<<"\")"<<std::endl);             \
55     Pointer p = MakeBlackBoxPointer(new Self(name));                    \
56     bbtkDebugMessage("object",1,"<## "<<#CLASS                          \
57                      <<"::New(\""<<name<<"\")"<<std::endl);             \
58     return p;                                                           \
59   }                                                                     \
60 //===========================================================================
61
62 //===========================================================================
63 #define BBTK_VTK_CLONE(CLASS,VTKPARENT)                                 \
64   inline bbtk::BlackBox::Pointer bbClone(const std::string& name)       \
65   {                                                                     \
66     vtkDebugLeaks::ConstructClass(#VTKPARENT);                          \
67     bbtkDebugMessage("object",1,"##> "<<#CLASS                          \
68                      <<"::bbClone(\""<<name<<"\")"<<std::endl);         \
69     Pointer p = MakeBlackBoxPointer(new Self(*this,name));              \
70     bbtkDebugMessage("object",1,"<## "<<#CLASS                          \
71                      <<"::bbClone(\""<<name<<"\")"<<std::endl);         \
72     return p;                                                           \
73   }                                                                     \
74
75
76 //===========================================================================
77 #define BBTK_VTK_BLACK_BOX_INTERFACE(CLASS,PARENTBLACKBOX,VTKPARENT)    \
78   BBTK_BLACK_BOX_INTERFACE_WITHOUT_NEW(CLASS,PARENTBLACKBOX);           \
79   typedef VTKPARENT vtkParent;                                          \
80   BBTK_VTK_DELETE();                                                    \
81   public :                                                              \
82   BBTK_VTK_NEW(CLASS,VTKPARENT);                                        \
83   BBTK_VTK_CLONE(CLASS,VTKPARENT);                                                      
84 //===========================================================================
85
86 //===========================================================================
87 /// Declares a vtkImageAlgorithm-inherited AtomicBlackBox input 
88 #define BBTK_DECLARE_VTK_IMAGE_ALGORITHM_INPUT(NAME,TYPE)               \
89   public:                                                               \
90   TYPE bbGetInput##NAME ()                                              \
91   { return GetImageDataInput(0); /*vtkParent::GetInput();*/ }           \
92   void bbSetInput##NAME (TYPE d)                                        \
93   { vtkParent::SetInput( (vtkDataObject*) d);                           \
94     /*bbSetModifiedStatus();*/ }                                
95 //===========================================================================
96
97 //===========================================================================
98 /// Declares a vtkPolyDataAlgorithm-inherited AtomicBlackBox input 
99 #define BBTK_DECLARE_VTK_POLY_DATA_ALGORITHM_INPUT(NAME,TYPE)           \
100   public:                                                               \
101   TYPE bbGetInput##NAME ()                                              \
102   { return GetPolyDataInput(0); /*vtkParent::GetInput();*/ }            \
103   void bbSetInput##NAME (TYPE d)                                        \
104   { vtkParent::SetInput( (vtkDataObject*) d);                           \
105     /*bbSetModifiedStatus();*/ }                                                       
106 //===========================================================================
107
108 //===========================================================================
109 /// Declares a vtkImageAlgorithm-inherited AtomicBlackBox output 
110 #define BBTK_DECLARE_VTK_OUTPUT(NAME,TYPE)                              \
111   public:                                                               \
112   TYPE bbGetOutput##NAME ()                                             \
113   { return vtkParent::GetOutput(); }                                    \
114   void bbSetOutput##NAME (TYPE d)                                       \
115   { /*vtkParent::GetOutput() = d;*/ }                                   
116 //===========================================================================
117
118 //===========================================================================
119 /// Declares a vtkAlgorithm-inherited AtomicBlackBox input 
120 #define BBTK_DECLARE_VTK_INPUT(NAME,TYPE)                       \
121   public:                                                               \
122   TYPE bbGetInput##NAME ()                                              \
123   { return dynamic_cast<TYPE>(vtkParent::GetInput()); }                 \
124   void bbSetInput##NAME (TYPE d)                                        \
125   { vtkParent::SetInput( (vtkDataObject*) d); /*vtkParent::GetOutput() = d;*/ }
126
127 //===========================================================================
128
129 //===========================================================================
130 /// Declares an AtomicBlackBox input corresponding to an 
131 /// inherited vtk parameter
132 /// which was declared by vtkSetMacro/vtkGetMacro
133 /// The NAME **MUST** be the same than the vtk parameter name
134 #define BBTK_DECLARE_VTK_PARAM(NAME,TYPE)                       \
135   public:                                                               \
136   TYPE bbGetInput##NAME ()                                              \
137   { return vtkParent::Get##NAME(); }                                    \
138   void bbSetInput##NAME (TYPE d)                                        \
139   { vtkParent::Set##NAME(d);                                            \
140     /*bbSetModifiedStatus();*/ }
141 //===========================================================================
142
143
144
145 //============================================================================
146 /// Defines the default bbUserProcess method for vtk inherited black boxes
147 /// (calls vtkParent::Update)
148 #define BBTK_VTK_PROCESS()                                              \
149   public:                                                               \
150   inline void bbUserProcess()                                           \
151   {                                                                     \
152     bbtkDebugMessage("process",1,"**> Processing ["<<bbGetFullName()    \
153                      <<"]"<<std::endl);                                 \
154     vtkParent::Update();                                                \
155     bbtkDebugMessage("process",2,"<** Processing ["<<bbGetFullName()    \
156                      <<"]"<<std::endl);                                 \
157   }
158 //============================================================================
159
160
161 //===========================================================================
162 /// EOF
163 //===========================================================================
164 #endif