From: jpr Date: Fri, 20 Feb 2004 17:31:31 +0000 (+0000) Subject: Replace confusing names gdcmImage, etc by gdcmDicomDirImage etc, to avoid X-Git-Tag: Version0.5.bp~301 X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=commitdiff_plain;h=22f785a2627d1e7823701193bd7624739a3e033b;p=gdcm.git Replace confusing names gdcmImage, etc by gdcmDicomDirImage etc, to avoid messing up the users --- diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 4db41ba8..715d901b 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -10,11 +10,12 @@ INCLUDE_DIRECTORIES( ) SET(libgdcm_la_SOURCES - gdcmDicomDir.cxx - gdcmDicomDirElement.cxx - gdcmDict.cxx - gdcmDictEntry.cxx - gdcmDictSet.cxx + + gdcmDicomDir.cxx + gdcmDicomDirElement.cxx + gdcmDict.cxx + gdcmDictEntry.cxx + gdcmDictSet.cxx gdcmDirList.cxx gdcmException.cxx gdcmFile.cxx diff --git a/src/Makefile.am b/src/Makefile.am index da2a8224..26911da7 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -10,11 +10,16 @@ CXXFLAGS = @CXXFLAGS@ -DPUB_DICT_PATH=\"$(datadir)/gdcm/\" \ libgdcm_la_LIBADD = \ $(top_builddir)/src/jpeg/libijg12/libgdcmijpeg12.la \ $(top_builddir)/src/jpeg/libijg8/libgdcmijpeg8.la \ - $(top_builddir)/src/jpeg/ljpg/libgdcmjpg.la + $(top_builddir)/src/jpeg/ljpg/libgdcmjpg.la libgdcm_la_SOURCES= \ gdcmDicomDir.cxx \ gdcmDicomDirElement.cxx \ + gdcmDicomDirImage.cxx \ + gdcmDicomDirMeta.cxx \ + gdcmDicomDirPatient.cxx \ + gdcmDicomDirSerie.cxx \ + gdcmDicomDirStudy.cxx \ gdcmDict.cxx \ gdcmDictEntry.cxx \ gdcmDictSet.cxx \ @@ -24,18 +29,13 @@ libgdcm_la_SOURCES= \ gdcmHeader.cxx \ gdcmHeaderEntry.cxx \ gdcmHeaderHelper.cxx \ - gdcmImage.cxx \ - gdcmMeta.cxx \ gdcmJpeg12.cxx \ gdcmJpeg2000.cxx \ gdcmJpeg.cxx \ gdcmObject.cxx \ gdcmParsePixels.cxx \ gdcmParser.cxx \ - gdcmPatient.cxx \ gdcmRLE.cxx \ - gdcmSerie.cxx \ - gdcmStudy.cxx \ gdcmTS.cxx \ gdcmUtil.cxx \ gdcmVR.cxx @@ -46,7 +46,12 @@ libgdcminclude_HEADERS = \ gdcmCommon.h \ gdcmDicomDir.h \ gdcmDicomDirElement.h \ - gdcmDictEntry.h \ + gdcmDicomDirImage.h \ + gdcmDicomDirMeta.h \ + gdcmDicomDirPatient.h \ + gdcmDicomDirSerie.h \ + gdcmDicomDirStudy.h \ + gdcmDictEntry.h \ gdcmDict.h \ gdcmDictSet.h \ gdcmDirList.h \ @@ -56,17 +61,11 @@ libgdcminclude_HEADERS = \ gdcmHeaderEntry.h \ gdcmHeader.h \ gdcmHeaderHelper.h \ - gdcmImage.h \ - gdcmMeta.h \ gdcmObject.h \ gdcmParser.h \ - gdcmPatient.h \ - gdcmSerie.h \ - gdcmStudy.h \ gdcmVR.h \ gdcmTS.h - EXTRA_DIST = \ - gdcmUtil.h + gdcmUtil.h diff --git a/src/gdcmDicomDir.cxx b/src/gdcmDicomDir.cxx index ac19e312..145ce1e8 100644 --- a/src/gdcmDicomDir.cxx +++ b/src/gdcmDicomDir.cxx @@ -1,9 +1,9 @@ // gdcmDicomDir.cxx //----------------------------------------------------------------------------- #include "gdcmDicomDir.h" -#include "gdcmStudy.h" -#include "gdcmSerie.h" -#include "gdcmImage.h" +#include "gdcmDicomDirStudy.h" +#include "gdcmDicomDirSerie.h" +#include "gdcmDicomDirImage.h" #include "gdcmDirList.h" #include "gdcmUtil.h" @@ -20,25 +20,28 @@ // Constructor / Destructor /* * \ingroup gdcmDicomDir - * \brief Constructor - * @param Filename + * \brief Constructor : Parses recursively the directory and creates the DicomDir + * \ or uses an already built DICOMDIR, depending on 'parseDir' value + * @param Name name of the root directory (parseDir = true) + * name of the DICOMDIR (parseDir = false) + * @param parseDir true if user wants to explore the directories * @param exception_on_error */ -gdcmDicomDir::gdcmDicomDir(const char *FileName, bool parseDir, +gdcmDicomDir::gdcmDicomDir(const char *Name, bool parseDir, bool exception_on_error): - gdcmParser(FileName,exception_on_error,true) + gdcmParser(Name,exception_on_error,true) { - startMethod=NULL; - progressMethod=NULL; - endMethod=NULL; - startMethodArgDelete=NULL; + startMethod= NULL; + progressMethod= NULL; + endMethod= NULL; + startMethodArgDelete= NULL; progressMethodArgDelete=NULL; - endMethodArgDelete=NULL; - startArg=NULL; - progressArg=NULL; - endArg=NULL; + endMethodArgDelete= NULL; + startArg= NULL; + progressArg= NULL; + endArg= NULL; - progress=NULL; + progress=0.0; abort=false; metaElems=NULL; @@ -70,7 +73,7 @@ gdcmDicomDir::~gdcmDicomDir() if(metaElems) delete metaElems; - for(ListPatient::iterator cc=patients.begin();cc!=patients.end();++cc) + for(ListDicomDirPatient::iterator cc=patients.begin();cc!=patients.end();++cc) { delete *cc; } @@ -90,7 +93,7 @@ void gdcmDicomDir::Print(std::ostream &os) metaElems->Print(os); } - for(ListPatient::iterator cc=patients.begin();cc!=patients.end();++cc) + for(ListDicomDirPatient::iterator cc=patients.begin();cc!=patients.end();++cc) { (*cc)->SetPrintLevel(printLevel); (*cc)->Print(os); @@ -240,8 +243,8 @@ bool gdcmDicomDir::Write(std::string fileName) filePreamble=(char*)calloc(128,1); fwrite(filePreamble,128,1,fp1); fwrite("DICM",4,1,fp1); - free(filePreamble); - + free(filePreamble); + UpdateDirectoryRecordSequenceLength(); WriteEntries(fp1,DICOMDIR); fclose(fp1); @@ -348,7 +351,7 @@ void gdcmDicomDir::CreateDicomDir() // + we create the object for the precedent tag // + loop to 1 - - gdcmDicomDirType type=gdcmDicomDir::GDCM_META; + gdcmDicomDirType type=gdcmDicomDir::GDCM_DICOMDIR_META; ListTag::iterator begin; ListTag::iterator end; @@ -362,7 +365,7 @@ void gdcmDicomDir::CreateDicomDir() end=i; AddObjectToEnd(type,begin,end); - type=gdcmDicomDir::GDCM_PATIENT; + type=gdcmDicomDir::GDCM_DICOMDIR_PATIENT; begin=end; } @@ -371,7 +374,7 @@ void gdcmDicomDir::CreateDicomDir() end=i; AddObjectToEnd(type,begin,end); - type=gdcmDicomDir::GDCM_STUDY; + type=gdcmDicomDir::GDCM_DICOMDIR_STUDY; begin=end; } @@ -380,7 +383,7 @@ void gdcmDicomDir::CreateDicomDir() end=i; AddObjectToEnd(type,begin,end); - type=gdcmDicomDir::GDCM_SERIE; + type=gdcmDicomDir::GDCM_DICOMDIR_SERIE; begin=end; } @@ -389,7 +392,7 @@ void gdcmDicomDir::CreateDicomDir() end=i; AddObjectToEnd(type,begin,end); - type=gdcmDicomDir::GDCM_IMAGE; + type=gdcmDicomDir::GDCM_DICOMDIR_IMAGE; begin=end; } } @@ -412,20 +415,20 @@ void gdcmDicomDir::AddObjectToEnd(gdcmDicomDirType type,ListTag::iterator begin, switch(type) { - case gdcmDicomDir::GDCM_META: - AddMetaToEnd(begin,end); + case gdcmDicomDir::GDCM_DICOMDIR_META: + AddDicomDirMetaToEnd(begin,end); break; - case gdcmDicomDir::GDCM_PATIENT: - AddPatientToEnd(begin,end); + case gdcmDicomDir::GDCM_DICOMDIR_PATIENT: + AddDicomDirPatientToEnd(begin,end); break; - case gdcmDicomDir::GDCM_STUDY: - AddStudyToEnd(begin,end); + case gdcmDicomDir::GDCM_DICOMDIR_STUDY: + AddDicomDirStudyToEnd(begin,end); break; - case gdcmDicomDir::GDCM_SERIE: - AddSerieToEnd(begin,end); + case gdcmDicomDir::GDCM_DICOMDIR_SERIE: + AddDicomDirSerieToEnd(begin,end); break; - case gdcmDicomDir::GDCM_IMAGE: - AddImageToEnd(begin,end); + case gdcmDicomDir::GDCM_DICOMDIR_IMAGE: + AddDicomDirImageToEnd(begin,end); break; } } @@ -436,11 +439,11 @@ void gdcmDicomDir::AddObjectToEnd(gdcmDicomDirType type,ListTag::iterator begin, * @param begin * @param end */ -void gdcmDicomDir::AddMetaToEnd(ListTag::iterator begin,ListTag::iterator end) +void gdcmDicomDir::AddDicomDirMetaToEnd(ListTag::iterator begin,ListTag::iterator end) { if(metaElems) delete metaElems; - metaElems = new gdcmMeta(begin,end); + metaElems = new gdcmDicomDirMeta(begin,end); } /* @@ -449,9 +452,9 @@ void gdcmDicomDir::AddMetaToEnd(ListTag::iterator begin,ListTag::iterator end) * @param begin * @param end */ -void gdcmDicomDir::AddPatientToEnd(ListTag::iterator begin,ListTag::iterator end) +void gdcmDicomDir::AddDicomDirPatientToEnd(ListTag::iterator begin,ListTag::iterator end) { - patients.push_back(new gdcmPatient(begin,end)); + patients.push_back(new gdcmDicomDirPatient(begin,end)); } /* @@ -460,13 +463,13 @@ void gdcmDicomDir::AddPatientToEnd(ListTag::iterator begin,ListTag::iterator end * @param begin * @param end */ - void gdcmDicomDir::AddStudyToEnd(ListTag::iterator begin,ListTag::iterator end) + void gdcmDicomDir::AddDicomDirStudyToEnd(ListTag::iterator begin,ListTag::iterator end) { if(patients.size()>0) { - ListPatient::iterator itp=patients.end(); + ListDicomDirPatient::iterator itp=patients.end(); itp--; - (*itp)->AddStudy(new gdcmStudy(begin,end)); + (*itp)->AddDicomDirStudy(new gdcmDicomDirStudy(begin,end)); } } /* @@ -475,18 +478,18 @@ void gdcmDicomDir::AddPatientToEnd(ListTag::iterator begin,ListTag::iterator end * @param begin * @param end */ -void gdcmDicomDir::AddSerieToEnd(ListTag::iterator begin,ListTag::iterator end) +void gdcmDicomDir::AddDicomDirSerieToEnd(ListTag::iterator begin,ListTag::iterator end) { if(patients.size()>0) { - ListPatient::iterator itp=patients.end(); + ListDicomDirPatient::iterator itp=patients.end(); itp--; - if((*itp)->GetStudies().size()>0) + if((*itp)->GetDicomDirStudies().size()>0) { - ListStudy::iterator itst=(*itp)->GetStudies().end(); + ListDicomDirStudy::iterator itst=(*itp)->GetDicomDirStudies().end(); itst--; - (*itst)->AddSerie(new gdcmSerie(begin,end)); + (*itst)->AddDicomDirSerie(new gdcmDicomDirSerie(begin,end)); } } } @@ -497,23 +500,23 @@ void gdcmDicomDir::AddSerieToEnd(ListTag::iterator begin,ListTag::iterator end) * @param end * @param */ - void gdcmDicomDir::AddImageToEnd(ListTag::iterator begin,ListTag::iterator end) + void gdcmDicomDir::AddDicomDirImageToEnd(ListTag::iterator begin,ListTag::iterator end) { if(patients.size()>0) { - ListPatient::iterator itp=patients.end(); + ListDicomDirPatient::iterator itp=patients.end(); itp--; - if((*itp)->GetStudies().size()>0) + if((*itp)->GetDicomDirStudies().size()>0) { - ListStudy::iterator itst=(*itp)->GetStudies().end(); + ListDicomDirStudy::iterator itst=(*itp)->GetDicomDirStudies().end(); itst--; - if((*itst)->GetSeries().size()>0) + if((*itst)->GetDicomDirSeries().size()>0) { - ListSerie::iterator its=(*itst)->GetSeries().end(); + ListDicomDirSerie::iterator its=(*itst)->GetDicomDirSeries().end(); its--; - (*its)->AddImage(new gdcmImage(begin,end)); + (*its)->AddDicomDirImage(new gdcmDicomDirImage(begin,end)); } } } @@ -527,47 +530,47 @@ void gdcmDicomDir::AddSerieToEnd(ListTag::iterator begin,ListTag::iterator end) */ void gdcmDicomDir::SetElements(std::string &path,ListHeader &list) { - std::string patPrevName="", patPrevID=""; + std::string patPrevName="", patPrevID=""; std::string studPrevInstanceUID="", studPrevID=""; - std::string serPrevInstanceUID="", serPrevID=""; + std::string serPrevInstanceUID="", serPrevID=""; - std::string patCurName, patCurID; + std::string patCurName, patCurID; std::string studCurInstanceUID, studCurID; - std::string serCurInstanceUID, serCurID; + std::string serCurInstanceUID, serCurID; - SetElement(path,GDCM_NONE,NULL); + SetElement(path,GDCM_DICOMDIR_NONE,NULL); ListTag::iterator debPat=listEntries.begin(); for(ListHeader::iterator it=list.begin();it!=list.end();++it) { // get the current file characteristics - patCurName=(*it)->GetEntryByNumber(0x0010,0x0010); - patCurID=(*it)->GetEntryByNumber(0x0010,0x0011); + patCurName= (*it)->GetEntryByNumber(0x0010,0x0010); + patCurID= (*it)->GetEntryByNumber(0x0010,0x0011); studCurInstanceUID=(*it)->GetEntryByNumber(0x0020,0x000d); - studCurID=(*it)->GetEntryByNumber(0x0020,0x0010); - serCurInstanceUID=(*it)->GetEntryByNumber(0x0020,0x000e); - serCurID=(*it)->GetEntryByNumber(0x0020,0x0011); + studCurID= (*it)->GetEntryByNumber(0x0020,0x0010); + serCurInstanceUID= (*it)->GetEntryByNumber(0x0020,0x000e); + serCurID= (*it)->GetEntryByNumber(0x0020,0x0011); if(patCurName!=patPrevName || patCurID!=patPrevID) - SetElement(path,GDCM_PATIENT,*it); + SetElement(path,GDCM_DICOMDIR_PATIENT,*it); // if new Study Deal with 'STUDY' Elements if(studCurInstanceUID!=studPrevInstanceUID || studCurID!=studPrevID) - SetElement(path,GDCM_STUDY,*it); + SetElement(path,GDCM_DICOMDIR_STUDY,*it); // if new Serie Deal with 'SERIE' Elements if(serCurInstanceUID!=serPrevInstanceUID || serCurID!=serPrevID) - SetElement(path,GDCM_SERIE,*it); + SetElement(path,GDCM_DICOMDIR_SERIE,*it); // Always Deal with 'IMAGE' Elements - SetElement(path,GDCM_IMAGE,*it); + SetElement(path,GDCM_DICOMDIR_IMAGE,*it); - patPrevName=patCurName; - patPrevID=patCurID; + patPrevName= patCurName; + patPrevID= patCurID; studPrevInstanceUID=studCurInstanceUID; - studPrevID=studCurID; - serPrevInstanceUID=serCurInstanceUID; - serPrevID=serCurID; + studPrevID= studCurID; + serPrevInstanceUID= serCurInstanceUID; + serPrevID= serCurID; } } @@ -589,20 +592,20 @@ void gdcmDicomDir::SetElement(std::string &path,gdcmDicomDirType type,gdcmHeader switch(type) { - case GDCM_PATIENT: - elemList=gdcmGlobal::GetDicomDirElements()->GetPatientElements(); + case GDCM_DICOMDIR_PATIENT: + elemList=gdcmGlobal::GetDicomDirElements()->GetDicomDirPatientElements(); break; - case GDCM_STUDY: - elemList=gdcmGlobal::GetDicomDirElements()->GetStudyElements(); + case GDCM_DICOMDIR_STUDY: + elemList=gdcmGlobal::GetDicomDirElements()->GetDicomDirStudyElements(); break; - case GDCM_SERIE: - elemList=gdcmGlobal::GetDicomDirElements()->GetSerieElements(); + case GDCM_DICOMDIR_SERIE: + elemList=gdcmGlobal::GetDicomDirElements()->GetDicomDirSerieElements(); break; - case GDCM_IMAGE: - elemList=gdcmGlobal::GetDicomDirElements()->GetImageElements(); + case GDCM_DICOMDIR_IMAGE: + elemList=gdcmGlobal::GetDicomDirElements()->GetDicomDirImageElements(); break; - case GDCM_NONE: - elemList=gdcmGlobal::GetDicomDirElements()->GetMetaElements(); + case GDCM_DICOMDIR_NONE: + elemList=gdcmGlobal::GetDicomDirElements()->GetDicomDirMetaElements(); break; default: return; @@ -643,12 +646,22 @@ void gdcmDicomDir::SetElement(std::string &path,gdcmDicomDirType type,gdcmHeader { val=it->value; } + } + else + { + if (header->GetEntryLengthByNumber(tmpGr,tmpEl)== 0) + val=val=it->value; } + entry->SetValue(val); if(dictEntry) { - if( (dictEntry->GetVR()=="UL") || (dictEntry->GetVR()=="SL") ) + if(dictEntry->GetGroup()==0xfffe) + { + entry->SetLength(entry->GetValue().length()); //JPR + } + else if( (dictEntry->GetVR()=="UL") || (dictEntry->GetVR()=="SL") ) { entry->SetLength(4); } @@ -665,8 +678,8 @@ void gdcmDicomDir::SetElement(std::string &path,gdcmDicomDirType type,gdcmHeader entry->SetLength(entry->GetValue().length()); } } - - listEntries.push_back(entry); + //listEntries.push_back(entry); + AddHeaderEntry(entry); } } @@ -675,4 +688,28 @@ bool gdcmDicomDir::HeaderLessThan(gdcmHeader *header1,gdcmHeader *header2) return(*header1<*header2); } + + +void gdcmDicomDir::UpdateDirectoryRecordSequenceLength() { + int offset = 0; + ListTag::iterator it; + guint16 gr, el; + string vr; + for(it=listEntries.begin();it!=listEntries.end();++it) { + gr = (*it)->GetGroup(); + el = (*it)->GetElement(); + vr = (*it)->GetVR(); + if (gr !=0xfffe) { + if ( (vr == "OB") || (vr == "OW") || (vr == "SQ") ) { + offset += 4; // explicit VR AND OB, OW, SQ : 4 more bytes + } + offset += 2 + 2 + 4 + (*it)->GetLength(); + } else { + offset += 4; // delimiters don't have a value. + } + } + bool res=SetEntryLengthByNumber(offset, 0x0004, 0x1220); // Hope there is no dupps. + return; +} + //----------------------------------------------------------------------------- diff --git a/src/gdcmDicomDir.h b/src/gdcmDicomDir.h index 73cf77e5..5db25bd1 100644 --- a/src/gdcmDicomDir.h +++ b/src/gdcmDicomDir.h @@ -5,18 +5,18 @@ #include "gdcmHeader.h" #include "gdcmCommon.h" -#include "gdcmPatient.h" -#include "gdcmMeta.h" +#include "gdcmDicomDirPatient.h" +#include "gdcmDicomDirMeta.h" #include "gdcmDicomDirElement.h" #include #include //----------------------------------------------------------------------------- -typedef std::list ListPatient; +typedef std::list ListDicomDirPatient; typedef std::vector ListHeader; -typedef GDCM_EXPORT void( gdcmMethod)(void * =NULL); +typedef GDCM_EXPORT void(gdcmMethod)(void * = NULL); //----------------------------------------------------------------------------- /* * \defgroup gdcmDicomDir @@ -26,7 +26,8 @@ typedef GDCM_EXPORT void( gdcmMethod)(void * =NULL); class GDCM_EXPORT gdcmDicomDir: public gdcmParser { public: -// gdcmDicomDir(ListTag *l, bool exception_on_error = false); +// gdcmDicomDir(ListTag *l, +// bool exception_on_error = false); gdcmDicomDir(const char *FileName, bool parseDir = false, bool exception_on_error = false); @@ -38,8 +39,8 @@ public: // Informations contained in the parser virtual bool IsReadable(void); - inline gdcmMeta *GetMeta() {return metaElems;}; - inline ListPatient &GetPatients() {return patients;}; + inline gdcmDicomDirMeta *GetDicomDirMeta() {return metaElems;}; + inline ListDicomDirPatient &GetDicomDirPatients() {return patients;}; // Parsing void ParseDirectory(void); @@ -62,12 +63,12 @@ public: // Types typedef enum { - GDCM_NONE, - GDCM_META, - GDCM_PATIENT, - GDCM_STUDY, - GDCM_SERIE, - GDCM_IMAGE, + GDCM_DICOMDIR_NONE, + GDCM_DICOMDIR_META, + GDCM_DICOMDIR_PATIENT, + GDCM_DICOMDIR_STUDY, + GDCM_DICOMDIR_SERIE, + GDCM_DICOMDIR_IMAGE, } gdcmDicomDirType; protected: @@ -82,19 +83,21 @@ private: void CreateDicomDir(void); void AddObjectToEnd(gdcmDicomDirType type, ListTag::iterator begin,ListTag::iterator end); - void AddMetaToEnd (ListTag::iterator begin,ListTag::iterator end); - void AddPatientToEnd(ListTag::iterator begin,ListTag::iterator end); - void AddStudyToEnd (ListTag::iterator begin,ListTag::iterator end); - void AddSerieToEnd (ListTag::iterator begin,ListTag::iterator end); - void AddImageToEnd (ListTag::iterator begin,ListTag::iterator end); + void AddDicomDirMetaToEnd (ListTag::iterator begin,ListTag::iterator end); + void AddDicomDirPatientToEnd(ListTag::iterator begin,ListTag::iterator end); + void AddDicomDirStudyToEnd (ListTag::iterator begin,ListTag::iterator end); + void AddDicomDirSerieToEnd (ListTag::iterator begin,ListTag::iterator end); + void AddDicomDirImageToEnd (ListTag::iterator begin,ListTag::iterator end); void SetElements(std::string &path,ListHeader &list); void SetElement (std::string &path,gdcmDicomDirType type,gdcmHeader *header); + + void UpdateDirectoryRecordSequenceLength(void); static bool HeaderLessThan(gdcmHeader *header1,gdcmHeader *header2); - gdcmMeta *metaElems; - ListPatient patients; + gdcmDicomDirMeta *metaElems; + ListDicomDirPatient patients; gdcmMethod *startMethod; gdcmMethod *progressMethod; diff --git a/src/gdcmDicomDirElement.cxx b/src/gdcmDicomDirElement.cxx index 25afc82d..d7197ce9 100644 --- a/src/gdcmDicomDirElement.cxx +++ b/src/gdcmDicomDirElement.cxx @@ -53,17 +53,16 @@ elem.value = buff; if(type=="metaElem") - MetaList.push_back(elem); + DicomDirMetaList.push_back(elem); else if(type=="patientElem") - PatientList.push_back(elem); + DicomDirPatientList.push_back(elem); else if(type=="studyElem") - StudyList.push_back(elem); + DicomDirStudyList.push_back(elem); else if(type=="serieElem") - SerieList.push_back(elem); + DicomDirSerieList.push_back(elem); else if(type=="imageElem") - ImageList.push_back(elem); + DicomDirImageList.push_back(elem); } - from.getline(buff, 1024, '\n'); } from.close(); @@ -74,11 +73,11 @@ * \brief destructor */ gdcmDicomDirElement::~gdcmDicomDirElement() { - MetaList.clear(); - PatientList.clear(); - StudyList.clear(); - SerieList.clear(); - ImageList.clear(); + DicomDirMetaList.clear(); + DicomDirPatientList.clear(); + DicomDirStudyList.clear(); + DicomDirSerieList.clear(); + DicomDirImageList.clear(); } //----------------------------------------------------------------------------- @@ -95,35 +94,35 @@ void gdcmDicomDirElement::Print(std::ostream &os) { char greltag[10]; //group element tag s << "Meta Elements :"<group,it->elem); s << " ("<value<group,it->elem); s << " ("<value<group,it->elem); s << " ("<value<group,it->elem); s << " ("<value<group,it->elem); s << " ("<value< ListMetaElem; -typedef std::list ListPatientElem; -typedef std::list ListStudyElem; -typedef std::list ListSerieElem; -typedef std::list ListImageElem; +typedef std::list ListDicomDirMetaElem; +typedef std::list ListDicomDirPatientElem; +typedef std::list ListDicomDirStudyElem; +typedef std::list ListDicomDirSerieElem; +typedef std::list ListDicomDirImageElem; //----------------------------------------------------------------------------- /* @@ -35,18 +35,23 @@ public: void Print(std::ostream &os); - ListMetaElem &GetMetaElements(void) {return(MetaList);}; - ListPatientElem &GetPatientElements(void) {return(PatientList);}; - ListStudyElem &GetStudyElements(void) {return(StudyList);}; - ListSerieElem &GetSerieElements(void) {return(SerieList);}; - ListImageElem &GetImageElements(void) {return(ImageList);}; + ListDicomDirMetaElem &GetDicomDirMetaElements(void) + {return(DicomDirMetaList);}; + ListDicomDirPatientElem &GetDicomDirPatientElements(void) + {return(DicomDirPatientList);}; + ListDicomDirStudyElem &GetDicomDirStudyElements(void) + {return(DicomDirStudyList);}; + ListDicomDirSerieElem &GetDicomDirSerieElements(void) + {return(DicomDirSerieList);}; + ListDicomDirImageElem &GetDicomDirImageElements(void) + {return(DicomDirImageList);}; private: - ListMetaElem MetaList; - ListPatientElem PatientList; - ListStudyElem StudyList; - ListSerieElem SerieList; - ListImageElem ImageList; + ListDicomDirMetaElem DicomDirMetaList; + ListDicomDirPatientElem DicomDirPatientList; + ListDicomDirStudyElem DicomDirStudyList; + ListDicomDirSerieElem DicomDirSerieList; + ListDicomDirImageElem DicomDirImageList; }; //----------------------------------------------------------------------------- diff --git a/src/gdcmImage.cxx b/src/gdcmDicomDirImage.cxx similarity index 79% rename from src/gdcmImage.cxx rename to src/gdcmDicomDirImage.cxx index 5484f9d9..00a54a20 100644 --- a/src/gdcmImage.cxx +++ b/src/gdcmDicomDirImage.cxx @@ -1,16 +1,16 @@ -// gdcmImage.cxx +// gdcmDicomDirImage.cxx //----------------------------------------------------------------------------- -#include "gdcmImage.h" +#include "gdcmDicomDirImage.h" //----------------------------------------------------------------------------- // Constructor / Destructor /** - * \ingroup gdcmImage + * \ingroup gdcmDicomDirImage * \brief * @param begin iterator of begin for the object * @param end iterator of end for the object */ -gdcmImage::gdcmImage(ListTag::iterator begin,ListTag::iterator end): +gdcmDicomDirImage::gdcmDicomDirImage(ListTag::iterator begin,ListTag::iterator end): gdcmObject(begin,end) { } @@ -19,18 +19,18 @@ gdcmImage::gdcmImage(ListTag::iterator begin,ListTag::iterator end): * \ingroup gdcmImage * \brief Canonical destructor. */ -gdcmImage::~gdcmImage() +gdcmDicomDirImage::~gdcmDicomDirImage() { } //----------------------------------------------------------------------------- // Print /** - * \ingroup gdcmImage + * \ingroup gdcmDicomDirImage * \brief Prints the Object * @return */ -void gdcmImage::Print(std::ostream &os) +void gdcmDicomDirImage::Print(std::ostream &os) { os<<"IMAGE : "; for(ListTag::iterator i=beginObj;i!=endObj;++i) diff --git a/src/gdcmImage.h b/src/gdcmDicomDirImage.h similarity index 59% rename from src/gdcmImage.h rename to src/gdcmDicomDirImage.h index 8c7906fc..4f1173d9 100644 --- a/src/gdcmImage.h +++ b/src/gdcmDicomDirImage.h @@ -1,16 +1,16 @@ -// gdcmImage.h +// gdcmDicomDirImage.h //----------------------------------------------------------------------------- -#ifndef GDCMIMAGE_H -#define GDCMIMAGE_H +#ifndef GDCMDICOMIMAGE_H +#define GDCMDICOMIMAGE_H #include "gdcmObject.h" //----------------------------------------------------------------------------- -class GDCM_EXPORT gdcmImage : public gdcmObject +class GDCM_EXPORT gdcmDicomDirImage : public gdcmObject { public: - gdcmImage(ListTag::iterator begin,ListTag::iterator end); - ~gdcmImage(void); + gdcmDicomDirImage(ListTag::iterator begin,ListTag::iterator end); + ~gdcmDicomDirImage(void); virtual void Print(std::ostream &os = std::cout); }; diff --git a/src/gdcmMeta.cxx b/src/gdcmDicomDirMeta.cxx similarity index 75% rename from src/gdcmMeta.cxx rename to src/gdcmDicomDirMeta.cxx index a9a0aa0d..94584760 100644 --- a/src/gdcmMeta.cxx +++ b/src/gdcmDicomDirMeta.cxx @@ -1,36 +1,36 @@ -// gdcmMeta.h +// gdcmDicomDirMeta.h //----------------------------------------------------------------------------- -#include "gdcmMeta.h" +#include "gdcmDicomDirMeta.h" //----------------------------------------------------------------------------- // Constructor / Destructor /** - * \ingroup gdcmMeta + * \ingroup gdcmDicomDirMeta * \brief * @param begin iterator of begin for the object * @param end iterator of end for the object */ -gdcmMeta::gdcmMeta(ListTag::iterator begin,ListTag::iterator end): +gdcmDicomDirMeta::gdcmDicomDirMeta(ListTag::iterator begin,ListTag::iterator end): gdcmObject(begin,end) { } /** - * \ingroup gdcmMeta + * \ingroup gdcmDicomDirMeta * \brief Canonical destructor. */ -gdcmMeta::~gdcmMeta() +gdcmDicomDirMeta::~gdcmDicomDirMeta() { } //----------------------------------------------------------------------------- // Print /** - * \ingroup gdcmMeta + * \ingroup gdcmDicomDirMeta * \brief Prints the Object * @return */ -void gdcmMeta::Print(std::ostream &os) +void gdcmDicomDirMeta::Print(std::ostream &os) { os<<"META"<SetPrintLevel(printLevel); (*cc)->Print(os); diff --git a/src/gdcmPatient.h b/src/gdcmDicomDirPatient.h similarity index 51% rename from src/gdcmPatient.h rename to src/gdcmDicomDirPatient.h index 2d4d1e26..2868f42a 100644 --- a/src/gdcmPatient.h +++ b/src/gdcmDicomDirPatient.h @@ -1,28 +1,28 @@ -// gdcmPatient.h +// gdcmDicomDirPatient.h //----------------------------------------------------------------------------- #ifndef GDCMPATIENT_H #define GDCMPATIENT_H #include "gdcmObject.h" -#include "gdcmStudy.h" +#include "gdcmDicomDirStudy.h" //----------------------------------------------------------------------------- -typedef std::list ListStudy; +typedef std::list ListDicomDirStudy; //----------------------------------------------------------------------------- -class GDCM_EXPORT gdcmPatient : public gdcmObject +class GDCM_EXPORT gdcmDicomDirPatient : public gdcmObject { public: - gdcmPatient(ListTag::iterator begin,ListTag::iterator end); - ~gdcmPatient(void); + gdcmDicomDirPatient(ListTag::iterator begin,ListTag::iterator end); + ~gdcmDicomDirPatient(void); virtual void Print(std::ostream &os = std::cout); - inline ListStudy &GetStudies() {return studies;}; - inline void AddStudy(gdcmStudy *obj) {studies.push_back(obj);}; + inline ListDicomDirStudy &GetDicomDirStudies() {return studies;}; + inline void AddDicomDirStudy(gdcmDicomDirStudy *obj) {studies.push_back(obj);}; private: - ListStudy studies; + ListDicomDirStudy studies; }; //----------------------------------------------------------------------------- diff --git a/src/gdcmSerie.cxx b/src/gdcmDicomDirSerie.cxx similarity index 68% rename from src/gdcmSerie.cxx rename to src/gdcmDicomDirSerie.cxx index 1ad1b6fd..a9f2d965 100644 --- a/src/gdcmSerie.cxx +++ b/src/gdcmDicomDirSerie.cxx @@ -1,27 +1,27 @@ -// gdcmSequence.cxx +// gdcmDicomDirSerie.cxx //----------------------------------------------------------------------------- -#include "gdcmSerie.h" +#include "gdcmDicomDirSerie.h" //----------------------------------------------------------------------------- // Constructor / Destructor /** - * \ingroup gdcmSerie + * \ingroup gdcmDicomDirSerie * \brief * @param begin iterator of begin for the object * @param end iterator of end for the object */ -gdcmSerie::gdcmSerie(ListTag::iterator begin,ListTag::iterator end): +gdcmDicomDirSerie::gdcmDicomDirSerie(ListTag::iterator begin,ListTag::iterator end): gdcmObject(begin,end) { } /** - * \ingroup gdcmSerie + * \ingroup gdcmDicomDirSerie * \brief Canonical destructor. */ -gdcmSerie::~gdcmSerie() +gdcmDicomDirSerie::~gdcmDicomDirSerie() { - for(ListImage::iterator cc = images.begin();cc != images.end();++cc) + for(ListDicomDirImage::iterator cc = images.begin();cc != images.end();++cc) { delete *cc; } @@ -30,16 +30,16 @@ gdcmSerie::~gdcmSerie() //----------------------------------------------------------------------------- // Print /** - * \ingroup gdcmSerie + * \ingroup gdcmDicomDirSerie * \brief Prints the Object * @return */ -void gdcmSerie::Print(std::ostream &os) +void gdcmDicomDirSerie::Print(std::ostream &os) { os<<"SERIE"<SetPrintLevel(printLevel); (*cc)->Print(os); diff --git a/src/gdcmDicomDirSerie.h b/src/gdcmDicomDirSerie.h new file mode 100644 index 00000000..9554d39a --- /dev/null +++ b/src/gdcmDicomDirSerie.h @@ -0,0 +1,29 @@ +// gdcmDicomDirSerie.h +//----------------------------------------------------------------------------- +#ifndef GDCMDICOMDIRSERIE_H +#define GDCMDICOMDIRSERIE_H + +#include "gdcmObject.h" +#include "gdcmDicomDirImage.h" + +//----------------------------------------------------------------------------- +typedef std::list ListDicomDirImage; + +//----------------------------------------------------------------------------- +class GDCM_EXPORT gdcmDicomDirSerie : public gdcmObject +{ +public: + gdcmDicomDirSerie(ListTag::iterator begin,ListTag::iterator end); + ~gdcmDicomDirSerie(void); + + virtual void Print(std::ostream &os = std::cout); + + inline ListDicomDirImage &GetDicomDirImages() {return images;}; + inline void AddDicomDirImage(gdcmDicomDirImage *obj) {images.push_back(obj);}; + +private: + ListDicomDirImage images; +}; + +//----------------------------------------------------------------------------- +#endif diff --git a/src/gdcmStudy.cxx b/src/gdcmDicomDirStudy.cxx similarity index 68% rename from src/gdcmStudy.cxx rename to src/gdcmDicomDirStudy.cxx index d57391e2..fd8e886b 100644 --- a/src/gdcmStudy.cxx +++ b/src/gdcmDicomDirStudy.cxx @@ -1,27 +1,27 @@ -// gdcmStudy.cxx +// gdcmDicomDirStudy.cxx //----------------------------------------------------------------------------- -#include "gdcmStudy.h" +#include "gdcmDicomDirStudy.h" //----------------------------------------------------------------------------- // Constructor / Destructor /** - * \ingroup gdcmStudy + * \ingroup gdcmDicomDirStudy * \brief * @param begin iterator of begin for the object * @param end iterator of end for the object */ -gdcmStudy::gdcmStudy(ListTag::iterator begin,ListTag::iterator end): +gdcmDicomDirStudy::gdcmDicomDirStudy(ListTag::iterator begin,ListTag::iterator end): gdcmObject(begin,end) { } /** - * \ingroup gdcmStudy + * \ingroup gdcmDicomDirStudy * \brief Canonical destructor. */ -gdcmStudy::~gdcmStudy() +gdcmDicomDirStudy::~gdcmDicomDirStudy() { - for(ListSerie::iterator cc = series.begin();cc != series.end();++cc) + for(ListDicomDirSerie::iterator cc = series.begin();cc != series.end();++cc) { delete *cc; } @@ -30,16 +30,16 @@ gdcmStudy::~gdcmStudy() //----------------------------------------------------------------------------- // Print /** - * \ingroup gdcmStudy + * \ingroup gdcmDicomDirStudy * \brief Prints the Object * @return */ -void gdcmStudy::Print(std::ostream &os) +void gdcmDicomDirStudy::Print(std::ostream &os) { os<<"STUDY"<SetPrintLevel(printLevel); (*cc)->Print(os); diff --git a/src/gdcmDicomDirStudy.h b/src/gdcmDicomDirStudy.h new file mode 100644 index 00000000..4c69b7b0 --- /dev/null +++ b/src/gdcmDicomDirStudy.h @@ -0,0 +1,28 @@ +// gdcmDicomDirStudy.h +//----------------------------------------------------------------------------- +#ifndef GDCMDICOMDIRSTUDY_H +#define GDCMDICOMDIRSTUDY_H + +#include "gdcmObject.h" +#include "gdcmDicomDirSerie.h" + +//----------------------------------------------------------------------------- +typedef std::list ListDicomDirSerie; + +//----------------------------------------------------------------------------- +class GDCM_EXPORT gdcmDicomDirStudy : public gdcmObject { +public: + gdcmDicomDirStudy(ListTag::iterator begin,ListTag::iterator end); + ~gdcmDicomDirStudy(void); + + virtual void Print(std::ostream &os = std::cout); + + inline ListDicomDirSerie &GetDicomDirSeries() {return series;}; + inline void AddDicomDirSerie(gdcmDicomDirSerie *obj) {series.push_back(obj);}; + +private: + ListDicomDirSerie series; +}; + +//----------------------------------------------------------------------------- +#endif diff --git a/src/gdcmDict.cxx b/src/gdcmDict.cxx index c0fc1b26..75834e1f 100644 --- a/src/gdcmDict.cxx +++ b/src/gdcmDict.cxx @@ -62,7 +62,6 @@ gdcmDict::~gdcmDict() { if ( EntryToDelete ) delete EntryToDelete; } - // Since AddNewEntry adds symetrical in both KeyHt and NameHT we can // assume all the pointed gdcmDictEntries are already cleaned-up when // we cleaned KeyHt. @@ -131,7 +130,7 @@ void gdcmDict::PrintByName(std::ostream& os) { * \ingroup gdcmDict * \brief adds a new Dicom Dictionary Entry * @param NewEntry entry to add - * @return false if Dicom Element already existed + * @return false if Dicom Element already exists */ bool gdcmDict::AddNewEntry(gdcmDictEntry *NewEntry) { diff --git a/src/gdcmHeader.cxx b/src/gdcmHeader.cxx index fce0e465..04c501ac 100644 --- a/src/gdcmHeader.cxx +++ b/src/gdcmHeader.cxx @@ -810,7 +810,7 @@ bool gdcmHeader::anonymizeHeader() { } // Just for fun :-( - // (if any) remove or replace + // (if any) remove or replace all the stuff that contains a Date //0008 0012 DA ID Instance Creation Date //0008 0020 DA ID Study Date diff --git a/src/gdcmHeader.h b/src/gdcmHeader.h index 18591922..4308f3b4 100644 --- a/src/gdcmHeader.h +++ b/src/gdcmHeader.h @@ -84,16 +84,22 @@ public: inline virtual std::string GetEntryByNumber (guint16 group, guint16 element) { return(gdcmParser::GetEntryByNumber(group,element)); } + inline virtual std::string GetEntryVRByNumber(guint16 group, guint16 element) { return(gdcmParser::GetEntryVRByNumber(group,element)); } + inline virtual int GetEntryLengthByNumber(guint16 group, guint16 element) + { return(gdcmParser::GetEntryLengthByNumber(group,element)); } + inline virtual std::string GetEntryByName (std::string tagName) { return(gdcmParser::GetEntryByName(tagName)); } + inline virtual std::string GetEntryVRByName (std::string tagName) { return(gdcmParser::GetEntryVRByName(tagName)); } inline virtual bool SetEntryByNumber(std::string content,guint16 group, guint16 element) { return(gdcmParser::SetEntryByNumber(content,group,element)); } + inline virtual bool SetEntryByName(std::string content,std::string tagName) { return(gdcmParser::SetEntryByName(content,tagName)); } diff --git a/src/gdcmParser.cxx b/src/gdcmParser.cxx index 70c859fd..2090c155 100644 --- a/src/gdcmParser.cxx +++ b/src/gdcmParser.cxx @@ -1,4 +1,4 @@ -// gdcmHeader.cxx +// gdcmParser.cxx //----------------------------------------------------------------------------- #include "gdcmParser.h" #include "gdcmUtil.h" @@ -566,6 +566,7 @@ std::string gdcmParser::GetEntryVRByName(std::string tagName) { return elem->GetVR(); } + /** * \ingroup gdcmParser * \brief Searches within Header Entries (Dicom Elements) parsed with @@ -605,6 +606,21 @@ std::string gdcmParser::GetEntryVRByNumber(guint16 group, guint16 element) { return elem->GetVR(); } +/** + * \ingroup gdcmParser + * \brief Searches within Header Entries (Dicom Elements) parsed with + * the public and private dictionaries + * for the value length of a given tag.. + * @param group Group of the searched tag. + * @param element Element of the searched tag. + * @return Corresponding element length; -2 if not found + */ +int gdcmParser::GetEntryLengthByNumber(guint16 group, guint16 element) { + gdcmHeaderEntry* elem = GetHeaderEntryByNumber(group, element); + if ( !elem ) + return -2; + return elem->GetLength(); +} /** * \ingroup gdcmParser * \brief Sets the value (string) of the Header Entry (Dicom Element) @@ -682,7 +698,7 @@ bool gdcmParser::SetEntryByNumber(std::string content, * @param l new length to substitute with * @param group group of the Entry to modify * @param element element of the Entry to modify - * @return 1 on success, 0 otherwise. + * @return true on success, false otherwise. */ bool gdcmParser::SetEntryLengthByNumber(guint32 l, guint16 group, @@ -702,7 +718,7 @@ bool gdcmParser::SetEntryLengthByNumber(guint32 l, * \brief Gets (from Header) the offset of a 'non string' element value * (LoadElementValues has already be executed) * @param Group group of the Entry - * @param Elem element of the Entry + * @param Elem element of the Entry * @return File Offset of the Element Value */ size_t gdcmParser::GetEntryOffsetByNumber(guint16 Group, guint16 Elem) @@ -860,7 +876,7 @@ void gdcmParser::UpdateShaEntries(void) { */ gdcmHeaderEntry* gdcmParser::GetHeaderEntryByNumber(guint16 group, guint16 element) { - TagKey key = gdcmDictEntry::TranslateToKey(group, element); + TagKey key = gdcmDictEntry::TranslateToKey(group, element); if ( ! tagHT.count(key)) return NULL; return tagHT.find(key)->second; @@ -1034,7 +1050,7 @@ void gdcmParser::WriteEntries(FILE *_fp,FileType type) // TODO : find a trick (in STL?) to do it, at low cost ! void *ptr; - + int ff=0xffffffff; // TODO (?) tester les echecs en ecriture (apres chaque fwrite) int compte =0; @@ -1045,9 +1061,9 @@ void gdcmParser::WriteEntries(FILE *_fp,FileType type) // === Deal with the length // -------------------- if(((*tag2)->GetLength())%2==1) - { + { (*tag2)->SetValue((*tag2)->GetValue()+"\0"); - (*tag2)->SetLength((*tag2)->GetLength()+1); + (*tag2)->SetLength((*tag2)->GetReadLength()+1); } gr = (*tag2)->GetGroup(); @@ -1070,38 +1086,29 @@ void gdcmParser::WriteEntries(FILE *_fp,FileType type) fwrite ( &gr,(size_t)2 ,(size_t)1 ,_fp); //group fwrite ( &el,(size_t)2 ,(size_t)1 ,_fp); //element - // if ( (type == ExplicitVR) && (gr <= 0x0002) ) // ?!? < 2 - if ( (type == ExplicitVR) || (type == DICOMDIR) ) - { + if ( (type == ExplicitVR) || (type == DICOMDIR) ) { // EXPLICIT VR guint16 z=0, shortLgr; - if (vr == "unkn") - { // Unknown was 'written' - shortLgr=lgr; + + if (gr == 0xfffe) { // NO Value Representation for 'delimiters' + // no length : write ffffffff + fwrite (&ff,(size_t)4 ,(size_t)1 ,_fp); + continue; // NO value for 'delimiters' + } + + shortLgr=lgr; + if (vr == "unkn") { // Unknown was 'written' + // deal with Little Endian fwrite ( &shortLgr,(size_t)2 ,(size_t)1 ,_fp); fwrite ( &z, (size_t)2 ,(size_t)1 ,_fp); - } - else - { - if (gr != 0xfffe) - { // NO value for 'delimiters' - if (vr == "unkn") // Unknown was 'written' - fwrite(&z,(size_t)2 ,(size_t)1 ,_fp); - else - fwrite (vr.c_str(),(size_t)2 ,(size_t)1 ,_fp); - } - - if ( (vr == "OB") || (vr == "OW") || (vr == "SQ") || gr == 0xfffe) - { - if (gr != 0xfffe) + } else { + fwrite (vr.c_str(),(size_t)2 ,(size_t)1 ,_fp); + if ( (vr == "OB") || (vr == "OW") || (vr == "SQ") ){ fwrite ( &z, (size_t)2 ,(size_t)1 ,_fp); fwrite ( &lgr,(size_t)4 ,(size_t)1 ,_fp); - } - else - { - shortLgr=lgr; - fwrite ( &shortLgr,(size_t)2 ,(size_t)1 ,_fp); - } + } else { + fwrite ( &shortLgr,(size_t)2 ,(size_t)1 ,_fp); + } } } else // IMPLICIT VR @@ -1112,7 +1119,7 @@ void gdcmParser::WriteEntries(FILE *_fp,FileType type) // === Deal with the value // ------------------- if (vr == "SQ") continue; // no "value" to write for the SEQuences - if (gr == 0xfffe)continue; + if (gr == 0xfffe)continue; // no "value" to write for the delimiters if (voidArea != NULL) { // there is a 'non string' LUT, overlay, etc @@ -1160,6 +1167,110 @@ void gdcmParser::WriteEntries(FILE *_fp,FileType type) } } + +/** + * \ingroup gdcmParser + * \brief writes on disc according to the requested format + * (ACR-NEMA, ExplicitVR, ImplicitVR) the image + * \warning Uses the H Table, instead of the Chained List + * in order to be compliant with the old way to proceed + * (added elements taken in to account) + * Only THERALYS, during a transitory phase is supposed + * to use this method !!! + * \warning DON'T try, right now, to write a DICOM image + * from an ACR Header (meta elements will be missing!) + * @param _fp already open file pointer + * @param type type of the File to be written + * (ACR-NEMA, ExplicitVR, ImplicitVR) + */ +void gdcmParser::WriteEntriesDeprecated(FILE *_fp,FileType type) { + guint16 gr, el; + guint32 lgr; + const char * val; + std::string vr; + guint32 val_uint32; + guint16 val_uint16; + + std::vector tokens; + + void *ptr; + + // Tout ceci ne marche QUE parce qu'on est sur un proc Little Endian + // restent a tester les echecs en ecriture (apres chaque fwrite) + + for (TagHeaderEntryHT::iterator tag2=tagHT.begin(); + tag2 != tagHT.end(); + ++tag2){ + + gr = tag2->second->GetGroup(); + el = tag2->second->GetElement(); + lgr = tag2->second->GetLength(); + val = tag2->second->GetValue().c_str(); + vr = tag2->second->GetVR(); + + // std::cout << "Tag "<< std::hex << gr << " " << el << std::endl; + + if ( type == ACR ) { + if (gr < 0x0008) continue; // ignore pure DICOM V3 groups + if (gr %2) continue; // ignore shadow groups + if (vr == "SQ" ) continue; // ignore Sequences + if (gr == 0xfffe ) continue; // ignore delimiters + } + + fwrite ( &gr,(size_t)2 ,(size_t)1 ,_fp); //group + fwrite ( &el,(size_t)2 ,(size_t)1 ,_fp); //element + + if ( (type == ExplicitVR) && (gr <= 0x0002) ) { + // EXPLICIT VR + guint16 z=0, shortLgr; + fwrite (vr.c_str(),(size_t)2 ,(size_t)1 ,_fp); + + if ( (vr == "OB") || (vr == "OW") || (vr == "SQ") ) { + fwrite ( &z, (size_t)2 ,(size_t)1 ,_fp); + fwrite ( &lgr,(size_t)4 ,(size_t)1 ,_fp); + + } else { + shortLgr=lgr; + fwrite ( &shortLgr,(size_t)2 ,(size_t)1 ,_fp); + } + } else { // IMPLICIT VR + fwrite ( &lgr,(size_t)4 ,(size_t)1 ,_fp); + } + + if (vr == "US" || vr == "SS") { + tokens.erase(tokens.begin(),tokens.end()); // clean any previous value + Tokenize (tag2->second->GetValue(), tokens, "\\"); + for (unsigned int i=0; isecond->GetValue(), tokens, "\\"); + for (unsigned int i=0; iGetGroup(); std::string vr = Entry->GetVR(); guint16 length16; + if( (element == NumPixel) && (group == GrPixel) ) { dbg.SetDebug(GDCM_DEBUG); @@ -1522,18 +1634,18 @@ void gdcmParser::AddHeaderEntry(gdcmHeaderEntry *newHeaderEntry) { // Actually, length= 0xffff means that we deal with // Unknown Sequence Length } - FixHeaderEntryFoundLength(Entry, (guint32)length16); return; } else { - // Either implicit VR or a non DICOM conformal (see not below) explicit + // Either implicit VR or a non DICOM conformal (see note below) explicit // VR that ommited the VR of (at least) this element. Farts happen. // [Note: according to the part 5, PS 3.5-2001, section 7.1 p25 // on Data elements "Implicit and Explicit VR Data Elements shall // not coexist in a Data Set and Data Sets nested within it".] // Length is on 4 bytes. + FixHeaderEntryFoundLength(Entry, ReadInt32()); return; } @@ -1834,11 +1946,13 @@ void gdcmParser::FixHeaderEntryFoundLength(gdcmHeaderEntry *Entry, guint32 Found else if(Entry->GetGroup() == 0xfffe) { + // cout << "ReadLength " <GetReadLength() << " UsableLength " << FoundLength << endl; + // Entry->Print(); // sometimes, length seems to be wrong FoundLength =0; // some more clever checking to be done ! // I give up! // only gdcm-MR-PHILIPS-16-Multi-Seq.dcm - // causes troubles :-( + // causes troubles :-( } Entry->SetUsableLength(FoundLength); diff --git a/src/gdcmParser.h b/src/gdcmParser.h index 9841aa80..892ceb5e 100644 --- a/src/gdcmParser.h +++ b/src/gdcmParser.h @@ -114,6 +114,7 @@ protected: virtual std::string GetEntryVRByName (std::string tagName); virtual std::string GetEntryByNumber (guint16 group, guint16 element); virtual std::string GetEntryVRByNumber(guint16 group, guint16 element); + virtual int GetEntryLengthByNumber(guint16 group, guint16 element); virtual bool SetEntryByName (std::string content, std::string tagName); virtual bool SetEntryByNumber(std::string content, guint16 group, guint16 element); @@ -136,6 +137,9 @@ protected: void UpdateGroupLength(bool SkipSequence = false, FileType type = ImplicitVR); void WriteEntries(FILE *_fp,FileType type); + void WriteEntriesDeprecated(FILE *_fp,FileType type); // JPR + + void AddHeaderEntry (gdcmHeaderEntry *); // Variables FILE *fp; @@ -165,7 +169,6 @@ private: void LoadHeaderEntries (void); void LoadHeaderEntry (gdcmHeaderEntry *); - void AddHeaderEntry (gdcmHeaderEntry *); void FindHeaderEntryLength(gdcmHeaderEntry *); void FindHeaderEntryVR (gdcmHeaderEntry *); bool CheckHeaderEntryVR (gdcmHeaderEntry *, VRKey); diff --git a/src/gdcmSerie.h b/src/gdcmSerie.h index 996203b8..9554d39a 100644 --- a/src/gdcmSerie.h +++ b/src/gdcmSerie.h @@ -1,28 +1,28 @@ -// gdcmSerie.h +// gdcmDicomDirSerie.h //----------------------------------------------------------------------------- -#ifndef GDCMSERIE_H -#define GDCMSERIE_H +#ifndef GDCMDICOMDIRSERIE_H +#define GDCMDICOMDIRSERIE_H #include "gdcmObject.h" -#include "gdcmImage.h" +#include "gdcmDicomDirImage.h" //----------------------------------------------------------------------------- -typedef std::list ListImage; +typedef std::list ListDicomDirImage; //----------------------------------------------------------------------------- -class GDCM_EXPORT gdcmSerie : public gdcmObject +class GDCM_EXPORT gdcmDicomDirSerie : public gdcmObject { public: - gdcmSerie(ListTag::iterator begin,ListTag::iterator end); - ~gdcmSerie(void); + gdcmDicomDirSerie(ListTag::iterator begin,ListTag::iterator end); + ~gdcmDicomDirSerie(void); virtual void Print(std::ostream &os = std::cout); - inline ListImage &GetImages() {return images;}; - inline void AddImage(gdcmImage *obj) {images.push_back(obj);}; + inline ListDicomDirImage &GetDicomDirImages() {return images;}; + inline void AddDicomDirImage(gdcmDicomDirImage *obj) {images.push_back(obj);}; private: - ListImage images; + ListDicomDirImage images; }; //----------------------------------------------------------------------------- diff --git a/src/gdcmStudy.h b/src/gdcmStudy.h deleted file mode 100644 index ebf31c1f..00000000 --- a/src/gdcmStudy.h +++ /dev/null @@ -1,29 +0,0 @@ -// gdcmStudy.h -//----------------------------------------------------------------------------- -#ifndef GDCMSTUDY_H -#define GDCMSTUDY_H - -#include "gdcmObject.h" -#include "gdcmSerie.h" - -//----------------------------------------------------------------------------- -typedef std::list ListSerie; - -//----------------------------------------------------------------------------- -class GDCM_EXPORT gdcmStudy : public gdcmObject -{ -public: - gdcmStudy(ListTag::iterator begin,ListTag::iterator end); - ~gdcmStudy(void); - - virtual void Print(std::ostream &os = std::cout); - - inline ListSerie &GetSeries() {return series;}; - inline void AddSerie(gdcmSerie *obj) {series.push_back(obj);}; - -private: - ListSerie series; -}; - -//----------------------------------------------------------------------------- -#endif diff --git a/src/gdcmUtil.cxx b/src/gdcmUtil.cxx index faad0254..336be556 100644 --- a/src/gdcmUtil.cxx +++ b/src/gdcmUtil.cxx @@ -59,11 +59,11 @@ gdcmDicomDirElement *gdcmGlobal::ddElem = (gdcmDicomDirElement *)0; gdcmGlobal gdcmGlob; gdcmGlobal::gdcmGlobal(void) { - if (VR || TS || Dicts) + if (VR || TS || Dicts || ddElem) dbg.Verbose(0, "gdcmGlobal::gdcmGlobal : VR or TS or Dicts already allocated"); - Dicts = new gdcmDictSet(); - VR = new gdcmVR(); - TS = new gdcmTS(); + Dicts = new gdcmDictSet(); + VR = new gdcmVR(); + TS = new gdcmTS(); ddElem = new gdcmDicomDirElement(); }