]> Creatis software - bbtk.git/blob - kernel/src/bbtkVtkBlackBoxMacros.h
*** empty log message ***
[bbtk.git] / kernel / src / bbtkVtkBlackBoxMacros.h
1 /*=========================================================================                                                                               
2   Program:   bbtk
3   Module:    $RCSfile: bbtkVtkBlackBoxMacros.h,v $
4   Language:  C++
5   Date:      $Date: 2008/10/17 08:18:14 $
6   Version:   $Revision: 1.7 $
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 //===========================================================================
52 #define BBTK_VTK_DELETE()                                               \
53   void bbDelete() {                                                     \
54     bbGetOutputOut()->SetSource(NULL);                                  \
55     vtkParent::Delete();                                                \
56   }
57
58 //    bbmDescriptorPointer.reset();             
59 //===========================================================================
60
61 //===========================================================================
62 #define BBTK_VTK_NEW(CLASS,VTKPARENT)                                   \
63   inline static Pointer New(const std::string& name)                    \
64   {                                                                     \
65     vtkDebugLeaks::ConstructClass(#VTKPARENT);                          \
66     bbtkDebugMessage("object",1,"##> "<<#CLASS                          \
67                      <<"::New(\""<<name<<"\")"<<std::endl);             \
68     Pointer p = MakeBlackBoxPointer(new Self(name));                    \
69     bbtkDebugMessage("object",1,"<## "<<#CLASS                          \
70                      <<"::New(\""<<name<<"\")"<<std::endl);             \
71     return p;                                                           \
72   }                                                                     \
73 //===========================================================================
74
75 //===========================================================================
76 #define BBTK_VTK_CLONE(CLASS,VTKPARENT)                                 \
77   inline bbtk::BlackBox::Pointer bbClone(const std::string& name)       \
78   {                                                                     \
79     vtkDebugLeaks::ConstructClass(#VTKPARENT);                          \
80     bbtkDebugMessage("object",1,"##> "<<#CLASS                          \
81                      <<"::bbClone(\""<<name<<"\")"<<std::endl);         \
82     Pointer p = MakeBlackBoxPointer(new Self(*this,name));              \
83     bbtkDebugMessage("object",1,"<## "<<#CLASS                          \
84                      <<"::bbClone(\""<<name<<"\")"<<std::endl);         \
85     return p;                                                           \
86   }                                                                     \
87
88
89 //===========================================================================
90 #define BBTK_VTK_BLACK_BOX_INTERFACE(CLASS,PARENTBLACKBOX,VTKPARENT)    \
91   BBTK_BLACK_BOX_INTERFACE_WITHOUT_NEW(CLASS,PARENTBLACKBOX);           \
92   typedef VTKPARENT vtkParent;                                          \
93   BBTK_VTK_DELETE();                                                    \
94   public :                                                              \
95   BBTK_VTK_NEW(CLASS,VTKPARENT);                                        \
96   BBTK_VTK_CLONE(CLASS,VTKPARENT);                                                      
97 //===========================================================================
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   { return GetImageDataInput(0); /*vtkParent::GetInput();*/ }           \
105   void bbSetInput##NAME (TYPE d)                                        \
106   { vtkParent::SetInput( (vtkDataObject*) d);                           \
107     /*bbSetModifiedStatus();*/ }                                
108 //===========================================================================
109
110 //===========================================================================
111 /// Declares a vtkPolyDataAlgorithm-inherited AtomicBlackBox input 
112 #define BBTK_DECLARE_VTK_POLY_DATA_ALGORITHM_INPUT(NAME,TYPE)           \
113   public:                                                               \
114   TYPE bbGetInput##NAME ()                                              \
115   { return GetPolyDataInput(0); /*vtkParent::GetInput();*/ }            \
116   void bbSetInput##NAME (TYPE d)                                        \
117   { vtkParent::SetInput( (vtkDataObject*) d);                           \
118     /*bbSetModifiedStatus();*/ }                                                       
119 //===========================================================================
120
121 //===========================================================================
122 /// Declares a vtkImageAlgorithm-inherited AtomicBlackBox output 
123 #define BBTK_DECLARE_VTK_OUTPUT(NAME,TYPE)                              \
124   public:                                                               \
125   TYPE bbGetOutput##NAME ()                                             \
126   { return vtkParent::GetOutput(); }                                    \
127   void bbSetOutput##NAME (TYPE d)                                       \
128   { /*vtkParent::GetOutput() = d;*/ }                                   
129 //===========================================================================
130
131 //===========================================================================
132 /// Declares a vtkAlgorithm-inherited AtomicBlackBox input 
133 #define BBTK_DECLARE_VTK_INPUT(NAME,TYPE)                       \
134   public:                                                               \
135   TYPE bbGetInput##NAME ()                                              \
136   { return dynamic_cast<TYPE>(vtkParent::GetInput()); }                 \
137   void bbSetInput##NAME (TYPE d)                                        \
138   { vtkParent::SetInput( (vtkDataObject*) d); /*vtkParent::GetOutput() = d;*/ }
139
140 //===========================================================================
141
142 //===========================================================================
143 /// Declares an AtomicBlackBox input corresponding to an 
144 /// inherited vtk parameter
145 /// which was declared by vtkSetMacro/vtkGetMacro
146 /// The NAME **MUST** be the same than the vtk parameter name
147 #define BBTK_DECLARE_VTK_PARAM(NAME,TYPE)                       \
148   public:                                                               \
149   TYPE bbGetInput##NAME ()                                              \
150   { return vtkParent::Get##NAME(); }                                    \
151   void bbSetInput##NAME (TYPE d)                                        \
152   { vtkParent::Set##NAME(d);                                            \
153     /*bbSetModifiedStatus();*/ }
154 //===========================================================================
155
156
157
158 //============================================================================
159 /// Defines the default bbUserProcess method for vtk inherited black boxes
160 /// (calls vtkParent::Update)
161 #define BBTK_VTK_PROCESS()                                              \
162   public:                                                               \
163   inline void bbUserProcess()                                           \
164   {                                                                     \
165     bbtkDebugMessage("process",1,"**> Processing ["<<bbGetFullName()    \
166                      <<"]"<<std::endl);                                 \
167     vtkParent::Update();                                                \
168     bbtkDebugMessage("process",2,"<** Processing ["<<bbGetFullName()    \
169                      <<"]"<<std::endl);                                 \
170   }
171 //============================================================================
172
173
174 //===========================================================================
175 /// EOF
176 //===========================================================================
177 #endif