2 # ---------------------------------------------------------------------
4 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
6 # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
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.
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
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 # ------------------------------------------------------------------------
27 #include "bbPackRecalageReSlicerBox.h"
28 #include "bbPackRecalagePackage.h"
30 namespace bbPackRecalage
34 //-----------------------------------------------------------------------------
35 void ReSlicerBox::GetBackInfo(double *backInfo, vtkMatrix4x4 *vtkmatrix, std::vector<int> point )
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);
55 backInfo[16]=-point[0];
56 backInfo[17]=-point[1];;
57 backInfo[18]=-point[2];;
60 //-----------------------------------------------------------------------------
61 bool ReSlicerBox::CompareBackInfo(double* backInfoA, double * backInfoB)
65 for (i=0; i<sizeBackInfo; i++ )
67 if (backInfoA[i]!=backInfoB[i])
76 //-----------------------------------------------------------------------------
77 BBTK_ADD_BLACK_BOX_TO_PACKAGE(PackRecalage,ReSlicerBox)
78 BBTK_BLACK_BOX_IMPLEMENTATION(ReSlicerBox,bbtk::AtomicBlackBox);
79 void ReSlicerBox::Process()
81 if(!bbGetInputOrigin().empty() && bbGetInputTransform() != NULL)
83 //image = vtkImageChangeInformation::New();
84 //EED 2017-01-01 Migration VTK7
85 #if VTK_MAJOR_VERSION <= 5
86 image->SetInput( bbGetInputIn() );
88 image->SetInputData( bbGetInputIn() );
90 image->SetOutputSpacing( 1,1,1 );
92 if(bbGetInputCentered())
94 image->CenterImageOn();
97 double tmpbackInfo[19];
98 GetBackInfo(tmpbackInfo,bbGetInputTransform()->GetMatrix(),bbGetInputOrigin() );
100 if ( CompareBackInfo(backInfoA,tmpbackInfo)==false )
102 GetBackInfo(backInfoA,bbGetInputTransform()->GetMatrix(),bbGetInputOrigin() );
104 //slicer =vtkImageReslice::New();
105 //EED 2017-01-01 Migration VTK7
106 #if VTK_MAJOR_VERSION <= 5
107 slicer->SetInput( image->GetOutput() );
109 slicer->SetInputData( image->GetOutput() );
111 slicer->SetInformationInput( image->GetOutput() );
112 slicer->SetResliceTransform(bbGetInputTransform());
113 slicer->SetOutputOrigin( -(bbGetInputOrigin()[0]) , -(bbGetInputOrigin()[1]) , -(bbGetInputOrigin()[2]) );
115 if(bbGetInputInterpolate())
117 slicer->InterpolateOn();
121 //imageResult = vtkImageChangeInformation::New();
122 //EED 2017-01-01 Migration VTK7
123 #if VTK_MAJOR_VERSION <= 5
124 imageResult->SetInput( slicer->GetOutput() );
126 imageResult->SetInputData( slicer->GetOutput() );
129 bbGetInputIn()->GetSpacing(spc);
130 imageResult->SetOutputSpacing( spc );
131 imageResult->SetOutputOrigin( 0,0,0 );
132 imageResult->Update();
133 bbSetOutputOut( imageResult->GetOutput() );
135 if (bbGetInputTransform()!=NULL)
137 bbGetInputTransform()->Update();
138 vtkMatrix4x4 *m = bbGetInputTransform()->GetMatrix();
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));
148 } // Compare BackInfo
150 bbSetOutputOut( NULL );
155 void ReSlicerBox::bbUserSetDefaultValues()
157 std::vector<int> empty;
158 bbSetInputOrigin(empty);
160 bbSetInputTransform(NULL);
161 bbSetOutputOut(NULL);
163 bbSetInputCentered(false);
164 bbSetInputInterpolate(false);
167 for (int i=0; i<sizeBackInfo; i++)
174 void ReSlicerBox::bbUserInitializeProcessing()
177 // THE INITIALIZATION METHOD BODY :
179 // but this is where you should allocate the internal/output pointers
181 image = vtkImageChangeInformation::New();
182 slicer = vtkImageReslice::New();
183 imageResult = vtkImageChangeInformation::New();
186 void ReSlicerBox::bbUserFinalizeProcessing()
190 imageResult -> Delete();
194 // EO namespace bbPackRecalage