X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=src%2FgdcmDicomDir.cxx;h=fa59a3b765139fd27d02be25a2a511383e524319;hb=81fe774739a1629471fcc2705549fa56dad44a70;hp=b8501864e7d4907f7125c4d1cbfe911fe34aafcf;hpb=f24973b3daa0b2214838857d02bd61db6d4a0a40;p=gdcm.git diff --git a/src/gdcmDicomDir.cxx b/src/gdcmDicomDir.cxx index b8501864..fa59a3b7 100644 --- a/src/gdcmDicomDir.cxx +++ b/src/gdcmDicomDir.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmDicomDir.cxx,v $ Language: C++ - Date: $Date: 2004/07/17 22:36:55 $ - Version: $Revision: 1.56 $ + Date: $Date: 2004/07/21 14:02:10 $ + Version: $Revision: 1.58 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -46,25 +46,21 @@ //----------------------------------------------------------------------------- // Constructor / Destructor -void gdcmDicomDir::Initialize() -{ - startMethod = NULL; - progressMethod = NULL; - endMethod = NULL; - startMethodArgDelete = NULL; - progressMethodArgDelete = NULL; - endMethodArgDelete = NULL; - startArg = NULL; - progressArg = NULL; - endArg = NULL; - - progress = 0.0; - abort = false; +/** + * \ingroup gdcmDicomDir + * \brief Constructor : creates an empty gdcmDicomDir + * @param exception_on_error whether we want to throw an exception or not + */ +gdcmDicomDir::gdcmDicomDir(bool exception_on_error): + gdcmDocument( exception_on_error ) +{ + Initialize(); - metaElems = (gdcmDicomDirMeta *)0; + std::string pathBidon = "Bidon"; // Sorry, NULL not allowed ... + SetElement(pathBidon, GDCM_DICOMDIR_META, NULL); // Set the META elements + AddDicomDirMeta(); } - /** * \brief Constructor Parses recursively the directory and creates the DicomDir * or uses an already built DICOMDIR, depending on 'parseDir' value. @@ -90,21 +86,22 @@ gdcmDicomDir::gdcmDicomDir(std::string const & fileName, bool parseDir, // gdcmDocument already executed // if user passed a root directory, sure we didn't get anything - if( GetEntry().begin() == GetEntry().end() ) + if ( TagHT.begin() == TagHT.end() ) { dbg.Verbose(0, "gdcmDicomDir::gdcmDicomDir : entry HT empty"); - if( fileName.size() == 1 && fileName[0] == '.' ) + if ( fileName.size() == 1 && fileName[0] == '.' ) { // user passed '.' as Name // we get current directory name char* dummy = new char[1000]; getcwd(dummy, (size_t)1000); + std::cout << "Directory to parse : [" << dummy << "]" << std::endl; SetFileName( dummy ); // will be converted into a string - delete[] dummy; // no longer needed + delete[] dummy; // no longer needed } - if( parseDir ) + if ( parseDir ) { dbg.Verbose(0, "gdcmDicomDir::gdcmDicomDir : Parse directory" " and create the DicomDir"); @@ -113,6 +110,8 @@ gdcmDicomDir::gdcmDicomDir(std::string const & fileName, bool parseDir, else { /// \todo if parseDir == false, it should be tagged as an error + // NON ! il suffit d'appeler ParseDirectory() + // apres le constructeur } } else @@ -130,21 +129,6 @@ gdcmDicomDir::gdcmDicomDir(std::string const & fileName, bool parseDir, } } -/** - * \ingroup gdcmDicomDir - * \brief Constructor : creates an empty gdcmDicomDir - * @param exception_on_error whether we want to throw an exception or not - */ -gdcmDicomDir::gdcmDicomDir(bool exception_on_error): - gdcmDocument( exception_on_error ) -{ - Initialize(); - - std::string pathBidon = "Bidon"; // Sorry, NULL not allowed ... - SetElement(pathBidon, GDCM_DICOMDIR_META, NULL); // Set the META elements - AddDicomDirMeta(); -} - /** * \brief Canonical destructor */ @@ -154,7 +138,7 @@ gdcmDicomDir::~gdcmDicomDir() SetProgressMethod(NULL); SetEndMethod(NULL); - if( metaElems ) + if ( metaElems ) { delete metaElems; } @@ -176,14 +160,14 @@ void gdcmDicomDir::Print(std::ostream &os) { if(metaElems) { - metaElems->SetPrintLevel(printLevel); + metaElems->SetPrintLevel(PrintLevel); metaElems->Print(os); } for(ListDicomDirPatient::iterator cc = patients.begin(); cc != patients.end(); ++cc) { - (*cc)->SetPrintLevel( printLevel ); + (*cc)->SetPrintLevel( PrintLevel ); (*cc)->Print( os ); } } @@ -216,6 +200,29 @@ bool gdcmDicomDir::IsReadable() return true; } +/** + * \brief Sets all fields to NULL + */ + +void gdcmDicomDir::Initialize() +{ + startMethod = NULL; + progressMethod = NULL; + endMethod = NULL; + startMethodArgDelete = NULL; + progressMethodArgDelete = NULL; + endMethodArgDelete = NULL; + startArg = NULL; + progressArg = NULL; + endArg = NULL; + + progress = 0.0; + abort = false; + + metaElems = (gdcmDicomDirMeta *)0; +} + + /** * \ingroup gdcmDicomDir * \brief fills the whole structure, starting from a root Directory @@ -431,7 +438,7 @@ void gdcmDicomDir::CreateDicomDirChainedList(std::string const & path) VectDocument list; gdcmHeader *header; - tagHT.clear(); + TagHT.clear(); patients.clear(); for( gdcmDirList::iterator it = fileList.begin(); @@ -447,7 +454,7 @@ void gdcmDicomDir::CreateDicomDirChainedList(std::string const & path) header = new gdcmHeader(it->c_str(),false,true); if(!header) { - std::cout << "echec new Header " << it->c_str() << std::endl; // JPR + std::cout << "failure in new Header " << it->c_str() << std::endl; // JPR } if(header->IsReadable()) { list.push_back(header); // adds the file header to the chained list @@ -481,9 +488,9 @@ void gdcmDicomDir::CreateDicomDirChainedList(std::string const & path) gdcmDicomDirMeta * gdcmDicomDir::NewMeta() { - gdcmDicomDirMeta *m = new gdcmDicomDirMeta( &tagHT ); - for ( TagDocEntryHT::iterator cc = tagHT.begin(); - cc != tagHT.end(); ++cc) + gdcmDicomDirMeta *m = new gdcmDicomDirMeta( &TagHT ); + for ( TagDocEntryHT::iterator cc = TagHT.begin(); + cc != TagHT.end(); ++cc) { m->AddDocEntry( cc->second ); } @@ -500,16 +507,19 @@ gdcmDicomDirPatient * gdcmDicomDir::NewPatient() uint16_t tmpGr,tmpEl; gdcmDictEntry *dictEntry; gdcmValEntry *entry; - + + std::list elemList; + elemList=gdcmGlobal::GetDicomDirElements()->GetDicomDirPatientElements(); +// Looks nice, but gdcmDicomDir IS NOT a gdcmObject ... +// gdcmDicomDirPatient *p = new gdcmDicomDirPatient(ptagHT); +// FillObject(elemList); +// patients.push_front( p ); +// return p; +/// \todo TODO : find a trick to use FillObject !!! + gdcmSQItem *s = new gdcmSQItem(0); - - std::list elemList = - gdcmGlobal::GetDicomDirElements()->GetDicomDirPatientElements(); - - /// \todo TODO : use FillObject !!! - // for all the DicomDirPatient Elements - + // for all the DicomDirPatient Elements for( it = elemList.begin(); it != elemList.end(); ++it ) { tmpGr = it->group; @@ -544,7 +554,7 @@ gdcmDicomDirPatient * gdcmDicomDir::NewPatient() s->AddDocEntry( entry ); } - gdcmDicomDirPatient *p = new gdcmDicomDirPatient(s, &tagHT); + gdcmDicomDirPatient *p = new gdcmDicomDirPatient(s, &TagHT); patients.push_front( p ); return p; @@ -567,24 +577,29 @@ void gdcmDicomDir::SetElement(std::string &path,gdcmDicomDirType type, gdcmDictEntry *dictEntry; gdcmValEntry *entry; std::string val; - + gdcmObject *o; switch( type ) { - case GDCM_DICOMDIR_PATIENT: - elemList = gdcmGlobal::GetDicomDirElements()->GetDicomDirPatientElements(); - break; - case GDCM_DICOMDIR_STUDY: - elemList = gdcmGlobal::GetDicomDirElements()->GetDicomDirStudyElements(); + case GDCM_DICOMDIR_IMAGE: + elemList = gdcmGlobal::GetDicomDirElements()->GetDicomDirImageElements(); break; + case GDCM_DICOMDIR_SERIE: elemList = gdcmGlobal::GetDicomDirElements()->GetDicomDirSerieElements(); break; - case GDCM_DICOMDIR_IMAGE: - elemList = gdcmGlobal::GetDicomDirElements()->GetDicomDirImageElements(); + + case GDCM_DICOMDIR_STUDY: + elemList = gdcmGlobal::GetDicomDirElements()->GetDicomDirStudyElements(); break; + + case GDCM_DICOMDIR_PATIENT: + elemList = gdcmGlobal::GetDicomDirElements()->GetDicomDirPatientElements(); + break; + case GDCM_DICOMDIR_META: elemList = gdcmGlobal::GetDicomDirElements()->GetDicomDirMetaElements(); break; + default: return; } @@ -598,7 +613,8 @@ void gdcmDicomDir::SetElement(std::string &path,gdcmDicomDirType type, entry->SetOffset(0); // just to avoid further missprinting - if( header ) + if( header ) // NULL when we Build Up (ex nihilo) a DICOMDIR + // or when we add the META elems { val = header->GetEntryByNumber(tmpGr, tmpEl); } @@ -646,7 +662,7 @@ void gdcmDicomDir::SetElement(std::string &path,gdcmDicomDirType type, { if( dictEntry->GetGroup() == 0xfffe ) { - entry->SetLength( entry->GetValue().length() ); + entry->SetLength( entry->GetValue().length() ); // FIXME } else if( dictEntry->GetVR() == "UL" || dictEntry->GetVR() == "SL" ) { @@ -665,8 +681,12 @@ void gdcmDicomDir::SetElement(std::string &path,gdcmDicomDirType type, entry->SetLength( entry->GetValue().length() ); } } - //AddDocEntry(entry); // both in H Table and in chained list - tagHT[entry->GetKey()] = entry; // FIXME : use a SEQUENCE ! + std::cout << " was TagHT[entry->GetKey()] = entry " << std::endl; + if ( type == GDCM_DICOMDIR_META ) { + std::cout << " special Treatment for GDCM_DICOMDIR_META" << std::endl; + + } + //TagHT[entry->GetKey()] = entry; // FIXME : use a SEQUENCE ! } } @@ -724,8 +744,6 @@ void gdcmDicomDir::CreateDicomDir() // + we create the object for the precedent tag // + loop to 1 - - gdcmDicomDirType type = gdcmDicomDir::GDCM_DICOMDIR_META; - // Directory record sequence gdcmDocEntry *e = GetDocEntryByNumber(0x0004, 0x1220); if ( !e ) @@ -740,12 +758,14 @@ void gdcmDicomDir::CreateDicomDir() if ( !s ) { dbg.Verbose(0, "gdcmDicomDir::CreateDicomDir: no SeqEntry present"); + // useless : (0x0004,0x1220) IS a Sequence ! return; } + gdcmDicomDirType type = gdcmDicomDir::GDCM_DICOMDIR_META; + metaElems = NewMeta(); + ListSQItem listItems = s->GetSQItems(); - gdcmDicomDirMeta *m = new gdcmDicomDirMeta(&tagHT); - (void)m; //?? gdcmDocEntry * d; std::string v; @@ -846,7 +866,7 @@ void gdcmDicomDir::AddDicomDirMeta() { delete metaElems; } - metaElems = new gdcmDicomDirMeta( &tagHT ); + metaElems = new gdcmDicomDirMeta( &TagHT ); } /** @@ -856,7 +876,7 @@ void gdcmDicomDir::AddDicomDirMeta() */ void gdcmDicomDir::AddDicomDirPatientToEnd(gdcmSQItem *s) { - patients.push_back(new gdcmDicomDirPatient(s, &tagHT)); + patients.push_back(new gdcmDicomDirPatient(s, &TagHT)); } /** @@ -870,7 +890,7 @@ void gdcmDicomDir::AddDicomDirPatientToEnd(gdcmSQItem *s) { ListDicomDirPatient::iterator itp = patients.end(); itp--; - (*itp)->AddDicomDirStudy(new gdcmDicomDirStudy(s, &tagHT)); + (*itp)->AddDicomDirStudy(new gdcmDicomDirStudy(s, &TagHT)); } } @@ -890,7 +910,7 @@ void gdcmDicomDir::AddDicomDirSerieToEnd(gdcmSQItem *s) { ListDicomDirStudy::iterator itst=(*itp)->GetDicomDirStudies().end(); itst--; - (*itst)->AddDicomDirSerie(new gdcmDicomDirSerie(s, &tagHT)); + (*itst)->AddDicomDirSerie(new gdcmDicomDirSerie(s, &TagHT)); } } } @@ -916,7 +936,7 @@ void gdcmDicomDir::AddDicomDirSerieToEnd(gdcmSQItem *s) { ListDicomDirSerie::iterator its = (*itst)->GetDicomDirSeries().end(); its--; - (*its)->AddDicomDirImage(new gdcmDicomDirImage(s, &tagHT)); + (*its)->AddDicomDirImage(new gdcmDicomDirImage(s, &TagHT)); } } }