]> Creatis software - creaRigidRegistration.git/blob - PackRecalage/src/bbPackRecalageReSlicerBox.cxx
29953b0481c3882fb7742b3943776ff83d6a86d5
[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 BBTK_ADD_BLACK_BOX_TO_PACKAGE(PackRecalage,ReSlicerBox)
34 BBTK_BLACK_BOX_IMPLEMENTATION(ReSlicerBox,bbtk::AtomicBlackBox);
35 void ReSlicerBox::Process()
36 {
37         if(!bbGetInputOrigin().empty()  && bbGetInputTransform() != NULL)
38         {
39                 //image = vtkImageChangeInformation::New();
40                 image->SetInput( bbGetInputIn() );
41                 image->SetOutputSpacing( 1,1,1 );
42
43                 if(bbGetInputCentered())
44                 {
45                         image->CenterImageOn();
46                 }
47
48                 //slicer =vtkImageReslice::New();
49                 slicer->SetInput( image->GetOutput() );
50                 slicer->SetInformationInput( image->GetOutput() );
51                 slicer->SetResliceTransform(bbGetInputTransform());
52                 slicer->SetOutputOrigin( -(bbGetInputOrigin()[0]) , -(bbGetInputOrigin()[1]) , -(bbGetInputOrigin()[2]) );
53
54
55                 if(bbGetInputInterpolate())
56                 {
57                         slicer->InterpolateOn();
58                 }               
59                 slicer->Update();
60
61                 //imageResult = vtkImageChangeInformation::New();
62                 imageResult->SetInput( slicer->GetOutput() );
63                 double spc[3];
64                 bbGetInputIn()->GetSpacing(spc);
65                 imageResult->SetOutputSpacing( spc ); 
66                 imageResult->SetOutputOrigin( 0,0,0 ); 
67         
68                 bbSetOutputOut( imageResult->GetOutput() );
69
70                 if (bbGetInputTransform()!=NULL)
71                 { 
72                    bbGetInputTransform()->Update();
73                    vtkMatrix4x4 *m = bbGetInputTransform()->GetMatrix();
74                    if (m!=NULL)
75                    {
76                      printf("EED ReSlicerBox::Process Translation %d %d %d \n",-(bbGetInputOrigin()[0]),-(bbGetInputOrigin()[1]),-(bbGetInputOrigin()[2]));
77                      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));
78                      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));
79                      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));
80                      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));
81                    } // if m 
82                 } // if Transform
83         }
84         else
85         {
86                 bbSetOutputOut( NULL );
87         }  
88 }
89
90
91 void ReSlicerBox::bbUserSetDefaultValues()
92
93         std::vector<int> empty;
94         bbSetInputOrigin(empty); 
95     bbSetInputIn(NULL); 
96     bbSetInputTransform(NULL);
97     bbSetOutputOut(NULL);
98         bbSetInputCentered(false);
99         bbSetInputInterpolate(false);
100   
101 }
102
103
104 void ReSlicerBox::bbUserInitializeProcessing()
105 {
106  
107 //  THE INITIALIZATION METHOD BODY : 
108 //    Here does nothing  
109 //    but this is where you should allocate the internal/output pointers  
110 //    if any  
111         image = vtkImageChangeInformation::New();
112     slicer =vtkImageReslice::New();
113         imageResult = vtkImageChangeInformation::New();
114 }
115         
116 void ReSlicerBox::bbUserFinalizeProcessing()
117
118         image->Delete();
119         slicer->Delete();
120     imageResult->Delete();
121 }
122
123 }
124 // EO namespace bbPackRecalage