2 //-----------------------------------------------------------------------------
14 #include "gdcmDicomDir.h"
15 #include "gdcmDicomDirStudy.h"
16 #include "gdcmDicomDirSerie.h"
17 #include "gdcmDicomDirImage.h"
18 #include "gdcmDirList.h"
20 #include "gdcmDebug.h"
22 //-----------------------------------------------------------------------------
23 // For full DICOMDIR description, see:
24 // PS 3.3-2003, pages 731-750
25 //-----------------------------------------------------------------------------
27 // Constructor / Destructor
30 * \ingroup gdcmDicomDir
31 * \brief Constructor Parses recursively the directory and creates the DicomDir
32 * or uses an already built DICOMDIR, depending on 'parseDir' value
33 * @param FileName name
34 - of the root directory (parseDir = true)
35 * - of the DICOMDIR (parseDir = false)
36 * @param parseDir boolean
37 * - true if user passed an entry point
38 * and wants to explore recursively the directories
39 * - false if user passed an already built DICOMDIR file
41 * @param exception_on_error whether we want to throw an exception or not
43 gdcmDicomDir::gdcmDicomDir(const char *FileName, bool parseDir,
44 bool exception_on_error):
45 gdcmParser(FileName,exception_on_error,true) // true : enable SeQuences
47 // que l'on ai passe un root directory ou un DICOMDIR
48 // et quelle que soit la valeur de parseDir,
49 // on a lance gdcmParser
54 startMethodArgDelete= NULL;
55 progressMethodArgDelete=NULL;
56 endMethodArgDelete= NULL;
66 // gdcmParser already executed
67 // if user passed a root directory, sure we didn't get anything
69 if( GetListEntry().begin()==GetListEntry().end() )
71 // if parseDir == false, it should be tagged as an error
72 dbg.Verbose(0, "gdcmDicomDir::gdcmDicomDir : entry list empty");
74 if(strlen(FileName)==1 && FileName[0]=='.') { // user passed '.' as Name
75 // we get current directory name
76 char*dummy=(char*) malloc(1000);
77 getcwd(dummy,(size_t)1000);
78 SetFileName(dummy); // will be converted into a string
79 free(dummy); // no longer needed
84 dbg.Verbose(0, "gdcmDicomDir::gdcmDicomDir : Parse directory"
85 " and create the DicomDir");
91 CheckBoundaries(); // to maintain consistency between
92 // home-made gdcmDicomDir
93 // and the ones comming from a DICOMDIR file
98 * \ingroup gdcmDicomDir
99 * \brief Constructor : creates an empty gdcmDicomDir
100 * @param exception_on_error whether we want to throw an exception or not
102 gdcmDicomDir::gdcmDicomDir(bool exception_on_error):
103 gdcmParser(exception_on_error)
106 progressMethod= NULL;
108 startMethodArgDelete= NULL;
109 progressMethodArgDelete=NULL;
110 endMethodArgDelete= NULL;
117 std::string pathBidon = ""; // Sorry, NULL not allowed ...
118 SetElement(pathBidon, GDCM_DICOMDIR_META, NULL); // Set the META elements
120 AddDicomDirMetaToEnd(listEntries.begin(),--listEntries.end());
125 * \ingroup gdcmDicomDir
126 * \brief Canonical destructor
128 gdcmDicomDir::~gdcmDicomDir()
130 SetStartMethod(NULL);
131 SetProgressMethod(NULL);
137 for(ListDicomDirPatient::iterator cc=patients.begin();cc!=patients.end();++cc)
143 //-----------------------------------------------------------------------------
146 * \ingroup gdcmDicomDir
147 * \brief Canonical Printer
149 void gdcmDicomDir::Print(std::ostream &os)
153 metaElems->SetPrintLevel(printLevel);
154 metaElems->Print(os);
156 for(ListDicomDirPatient::iterator cc=patients.begin();cc!=patients.end();++cc)
158 (*cc)->SetPrintLevel(printLevel);
163 //-----------------------------------------------------------------------------
166 * \ingroup gdcmDicomDir
167 * \brief This predicate, based on hopefully reasonable heuristics,
168 * decides whether or not the current header was properly parsed
169 * and contains the mandatory information for being considered as
170 * a well formed and usable DicomDir.
171 * @return true when gdcmParser is the one of a reasonable DicomDir,
174 bool gdcmDicomDir::IsReadable(void)
176 if(!gdcmParser::IsReadable())
180 if(patients.size()<=0)
187 * \ingroup gdcmDicomDir
188 * \brief fills the whole structure, starting from a root Directory
190 void gdcmDicomDir::ParseDirectory(void)
192 CreateDicomDirChainedList(GetFileName());
197 * \ingroup gdcmDicomDir
198 * \brief Set the start method to call when the parsing of the directory starts
199 * @param method Method to call
200 * @param arg Argument to pass to the method
201 * @param argDelete Argument
202 * \warning In python : the arg parameter isn't considered
204 void gdcmDicomDir::SetStartMethod(gdcmMethod *method,void *arg,gdcmMethod *argDelete)
206 if((startArg)&&(startMethodArgDelete))
207 startMethodArgDelete(startArg);
211 startMethodArgDelete=argDelete;
215 * \ingroup gdcmDicomDir
216 * \brief Set the method to delete the argument
217 * The argument is destroyed when the method is changed or when the
219 * @param method Method to call to delete the argument
221 void gdcmDicomDir::SetStartMethodArgDelete(gdcmMethod *method)
223 startMethodArgDelete=method;
227 * \ingroup gdcmDicomDir
228 * \brief Set the progress method to call when the parsing of the directory progress
229 * @param method Method to call
230 * @param arg Argument to pass to the method
231 * @param argDelete Argument
232 * \warning In python : the arg parameter isn't considered
234 void gdcmDicomDir::SetProgressMethod(gdcmMethod *method,void *arg,gdcmMethod *argDelete)
236 if((progressArg)&&(progressMethodArgDelete))
237 progressMethodArgDelete(progressArg);
239 progressMethod=method;
241 progressMethodArgDelete=argDelete;
245 * \ingroup gdcmDicomDir
246 * \brief Set the method to delete the argument
247 * The argument is destroyed when the method is changed or when the
249 * @param method Method to call to delete the argument
251 void gdcmDicomDir::SetProgressMethodArgDelete(gdcmMethod *method)
253 progressMethodArgDelete=method;
257 * \ingroup gdcmDicomDir
258 * \brief Set the end method to call when the parsing of the directory ends
259 * @param method Method to call
260 * @param arg Argument to pass to the method
261 * @param argDelete Argument
262 * \warning In python : the arg parameter isn't considered
264 void gdcmDicomDir::SetEndMethod(gdcmMethod *method, void *arg, gdcmMethod *argDelete)
266 if((endArg)&&(endMethodArgDelete))
267 endMethodArgDelete(endArg);
271 endMethodArgDelete=argDelete;
275 * \ingroup gdcmDicomDir
276 * \brief Set the method to delete the argument
277 * The argument is destroyed when the method is changed or when the class
279 * @param method Method to call to delete the argument
281 void gdcmDicomDir::SetEndMethodArgDelete(gdcmMethod *method)
283 endMethodArgDelete=method;
287 * \ingroup gdcmDicomDir
288 * \brief writes on disc a DICOMDIR
289 * \ warning does NOT add the missing elements in the header :
290 * it's up to the user doing it !
291 * \todo : to be re-written using the DICOMDIR tree-like structure
292 * *not* the chained list
293 * (does NOT exist if the DICOMDIR is user-forged !)
294 * @param fileName file to be written to
295 * @return false only when fail to open
298 bool gdcmDicomDir::Write(std::string fileName)
302 fp1=fopen(fileName.c_str(),"wb");
305 printf("Failed to open(write) File [%s] \n",fileName.c_str());
310 filePreamble=(char*)calloc(128,1);
311 fwrite(filePreamble,128,1,fp1);
312 fwrite("DICM",4,1,fp1);
314 UpdateDirectoryRecordSequenceLength();
315 WriteDicomDirEntries(fp1);
322 * \ingroup gdcmParser
323 * \brief writes on disc according to the DICOMDIR format
324 * using the tree-like structure
325 * @param _fp already open file pointer
328 void gdcmDicomDir::WriteDicomDirEntries(FILE *_fp)
330 // TODO (?) tester les echecs en ecriture
331 // (apres chaque fwrite, dans le WriteEntry)
333 gdcmDicomDirMeta *ptrMeta;
334 ListDicomDirPatient::iterator itPatient;
335 ListDicomDirStudy::iterator itStudy;
336 ListDicomDirSerie::iterator itSerie;
337 ListDicomDirImage::iterator itImage;
340 ptrMeta= GetDicomDirMeta();
341 for(i=ptrMeta->debut();i!=ptrMeta->fin();++i) {
342 WriteEntry(*i,_fp,DICOMDIR);
345 itPatient = GetDicomDirPatients().begin();
346 while ( itPatient != GetDicomDirPatients().end() ) {
347 for(i=(*itPatient)->debut();i!=(*itPatient)->fin();++i) {
348 WriteEntry(*i,_fp,DICOMDIR);
350 itStudy = ((*itPatient)->GetDicomDirStudies()).begin();
351 while (itStudy != (*itPatient)->GetDicomDirStudies().end() ) {
352 for(i=(*itStudy)->debut();i!=(*itStudy)->fin();++i) {
353 WriteEntry(*i,_fp,DICOMDIR);
355 itSerie = ((*itStudy)->GetDicomDirSeries()).begin();
356 while (itSerie != (*itStudy)->GetDicomDirSeries().end() ) {
357 for(i=(*itSerie)->debut();i!=(*itSerie)->fin();++i) {
358 WriteEntry(*i,_fp,DICOMDIR);
360 itImage = ((*itSerie)->GetDicomDirImages()).begin();
361 while (itImage != (*itSerie)->GetDicomDirImages().end() ) {
362 for(i=(*itImage)->debut();i!=(*itImage)->fin();++i) {
363 WriteEntry(*i,_fp,DICOMDIR);
375 //-----------------------------------------------------------------------------
379 * \ingroup gdcmDicomDir
380 * \brief create a gdcmHeader-like chained list from a root Directory
381 * @param path entry point of the tree-like structure
383 void gdcmDicomDir::CreateDicomDirChainedList(std::string path)
387 gdcmDirList fileList(path,1); // gets recursively the file list
388 unsigned int count=0;
395 for(gdcmDirList::iterator it=fileList.begin();
399 progress=(float)(count+1)/(float)fileList.size();
400 CallProgressMethod();
404 header=new gdcmHeader(it->c_str());
405 if(header->IsReadable())
406 list.push_back(header); // adds the file header to the chained list
412 // sorts Patient/Study/Serie/
413 std::sort(list.begin(),list.end(),gdcmDicomDir::HeaderLessThan);
415 std::string tmp=fileList.GetDirName();
417 //for each Header of the chained list, add/update the Patient/Study/Serie/Image info
418 SetElements(tmp,list);
424 * \ingroup gdcmDicomDir
425 * \brief modifies the limits of a gdcmObject, created from a DICOMDIR file
428 void gdcmDicomDir::CheckBoundaries()
430 ListDicomDirPatient::iterator itPatient;
431 ListDicomDirStudy::iterator itStudy;
432 ListDicomDirSerie::iterator itSerie;
433 ListDicomDirImage::iterator itImage;
434 ListTag::iterator i,j;
436 GetDicomDirMeta()->ResetBoundaries(0);
438 itPatient = GetDicomDirPatients().begin();
439 while ( itPatient != GetDicomDirPatients().end() ) {
440 (*itPatient)->ResetBoundaries(1);
441 itStudy = ((*itPatient)->GetDicomDirStudies()).begin();
442 while (itStudy != (*itPatient)->GetDicomDirStudies().end() ) {
443 (*itStudy)->ResetBoundaries(1);
444 itSerie = ((*itStudy)->GetDicomDirSeries()).begin();
445 while (itSerie != (*itStudy)->GetDicomDirSeries().end() ) {
446 (*itSerie)->ResetBoundaries(1);
447 itImage = ((*itSerie)->GetDicomDirImages()).begin();
448 while (itImage != (*itSerie)->GetDicomDirImages().end() ) {
449 (*itImage)->ResetBoundaries(1);
462 * \ingroup gdcmDicomDir
463 * \brief adds a new Patient to a partially created DICOMDIR
465 gdcmDicomDirPatient * gdcmDicomDir::NewPatient(void) {
466 std::list<gdcmElement> elemList;
467 std::list<gdcmElement>::iterator it;
469 gdcmDictEntry *dictEntry;
470 gdcmHeaderEntry *entry;
472 elemList=gdcmGlobal::GetDicomDirElements()->GetDicomDirPatientElements();
473 std::list<gdcmHeaderEntry *>::iterator debInsertion, finInsertion, i,j;
475 debInsertion = metaElems->fin();
477 finInsertion=debInsertion;
479 // for all the DicomDirPatient Elements
480 for(it=elemList.begin();it!=elemList.end();++it)
484 dictEntry=GetPubDict()->GetDictEntryByNumber(tmpGr,tmpEl);
485 entry=new gdcmHeaderEntry(dictEntry);
486 entry->SetOffset(0); // just to avoid missprinting
487 entry->SetValue(it->value);
489 if(dictEntry->GetGroup()==0xfffe)
491 entry->SetLength(entry->GetValue().length());
493 else if( (dictEntry->GetVR()=="UL") || (dictEntry->GetVR()=="SL") )
497 else if( (dictEntry->GetVR()=="US") || (dictEntry->GetVR()=="SS") )
501 else if(dictEntry->GetVR()=="SQ")
503 entry->SetLength(0xffffffff);
507 entry->SetLength(entry->GetValue().length());
510 tagHT.insert( PairHT(entry->GetKey(),entry) ); // add in the (multimap) H Table
511 listEntries.insert(debInsertion ,entry); // en tete de liste des Patients
518 gdcmDicomDirPatient *p = new gdcmDicomDirPatient(i, --debInsertion,
519 &tagHT, &listEntries);
520 patients.push_front(p);
525 * \ingroup gdcmDicomDir
526 * \brief CallStartMethod
528 void gdcmDicomDir::CallStartMethod(void)
533 startMethod(startArg);
536 * \ingroup gdcmDicomDir
537 * \brief CallProgressMethod
539 void gdcmDicomDir::CallProgressMethod(void)
542 progressMethod(progressArg);
545 * \ingroup gdcmDicomDir
546 * \brief CallEndMethod
548 void gdcmDicomDir::CallEndMethod(void)
555 //-----------------------------------------------------------------------------
558 * \ingroup gdcmDicomDir
559 * \brief create a 'gdcmDicomDir' from a DICOMDIR gdcmHeader
561 void gdcmDicomDir::CreateDicomDir()
563 // The list is parsed.
564 // When a DicomDir tag ("PATIENT", "STUDY", "SERIE", "IMAGE") is found :
565 // 1 - we save the beginning iterator
566 // 2 - we continue to parse
567 // 3 - we find an other tag
568 // + we create the object for the precedent tag
571 gdcmDicomDirType type=gdcmDicomDir::GDCM_DICOMDIR_META;
572 ListTag::iterator begin;
573 ListTag::iterator end, end2;
575 begin=listEntries.begin();
577 for(ListTag::iterator i=end;i !=listEntries.end();++i)
579 std::string v=(*i)->GetValue();
583 AddObjectToEnd(type,begin,--end2);
584 type=gdcmDicomDir::GDCM_DICOMDIR_PATIENT;
591 AddObjectToEnd(type,begin,--end2);
592 type=gdcmDicomDir::GDCM_DICOMDIR_STUDY;
599 AddObjectToEnd(type,begin,--end2);
600 type=gdcmDicomDir::GDCM_DICOMDIR_SERIE;
607 AddObjectToEnd(type,begin,--end2);
608 type=gdcmDicomDir::GDCM_DICOMDIR_IMAGE;
613 end=end2=listEntries.end();
615 AddObjectToEnd(type,begin,--end2);
618 * \ingroup gdcmDicomDir
619 * \brief AddObjectToEnd
621 * @param begin iterator on the first HeaderEntry within the chained List
622 * @param end iterator on the last HeaderEntry within the chained List
624 void gdcmDicomDir::AddObjectToEnd(gdcmDicomDirType type,ListTag::iterator begin,ListTag::iterator end)
631 case gdcmDicomDir::GDCM_DICOMDIR_META:
632 AddDicomDirMetaToEnd(begin,end);
634 case gdcmDicomDir::GDCM_DICOMDIR_PATIENT:
635 AddDicomDirPatientToEnd(begin,end);
637 case gdcmDicomDir::GDCM_DICOMDIR_STUDY:
638 AddDicomDirStudyToEnd(begin,end);
640 case gdcmDicomDir::GDCM_DICOMDIR_SERIE:
641 AddDicomDirSerieToEnd(begin,end);
643 case gdcmDicomDir::GDCM_DICOMDIR_IMAGE:
644 AddDicomDirImageToEnd(begin,end);
650 * \ingroup gdcmDicomDir
651 * \brief Well ... Not realy to end, there is only one occurence
652 * @param begin iterator on the first HeaderEntry within the chained List
653 * @param end iterator on the last HeaderEntry within the chained List
655 void gdcmDicomDir::AddDicomDirMetaToEnd(ListTag::iterator begin,ListTag::iterator end)
659 metaElems = new gdcmDicomDirMeta(begin,end,&tagHT,&listEntries);
663 * \ingroup gdcmDicomDir
664 * \brief AddDicomDirPatientToEnd
665 * @param begin iterator on the first HeaderEntry within the chained List
666 * @param end iterator on the last HeaderEntry within the chained List
668 void gdcmDicomDir::AddDicomDirPatientToEnd(ListTag::iterator begin,ListTag::iterator end)
670 patients.push_back(new gdcmDicomDirPatient(begin,end,&tagHT, &listEntries));
674 * \ingroup gdcmDicomDir
675 * \brief AddDicomDirStudyToEnd
676 * @param begin iterator on the first HeaderEntry within the chained List
677 * @param end iterator on the last HeaderEntry within the chained List
679 void gdcmDicomDir::AddDicomDirStudyToEnd(ListTag::iterator begin,ListTag::iterator end)
681 if(patients.size()>0)
683 ListDicomDirPatient::iterator itp=patients.end();
685 (*itp)->AddDicomDirStudy(new gdcmDicomDirStudy(begin,end,&tagHT, &listEntries));
689 * \ingroup gdcmDicomDir
690 * \brief AddDicomDirSerieToEnd
691 * @param begin iterator on the first HeaderEntry within the chained List
692 * @param end iterator on the last HeaderEntry within the chained List
694 void gdcmDicomDir::AddDicomDirSerieToEnd(ListTag::iterator begin,ListTag::iterator end)
696 if(patients.size()>0)
698 ListDicomDirPatient::iterator itp=patients.end();
701 if((*itp)->GetDicomDirStudies().size()>0)
703 ListDicomDirStudy::iterator itst=(*itp)->GetDicomDirStudies().end();
705 (*itst)->AddDicomDirSerie(new gdcmDicomDirSerie(begin,end,&tagHT, &listEntries));
711 * \ingroup gdcmDicomDir
712 * \brief AddDicomDirImageToEnd
713 * @param begin iterator on the first HeaderEntry within the chained List
714 * @param end iterator on the last HeaderEntry within the chained List
716 void gdcmDicomDir::AddDicomDirImageToEnd(ListTag::iterator begin,ListTag::iterator end)
718 if(patients.size()>0)
720 ListDicomDirPatient::iterator itp=patients.end();
723 if((*itp)->GetDicomDirStudies().size()>0)
725 ListDicomDirStudy::iterator itst=(*itp)->GetDicomDirStudies().end();
728 if((*itst)->GetDicomDirSeries().size()>0)
730 ListDicomDirSerie::iterator its=(*itst)->GetDicomDirSeries().end();
732 (*its)->AddDicomDirImage(new gdcmDicomDirImage(begin,end,&tagHT, &listEntries));
739 * \ingroup gdcmDicomDir
740 * \brief for each Header of the chained list, add/update the Patient/Study/Serie/Image info
741 * @param path path of the root directory
742 * @param list chained list of Headers
744 void gdcmDicomDir::SetElements(std::string &path, ListHeader &list)
746 std::string patPrevName="", patPrevID="";
747 std::string studPrevInstanceUID="", studPrevID="";
748 std::string serPrevInstanceUID="", serPrevID="";
750 std::string patCurName, patCurID;
751 std::string studCurInstanceUID, studCurID;
752 std::string serCurInstanceUID, serCurID;
754 SetElement(path,GDCM_DICOMDIR_META,NULL);
756 ListTag::iterator debPat=listEntries.begin();
757 for(ListHeader::iterator it=list.begin();it!=list.end();++it)
759 // get the current file characteristics
760 patCurName= (*it)->GetEntryByNumber(0x0010,0x0010);
761 patCurID= (*it)->GetEntryByNumber(0x0010,0x0011);
762 studCurInstanceUID=(*it)->GetEntryByNumber(0x0020,0x000d);
763 studCurID= (*it)->GetEntryByNumber(0x0020,0x0010);
764 serCurInstanceUID= (*it)->GetEntryByNumber(0x0020,0x000e);
765 serCurID= (*it)->GetEntryByNumber(0x0020,0x0011);
767 if(patCurName!=patPrevName || patCurID!=patPrevID)
768 SetElement(path,GDCM_DICOMDIR_PATIENT,*it);
770 // if new Study Deal with 'STUDY' Elements
771 if(studCurInstanceUID!=studPrevInstanceUID || studCurID!=studPrevID)
772 SetElement(path,GDCM_DICOMDIR_STUDY,*it);
774 // if new Serie Deal with 'SERIE' Elements
775 if(serCurInstanceUID!=serPrevInstanceUID || serCurID!=serPrevID)
776 SetElement(path,GDCM_DICOMDIR_SERIE,*it);
778 // Always Deal with 'IMAGE' Elements
779 SetElement(path,GDCM_DICOMDIR_IMAGE,*it);
781 patPrevName= patCurName;
783 studPrevInstanceUID=studCurInstanceUID;
784 studPrevID= studCurID;
785 serPrevInstanceUID= serCurInstanceUID;
791 * \ingroup gdcmDicomDir
792 * \brief adds to the HTable and at the end of the Chained List
793 * the gdcmEntries (Dicom Elements) corresponding to the given type
794 * @param path full path file name(only used when type = GDCM_DICOMDIR_IMAGE
795 * @param type gdcmObject type to create (GDCM_DICOMDIR_PATIENT, GDCM_DICOMDIR_STUDY, GDCM_DICOMDIR_SERIE ...)
796 * @param header gdcmHeader of the current file
798 void gdcmDicomDir::SetElement(std::string &path,gdcmDicomDirType type,gdcmHeader *header)
800 std::list<gdcmElement> elemList;
801 std::list<gdcmElement>::iterator it;
802 guint16 tmpGr, tmpEl;
803 gdcmDictEntry *dictEntry;
804 gdcmHeaderEntry *entry;
809 case GDCM_DICOMDIR_PATIENT:
810 elemList=gdcmGlobal::GetDicomDirElements()->GetDicomDirPatientElements();
812 case GDCM_DICOMDIR_STUDY:
813 elemList=gdcmGlobal::GetDicomDirElements()->GetDicomDirStudyElements();
815 case GDCM_DICOMDIR_SERIE:
816 elemList=gdcmGlobal::GetDicomDirElements()->GetDicomDirSerieElements();
818 case GDCM_DICOMDIR_IMAGE:
819 elemList=gdcmGlobal::GetDicomDirElements()->GetDicomDirImageElements();
821 case GDCM_DICOMDIR_META:
822 elemList=gdcmGlobal::GetDicomDirElements()->GetDicomDirMetaElements();
828 for(it=elemList.begin();it!=elemList.end();++it)
832 dictEntry=GetPubDict()->GetDictEntryByNumber(tmpGr,tmpEl);
833 entry=new gdcmHeaderEntry(dictEntry);
834 entry->SetOffset(0); // just to avoid missprinting
837 val=header->GetEntryByNumber(tmpGr,tmpEl);
841 if(val==GDCM_UNFOUND)
843 if((tmpGr==0x0004) &&(tmpEl==0x1130) ) // File-set ID
845 // force to the *end* File Name
848 else if( (tmpGr==0x0004) && (tmpEl==0x1500) ) // Only used for image
850 if(header->GetFileName().substr(0,path.length())!=path)
852 dbg.Verbose(0, "gdcmDicomDir::SetElement : the base path of file name is incorrect");
853 val=header->GetFileName();
856 val=&(header->GetFileName().c_str()[path.length()]);
866 if (header->GetEntryLengthByNumber(tmpGr,tmpEl)== 0)
870 entry->SetValue(val);
874 if(dictEntry->GetGroup()==0xfffe)
876 entry->SetLength(entry->GetValue().length());
878 else if( (dictEntry->GetVR()=="UL") || (dictEntry->GetVR()=="SL") )
882 else if( (dictEntry->GetVR()=="US") || (dictEntry->GetVR()=="SS") )
886 else if(dictEntry->GetVR()=="SQ")
888 entry->SetLength(0xffffffff);
892 entry->SetLength(entry->GetValue().length());
895 //AddHeaderEntry(entry); // both in H Table and in chained list
896 tagHT.insert( PairHT( entry->GetKey(),entry) );
897 listEntries.push_back(entry);
898 //wasUpdated = 1; // is private
902 * \ingroup gdcmDicomDir
903 * \brief compares two dgcmHeaders
905 bool gdcmDicomDir::HeaderLessThan(gdcmHeader *header1,gdcmHeader *header2)
907 return(*header1<*header2);
911 * \ingroup gdcmDicomDir
912 * \brief Sets the accurate value for the (0x0004,0x1220) element of a DICOMDIR
915 void gdcmDicomDir::UpdateDirectoryRecordSequenceLength() {
917 ListTag::iterator it;
920 for(it=listEntries.begin();it!=listEntries.end();++it) {
921 gr = (*it)->GetGroup();
922 el = (*it)->GetElement();
925 if ( (vr == "OB") || (vr == "OW") || (vr == "SQ") ) {
926 offset += 4; // explicit VR AND OB, OW, SQ : 4 more bytes
928 offset += 2 + 2 + 4 + (*it)->GetLength();
930 offset += 4; // delimiters don't have a value.
933 bool res=SetEntryLengthByNumber(offset, 0x0004, 0x1220); // Hope there is no dupps.
937 //-----------------------------------------------------------------------------