1 /*# ---------------------------------------------------------------------
3 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
5 # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
6 # Previous Authors : Laurent Guigues, Jean-Pierre Roux
7 # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
9 # This software is governed by the CeCILL-B license under French law and
10 # abiding by the rules of distribution of free software. You can use,
11 # modify and/ or redistribute the software under the terms of the CeCILL-B
12 # license as circulated by CEA, CNRS and INRIA at the following URL
13 # http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
14 # or in the file LICENSE.txt.
16 # As a counterpart to the access to the source code and rights to copy,
17 # modify and redistribute granted by the license, users are provided only
18 # with a limited warranty and the software's author, the holder of the
19 # economic rights, and the successive licensors have only limited
22 # The fact that you are presently reading this means that you have had
23 # knowledge of the CeCILL-B license and that you accept its terms.
24 # ------------------------------------------------------------------------ */
26 #include "bbcreaMaracasVisuSliceImage.h"
27 #include "bbcreaMaracasVisuPackage.h"
28 namespace bbcreaMaracasVisu
31 BBTK_ADD_BLACK_BOX_TO_PACKAGE(creaMaracasVisu,SliceImage)
32 BBTK_BLACK_BOX_IMPLEMENTATION(SliceImage,bbtk::AtomicBlackBox);
34 void SliceImage::Process()
36 vtkImageData *imagedata=NULL;
38 //std::cout<<"MSJ: test SliceImage::Process()"<<this<<std::endl;
39 if ( bbGetInputIn()!=NULL )
42 //EED 2017-01-01 Migration VTK7
43 #if VTK_MAJOR_VERSION <= 5
44 imageReslice->SetInput( bbGetInputIn() );
46 imageReslice->SetInputData( bbGetInputIn() );
49 imageReslice->SetInformationInput(bbGetInputIn() );
51 double slice=bbGetInputSlice();
57 if (bbGetInputTypeOrientation()==3)
59 // Orientation 3 = FREE
60 // v1 = [ v1x , v1y , v1z ]
61 // v2 = [ v2x , v2y , v2z ]
62 // v3 = [ v3x , v3y , v3z ]
63 // SetResliceAxesDirectionCosines(v1x,v2x,v3x,v1y,v2y,v3y,v1z,v2z,v3z);
64 imageReslice->SetResliceAxesDirectionCosines( bbGetInputResliceAxesDirectionCosines()[0], // v1x
65 bbGetInputResliceAxesDirectionCosines()[3], // v2x
66 bbGetInputResliceAxesDirectionCosines()[6], // v3x
67 bbGetInputResliceAxesDirectionCosines()[1], // v1y
68 bbGetInputResliceAxesDirectionCosines()[4], // v2y
69 bbGetInputResliceAxesDirectionCosines()[7], // v3y
70 bbGetInputResliceAxesDirectionCosines()[2], // v1z
71 bbGetInputResliceAxesDirectionCosines()[5], // v2z
72 bbGetInputResliceAxesDirectionCosines()[8] // v3z
74 std::vector<double> AxOr = bbGetInputAxisOrigin();
76 bbGetInputIn()->GetSpacing(spc);
79 imageReslice->SetResliceAxesOrigin( AxOr[0]*spc[0] , AxOr[1]*spc[1] , AxOr[2]*spc[2] );
81 imageReslice->SetResliceAxesOrigin( slice*bbGetInputIn()->GetSpacing()[0] ,0 ,0);
83 } else if (bbGetInputTypeOrientation()==2)
85 // Orientation 2 = Y-Z
89 // SetResliceAxesDirectionCosines(v1x,v2x,v3x,v1y,v2y,v3y,v1z,v2z,v3z);
90 imageReslice->SetResliceAxesDirectionCosines( 0,1,0, 0,0,-1, -1,0,0 );
91 } else if (bbGetInputTypeOrientation()==-2)
93 // Orientation -2 = ZY
97 // SetResliceAxesDirectionCosines(v1x,v2x,v3x,v1y,v2y,v3y,v1z,v2z,v3z);
98 imageReslice->SetResliceAxesDirectionCosines( 0,0,1, 0,1,0, -1,0,0 );
99 imageReslice->SetResliceAxesOrigin( slice*bbGetInputIn()->GetSpacing()[0] ,0 ,0);
100 } else if (bbGetInputTypeOrientation()==1) {
101 // Orientation 1 = X-Z
102 // v1 = [ 1 , 0 , 0 ]
103 // v2 = [ 0 , 0 , -1 ]
105 // SetResliceAxesDirectionCosines(v1x,v2x,v3x,v1y,v2y,v3y,v1z,v2z,v3z);
106 imageReslice->SetResliceAxesDirectionCosines( 1,0,0, 0,0,-1, 0,1,0 );
107 imageReslice->SetResliceAxesOrigin(0, slice*bbGetInputIn()->GetSpacing()[1],0 );
108 } else if (bbGetInputTypeOrientation()==-1) {
109 // Orientation -1 = XZ
110 // v1 = [ 1 , 0 , 0 ]
111 // v2 = [ 0 , 0 , 1 ]
112 // v3 = [ 0 ,-1 , 0 ]
113 // SetResliceAxesDirectionCosines(v1x,v2x,v3x,v1y,v2y,v3y,v1z,v2z,v3z);
114 imageReslice->SetResliceAxesDirectionCosines( 1,0,0, 0,0,1, 0,-1,0 );
115 imageReslice->SetResliceAxesOrigin(0, slice*bbGetInputIn()->GetSpacing()[1],0 );
117 // Orientation 0 = XY
118 // v1 = [ 1 , 0 , 0 ]
119 // v2 = [ 0 , 1 , 0 ]
120 // v3 = [ 0 , 0 , 1 ]
121 // SetResliceAxesDirectionCosines(v1x,v2x,v3x,v1y,v2y,v3y,v1z,v2z,v3z);
122 imageReslice->SetResliceAxesDirectionCosines(1,0,0, 0,1,0 ,0,0,1);
123 imageReslice->SetResliceAxesOrigin(0,0, slice*bbGetInputIn()->GetSpacing()[2] );
125 imageReslice->SetOutputDimensionality(2);
127 if ( bbGetInputInterpolationMode()==0) { imageReslice->SetInterpolationModeToNearestNeighbor(); }
128 if ( bbGetInputInterpolationMode()==1) { imageReslice->SetInterpolationModeToLinear(); }
129 if ( bbGetInputInterpolationMode()==2) { imageReslice->SetInterpolationModeToCubic(); }
131 //EED 2017-01-01 Migration VTK7
132 #if VTK_MAJOR_VERSION <= 5
133 imagedata = imageReslice->GetOutput();
135 imagedata->UpdateInformation();
137 imageReslice->Update();
138 imagedata = imageReslice->GetOutput();
142 bbSetOutputOut( imagedata );
146 //-----------------------------------------------------------------
147 void SliceImage::bbUserSetDefaultValues()
152 bbSetInputInterpolationMode(0); // Linear
153 bbSetInputTypeOrientation(0);
155 std::vector<double> lstCos;
156 lstCos.push_back(1); // v1x
157 lstCos.push_back(0); // v1y
158 lstCos.push_back(0); // v1z
160 lstCos.push_back(0); // v2x
161 lstCos.push_back(1); // v2y
162 lstCos.push_back(0); // v2z
164 lstCos.push_back(0); // v3x
165 lstCos.push_back(0); // v3y
166 lstCos.push_back(1); // v3z
167 bbSetInputResliceAxesDirectionCosines(lstCos);
170 //-----------------------------------------------------------------
171 void SliceImage::bbUserInitializeProcessing()
173 imageReslice = vtkImageReslice::New();
176 //-----------------------------------------------------------------
177 void SliceImage::bbUserFinalizeProcessing()
181 //-----------------------------------------------------------------
185 // EO namespace bbcreaMaracasVisu