]> Creatis software - creaMaracasVisu.git/blob - bbtk/src/bbcreaMaracasVisuSliceImage.cxx
#3109 creaMaracasVisu Bug New Normal - branch vtk7itk4 compilation with vtk7
[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         
32         
33 BBTK_ADD_BLACK_BOX_TO_PACKAGE(creaMaracasVisu,SliceImage)
34 BBTK_BLACK_BOX_IMPLEMENTATION(SliceImage,bbtk::AtomicBlackBox);
35 void SliceImage::Process()
36 {
37         vtkImageData *imagedata=NULL;
38
39         //std::cout<<"MSJ: test SliceImage::Process()"<<this<<std::endl;
40         if ( bbGetInputIn()!=NULL )
41         {
42
43 //EED 2017-01-01 Migration VTK7
44 #if VTK_MAJOR_VERSION <= 5
45           imageReslice->SetInput( bbGetInputIn() );
46 #else
47           imageReslice->SetInputData( bbGetInputIn() );
48 #endif
49
50           imageReslice->SetInformationInput(bbGetInputIn() );
51
52           double slice=bbGetInputSlice();
53           if (slice<0) 
54           { 
55                 slice=0;
56           } 
57         
58           if (bbGetInputTypeOrientation()==3)
59           {
60                 // Orientation 3 = FREE
61                 // v1 = [ v1x , v1y , v1z ]
62                 // v2 = [ v2x , v2y , v2z ]
63                 // v3 = [ v3x , v3y , v3z ]
64                 // SetResliceAxesDirectionCosines(v1x,v2x,v3x,v1y,v2y,v3y,v1z,v2z,v3z);
65                imageReslice->SetResliceAxesDirectionCosines( bbGetInputResliceAxesDirectionCosines()[0],  // v1x
66                                                              bbGetInputResliceAxesDirectionCosines()[3],  // v2x
67                                                              bbGetInputResliceAxesDirectionCosines()[6],  // v3x
68                                                              bbGetInputResliceAxesDirectionCosines()[1],  // v1y
69                                                              bbGetInputResliceAxesDirectionCosines()[4],  // v2y
70                                                              bbGetInputResliceAxesDirectionCosines()[7],  // v3y
71                                                              bbGetInputResliceAxesDirectionCosines()[2],  // v1z
72                                                              bbGetInputResliceAxesDirectionCosines()[5],  // v2z
73                                                              bbGetInputResliceAxesDirectionCosines()[8]   // v3z
74                                                            );  
75                imageReslice->SetResliceAxesOrigin( slice*bbGetInputIn()->GetSpacing()[0] ,0 ,0);
76           } else if (bbGetInputTypeOrientation()==2)
77           {
78                 // Orientation 2 = YZ
79                 // v1 = [ 0 , 0 ,-1 ]
80                 // v2 = [ 1 , 0 , 0 ]
81                 // v3 = [ 0 ,-1 , 0 ]
82                 // SetResliceAxesDirectionCosines(v1x,v2x,v3x,v1y,v2y,v3y,v1z,v2z,v3z);
83                imageReslice->SetResliceAxesDirectionCosines(0,1,0, 0,0,-1 ,-1,0,0);  
84                imageReslice->SetResliceAxesOrigin( slice*bbGetInputIn()->GetSpacing()[0] ,0 ,0);
85           } else if (bbGetInputTypeOrientation()==1) {     
86                 // Orientation 1 = XZ
87                 // v1 = [ 1 , 0 , 0 ]
88                 // v2 = [ 0 , 0 , 1 ]
89                 // v3 = [ 0 ,-1 , 0 ]
90                 // SetResliceAxesDirectionCosines(v1x,v2x,v3x,v1y,v2y,v3y,v1z,v2z,v3z);
91                imageReslice->SetResliceAxesDirectionCosines(1,0,0, 0,0,-1 ,0,1,0); 
92                imageReslice->SetResliceAxesOrigin(0, slice*bbGetInputIn()->GetSpacing()[1],0 );
93           } else    
94           {
95                 // Orientation 0 = XY
96                 // v1 = [ 1 , 0 , 0 ]
97                 // v2 = [ 0 , 1 , 0 ]
98                 // v3 = [ 0 , 0 , 1 ]
99                 // SetResliceAxesDirectionCosines(v1x,v2x,v3x,v1y,v2y,v3y,v1z,v2z,v3z);
100                imageReslice->SetResliceAxesDirectionCosines(1,0,0, 0,1,0 ,0,0,1);   
101                imageReslice->SetResliceAxesOrigin(0,0, slice*bbGetInputIn()->GetSpacing()[2] );
102           } 
103           imageReslice->SetOutputDimensionality(2);
104           imageReslice->SetInterpolationModeToLinear();
105
106
107 //EED 2017-01-01 Migration VTK7
108 #if VTK_MAJOR_VERSION <= 5
109           imagedata = imageReslice->GetOutput();
110           imagedata->Update();
111           imagedata->UpdateInformation();       
112 #else
113           imageReslice->Update();
114           imagedata = imageReslice->GetOutput();
115 #endif
116
117         }
118   bbSetOutputOut( imagedata );
119 }
120         
121         
122         //-----------------------------------------------------------------     
123         void SliceImage::bbUserSetDefaultValues()
124         {
125                 bbSetInputIn(NULL);
126                 bbSetInputZ(0);
127                 bbSetInputSlice(0);
128                 bbSetInputTypeOrientation(0);
129                 imageReslice=NULL;
130                 std::vector<double> lstCos;
131                 lstCos.push_back(1); // v1x
132                 lstCos.push_back(0); // v1y
133                 lstCos.push_back(0); // v1z
134
135                 lstCos.push_back(0); // v2x
136                 lstCos.push_back(1); // v2y
137                 lstCos.push_back(0); // v2z
138
139                 lstCos.push_back(0); // v3x
140                 lstCos.push_back(0); // v3y
141                 lstCos.push_back(1); // v3z
142                 bbSetInputResliceAxesDirectionCosines(lstCos);
143         }
144         
145         //-----------------------------------------------------------------     
146         void SliceImage::bbUserInitializeProcessing()
147         {
148                 imageReslice = vtkImageReslice::New();
149         }
150         
151         //-----------------------------------------------------------------     
152         void SliceImage::bbUserFinalizeProcessing()
153         {
154         }
155         
156         //-----------------------------------------------------------------     
157         
158         
159 }
160 // EO namespace bbcreaMaracasVisu
161
162