]> Creatis software - clitk.git/blob - tools/clitkDicomInfo.cxx
Add option to display series and filename
[clitk.git] / tools / clitkDicomInfo.cxx
1 /*=========================================================================
2   Program:   vv                     http://www.creatis.insa-lyon.fr/rio/vv
3
4   Authors belong to:
5   - University of LYON              http://www.universite-lyon.fr/
6   - Léon Bérard cancer center       http://www.centreleonberard.fr
7   - CREATIS CNRS laboratory         http://www.creatis.insa-lyon.fr
8
9   This software is distributed WITHOUT ANY WARRANTY; without even
10   the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
11   PURPOSE.  See the copyright notices for more information.
12
13   It is distributed under dual licence
14
15   - BSD        See included LICENSE.txt file
16   - CeCILL-B   http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
17 ===========================================================================**/
18 /**
19    -------------------------------------------------
20    * @file   clitkDicomInfo.cxx
21    * @author Laurent ZAGNI <laurent.zagni@insa-lyon.fr>
22    * @date   27 Jul 2006
23    -------------------------------------------------*/
24
25 // clitk includes
26 #include "clitkDicomInfo_ggo.h"
27 #include "clitkCommon.h"
28
29 // itk (gdcm) include
30 #include "gdcmFile.h"
31 #if GDCM_MAJOR_VERSION == 2
32 #include "gdcmReader.h"
33 #include "gdcmPrinter.h"
34 #include "gdcmDict.h"
35 #include "gdcmStringFilter.h"
36 #endif
37
38 //--------------------------------------------------------------------
39 int main(int argc, char * argv[])
40 {
41
42   // init command line
43   GGO(clitkDicomInfo, args_info);
44
45   // check arg
46   if (args_info.inputs_num == 0) return 0;
47
48   // Study ID
49  #if GDCM_MAJOR_VERSION == 2
50  if (args_info.studyID_flag) {
51     std::set<std::string> l;
52     for(unsigned int i=0; i<args_info.inputs_num; i++) {
53       gdcm::Reader reader;
54       reader.SetFileName(args_info.inputs[i]);
55       std::set<gdcm::Tag> tags;
56       gdcm::Tag StudyInstanceUIDTag(0x0020, 0x000d);
57       gdcm::Tag SeriesDateTag(0x0008, 0x0021);
58       tags.insert(StudyInstanceUIDTag);
59       tags.insert(SeriesDateTag);
60       if (reader.ReadSelectedTags(tags)) {
61         gdcm::StringFilter sf;
62         sf.SetFile(reader.GetFile());
63         std::pair<std::string, std::string> p = sf.ToStringPair(StudyInstanceUIDTag);
64         std::pair<std::string, std::string> d = sf.ToStringPair(SeriesDateTag);
65         if (args_info.uniq_flag) {
66           if (l.insert(p.second).second == true) {
67             if (args_info.filename_flag)
68               std::cout << args_info.inputs[i] << " " << p.second << " " << d.second << std::endl;
69             else
70               std::cout << p.second << std::endl;
71           }
72         }
73         else {
74           if (args_info.filename_flag)
75             std::cout << args_info.inputs[i] << " " << p.second << " " << d.second << std::endl;
76           else
77             std::cout << p.second << std::endl;
78         }
79       } // tag not found
80     }
81   }
82 #endif
83
84   // Loop files
85  if (!args_info.studyID_flag)
86   for(unsigned int i=0; i<args_info.inputs_num; i++) {
87     if (args_info.filename_flag) std::cout << args_info.inputs[i] << std::endl;
88 #if GDCM_MAJOR_VERSION == 2
89     gdcm::Reader reader;
90     reader.SetFileName(args_info.inputs[i]);
91     reader.Read();
92     gdcm::Printer printer;
93     printer.SetFile(reader.GetFile());
94     printer.SetStyle(gdcm::Printer::VERBOSE_STYLE);
95     printer.Print( std::cout );
96 #else
97     gdcm::File *header = new gdcm::File();
98     header->SetFileName(args_info.inputs[i]);
99     header->SetMaxSizeLoadEntry(163840);
100     header->Load();
101     header->Print();
102 #endif
103   }
104
105   // this is the end my friend
106   return 0;
107 }
108 //--------------------------------------------------------------------