1 /*=========================================================================
4 Module: $RCSfile: exXCoherentFileSet.cxx,v $
6 Date: $Date: 2006/01/26 15:52:43 $
7 Version: $Revision: 1.7 $
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 } ",
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 " noshadowseq: user doesn't want to load Private Sequences ",
44 " noshadow : user doesn't want to load Private groups (odd number) ",
45 " noseq : user doesn't want to load Sequences ",
46 " debug : user wants to run the program in 'debug mode' ",
49 // ----- Initialize Arguments Manager ------
51 gdcm::ArgMgr *am = new gdcm::ArgMgr(argc, argv);
53 if (am->ArgMgrDefined("usage") || argc == 1)
55 am->ArgMgrUsage(usage); // Display 'usage'
60 if (am->ArgMgrDefined("debug"))
61 gdcm::Debug::DebugOn();
63 int loadMode = gdcm::LD_ALL;
64 if ( am->ArgMgrDefined("noshadowseq") )
65 loadMode |= gdcm::LD_NOSHADOWSEQ;
68 if ( am->ArgMgrDefined("noshadow") )
69 loadMode |= gdcm::LD_NOSHADOW;
70 if ( am->ArgMgrDefined("noseq") )
71 loadMode |= gdcm::LD_NOSEQ;
74 const char *dirName = am->ArgMgrGetString("dirin");
78 << "'dirin=' must be present;"
80 am->ArgMgrUsage(usage); // Display 'usage'
85 // FIXME : check only one of them is set !
87 int pos = am->ArgMgrDefined("pos");
88 int ori = am->ArgMgrDefined("ori");
92 groupelem = am->ArgMgrGetXInt16Enum("tag", &nb);
98 std::cout << "TAG : one and only one group,elem!" << std::endl;
105 /* if unused Param we give up */
106 if ( am->ArgMgrPrintUnusedLabels() )
108 am->ArgMgrUsage(usage);
113 delete am; // ------ we don't need Arguments Manager any longer ------
116 gdcm::SerieHelper *s;
118 s = gdcm::SerieHelper::New();
119 s->SetLoadMode(gdcm::LD_ALL); // Load everything for each File
120 //gdcm::TagKey t(0x0020,0x0013);
121 //s->AddRestriction(t, "340", gdcm::GDCM_LESS); // Keep only files where
122 // restriction is true
123 s->SetDirectory(dirName, true); // true : recursive exploration
126 std::cout << " ---------------------------------------- "
127 << "'Single UID' Filesets found in :["
128 << dirName << "]" << std::endl;
131 std::cout << " ------------------------------------- Result after splitting"
135 std::string fileName;
136 // For all the Single SerieUID Files Sets of the gdcm::Serie
137 gdcm::FileList *l = s->GetFirstSingleSerieUIDFileSet();
139 gdcm::XCoherentFileSetmap xcm;
142 nbFiles = l->size() ;
143 if ( l->size() > 3 ) // Why not ? Just an example, for testing
145 std::cout << "Split the 'Single SerieUID' FileSet :["
146 << s->GetCurrentSerieUIDFileSetUID()
147 << "] " << nbFiles << " long" << std::endl;
148 std::cout << "-----------------------------------" << std::endl;
151 xcm = s->SplitOnOrientation(l);
153 xcm = s->SplitOnPosition(l);
155 xcm = s->SplitOnTagValue(l, groupelem[0],groupelem[1] );
157 for (gdcm::XCoherentFileSetmap::iterator i = xcm.begin();
162 std::cout << "Orientation : ";
164 std::cout << "Position : ";
166 std::cout << "Tag (" << std::hex << groupelem[0]
167 << "|" << groupelem[1] << ") value : ";
169 std::cout << "[" << (*i).first << "]" << std::endl;
171 // Nowadays OrderFileList() causes trouble, since some files
172 // (MIP views) don't have 'Position', now considered as mandatory
173 // Commented out for the moment.
175 //s->OrderFileList((*i).second); // sort the XCoherent Fileset
177 for (std::vector<gdcm::File* >::iterator it = ((*i).second)->begin();
178 it != ((*i).second)->end();
181 fileName = (*it)->GetFileName();
182 std::cout << " " << fileName << std::endl;
184 std::cout << std::endl;
187 l = s->GetNextSingleSerieUIDFileSet();