]> Creatis software - bbtk.git/blob - packages/gdcmvtk/src/bbgdcmvtkGetInfoGdcmReader.cxx
#3107 BBTK Bug New Normal - branch vtk7itk4 compilation with vtk7
[bbtk.git] / packages / gdcmvtk / src / bbgdcmvtkGetInfoGdcmReader.cxx
1 /*
2 # ---------------------------------------------------------------------
3 #
4 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
5 #                        pour la SantÈ)
6 # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
7 # Previous Authors : Laurent Guigues, Jean-Pierre Roux
8 # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
9 #
10 #  This software is governed by the CeCILL-B license under French law and
11 #  abiding by the rules of distribution of free software. You can  use,
12 #  modify and/ or redistribute the software under the terms of the CeCILL-B
13 #  license as circulated by CEA, CNRS and INRIA at the following URL
14 #  http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
15 #  or in the file LICENSE.txt.
16 #
17 #  As a counterpart to the access to the source code and  rights to copy,
18 #  modify and redistribute granted by the license, users are provided only
19 #  with a limited warranty  and the software's author,  the holder of the
20 #  economic rights,  and the successive licensors  have only  limited
21 #  liability.
22 #
23 #  The fact that you are presently reading this means that you have had
24 #  knowledge of the CeCILL-B license and that you accept its terms.
25 # ------------------------------------------------------------------------ */
26
27 #include "bbgdcmvtkGetInfoGdcmReader.h"
28 #include "bbgdcmvtkPackage.h"
29
30 #if defined USE_GDCM
31         #include "gdcmFile.h"
32         #include "gdcmFileHelper.h"
33         #include "vtkImageData.h"
34         #include "vtkGdcmReader.h"
35 #endif
36 #if defined USE_GDCM2
37         #include <gdcmReader.h>
38 //      #include "vtkImageData.h"       
39         #include <gdcmImageHelper.h>
40         #include <vtkGDCMImageReader.h>
41 #endif
42 #include <vtkIndent.h>
43
44 namespace bbgdcmvtk
45 {
46
47 BBTK_ADD_BLACK_BOX_TO_PACKAGE(gdcmvtk,GetInfoGdcmReader)
48 BBTK_BLACK_BOX_IMPLEMENTATION(GetInfoGdcmReader,bbtk::AtomicBlackBox);
49
50 #if defined USE_GDCM
51 void GetInfoGdcmReader::Process()
52 {
53         // Reset de reader, f
54         bbUserFinalizeProcessing();
55         
56    f = GDCM_NAME_SPACE::File::New();
57    f->SetFileName( bbGetInputIn() );
58    bool res = f->Load();  
59    if ( !res )
60    {
61       f->Delete();
62       bbSetOutputOut(0);
63       return;
64    }
65  // Get info from THE image file (only *one* as input)
66    int i;
67    std::vector<double> v_iop;
68    float iop[6];
69    f->GetImageOrientationPatient(iop);
70    
71    for(i=0; i< 6; i++)
72       v_iop.push_back(iop[i]);
73    bbSetOutputIOP(v_iop );
74  
75    std::vector<double> v_ipp;
76    float ipp[3];
77    f->GetImagePositionPatient(ipp);
78    
79    for(i=0; i< 3; i++)
80         {
81       v_ipp.push_back(ipp[i]);
82         } // for i
83    bbSetOutputIPP(v_ipp );
84
85    std::vector<double> v_pixelspacing;
86    v_pixelspacing.push_back(f->GetXSpacing());
87    v_pixelspacing.push_back(f->GetYSpacing());
88    
89    if (f->GetZSize() != 1) 
90    {
91       v_pixelspacing.push_back(f->GetZSpacing());
92    } // if size
93    bbSetOutputPixelSpacing(v_pixelspacing);
94    
95    //double interslice;
96     bbSetOutputInterSlice(f->GetZSpacing());
97    
98    reader = vtkGdcmReader::New();
99    reader->SetFileName( bbGetInputIn().c_str() );
100    reader->SetFlipY(true);
101    reader->Update();
102    reader->GetOutput();
103
104 //   vtkIndent indent ;
105 //   reader->GetOutput()->PrintSelf(std::cout, indent);
106    bbSetOutputOut( reader->GetOutput() );
107 }
108 #endif
109
110 #if defined USE_GDCM2
111 void GetInfoGdcmReader::Process()
112 {
113         // Reset de reader, f
114         bbUserFinalizeProcessing();
115         gdcm::Reader *read = new gdcm::Reader();
116         read->SetFileName( bbGetInputIn().c_str());
117   
118         bool res = read->Read();  
119    if ( !res )
120    {
121       delete read;
122       bbSetOutputOut(0);
123       return;
124    }
125    
126  // Get info from THE image file (only *one* as input)
127    const gdcm::File &f = read->GetFile();
128    
129    // Image Orientation (Patient)
130    int i;
131    std::vector<double> v_iop;
132    const gdcm::DataElement &deIop = f.GetDataSet().GetDataElement(gdcm::Tag(0x0020, 0x0037));
133    std::stringstream ss;
134    deIop.GetValue().Print(ss);
135    gdcm::Element<gdcm::VR::DS,gdcm::VM::VM6> iop;
136    iop.Read( ss );
137    for(i=0; i< 6; i++) 
138         {
139       v_iop.push_back((float)(iop[i]));
140         } // for i
141    bbSetOutputIOP(v_iop );
142  
143    // Image Position (Patient)
144    std::vector<double> v_ipp;
145    const gdcm::DataElement &deIpp = f.GetDataSet().GetDataElement(gdcm::Tag((0x0020,0x0032)));
146    deIpp.GetValue().Print(ss);
147    gdcm::Element<gdcm::VR::DS,gdcm::VM::VM3> ipp;
148    ipp.Read( ss );
149    for(i=0; i< 3; i++)
150         {
151                 v_ipp.push_back((float)(ipp[i]));
152         } // for
153    bbSetOutputIPP(v_ipp );
154
155    std::vector<double> v_pixelspacing = gdcm::ImageHelper::GetSpacingValue(f);
156    bbSetOutputPixelSpacing(v_pixelspacing);
157    
158    //double interslice; ?? ==1 NO?
159     bbSetOutputInterSlice(v_pixelspacing[2]);
160    
161    reader = vtkGDCMImageReader::New();
162    reader->SetFileName( bbGetInputIn().c_str() );
163    reader->Update();
164    reader->GetOutput();
165    vtkIndent indent ;
166    reader->GetOutput()->PrintSelf(std::cout, indent);
167    bbSetOutputOut( reader->GetOutput() );
168 }
169 #endif
170
171
172 void GetInfoGdcmReader::bbUserSetDefaultValues()
173 {
174 #if defined USE_GDCM2
175    reader=NULL;
176 #endif   
177 #if defined USE_GDCM
178    reader=NULL;
179    f=NULL;
180 #endif
181    bbSetInputIn("");  
182 }
183
184
185 void GetInfoGdcmReader::bbUserInitializeProcessing()
186 {
187 }
188
189
190 void GetInfoGdcmReader::bbUserFinalizeProcessing()
191 {
192 #if defined USE_GDCM2
193    if( reader )
194    {
195       reader->Delete();
196       reader=NULL;
197    }
198 #endif
199
200 #if defined USE_GDCM    
201    if( reader )
202    {
203       reader->Delete();
204       reader=NULL;
205    }   
206
207    if(f)
208    {
209       f->Delete();
210       f=NULL;
211    }    
212 #endif
213 }
214 }
215
216 // EO namespace bbgdcmvtk
217
218