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
33 BBTK_ADD_BLACK_BOX_TO_PACKAGE(creaMaracasVisu,SliceImage)
34 BBTK_BLACK_BOX_IMPLEMENTATION(SliceImage,bbtk::AtomicBlackBox);
36 void SliceImage::Process()
38 vtkImageData *imagedata=NULL;
40 //std::cout<<"MSJ: test SliceImage::Process()"<<this<<std::endl;
41 if ( bbGetInputIn()!=NULL )
44 //EED 2017-01-01 Migration VTK7
45 #if VTK_MAJOR_VERSION <= 5
46 imageReslice->SetInput( bbGetInputIn() );
48 imageReslice->SetInputData( bbGetInputIn() );
51 imageReslice->SetInformationInput(bbGetInputIn() );
53 double slice=bbGetInputSlice();
59 if (bbGetInputTypeOrientation()==3)
61 // Orientation 3 = FREE
62 // v1 = [ v1x , v1y , v1z ]
63 // v2 = [ v2x , v2y , v2z ]
64 // v3 = [ v3x , v3y , v3z ]
65 // SetResliceAxesDirectionCosines(v1x,v2x,v3x,v1y,v2y,v3y,v1z,v2z,v3z);
66 imageReslice->SetResliceAxesDirectionCosines( bbGetInputResliceAxesDirectionCosines()[0], // v1x
67 bbGetInputResliceAxesDirectionCosines()[3], // v2x
68 bbGetInputResliceAxesDirectionCosines()[6], // v3x
69 bbGetInputResliceAxesDirectionCosines()[1], // v1y
70 bbGetInputResliceAxesDirectionCosines()[4], // v2y
71 bbGetInputResliceAxesDirectionCosines()[7], // v3y
72 bbGetInputResliceAxesDirectionCosines()[2], // v1z
73 bbGetInputResliceAxesDirectionCosines()[5], // v2z
74 bbGetInputResliceAxesDirectionCosines()[8] // v3z
76 imageReslice->SetResliceAxesOrigin( slice*bbGetInputIn()->GetSpacing()[0] ,0 ,0);
77 } else if (bbGetInputTypeOrientation()==2)
79 // Orientation 2 = Y-Z
83 // SetResliceAxesDirectionCosines(v1x,v2x,v3x,v1y,v2y,v3y,v1z,v2z,v3z);
84 imageReslice->SetResliceAxesDirectionCosines( 0,1,0, 0,0,-1, -1,0,0 );
85 imageReslice->SetResliceAxesOrigin( slice*bbGetInputIn()->GetSpacing()[0] ,0 ,0);
86 } else if (bbGetInputTypeOrientation()==-2)
88 // Orientation -2 = ZY
92 // SetResliceAxesDirectionCosines(v1x,v2x,v3x,v1y,v2y,v3y,v1z,v2z,v3z);
93 imageReslice->SetResliceAxesDirectionCosines( 0,0,1, 0,1,0, -1,0,0 );
94 imageReslice->SetResliceAxesOrigin( slice*bbGetInputIn()->GetSpacing()[0] ,0 ,0);
95 } else if (bbGetInputTypeOrientation()==1) {
96 // Orientation 1 = X-Z
98 // v2 = [ 0 , 0 , -1 ]
100 // SetResliceAxesDirectionCosines(v1x,v2x,v3x,v1y,v2y,v3y,v1z,v2z,v3z);
101 imageReslice->SetResliceAxesDirectionCosines( 1,0,0, 0,0,-1, 0,1,0 );
102 imageReslice->SetResliceAxesOrigin(0, slice*bbGetInputIn()->GetSpacing()[1],0 );
103 } else if (bbGetInputTypeOrientation()==-1) {
104 // Orientation -1 = XZ
105 // v1 = [ 1 , 0 , 0 ]
106 // v2 = [ 0 , 0 , 1 ]
107 // v3 = [ 0 ,-1 , 0 ]
108 // SetResliceAxesDirectionCosines(v1x,v2x,v3x,v1y,v2y,v3y,v1z,v2z,v3z);
109 imageReslice->SetResliceAxesDirectionCosines( 1,0,0, 0,0,1, 0,-1,0 );
110 imageReslice->SetResliceAxesOrigin(0, slice*bbGetInputIn()->GetSpacing()[1],0 );
112 // Orientation 0 = XY
113 // v1 = [ 1 , 0 , 0 ]
114 // v2 = [ 0 , 1 , 0 ]
115 // v3 = [ 0 , 0 , 1 ]
116 // SetResliceAxesDirectionCosines(v1x,v2x,v3x,v1y,v2y,v3y,v1z,v2z,v3z);
117 imageReslice->SetResliceAxesDirectionCosines(1,0,0, 0,1,0 ,0,0,1);
118 imageReslice->SetResliceAxesOrigin(0,0, slice*bbGetInputIn()->GetSpacing()[2] );
120 imageReslice->SetOutputDimensionality(2);
122 if ( bbGetInputInterpolationMode()==0) { imageReslice->SetInterpolationModeToNearestNeighbor(); }
123 if ( bbGetInputInterpolationMode()==1) { imageReslice->SetInterpolationModeToLinear(); }
124 if ( bbGetInputInterpolationMode()==2) { imageReslice->SetInterpolationModeToCubic(); }
126 //EED 2017-01-01 Migration VTK7
127 #if VTK_MAJOR_VERSION <= 5
128 imagedata = imageReslice->GetOutput();
130 imagedata->UpdateInformation();
132 imageReslice->Update();
133 imagedata = imageReslice->GetOutput();
137 bbSetOutputOut( imagedata );
141 //-----------------------------------------------------------------
142 void SliceImage::bbUserSetDefaultValues()
147 bbSetInputInterpolationMode(0); // Linear
148 bbSetInputTypeOrientation(0);
150 std::vector<double> lstCos;
151 lstCos.push_back(1); // v1x
152 lstCos.push_back(0); // v1y
153 lstCos.push_back(0); // v1z
155 lstCos.push_back(0); // v2x
156 lstCos.push_back(1); // v2y
157 lstCos.push_back(0); // v2z
159 lstCos.push_back(0); // v3x
160 lstCos.push_back(0); // v3y
161 lstCos.push_back(1); // v3z
162 bbSetInputResliceAxesDirectionCosines(lstCos);
165 //-----------------------------------------------------------------
166 void SliceImage::bbUserInitializeProcessing()
168 imageReslice = vtkImageReslice::New();
171 //-----------------------------------------------------------------
172 void SliceImage::bbUserFinalizeProcessing()
176 //-----------------------------------------------------------------
180 // EO namespace bbcreaMaracasVisu