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 image->SetInput( bbGetInputIn() );
85 image->SetOutputSpacing( 1,1,1 );
87 if(bbGetInputCentered())
89 image->CenterImageOn();
92 double tmpbackInfo[19];
93 GetBackInfo(tmpbackInfo,bbGetInputTransform()->GetMatrix(),bbGetInputOrigin() );
95 if ( CompareBackInfo(backInfoA,tmpbackInfo)==false )
97 GetBackInfo(backInfoA,bbGetInputTransform()->GetMatrix(),bbGetInputOrigin() );
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]) );
105 if(bbGetInputInterpolate())
107 slicer->InterpolateOn();
111 //imageResult = vtkImageChangeInformation::New();
112 imageResult->SetInput( slicer->GetOutput() );
114 bbGetInputIn()->GetSpacing(spc);
115 imageResult->SetOutputSpacing( spc );
116 imageResult->SetOutputOrigin( 0,0,0 );
118 bbSetOutputOut( imageResult->GetOutput() );
120 if (bbGetInputTransform()!=NULL)
122 bbGetInputTransform()->Update();
123 vtkMatrix4x4 *m = bbGetInputTransform()->GetMatrix();
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));
133 } // Compare BackInfo
135 bbSetOutputOut( NULL );
140 void ReSlicerBox::bbUserSetDefaultValues()
142 std::vector<int> empty;
143 bbSetInputOrigin(empty);
145 bbSetInputTransform(NULL);
146 bbSetOutputOut(NULL);
148 bbSetInputCentered(false);
149 bbSetInputInterpolate(false);
152 for (int i=0; i<sizeBackInfo; i++)
159 void ReSlicerBox::bbUserInitializeProcessing()
162 // THE INITIALIZATION METHOD BODY :
164 // but this is where you should allocate the internal/output pointers
166 image = vtkImageChangeInformation::New();
167 slicer =vtkImageReslice::New();
168 imageResult = vtkImageChangeInformation::New();
171 void ReSlicerBox::bbUserFinalizeProcessing()
175 imageResult->Delete();
179 // EO namespace bbPackRecalage