]> Creatis software - bbtk.git/blob - kernel/src/bbtkVtkBlackBoxMacros.h
6102fef06bdb30fa24a03e785bf1ded593a8c423
[bbtk.git] / kernel / src / bbtkVtkBlackBoxMacros.h
1 /*=========================================================================                                                                               
2   Program:   bbtk
3   Module:    $RCSfile: bbtkVtkBlackBoxMacros.h,v $
4   Language:  C++
5   Date:      $Date: 2009/12/18 18:37:44 $
6   Version:   $Revision: 1.14 $
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_BLACK_BOX_INTERFACE(CLASS,PARENTBLACKBOX,VTKOBJECT)    \
52   BBTK_BLACK_BOX_INTERFACE(CLASS,PARENTBLACKBOX);                       \
53   typedef VTKOBJECT bbVtkObject;                                        \
54   bbVtkObject* bbGetVtkObject() { return mVtkObject; }                  \
55   private:                                                              \
56   bbVtkObject *mVtkObject;                                              
57
58 //===========================================================================
59 #define BBTK_VTK_SET_DEFAULT_VALUES()           \
60   mVtkObject = NULL;
61
62 //===========================================================================
63 #define BBTK_VTK_INITIALIZE_PROCESSING()        \
64   mVtkObject = bbVtkObject::New();
65
66 //===========================================================================
67 #define BBTK_VTK_FINALIZE_PROCESSING()          \
68   if (mVtkObject) { mVtkObject->Delete(); mVtkObject = NULL; }
69
70 /*
71 //===========================================================================
72 #define BBTK_VTK_DELETE()                                               \
73   int bbDelete() {                                                      \
74     for (int i=0; i<mVtkObject->GetNumberOfInputPorts();++i)            \
75     mVtkObject->SetInput(i,0);                                          \
76     bbGetOutputOut()->SetSource(NULL);                                  \
77     int refs = mVtkObject->GetReferenceCount()-1;                                       \
78     mVtkObject->Delete();                                               \
79     return refs;                                                        \
80   }
81
82 //    bbmDescriptorPointer.reset();             
83 //===========================================================================
84 */
85
86
87 //===========================================================================
88 /// Declares a vtkImageAlgorithm-inherited AtomicBlackBox input 
89 #define BBTK_DECLARE_VTK_IMAGE_ALGORITHM_INPUT(NAME,TYPE)               \
90   public:                                                               \
91   TYPE bbGetInput##NAME ()                                              \
92   { if (mVtkObject) return mVtkObject->GetImageDataInput(0); return 0; } \
93   void bbSetInput##NAME (TYPE d)                                        \
94   { if (mVtkObject) mVtkObject->SetInput( (vtkDataObject*) d); }
95
96 //===========================================================================
97
98 //===========================================================================
99 /// Declares a vtkPolyDataAlgorithm-inherited AtomicBlackBox input 
100 #define BBTK_DECLARE_VTK_POLY_DATA_ALGORITHM_INPUT(NAME,TYPE)           \
101   public:                                                               \
102   TYPE bbGetInput##NAME ()                                              \
103   { if (mVtkObject) return mVtkObject->GetPolyDataInput(0); return 0; } \
104   void bbSetInput##NAME (TYPE d)                                        \
105   { if (mVtkObject) mVtkObject->SetInput( (vtkDataObject*) d); }
106
107 //===========================================================================
108
109 //===========================================================================
110 /// Declares a vtkImageAlgorithm-inherited AtomicBlackBox output 
111 #define BBTK_DECLARE_VTK_OUTPUT(NAME,TYPE)                              \
112   public:                                                               \
113   TYPE bbGetOutput##NAME ()                                             \
114   { if (mVtkObject) return mVtkObject->GetOutput(); return 0; }         \
115   void bbSetOutput##NAME (TYPE d)                                       \
116   { }                                   
117 //===========================================================================
118
119 //===========================================================================
120 /// Declares a vtkAlgorithm-inherited AtomicBlackBox input 
121 #define BBTK_DECLARE_VTK_INPUT(NAME,TYPE)                               \
122   public:                                                               \
123   TYPE bbGetInput##NAME ()                                              \
124   { if (mVtkObject) return dynamic_cast<TYPE>(mVtkObject->GetInput());  \
125     return 0;}                                                          \
126   void bbSetInput##NAME (TYPE d)                                        \
127   { if (mVtkObject)  mVtkObject->SetInput( (vtkDataObject*) d); }
128
129 //===========================================================================
130
131 //===========================================================================
132 /// Declares an AtomicBlackBox input corresponding to an 
133 /// inherited vtk parameter
134 /// which was declared by vtkSetMacro/vtkGetMacro
135 /// The NAME **MUST** be the same than the vtk parameter name
136 #define BBTK_DECLARE_VTK_PARAM(NAME,TYPE)                       \
137   public:                                                               \
138   TYPE bbGetInput##NAME ()                                              \
139   { if (mVtkObject) return mVtkObject->Get##NAME(); return 0; }         \
140   void bbSetInput##NAME (TYPE d)                                        \
141   { if (mVtkObject) mVtkObject->Set##NAME(d);                           \
142   }
143 //===========================================================================
144
145 //===========================================================================
146 /// Declares an AtomicBlackBox input corresponding to an 
147 /// inherited vtk parameter
148 /// which was declared by vtkSetMacro/vtkGetMacro
149 /// The NAME **MUST** be the same than the vtk parameter name
150 /*
151 #define BBTK_DECLARE_VTK_2_PARAM(NAME,TYPE)             \
152   public:                                                               \
153   TYPE bbGetInput##NAME ()                                              \
154   {
155   TO DO : HOW TO RECOMPOSE A VECTOR ?
156   { return mVtkObject->Get##NAME(); }                                   \
157   void bbSetInput##NAME (TYPE d)                                        \
158   { 
159   mVtkObject->Set##NAME(d[0],d[1]);             \
160 }
161 */
162 //===========================================================================
163
164
165 //============================================================================
166 /// Defines the default bbUserProcess method for vtk inherited black boxes
167 /// (calls vtkParent::Update)
168 #define BBTK_VTK_PROCESS()                                              \
169   public:                                                               \
170   inline void bbUserProcess()                                           \
171   {                                                                     \
172     bbtkBlackBoxDebugMessage("process",1,"**> Processing..."            \
173                              <<std::endl);                              \
174     mVtkObject->Update();       \
175 printf("EED Process %s\n", bbGetFullName().c_str() ); \
176   vtkIndent indent(2); \
177    mVtkObject->PrintSelf(std::cout, indent ); \
178     bbtkBlackBoxDebugMessage("process",2,"<** Processing"               \
179                              <<std::endl);                              \
180   }
181 //============================================================================
182
183
184 //===========================================================================
185 /// EOF
186 //===========================================================================
187 #endif