]> Creatis software - creaRigidRegistration.git/blob - PackRecalage/src/bbPackRecalageReSlicerBox.cxx
2075 creaRigidRegistration Feature New Normal Registration 3D 1P
[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                 image->SetInput( bbGetInputIn() );
85                 image->SetOutputSpacing( 1,1,1 );
86
87                 if(bbGetInputCentered())
88                 {
89                         image->CenterImageOn();
90                 }
91
92                 double tmpbackInfo[19];
93                 GetBackInfo(tmpbackInfo,bbGetInputTransform()->GetMatrix(),bbGetInputOrigin() );
94
95                 if ( CompareBackInfo(backInfoA,tmpbackInfo)==false ) 
96                 {
97                         GetBackInfo(backInfoA,bbGetInputTransform()->GetMatrix(),bbGetInputOrigin() );
98
99                         //slicer =vtkImageReslice::New();
100                         slicer->SetInput( image->GetOutput() );
101                         slicer->SetInformationInput( image->GetOutput() );
102                         slicer->SetResliceTransform(bbGetInputTransform());
103                         slicer->SetOutputOrigin( -(bbGetInputOrigin()[0]) , -(bbGetInputOrigin()[1]) , -(bbGetInputOrigin()[2]) );
104
105                         if(bbGetInputInterpolate())
106                         {
107                                 slicer->InterpolateOn();
108                         }               
109                         slicer->Update();
110
111                         //imageResult = vtkImageChangeInformation::New();
112                         imageResult->SetInput( slicer->GetOutput() );
113                         double spc[3];
114                         bbGetInputIn()->GetSpacing(spc);
115                         imageResult->SetOutputSpacing( spc ); 
116                         imageResult->SetOutputOrigin( 0,0,0 ); 
117         
118                         bbSetOutputOut( imageResult->GetOutput() );
119
120                         if (bbGetInputTransform()!=NULL)
121                         { 
122                                 bbGetInputTransform()->Update();
123                                 vtkMatrix4x4 *m = bbGetInputTransform()->GetMatrix();
124                                 if (m!=NULL)
125                                 {
126                                         printf("EED ReSlicerBox::Process Translation %d %d %d \n",-(bbGetInputOrigin()[0]),-(bbGetInputOrigin()[1]),-(bbGetInputOrigin()[2]));
127                                         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));
128                                         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));
129                                         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));
130                                         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));
131                                 } // if m 
132                         } // if Transform
133                 } // Compare BackInfo
134         } else {
135                         bbSetOutputOut( NULL );
136         }  
137 }
138
139
140 void ReSlicerBox::bbUserSetDefaultValues()
141
142         std::vector<int> empty;
143         bbSetInputOrigin(empty); 
144         bbSetInputIn(NULL); 
145         bbSetInputTransform(NULL);
146         bbSetOutputOut(NULL);
147
148         bbSetInputCentered(false);
149         bbSetInputInterpolate(false);
150   
151         sizeBackInfo=19;
152         for (int i=0; i<sizeBackInfo; i++)
153         {
154                 backInfoA[i]=0;
155         } // for
156 }
157
158
159 void ReSlicerBox::bbUserInitializeProcessing()
160 {
161  
162 //  THE INITIALIZATION METHOD BODY : 
163 //    Here does nothing  
164 //    but this is where you should allocate the internal/output pointers  
165 //    if any  
166         image = vtkImageChangeInformation::New();
167     slicer =vtkImageReslice::New();
168         imageResult = vtkImageChangeInformation::New();
169 }
170         
171 void ReSlicerBox::bbUserFinalizeProcessing()
172
173         image->Delete();
174         slicer->Delete();
175     imageResult->Delete();
176 }
177
178 }
179 // EO namespace bbPackRecalage