]> Creatis software - creaMaracasVisu.git/blob - bbtk/src/bbcreaMaracasVisuSliceImage.cxx
2041 Feature box SliceImage of XY,YZ,XZ and FREE planes
[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           imageReslice->SetInput( bbGetInputIn() );
43           imageReslice->SetInformationInput(bbGetInputIn() );
44
45           double slice=bbGetInputSlice();
46           if (slice<0) 
47           { 
48                 slice=0;
49           } 
50         
51           if (bbGetInputTypeOrientation()==3)
52           {
53                 // Orientation 3 = FREE
54                 // v1 = [ v1x , v1y , v1z ]
55                 // v2 = [ v2x , v2y , v2z ]
56                 // v3 = [ v3x , v3y , v3z ]
57                 // SetResliceAxesDirectionCosines(v1x,v2x,v3x,v1y,v2y,v3y,v1z,v2z,v3z);
58                imageReslice->SetResliceAxesDirectionCosines( bbGetInputResliceAxesDirectionCosines()[0],  // v1x
59                                                              bbGetInputResliceAxesDirectionCosines()[3],  // v2x
60                                                              bbGetInputResliceAxesDirectionCosines()[6],  // v3x
61                                                              bbGetInputResliceAxesDirectionCosines()[1],  // v1y
62                                                              bbGetInputResliceAxesDirectionCosines()[4],  // v2y
63                                                              bbGetInputResliceAxesDirectionCosines()[7],  // v3y
64                                                              bbGetInputResliceAxesDirectionCosines()[2],  // v1z
65                                                              bbGetInputResliceAxesDirectionCosines()[5],  // v2z
66                                                              bbGetInputResliceAxesDirectionCosines()[8]   // v3z
67                                                            );  
68                imageReslice->SetResliceAxesOrigin( slice*bbGetInputIn()->GetSpacing()[0] ,0 ,0);
69           } else if (bbGetInputTypeOrientation()==2)
70           {
71                 // Orientation 2 = YZ
72                 // v1 = [ 0 , 0 ,-1 ]
73                 // v2 = [ 1 , 0 , 0 ]
74                 // v3 = [ 0 ,-1 , 0 ]
75                 // SetResliceAxesDirectionCosines(v1x,v2x,v3x,v1y,v2y,v3y,v1z,v2z,v3z);
76                imageReslice->SetResliceAxesDirectionCosines(0,1,0, 0,0,-1 ,-1,0,0);  
77                imageReslice->SetResliceAxesOrigin( slice*bbGetInputIn()->GetSpacing()[0] ,0 ,0);
78           } else if (bbGetInputTypeOrientation()==1) {     
79                 // Orientation 1 = XZ
80                 // v1 = [ 1 , 0 , 0 ]
81                 // v2 = [ 0 , 0 , 1 ]
82                 // v3 = [ 0 ,-1 , 0 ]
83                 // SetResliceAxesDirectionCosines(v1x,v2x,v3x,v1y,v2y,v3y,v1z,v2z,v3z);
84                imageReslice->SetResliceAxesDirectionCosines(1,0,0, 0,0,-1 ,0,1,0); 
85                imageReslice->SetResliceAxesOrigin(0, slice*bbGetInputIn()->GetSpacing()[1],0 );
86           } else    
87           {
88                 // Orientation 0 = XY
89                 // v1 = [ 1 , 0 , 0 ]
90                 // v2 = [ 0 , 1 , 0 ]
91                 // v3 = [ 0 , 0 , 1 ]
92                 // SetResliceAxesDirectionCosines(v1x,v2x,v3x,v1y,v2y,v3y,v1z,v2z,v3z);
93                imageReslice->SetResliceAxesDirectionCosines(1,0,0, 0,1,0 ,0,0,1);   
94                imageReslice->SetResliceAxesOrigin(0,0, slice*bbGetInputIn()->GetSpacing()[2] );
95           } 
96           imageReslice->SetOutputDimensionality(2);
97           imageReslice->SetInterpolationModeToLinear();
98           imagedata = imageReslice->GetOutput();
99           imagedata->Update();
100           imagedata->UpdateInformation();       
101         }
102   bbSetOutputOut( imagedata );
103 }
104         
105         
106         //-----------------------------------------------------------------     
107         void SliceImage::bbUserSetDefaultValues()
108         {
109                 bbSetInputIn(NULL);
110                 bbSetInputZ(0);
111                 bbSetInputSlice(0);
112                 bbSetInputTypeOrientation(0);
113                 imageReslice=NULL;
114                 std::vector<double> lstCos;
115                 lstCos.push_back(1); // v1x
116                 lstCos.push_back(0); // v1y
117                 lstCos.push_back(0); // v1z
118
119                 lstCos.push_back(0); // v2x
120                 lstCos.push_back(1); // v2y
121                 lstCos.push_back(0); // v2z
122
123                 lstCos.push_back(0); // v3x
124                 lstCos.push_back(0); // v3y
125                 lstCos.push_back(1); // v3z
126                 bbSetInputResliceAxesDirectionCosines(lstCos);
127         }
128         
129         //-----------------------------------------------------------------     
130         void SliceImage::bbUserInitializeProcessing()
131         {
132                 imageReslice = vtkImageReslice::New();
133         }
134         
135         //-----------------------------------------------------------------     
136         void SliceImage::bbUserFinalizeProcessing()
137         {
138         }
139         
140         //-----------------------------------------------------------------     
141         
142         
143 }
144 // EO namespace bbcreaMaracasVisu
145
146