Program: gdcm
Module: $RCSfile: gdcmDicomDir.cxx,v $
Language: C++
- Date: $Date: 2005/01/20 16:16:41 $
- Version: $Revision: 1.111 $
+ Date: $Date: 2005/02/02 10:02:16 $
+ Version: $Revision: 1.126 $
Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
l'Image). All rights reserved. See Doc/License.txt or
=========================================================================*/
+//-----------------------------------------------------------------------------
+// For full DICOMDIR description, see:
+// PS 3.3-2003, pages 731-750
+//-----------------------------------------------------------------------------
#include "gdcmDicomDir.h"
#include "gdcmDicomDirStudy.h"
#include "gdcmDicomDirSerie.h"
#include "gdcmUtil.h"
#include "gdcmDebug.h"
#include "gdcmGlobal.h"
-#include "gdcmHeader.h"
+#include "gdcmFile.h"
#include "gdcmSeqEntry.h"
#include "gdcmSQItem.h"
#include "gdcmValEntry.h"
namespace gdcm
{
-
-//-----------------------------------------------------------------------------
-// For full DICOMDIR description, see:
-// PS 3.3-2003, pages 731-750
//-----------------------------------------------------------------------------
// Constructor / Destructor
-
/**
* \brief Constructor : creates an empty DicomDir
*/
DicomDir::DicomDir()
- :Document( )
+ :Document( )
{
Initialize(); // sets all private fields to NULL
NewMeta();
/**
* \brief Constructor Parses recursively the directory and creates the DicomDir
* or uses an already built DICOMDIR, depending on 'parseDir' value.
- * @param fileName name
+ * @param fileName name
* - of the root directory (parseDir = true)
* - of the DICOMDIR (parseDir = false)
* @param parseDir boolean
Initialize(); // sets all private fields to NULL
// if user passed a root directory, sure we didn't get anything
- if ( TagHT.begin() == TagHT.end() ) // when user passed a Directory to parse
+
+ if ( GetFirstEntry() == 0 ) // when user passed a Directory to parse
{
if (!parseDir)
gdcmVerboseMacro( "Entry HT empty for file: "<<fileName);
SetProgressMethod(NULL);
SetEndMethod(NULL);
- for(ListDicomDirPatient::iterator cc = Patients.begin();
- cc!= Patients.end();
- ++cc)
- {
- delete *cc;
- }
+ ClearPatient();
if ( MetaElems )
{
delete MetaElems;
}
}
-//-----------------------------------------------------------------------------
-// Print
-/**
- * \brief Canonical Printer
- */
-void DicomDir::Print(std::ostream &os, std::string const & )
-{
- if( MetaElems )
- {
- MetaElems->SetPrintLevel(PrintLevel);
- MetaElems->Print(os);
- }
- for(ListDicomDirPatient::iterator cc = Patients.begin();
- cc != Patients.end();
- ++cc)
- {
- (*cc)->SetPrintLevel(PrintLevel);
- (*cc)->Print(os);
- }
-}
-
//-----------------------------------------------------------------------------
// Public
/**
* \brief This predicate, based on hopefully reasonable heuristics,
- * decides whether or not the current header was properly parsed
+ * decides whether or not the current document was properly parsed
* and contains the mandatory information for being considered as
* a well formed and usable DicomDir.
* @return true when Document is the one of a reasonable DicomDir,
DicomDirPatient *DicomDir::GetNextPatient()
{
gdcmAssertMacro (ItPatient != Patients.end());
- {
- ++ItPatient;
- if ( ItPatient != Patients.end() )
- return *ItPatient;
- }
+
+ ++ItPatient;
+ if ( ItPatient != Patients.end() )
+ return *ItPatient;
return NULL;
}
//-----------------------------------------------------------------------------
// 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)
+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;
+ File *header;
DirListType fileList = dirList.GetFilenames();
break;
}
- header = new Header( it->c_str() );
+ header = new File( it->c_str() );
if( !header )
{
- gdcmVerboseMacro( "Failure in new Header " << it->c_str() );
+ gdcmVerboseMacro( "Failure in new gdcm::File " << it->c_str() );
continue;
}
if( header->IsReadable() )
{
- // Add the file header to the chained list:
+ // Add the file to the chained list:
list.push_back(header);
gdcmVerboseMacro( "Readable " << it->c_str() );
}
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
+ //for each File of the chained list, add/update the Patient/Study/Serie/Image info
SetElements(tmp, list);
CallEndMethod();
itDoc!=list.end();
++itDoc)
{
- delete dynamic_cast<Header *>(*itDoc);
+ delete dynamic_cast<File *>(*itDoc);
}
}
/**
* \brief adds *the* Meta to a partially created DICOMDIR
- */
-
-DicomDirMeta * DicomDir::NewMeta()
+ */
+DicomDirMeta *DicomDir::NewMeta()
{
if( MetaElems )
delete MetaElems;
-
- if ( TagHT.begin() != TagHT.end() ) // after Document Parsing
+ DocEntry *entry = GetFirstEntry();
+ if( entry )
{
MetaElems = new DicomDirMeta(true);
- 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)
+ entry = GetFirstEntry();
+ while( entry )
{
- MetaElems->AddEntry( cc->second );
+ if( dynamic_cast<SeqEntry *>(entry) )
+ break;
+
+ RemoveEntryNoDestroy(entry);
+ MetaElems->AddEntry(entry);
+
+ entry = GetFirstEntry();
}
}
else // after root directory parsing
}
/**
- * \brief adds a new Patient (with the basic elements) to a partially created DICOMDIR
+ * \brief adds a new Patient (with the basic elements) to a partially created
+ * DICOMDIR
*/
DicomDirPatient *DicomDir::NewPatient()
{
return p;
}
+/**
+ * \brief Remove all Patients
+ */
+void DicomDir::ClearPatient()
+{
+ for(ListDicomDirPatient::iterator cc = Patients.begin();
+ cc!= Patients.end();
+ ++cc)
+ {
+ delete *cc;
+ }
+ Patients.clear();
+}
+
/**
* \brief adds to the HTable
* the Entries (Dicom Elements) corresponding to the given type
// 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);
+ dictEntry = GetPubDict()->GetEntry(tmpGr, tmpEl);
entry = new ValEntry( dictEntry ); // Be sure it's never a BinEntry !
{
// NULL when we Build Up (ex nihilo) a DICOMDIR
// or when we add the META elems
- val = header->GetEntry(tmpGr, tmpEl);
+ val = header->GetEntryValue(tmpGr, tmpEl);
}
else
{
}
}
-//-----------------------------------------------------------------------------
/**
* \brief CallStartMethod
*/
}
}
-//-----------------------------------------------------------------------------
/**
* \brief CallProgressMethod
*/
}
}
-//-----------------------------------------------------------------------------
/**
* \brief CallEndMethod
*/
*/
void DicomDir::CreateDicomDir()
{
- // The list is parsed.
+ // The SeqEntries of "Directory Record Sequence" are parsed.
// When a DicomDir tag ("PATIENT", "STUDY", "SERIE", "IMAGE") is found :
// 1 - we save the beginning iterator
// 2 - we continue to parse
DocEntry *e = GetDocEntry(0x0004, 0x1220);
if ( !e )
{
- gdcmVerboseMacro( "NO Directory record sequence (0x0004,0x1220)");
+ gdcmVerboseMacro( "No Directory Record Sequence (0004,1220) found");
/// \todo FIXME: what to do when the parsed file IS NOT a DICOMDIR file ?
return;
}
SeqEntry *s = dynamic_cast<SeqEntry *>(e);
if ( !s )
{
- gdcmVerboseMacro( "No SeqEntry present");
- // useless : (0x0004,0x1220) IS a Sequence !
+ gdcmVerboseMacro( "Element (0004,1220) is not a Sequence ?!?");
return;
}
NewMeta();
-
- //ListSQItem listItems = s->GetSQItems();
DocEntry *d;
std::string v;
// neither an 'IMAGE' SQItem. Skip to next item.
continue;
}
-
if( si )
MoveSQItem(si,tmpSI);
tmpSI=s->GetNextSQItem();
}
- TagHT.clear();
+ ClearEntry();
}
/**
study->AddSerie(dd);
return true;
}
-/* if( (*itp)->GetDicomDirStudies().size() > 0 )
- {
- ListDicomDirStudy::const_iterator itst =
- (*itp)->GetDicomDirStudies().end();
- itst--;
- (*itst)->AddSerie(dd);
- return true;
- }*/
}
return false;
}
return true;
}
}
-/* if( (*itp)->GetDicomDirStudies().size() > 0 )
- {
- ListDicomDirStudy::const_iterator itst =
- (*itp)->GetDicomDirStudies().end();
- itst--;
-
- if( (*itst)->GetDicomDirSeries().size() > 0 )
- {
- ListDicomDirSerie::const_iterator its = (*itst)->GetDicomDirSeries().end();
- its--;
- (*its)->AddImage(dd);
- return true;
- }
- }*/
}
return false;
}
/**
- * \brief for each Header of the chained list, add/update the Patient/Study/Serie/Image info
+ * \brief for each Header of the chained list,
+ * add/update the Patient/Study/Serie/Image info
* @param path path of the root directory
* @param list chained list of Headers
*/
void DicomDir::SetElements(std::string const & path, VectDocument const &list)
{
- TagHT.clear();
- Patients.clear();
+ ClearEntry();
+ ClearPatient();
std::string patPrevName = "", patPrevID = "";
std::string studPrevInstanceUID = "", studPrevID = "";
it != list.end(); ++it )
{
// get the current file characteristics
- patCurName = (*it)->GetEntry(0x0010,0x0010);
- patCurID = (*it)->GetEntry(0x0010,0x0011);
- studCurInstanceUID = (*it)->GetEntry(0x0020,0x000d);
- studCurID = (*it)->GetEntry(0x0020,0x0010);
- serCurInstanceUID = (*it)->GetEntry(0x0020,0x000e);
- serCurID = (*it)->GetEntry(0x0020,0x0011);
+ patCurName = (*it)->GetEntryValue(0x0010,0x0010);
+ patCurID = (*it)->GetEntryValue(0x0010,0x0011);
+ studCurInstanceUID = (*it)->GetEntryValue(0x0020,0x000d);
+ studCurID = (*it)->GetEntryValue(0x0020,0x0010);
+ serCurInstanceUID = (*it)->GetEntryValue(0x0020,0x000e);
+ serCurID = (*it)->GetEntryValue(0x0020,0x0011);
if( patCurName != patPrevName || patCurID != patPrevID || first )
{
* @param dst destination SQItem
* @param src source SQItem
*/
-void DicomDir::MoveSQItem(SQItem *dst,SQItem *src)
+void DicomDir::MoveSQItem(DocEntrySet *dst,DocEntrySet *src)
{
DocEntry *entry;
}
/**
- * \brief compares two dgcmHeaders
+ * \brief compares two files
*/
bool DicomDir::HeaderLessThan(Document *header1, Document *header2)
{
return *header1 < *header2;
}
-} // end namespace gdcm
+//-----------------------------------------------------------------------------
+// Print
+/**
+ * \brief Canonical Printer
+ * @param os ostream we want to print in
+ * @param indent Indentation string to be prepended during printing
+ */
+void DicomDir::Print(std::ostream &os, std::string const & )
+{
+ if( MetaElems )
+ {
+ MetaElems->SetPrintLevel(PrintLevel);
+ MetaElems->Print(os);
+ }
+ for(ListDicomDirPatient::iterator cc = Patients.begin();
+ cc != Patients.end();
+ ++cc)
+ {
+ (*cc)->SetPrintLevel(PrintLevel);
+ (*cc)->Print(os);
+ }
+}
//-----------------------------------------------------------------------------
+} // end namespace gdcm