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