+/**
+ * \ingroup gdcmDicomDir
+ * \brief create a gdcmDocument-like chained list from a root Directory
+ * @param path entry point of the tree-like structure
+ */
+void gdcmDicomDir::CreateDicomDirChainedList(std::string path)
+{
+ CallStartMethod();
+
+ gdcmDirList fileList(path,1); // gets recursively the file list
+ unsigned int count=0;
+ ListHeader list;
+ gdcmHeader *header;
+
+ tagHT.clear();
+ patients.clear();
+
+ for(gdcmDirList::iterator it=fileList.begin();
+ it!=fileList.end();
+ ++it)
+ {
+ progress=(float)(count+1)/(float)fileList.size();
+ CallProgressMethod();
+ if(abort)
+ break;
+
+ header=new gdcmHeader(it->c_str());
+ if(header->IsReadable())
+ list.push_back(header); // adds the file header to the chained list
+ else
+ delete header;
+
+ count++;
+ }
+ // sorts Patient/Study/Serie/
+ std::sort(list.begin(),list.end(),gdcmDicomDir::HeaderLessThan);
+
+ std::string tmp=fileList.GetDirName();
+
+ //for each Header of the chained list, add/update the Patient/Study/Serie/Image info
+ SetElements(tmp,list);
+
+ CallEndMethod();
+}
+
+/**
+ * \ingroup gdcmDicomDir
+ * \brief adds *the* Meta to a partially created DICOMDIR
+ */
+
+ // FIXME : Heuuuuu ! Il prend les Entries du Document deja parse,
+ // il ne fabrique rien !
+
+gdcmDicomDirMeta * gdcmDicomDir::NewMeta(void) {
+ gdcmDicomDirMeta *m = new gdcmDicomDirMeta(&tagHT);
+ for (TagDocEntryHT::iterator cc = tagHT.begin();cc != tagHT.end();++cc) {
+ m->AddDocEntry(cc->second);
+ }
+ return m;
+}
+
+
+/**
+ * \ingroup gdcmDicomDir
+ * \brief adds a new Patient (with the basic elements) to a partially created DICOMDIR
+ */
+gdcmDicomDirPatient * gdcmDicomDir::NewPatient(void) {
+ std::list<gdcmElement> elemList;
+ std::list<gdcmElement>::iterator it;
+ guint16 tmpGr,tmpEl;
+ gdcmDictEntry *dictEntry;
+ gdcmValEntry *entry;
+
+ gdcmSQItem *s = new gdcmSQItem(0);
+
+ elemList=gdcmGlobal::GetDicomDirElements()->GetDicomDirPatientElements();
+
+ // TODO : use FillObject !!!
+
+ // for all the DicomDirPatient Elements
+
+ for(it=elemList.begin();it!=elemList.end();++it)
+ {
+ tmpGr=it->group;
+ tmpEl=it->elem;
+ dictEntry=GetPubDict()->GetDictEntryByNumber(tmpGr,tmpEl);
+ entry=new gdcmValEntry(dictEntry);
+ entry->SetOffset(0); // just to avoid further missprinting
+ entry->SetValue(it->value);
+
+ // dealing with value length ...
+
+ if(dictEntry->GetGroup()==0xfffe)
+ {
+ entry->SetLength(entry->GetValue().length());
+ }
+ else if( (dictEntry->GetVR()=="UL") || (dictEntry->GetVR()=="SL") )
+ {
+ entry->SetLength(4);
+ }
+ else if( (dictEntry->GetVR()=="US") || (dictEntry->GetVR()=="SS") )
+ {
+ entry->SetLength(2);
+ }
+ else if(dictEntry->GetVR()=="SQ")
+ {
+ entry->SetLength(0xffffffff);
+ }
+ else
+ {
+ entry->SetLength(entry->GetValue().length());
+ }
+ s->AddDocEntry(entry);
+ }
+
+ gdcmDicomDirPatient *p = new gdcmDicomDirPatient(s, &tagHT);
+ patients.push_front(p);
+ return p;
+}
+
+
+/**
+ * \ingroup gdcmDicomDir
+ * \brief adds to the HTable
+ * the gdcmEntries (Dicom Elements) corresponding to the given type
+ * @param path full path file name (only used when type = GDCM_DICOMDIR_IMAGE
+ * @param type gdcmObject type to create (GDCM_DICOMDIR_PATIENT, GDCM_DICOMDIR_STUDY, GDCM_DICOMDIR_SERIE ...)
+ * @param header gdcmHeader of the current file
+ */
+void gdcmDicomDir::SetElement(std::string &path,gdcmDicomDirType type,gdcmHeader *header)
+{
+ std::list<gdcmElement> elemList;
+ std::list<gdcmElement>::iterator it;
+ guint16 tmpGr, tmpEl;
+ gdcmDictEntry *dictEntry;
+ gdcmDocEntry *entry;
+ std::string val;
+
+ switch(type)
+ {
+ case GDCM_DICOMDIR_PATIENT:
+ elemList=gdcmGlobal::GetDicomDirElements()->GetDicomDirPatientElements();
+ break;
+ case GDCM_DICOMDIR_STUDY:
+ elemList=gdcmGlobal::GetDicomDirElements()->GetDicomDirStudyElements();
+ break;
+ case GDCM_DICOMDIR_SERIE:
+ elemList=gdcmGlobal::GetDicomDirElements()->GetDicomDirSerieElements();
+ break;
+ case GDCM_DICOMDIR_IMAGE:
+ elemList=gdcmGlobal::GetDicomDirElements()->GetDicomDirImageElements();
+ break;
+ case GDCM_DICOMDIR_META:
+ elemList=gdcmGlobal::GetDicomDirElements()->GetDicomDirMetaElements();
+ break;
+ default:
+ return;
+ }
+
+ for(it=elemList.begin();it!=elemList.end();++it)
+ {
+ tmpGr=it->group;
+ tmpEl=it->elem;
+ dictEntry=GetPubDict()->GetDictEntryByNumber(tmpGr,tmpEl);
+ entry=new gdcmDocEntry(dictEntry);
+ entry->SetOffset(0); // just to avoid further missprinting
+
+ if(header)
+ val=header->GetEntryByNumber(tmpGr,tmpEl);
+ else
+ val=GDCM_UNFOUND;
+
+ if(val==GDCM_UNFOUND)
+ {
+ if((tmpGr==0x0004) &&(tmpEl==0x1130) ) // File-set ID
+ {
+ // force to the *end* File Name
+ val=GetName(path);
+ }
+ else if( (tmpGr==0x0004) && (tmpEl==0x1500) ) // Only used for image
+ {
+ if(header->GetFileName().substr(0,path.length())!=path)
+ {
+ dbg.Verbose(0, "gdcmDicomDir::SetElement : the base path of file name is incorrect");
+ val=header->GetFileName();
+ }
+ else {
+ val=&(header->GetFileName().c_str()[path.length()]);
+ }
+ }
+ else
+ {
+ val=it->value;
+ }
+ }
+ else
+ {
+ if (header->GetEntryLengthByNumber(tmpGr,tmpEl)== 0)
+ val=it->value;
+ }
+
+ ((gdcmValEntry *)entry)->SetValue(val);
+
+ if(dictEntry)
+ {
+ if(dictEntry->GetGroup()==0xfffe)
+ {
+ entry->SetLength(((gdcmValEntry *)entry)->GetValue().length());
+ }
+ else if( (dictEntry->GetVR()=="UL") || (dictEntry->GetVR()=="SL") )
+ {
+ entry->SetLength(4);
+ }
+ else if( (dictEntry->GetVR()=="US") || (dictEntry->GetVR()=="SS") )
+ {
+ entry->SetLength(2);
+ }
+ else if(dictEntry->GetVR()=="SQ")
+ {
+ entry->SetLength(0xffffffff);
+ }
+ else
+ {
+ entry->SetLength(((gdcmValEntry *)entry)->GetValue().length());
+ }
+ }
+ //AddDocEntry(entry); // both in H Table and in chained list
+ tagHT[entry->GetKey()] = entry; // FIXME : use a SEQUENCE !
+ }
+}
+/**
+ * \ingroup gdcmDicomDir
+ * \brief CallStartMethod
+ */
+void gdcmDicomDir::CallStartMethod(void)
+{
+ progress=0.0f;
+ abort=false;
+ if(startMethod)
+ startMethod(startArg);
+}
+/**
+ * \ingroup gdcmDicomDir
+ * \brief CallProgressMethod
+ */
+void gdcmDicomDir::CallProgressMethod(void)
+{
+ if(progressMethod)
+ progressMethod(progressArg);
+}
+/**
+ * \ingroup gdcmDicomDir
+ * \brief CallEndMethod
+ */
+void gdcmDicomDir::CallEndMethod(void)
+{
+ progress=1.0f;
+ if(endMethod)
+ endMethod(endArg);
+}
+