1 /*=========================================================================
4 Module: $RCSfile: PhilipsToBrucker.cxx,v $
6 Date: $Date: 2005/12/21 15:01:04 $
7 Version: $Revision: 1.1 $
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 "gdcmDocEntry.h"
19 #include "gdcmDicomDir.h"
20 #include "gdcmDicomDirPatient.h"
22 #include "gdcmDirList.h"
23 #include "gdcmDebug.h"
24 #include "gdcmArgMgr.h"
26 #include "gdcmSerieHelper.h"
32 * - explores recursively the given directory
33 * - keeps the requested series
34 * - orders the gdcm-readable found Files
35 * according their Patient/Study/Serie/Image characteristics
36 * - fills a single level Directory with *all* the files,
37 * converted into a Brucker-like Dicom, Intags compliant
41 typedef std::map<std::string, gdcm::File*> SortedFiles;
43 int main(int argc, char *argv[])
47 " \n PhilipsToBrucker :\n ",
48 " Explores recursively the given directory, ",
50 " usage: PhilipsToBrucker dirin=rootDirectoryName ",
51 " dirout=outputDirectoryName ",
52 " [noshadowseq][noshadow][noseq] [debug] ",
54 " noshadowseq: user doesn't want to load Private Sequences ",
55 " noshadow : user doesn't want to load Private groups (odd number) ",
56 " noseq : user doesn't want to load Sequences ",
57 " debug : user wants to run the program in 'debug mode' ",
62 // ----- Initialize Arguments Manager ------
63 gdcm::ArgMgr *am = new gdcm::ArgMgr(argc, argv);
65 if (argc == 1 || am->ArgMgrDefined("usage"))
67 am->ArgMgrUsage(usage); // Display 'usage'
73 dirNamein = am->ArgMgrGetString("dirin",(char *)".");
76 dirNameout = am->ArgMgrGetString("dirout",(char *)".");
78 int loadMode = gdcm::LD_ALL;
79 if ( am->ArgMgrDefined("noshadowseq") )
80 loadMode |= gdcm::LD_NOSHADOWSEQ;
83 if ( am->ArgMgrDefined("noshadow") )
84 loadMode |= gdcm::LD_NOSHADOW;
85 if ( am->ArgMgrDefined("noseq") )
86 loadMode |= gdcm::LD_NOSEQ;
89 if (am->ArgMgrDefined("debug"))
90 gdcm::Debug::DebugOn();
92 // if unused Param we give up
93 if ( am->ArgMgrPrintUnusedLabels() )
95 am->ArgMgrUsage(usage);
100 delete am; // we don't need Argument Manager any longer
102 // ----- Begin Processing -----
104 std::string strDirNamein(dirNamein);
105 gdcm::DirList dirList(strDirNamein, true);
108 std::cout << "---------------File list found ------------" << std::endl;
112 gdcm::DirListType fileNames;
113 fileNames = dirList.GetFilenames();
114 gdcm::SerieHelper *s;
115 s = gdcm::SerieHelper::New();
118 std::cout << "---------------Print Serie--------------" << std::endl;
119 s->SetDirectory(dirNamein, true); // true : recursive exploration
120 s->SetUseSeriesDetails(true);
121 s->AddSeriesDetail(0x0018, 0x1312);
130 std::cout << "---------------Print Unique Series identifiers---------" << std::endl;
131 std::string uniqueSeriesIdentifier;
133 for (gdcm::DirListType::iterator it = fileNames.begin();
134 it != fileNames.end();
137 std::cout << "File Name : " << *it << std::endl;
138 f = gdcm::File::New();
139 f->SetLoadMode(gdcm::LD_ALL);
140 f->SetFileName( *it );
143 uniqueSeriesIdentifier=s->CreateUniqueSeriesIdentifier(f);
145 uniqueSeriesIdentifier << "]" << std::endl;
151 std::cout << "------------------Print Break levels-----------------" << std::endl;
153 std::string userFileIdentifier;
157 s->AddSeriesDetail(0x0010, 0x0010, false); // Patient's Name
158 s->AddSeriesDetail(0x0020, 0x000e, false); // Series Instance UID
159 s->AddSeriesDetail(0x0020, 0x0032, false); // Image Position (Patient)
160 s->AddSeriesDetail(0x0018, 0x1312, false); // In-plane Phase Encoding Direction
161 s->AddSeriesDetail(0x0018, 0x1060, true); // Trigger Time
163 for (gdcm::DirListType::iterator it = fileNames.begin();
164 it != fileNames.end();
167 //std::cout << "File Name : " << *it << std::endl;
168 f = gdcm::File::New();
169 f->SetLoadMode(gdcm::LD_ALL);
170 f->SetFileName( *it );
173 userFileIdentifier=s->CreateUserDefinedFileIdentifier(f);
174 //std::cout << " [" <<
175 // userFileIdentifier << "]" << std::endl;
176 // storing in a map ensures automatic sorting !
177 sf[userFileIdentifier] = f;
180 std::vector<std::string> tokens;
181 std::string fullFilename;
182 std::string previousPatientName, currentPatientName;
183 std::string previousSerieInstanceUID, currentSerieInstanceUID;
184 std::string previousImagePosition, currentImagePosition;
185 std::string previousPhaseEncodingDirection, currentPhaseEncodingDirection;
187 SortedFiles::iterator it2 = sf.begin();
189 gdcm::Util::Tokenize (it2->first, tokens, "_");
191 previousPatientName = tokens[0];
192 previousSerieInstanceUID = tokens[1];
193 previousImagePosition = tokens[2];
194 previousPhaseEncodingDirection = tokens[3];
195 std::cout << "==== new Patient " << currentPatientName << std::endl;
196 std::cout << "==== === new Serie " << currentSerieInstanceUID << std::endl;
197 std::cout << "==== === === new Position " << currentImagePosition << std::endl;
198 std::cout << "==== === === === new PhaseEncodingDirection " << currentImagePosition << std::endl;
199 std::cout << "==== === === === " << it2->first << std::endl;
203 for ( ; it2 != sf.end(); ++it2)
206 gdcm::Util::Tokenize (it2->first, tokens, "_");
208 currentPatientName = tokens[0];
209 currentSerieInstanceUID = tokens[1];
210 currentImagePosition = tokens[2];
211 currentPhaseEncodingDirection = tokens[3];
213 if (previousPatientName != currentPatientName)
215 previousPatientName = currentPatientName;
216 std::cout << "==== new Patient " << currentPatientName << std::endl;
217 previousPatientName = currentPatientName;
218 previousSerieInstanceUID = currentSerieInstanceUID;
219 previousImagePosition = currentImagePosition;
220 previousPhaseEncodingDirection = currentPhaseEncodingDirection;
223 if (previousSerieInstanceUID != currentSerieInstanceUID)
225 std::cout << "==== === new Serie " << currentSerieInstanceUID << std::endl;
226 previousSerieInstanceUID = currentSerieInstanceUID;
227 previousImagePosition = currentImagePosition;
228 previousPhaseEncodingDirection = currentPhaseEncodingDirection;
231 if (previousImagePosition != currentImagePosition)
233 std::cout << "==== === === new Position " << currentImagePosition << std::endl;
234 previousImagePosition = currentImagePosition;
235 previousPhaseEncodingDirection = currentPhaseEncodingDirection;
238 if (previousPhaseEncodingDirection != currentPhaseEncodingDirection)
240 std::cout << "==== === === === new PhaseEncodingDirection " << currentImagePosition << std::endl;
241 previousPhaseEncodingDirection = currentPhaseEncodingDirection;
243 fullFilename = (it2->second)->GetFileName();
244 std::cout << "==== === === === " << it2->first << " " << (it2->second)->GetFileName() << " "
245 << gdcm::Util::GetName( fullFilename ) <<std::endl;