]> Creatis software - bbtk.git/blob - packages/vtk/src/bbvtkCleanExternalPlane.cxx
#3107 BBTK Bug New Normal - branch vtk7itk4 compilation with vtk7
[bbtk.git] / packages / vtk / src / bbvtkCleanExternalPlane.cxx
1 /*
2  # ---------------------------------------------------------------------
3  #
4  # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
5  #                        pour la SantÈ)
6  # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
7  # Previous Authors : Laurent Guigues, Jean-Pierre Roux
8  # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
9  #
10  #  This software is governed by the CeCILL-B license under French law and
11  #  abiding by the rules of distribution of free software. You can  use,
12  #  modify and/ or redistribute the software under the terms of the CeCILL-B
13  #  license as circulated by CEA, CNRS and INRIA at the following URL
14  #  http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
15  #  or in the file LICENSE.txt.
16  #
17  #  As a counterpart to the access to the source code and  rights to copy,
18  #  modify and redistribute granted by the license, users are provided only
19  #  with a limited warranty  and the software's author,  the holder of the
20  #  economic rights,  and the successive licensors  have only  limited
21  #  liability.
22  #
23  #  The fact that you are presently reading this means that you have had
24  #  knowledge of the CeCILL-B license and that you accept its terms.
25  # ------------------------------------------------------------------------ */
26
27
28 //=====
29 // Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost)
30 //===== 
31 #include "bbvtkCleanExternalPlane.h"
32 #include "bbvtkPackage.h"
33 namespace bbvtk
34 {
35
36 BBTK_ADD_BLACK_BOX_TO_PACKAGE(vtk,CleanExternalPlane)
37 BBTK_BLACK_BOX_IMPLEMENTATION(CleanExternalPlane,bbtk::AtomicBlackBox);
38
39 //----------------------------------------------------------------------
40 void CleanExternalPlane::CleanTypeA(vtkImageData* image)
41 {
42         if ( bbGetInputIn()!=NULL )
43         {
44                 int i,j;
45                 int ext[6];
46                 int dim[3];
47
48 //EED 2017-01-01 Migration VTK7
49 #if (VTK_MAJOR_VERSION <= 5) 
50                 image->GetWholeExtent(ext);
51 #endif
52 #if (VTK_MAJOR_VERSION >= 6) 
53                 image->GetExtent(ext);
54 #endif
55                 
56                 dim[0]=ext[1]-ext[0]+1;
57                 dim[1]=ext[3]-ext[2]+1;
58                 dim[2]=ext[5]-ext[4]+1;
59                 
60                 // XY plane
61                 for (i=0 ; i<dim[0] ; i++)
62                 {
63                         for (j=0 ; j<dim[1] ; j++)
64                         {
65                                 image->SetScalarComponentFromDouble (ext[0]+i, ext[2]+j, ext[4]+0       , 0, 0.0);
66                                 image->SetScalarComponentFromDouble (ext[0]+i, ext[2]+j, ext[4]+dim[2]-1, 0, 0.0);
67                         } // for j
68                 }// for i
69                 
70                 // YZ plane
71                 for (i=0 ; i<dim[1] ; i++)
72                 {
73                         for (j=0 ; j<dim[2] ; j++)
74                         {
75                                 image->SetScalarComponentFromDouble (ext[0]+0           , ext[2]+i, ext[4]+j, 0, 0.0);
76                                 image->SetScalarComponentFromDouble (ext[0]+dim[0]-1    , ext[2]+i, ext[4]+j, 0, 0.0);
77                         } // for j
78                 } // for i
79                 
80                 // YZ plane
81                 for (i=0 ; i<dim[0] ; i++)
82                 {
83                         for (j=0 ; j<dim[2] ; j++)
84                         {
85                                 image->SetScalarComponentFromDouble (ext[0]+i, ext[2]+0         , ext[4]+j, 0, 0.0);
86                                 image->SetScalarComponentFromDouble (ext[0]+i, ext[2]+dim[1]-1  , ext[4]+j, 0, 0.0);
87                         } // for j
88                 }// for i
89         } // if In
90 }
91
92 //----------------------------------------------------------------------
93 void CleanExternalPlane::CleanTypeB()
94 {
95         int             ext[6]; 
96         int             dimA[3];        
97         int             dimB[3];        
98
99 //EED 2017-01-01 Migration VTK7
100 #if (VTK_MAJOR_VERSION <= 5) 
101         bbGetInputIn()->GetWholeExtent(ext);
102 #endif
103 #if (VTK_MAJOR_VERSION >= 6) 
104         bbGetInputIn()->GetExtent(ext);
105 #endif
106
107         dimA[0] =       ext[1]-ext[0]+1;
108         dimA[1] =       ext[3]-ext[2]+1;
109         dimA[2] =       ext[5]-ext[4]+1;
110
111         dimB[0] =       dimA[0] + 2;
112         dimB[1] =       dimA[1] + 2;
113         dimB[2] =       dimA[2] + 2;
114
115         
116         imageoutput->Initialize();
117         imageoutput->SetSpacing( bbGetInputIn()->GetSpacing() );
118         imageoutput->SetDimensions(  dimB[0], dimB[1], dimB[2] );
119
120 //EED 2017-01-01 Migration VTK7
121 #if (VTK_MAJOR_VERSION <= 5) 
122         imageoutput->SetScalarType( bbGetInputIn()->GetScalarType() );  
123         imageoutput->AllocateScalars();
124 #endif
125 #if (VTK_MAJOR_VERSION >= 6) 
126         imageoutput->AllocateScalars( bbGetInputIn()->GetScalarType() , 1);
127 #endif
128         
129
130         int j,k;
131         long sizeBlock= dimA[0] * bbGetInputIn()->GetScalarSize();
132
133         for (j=0;j<dimA[1];j++)
134         {
135                 for (k=0;k<dimA[2];k++)
136                 {
137                         memcpy(   imageoutput->GetScalarPointer(1,j+1,k+1) , bbGetInputIn()->GetScalarPointer(0,j,k) , sizeBlock );
138                 } // for k
139         } // for j
140
141
142 //EED 2017-01-01 Migration VTK7
143 #if (VTK_MAJOR_VERSION <= 5) 
144         imageoutput->Update();
145 #endif
146 #if (VTK_MAJOR_VERSION >= 6) 
147         // ..
148 #endif
149
150         imageoutput->Modified();
151 }
152
153
154 //===== 
155 // Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost)
156 //===== 
157 void CleanExternalPlane::Process()
158 {
159
160 // THE MAIN PROCESSING METHOD BODY
161 //   Here we simply set the input 'In' value to the output 'Out'
162 //   And print out the output value
163 // INPUT/OUTPUT ACCESSORS ARE OF THE FORM :
164 //    void bbSet{Input|Output}NAME(const TYPE&)
165 //    const TYPE& bbGet{Input|Output}NAME() const 
166 //    Where :
167 //    * NAME is the name of the input/output
168 //      (the one provided in the attribute 'name' of the tag 'input')
169 //    * TYPE is the C++ type of the input/output
170 //      (the one provided in the attribute 'type' of the tag 'input')
171
172 // Nothing to do
173         if (bbGetInputType()==-1)
174         {
175                 bbSetOutputOut( bbGetInputIn() );
176         }
177
178 // Clean external planes
179         if (bbGetInputType()==0)
180         {
181                 CleanTypeA( bbGetInputIn() );
182                 bbSetOutputOut( bbGetInputIn() );
183         }
184
185 // Add new faces and clean the external planes
186         if (bbGetInputType()==1)
187         {
188                 CleanTypeB();
189                 CleanTypeA(imageoutput);
190                 bbSetOutputOut( imageoutput );
191         }
192
193
194         
195         
196 }
197 //===== 
198 // Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost)
199 //===== 
200 void CleanExternalPlane::bbUserSetDefaultValues()
201 {
202
203 //  SET HERE THE DEFAULT INPUT/OUTPUT VALUES OF YOUR BOX 
204 //    Here we initialize the input 'In' to 0
205    bbSetInputIn(NULL);
206    bbSetInputType(0);
207   
208 }
209 //===== 
210 // Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost)
211 //===== 
212 void CleanExternalPlane::bbUserInitializeProcessing()
213 {
214
215 //  THE INITIALIZATION METHOD BODY :
216 //    Here does nothing 
217 //    but this is where you should allocate the internal/output pointers 
218 //    if any 
219
220         imageoutput = vtkImageData::New();
221   
222 }
223 //===== 
224 // Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost)
225 //===== 
226 void CleanExternalPlane::bbUserFinalizeProcessing()
227 {
228
229 //  THE FINALIZATION METHOD BODY :
230 //    Here does nothing 
231 //    but this is where you should desallocate the internal/output pointers 
232 //    if any
233         imageoutput->Delete();
234 }
235
236 } // EO namespace bbvtk
237
238