]> Creatis software - bbtk.git/blob - packages/vtk/src/bbvtkCleanExternalPlane.cxx
#3000 BBTK Bug New Normal - vtk package CleanPlanes box. limits not clear
[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                 image->GetWholeExtent(ext);
48                 
49                 dim[0]=ext[1]-ext[0]+1;
50                 dim[1]=ext[3]-ext[2]+1;
51                 dim[2]=ext[5]-ext[4]+1;
52                 
53                 // XY plane
54                 for (i=0 ; i<dim[0] ; i++)
55                 {
56                         for (j=0 ; j<dim[1] ; j++)
57                         {
58                                 image->SetScalarComponentFromDouble (ext[0]+i, ext[2]+j, ext[4]+0       , 0, 0.0);
59                                 image->SetScalarComponentFromDouble (ext[0]+i, ext[2]+j, ext[4]+dim[2]-1, 0, 0.0);
60                         } // for j
61                 }// for i
62                 
63                 // YZ plane
64                 for (i=0 ; i<dim[1] ; i++)
65                 {
66                         for (j=0 ; j<dim[2] ; j++)
67                         {
68                                 image->SetScalarComponentFromDouble (ext[0]+0           , ext[2]+i, ext[4]+j, 0, 0.0);
69                                 image->SetScalarComponentFromDouble (ext[0]+dim[0]-1    , ext[2]+i, ext[4]+j, 0, 0.0);
70                         } // for j
71                 } // for i
72                 
73                 // YZ plane
74                 for (i=0 ; i<dim[0] ; i++)
75                 {
76                         for (j=0 ; j<dim[2] ; j++)
77                         {
78                                 image->SetScalarComponentFromDouble (ext[0]+i, ext[2]+0         , ext[4]+j, 0, 0.0);
79                                 image->SetScalarComponentFromDouble (ext[0]+i, ext[2]+dim[1]-1  , ext[4]+j, 0, 0.0);
80                         } // for j
81                 }// for i
82         } // if In
83 }
84
85 //----------------------------------------------------------------------
86 void CleanExternalPlane::CleanTypeB()
87 {
88
89         int             ext[6]; 
90         int             dimA[3];        
91         int             dimB[3];        
92         bbGetInputIn()->GetWholeExtent(ext);
93
94         dimA[0] =       ext[1]-ext[0]+1;
95         dimA[1] =       ext[3]-ext[2]+1;
96         dimA[2] =       ext[5]-ext[4]+1;
97
98         dimB[0] =       dimA[0] + 2;
99         dimB[1] =       dimA[1] + 2;
100         dimB[2] =       dimA[2] + 2;
101
102         
103         imageoutput->Initialize();
104         imageoutput->SetScalarType( bbGetInputIn()->GetScalarType() );  
105         imageoutput->SetSpacing( bbGetInputIn()->GetSpacing() );
106         imageoutput->SetDimensions(  dimB[0], dimB[1], dimB[2] );
107         imageoutput->AllocateScalars();
108         
109
110         int j,k;
111         long sizeBlock= dimA[0] * bbGetInputIn()->GetScalarSize();
112
113         for (j=0;j<dimA[1];j++)
114         {
115                 for (k=0;k<dimA[2];k++)
116                 {
117                         memcpy(   imageoutput->GetScalarPointer(1,j+1,k+1) , bbGetInputIn()->GetScalarPointer(0,j,k) , sizeBlock );
118                 }
119         }
120         imageoutput->Update();
121         imageoutput->Modified();
122 }
123
124
125 //===== 
126 // 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)
127 //===== 
128 void CleanExternalPlane::Process()
129 {
130
131 // THE MAIN PROCESSING METHOD BODY
132 //   Here we simply set the input 'In' value to the output 'Out'
133 //   And print out the output value
134 // INPUT/OUTPUT ACCESSORS ARE OF THE FORM :
135 //    void bbSet{Input|Output}NAME(const TYPE&)
136 //    const TYPE& bbGet{Input|Output}NAME() const 
137 //    Where :
138 //    * NAME is the name of the input/output
139 //      (the one provided in the attribute 'name' of the tag 'input')
140 //    * TYPE is the C++ type of the input/output
141 //      (the one provided in the attribute 'type' of the tag 'input')
142
143 // Nothing to do
144         if (bbGetInputType()==-1)
145         {
146                 bbSetOutputOut( bbGetInputIn() );
147         }
148
149 // Clean external planes
150         if (bbGetInputType()==0)
151         {
152                 CleanTypeA( bbGetInputIn() );
153                 bbSetOutputOut( bbGetInputIn() );
154         }
155
156 // Add new faces and clean the external planes
157         if (bbGetInputType()==1)
158         {
159                 CleanTypeB();
160                 CleanTypeA(imageoutput);
161                 bbSetOutputOut( imageoutput );
162         }
163
164
165         
166         
167 }
168 //===== 
169 // 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)
170 //===== 
171 void CleanExternalPlane::bbUserSetDefaultValues()
172 {
173
174 //  SET HERE THE DEFAULT INPUT/OUTPUT VALUES OF YOUR BOX 
175 //    Here we initialize the input 'In' to 0
176    bbSetInputIn(NULL);
177    bbSetInputType(0);
178   
179 }
180 //===== 
181 // 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)
182 //===== 
183 void CleanExternalPlane::bbUserInitializeProcessing()
184 {
185
186 //  THE INITIALIZATION METHOD BODY :
187 //    Here does nothing 
188 //    but this is where you should allocate the internal/output pointers 
189 //    if any 
190
191         imageoutput = vtkImageData::New();
192   
193 }
194 //===== 
195 // 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)
196 //===== 
197 void CleanExternalPlane::bbUserFinalizeProcessing()
198 {
199
200 //  THE FINALIZATION METHOD BODY :
201 //    Here does nothing 
202 //    but this is where you should desallocate the internal/output pointers 
203 //    if any
204         imageoutput->Delete();
205 }
206
207 } // EO namespace bbvtk
208
209