]> Creatis software - creaRigidRegistration.git/blob - PackRecalage/src/bbPackRecalageReSlicerBox.cxx
#3221 creaRigidRegistration Feature New Normal - vtk8itk4wx3-mingw64
[creaRigidRegistration.git] / PackRecalage / src / bbPackRecalageReSlicerBox.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 #
8 #  This software is governed by the CeCILL-B license under French law and 
9 #  abiding by the rules of distribution of free software. You can  use, 
10 #  modify and/ or redistribute the software under the terms of the CeCILL-B 
11 #  license as circulated by CEA, CNRS and INRIA at the following URL 
12 #  http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html 
13 #  or in the file LICENSE.txt.
14 #
15 #  As a counterpart to the access to the source code and  rights to copy,
16 #  modify and redistribute granted by the license, users are provided only
17 #  with a limited warranty  and the software's author,  the holder of the
18 #  economic rights,  and the successive licensors  have only  limited
19 #  liability. 
20 #
21 #  The fact that you are presently reading this means that you have had
22 #  knowledge of the CeCILL-B license and that you accept its terms.
23 # ------------------------------------------------------------------------   
24 */
25
26
27 #include "bbPackRecalageReSlicerBox.h"
28 #include "bbPackRecalagePackage.h"
29
30 namespace bbPackRecalage
31 {
32
33
34 //-----------------------------------------------------------------------------
35 void ReSlicerBox::GetBackInfo(double *backInfo, vtkMatrix4x4 *vtkmatrix, std::vector<int> point )
36 {
37
38                 backInfo[0]=vtkmatrix->GetElement(0,0);
39                 backInfo[1]=vtkmatrix->GetElement(0,1);
40                 backInfo[2]=vtkmatrix->GetElement(0,2);
41                 backInfo[3]=vtkmatrix->GetElement(0,3);
42                 backInfo[4]=vtkmatrix->GetElement(1,0);
43                 backInfo[5]=vtkmatrix->GetElement(1,1);
44                 backInfo[6]=vtkmatrix->GetElement(1,2);
45                 backInfo[7]=vtkmatrix->GetElement(1,3);
46                 backInfo[8]=vtkmatrix->GetElement(2,0);
47                 backInfo[9]=vtkmatrix->GetElement(2,1);
48                 backInfo[10]=vtkmatrix->GetElement(2,2);
49                 backInfo[11]=vtkmatrix->GetElement(2,3);
50                 backInfo[12]=vtkmatrix->GetElement(3,0);
51                 backInfo[13]=vtkmatrix->GetElement(3,1);
52                 backInfo[14]=vtkmatrix->GetElement(3,2);
53                 backInfo[15]=vtkmatrix->GetElement(3,3);
54
55                 backInfo[16]=-point[0];
56                 backInfo[17]=-point[1];;
57                 backInfo[18]=-point[2];;
58 }
59
60 //-----------------------------------------------------------------------------
61 bool ReSlicerBox::CompareBackInfo(double* backInfoA, double * backInfoB)
62 {
63         bool ok=true;
64         int i;
65         for (i=0; i<sizeBackInfo; i++ )
66         {
67            if (backInfoA[i]!=backInfoB[i])
68            {
69                 ok=false;
70            } // if
71         } //for
72         return ok;
73 }
74
75
76 //-----------------------------------------------------------------------------
77 BBTK_ADD_BLACK_BOX_TO_PACKAGE(PackRecalage,ReSlicerBox)
78 BBTK_BLACK_BOX_IMPLEMENTATION(ReSlicerBox,bbtk::AtomicBlackBox);
79 void ReSlicerBox::Process()
80 {
81         if(!bbGetInputOrigin().empty()  && bbGetInputTransform() != NULL)
82         {
83                 //image = vtkImageChangeInformation::New();
84 //EED 2017-01-01 Migration VTK7
85 #if VTK_MAJOR_VERSION <= 5
86                 image->SetInput( bbGetInputIn() );
87 #else
88                 image->SetInputData( bbGetInputIn() );
89 #endif
90                 image->SetOutputSpacing( 1,1,1 );
91
92                 if(bbGetInputCentered())
93                 {
94                         image->CenterImageOn();
95                 }
96                 image->Update();
97         double tmpbackInfo[19];
98                 GetBackInfo(tmpbackInfo,bbGetInputTransform()->GetMatrix(),bbGetInputOrigin() );
99
100                 if ( CompareBackInfo(backInfoA,tmpbackInfo)==false ) 
101                 {
102                         GetBackInfo(backInfoA,bbGetInputTransform()->GetMatrix(),bbGetInputOrigin() );
103
104                         //slicer =vtkImageReslice::New();
105 //EED 2017-01-01 Migration VTK7
106 #if VTK_MAJOR_VERSION <= 5
107                         slicer->SetInput( image->GetOutput() );
108 #else
109                         slicer->SetInputData( image->GetOutput() );
110 #endif
111                         slicer->SetInformationInput( image->GetOutput() );
112                         slicer->SetResliceTransform(bbGetInputTransform());
113                         slicer->SetOutputOrigin( -(bbGetInputOrigin()[0]) , -(bbGetInputOrigin()[1]) , -(bbGetInputOrigin()[2]) );
114
115                         if(bbGetInputInterpolate())
116                         {
117                                 slicer->InterpolateOn();
118                         }               
119                         slicer->Update();
120
121                         //imageResult = vtkImageChangeInformation::New();
122 //EED 2017-01-01 Migration VTK7
123 #if VTK_MAJOR_VERSION <= 5
124                         imageResult->SetInput( slicer->GetOutput() );
125 #else
126                         imageResult->SetInputData( slicer->GetOutput() );
127 #endif
128                         double spc[3];
129                         bbGetInputIn()->GetSpacing(spc);
130                         imageResult->SetOutputSpacing( spc ); 
131                         imageResult->SetOutputOrigin( 0,0,0 ); 
132                         imageResult->Update();
133                         bbSetOutputOut( imageResult->GetOutput() );
134
135                         if (bbGetInputTransform()!=NULL)
136                         { 
137                                 bbGetInputTransform()->Update();
138                                 vtkMatrix4x4 *m = bbGetInputTransform()->GetMatrix();
139                                 if (m!=NULL)
140                                 {
141                                         printf("EED ReSlicerBox::Process Translation %d %d %d \n",-(bbGetInputOrigin()[0]),-(bbGetInputOrigin()[1]),-(bbGetInputOrigin()[2]));
142                                         printf("EED ReSlicerBox::Process Matrix %f %f %f %f\n", m->GetElement(0,0),m->GetElement(0,1),m->GetElement(0,2),m->GetElement(0,3));
143                                         printf("EED ReSlicerBox::Process Matrix %f %f %f %f\n", m->GetElement(1,0),m->GetElement(1,1),m->GetElement(1,2),m->GetElement(1,3));
144                                         printf("EED ReSlicerBox::Process Matrix %f %f %f %f\n", m->GetElement(2,0),m->GetElement(2,1),m->GetElement(2,2),m->GetElement(2,3));
145                                         printf("EED ReSlicerBox::Process Matrix %f %f %f %f\n", m->GetElement(3,0),m->GetElement(3,1),m->GetElement(3,2),m->GetElement(3,3));
146                                 } // if m 
147                         } // if Transform
148                 } // Compare BackInfo
149         } else {
150                         bbSetOutputOut( NULL );
151         }  
152 }
153
154
155 void ReSlicerBox::bbUserSetDefaultValues()
156
157         std::vector<int> empty;
158         bbSetInputOrigin(empty); 
159         bbSetInputIn(NULL); 
160         bbSetInputTransform(NULL);
161         bbSetOutputOut(NULL);
162
163         bbSetInputCentered(false);
164         bbSetInputInterpolate(false);
165   
166         sizeBackInfo=19;
167         for (int i=0; i<sizeBackInfo; i++)
168         {
169                 backInfoA[i]=0;
170         } // for
171 }
172
173
174 void ReSlicerBox::bbUserInitializeProcessing()
175 {
176  
177 //  THE INITIALIZATION METHOD BODY : 
178 //    Here does nothing  
179 //    but this is where you should allocate the internal/output pointers  
180 //    if any  
181         image           = vtkImageChangeInformation::New();
182     slicer              = vtkImageReslice::New();
183         imageResult = vtkImageChangeInformation::New();
184 }
185         
186 void ReSlicerBox::bbUserFinalizeProcessing()
187
188         image           -> Delete();
189         slicer          -> Delete();
190     imageResult -> Delete();
191 }
192
193 }
194 // EO namespace bbPackRecalage