1 /*=========================================================================
4 Module: $RCSfile: exXCoherentFileSet.cxx,v $
6 Date: $Date: 2007/06/15 13:18:51 $
7 Version: $Revision: 1.10 $
9 Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
10 l'Image). All rights reserved. See Doc/License.txt or
11 http://www.creatis.insa-lyon.fr/Public/Gdcm/License.html for details.
13 This software is distributed WITHOUT ANY WARRANTY; without even
14 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 PURPOSE. See the above copyright notices for more information.
17 =========================================================================*/
18 #include "gdcmSerieHelper.h"
20 #include "gdcmDebug.h"
23 #include "gdcmArgMgr.h"
25 int main(int argc, char *argv[])
29 "\n exXCoherentFileSet :\n ",
30 "Shows the various 'XCoherent' Filesets within a directory ",
31 "usage: exXCoherentFileSet {dirin=inputDirectoryName} ",
32 " { tag= group-elem | pos | ori } sort ",
33 " [ { [noshadowseq] | [noshadow][noseq] } ] [debug] ",
35 " inputDirectoryName : user wants to analyze *all* the files ",
36 " within the directory ",
37 " pos : user wants to split each Single SerieUID Fileset on the ",
38 " 'Image Position ' ",
39 " ori : user wants to split each Single SerieUID Fileset on the ",
40 " 'Image Orientation ' ",
41 " tag : group-elem (in hexa, no space) ",
42 " the user wants to split on ",
43 " sort : user wants FileHelper to sort the images ",
44 " Warning : will probabely crah if sort has no meaning ",
45 " noshadowseq: user doesn't want to load Private Sequences ",
46 " noshadow : user doesn't want to load Private groups (odd number) ",
47 " noseq : user doesn't want to load Sequences ",
48 " debug : user wants to run the program in 'debug mode' ",
51 // ----- Initialize Arguments Manager ------
53 GDCM_NAME_SPACE::ArgMgr *am = new GDCM_NAME_SPACE::ArgMgr(argc, argv);
55 if (am->ArgMgrDefined("usage") || argc == 1)
57 am->ArgMgrUsage(usage); // Display 'usage'
62 if (am->ArgMgrDefined("debug"))
63 GDCM_NAME_SPACE::Debug::DebugOn();
65 int loadMode = GDCM_NAME_SPACE::LD_ALL;
66 if ( am->ArgMgrDefined("noshadowseq") )
67 loadMode |= GDCM_NAME_SPACE::LD_NOSHADOWSEQ;
70 if ( am->ArgMgrDefined("noshadow") )
71 loadMode |= GDCM_NAME_SPACE::LD_NOSHADOW;
72 if ( am->ArgMgrDefined("noseq") )
73 loadMode |= GDCM_NAME_SPACE::LD_NOSEQ;
76 const char *dirName = am->ArgMgrGetString("dirin");
80 << "'dirin=' must be present;"
82 am->ArgMgrUsage(usage); // Display 'usage'
87 // FIXME : check only one of them is set !
89 int pos = am->ArgMgrDefined("pos");
90 int ori = am->ArgMgrDefined("ori");
91 int sort = am->ArgMgrDefined("sort");
95 groupelem = am->ArgMgrGetXInt16Enum("tag", &nb);
101 std::cout << "TAG : one and only one group,elem!" << std::endl;
108 /* if unused Param we give up */
109 if ( am->ArgMgrPrintUnusedLabels() )
111 am->ArgMgrUsage(usage);
116 delete am; // ------ we don't need Arguments Manager any longer ------
119 GDCM_NAME_SPACE::SerieHelper *s;
121 s = GDCM_NAME_SPACE::SerieHelper::New();
122 s->SetLoadMode(GDCM_NAME_SPACE::LD_ALL); // Load everything for each File
123 //GDCM_NAME_SPACE::TagKey t(0x0020,0x0013);
124 //s->AddRestriction(t, "340", GDCM_NAME_SPACE::GDCM_LESS); // Keep only files where
125 // restriction is true
126 s->SetDirectory(dirName, true); // true : recursive exploration
128 // The Dicom file set is splitted into several 'Single SerieUID Files Sets'
129 // (a 'Single SerieUID Files Set' per SerieUID)
130 // In some cases, it's not enough, since, in some cases
131 // we can find scout view with the same SerieUID
134 std::cout << " ---------------------------------------- "
135 << "'Single UID' Filesets found in :["
136 << dirName << "]" << std::endl;
139 std::cout << " ------------------------------------- Result after splitting"
143 std::string fileName;
144 // For all the Single SerieUID Files Sets of the GDCM_NAME_SPACE::Serie
145 GDCM_NAME_SPACE::FileList *l = s->GetFirstSingleSerieUIDFileSet();
147 GDCM_NAME_SPACE::XCoherentFileSetmap xcm;
148 while (l) // for each 'Single SerieUID FileSet'
150 nbFiles = l->size() ;
151 if ( l->size() > 3 ) // Why not ? Just an example, for testing
153 std::cout << "Split the 'Single SerieUID' FileSet :["
154 << s->GetCurrentSerieUIDFileSetUID()
155 << "] " << nbFiles << " long" << std::endl;
156 std::cout << "-----------------------------------" << std::endl;
159 xcm = s->SplitOnOrientation(l);
161 xcm = s->SplitOnPosition(l);
163 xcm = s->SplitOnTagValue(l, groupelem[0],groupelem[1] );
165 for (GDCM_NAME_SPACE::XCoherentFileSetmap::iterator i = xcm.begin();
170 std::cout << "Orientation : ";
172 std::cout << "Position : ";
174 std::cout << "Tag (" << std::hex << groupelem[0]
175 << "|" << groupelem[1] << ") value : ";
177 std::cout << "[" << (*i).first << "]" << std::endl;
179 // Within a 'just to see' program,
180 // OrderFileList() causes trouble, since some files
181 // (eg:MIP views) don't have 'Position', now considered as mandatory
182 // Commented out for the moment.
185 s->OrderFileList((*i).second); // sort the XCoherent Fileset
186 std::cout << "ZSpacing for the file set " << s->GetZSpacing()
190 for (GDCM_NAME_SPACE::FileList::iterator it = ((*i).second)->begin();
191 it != ((*i).second)->end();
194 fileName = (*it)->GetFileName();
195 std::cout << " " << fileName << std::endl;
197 std::cout << std::endl;
200 l = s->GetNextSingleSerieUIDFileSet();