]> Creatis software - bbtk.git/blob - kernel/src/bbtkVtkBlackBoxMacros.h
.
[bbtk.git] / kernel / src / bbtkVtkBlackBoxMacros.h
1 /*=========================================================================                                                                               
2   Program:   bbtk
3   Module:    $RCSfile: bbtkVtkBlackBoxMacros.h,v $
4   Language:  C++
5   Date:      $Date: 2009/05/18 06:07:58 $
6   Version:   $Revision: 1.11 $
7 =========================================================================*/
8
9 /* ---------------------------------------------------------------------
10
11 * Copyright (c) CREATIS-LRMN (Centre de Recherche en Imagerie Medicale)
12 * Authors : Eduardo Davila, Laurent Guigues, Jean-Pierre Roux
13 *
14 *  This software is governed by the CeCILL-B license under French law and 
15 *  abiding by the rules of distribution of free software. You can  use, 
16 *  modify and/ or redistribute the software under the terms of the CeCILL-B 
17 *  license as circulated by CEA, CNRS and INRIA at the following URL 
18 *  http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html 
19 *  or in the file LICENSE.txt.
20 *
21 *  As a counterpart to the access to the source code and  rights to copy,
22 *  modify and redistribute granted by the license, users are provided only
23 *  with a limited warranty  and the software's author,  the holder of the
24 *  economic rights,  and the successive licensors  have only  limited
25 *  liability. 
26 *
27 *  The fact that you are presently reading this means that you have had
28 *  knowledge of the CeCILL-B license and that you accept its terms.
29 * ------------------------------------------------------------------------ */                                                                         
30
31
32
33 /**
34  *  \file 
35  *  \brief Defines macros for the creation of vtk object inherited black boxes
36  */
37 #ifndef __bbtkVtkBlackBoxMacros_h__
38 #define __bbtkVtkBlackBoxMacros_h__
39 #include <vtkGarbageCollector.h>
40 //#include <vtkObjectFactory.h>
41 #include <vtkDebugLeaks.h>
42
43
44 //===========================================================================
45 //============================================================================
46 // VTK Specific macros
47 //===========================================================================
48 //===========================================================================
49
50 //===========================================================================
51 #define BBTK_VTK_DISABLE_GARBAGE_COLLECTOR                              \
52   public:                                                               \
53   virtual void Register(vtkObjectBase* o) {}                            \
54   virtual void UnRegister(vtkObjectBase* o) {}                          \
55   protected:                                                            \
56   virtual void ReportReferences(vtkGarbageCollector* collector) {}
57
58 /*
59         
60   public:                                  \
61   virtual void Register(vtkObjectBase* o) {} \
62      {
63      this->RegisterInternal(o, 1);
64      }
65    virtual void UnRegister(vtkObjectBase* o)
66      {
67      this->UnRegisterInternal(o, 1);
68      }
69
70   protected:
71
72    virtual void ReportReferences(vtkGarbageCollector* collector)
73      {
74      // Report references held by this object that may be in a loop.
75      this->Superclass::ReportReferences(collector);
76      vtkGarbageCollectorReport(collector, this->OtherObject, "Other Object");
77      }
78 */
79 //===========================================================================
80
81 //===========================================================================
82 #define BBTK_VTK_DELETE()                                               \
83   int bbDelete() {                                                      \
84     for (int i=0; i<mVtkObject->GetNumberOfInputPorts();++i)            \
85       mVtkObject->SetInput(i,0);                                                \
86     bbGetOutputOut()->SetSource(NULL);                                  \
87     int refs = mVtkObject->GetReferenceCount()-1;                                       \
88     mVtkObject->Delete();                                               \
89     return refs;                                                        \
90   }
91
92 //    bbmDescriptorPointer.reset();             
93 //===========================================================================
94
95 //===========================================================================
96 #define BBTK_VTK_NEW(CLASS,VTKPARENT)                                   \
97   inline static Pointer New(const std::string& name)                    \
98   {                                                                     \
99     /*vtkDebugLeaks::ConstructClass(#VTKPARENT);*/                      \
100     bbtkDebugMessage("object",1,"##> "<<#CLASS                          \
101                      <<"::New(\""<<name<<"\")"<<std::endl);             \
102     Pointer p = MakeBlackBoxPointer(new Self(name));                    \
103     bbtkDebugMessage("object",1,"<## "<<#CLASS                          \
104                      <<"::New(\""<<name<<"\")"<<std::endl);             \
105     return p;                                                           \
106   }                                                                     
107 //===========================================================================
108
109 //===========================================================================
110 #define BBTK_VTK_CLONE(CLASS,VTKPARENT)                                 \
111   inline bbtk::BlackBox::Pointer bbClone(const std::string& name)       \
112   {                                                                     \
113     /*vtkDebugLeaks::ConstructClass(#VTKPARENT);*/                      \
114     bbtkDebugMessage("object",1,"##> "<<#CLASS                          \
115                      <<"::bbClone(\""<<name<<"\")"<<std::endl);         \
116     Pointer p = MakeBlackBoxPointer(new Self(*this,name));              \
117     bbtkDebugMessage("object",1,"<## "<<#CLASS                          \
118                      <<"::bbClone(\""<<name<<"\")"<<std::endl);         \
119     return p;                                                           \
120   }                                                                     
121
122
123 //===========================================================================
124 #define BBTK_VTK_BLACK_BOX_INTERFACE(CLASS,PARENTBLACKBOX,VTKPARENT)    \
125   BBTK_BLACK_BOX_INTERFACE_WITHOUT_NEW(CLASS,PARENTBLACKBOX);           \
126   typedef VTKPARENT vtkParent;                                          \
127     BBTK_VTK_DELETE();                                                  \
128   public :                                                              \
129     BBTK_VTK_NEW(CLASS,VTKPARENT);                                      \
130     BBTK_VTK_CLONE(CLASS,VTKPARENT);                                    \
131   private:                                                              \
132       vtkParent *mVtkObject;                                            
133        
134 //  BBTK_VTK_DISABLE_GARBAGE_COLLECTOR
135 //===========================================================================
136
137 #define BBTK_VTK_UNREGISTER(O) 
138
139 //O->UnRegister(this);
140
141 //===========================================================================
142 /// Declares a vtkImageAlgorithm-inherited AtomicBlackBox input 
143 #define BBTK_DECLARE_VTK_IMAGE_ALGORITHM_INPUT(NAME,TYPE)               \
144   public:                                                               \
145   TYPE bbGetInput##NAME ()                                              \
146   { return mVtkObject->GetImageDataInput(0); /*vtkParent::GetInput();*/ }               \
147   void bbSetInput##NAME (TYPE d)                                        \
148   { mVtkObject->SetInput( (vtkDataObject*) d);                          \
149     BBTK_VTK_UNREGISTER(d);/*bbSetModifiedStatus();*/ }                         
150 //===========================================================================
151
152 //===========================================================================
153 /// Declares a vtkPolyDataAlgorithm-inherited AtomicBlackBox input 
154 #define BBTK_DECLARE_VTK_POLĂ·,TYPE)            \
155   public:                                                               \
156   TYPE bbGetInput##NAME ()                                              \
157   { return mVtkObject->GetPolyDataInput(0); /*vtkParent::GetInput();*/ }                \
158   void bbSetInput##NAME (TYPE d)                                        \
159   { mVtkObject->SetInput( (vtkDataObject*) d);                          \
160     BBTK_VTK_UNREGISTER(d);/*bbSetModifiedStatus();*/ }                                                
161 //===========================================================================
162
163 //===========================================================================
164 /// Declares a vtkImageAlgorithm-inherited AtomicBlackBox output 
165 #define BBTK_DECLARE_VTK_OUTPUT(NAME,TYPE)                              \
166   public:                                                               \
167   TYPE bbGetOutput##NAME ()                                             \
168   { return mVtkObject->GetOutput(); }                                   \
169   void bbSetOutput##NAME (TYPE d)                                       \
170   { /*vtkParent::GetOutput() = d;*/ }                                   
171 //===========================================================================
172
173 //===========================================================================
174 /// Declares a vtkAlgorithm-inherited AtomicBlackBox input 
175 #define BBTK_DECLARE_VTK_INPUT(NAME,TYPE)                       \
176   public:                                                               \
177   TYPE bbGetInput##NAME ()                                              \
178   { return dynamic_cast<TYPE>(mVtkObject->GetInput()); }                        \
179   void bbSetInput##NAME (TYPE d)                                        \
180   { mVtkObject->SetInput( (vtkDataObject*) d);                          \
181    BBTK_VTK_UNREGISTER(d);/*vtkParent::GetOutput() = d;*/ }
182
183 //===========================================================================
184
185 //===========================================================================
186 /// Declares an AtomicBlackBox input corresponding to an 
187 /// inherited vtk parameter
188 /// which was declared by vtkSetMacro/vtkGetMacro
189 /// The NAME **MUST** be the same than the vtk parameter name
190 #define BBTK_DECLARE_VTK_PARAM(NAME,TYPE)                       \
191   public:                                                               \
192   TYPE bbGetInput##NAME ()                                              \
193   { return mVtkObject->Get##NAME(); }                                   \
194   void bbSetInput##NAME (TYPE d)                                        \
195   { mVtkObject->Set##NAME(d);                                           \
196   }
197 //===========================================================================
198
199 //===========================================================================
200 /// Declares an AtomicBlackBox input corresponding to an 
201 /// inherited vtk parameter
202 /// which was declared by vtkSetMacro/vtkGetMacro
203 /// The NAME **MUST** be the same than the vtk parameter name
204 /*
205 #define BBTK_DECLARE_VTK_2_PARAM(NAME,TYPE)             \
206   public:                                                               \
207   TYPE bbGetInput##NAME ()                                              \
208   {
209   TO DO : HOW TO RECOMPOSE A VECTOR ?
210   { return mVtkObject->Get##NAME(); }                                   \
211   void bbSetInput##NAME (TYPE d)                                        \
212   { 
213   mVtkObject->Set##NAME(d[0],d[1]);             \
214 }
215 */
216 //===========================================================================
217
218
219 //============================================================================
220 /// Defines the default bbUserProcess method for vtk inherited black boxes
221 /// (calls vtkParent::Update)
222 #define BBTK_VTK_PROCESS()                                              \
223   public:                                                               \
224   inline void bbUserProcess()                                           \
225   {                                                                     \
226     bbtkDebugMessage("process",1,"**> Processing ["<<bbGetFullName()    \
227                      <<"]"<<std::endl);                                 \
228     mVtkObject->Update();                                               \
229     bbtkDebugMessage("process",2,"<** Processing ["<<bbGetFullName()    \
230                      <<"]"<<std::endl);                                 \
231   }
232 //============================================================================
233
234
235 //===========================================================================
236 /// EOF
237 //===========================================================================
238 #endif