1 /*=========================================================================
3 Module: $RCSfile: bbtkVtkBlackBoxMacros.h,v $
5 Date: $Date: 2009/12/18 18:37:44 $
6 Version: $Revision: 1.14 $
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_BLACK_BOX_INTERFACE(CLASS,PARENTBLACKBOX,VTKOBJECT) \
52 BBTK_BLACK_BOX_INTERFACE(CLASS,PARENTBLACKBOX); \
53 typedef VTKOBJECT bbVtkObject; \
54 bbVtkObject* bbGetVtkObject() { return mVtkObject; } \
56 bbVtkObject *mVtkObject;
58 //===========================================================================
59 #define BBTK_VTK_SET_DEFAULT_VALUES() \
62 //===========================================================================
63 #define BBTK_VTK_INITIALIZE_PROCESSING() \
64 mVtkObject = bbVtkObject::New();
66 //===========================================================================
67 #define BBTK_VTK_FINALIZE_PROCESSING() \
68 if (mVtkObject) { mVtkObject->Delete(); mVtkObject = NULL; }
71 //===========================================================================
72 #define BBTK_VTK_DELETE() \
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(); \
82 // bbmDescriptorPointer.reset();
83 //===========================================================================
87 //===========================================================================
88 /// Declares a vtkImageAlgorithm-inherited AtomicBlackBox input
89 #define BBTK_DECLARE_VTK_IMAGE_ALGORITHM_INPUT(NAME,TYPE) \
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); }
96 //===========================================================================
98 //===========================================================================
99 /// Declares a vtkPolyDataAlgorithm-inherited AtomicBlackBox input
100 #define BBTK_DECLARE_VTK_POLY_DATA_ALGORITHM_INPUT(NAME,TYPE) \
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); }
107 //===========================================================================
109 //===========================================================================
110 /// Declares a vtkImageAlgorithm-inherited AtomicBlackBox output
111 #define BBTK_DECLARE_VTK_OUTPUT(NAME,TYPE) \
113 TYPE bbGetOutput##NAME () \
114 { if (mVtkObject) return mVtkObject->GetOutput(); return 0; } \
115 void bbSetOutput##NAME (TYPE d) \
117 //===========================================================================
119 //===========================================================================
120 /// Declares a vtkAlgorithm-inherited AtomicBlackBox input
121 #define BBTK_DECLARE_VTK_INPUT(NAME,TYPE) \
123 TYPE bbGetInput##NAME () \
124 { if (mVtkObject) return dynamic_cast<TYPE>(mVtkObject->GetInput()); \
126 void bbSetInput##NAME (TYPE d) \
127 { if (mVtkObject) mVtkObject->SetInput( (vtkDataObject*) d); }
129 //===========================================================================
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) \
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); \
143 //===========================================================================
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
151 #define BBTK_DECLARE_VTK_2_PARAM(NAME,TYPE) \
153 TYPE bbGetInput##NAME () \
155 TO DO : HOW TO RECOMPOSE A VECTOR ?
156 { return mVtkObject->Get##NAME(); } \
157 void bbSetInput##NAME (TYPE d) \
159 mVtkObject->Set##NAME(d[0],d[1]); \
162 //===========================================================================
165 //============================================================================
166 /// Defines the default bbUserProcess method for vtk inherited black boxes
167 /// (calls vtkParent::Update)
168 #define BBTK_VTK_PROCESS() \
170 inline void bbUserProcess() \
172 bbtkBlackBoxDebugMessage("process",1,"**> Processing..." \
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" \
181 //============================================================================
184 //===========================================================================
186 //===========================================================================