1 /*=========================================================================
4 Module: $RCSfile: exXCoherentFileSet.cxx,v $
6 Date: $Date: 2005/11/02 10:08:18 $
7 Version: $Revision: 1.2 $
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 char *dirName = am->ArgMgrGetString("dirin",(char *)0);
78 << "'dirin=' must be present;"
80 am->ArgMgrUsage(usage); // Display 'usage'
85 // FIXME : check only one of them is set !
87 bool pos = am->ArgMgrDefined("pos");
88 bool ori = am->ArgMgrDefined("ori");
89 bool tag = am->ArgMgrDefined("tag");
95 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 = new gdcm::SerieHelper();
119 s->SetLoadMode(gdcm::LD_ALL); // Load everything for each File
120 //s->AddRestriction(tagKey, valueToCheck); // Keep only files where
121 // restriction is true
122 s->SetDirectory(dirName, true); // true : recursive exploration
125 std::cout << " ---------------------------------------- "
126 << "'Single UID' Filesets found in :["
127 << dirName << "]" << std::endl;
130 std::cout << " ------------------------------------- Result after splitting"
134 std::string fileName;
135 // For all the Single SerieUID Files Sets of the gdcm::Serie
136 gdcm::FileList *l = s->GetFirstSingleSerieUIDFileSet();
138 gdcm::XCoherentFileSetmap xcm;
141 nbFiles = l->size() ;
142 if ( l->size() > 3 ) // Why not ? Just an example, for testing
144 std::cout << "Split the 'Single SerieUID' FileSet :["
145 << s->GetCurrentSerieUIDFileSetUID()
146 << "] " << nbFiles << " long" << std::endl;
147 std::cout << "-----------------------------------" << std::endl;
150 xcm = s->SplitOnOrientation(l);
152 xcm = s->SplitOnPosition(l);
154 xcm = s->SplitOnTagValue(l, groupelem[0],groupelem[1] );
156 for (gdcm::XCoherentFileSetmap::iterator i = xcm.begin();
161 std::cout << "Orientation : ";
163 std::cout << "Position : ";
165 std::cout << "Tag (" << std::hex << groupelem[0]
166 << "|" << groupelem[1] << ") value : ";
168 std::cout << "[" << (*i).first << "]" << std::endl;
170 // Nowadays OrderFileList() causes trouble, since some files
171 // (MIP views) don't have 'Position', now considered as mandatory
172 // Commented out for the moment.
174 //s->OrderFileList((*i).second); // sort the XCoherent Fileset
176 for (std::vector<gdcm::File* >::iterator it = ((*i).second)->begin();
177 it != ((*i).second)->end();
180 fileName = (*it)->GetFileName();
181 std::cout << " " << fileName << std::endl;
183 std::cout << std::endl;
186 l = s->GetNextSingleSerieUIDFileSet();