X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=src%2FgdcmDicomDir.cxx;h=2f19e2432703aae4b464030cb15b5e6736a5ed26;hb=e70a7e5ba954ce367c4b1bce03f6c7065cd45edf;hp=606a6437c252791d1f3187e9d511e94685b27ba5;hpb=6ae0c7b2171502cfc859786a4380efa7bcabcb2f;p=gdcm.git diff --git a/src/gdcmDicomDir.cxx b/src/gdcmDicomDir.cxx index 606a6437..2f19e243 100644 --- a/src/gdcmDicomDir.cxx +++ b/src/gdcmDicomDir.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmDicomDir.cxx,v $ Language: C++ - Date: $Date: 2005/07/08 19:07:12 $ - Version: $Revision: 1.146 $ + Date: $Date: 2005/10/25 14:52:33 $ + Version: $Revision: 1.167 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -21,6 +21,7 @@ // PS 3.3-2003, pages 731-750 //----------------------------------------------------------------------------- #include "gdcmDicomDir.h" +#include "gdcmDicomDirObject.h" #include "gdcmDicomDirStudy.h" #include "gdcmDicomDirSerie.h" #include "gdcmDicomDirVisit.h" @@ -35,7 +36,7 @@ #include "gdcmFile.h" #include "gdcmSeqEntry.h" #include "gdcmSQItem.h" -#include "gdcmValEntry.h" +#include "gdcmDataEntry.h" #include #include @@ -99,7 +100,8 @@ // // (Root directory Entity) PATIENT // PATIENT STUDY -// STUDY SERIES +// STUDY SERIES +// STUDY VISIT // SERIES IMAGE // IMAGE / // @@ -122,44 +124,19 @@ DicomDir::DicomDir() NewMeta(); } -/** - * \brief Constructor Parses recursively the directory and creates the DicomDir - * or uses an already built DICOMDIR, depending on 'parseDir' value. - * @param fileName name - * - of the root directory (parseDir = true) - * - of the DICOMDIR (parseDir = false) - * @param parseDir boolean - * - true if user passed an entry point - * and wants to explore recursively the directories - * - false if user passed an already built DICOMDIR file - * and wants to use it - */ -DicomDir::DicomDir(std::string const &fileName, bool parseDir ): - Document( ) -{ - // At this step, Document constructor is already executed, - // whatever user passed (either a root directory or a DICOMDIR) - // and whatever the value of parseDir was. - // (nothing is cheked in Document constructor, to avoid overhead) - - ParseDir = parseDir; - SetLoadMode (0x00000000); // concerns only dicom files - Load( fileName ); -} - /** * \brief Canonical destructor */ DicomDir::~DicomDir() { - SetStartMethod(NULL); - SetProgressMethod(NULL); - SetEndMethod(NULL); + SetStartMethod(NULL,NULL,NULL); + SetProgressMethod(NULL,NULL,NULL); + SetEndMethod(NULL,NULL,NULL); ClearPatient(); if ( MetaElems ) { - delete MetaElems; + MetaElems->Delete(); } } @@ -167,42 +144,46 @@ DicomDir::~DicomDir() // Public /** - * \brief Loader. use SetLoadMode(), SetFileName() before ! + * \brief Loader. use SetFileName(fn) + * or SetLoadMode(lm) + SetDirectoryName(dn) before ! * @return false if file cannot be open or no swap info was found, * or no tag was found. */ bool DicomDir::Load( ) { - // We should clean out anything that already exists. - Initialize(); // sets all private fields to NULL - if (!ParseDir) { if ( ! this->Document::Load( ) ) return false; } - return DoTheLoadingJob( ); + return DoTheLoadingJob( ); } -/** - * \brief Loader. (DEPRECATED : not to break the API) - * @param fileName file to be open for parsing - * @return false if file cannot be open or no swap info was found, +#ifndef GDCM_LEGACY_REMOVE +/* * + * \ brief Loader. (DEPRECATED : kept not to break the API) + * @ param fileName file to be open for parsing + * @ return false if file cannot be open or no swap info was found, * or no tag was found. + * @ deprecated use SetFileName(n) + Load() instead */ bool DicomDir::Load(std::string const &fileName ) { - // We should clean out anything that already exists. - Initialize(); // sets all private fields to NULL + SetFileName(fileName); + return Load(); +} - SetFileName( fileName ); - if (!ParseDir) - { - if ( ! this->Document::Load( ) ) - return false; - } - return DoTheLoadingJob( ); +/// DEPRECATED : use SetDirectoryName(dname) instead +/* * + * \brief Loader. (DEPRECATED : kept not to break the API) + * @param paseDir Parse Dir + * @deprecated use SetDirectoryName(dname) instead + */ +void DicomDir::SetParseDir(bool parseDir) +{ + ParseDir = parseDir; } +#endif /** * \brief Does the Loading Job (internal use only) @@ -211,18 +192,14 @@ bool DicomDir::Load(std::string const &fileName ) */ bool DicomDir::DoTheLoadingJob( ) { - // We should clean out anything that already exists. - Initialize(); // sets all private fields to NULL + Progress = 0.0f; + Abort = false; if (!ParseDir) { // Only if user passed a DICOMDIR // ------------------------------ Fp = 0; - if ( !OpenFile() ) - { - return false; - } if (!Document::Load() ) { return false; @@ -299,12 +276,12 @@ bool DicomDir::IsReadable() DicomDirMeta *DicomDir::NewMeta() { if ( MetaElems ) - delete MetaElems; + MetaElems->Delete(); DocEntry *entry = GetFirstEntry(); if ( entry ) { - MetaElems = new DicomDirMeta(true); // true = empty + MetaElems = DicomDirMeta::New(true); // true = empty entry = GetFirstEntry(); while( entry ) @@ -312,15 +289,15 @@ DicomDirMeta *DicomDir::NewMeta() if ( dynamic_cast(entry) ) break; - RemoveEntryNoDestroy(entry); MetaElems->AddEntry(entry); + RemoveEntry(entry); entry = GetFirstEntry(); } } else // after root directory parsing { - MetaElems = new DicomDirMeta(false); // false = not empty + MetaElems = DicomDirMeta::New(false); // false = not empty } MetaElems->SetSQItemNumber(0); // To avoid further missprinting return MetaElems; @@ -332,9 +309,9 @@ DicomDirMeta *DicomDir::NewMeta() */ DicomDirPatient *DicomDir::NewPatient() { - DicomDirPatient *p = new DicomDirPatient(); - AddPatientToEnd( p ); - return p; + DicomDirPatient *dd = DicomDirPatient::New(); + AddPatientToEnd( dd ); + return dd; } /** @@ -346,7 +323,7 @@ void DicomDir::ClearPatient() cc!= Patients.end(); ++cc) { - delete *cc; + (*cc)->Unregister(); } Patients.clear(); } @@ -387,6 +364,21 @@ void DicomDir::ParseDirectory() CreateDicomDir(); } +void DicomDir::SetStartMethod( DicomDir::Method *method, void *arg ) +{ + SetStartMethod(method,arg,NULL); +} + +void DicomDir::SetProgressMethod( DicomDir::Method *method, void *arg ) +{ + SetProgressMethod(method,arg,NULL); +} + +void DicomDir::SetEndMethod( DicomDir::Method *method, void *arg ) +{ + SetEndMethod(method,arg,NULL); +} + /** * \brief Set the start method to call when the parsing of the * directory starts. @@ -491,7 +483,7 @@ void DicomDir::SetEndMethodArgDelete( DicomDir::Method *method ) * @return false only when fail to open */ -bool DicomDir::WriteDicomDir(std::string const &fileName) +bool DicomDir::Write(std::string const &fileName) { int i; uint16_t sq[4] = { 0x0004, 0x1220, 0xffff, 0xffff }; @@ -543,9 +535,9 @@ bool DicomDir::WriteDicomDir(std::string const &fileName) * @return true */ -bool DicomDir::AnonymizeDicomDir() +bool DicomDir::Anonymize() { - ValEntry *v; + DataEntry *v; // Something clever to be found to forge the Patient names std::ostringstream s; int i = 1; @@ -554,22 +546,22 @@ bool DicomDir::AnonymizeDicomDir() ++cc) { s << i; - v = (*cc)->GetValEntry(0x0010, 0x0010) ; // Patient's Name + v = (*cc)->GetDataEntry(0x0010, 0x0010) ; // Patient's Name if (v) { - v->SetValue(s.str()); + v->SetString(s.str()); } - v = (*cc)->GetValEntry(0x0010, 0x0020) ; // Patient ID + v = (*cc)->GetDataEntry(0x0010, 0x0020) ; // Patient ID if (v) { - v->SetValue(" "); + v->SetString(" "); } - v = (*cc)->GetValEntry(0x0010, 0x0030) ; // Patient's BirthDate + v = (*cc)->GetDataEntry(0x0010, 0x0030) ; // Patient's BirthDate if (v) { - v->SetValue(" "); + v->SetString(" "); } s << ""; i++; @@ -604,16 +596,12 @@ void DicomDir::CreateDicomDirChainedList(std::string const &path) break; } - f = new File( ); - f->SetLoadMode(LoadMode); // we allow user not to load Sequences... - f->Load( it->c_str() ); + f = File::New( ); + f->SetLoadMode(LoadMode); // we allow user not to load Sequences, or Shadow + // groups, or ...... + f->SetFileName( it->c_str() ); + f->Load( ); -// if ( !f ) -// { -// gdcmWarningMacro( "Failure in new gdcm::File " << it->c_str() ); -// continue; -// } - if ( f->IsReadable() ) { // Add the file to the chained list: @@ -622,7 +610,7 @@ void DicomDir::CreateDicomDirChainedList(std::string const &path) } else { - delete f; + f->Delete(); } count++; } @@ -638,7 +626,7 @@ void DicomDir::CreateDicomDirChainedList(std::string const &path) itDoc!=list.end(); ++itDoc) { - delete dynamic_cast(*itDoc); + dynamic_cast(*itDoc)->Delete(); } } @@ -713,6 +701,7 @@ void DicomDir::CreateDicomDir() // 3 - we find an other tag // + we create the object for the precedent tag // + loop to 1 - + gdcmDebugMacro("Create DicomDir"); // Directory record sequence DocEntry *e = GetDocEntry(0x0004, 0x1220); @@ -739,13 +728,13 @@ void DicomDir::CreateDicomDir() while(tmpSI) { d = tmpSI->GetDocEntry(0x0004, 0x1430); // Directory Record Type - if ( ValEntry* valEntry = dynamic_cast(d) ) + if ( DataEntry *dataEntry = dynamic_cast(d) ) { - v = valEntry->GetValue(); + v = dataEntry->GetString(); } else { - gdcmWarningMacro( "(0004,1430) not a ValEntry ?!?"); + gdcmWarningMacro( "(0004,1430) not a DataEntry ?!?"); continue; } @@ -755,50 +744,50 @@ void DicomDir::CreateDicomDir() if ( v == "IMAGE " ) { - si = new DicomDirImage(true); + si = DicomDirImage::New(true); if ( !AddImageToEnd( static_cast(si)) ) { - delete si; + si->Delete(); si = NULL; gdcmErrorMacro( "Add AddImageToEnd failed"); } } else if ( v == "SERIES" ) { - si = new DicomDirSerie(true); + si = DicomDirSerie::New(true); if ( !AddSerieToEnd( static_cast(si)) ) { - delete si; + si->Delete(); si = NULL; gdcmErrorMacro( "Add AddSerieToEnd failed"); } } else if ( v == "VISIT " ) { - si = new DicomDirVisit(true); + si = DicomDirVisit::New(true); if ( !AddVisitToEnd( static_cast(si)) ) { - delete si; + si->Delete(); si = NULL; gdcmErrorMacro( "Add AddVisitToEnd failed"); } } else if ( v == "STUDY " ) { - si = new DicomDirStudy(true); + si = DicomDirStudy::New(true); if ( !AddStudyToEnd( static_cast(si)) ) { - delete si; + si->Delete(); si = NULL; gdcmErrorMacro( "Add AddStudyToEnd failed"); } } else if ( v == "PATIENT " ) { - si = new DicomDirPatient(true); + si = DicomDirPatient::New(true); if ( !AddPatientToEnd( static_cast(si)) ) { - delete si; + si->Delete(); si = NULL; gdcmErrorMacro( "Add PatientToEnd failed"); } @@ -816,7 +805,7 @@ void DicomDir::CreateDicomDir() continue; } if ( si ) - MoveSQItem(si,tmpSI); + si->MoveObject(tmpSI); // New code : Copies the List tmpSI=s->GetNextSQItem(); } @@ -940,12 +929,12 @@ void DicomDir::SetElements(std::string const &path, VectDocument const &list) ++it ) { // get the current file characteristics - 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); + patCurName = (*it)->GetEntryString(0x0010,0x0010); + patCurID = (*it)->GetEntryString(0x0010,0x0011); + studCurInstanceUID = (*it)->GetEntryString(0x0020,0x000d); + studCurID = (*it)->GetEntryString(0x0020,0x0010); + serCurInstanceUID = (*it)->GetEntryString(0x0020,0x000e); + serCurID = (*it)->GetEntryString(0x0020,0x0011); if ( patCurName != patPrevName || patCurID != patPrevID || first ) { @@ -996,7 +985,7 @@ void DicomDir::SetElement(std::string const &path, DicomDirType type, ListDicomDirElem::const_iterator it; uint16_t tmpGr, tmpEl; DictEntry *dictEntry; - ValEntry *entry; + DataEntry *entry; std::string val; SQItem *si; @@ -1004,49 +993,49 @@ void DicomDir::SetElement(std::string const &path, DicomDirType type, { case GDCM_DICOMDIR_IMAGE: elemList = Global::GetDicomDirElements()->GetDicomDirImageElements(); - si = new DicomDirImage(true); + si = DicomDirImage::New(true); if ( !AddImageToEnd(static_cast(si)) ) { - delete si; + si->Delete(); gdcmErrorMacro( "Add ImageToEnd failed"); } break; case GDCM_DICOMDIR_SERIE: elemList = Global::GetDicomDirElements()->GetDicomDirSerieElements(); - si = new DicomDirSerie(true); + si = DicomDirSerie::New(true); if ( !AddSerieToEnd(static_cast(si)) ) { - delete si; + si->Delete(); gdcmErrorMacro( "Add SerieToEnd failed"); } break; case GDCM_DICOMDIR_STUDY: elemList = Global::GetDicomDirElements()->GetDicomDirStudyElements(); - si = new DicomDirStudy(true); + si = DicomDirStudy::New(true); if ( !AddStudyToEnd(static_cast(si)) ) { - delete si; + si->Delete(); gdcmErrorMacro( "Add StudyToEnd failed"); } break; case GDCM_DICOMDIR_PATIENT: elemList = Global::GetDicomDirElements()->GetDicomDirPatientElements(); - si = new DicomDirPatient(true); + si = DicomDirPatient::New(true); if ( !AddPatientToEnd(static_cast(si)) ) { - delete si; + si->Delete(); gdcmErrorMacro( "Add PatientToEnd failed"); } break; case GDCM_DICOMDIR_META: - elemList = Global::GetDicomDirElements()->GetDicomDirMetaElements(); - si = new DicomDirMeta(true); if ( MetaElems ) { - delete MetaElems; + MetaElems->Delete(); gdcmErrorMacro( "MetaElements already exist, they will be destroyed"); } - MetaElems = static_cast(si); + elemList = Global::GetDicomDirElements()->GetDicomDirMetaElements(); + MetaElems = DicomDirMeta::New(true); + si = MetaElems; break; default: return; @@ -1068,15 +1057,14 @@ void DicomDir::SetElement(std::string const &path, DicomDirType type, tmpEl = it->Elem; dictEntry = GetPubDict()->GetEntry(tmpGr, tmpEl); - entry = new ValEntry( dictEntry ); // Be sure it's never a BinEntry ! - + entry = DataEntry::New( dictEntry ); 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->GetEntryValue(tmpGr, tmpEl); + val = header->GetEntryString(tmpGr, tmpEl); } else { @@ -1113,13 +1101,14 @@ void DicomDir::SetElement(std::string const &path, DicomDirType type, val = it->Value; } - entry->SetValue( val ); // troubles expected when vr=SQ ... + entry->SetString( val ); // troubles expected when vr=SQ ... if ( type == GDCM_DICOMDIR_META ) // fusible : should never print ! { gdcmWarningMacro("GDCM_DICOMDIR_META ?!? should never print that"); } si->AddEntry(entry); + entry->Delete(); } } @@ -1130,13 +1119,13 @@ void DicomDir::SetElement(std::string const &path, DicomDirType type, * @param src source SQItem */ void DicomDir::MoveSQItem(DocEntrySet *dst,DocEntrySet *src) -{ +{ DocEntry *entry; entry = src->GetFirstEntry(); while(entry) { - src->RemoveEntryNoDestroy(entry); + src->RemoveEntry(entry); dst->AddEntry(entry); // we destroyed -> the current iterator is not longer valid entry = src->GetFirstEntry();