1 /*=========================================================================
3 Module: $RCSfile: bbtkVtkBlackBoxMacros.h,v $
5 Date: $Date: 2009/05/14 14:43:34 $
6 Version: $Revision: 1.10 $
7 =========================================================================*/
9 /* ---------------------------------------------------------------------
11 * Copyright (c) CREATIS-LRMN (Centre de Recherche en Imagerie Medicale)
12 * Authors : Eduardo Davila, Laurent Guigues, Jean-Pierre Roux
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.
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
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 * ------------------------------------------------------------------------ */
35 * \brief Defines macros for the creation of vtk object inherited black boxes
37 #ifndef __bbtkVtkBlackBoxMacros_h__
38 #define __bbtkVtkBlackBoxMacros_h__
39 #include <vtkGarbageCollector.h>
40 //#include <vtkObjectFactory.h>
41 #include <vtkDebugLeaks.h>
44 //===========================================================================
45 //============================================================================
46 // VTK Specific macros
47 //===========================================================================
48 //===========================================================================
50 //===========================================================================
51 #define BBTK_VTK_DISABLE_GARBAGE_COLLECTOR \
53 virtual void Register(vtkObjectBase* o) {} \
54 virtual void UnRegister(vtkObjectBase* o) {} \
56 virtual void ReportReferences(vtkGarbageCollector* collector) {}
61 virtual void Register(vtkObjectBase* o) {} \
63 this->RegisterInternal(o, 1);
65 virtual void UnRegister(vtkObjectBase* o)
67 this->UnRegisterInternal(o, 1);
72 virtual void ReportReferences(vtkGarbageCollector* collector)
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");
79 //===========================================================================
81 //===========================================================================
82 #define BBTK_VTK_DELETE() \
84 for (int i=0; i<vtkParent::GetNumberOfInputPorts();++i) \
85 vtkParent::SetInput(i,0); \
86 bbGetOutputOut()->SetSource(NULL); \
87 int refs = GetReferenceCount()-1; \
88 vtkParent::Delete(); \
92 // bbmDescriptorPointer.reset();
93 //===========================================================================
95 //===========================================================================
96 #define BBTK_VTK_NEW(CLASS,VTKPARENT) \
97 inline static Pointer New(const std::string& name) \
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); \
107 //===========================================================================
109 //===========================================================================
110 #define BBTK_VTK_CLONE(CLASS,VTKPARENT) \
111 inline bbtk::BlackBox::Pointer bbClone(const std::string& name) \
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); \
123 //===========================================================================
124 #define BBTK_VTK_BLACK_BOX_INTERFACE(CLASS,PARENTBLACKBOX,VTKPARENT) \
125 BBTK_BLACK_BOX_INTERFACE_WITHOUT_NEW(CLASS,PARENTBLACKBOX); \
126 typedef VTKPARENT vtkParent; \
129 BBTK_VTK_NEW(CLASS,VTKPARENT); \
130 BBTK_VTK_CLONE(CLASS,VTKPARENT);
132 // BBTK_VTK_DISABLE_GARBAGE_COLLECTOR
133 //===========================================================================
135 #define BBTK_VTK_UNREGISTER(O)
137 //O->UnRegister(this);
139 //===========================================================================
140 /// Declares a vtkImageAlgorithm-inherited AtomicBlackBox input
141 #define BBTK_DECLARE_VTK_IMAGE_ALGORITHM_INPUT(NAME,TYPE) \
143 TYPE bbGetInput##NAME () \
144 { return GetImageDataInput(0); /*vtkParent::GetInput();*/ } \
145 void bbSetInput##NAME (TYPE d) \
146 { vtkParent::SetInput( (vtkDataObject*) d); \
147 BBTK_VTK_UNREGISTER(d);/*bbSetModifiedStatus();*/ }
148 //===========================================================================
150 //===========================================================================
151 /// Declares a vtkPolyDataAlgorithm-inherited AtomicBlackBox input
152 #define BBTK_DECLARE_VTK_POLY_DATA_ALGORITHM_INPUT(NAME,TYPE) \
154 TYPE bbGetInput##NAME () \
155 { return GetPolyDataInput(0); /*vtkParent::GetInput();*/ } \
156 void bbSetInput##NAME (TYPE d) \
157 { vtkParent::SetInput( (vtkDataObject*) d); \
158 BBTK_VTK_UNREGISTER(d);/*bbSetModifiedStatus();*/ }
159 //===========================================================================
161 //===========================================================================
162 /// Declares a vtkImageAlgorithm-inherited AtomicBlackBox output
163 #define BBTK_DECLARE_VTK_OUTPUT(NAME,TYPE) \
165 TYPE bbGetOutput##NAME () \
166 { return vtkParent::GetOutput(); } \
167 void bbSetOutput##NAME (TYPE d) \
168 { /*vtkParent::GetOutput() = d;*/ }
169 //===========================================================================
171 //===========================================================================
172 /// Declares a vtkAlgorithm-inherited AtomicBlackBox input
173 #define BBTK_DECLARE_VTK_INPUT(NAME,TYPE) \
175 TYPE bbGetInput##NAME () \
176 { return dynamic_cast<TYPE>(vtkParent::GetInput()); } \
177 void bbSetInput##NAME (TYPE d) \
178 { vtkParent::SetInput( (vtkDataObject*) d); \
179 BBTK_VTK_UNREGISTER(d);/*vtkParent::GetOutput() = d;*/ }
181 //===========================================================================
183 //===========================================================================
184 /// Declares an AtomicBlackBox input corresponding to an
185 /// inherited vtk parameter
186 /// which was declared by vtkSetMacro/vtkGetMacro
187 /// The NAME **MUST** be the same than the vtk parameter name
188 #define BBTK_DECLARE_VTK_PARAM(NAME,TYPE) \
190 TYPE bbGetInput##NAME () \
191 { return vtkParent::Get##NAME(); } \
192 void bbSetInput##NAME (TYPE d) \
193 { vtkParent::Set##NAME(d); \
195 //===========================================================================
197 //===========================================================================
198 /// Declares an AtomicBlackBox input corresponding to an
199 /// inherited vtk parameter
200 /// which was declared by vtkSetMacro/vtkGetMacro
201 /// The NAME **MUST** be the same than the vtk parameter name
203 #define BBTK_DECLARE_VTK_2_PARAM(NAME,TYPE) \
205 TYPE bbGetInput##NAME () \
207 TO DO : HOW TO RECOMPOSE A VECTOR ?
208 { return vtkParent::Get##NAME(); } \
209 void bbSetInput##NAME (TYPE d) \
211 vtkParent::Set##NAME(d[0],d[1]); \
214 //===========================================================================
217 //============================================================================
218 /// Defines the default bbUserProcess method for vtk inherited black boxes
219 /// (calls vtkParent::Update)
220 #define BBTK_VTK_PROCESS() \
222 inline void bbUserProcess() \
224 bbtkDebugMessage("process",1,"**> Processing ["<<bbGetFullName() \
226 vtkParent::Update(); \
227 bbtkDebugMessage("process",2,"<** Processing ["<<bbGetFullName() \
230 //============================================================================
233 //===========================================================================
235 //===========================================================================