- return true;
-}
-
-//-----------------------------------------------------------------------------
-// Protected
-
-/**
- * \brief create a Document-like chained list from a root Directory
- * @param path entry point of the tree-like structure
- */
-void DicomDir::CreateDicomDirChainedList(std::string const & path)
-{
- CallStartMethod();
- DirList dirList(path,1); // gets recursively the file list
- unsigned int count = 0;
- VectDocument list;
- Header *header;
-
- DirListType fileList = dirList.GetFilenames();
-
- for( DirListType::iterator it = fileList.begin();
- it != fileList.end();
- ++it )
- {
- Progress = (float)(count+1)/(float)fileList.size();
- CallProgressMethod();
- if( Abort )
- {
- break;
- }
-
- header = new Header( it->c_str() );
- if( !header )
- {
- gdcmVerboseMacro( "Failure in new Header " << it->c_str() );
- continue;
- }
-
- if( header->IsReadable() )
- {
- // Add the file header to the chained list:
- list.push_back(header);
- gdcmVerboseMacro( "Readable " << it->c_str() );
- }
- else
- {
- delete header;
- }
- count++;
- }
- // sorts Patient/Study/Serie/
- std::sort(list.begin(), list.end(), DicomDir::HeaderLessThan );
-
- std::string tmp = dirList.GetDirName();
- //for each Header of the chained list, add/update the Patient/Study/Serie/Image info
- SetElements(tmp, list);
- CallEndMethod();
-
- for(VectDocument::iterator itDoc=list.begin();
- itDoc!=list.end();
- ++itDoc)
- {
- delete dynamic_cast<Header *>(*itDoc);
- }
-}
-
-/**
- * \brief adds *the* Meta to a partially created DICOMDIR
- */
-
-DicomDirMeta * DicomDir::NewMeta()
-{
- if( MetaElems )
- delete MetaElems;
-
- MetaElems = new DicomDirMeta();
-
- if ( TagHT.begin() != TagHT.end() ) // after Document Parsing
- {
- TagDocEntryHT::iterator lastOneButSequence = TagHT.end();
- lastOneButSequence --;
- // ALL the 'out of Sequence' Tags belong to Meta Elems
- // (we skip 0004|1220 [Directory record sequence] )
- for ( TagDocEntryHT::iterator cc = TagHT.begin();
- cc != lastOneButSequence;
- ++cc)
- {
- MetaElems->AddEntry( cc->second );
- }
- }
- else // after root directory parsing
- {
- ListDicomDirMetaElem const &elemList =
- Global::GetDicomDirElements()->GetDicomDirMetaElements();
- MetaElems->FillObject(elemList);
- }
- MetaElems->SetSQItemNumber(0); // To avoid further missprinting
- return MetaElems;
-}
-
-/**
- * \brief adds a new Patient (with the basic elements) to a partially created DICOMDIR
- */
-DicomDirPatient *DicomDir::NewPatient()
-{
- ListDicomDirPatientElem::const_iterator it;
- uint16_t tmpGr,tmpEl;
- DictEntry *dictEntry;
- ValEntry *entry;
-
- ListDicomDirPatientElem const & elemList =
- Global::GetDicomDirElements()->GetDicomDirPatientElements();
- DicomDirPatient *p = new DicomDirPatient();
-
- // for all the DicomDirPatient Elements
- for( it = elemList.begin(); it != elemList.end(); ++it )
- {
- tmpGr = it->Group;
- tmpEl = it->Elem;
- dictEntry = GetPubDict()->GetDictEntry(tmpGr, tmpEl);
- entry = new ValEntry( dictEntry );
- entry->SetOffset(0); // just to avoid further missprinting
- entry->SetValue( it->Value );
-
- p->AddEntry( entry );
- }
-
- AddPatientToEnd( p );
- return p;
-}
-
-/**
- * \brief adds to the HTable
- * the Entries (Dicom Elements) corresponding to the given type
- * @param path full path file name (only used when type = GDCM_DICOMDIR_IMAGE
- * @param type DicomDirObject type to create (GDCM_DICOMDIR_PATIENT,
- * GDCM_DICOMDIR_STUDY, GDCM_DICOMDIR_SERIE ...)
- * @param header Header of the current file
- */
-void DicomDir::SetElement(std::string const &path, DicomDirType type,
- Document *header)
-{
- ListDicomDirElem elemList; //FIXME this is going to be a by copy operation
- ListDicomDirElem::const_iterator it;
- uint16_t tmpGr, tmpEl;
- DictEntry *dictEntry;
- ValEntry *entry;
- std::string val;
- SQItem *si;
-
- switch( type )
- {
- case GDCM_DICOMDIR_IMAGE:
- elemList = Global::GetDicomDirElements()->GetDicomDirImageElements();
- si = new DicomDirImage();
- if( !AddImageToEnd(static_cast<DicomDirImage *>(si)) )
- {
- delete si;
- gdcmErrorMacro( "Add ImageToEnd failed");
- }
- break;
- case GDCM_DICOMDIR_SERIE:
- elemList = Global::GetDicomDirElements()->GetDicomDirSerieElements();
- si = new DicomDirSerie();
- if( !AddSerieToEnd(static_cast<DicomDirSerie *>(si)) )
- {
- delete si;
- gdcmErrorMacro( "Add SerieToEnd failed");
- }
- break;
- case GDCM_DICOMDIR_STUDY:
- elemList = Global::GetDicomDirElements()->GetDicomDirStudyElements();
- si = new DicomDirStudy();
- if( !AddStudyToEnd(static_cast<DicomDirStudy *>(si)) )
- {
- delete si;
- gdcmErrorMacro( "Add StudyToEnd failed");
- }
- break;
- case GDCM_DICOMDIR_PATIENT:
- elemList = Global::GetDicomDirElements()->GetDicomDirPatientElements();
- si = new DicomDirPatient();
- if( !AddPatientToEnd(static_cast<DicomDirPatient *>(si)) )
- {
- delete si;
- gdcmErrorMacro( "Add PatientToEnd failed");
- }
- break;
- case GDCM_DICOMDIR_META:
- elemList = Global::GetDicomDirElements()->GetDicomDirMetaElements();
- si = new DicomDirMeta();
- if( MetaElems )
- {
- delete MetaElems;
- gdcmErrorMacro( "MetaElements already exist, they will be destroyed");
- }
- MetaElems = static_cast<DicomDirMeta *>(si);
- break;
- default:
- return;
- }
- // removed all the seems-to-be-useless stuff about Referenced Image Sequence
- // to avoid further troubles
- // imageElem 0008 1140 "" // Referenced Image Sequence
- // imageElem fffe e000 "" // 'no length' item : length to be set to 0xffffffff later
- // imageElem 0008 1150 "" // Referenced SOP Class UID : to be set/forged later
- // imageElem 0008 1155 "" // Referenced SOP Instance UID : to be set/forged later
- // imageElem fffe e00d "" // Item delimitation : length to be set to ZERO later
- // for all the relevant elements found in their own spot of the DicomDir.dic
- // FIXME : troubles found when it's a SeqEntry
-
- for( it = elemList.begin(); it != elemList.end(); ++it)
- {
- tmpGr = it->Group;
- tmpEl = it->Elem;
- dictEntry = GetPubDict()->GetDictEntry(tmpGr, tmpEl);
-
- entry = new ValEntry( dictEntry ); // Be sure it's never a BinEntry !
-
- entry->SetOffset(0); // just to avoid further missprinting
-
- if( header )
- {
- // NULL when we Build Up (ex nihilo) a DICOMDIR
- // or when we add the META elems
- val = header->GetEntry(tmpGr, tmpEl);
- }
- else
- {
- val = GDCM_UNFOUND;
- }
-
- if( val == GDCM_UNFOUND)