]> Creatis software - bbtk.git/blob - packages/vtk/src/bbvtkAutoCrop.cxx
97d8387e2e37289312f0a19e9ced6c6405575b07
[bbtk.git] / packages / vtk / src / bbvtkAutoCrop.cxx
1 //===== 
2 // 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)
3 //===== 
4 #include "bbvtkAutoCrop.h"
5 #include "bbvtkPackage.h"
6 namespace bbvtk
7 {
8
9 BBTK_ADD_BLACK_BOX_TO_PACKAGE(vtk,AutoCrop)
10 BBTK_BLACK_BOX_IMPLEMENTATION(AutoCrop,bbtk::AtomicBlackBox);
11 //===== 
12 // 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)
13 //===== 
14 void AutoCrop::Process()
15 {
16
17         printf("EED  AutoCrop::Process Start\n");               
18
19 // THE MAIN PROCESSING METHOD BODY
20 //   Here we simply set the input 'In' value to the output 'Out'
21 //   And print out the output value
22 // INPUT/OUTPUT ACCESSORS ARE OF THE FORM :
23 //    void bbSet{Input|Output}NAME(const TYPE&)
24 //    const TYPE& bbGet{Input|Output}NAME() const 
25 //    Where :
26 //    * NAME is the name of the input/output
27 //      (the one provided in the attribute 'name' of the tag 'input')
28 //    * TYPE is the C++ type of the input/output
29 //      (the one provided in the attribute 'type' of the tag 'input')
30
31         double value;
32         int i,j,k;
33         int sizeX,sizeY,sizeZ;
34
35         if (bbGetInputIn()!=NULL){
36                 bbGetInputIn()->Update();
37                 int ext[6];
38                 bbGetInputIn()->GetWholeExtent(ext);
39                 sizeX=ext[1]-ext[0]+1;
40                 sizeY=ext[3]-ext[2]+1;
41                 sizeZ=ext[5]-ext[4]+1;
42                 
43                 sizeX=(sizeX/2)*2;
44                 sizeY=(sizeY/2)*2;
45 //              if (_newImage==NULL)
46 //              {
47                         _newImage = vtkImageData::New();
48                         _newImage->Initialize();
49                         _newImage->SetScalarType( bbGetInputIn()->GetScalarType() );
50                         _newImage->SetSpacing( bbGetInputIn()->GetSpacing() );
51                         _newImage->SetNumberOfScalarComponents( bbGetInputIn()->GetNumberOfScalarComponents() );
52                         _newImage->SetDimensions(  sizeX,sizeY,sizeZ );
53                     _newImage->SetWholeExtent(0,sizeX-1,0,sizeY-1,0,sizeZ-1);
54                         _newImage->AllocateScalars();
55 //              }
56         
57
58                 
59                 for (i=0; i<sizeX; i++) 
60                 {
61                          for (j=0; j<sizeY; j++)
62                          {
63                                 for (k=0; k<sizeZ; k++)
64                                 {
65                                         value = bbGetInputIn()->GetScalarComponentAsDouble(i,j,k, 0 );
66                                         _newImage->SetScalarComponentFromDouble(i,j,k, 0, value );
67                                 } // for k
68                         } // for j
69                 } // for i
70                          
71         }// bbGetInputIn
72                          
73    bbSetOutputOut(_newImage);
74                 
75 }
76 //===== 
77 // 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)
78 //===== 
79 void AutoCrop::bbUserSetDefaultValues()
80 {
81
82 //  SET HERE THE DEFAULT INPUT/OUTPUT VALUES OF YOUR BOX 
83 //    Here we initialize the input 'In' to 0
84                  _newImage=NULL;
85                  bbSetInputIn(NULL);
86                  bbSetInputType(0);
87   
88 }
89 //===== 
90 // 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)
91 //===== 
92 void AutoCrop::bbUserInitializeProcessing()
93 {
94
95 //  THE INITIALIZATION METHOD BODY :
96 //    Here does nothing 
97 //    but this is where you should allocate the internal/output pointers 
98 //    if any 
99
100   
101 }
102 //===== 
103 // 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)
104 //===== 
105 void AutoCrop::bbUserFinalizeProcessing()
106 {
107
108 //  THE FINALIZATION METHOD BODY :
109 //    Here does nothing 
110 //    but this is where you should desallocate the internal/output pointers 
111 //    if any
112   
113 }
114 }
115 // EO namespace bbvtk
116
117