]> Creatis software - creaMaracasVisu.git/blob - bbtk/src/bbcreaMaracasVisuSliceImage.cxx
d5bd08cdd35d11ea16f4229371e5a7222debe955
[creaMaracasVisu.git] / bbtk / src / bbcreaMaracasVisuSliceImage.cxx
1 /*# ---------------------------------------------------------------------
2 #
3 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
4 #                        pour la Sant�)
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
8 #
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.
15 #
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
20 #  liability.
21 #
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 # ------------------------------------------------------------------------ */
25
26 #include "bbcreaMaracasVisuSliceImage.h"
27 #include "bbcreaMaracasVisuPackage.h"
28 namespace bbcreaMaracasVisu
29 {
30
31 BBTK_ADD_BLACK_BOX_TO_PACKAGE(creaMaracasVisu,SliceImage)
32 BBTK_BLACK_BOX_IMPLEMENTATION(SliceImage,bbtk::AtomicBlackBox);
33
34 void SliceImage::Process()
35 {
36         vtkImageData *imagedata=NULL;
37
38         //std::cout<<"MSJ: test SliceImage::Process()"<<this<<std::endl;
39         if ( bbGetInputIn()!=NULL )
40         {
41
42 //EED 2017-01-01 Migration VTK7
43 #if VTK_MAJOR_VERSION <= 5
44                 imageReslice->SetInput( bbGetInputIn() );
45 #else
46                 imageReslice->SetInputData( bbGetInputIn() );
47 #endif
48
49                 imageReslice->SetInformationInput(bbGetInputIn() );
50
51                 double slice=bbGetInputSlice();
52                 if (slice<0) 
53         { 
54                         slice=0;
55         } 
56
57                 if (bbGetInputTypeOrientation()==3)
58                 {
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
73                                                            );  
74            std::vector<double> AxOr = bbGetInputAxisOrigin();
75            double spc[3];
76            bbGetInputIn()->GetSpacing(spc);
77                    if (AxOr.size()==3)
78                    {
79                        imageReslice->SetResliceAxesOrigin( AxOr[0]*spc[0]  ,   AxOr[1]*spc[1]  ,  AxOr[2]*spc[2]  );
80               } else {
81                        imageReslice->SetResliceAxesOrigin( slice*bbGetInputIn()->GetSpacing()[0] ,0 ,0);                
82               }
83           } else if (bbGetInputTypeOrientation()==2)
84           {
85                 // Orientation 2 = Y-Z
86                 // v1 = [ 0 , 1 ,0 ]
87                 // v2 = [ 0 , 0 ,-1 ]
88                 // v3 = [ -1 ,0 , 0 ]
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)
92           {
93                 // Orientation -2 = ZY
94                 // v1 = [ 0 , 0 , 1 ]
95                 // v2 = [ 0 , 1 , 0 ]
96                 // v3 = [ -1, 0 , 0 ]
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 ]
104                 // v3 = [ 0 ,1 , 0 ]
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 );
116           } else    {
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] );
124           } 
125           imageReslice->SetOutputDimensionality(2);
126
127                 if ( bbGetInputInterpolationMode()==0) { imageReslice->SetInterpolationModeToNearestNeighbor(); }
128                 if ( bbGetInputInterpolationMode()==1) { imageReslice->SetInterpolationModeToLinear();                  }
129                 if ( bbGetInputInterpolationMode()==2) { imageReslice->SetInterpolationModeToCubic();                   }
130                         
131 //EED 2017-01-01 Migration VTK7
132 #if VTK_MAJOR_VERSION <= 5
133           imagedata = imageReslice->GetOutput();
134           imagedata->Update();
135           imagedata->UpdateInformation();       
136 #else
137           imageReslice->Update();
138           imagedata = imageReslice->GetOutput();
139 #endif
140
141         }
142   bbSetOutputOut( imagedata );
143 }
144         
145         
146         //-----------------------------------------------------------------     
147         void SliceImage::bbUserSetDefaultValues()
148         {
149                 bbSetInputIn(NULL);
150                 bbSetInputZ(0);
151                 bbSetInputSlice(0);
152                 bbSetInputInterpolationMode(0);  // Linear
153                 bbSetInputTypeOrientation(0);
154                 imageReslice=NULL;
155                 std::vector<double> lstCos;
156                 lstCos.push_back(1); // v1x
157                 lstCos.push_back(0); // v1y
158                 lstCos.push_back(0); // v1z
159
160                 lstCos.push_back(0); // v2x
161                 lstCos.push_back(1); // v2y
162                 lstCos.push_back(0); // v2z
163
164                 lstCos.push_back(0); // v3x
165                 lstCos.push_back(0); // v3y
166                 lstCos.push_back(1); // v3z
167                 bbSetInputResliceAxesDirectionCosines(lstCos);
168         }
169         
170         //-----------------------------------------------------------------     
171         void SliceImage::bbUserInitializeProcessing()
172         {
173                 imageReslice = vtkImageReslice::New();
174         }
175         
176         //-----------------------------------------------------------------     
177         void SliceImage::bbUserFinalizeProcessing()
178         {
179         }
180         
181         //-----------------------------------------------------------------     
182         
183         
184 }
185 // EO namespace bbcreaMaracasVisu
186
187