1 /*=========================================================================
3 Module: $RCSfile: bbtkVtkBlackBoxMacros.h,v $
5 Date: $Date: 2009/02/27 11:20:25 $
6 Version: $Revision: 1.8 $
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 /*std::cout << "VTK : bbDelete() "<<std::endl;*/ \
88 /*std::cout << "Use count = "<<GetUseCount()<<std::endl;*/ \
89 /*std::cout << "VTK count = "<<GetReferenceCount()<<std::endl;*/ \
90 /* vtkParent::SetReferenceCount(1); GetUseCount());*/ \
92 vtkParent::Delete(); \
95 // bbmDescriptorPointer.reset();
96 //===========================================================================
98 //===========================================================================
99 #define BBTK_VTK_NEW(CLASS,VTKPARENT) \
100 inline static Pointer New(const std::string& name) \
102 /*vtkDebugLeaks::ConstructClass(#VTKPARENT);*/ \
103 bbtkDebugMessage("object",1,"##> "<<#CLASS \
104 <<"::New(\""<<name<<"\")"<<std::endl); \
105 Pointer p = MakeBlackBoxPointer(new Self(name)); \
106 bbtkDebugMessage("object",1,"<## "<<#CLASS \
107 <<"::New(\""<<name<<"\")"<<std::endl); \
110 //===========================================================================
112 //===========================================================================
113 #define BBTK_VTK_CLONE(CLASS,VTKPARENT) \
114 inline bbtk::BlackBox::Pointer bbClone(const std::string& name) \
116 /*vtkDebugLeaks::ConstructClass(#VTKPARENT);*/ \
117 bbtkDebugMessage("object",1,"##> "<<#CLASS \
118 <<"::bbClone(\""<<name<<"\")"<<std::endl); \
119 Pointer p = MakeBlackBoxPointer(new Self(*this,name)); \
120 bbtkDebugMessage("object",1,"<## "<<#CLASS \
121 <<"::bbClone(\""<<name<<"\")"<<std::endl); \
126 //===========================================================================
127 #define BBTK_VTK_BLACK_BOX_INTERFACE(CLASS,PARENTBLACKBOX,VTKPARENT) \
128 BBTK_BLACK_BOX_INTERFACE_WITHOUT_NEW(CLASS,PARENTBLACKBOX); \
129 typedef VTKPARENT vtkParent; \
132 BBTK_VTK_NEW(CLASS,VTKPARENT); \
133 BBTK_VTK_CLONE(CLASS,VTKPARENT);
135 // BBTK_VTK_DISABLE_GARBAGE_COLLECTOR
136 //===========================================================================
138 #define BBTK_VTK_UNREGISTER(O)
140 //O->UnRegister(this);
142 //===========================================================================
143 /// Declares a vtkImageAlgorithm-inherited AtomicBlackBox input
144 #define BBTK_DECLARE_VTK_IMAGE_ALGORITHM_INPUT(NAME,TYPE) \
146 TYPE bbGetInput##NAME () \
147 { return GetImageDataInput(0); /*vtkParent::GetInput();*/ } \
148 void bbSetInput##NAME (TYPE d) \
149 { vtkParent::SetInput( (vtkDataObject*) d); \
150 BBTK_VTK_UNREGISTER(d);/*bbSetModifiedStatus();*/ }
151 //===========================================================================
153 //===========================================================================
154 /// Declares a vtkPolyDataAlgorithm-inherited AtomicBlackBox input
155 #define BBTK_DECLARE_VTK_POLY_DATA_ALGORITHM_INPUT(NAME,TYPE) \
157 TYPE bbGetInput##NAME () \
158 { return GetPolyDataInput(0); /*vtkParent::GetInput();*/ } \
159 void bbSetInput##NAME (TYPE d) \
160 { vtkParent::SetInput( (vtkDataObject*) d); \
161 BBTK_VTK_UNREGISTER(d);/*bbSetModifiedStatus();*/ }
162 //===========================================================================
164 //===========================================================================
165 /// Declares a vtkImageAlgorithm-inherited AtomicBlackBox output
166 #define BBTK_DECLARE_VTK_OUTPUT(NAME,TYPE) \
168 TYPE bbGetOutput##NAME () \
169 { return vtkParent::GetOutput(); } \
170 void bbSetOutput##NAME (TYPE d) \
171 { /*vtkParent::GetOutput() = d;*/ }
172 //===========================================================================
174 //===========================================================================
175 /// Declares a vtkAlgorithm-inherited AtomicBlackBox input
176 #define BBTK_DECLARE_VTK_INPUT(NAME,TYPE) \
178 TYPE bbGetInput##NAME () \
179 { return dynamic_cast<TYPE>(vtkParent::GetInput()); } \
180 void bbSetInput##NAME (TYPE d) \
181 { vtkParent::SetInput( (vtkDataObject*) d); \
182 BBTK_VTK_UNREGISTER(d);/*vtkParent::GetOutput() = d;*/ }
184 //===========================================================================
186 //===========================================================================
187 /// Declares an AtomicBlackBox input corresponding to an
188 /// inherited vtk parameter
189 /// which was declared by vtkSetMacro/vtkGetMacro
190 /// The NAME **MUST** be the same than the vtk parameter name
191 #define BBTK_DECLARE_VTK_PARAM(NAME,TYPE) \
193 TYPE bbGetInput##NAME () \
194 { return vtkParent::Get##NAME(); } \
195 void bbSetInput##NAME (TYPE d) \
196 { vtkParent::Set##NAME(d); \
197 /*bbSetModifiedStatus();*/ }
198 //===========================================================================
202 //============================================================================
203 /// Defines the default bbUserProcess method for vtk inherited black boxes
204 /// (calls vtkParent::Update)
205 #define BBTK_VTK_PROCESS() \
207 inline void bbUserProcess() \
209 bbtkDebugMessage("process",1,"**> Processing ["<<bbGetFullName() \
211 vtkParent::Update(); \
212 bbtkDebugMessage("process",2,"<** Processing ["<<bbGetFullName() \
215 //============================================================================
218 //===========================================================================
220 //===========================================================================