1 /*=========================================================================
4 Module: $RCSfile: gdcmDicomDir.cxx,v $
6 Date: $Date: 2004/08/30 16:15:40 $
7 Version: $Revision: 1.66 $
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.htm 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 =========================================================================*/
21 #include <sys/types.h>
29 #include "gdcmDicomDir.h"
30 #include "gdcmDicomDirStudy.h"
31 #include "gdcmDicomDirSerie.h"
32 #include "gdcmDicomDirImage.h"
33 #include "gdcmDirList.h"
35 #include "gdcmDebug.h"
36 #include "gdcmGlobal.h"
37 #include "gdcmHeader.h"
38 #include "gdcmSeqEntry.h"
39 #include "gdcmSQItem.h"
40 #include "gdcmValEntry.h"
42 //-----------------------------------------------------------------------------
43 // For full DICOMDIR description, see:
44 // PS 3.3-2003, pages 731-750
45 //-----------------------------------------------------------------------------
46 // Constructor / Destructor
49 * \ingroup gdcmDicomDir
50 * \brief Constructor : creates an empty gdcmDicomDir
52 gdcmDicomDir::gdcmDicomDir()
55 Initialize(); // sets all private fields to NULL
56 std::string pathBidon = "Bidon"; // Sorry, NULL not allowed ...
57 metaElems = NewMeta();
61 * \brief Constructor Parses recursively the directory and creates the DicomDir
62 * or uses an already built DICOMDIR, depending on 'parseDir' value.
63 * @param FileName name
64 * - of the root directory (parseDir = true)
65 * - of the DICOMDIR (parseDir = false)
66 * @param parseDir boolean
67 * - true if user passed an entry point
68 * and wants to explore recursively the directories
69 * - false if user passed an already built DICOMDIR file
72 gdcmDicomDir::gdcmDicomDir(std::string const & fileName, bool parseDir ):
73 gdcmDocument( fileName )
75 // que l'on ai passe un root directory ou un DICOMDIR
76 // et quelle que soit la valeur de parseDir,
77 // on a deja lance gdcmDocument
78 Initialize(); // sets all private fields to NULL
80 // gdcmDocument already executed
81 // if user passed a root directory, sure we didn't get anything
83 if ( TagHT.begin() == TagHT.end() ) // when user passed a Directory to parse
85 dbg.Verbose(0, "gdcmDicomDir::gdcmDicomDir : entry HT empty");
87 if ( fileName.size() == 1 && fileName[0] == '.' )
89 // user passed '.' as Name
90 // we get current directory name
91 char* dummy = new char[1000];
92 getcwd(dummy, (size_t)1000);
93 SetFileName( dummy ); // will be converted into a string
94 delete[] dummy; // no longer needed
97 if ( parseDir ) // user asked for a recursive parsing of a root directory
99 metaElems = NewMeta();
101 dbg.Verbose(0, "gdcmDicomDir::gdcmDicomDir : Parse directory"
102 " and create the DicomDir");
107 /// \todo if parseDir == false, it should be tagged as an error
108 // NON ! il suffit d'appeler ParseDirectory()
109 // apres le constructeur
112 else // Only if user passed a DICOMDIR
114 // Directory record sequence
115 gdcmDocEntry *e = GetDocEntryByNumber(0x0004, 0x1220);
118 dbg.Verbose(0, "gdcmDicomDir::gdcmDicomDir : NO Directory record"
119 " sequence (0x0004,0x1220)");
120 /// \todo FIXME : what do we do when the parsed file IS NOT a
128 * \brief Canonical destructor
130 gdcmDicomDir::~gdcmDicomDir()
132 SetStartMethod(NULL);
133 SetProgressMethod(NULL);
135 for(ListDicomDirPatient::iterator cc = patients.begin();
147 //-----------------------------------------------------------------------------
150 * \brief Canonical Printer
152 void gdcmDicomDir::Print(std::ostream &os)
156 metaElems->SetPrintLevel(PrintLevel);
157 metaElems->Print(os);
159 for(ListDicomDirPatient::iterator cc = patients.begin();
160 cc != patients.end();
163 (*cc)->SetPrintLevel( PrintLevel );
168 //-----------------------------------------------------------------------------
171 * \brief This predicate, based on hopefully reasonable heuristics,
172 * decides whether or not the current header was properly parsed
173 * and contains the mandatory information for being considered as
174 * a well formed and usable DicomDir.
175 * @return true when gdcmDocument is the one of a reasonable DicomDir,
178 bool gdcmDicomDir::IsReadable()
180 if( !gdcmDocument::IsReadable() )
188 if( patients.size() <= 0 )
197 * \brief Sets all fields to NULL
200 void gdcmDicomDir::Initialize()
203 progressMethod = NULL;
205 startMethodArgDelete = NULL;
206 progressMethodArgDelete = NULL;
207 endMethodArgDelete = NULL;
220 * \ingroup gdcmDicomDir
221 * \brief fills the whole structure, starting from a root Directory
223 void gdcmDicomDir::ParseDirectory()
225 CreateDicomDirChainedList( GetFileName() );
230 * \ingroup gdcmDicomDir
231 * \brief Set the start method to call when the parsing of the directory starts
232 * @param method Method to call
233 * @param arg Argument to pass to the method
234 * @param argDelete Argument
235 * \warning In python : the arg parameter isn't considered
237 void gdcmDicomDir::SetStartMethod(gdcmMethod *method, void *arg,
238 gdcmMethod *argDelete )
240 if( startArg && startMethodArgDelete )
242 startMethodArgDelete( startArg );
245 startMethod = method;
247 startMethodArgDelete = argDelete;
251 * \ingroup gdcmDicomDir
252 * \brief Set the method to delete the argument
253 * The argument is destroyed when the method is changed or when the
255 * @param method Method to call to delete the argument
257 void gdcmDicomDir::SetStartMethodArgDelete(gdcmMethod *method)
259 startMethodArgDelete = method;
263 * \ingroup gdcmDicomDir
264 * \brief Set the progress method to call when the parsing of the directory progress
265 * @param method Method to call
266 * @param arg Argument to pass to the method
267 * @param argDelete Argument
268 * \warning In python : the arg parameter isn't considered
270 void gdcmDicomDir::SetProgressMethod(gdcmMethod *method, void *arg,
271 gdcmMethod *argDelete )
273 if( progressArg && progressMethodArgDelete )
275 progressMethodArgDelete( progressArg );
278 progressMethod = method;
280 progressMethodArgDelete = argDelete;
284 * \ingroup gdcmDicomDir
285 * \brief Set the method to delete the argument
286 * The argument is destroyed when the method is changed or when the
288 * @param method Method to call to delete the argument
290 void gdcmDicomDir::SetProgressMethodArgDelete(gdcmMethod *method)
292 progressMethodArgDelete = method;
296 * \ingroup gdcmDicomDir
297 * \brief Set the end method to call when the parsing of the directory ends
298 * @param method Method to call
299 * @param arg Argument to pass to the method
300 * @param argDelete Argument
301 * \warning In python : the arg parameter isn't considered
303 void gdcmDicomDir::SetEndMethod(gdcmMethod *method, void *arg,
304 gdcmMethod *argDelete )
306 if( endArg && endMethodArgDelete )
308 endMethodArgDelete( endArg );
313 endMethodArgDelete = argDelete;
317 * \ingroup gdcmDicomDir
318 * \brief Set the method to delete the argument
319 * The argument is destroyed when the method is changed or when the class
321 * @param method Method to call to delete the argument
323 void gdcmDicomDir::SetEndMethodArgDelete(gdcmMethod *method)
325 endMethodArgDelete = method;
329 * \ingroup gdcmDicomDir
330 * \brief writes on disc a DICOMDIR
331 * \ warning does NOT add the missing elements in the header :
332 * it's up to the user doing it !
333 * \todo : to be re-written using the DICOMDIR tree-like structure
334 * *not* the chained list
335 * (does NOT exist if the DICOMDIR is user-forged !)
336 * @param fileName file to be written to
337 * @return false only when fail to open
340 bool gdcmDicomDir::Write(std::string const & fileName)
342 uint16_t sq[4] = { 0x0004, 0x1220, 0xffff, 0xffff };
343 uint16_t sqt[4]= { 0xfffe, 0xe0dd, 0xffff, 0xffff };
345 FILE * fp = fopen(fileName.c_str(), "wb");
348 printf("Failed to open(write) File [%s] \n", fileName.c_str());
352 uint8_t* filePreamble = new uint8_t[128];
353 memset(filePreamble, 0, 128);
354 fwrite(filePreamble,128,1,fp);
355 fwrite("DICM",4,1,fp);
356 delete[] filePreamble;
358 // UpdateDirectoryRecordSequenceLength(); // TODO (if *really* usefull)
360 gdcmDicomDirMeta *ptrMeta = GetDicomDirMeta();
361 ptrMeta->Write(fp, gdcmExplicitVR);
363 // force writing 0004|1220 [SQ ], that CANNOT exist within gdcmDicomDirMeta
364 fwrite(&sq[0],8,1,fp); // 0004 1220 ffff ffff
366 for(ListDicomDirPatient::iterator cc = patients.begin();cc!=patients.end();++cc)
368 (*cc)->Write( fp, gdcmExplicitVR );
371 // force writing Sequence Delimitation Item
372 fwrite(&sqt[0],8,1,fp); // fffe e0dd ffff ffff
378 //-----------------------------------------------------------------------------
382 * \ingroup gdcmDicomDir
383 * \brief create a gdcmDocument-like chained list from a root Directory
384 * @param path entry point of the tree-like structure
386 void gdcmDicomDir::CreateDicomDirChainedList(std::string const & path)
389 gdcmDirList fileList(path,1); // gets recursively the file list
390 unsigned int count = 0;
397 for( gdcmDirList::iterator it = fileList.begin();
398 it != fileList.end();
401 progress = (float)(count+1)/(float)fileList.size();
402 CallProgressMethod();
408 header = new gdcmHeader( it->c_str() );
412 "gdcmDicomDir::CreateDicomDirChainedList: "
413 "failure in new Header ",
417 if( header->IsReadable() )
419 // Add the file header to the chained list:
420 list.push_back(header);
422 "gdcmDicomDir::CreateDicomDirChainedList: readable ",
432 // sorts Patient/Study/Serie/
433 std::sort(list.begin(), list.end(), gdcmDicomDir::HeaderLessThan );
434 std::string tmp = fileList.GetDirName();
436 //for each Header of the chained list, add/update the Patient/Study/Serie/Image info
437 SetElements(tmp, list);
442 * \ingroup gdcmDicomDir
443 * \brief adds *the* Meta to a partially created DICOMDIR
446 gdcmDicomDirMeta * gdcmDicomDir::NewMeta()
448 gdcmDicomDirMeta *m = new gdcmDicomDirMeta( &TagHT );
450 if ( TagHT.begin() != TagHT.end() ) // after Document Parsing
452 TagDocEntryHT::iterator lastOneButSequence = TagHT.end();
453 lastOneButSequence --;
454 // This works because ALL the 'out of Sequence' Tags belong to Meta Elems
455 // (we skip 0004|1220 [Directory record sequence] )
456 for ( TagDocEntryHT::iterator cc = TagHT.begin();
457 cc != lastOneButSequence;
460 m->AddDocEntry( cc->second );
463 else // after root directory parsing
465 std::list<gdcmElement> elemList;
466 elemList=gdcmGlobal::GetDicomDirElements()->GetDicomDirMetaElements();
467 m->FillObject(elemList);
469 m->SetSQItemNumber(0); // To avoid further missprinting
475 * \brief adds a new Patient (with the basic elements) to a partially created DICOMDIR
477 gdcmDicomDirPatient * gdcmDicomDir::NewPatient()
479 std::list<gdcmElement>::iterator it;
480 uint16_t tmpGr,tmpEl;
481 gdcmDictEntry *dictEntry;
484 std::list<gdcmElement> elemList;
485 elemList=gdcmGlobal::GetDicomDirElements()->GetDicomDirPatientElements();
486 gdcmSQItem *s = new gdcmSQItem(0);
488 // for all the DicomDirPatient Elements
489 for( it = elemList.begin(); it != elemList.end(); ++it )
493 dictEntry = GetPubDict()->GetDictEntryByNumber(tmpGr, tmpEl);
494 entry = new gdcmValEntry( dictEntry );
495 entry->SetOffset(0); // just to avoid further missprinting
496 entry->SetValue( it->value );
498 // dealing with value length ...
500 if( dictEntry->GetGroup() == 0xfffe)
502 entry->SetLength(entry->GetValue().length());
504 else if( dictEntry->GetVR() == "UL" || dictEntry->GetVR() == "SL" )
506 entry->SetLength( 4 );
508 else if( dictEntry->GetVR() == "US" || dictEntry->GetVR() == "SS" )
512 else if( dictEntry->GetVR() == "SQ" )
514 entry->SetLength( 0xffffffff );
518 entry->SetLength( entry->GetValue().length() );
520 s->AddDocEntry( entry );
523 gdcmDicomDirPatient *p = new gdcmDicomDirPatient(s, &TagHT);
524 patients.push_front( p );
530 * \brief adds to the HTable
531 * the gdcmEntries (Dicom Elements) corresponding to the given type
532 * @param path full path file name (only used when type = GDCM_DICOMDIR_IMAGE
533 * @param type gdcmObject type to create (GDCM_DICOMDIR_PATIENT,
534 * GDCM_DICOMDIR_STUDY, GDCM_DICOMDIR_SERIE ...)
535 * @param header gdcmHeader of the current file
537 void gdcmDicomDir::SetElement(std::string &path,gdcmDicomDirType type,
538 gdcmDocument *header)
540 std::list<gdcmElement> elemList;
541 std::list<gdcmElement>::iterator it;
542 uint16_t tmpGr, tmpEl;
543 gdcmDictEntry *dictEntry;
546 gdcmSQItem *si = new gdcmSQItem(0); // all the items will be at level 1
549 case GDCM_DICOMDIR_IMAGE:
550 elemList = gdcmGlobal::GetDicomDirElements()->GetDicomDirImageElements();
553 case GDCM_DICOMDIR_SERIE:
554 elemList = gdcmGlobal::GetDicomDirElements()->GetDicomDirSerieElements();
557 case GDCM_DICOMDIR_STUDY:
558 elemList = gdcmGlobal::GetDicomDirElements()->GetDicomDirStudyElements();
561 case GDCM_DICOMDIR_PATIENT:
562 elemList = gdcmGlobal::GetDicomDirElements()->GetDicomDirPatientElements();
565 case GDCM_DICOMDIR_META:
566 elemList = gdcmGlobal::GetDicomDirElements()->GetDicomDirMetaElements();
572 // removed all the seems-to-be-useless stuff about Referenced Image Sequence
573 // to avoid further troubles
574 // imageElem 0008 1140 "" // Referenced Image Sequence
575 // imageElem fffe e000 "" // 'no length' item : length to be set to 0xffffffff later
576 // imageElem 0008 1150 "" // Referenced SOP Class UID : to be set/forged later
577 // imageElem 0008 1155 "" // Referenced SOP Instance UID : to be set/forged later
578 // imageElem fffe e00d "" // Item delimitation : length to be set to ZERO later
579 // for all the relevant elements found in their own spot of the DicomDir.dic
580 // FIXME : troubles found when it's a SeqEntry
582 for( it = elemList.begin(); it != elemList.end(); ++it)
586 dictEntry = GetPubDict()->GetDictEntryByNumber(tmpGr, tmpEl);
588 entry = new gdcmValEntry( dictEntry ); // Be sure it's never a BinEntry !
590 entry->SetOffset(0); // just to avoid further missprinting
591 entry->SetLength(0); // just to avoid further missprinting
593 if( header ) // NULL when we Build Up (ex nihilo) a DICOMDIR
594 // or when we add the META elems
595 val = header->GetEntryByNumber(tmpGr, tmpEl);
599 if( val == GDCM_UNFOUND)
601 if( tmpGr == 0x0004 && tmpEl == 0x1130 ) // File-set ID
603 // force to the *end* File Name
604 val = GetName( path );
606 else if( tmpGr == 0x0004 && tmpEl == 0x1500 ) // Only used for image
608 if( header->GetFileName().substr(0, path.length()) != path )
610 dbg.Verbose(0, "gdcmDicomDir::SetElement : the base path"
611 " of file name is incorrect");
612 val = header->GetFileName();
615 val = &(header->GetFileName().c_str()[path.length()]);
622 if ( header->GetEntryLengthByNumber(tmpGr,tmpEl) == 0 )
626 // GDCM_UNFOUND or not !
628 entry->SetValue( val ); // troubles expected when vr=SQ ...
632 if( dictEntry->GetGroup() == 0xfffe )
634 entry->SetLength( entry->GetValue().length() ); // FIXME
636 else if( dictEntry->GetVR() == "UL" || dictEntry->GetVR() == "SL" )
640 else if( dictEntry->GetVR() == "US" || dictEntry->GetVR() == "SS" )
644 else if( dictEntry->GetVR() == "SQ" )
646 entry->SetLength( 0xffffffff );
650 entry->SetLength( entry->GetValue().length() );
654 if ( type == GDCM_DICOMDIR_META ) // fusible : should never print !
656 std::cout << "GDCM_DICOMDIR_META ?!? should never print that"
663 case GDCM_DICOMDIR_IMAGE:
664 AddDicomDirImageToEnd(si);
667 case GDCM_DICOMDIR_SERIE:
668 AddDicomDirSerieToEnd(si);
671 case GDCM_DICOMDIR_STUDY:
672 AddDicomDirStudyToEnd(si);
675 case GDCM_DICOMDIR_PATIENT:
676 AddDicomDirPatientToEnd(si);
682 //int count=1; // find a trick to increment
683 //s->AddEntry(si, count); // Seg Faults
688 * \brief CallStartMethod
690 void gdcmDicomDir::CallStartMethod()
696 startMethod( startArg );
701 * \ingroup gdcmDicomDir
702 * \brief CallProgressMethod
704 void gdcmDicomDir::CallProgressMethod()
708 progressMethod( progressArg );
713 * \ingroup gdcmDicomDir
714 * \brief CallEndMethod
716 void gdcmDicomDir::CallEndMethod()
725 //-----------------------------------------------------------------------------
728 * \ingroup gdcmDicomDir
729 * \brief create a 'gdcmDicomDir' from a DICOMDIR gdcmHeader
731 void gdcmDicomDir::CreateDicomDir()
733 // The list is parsed.
734 // When a DicomDir tag ("PATIENT", "STUDY", "SERIE", "IMAGE") is found :
735 // 1 - we save the beginning iterator
736 // 2 - we continue to parse
737 // 3 - we find an other tag
738 // + we create the object for the precedent tag
741 // Directory record sequence
742 gdcmDocEntry *e = GetDocEntryByNumber(0x0004, 0x1220);
745 dbg.Verbose(0, "gdcmDicomDir::gdcmDicomDir : NO Directory record"
746 " sequence (0x0004,0x1220)");
747 /// \todo FIXME: what to do when the parsed file IS NOT a DICOMDIR file ?
751 gdcmSeqEntry* s = dynamic_cast<gdcmSeqEntry*>(e);
754 dbg.Verbose(0, "gdcmDicomDir::CreateDicomDir: no SeqEntry present");
755 // useless : (0x0004,0x1220) IS a Sequence !
759 gdcmDicomDirType type = gdcmDicomDir::GDCM_DICOMDIR_META;
760 metaElems = NewMeta();
762 ListSQItem listItems = s->GetSQItems();
766 for( ListSQItem::iterator i = listItems.begin();
767 i !=listItems.end(); ++i )
769 d = (*i)->GetDocEntryByNumber(0x0004, 0x1430); // Directory Record Type
770 if ( gdcmValEntry* ValEntry = dynamic_cast< gdcmValEntry* >(d) )
772 v = ValEntry->GetValue();
776 dbg.Verbose(0, "gdcmDicomDir::CreateDicomDir: not a ValEntry.");
780 if( v == "PATIENT " )
782 AddDicomDirPatientToEnd( *i );
783 type = gdcmDicomDir::GDCM_DICOMDIR_PATIENT;
785 else if( v == "STUDY " )
787 AddDicomDirStudyToEnd( *i );
788 type = gdcmDicomDir::GDCM_DICOMDIR_STUDY;
790 else if( v == "SERIES" )
792 AddDicomDirSerieToEnd( *i );
793 type = gdcmDicomDir::GDCM_DICOMDIR_SERIE;
795 else if( v == "IMAGE " )
797 AddDicomDirImageToEnd( *i );
798 type = gdcmDicomDir::GDCM_DICOMDIR_IMAGE;
802 // It was not a 'PATIENT', nor a 'STUDY', nor a 'SERIE',
803 // neither an 'IMAGE' SQItem. Skip to next item.
810 * \ingroup gdcmDicomDir
811 * \brief Well ... there is only one occurence
813 void gdcmDicomDir::AddDicomDirMeta()
819 metaElems = new gdcmDicomDirMeta( &TagHT );
823 * \ingroup gdcmDicomDir
824 * \brief AddDicomDirPatientToEnd
825 * @param s SQ Item to enqueue to the DicomPatient chained List
827 void gdcmDicomDir::AddDicomDirPatientToEnd(gdcmSQItem *s)
829 patients.push_back(new gdcmDicomDirPatient(s, &TagHT));
833 * \ingroup gdcmDicomDir
834 * \brief AddDicomDirStudyToEnd
835 * @param s SQ Item to enqueue to the DicomDirStudy chained List
837 void gdcmDicomDir::AddDicomDirStudyToEnd(gdcmSQItem *s)
839 if( patients.size() > 0 )
841 ListDicomDirPatient::iterator itp = patients.end();
843 (*itp)->AddDicomDirStudy(new gdcmDicomDirStudy(s, &TagHT));
848 * \ingroup gdcmDicomDir
849 * \brief AddDicomDirSerieToEnd
850 * @param s SQ Item to enqueue to the DicomDirSerie chained List
852 void gdcmDicomDir::AddDicomDirSerieToEnd(gdcmSQItem *s)
854 if( patients.size() > 0 )
856 ListDicomDirPatient::iterator itp = patients.end();
859 if( (*itp)->GetDicomDirStudies().size() > 0 )
861 ListDicomDirStudy::iterator itst=(*itp)->GetDicomDirStudies().end();
863 (*itst)->AddDicomDirSerie(new gdcmDicomDirSerie(s, &TagHT));
869 * \ingroup gdcmDicomDir
870 * \brief AddDicomDirImageToEnd
871 * @param s SQ Item to enqueue to the DicomDirImage chained List
873 void gdcmDicomDir::AddDicomDirImageToEnd(gdcmSQItem *s)
875 if( patients.size() > 0 )
877 ListDicomDirPatient::iterator itp = patients.end();
880 if( (*itp)->GetDicomDirStudies().size() > 0 )
882 ListDicomDirStudy::iterator itst = (*itp)->GetDicomDirStudies().end();
885 if( (*itst)->GetDicomDirSeries().size() > 0 )
887 ListDicomDirSerie::iterator its = (*itst)->GetDicomDirSeries().end();
889 (*its)->AddDicomDirImage(new gdcmDicomDirImage(s, &TagHT));
896 * \ingroup gdcmDicomDir
897 * \brief for each Header of the chained list, add/update the Patient/Study/Serie/Image info
898 * @param path path of the root directory
899 * @param list chained list of Headers
901 void gdcmDicomDir::SetElements(std::string &path, VectDocument &list)
903 std::string patPrevName = "", patPrevID = "";
904 std::string studPrevInstanceUID = "", studPrevID = "";
905 std::string serPrevInstanceUID = "", serPrevID = "";
907 std::string patCurName, patCurID;
908 std::string studCurInstanceUID, studCurID;
909 std::string serCurInstanceUID, serCurID;
911 //SetElement( path, GDCM_DICOMDIR_META,NULL); // already done (NewMeta)
913 for( VectDocument::iterator it = list.begin();
914 it != list.end(); ++it )
916 // get the current file characteristics
917 patCurName = (*it)->GetEntryByNumber(0x0010,0x0010);
918 patCurID = (*it)->GetEntryByNumber(0x0010,0x0011);
919 studCurInstanceUID = (*it)->GetEntryByNumber(0x0020,0x000d);
920 studCurID = (*it)->GetEntryByNumber(0x0020,0x0010);
921 serCurInstanceUID = (*it)->GetEntryByNumber(0x0020,0x000e);
922 serCurID = (*it)->GetEntryByNumber(0x0020,0x0011);
924 if( patCurName != patPrevName || patCurID != patPrevID)
926 SetElement(path, GDCM_DICOMDIR_PATIENT, *it);
929 // if new Study Deal with 'STUDY' Elements
930 if( studCurInstanceUID != studPrevInstanceUID || studCurID != studPrevID )
932 SetElement(path, GDCM_DICOMDIR_STUDY, *it);
935 // if new Serie Deal with 'SERIE' Elements
936 if( serCurInstanceUID != serPrevInstanceUID || serCurID != serPrevID )
938 SetElement(path, GDCM_DICOMDIR_SERIE, *it);
941 // Always Deal with 'IMAGE' Elements
942 SetElement(path, GDCM_DICOMDIR_IMAGE, *it);
944 patPrevName = patCurName;
945 patPrevID = patCurID;
946 studPrevInstanceUID = studCurInstanceUID;
947 studPrevID = studCurID;
948 serPrevInstanceUID = serCurInstanceUID;
949 serPrevID = serCurID;
954 * \ingroup gdcmDicomDir
955 * \brief compares two dgcmHeaders
957 bool gdcmDicomDir::HeaderLessThan(gdcmDocument *header1, gdcmDocument *header2)
960 std::cout <<header1->GetFileName() << " " << header2->GetFileName() <<std::endl;
961 return *header1 < *header2;
965 * \brief Sets the accurate value for the (0x0004,0x1220) element of a DICOMDIR
967 void gdcmDicomDir::UpdateDirectoryRecordSequenceLength()
970 /// \todo FIXME : to go on compiling
972 /// to be re written !
974 /// ListTag::iterator it;
977 /// for(it=listEntries.begin();it!=listEntries.end();++it) {
978 /// gr = (*it)->GetGroup();
979 /// el = (*it)->GetElement();
980 /// vr = (*it)->GetVR();
981 /// if (gr !=0xfffe) {
982 /// if ( (vr == "OB") || (vr == "OW") || (vr == "SQ") ) {
983 /// offset += 4; // explicit VR AND OB, OW, SQ : 4 more bytes
985 /// offset += 2 + 2 + 4 + (*it)->GetLength();
987 /// offset += 4; // delimiters don't have a value.
990 /// //bool res=SetEntryLengthByNumber(offset, 0x0004, 0x1220); // Hope there is no dupps.
991 /// SetEntryLengthByNumber(offset, 0x0004, 0x1220); // Hope there is no dupps.
996 //-----------------------------------------------------------------------------