]> Creatis software - bbtk.git/blob - packages/gdcmvtk/src/bbgdcmvtkGetInfoGdcmReader.cxx
Feature #1774
[bbtk.git] / packages / gdcmvtk / src / bbgdcmvtkGetInfoGdcmReader.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 "bbgdcmvtkGetInfoGdcmReader.h"
27 #include "bbgdcmvtkPackage.h"
28
29 #if defined USE_GDCM
30         #include "gdcmFile.h"
31         #include "gdcmFileHelper.h"
32         #include "vtkImageData.h"
33         #include "vtkGdcmReader.h"
34 #endif
35 #if defined USE_GDCM2
36         #include <gdcmReader.h>
37 //      #include "vtkImageData.h"       
38         #include <gdcmImageHelper.h>
39         #include <vtkGDCMImageReader.h>
40 #endif
41 #include <vtkIndent.h>
42
43 namespace bbgdcmvtk
44 {
45
46 BBTK_ADD_BLACK_BOX_TO_PACKAGE(gdcmvtk,GetInfoGdcmReader)
47 BBTK_BLACK_BOX_IMPLEMENTATION(GetInfoGdcmReader,bbtk::AtomicBlackBox);
48
49 #if defined USE_GDCM
50 void GetInfoGdcmReader::Process()
51 {
52         // Reset de reader, f
53         bbUserFinalizeProcessing();
54         
55    f = GDCM_NAME_SPACE::File::New();
56    f->SetFileName( bbGetInputIn() );
57    bool res = f->Load();  
58    if ( !res )
59    {
60       f->Delete();
61       bbSetOutputOut(0);
62       return;
63    }
64  // Get info from THE image file (only *one* as input)
65    int i;
66    std::vector<double> v_iop;
67    float iop[6];
68    f->GetImageOrientationPatient(iop);
69    
70    for(i=0; i< 6; i++)
71       v_iop.push_back(iop[i]);
72    bbSetOutputIOP(v_iop );
73  
74    std::vector<double> v_ipp;
75    float ipp[3];
76    f->GetImagePositionPatient(ipp);
77    
78    for(i=0; i< 3; i++)
79       v_ipp.push_back(ipp[i]);
80    bbSetOutputIPP(v_ipp );
81
82    std::vector<double> v_pixelspacing;
83    v_pixelspacing.push_back(f->GetXSpacing());
84    v_pixelspacing.push_back(f->GetYSpacing());
85    
86    if (f->GetZSize() != 1) 
87    {
88       v_pixelspacing.push_back(f->GetZSpacing());
89    }
90    bbSetOutputPixelSpacing(v_pixelspacing);
91    
92    //double interslice;
93     bbSetOutputInterSlice(f->GetZSpacing());
94    
95    reader = vtkGdcmReader::New();
96    reader->SetFileName( bbGetInputIn().c_str() );
97    reader->Update();
98    reader->GetOutput();
99
100    vtkIndent indent ;
101    reader->GetOutput()->PrintSelf(std::cout, indent);
102    bbSetOutputOut( reader->GetOutput() );
103 }
104 #endif
105
106 #if defined USE_GDCM2
107 void GetInfoGdcmReader::Process()
108 {
109         // Reset de reader, f
110         bbUserFinalizeProcessing();
111         gdcm::Reader *read = new gdcm::Reader();
112         read->SetFileName( bbGetInputIn().c_str());
113   
114         bool res = read->Read();  
115    if ( !res )
116    {
117       delete read;
118       bbSetOutputOut(0);
119       return;
120    }
121    
122  // Get info from THE image file (only *one* as input)
123    const gdcm::File &f = read->GetFile();
124    
125    // Image Orientation (Patient)
126    int i;
127    std::vector<double> v_iop;
128    const gdcm::DataElement &deIop = f.GetDataSet().GetDataElement(gdcm::Tag(0x0020, 0x0037));
129    std::stringstream ss;
130    deIop.GetValue().Print(ss);
131    gdcm::Element<gdcm::VR::DS,gdcm::VM::VM6> iop;
132    iop.Read( ss );
133    for(i=0; i< 6; i++)
134       v_iop.push_back((float)(iop[i]));
135    bbSetOutputIOP(v_iop );
136  
137    // Image Position (Patient)
138    std::vector<double> v_ipp;
139    const gdcm::DataElement &deIpp = f.GetDataSet().GetDataElement(gdcm::Tag((0x0020,0x0032)));
140    deIpp.GetValue().Print(ss);
141    gdcm::Element<gdcm::VR::DS,gdcm::VM::VM3> ipp;
142    ipp.Read( ss );
143           for(i=0; i< 3; i++)
144                 v_ipp.push_back((float)(ipp[i]));
145    bbSetOutputIPP(v_ipp );
146
147    std::vector<double> v_pixelspacing = gdcm::ImageHelper::GetSpacingValue(f);
148    bbSetOutputPixelSpacing(v_pixelspacing);
149    
150    //double interslice; ?? ==1 NO?
151     bbSetOutputInterSlice(v_pixelspacing[2]);
152    
153    reader = vtkGDCMImageReader::New();
154    reader->SetFileName( bbGetInputIn().c_str() );
155    reader->Update();
156    reader->GetOutput();
157    vtkIndent indent ;
158    reader->GetOutput()->PrintSelf(std::cout, indent);
159    bbSetOutputOut( reader->GetOutput() );
160 }
161 #endif
162
163
164 void GetInfoGdcmReader::bbUserSetDefaultValues()
165 {
166 #if defined USE_GDCM2
167    read=NULL;
168 #endif   
169 #if defined USE_GDCM
170    reader=NULL;
171    f=NULL;
172 #endif
173    bbSetInputIn("");  
174 }
175
176
177 void GetInfoGdcmReader::bbUserInitializeProcessing()
178 {
179 }
180
181
182 void GetInfoGdcmReader::bbUserFinalizeProcessing()
183 {
184 #if defined USE_GDCM2
185    if( reader )
186    {
187       reader->Delete();
188       reader=NULL;
189    }
190 #endif
191
192 #if defined USE_GDCM    
193    if( reader )
194    {
195       reader->Delete();
196       reader=NULL;
197    }   
198
199    if(f)
200    {
201       f->Delete();
202       f=NULL;
203    }    
204 #endif
205 }
206 }
207
208 // EO namespace bbgdcmvtk
209
210