1 /*=========================================================================
4 Module: $RCSfile: gdcmDicomDir.cxx,v $
6 Date: $Date: 2005/08/31 16:24:19 $
7 Version: $Revision: 1.159 $
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 =========================================================================*/
19 //-----------------------------------------------------------------------------
20 // For full DICOMDIR description, see:
21 // PS 3.3-2003, pages 731-750
22 //-----------------------------------------------------------------------------
23 #include "gdcmDicomDir.h"
24 #include "gdcmDicomDirObject.h"
25 #include "gdcmDicomDirStudy.h"
26 #include "gdcmDicomDirSerie.h"
27 #include "gdcmDicomDirVisit.h"
28 #include "gdcmDicomDirImage.h"
29 #include "gdcmDicomDirPatient.h"
30 #include "gdcmDicomDirMeta.h"
31 #include "gdcmDicomDirElement.h"
32 #include "gdcmDirList.h"
34 #include "gdcmDebug.h"
35 #include "gdcmGlobal.h"
37 #include "gdcmSeqEntry.h"
38 #include "gdcmSQItem.h"
39 #include "gdcmValEntry.h"
44 #include <sys/types.h>
47 # define getcwd _getcwd
50 #if defined(_MSC_VER) || defined(__BORLANDC__)
55 // ----------------------------------------------------------------------------
56 // Note for future developpers
57 // ----------------------------------------------------------------------------
59 // Dicom PS 3.3 describes the relationship between Directory Records, as follow
60 // (see also PS 4.3, 2004, page 50 for Entity-Relationship model)
62 // Directory Record Type Directory Record Types which may be included
63 // in the next lower-level directory Entity
65 // (Root directory Entity) PATIENT, TOPIC, PRIVATE
67 // PATIENT STUDY, PRIVATE
69 // STUDY SERIES, VISIT, RESULTS, STUDY COMPONENT, PRIVATE
71 // SERIES IMAGE, OVERLAYS, MODALITY LUT, VOI LUT,
72 // CURVE, STORED PRINT, RT DOSE, RT STRUCTURE SET
73 // RT PLAN, RT TREAT RECORD, PRESENTATION, WAVEFORM,
74 // SR DOCUMENT, KEY OBJECT DOC, SPECTROSCOPY,
75 // RAW DATA, REGISTRATION, FIDUCIAL, PRIVATE,
98 // ----------------------
99 // The current gdcm version only deals with :
101 // (Root directory Entity) PATIENT
108 // DicomDir::CreateDicomDir will have to be completed
109 // Treelike structure management will have to be upgraded
110 // ----------------------------------------------------------------------------
114 //-----------------------------------------------------------------------------
115 // Constructor / Destructor
117 * \brief Constructor : creates an empty DicomDir
122 Initialize(); // sets all private fields to NULL
127 #ifndef GDCM_LEGACY_REMOVE
129 * \brief Constructor Parses recursively the directory and creates the DicomDir
130 * or uses an already built DICOMDIR, depending on 'parseDir' value.
131 * @param fileName name
132 * - of the root directory (parseDir = true)
133 * - of the DICOMDIR (parseDir = false)
134 * @param parseDir boolean
135 * - true if user passed an entry point
136 * and wants to explore recursively the directories
137 * - false if user passed an already built DICOMDIR file
138 * and wants to use it
139 * @deprecated use : new DicomDir() + [ SetLoadMode(lm) + ] SetDirectoryName(name)
140 * or : new DicomDir() + SetFileName(name)
142 DicomDir::DicomDir(std::string const &fileName, bool parseDir ):
145 // At this step, Document constructor is already executed,
146 // whatever user passed (either a root directory or a DICOMDIR)
147 // and whatever the value of parseDir was.
148 // (nothing is cheked in Document constructor, to avoid overhead)
151 SetLoadMode (LD_ALL); // concerns only dicom files
152 SetFileName( fileName );
158 * \brief Canonical destructor
160 DicomDir::~DicomDir()
162 SetStartMethod(NULL,NULL,NULL);
163 SetProgressMethod(NULL,NULL,NULL);
164 SetEndMethod(NULL,NULL,NULL);
173 //-----------------------------------------------------------------------------
177 * \brief Loader. use SetFileName(fn)
178 * or SetLoadMode(lm) + SetDirectoryName(dn) before !
179 * @return false if file cannot be open or no swap info was found,
180 * or no tag was found.
182 bool DicomDir::Load( )
184 // We should clean out anything that already exists.
185 Initialize(); // sets all private fields to NULL
189 if ( ! this->Document::Load( ) )
192 return DoTheLoadingJob( );
195 #ifndef GDCM_LEGACY_REMOVE
197 * \brief Loader. (DEPRECATED : kept not to break the API)
198 * @param fileName file to be open for parsing
199 * @return false if file cannot be open or no swap info was found,
200 * or no tag was found.
201 * @deprecated use SetFileName(n) + Load() instead
203 bool DicomDir::Load(std::string const &fileName )
205 // We should clean out anything that already exists.
206 Initialize(); // sets all private fields to NULL
208 SetFileName( fileName );
211 if ( ! this->Document::Load( ) )
214 return DoTheLoadingJob( );
217 /// DEPRECATED : use SetDirectoryName(dname) instead
219 * \brief Loader. (DEPRECATED : kept not to break the API)
220 * @param paseDir Parse Dir
221 * @deprecated use SetDirectoryName(dname) instead
223 void DicomDir::SetParseDir(bool parseDir)
230 * \brief Does the Loading Job (internal use only)
231 * @return false if file cannot be open or no swap info was found,
232 * or no tag was found.
234 bool DicomDir::DoTheLoadingJob( )
236 // We should clean out anything that already exists.
237 Initialize(); // sets all private fields to NULL
241 // Only if user passed a DICOMDIR
242 // ------------------------------
248 if (!Document::Load() )
253 if ( GetFirstEntry() == 0 ) // when user passed a Directory to parse
255 gdcmWarningMacro( "Entry HT empty for file: "<< GetFileName());
258 // Directory record sequence
259 DocEntry *e = GetDocEntry(0x0004, 0x1220);
262 gdcmWarningMacro( "NO 'Directory record sequence' (0x0004,0x1220)"
263 << " in file " << GetFileName());
271 // Only if user passed a root directory
272 // ------------------------------------
273 if ( GetFileName() == "." )
275 // user passed '.' as Name
276 // we get current directory name
278 getcwd(dummy, (size_t)1000);
279 SetFileName( dummy ); // will be converted into a string
282 gdcmWarningMacro( "Parse directory and create the DicomDir : "
290 * \brief This predicate, based on hopefully reasonable heuristics,
291 * decides whether or not the current document was properly parsed
292 * and contains the mandatory information for being considered as
293 * a well formed and usable DicomDir.
294 * @return true when Document is the one of a reasonable DicomDir,
297 bool DicomDir::IsReadable()
299 if ( Filetype == Unknown )
301 gdcmWarningMacro( "Wrong filetype");
306 gdcmWarningMacro( "Meta Elements missing in DicomDir");
309 if ( Patients.size() <= 0 )
311 gdcmWarningMacro( "NO Patient in DicomDir");
319 * \brief adds *the* Meta to a partially created DICOMDIR
321 DicomDirMeta *DicomDir::NewMeta()
326 DocEntry *entry = GetFirstEntry();
329 MetaElems = new DicomDirMeta(true); // true = empty
331 entry = GetFirstEntry();
334 if ( dynamic_cast<SeqEntry *>(entry) )
337 RemoveEntryNoDestroy(entry);
338 MetaElems->AddEntry(entry);
340 entry = GetFirstEntry();
343 else // after root directory parsing
345 MetaElems = new DicomDirMeta(false); // false = not empty
347 MetaElems->SetSQItemNumber(0); // To avoid further missprinting
352 * \brief adds a new Patient (with the basic elements) to a partially created
355 DicomDirPatient *DicomDir::NewPatient()
357 DicomDirPatient *p = new DicomDirPatient();
358 AddPatientToEnd( p );
363 * \brief Remove all Patients
365 void DicomDir::ClearPatient()
367 for(ListDicomDirPatient::iterator cc = Patients.begin();
377 * \brief Get the first entry while visiting the DicomDirPatients
378 * \return The first DicomDirPatient if found, otherwhise NULL
380 DicomDirPatient *DicomDir::GetFirstPatient()
382 ItPatient = Patients.begin();
383 if ( ItPatient != Patients.end() )
389 * \brief Get the next entry while visiting the DicomDirPatients
390 * \note : meaningfull only if GetFirstEntry already called
391 * \return The next DicomDirPatient if found, otherwhise NULL
393 DicomDirPatient *DicomDir::GetNextPatient()
395 gdcmAssertMacro (ItPatient != Patients.end());
398 if ( ItPatient != Patients.end() )
404 * \brief fills the whole structure, starting from a root Directory
406 void DicomDir::ParseDirectory()
408 CreateDicomDirChainedList( GetFileName() );
412 void DicomDir::SetStartMethod( DicomDir::Method *method, void *arg )
414 SetStartMethod(method,arg,NULL);
417 void DicomDir::SetProgressMethod( DicomDir::Method *method, void *arg )
419 SetProgressMethod(method,arg,NULL);
422 void DicomDir::SetEndMethod( DicomDir::Method *method, void *arg )
424 SetEndMethod(method,arg,NULL);
428 * \brief Set the start method to call when the parsing of the
430 * @param method Method to call
431 * @param arg Argument to pass to the method
432 * @param argDelete Argument
433 * \warning In python : the arg parameter isn't considered
435 void DicomDir::SetStartMethod( DicomDir::Method *method, void *arg,
436 DicomDir::Method *argDelete )
438 if ( StartArg && StartMethodArgDelete )
440 StartMethodArgDelete( StartArg );
443 StartMethod = method;
445 StartMethodArgDelete = argDelete;
450 * \brief Set the progress method to call when the parsing of the
452 * @param method Method to call
453 * @param arg Argument to pass to the method
454 * @param argDelete Argument
455 * \warning In python : the arg parameter isn't considered
457 void DicomDir::SetProgressMethod( DicomDir::Method *method, void *arg,
458 DicomDir::Method *argDelete )
460 if ( ProgressArg && ProgressMethodArgDelete )
462 ProgressMethodArgDelete( ProgressArg );
465 ProgressMethod = method;
467 ProgressMethodArgDelete = argDelete;
471 * \brief Set the end method to call when the parsing of the directory ends
472 * @param method Method to call
473 * @param arg Argument to pass to the method
474 * @param argDelete Argument
475 * \warning In python : the arg parameter isn't considered
477 void DicomDir::SetEndMethod( DicomDir::Method *method, void *arg,
478 DicomDir::Method *argDelete )
480 if ( EndArg && EndMethodArgDelete )
482 EndMethodArgDelete( EndArg );
487 EndMethodArgDelete = argDelete;
491 * \brief Set the method to delete the argument
492 * The argument is destroyed when the method is changed or when the
494 * @param method Method to call to delete the argument
496 void DicomDir::SetStartMethodArgDelete( DicomDir::Method *method )
498 StartMethodArgDelete = method;
502 * \brief Set the method to delete the argument
503 * The argument is destroyed when the method is changed or when the
505 * @param method Method to call to delete the argument
507 void DicomDir::SetProgressMethodArgDelete( DicomDir::Method *method )
509 ProgressMethodArgDelete = method;
513 * \brief Set the method to delete the argument
514 * The argument is destroyed when the method is changed or when
515 * the class is destroyed
516 * @param method Method to call to delete the argument
518 void DicomDir::SetEndMethodArgDelete( DicomDir::Method *method )
520 EndMethodArgDelete = method;
524 * \brief writes on disc a DICOMDIR
525 * \ warning does NOT add the missing elements in the header :
526 * it's up to the user doing it !
527 * @param fileName file to be written to
528 * @return false only when fail to open
531 bool DicomDir::Write(std::string const &fileName)
534 uint16_t sq[4] = { 0x0004, 0x1220, 0xffff, 0xffff };
535 uint16_t sqt[4]= { 0xfffe, 0xe0dd, 0xffff, 0xffff };
537 std::ofstream *fp = new std::ofstream(fileName.c_str(),
538 std::ios::out | std::ios::binary);
541 gdcmWarningMacro("Failed to open(write) File: " << fileName.c_str());
545 char filePreamble[128];
546 memset(filePreamble, 0, 128);
547 fp->write(filePreamble, 128);
548 binary_write( *fp, "DICM");
550 DicomDirMeta *ptrMeta = GetMeta();
551 ptrMeta->WriteContent(fp, ExplicitVR);
553 // force writing 0004|1220 [SQ ], that CANNOT exist within DicomDirMeta
556 binary_write(*fp, sq[i]);
559 for(ListDicomDirPatient::iterator cc = Patients.begin();
560 cc != Patients.end();
563 (*cc)->WriteContent( fp, ExplicitVR );
566 // force writing Sequence Delimitation Item
569 binary_write(*fp, sqt[i]); // fffe e0dd ffff ffff
579 * \brief Anonymize a DICOMDIR
583 bool DicomDir::Anonymize()
586 // Something clever to be found to forge the Patient names
587 std::ostringstream s;
589 for(ListDicomDirPatient::iterator cc = Patients.begin();
594 v = (*cc)->GetValEntry(0x0010, 0x0010) ; // Patient's Name
597 v->SetValue(s.str());
600 v = (*cc)->GetValEntry(0x0010, 0x0020) ; // Patient ID
606 v = (*cc)->GetValEntry(0x0010, 0x0030) ; // Patient's BirthDate
617 //-----------------------------------------------------------------------------
620 * \brief create a Document-like chained list from a root Directory
621 * @param path entry point of the tree-like structure
623 void DicomDir::CreateDicomDirChainedList(std::string const &path)
626 DirList dirList(path,1); // gets recursively the file list
627 unsigned int count = 0;
631 DirListType fileList = dirList.GetFilenames();
633 for( DirListType::iterator it = fileList.begin();
634 it != fileList.end();
637 Progress = (float)(count+1)/(float)fileList.size();
638 CallProgressMethod();
645 f->SetLoadMode(LoadMode); // we allow user not to load Sequences, or Shadow
647 f->SetFileName( it->c_str() );
648 /*int res = */f->Load( );
652 // gdcmWarningMacro( "Failure in new gdcm::File " << it->c_str() );
656 if ( f->IsReadable() )
658 // Add the file to the chained list:
660 gdcmWarningMacro( "Readable " << it->c_str() );
668 // sorts Patient/Study/Serie/
669 std::sort(list.begin(), list.end(), DicomDir::HeaderLessThan );
671 std::string tmp = dirList.GetDirName();
672 //for each File of the chained list, add/update the Patient/Study/Serie/Image info
673 SetElements(tmp, list);
676 for(VectDocument::iterator itDoc=list.begin();
680 delete dynamic_cast<File *>(*itDoc);
685 * \brief CallStartMethod
687 void DicomDir::CallStartMethod()
693 StartMethod( StartArg );
698 * \brief CallProgressMethod
700 void DicomDir::CallProgressMethod()
702 if ( ProgressMethod )
704 ProgressMethod( ProgressArg );
709 * \brief CallEndMethod
711 void DicomDir::CallEndMethod()
720 //-----------------------------------------------------------------------------
723 * \brief Sets all fields to NULL
725 void DicomDir::Initialize()
728 ProgressMethod = NULL;
730 StartMethodArgDelete = NULL;
731 ProgressMethodArgDelete = NULL;
732 EndMethodArgDelete = NULL;
744 * \brief create a 'gdcm::DicomDir' from a DICOMDIR Header
746 void DicomDir::CreateDicomDir()
748 // The SeqEntries of "Directory Record Sequence" are parsed.
749 // When a DicomDir tag ("PATIENT", "STUDY", "SERIE", "IMAGE") is found :
750 // 1 - we save the beginning iterator
751 // 2 - we continue to parse
752 // 3 - we find an other tag
753 // + we create the object for the precedent tag
756 // Directory record sequence
757 DocEntry *e = GetDocEntry(0x0004, 0x1220);
760 gdcmWarningMacro( "No Directory Record Sequence (0004,1220) found");
764 SeqEntry *s = dynamic_cast<SeqEntry *>(e);
767 gdcmWarningMacro( "Element (0004,1220) is not a Sequence ?!?");
777 SQItem *tmpSI=s->GetFirstSQItem();
780 d = tmpSI->GetDocEntry(0x0004, 0x1430); // Directory Record Type
781 if ( ValEntry* valEntry = dynamic_cast<ValEntry *>(d) )
783 v = valEntry->GetValue();
787 gdcmWarningMacro( "(0004,1430) not a ValEntry ?!?");
791 // A decent DICOMDIR has much more images than series,
792 // more series than studies, and so on.
793 // This is the right order to preform the tests
797 si = new DicomDirImage(true);
798 if ( !AddImageToEnd( static_cast<DicomDirImage *>(si)) )
802 gdcmErrorMacro( "Add AddImageToEnd failed");
805 else if ( v == "SERIES" )
807 si = new DicomDirSerie(true);
808 if ( !AddSerieToEnd( static_cast<DicomDirSerie *>(si)) )
812 gdcmErrorMacro( "Add AddSerieToEnd failed");
815 else if ( v == "VISIT " )
817 si = new DicomDirVisit(true);
818 if ( !AddVisitToEnd( static_cast<DicomDirVisit *>(si)) )
822 gdcmErrorMacro( "Add AddVisitToEnd failed");
825 else if ( v == "STUDY " )
827 si = new DicomDirStudy(true);
828 if ( !AddStudyToEnd( static_cast<DicomDirStudy *>(si)) )
832 gdcmErrorMacro( "Add AddStudyToEnd failed");
835 else if ( v == "PATIENT " )
837 si = new DicomDirPatient(true);
838 if ( !AddPatientToEnd( static_cast<DicomDirPatient *>(si)) )
842 gdcmErrorMacro( "Add PatientToEnd failed");
847 // It was neither a 'PATIENT', nor a 'STUDY', nor a 'SERIE',
848 // nor an 'IMAGE' SQItem. Skip to next item.
849 gdcmWarningMacro( " -------------------------------------------"
850 << "a non PATIENT/STUDY/SERIE/IMAGE SQItem was found : "
853 // FIXME : deal with other item types !
854 tmpSI=s->GetNextSQItem(); // To avoid infinite loop
858 //MoveSQItem(si,tmpSI); // Old code : Copies each Entry
859 // -and then removes the source-
860 si->MoveObject(tmpSI); // New code : Copies the List
862 tmpSI=s->GetNextSQItem();
868 * \brief AddPatientToEnd
869 * @param dd SQ Item to enqueue to the DicomPatient chained List
871 bool DicomDir::AddPatientToEnd(DicomDirPatient *dd)
873 Patients.push_back(dd);
878 * \brief AddStudyToEnd
879 * @param dd SQ Item to enqueue to the DicomDirStudy chained List
881 bool DicomDir::AddStudyToEnd(DicomDirStudy *dd)
883 if ( Patients.size() > 0 )
885 ListDicomDirPatient::iterator itp = Patients.end();
887 (*itp)->AddStudy(dd);
894 * \brief AddSerieToEnd
895 * @param dd SQ Item to enqueue to the DicomDirSerie chained List
897 bool DicomDir::AddSerieToEnd(DicomDirSerie *dd)
899 if ( Patients.size() > 0 )
901 ListDicomDirPatient::iterator itp = Patients.end();
904 DicomDirStudy *study = (*itp)->GetLastStudy();
915 * \brief AddVisitToEnd
916 * @param dd SQ Item to enqueue to the DicomDirVisit chained List
918 bool DicomDir::AddVisitToEnd(DicomDirVisit *dd)
920 if ( Patients.size() > 0 )
922 ListDicomDirPatient::iterator itp = Patients.end();
925 DicomDirStudy *study = (*itp)->GetLastStudy();
935 * \brief AddImageToEnd
936 * @param dd SQ Item to enqueue to the DicomDirImage chained List
938 bool DicomDir::AddImageToEnd(DicomDirImage *dd)
940 if ( Patients.size() > 0 )
942 ListDicomDirPatient::iterator itp = Patients.end();
945 DicomDirStudy *study = (*itp)->GetLastStudy();
948 DicomDirSerie *serie = study->GetLastSerie();
960 * \brief for each Header of the chained list,
961 * add/update the Patient/Study/Serie/Image info
962 * @param path path of the root directory
963 * @param list chained list of Headers
965 void DicomDir::SetElements(std::string const &path, VectDocument const &list)
970 std::string patPrevName = "", patPrevID = "";
971 std::string studPrevInstanceUID = "", studPrevID = "";
972 std::string serPrevInstanceUID = "", serPrevID = "";
974 std::string patCurName, patCurID;
975 std::string studCurInstanceUID, studCurID;
976 std::string serCurInstanceUID, serCurID;
979 for( VectDocument::const_iterator it = list.begin();
983 // get the current file characteristics
984 patCurName = (*it)->GetEntryValue(0x0010,0x0010);
985 patCurID = (*it)->GetEntryValue(0x0010,0x0011);
986 studCurInstanceUID = (*it)->GetEntryValue(0x0020,0x000d);
987 studCurID = (*it)->GetEntryValue(0x0020,0x0010);
988 serCurInstanceUID = (*it)->GetEntryValue(0x0020,0x000e);
989 serCurID = (*it)->GetEntryValue(0x0020,0x0011);
991 if ( patCurName != patPrevName || patCurID != patPrevID || first )
993 SetElement(path, GDCM_DICOMDIR_PATIENT, *it);
997 // if new Study, deal with 'STUDY' Elements
998 if ( studCurInstanceUID != studPrevInstanceUID || studCurID != studPrevID
1001 SetElement(path, GDCM_DICOMDIR_STUDY, *it);
1005 // if new Serie, deal with 'SERIE' Elements
1006 if ( serCurInstanceUID != serPrevInstanceUID || serCurID != serPrevID
1009 SetElement(path, GDCM_DICOMDIR_SERIE, *it);
1012 // Always Deal with 'IMAGE' Elements
1013 SetElement(path, GDCM_DICOMDIR_IMAGE, *it);
1015 patPrevName = patCurName;
1016 patPrevID = patCurID;
1017 studPrevInstanceUID = studCurInstanceUID;
1018 studPrevID = studCurID;
1019 serPrevInstanceUID = serCurInstanceUID;
1020 serPrevID = serCurID;
1026 * \brief adds to the HTable
1027 * the Entries (Dicom Elements) corresponding to the given type
1028 * @param path full path file name (only used when type = GDCM_DICOMDIR_IMAGE
1029 * @param type DicomDirObject type to create (GDCM_DICOMDIR_PATIENT,
1030 * GDCM_DICOMDIR_STUDY, GDCM_DICOMDIR_SERIE ...)
1031 * @param header Header of the current file
1033 void DicomDir::SetElement(std::string const &path, DicomDirType type,
1036 ListDicomDirElem elemList;
1037 ListDicomDirElem::const_iterator it;
1038 uint16_t tmpGr, tmpEl;
1039 DictEntry *dictEntry;
1046 case GDCM_DICOMDIR_IMAGE:
1047 elemList = Global::GetDicomDirElements()->GetDicomDirImageElements();
1048 si = new DicomDirImage(true);
1049 if ( !AddImageToEnd(static_cast<DicomDirImage *>(si)) )
1052 gdcmErrorMacro( "Add ImageToEnd failed");
1055 case GDCM_DICOMDIR_SERIE:
1056 elemList = Global::GetDicomDirElements()->GetDicomDirSerieElements();
1057 si = new DicomDirSerie(true);
1058 if ( !AddSerieToEnd(static_cast<DicomDirSerie *>(si)) )
1061 gdcmErrorMacro( "Add SerieToEnd failed");
1064 case GDCM_DICOMDIR_STUDY:
1065 elemList = Global::GetDicomDirElements()->GetDicomDirStudyElements();
1066 si = new DicomDirStudy(true);
1067 if ( !AddStudyToEnd(static_cast<DicomDirStudy *>(si)) )
1070 gdcmErrorMacro( "Add StudyToEnd failed");
1073 case GDCM_DICOMDIR_PATIENT:
1074 elemList = Global::GetDicomDirElements()->GetDicomDirPatientElements();
1075 si = new DicomDirPatient(true);
1076 if ( !AddPatientToEnd(static_cast<DicomDirPatient *>(si)) )
1079 gdcmErrorMacro( "Add PatientToEnd failed");
1082 case GDCM_DICOMDIR_META:
1083 elemList = Global::GetDicomDirElements()->GetDicomDirMetaElements();
1084 si = new DicomDirMeta(true);
1088 gdcmErrorMacro( "MetaElements already exist, they will be destroyed");
1090 MetaElems = static_cast<DicomDirMeta *>(si);
1095 // removed all the seems-to-be-useless stuff about Referenced Image Sequence
1096 // to avoid further troubles
1097 // imageElem 0008 1140 "" // Referenced Image Sequence
1098 // imageElem fffe e000 "" // 'no length' item : length to be set to 0xffffffff later
1099 // imageElem 0008 1150 "" // Referenced SOP Class UID : to be set/forged later
1100 // imageElem 0008 1155 "" // Referenced SOP Instance UID : to be set/forged later
1101 // imageElem fffe e00d "" // Item delimitation : length to be set to ZERO later
1103 // FIXME : troubles found when it's a SeqEntry
1105 // for all the relevant elements found in their own spot of the DicomDir.dic
1106 for( it = elemList.begin(); it != elemList.end(); ++it)
1110 dictEntry = GetPubDict()->GetEntry(tmpGr, tmpEl);
1112 entry = new ValEntry( dictEntry ); // Be sure it's never a BinEntry !
1114 entry->SetOffset(0); // just to avoid further missprinting
1118 // NULL when we Build Up (ex nihilo) a DICOMDIR
1119 // or when we add the META elems
1120 val = header->GetEntryValue(tmpGr, tmpEl);
1127 if ( val == GDCM_UNFOUND)
1129 if ( tmpGr == 0x0004 && tmpEl == 0x1130 ) // File-set ID
1131 // force to the *end* File Name
1132 val = Util::GetName( path );
1134 else if ( tmpGr == 0x0004 && tmpEl == 0x1500 ) // Only used for image
1136 if ( header->GetFileName().substr(0, path.length()) != path )
1138 gdcmWarningMacro( "The base path of file name is incorrect");
1139 val = header->GetFileName();
1143 val = &(header->GetFileName().c_str()[path.length()]);
1153 if ( header->GetEntryLength(tmpGr,tmpEl) == 0 )
1157 entry->SetValue( val ); // troubles expected when vr=SQ ...
1159 if ( type == GDCM_DICOMDIR_META ) // fusible : should never print !
1161 gdcmWarningMacro("GDCM_DICOMDIR_META ?!? should never print that");
1163 si->AddEntry(entry);
1168 * \brief Move the content of the source SQItem to the destination SQItem
1169 * Only DocEntry's are moved
1170 * @param dst destination SQItem
1171 * @param src source SQItem
1173 void DicomDir::MoveSQItem(DocEntrySet *dst,DocEntrySet *src)
1177 entry = src->GetFirstEntry();
1180 src->RemoveEntryNoDestroy(entry);
1181 dst->AddEntry(entry);
1182 // we destroyed -> the current iterator is not longer valid
1183 entry = src->GetFirstEntry();
1188 * \brief compares two files
1190 bool DicomDir::HeaderLessThan(Document *header1, Document *header2)
1192 return *header1 < *header2;
1195 //-----------------------------------------------------------------------------
1198 * \brief Canonical Printer
1199 * @param os ostream we want to print in
1200 * @param indent Indentation string to be prepended during printing
1202 void DicomDir::Print(std::ostream &os, std::string const & )
1206 MetaElems->SetPrintLevel(PrintLevel);
1207 MetaElems->Print(os);
1209 for(ListDicomDirPatient::iterator cc = Patients.begin();
1210 cc != Patients.end();
1213 (*cc)->SetPrintLevel(PrintLevel);
1218 //-----------------------------------------------------------------------------
1219 } // end namespace gdcm