From bfbd90327a5e45d972546843b0d9e4185e16cb24 Mon Sep 17 00:00:00 2001 From: regrain Date: Thu, 22 Jan 2004 18:13:42 +0000 Subject: [PATCH 1/1] * DicomDir : clean code, add methods, set variables in protected or private * gdcmUtil : bug fix for the clean string method -- BeNours --- ChangeLog | 4 + Testing/TestDicomDir.cxx | 256 +++++++++++++++------------ gdcm.dsw | 15 ++ gdcmPython/win32/_vtkGdcm.dsp | 24 +++ gdcmPython/win32/gdcmpyembedded.dsp | 26 ++- src/gdcmDicomDir.cxx | 261 +++++++++++++++++++--------- src/gdcmDicomDir.h | 34 +++- src/gdcmHeaderEntry.cxx | 4 +- src/gdcmImage.cxx | 26 ++- src/gdcmImage.h | 13 +- src/gdcmObject.cxx | 67 ++++--- src/gdcmObject.h | 16 +- src/gdcmParser.h | 6 +- src/gdcmPatient.cxx | 38 +++- src/gdcmPatient.h | 19 +- src/gdcmSerie.cxx | 38 +++- src/gdcmSerie.h | 22 ++- src/gdcmStudy.cxx | 39 ++++- src/gdcmStudy.h | 22 ++- src/gdcmTS.cxx | 6 +- src/gdcmUtil.cxx | 40 ++--- src/win32/gdcmdll.dsp | 16 +- 22 files changed, 667 insertions(+), 325 deletions(-) diff --git a/ChangeLog b/ChangeLog index 59d8f9c4..6aa75ddf 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2004-01-22 Benoit Regrain + * DicomDir : clean code, add methods, set variables in protected or private + * gdcmUtil : bug fix for the clean string method + 2004-01-19 Benoit Regrain * Add the use of shadow dictionaries * bug fix and coding style diff --git a/Testing/TestDicomDir.cxx b/Testing/TestDicomDir.cxx index 16f0e63b..10180b5d 100644 --- a/Testing/TestDicomDir.cxx +++ b/Testing/TestDicomDir.cxx @@ -10,147 +10,181 @@ # else # include #endif +#include +#include #define ostringstream ostrstream //extern "C" +using namespace std; -void aff (ListTag::iterator deb, ListTag::iterator fin); - -// =============================================================================== -void aff (ListTag::iterator deb, ListTag::iterator fin, int nbFFFE) { +void aff(ListTag::iterator deb, ListTag::iterator fin, int nbFFFE) +{ int count =0; - for (ListTag::iterator i= deb; i!= fin; i++) { - if( (*i)->GetGroup() == 0xfffe) { - count ++; - if (count == nbFFFE) break; - } - (*i)->SetPrintLevel(0); - (*i)->Print(); + for (ListTag::iterator i= deb; i!= fin; i++) + { + if( (*i)->GetGroup() == 0xfffe) + { + count ++; + if (count == nbFFFE) break; + } + (*i)->SetPrintLevel(0); + (*i)->Print(); } } int main(int argc, char* argv[]) { - gdcmDICOMDIR* e1; - unsigned short int g, e; - int o; + gdcmDicomDir *e1; + ListTag::iterator deb , fin; + ListPatient::iterator itPatient; + ListStudy::iterator itStudy; + ListSerie::iterator itSerie; + ListImage::iterator itImage; TSKey v; - string a; + std::string file; if (argc > 1) - a = argv[1]; + file = argv[1]; else - a = "DICOMDIR"; + file = "../gdcmData/DICOMDIR"; - e1 = new gdcmDICOMDIR(a); - - if(e1->GetPatients().begin() == e1->GetPatients().end() ) - std::cout << "Liste Vide" << std::endl; + e1 = new gdcmDicomDir(file); + if (argc > 2) { + int level = atoi(argv[2]); + e1->SetPrintLevel(level); + } + + if(e1->GetPatients().begin() == e1->GetPatients().end() ) + { + std::cout<<"Empty list"<GetPatients().begin(); - while ( itPatient != e1->GetPatients().end() ) { // on degouline la liste de PATIENT - //cout << " = PATIENT ==========================================" << std::endl; - //deb = (*itPatient)->beginObj; - //fin = (*((*itPatient)->GetStudies()).begin())->beginObj; - //e1->SetPrintLevel(2); - //aff(deb,fin,1); - std::cout << (*itPatient)->GetEntryByNumber(0x0010, 0x0010) << std::endl; // Patient's Name - itPatient ++; - } + itPatient = e1->GetPatients().begin(); + while ( itPatient != e1->GetPatients().end() ) { // on degouline la liste de PATIENT + std::cout << (*itPatient)->GetEntryByNumber(0x0010, 0x0010) << std::endl; // Patient's Name + itPatient ++; + } +// STUDY cout << std::endl << std::endl << " = Liste des PATIENT/STUDY ==========================================" - << std::endl<< std::endl; + << std::endl<< std::endl; + + itPatient = e1->GetPatients().begin(); + while ( itPatient != e1->GetPatients().end() ) { // on degouline la liste de PATIENT + std::cout << (*itPatient)->GetEntryByNumber(0x0010, 0x0010) << std::endl; // Patient's Name + itStudy = ((*itPatient)->GetStudies()).begin(); + while (itStudy != (*itPatient)->GetStudies().end() ) { // on degouline les STUDY de ce patient + std::cout << "--- "<< (*itStudy)->GetEntryByNumber(0x0008, 0x1030) << std::endl; // Stdy Description + ++itStudy; + } + itPatient ++; + } + +// SERIE + cout << std::endl << std::endl + << " = Liste des PATIENT/STUDY/SERIE ==========================================" + << std::endl<< std::endl; - itPatient = e1->GetPatients().begin(); - while ( itPatient != e1->GetPatients().end() ) { // on degouline la liste de PATIENT - std::cout << (*itPatient)->GetEntryByNumber(0x0010, 0x0010) << std::endl; // Patient's Name - lStudy::iterator itStudy = ((*itPatient)->GetStudies()).begin(); - while (itStudy != (*itPatient)->GetStudies().end() ) { // on degouline les STUDY de ce patient - std::cout << "--- "<< (*itStudy)->GetEntryByNumber(0x0008, 0x1030) << std::endl; // Stdy Description - - - ++itStudy; - } - itPatient ++; - } - + itPatient = e1->GetPatients().begin(); + while ( itPatient != e1->GetPatients().end() ) { // on degouline la liste de PATIENT + std::cout << (*itPatient)->GetEntryByNumber(0x0010, 0x0010) << std::endl; // Patient's Name + itStudy = ((*itPatient)->GetStudies()).begin(); + while (itStudy != (*itPatient)->GetStudies().end() ) { // on degouline les STUDY de ce patient + std::cout << "--- "<< (*itStudy)->GetEntryByNumber(0x0008, 0x1030) << std::endl; // Study Description + itSerie = ((*itStudy)->GetSeries()).begin(); + while (itSerie != (*itStudy)->GetSeries().end() ) { // on degouline les SERIES de cette study + std::cout << "--- --- "<< (*itSerie)->GetEntryByNumber(0x0008, 0x103e) << std::endl; // Serie Description + ++itSerie; + } + ++itStudy; + } + itPatient ++; + } + +// IMAGE cout << std::endl << std::endl - << " = Liste des PATIENT/STUDY/SERIE ==========================================" - << std::endl<< std::endl; + << " = Liste des PATIENT/STUDY/SERIE/IMAGE ===================================" + << std::endl<< std::endl; - itPatient = e1->GetPatients().begin(); - while ( itPatient != e1->GetPatients().end() ) { // on degouline la liste de PATIENT - std::cout << (*itPatient)->GetEntryByNumber(0x0010, 0x0010) << std::endl; // Patient's Name - lStudy::iterator itStudy = ((*itPatient)->GetStudies()).begin(); - while (itStudy != (*itPatient)->GetStudies().end() ) { // on degouline les STUDY de ce patient - std::cout << "--- "<< (*itStudy)->GetEntryByNumber(0x0008, 0x1030) << std::endl; // Study Description - lSerie::iterator itSerie = ((*itStudy)->GetSeries()).begin(); - while (itSerie != (*itStudy)->GetSeries().end() ) { // on degouline les SERIES de cette study - std::cout << "--- --- "<< (*itSerie)->GetEntryByNumber(0x0008, 0x103e) << std::endl; // Serie Description - ++itSerie; - } - ++itStudy; - } - itPatient ++; - } + itPatient = e1->GetPatients().begin(); + while ( itPatient != e1->GetPatients().end() ) { // on degouline la liste de PATIENT + std::cout << (*itPatient)->GetEntryByNumber(0x0010, 0x0010) << std::endl; // Patient's Name + itStudy = ((*itPatient)->GetStudies()).begin(); + while (itStudy != (*itPatient)->GetStudies().end() ) { // on degouline les STUDY de ce patient + std::cout << "--- "<< (*itStudy)->GetEntryByNumber(0x0008, 0x1030) << std::endl; // Study Description + itSerie = ((*itStudy)->GetSeries()).begin(); + while (itSerie != (*itStudy)->GetSeries().end() ) { // on degouline les SERIES de cette study + std::cout << "--- --- "<< (*itSerie)->GetEntryByNumber(0x0008, 0x103e) << std::endl; // Serie Description + itImage = ((*itSerie)->GetImages()).begin(); + while (itImage != (*itSerie)->GetImages().end() ) { // on degouline les SERIES de cette study + std::cout << "--- --- --- "<< (*itImage)->GetEntryByNumber(0x0004, 0x1500) << std::endl; // File name + ++itImage; + } + ++itSerie; + } + ++itStudy; + } + itPatient ++; + }*/ +// DICOM DIR cout << std::endl << std::endl - << " = Contenu Complet du DICOMDIR ==========================================" - << std::endl<< std::endl; + << " = Contenu Complet du DICOMDIR ==========================================" + << std::endl<< std::endl; + e1->Print(); - itPatient = e1->GetPatients().begin(); - while ( itPatient != e1->GetPatients().end() ) { // on degouline la liste de PATIENT - cout << " = PATIENT ==========================================" << std::endl; - deb = (*itPatient)->beginObj; - fin = (*((*itPatient)->GetStudies()).begin())->beginObj; - e1->SetPrintLevel(2); - aff(deb,fin,1); - - lStudy::iterator itStudy = ((*itPatient)->GetStudies()).begin(); - while (itStudy != (*itPatient)->GetStudies().end() ) { // on degouline les STUDY de ce patient - std::cout << " ==== STUDY ==========================================" <beginObj; - fin = (*((*itStudy)->GetSeries()).begin())->beginObj; - //e1->SetPrintLevel(2); - aff(deb,fin,1); - - lSerie::iterator itSerie = ((*itStudy)->GetSeries()).begin(); - while (itSerie != (*itStudy)->GetSeries().end() ) { // on degouline les SERIES de cette study - cout << " ======= SERIES ==========================================" << std::endl; - deb = (*itSerie)->beginObj; - fin = (*((*itSerie)->GetImages()).begin())->beginObj; - //e1->SetPrintLevel(2); - aff(deb,fin,1); - - lImage::iterator itImage = ((*itSerie)->GetImages()).begin(); - while (itImage != (*itSerie)->GetImages().end() ) { // on degouline les IMAGE de cette serie - - cout << " ========== IMAGE ==========================================" << std::endl; - std::cout << "--- --- --- File Name: "<< (*itImage)->GetEntryByNumber(0x0004, 0x1500) << std::endl; // Referenced File - - ++itImage; - } - ++itSerie; - } - ++itStudy; - } - itPatient ++; - } - - delete e1; +/* itPatient = e1->GetPatients().begin(); + while ( itPatient != e1->GetPatients().end() ) { // on degouline la liste de PATIENT + cout << " = PATIENT ==========================================" << std::endl; + deb = (*itPatient)->beginObj; + fin = (*((*itPatient)->GetStudies()).begin())->beginObj; + e1->SetPrintLevel(2); + aff(deb,fin,1); + + itStudy = ((*itPatient)->GetStudies()).begin(); + while (itStudy != (*itPatient)->GetStudies().end() ) { // on degouline les STUDY de ce patient + std::cout << " ==== STUDY ==========================================" <beginObj; + fin = (*((*itStudy)->GetSeries()).begin())->beginObj; + //e1->SetPrintLevel(2); + aff(deb,fin,1); + + itSerie = ((*itStudy)->GetSeries()).begin(); + while (itSerie != (*itStudy)->GetSeries().end() ) { // on degouline les SERIES de cette study + cout << " ======= SERIES ==========================================" << std::endl; + deb = (*itSerie)->beginObj; + fin = (*((*itSerie)->GetImages()).begin())->beginObj; + //e1->SetPrintLevel(2); + aff(deb,fin,1); + + itImage = ((*itSerie)->GetImages()).begin(); + while (itImage != (*itSerie)->GetImages().end() ) { // on degouline les IMAGE de cette serie + cout << " ========== IMAGE ==========================================" << std::endl; + std::cout << "--- --- --- File Name: "<< (*itImage)->GetEntryByNumber(0x0004, 0x1500) << std::endl; // Referenced File + + ++itImage; + } + ++itSerie; + } + ++itStudy; + } + itPatient ++; + }*/ + + delete e1; + + return(0); } diff --git a/gdcm.dsw b/gdcm.dsw index fa57c94e..dfeb8b92 100644 --- a/gdcm.dsw +++ b/gdcm.dsw @@ -39,6 +39,21 @@ Package=<4> ############################################################################### +Project: "gdcmTestDicomDir"=.\TEST\WIN32\gdcmTestDicomDir.dsp - Package Owner=<4> + +Package=<5> +{{{ +}}} + +Package=<4> +{{{ + Begin Project Dependency + Project_Dep_Name gdcmdll + End Project Dependency +}}} + +############################################################################### + Project: "gdcmdll"=.\src\win32\gdcmdll.dsp - Package Owner=<4> Package=<5> diff --git a/gdcmPython/win32/_vtkGdcm.dsp b/gdcmPython/win32/_vtkGdcm.dsp index be158e83..596f6a4a 100644 --- a/gdcmPython/win32/_vtkGdcm.dsp +++ b/gdcmPython/win32/_vtkGdcm.dsp @@ -58,6 +58,10 @@ LINK32=link.exe # PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat" # Begin Source File +SOURCE=..\..\src\gdcmDicomDir.cxx +# End Source File +# Begin Source File + SOURCE=..\..\src\gdcmDict.cxx # End Source File # Begin Source File @@ -90,6 +94,10 @@ SOURCE=..\..\src\gdcmHeaderHelper.cxx # End Source File # Begin Source File +SOURCE=..\..\src\gdcmImage.cxx +# End Source File +# Begin Source File + SOURCE=..\..\src\gdcmJpeg.cxx # End Source File # Begin Source File @@ -102,6 +110,10 @@ SOURCE=..\..\src\gdcmJpeg2000.cxx # End Source File # Begin Source File +SOURCE=..\..\src\gdcmObject.cxx +# End Source File +# Begin Source File + SOURCE=..\..\src\gdcmParsePixels.cxx # End Source File # Begin Source File @@ -110,10 +122,22 @@ SOURCE=..\..\src\gdcmParser.cxx # End Source File # Begin Source File +SOURCE=..\..\src\gdcmPatient.cxx +# End Source File +# Begin Source File + SOURCE=..\..\src\gdcmRLE.cxx # End Source File # Begin Source File +SOURCE=..\..\src\gdcmSerie.cxx +# End Source File +# Begin Source File + +SOURCE=..\..\src\gdcmStudy.cxx +# End Source File +# Begin Source File + SOURCE=..\..\src\gdcmTS.cxx # End Source File # Begin Source File diff --git a/gdcmPython/win32/gdcmpyembedded.dsp b/gdcmPython/win32/gdcmpyembedded.dsp index ea230953..de390fe5 100644 --- a/gdcmPython/win32/gdcmpyembedded.dsp +++ b/gdcmPython/win32/gdcmpyembedded.dsp @@ -53,7 +53,7 @@ LINK32=link.exe # Begin Special Build Tool ProjDir=. SOURCE="$(InputPath)" -PostBuild_Cmds=move $(ProjDir)\gdcm.py $(ProjDir)\..\ +PostBuild_Cmds=move $(ProjDir)\gdcm.py $(ProjDir)\..\ # End Special Build Tool # Begin Target @@ -80,6 +80,10 @@ SOURCE=.\gdcm_wrap.cxx # End Source File # Begin Source File +SOURCE=..\..\src\gdcmDicomDir.cxx +# End Source File +# Begin Source File + SOURCE=..\..\src\gdcmDict.cxx # End Source File # Begin Source File @@ -112,6 +116,10 @@ SOURCE=..\..\src\gdcmHeaderHelper.cxx # End Source File # Begin Source File +SOURCE=..\..\src\gdcmImage.cxx +# End Source File +# Begin Source File + SOURCE=..\..\src\gdcmJpeg.cxx # End Source File # Begin Source File @@ -124,6 +132,10 @@ SOURCE=..\..\src\gdcmJpeg2000.cxx # End Source File # Begin Source File +SOURCE=..\..\src\gdcmObject.cxx +# End Source File +# Begin Source File + SOURCE=..\..\src\gdcmParsePixels.cxx # End Source File # Begin Source File @@ -132,10 +144,22 @@ SOURCE=..\..\src\gdcmParser.cxx # End Source File # Begin Source File +SOURCE=..\..\src\gdcmPatient.cxx +# End Source File +# Begin Source File + SOURCE=..\..\src\gdcmRLE.cxx # End Source File # Begin Source File +SOURCE=..\..\src\gdcmSerie.cxx +# End Source File +# Begin Source File + +SOURCE=..\..\src\gdcmStudy.cxx +# End Source File +# Begin Source File + SOURCE=..\..\src\gdcmTS.cxx # End Source File # Begin Source File diff --git a/src/gdcmDicomDir.cxx b/src/gdcmDicomDir.cxx index eaf7e82f..edd6e84e 100644 --- a/src/gdcmDicomDir.cxx +++ b/src/gdcmDicomDir.cxx @@ -1,101 +1,194 @@ // gdcmDicomDir.cxx //----------------------------------------------------------------------------- #include "gdcmDicomDir.h" -#include "gdcmPatient.h" #include "gdcmStudy.h" #include "gdcmSerie.h" #include "gdcmImage.h" +#include "gdcmUtil.h" #include +//----------------------------------------------------------------------------- +// Constructor / Destructor gdcmDicomDir::gdcmDicomDir(std::string & FileName, bool exception_on_error): - gdcmParser(FileName.c_str(),exception_on_error, true ) { - - - gdcmPatient *patCur; - gdcmStudy *studCur; - gdcmSerie *serCur; - gdcmImage *imaCur; - - ListTag::iterator i, j; - - - if ( GetListEntry().begin() == GetListEntry().end() ) { - cout << "ListEntry vide " << endl; - } - - i = GetListEntry().begin(); - while ( i != GetListEntry().end() ) { - - // std::cout << std::hex << (*i)->GetGroup() << - // " " << (*i)->GetElement() << endl; - - std::string v = (*i)->GetValue(); - if (v == "PATIENT ") { - patCur=new gdcmPatient(); - //cout << "PATIENT" << endl, - patCur->beginObj =i; - GetPatients().push_back(patCur); - } - - if (v == "STUDY ") { - //cout << "STUDY" << endl, - studCur=new gdcmStudy(); - studCur->beginObj = patCur->endObj = i; - lPatient::iterator aa = GetPatients().end(); - --aa; - (*aa)->GetStudies().push_back(studCur); - } - studCur=new gdcmStudy(); - - if (v == "SERIES") { - //cout << "SERIES" << endl, - serCur=new gdcmSerie(); - - serCur->beginObj = studCur->endObj= i; - lPatient::iterator aa = GetPatients().end(); - --aa; - lStudy::iterator bb = (*aa)->GetStudies().end(); - --bb; - (*bb)->GetSeries().push_back(serCur); - } - - if (v == "IMAGE ") { - //cout << "IMAGE" << endl; - imaCur=new gdcmImage(); - imaCur->beginObj = serCur->endObj= i; - - lPatient::iterator aa = GetPatients().end(); - --aa; - lStudy::iterator bb = (*aa)->GetStudies().end(); - --bb; - lSerie::iterator cc = (*bb)->GetSeries().end(); - --cc; - (*cc)->GetImages().push_back(imaCur); - - - /* --- - // ce n'est pas sur une nouvelle IMAGE, qu'il faut intervenir - // mais lorsqu'on rencontre un 'non IMAGE' apres des 'IMAGE' - lImage::iterator dd = (*cc)->GetImages().end(); - - if ( (*cc)->GetImages().begin() != dd ) { - --dd; - (*dd)->endObj = i; - } - --- */ - } - ++i; - } + gdcmParser(FileName.c_str(),exception_on_error, true ) +{ + if ( GetListEntry().begin() == GetListEntry().end() ) + { + dbg.Verbose(0, "gdcmDicomDir::gdcmDicomDir entry list empty"); + } + + CreateDicomDir(); } -gdcmDicomDir::~gdcmDicomDir() { - lPatient::iterator cc = GetPatients().begin(); - while (cc != GetPatients().end() ) { - //cout << "delete PATIENT" << endl; +gdcmDicomDir::~gdcmDicomDir() +{ + for(ListPatient::iterator cc = patients.begin();cc!=patients.end();++cc) + { delete *cc; - ++cc; } } + +//----------------------------------------------------------------------------- +// Print +void gdcmDicomDir::Print(std::ostream &os) +{ + for(ListPatient::iterator cc = patients.begin();cc!=patients.end();++cc) + { + (*cc)->SetPrintLevel(printLevel); + (*cc)->Print(os); + } +} + +//----------------------------------------------------------------------------- +// Public + +//----------------------------------------------------------------------------- +// Protected + +//----------------------------------------------------------------------------- +// Private +void gdcmDicomDir::CreateDicomDir(void) +{ + // The list is parsed. When a tag is found : + // 1 - we save the beginning iterator + // 2 - we continue to parse + // 3 - we find an other tag + // + we create the object for the precedent tag + // + loop to 1 - + + gdcmDicomDirType type=gdcmDicomDir::GDCM_NONE; + ListTag::iterator begin; + ListTag::iterator end; + + begin=GetListEntry().begin(); + end=begin; + for(ListTag::iterator i=GetListEntry().begin();i != GetListEntry().end();++i) + { + // std::cout << std::hex << (*i)->GetGroup() << + // " " << (*i)->GetElement() << endl; + + std::string v = (*i)->GetValue(); + if (v == "PATIENT ") + { +// std::cout<<"PATIENT"<0) + { + ListPatient::iterator itp=patients.end(); + itp--; + (*itp)->AddStudy(new gdcmStudy(begin,end)); + } +} + +void gdcmDicomDir::AddSerieToEnd(ListTag::iterator begin,ListTag::iterator end) +{ + if(patients.size()>0) + { + ListPatient::iterator itp=patients.end(); + itp--; + + if((*itp)->GetStudies().size()>0) + { + ListStudy::iterator itst=(*itp)->GetStudies().end(); + itst--; + (*itst)->AddSerie(new gdcmSerie(begin,end)); + } + } +} + +void gdcmDicomDir::AddImageToEnd(ListTag::iterator begin,ListTag::iterator end) +{ + if(patients.size()>0) + { + ListPatient::iterator itp=patients.end(); + itp--; + + if((*itp)->GetStudies().size()>0) + { + ListStudy::iterator itst=(*itp)->GetStudies().end(); + itst--; + + if((*itst)->GetSeries().size()>0) + { + ListSerie::iterator its=(*itst)->GetSeries().end(); + its--; + (*its)->AddImage(new gdcmImage(begin,end)); + } + } + } +} + +//----------------------------------------------------------------------------- diff --git a/src/gdcmDicomDir.h b/src/gdcmDicomDir.h index 1426b631..d3fbc023 100644 --- a/src/gdcmDicomDir.h +++ b/src/gdcmDicomDir.h @@ -8,8 +8,7 @@ #include "gdcmPatient.h" //----------------------------------------------------------------------------- - -typedef std::list lPatient; +typedef std::list ListPatient; //----------------------------------------------------------------------------- /* @@ -17,18 +16,35 @@ typedef std::list lPatient; * \brief gdcmDicomDir defines an object representing a DICOMDIR in memory. * */ -class GDCM_EXPORT gdcmDicomDir: public gdcmParser { +class GDCM_EXPORT gdcmDicomDir: public gdcmParser +{ public: - gdcmDicomDir(std::string &FileName,bool exception_on_error = false ); - ~gdcmDicomDir(); + ~gdcmDicomDir(void); + + void SetPrintLevel(int level) { printLevel = level; }; + virtual void Print(std::ostream &os = std::cout); - inline lPatient &GetPatients() {return patients;}; - inline void AddPatient(gdcmPatient *patient) {patients.push_back(patient);}; + inline ListPatient &GetPatients() {return patients;}; + + typedef enum + { + GDCM_NONE, + GDCM_PATIENT, + GDCM_STUDY, + GDCM_SERIE, + GDCM_IMAGE, + } gdcmDicomDirType; private: - lPatient patients; - + void CreateDicomDir(void); + void AddObjectToEnd(gdcmDicomDirType type,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); + + ListPatient patients; }; //----------------------------------------------------------------------------- diff --git a/src/gdcmHeaderEntry.cxx b/src/gdcmHeaderEntry.cxx index d11b342f..56ff8978 100644 --- a/src/gdcmHeaderEntry.cxx +++ b/src/gdcmHeaderEntry.cxx @@ -44,9 +44,9 @@ void gdcmHeaderEntry::Print(std::ostream & os) { v = GetValue(); o = GetOffset(); sprintf(greltag,"%04x|%04x ",g,e); - d2 = _CreateCleanString(v); // replace non printable characters by '.' s << greltag ; + d2 = _CreateCleanString(v); // replace non printable characters by '.' if (printLevel>=2) { s << "lg : "; lgth = GetReadLength(); @@ -97,7 +97,7 @@ void gdcmHeaderEntry::Print(std::ostream & os) { else sprintf(st," x(%08x)",atoi(v.c_str())); s << st; - } + } s << std::endl; os << s.str(); } diff --git a/src/gdcmImage.cxx b/src/gdcmImage.cxx index 382a7470..30588f46 100644 --- a/src/gdcmImage.cxx +++ b/src/gdcmImage.cxx @@ -2,12 +2,32 @@ //----------------------------------------------------------------------------- #include "gdcmImage.h" -gdcmImage::gdcmImage() { +//----------------------------------------------------------------------------- +// Constructor / Destructor +gdcmImage::gdcmImage(ListTag::iterator begin,ListTag::iterator end): + gdcmObject(begin,end) +{ +} +gdcmImage::~gdcmImage() +{ +} + +//----------------------------------------------------------------------------- +// Print +void gdcmImage::Print(std::ostream &os) +{ + os<<"IMAGE"<SetPrintLevel(printLevel); + (*i)->Print(os); + } } -*/ - -std::string gdcmObject::GetEntryByNumber(guint16 group, guint16 element) { - guint16 gr, el; - ListTag::iterator deb , fin; - deb = beginObj; - fin = endObj; - - ListTag::iterator i=deb; - - if (deb == fin) cout << "Big Trouble : Empty List!" <GetGroup()==group && (*i)->GetElement()==element) + return (*i)->GetValue(); + } + return GDCM_UNFOUND; } -std::string gdcmObject::GetEntryByName(TagName name) { +std::string gdcmObject::GetEntryByName(TagName name) +{ gdcmDict *PubDict=gdcmGlobal::GetDicts()->GetDefaultPubDict(); gdcmDictEntry *dictEntry = (*PubDict).GetDictEntryByName(name); + if( dictEntry == NULL) return GDCM_UNFOUND; return GetEntryByNumber(dictEntry->GetGroup(),dictEntry->GetElement()); } +//----------------------------------------------------------------------------- +// Protected + +//----------------------------------------------------------------------------- +// Private + +//----------------------------------------------------------------------------- diff --git a/src/gdcmObject.h b/src/gdcmObject.h index 77c2aab1..ff560f55 100644 --- a/src/gdcmObject.h +++ b/src/gdcmObject.h @@ -14,15 +14,25 @@ class gdcmObject; typedef std::list ListContent; //----------------------------------------------------------------------------- -class gdcmObject { +class GDCM_EXPORT gdcmObject +{ public: + gdcmObject(ListTag::iterator begin,ListTag::iterator end); + ~gdcmObject(void); + + void SetPrintLevel(int level) { printLevel = level; }; + virtual void Print(std::ostream &os = std::cout); + std::string GetEntryByNumber(guint16 group, guint16 element); std::string GetEntryByName(TagName name); +protected: ListTag::iterator beginObj; ListTag::iterator endObj; - -protected: + + int printLevel; + +private: }; //----------------------------------------------------------------------------- diff --git a/src/gdcmParser.h b/src/gdcmParser.h index 8e9e5af6..34311b8e 100644 --- a/src/gdcmParser.h +++ b/src/gdcmParser.h @@ -136,8 +136,11 @@ protected: static const unsigned int HEADER_LENGTH_TO_READ; static const unsigned int MAX_SIZE_LOAD_ELEMENT_VALUE; + protected: int enableSequences; + int printLevel; + private: // Read void Parse(bool exception_on_error = false) throw(gdcmFormatError); @@ -210,9 +213,6 @@ private: // this upper bound is fixed to 1024 bytes (which might look reasonable // when one considers the definition of the various VR contents). guint32 MaxSizeLoadEntry; - - // for PrintHeader - int printLevel; }; //----------------------------------------------------------------------------- diff --git a/src/gdcmPatient.cxx b/src/gdcmPatient.cxx index 45781881..11ec6ac8 100644 --- a/src/gdcmPatient.cxx +++ b/src/gdcmPatient.cxx @@ -2,16 +2,42 @@ //----------------------------------------------------------------------------- #include "gdcmPatient.h" -gdcmPatient::gdcmPatient() { +//----------------------------------------------------------------------------- +// Constructor / Destructor +gdcmPatient::gdcmPatient(ListTag::iterator begin,ListTag::iterator end): + gdcmObject(begin,end) +{ +} +gdcmPatient::~gdcmPatient() +{ + for(ListStudy::iterator cc = studies.begin();cc != studies.end();++cc) + { + delete *cc; + } } +//----------------------------------------------------------------------------- +// Print +void gdcmPatient::Print(std::ostream &os) +{ + os<<"PATIENT"<SetPrintLevel(printLevel); + (*cc)->Print(os); } } +//----------------------------------------------------------------------------- +// Public + +//----------------------------------------------------------------------------- +// Protected + +//----------------------------------------------------------------------------- +// Private + +//----------------------------------------------------------------------------- diff --git a/src/gdcmPatient.h b/src/gdcmPatient.h index 662bca15..2d4d1e26 100644 --- a/src/gdcmPatient.h +++ b/src/gdcmPatient.h @@ -7,23 +7,22 @@ #include "gdcmStudy.h" //----------------------------------------------------------------------------- - -typedef std::list lStudy; +typedef std::list ListStudy; //----------------------------------------------------------------------------- - -class GDCM_EXPORT gdcmPatient : public gdcmObject { // +class GDCM_EXPORT gdcmPatient : public gdcmObject +{ public: + gdcmPatient(ListTag::iterator begin,ListTag::iterator end); + ~gdcmPatient(void); - gdcmPatient(); - ~gdcmPatient(); + virtual void Print(std::ostream &os = std::cout); - inline lStudy &GetStudies() {return studies;}; + inline ListStudy &GetStudies() {return studies;}; + inline void AddStudy(gdcmStudy *obj) {studies.push_back(obj);}; - lStudy studies; private: - - + ListStudy studies; }; //----------------------------------------------------------------------------- diff --git a/src/gdcmSerie.cxx b/src/gdcmSerie.cxx index 9e4a275b..b21c2417 100644 --- a/src/gdcmSerie.cxx +++ b/src/gdcmSerie.cxx @@ -2,16 +2,42 @@ //----------------------------------------------------------------------------- #include "gdcmSerie.h" -gdcmSerie::gdcmSerie() { +//----------------------------------------------------------------------------- +// Constructor / Destructor +gdcmSerie::gdcmSerie(ListTag::iterator begin,ListTag::iterator end): + gdcmObject(begin,end) +{ +} +gdcmSerie::~gdcmSerie() +{ + for(ListImage::iterator cc = images.begin();cc != images.end();++cc) + { + delete *cc; + } } +//----------------------------------------------------------------------------- +// Print +void gdcmSerie::Print(std::ostream &os) +{ + os<<"SERIE"<SetPrintLevel(printLevel); + (*cc)->Print(os); } } +//----------------------------------------------------------------------------- +// Public + +//----------------------------------------------------------------------------- +// Protected + +//----------------------------------------------------------------------------- +// Private + +//----------------------------------------------------------------------------- diff --git a/src/gdcmSerie.h b/src/gdcmSerie.h index 02fe496d..996203b8 100644 --- a/src/gdcmSerie.h +++ b/src/gdcmSerie.h @@ -7,24 +7,22 @@ #include "gdcmImage.h" //----------------------------------------------------------------------------- - -typedef std::list lImage; +typedef std::list ListImage; //----------------------------------------------------------------------------- - -class GDCM_EXPORT gdcmSerie : public gdcmObject { +class GDCM_EXPORT gdcmSerie : public gdcmObject +{ public: + gdcmSerie(ListTag::iterator begin,ListTag::iterator end); + ~gdcmSerie(void); - gdcmSerie(); - ~gdcmSerie(); - - inline lImage &GetImages() {return images;}; - - lImage images; - -private: + virtual void Print(std::ostream &os = std::cout); + inline ListImage &GetImages() {return images;}; + inline void AddImage(gdcmImage *obj) {images.push_back(obj);}; +private: + ListImage images; }; //----------------------------------------------------------------------------- diff --git a/src/gdcmStudy.cxx b/src/gdcmStudy.cxx index 9380f519..29af9518 100644 --- a/src/gdcmStudy.cxx +++ b/src/gdcmStudy.cxx @@ -2,15 +2,42 @@ //----------------------------------------------------------------------------- #include "gdcmStudy.h" -gdcmStudy::gdcmStudy() { +//----------------------------------------------------------------------------- +// Constructor / Destructor +gdcmStudy::gdcmStudy(ListTag::iterator begin,ListTag::iterator end): + gdcmObject(begin,end) +{ +} +gdcmStudy::~gdcmStudy() +{ + for(ListSerie::iterator cc = series.begin();cc != series.end();++cc) + { + delete *cc; + } } +//----------------------------------------------------------------------------- +// Print +void gdcmStudy::Print(std::ostream &os) +{ + os<<"STUDY"<SetPrintLevel(printLevel); + (*cc)->Print(os); } } + +//----------------------------------------------------------------------------- +// Public + +//----------------------------------------------------------------------------- +// Protected + +//----------------------------------------------------------------------------- +// Private + +//----------------------------------------------------------------------------- diff --git a/src/gdcmStudy.h b/src/gdcmStudy.h index f08f709f..ebf31c1f 100644 --- a/src/gdcmStudy.h +++ b/src/gdcmStudy.h @@ -7,24 +7,22 @@ #include "gdcmSerie.h" //----------------------------------------------------------------------------- - -typedef std::list lSerie; +typedef std::list ListSerie; //----------------------------------------------------------------------------- - -class GDCM_EXPORT gdcmStudy : public gdcmObject { +class GDCM_EXPORT gdcmStudy : public gdcmObject +{ public: + gdcmStudy(ListTag::iterator begin,ListTag::iterator end); + ~gdcmStudy(void); - gdcmStudy(); - ~gdcmStudy(); - - inline lSerie &GetSeries() {return series;}; - - lSerie series; - -private: + 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; }; //----------------------------------------------------------------------------- diff --git a/src/gdcmTS.cxx b/src/gdcmTS.cxx index 7445b59c..469247c6 100644 --- a/src/gdcmTS.cxx +++ b/src/gdcmTS.cxx @@ -34,8 +34,12 @@ gdcmTS::gdcmTS(void) eatwhite(from); from.getline(buff, 1024, ' '); key = buff; + if(key.size()%2==1) - key.push_back(0); + { + key.resize(key.size()+1); + key[key.size()-1]=0; + } eatwhite(from); from.getline(buff, 1024, '\n'); diff --git a/src/gdcmUtil.cxx b/src/gdcmUtil.cxx index 475d71c2..fb1f87fb 100644 --- a/src/gdcmUtil.cxx +++ b/src/gdcmUtil.cxx @@ -118,11 +118,11 @@ char *_cleanString(char *v) { int i, l; l = strlen(v); for (i=0,d=v; - i0) + if(!isprint(s[str.size()-1])) + if(s[str.size()-1]==0) + str[str.size()-1]=' '; + + return(str); +} diff --git a/src/win32/gdcmdll.dsp b/src/win32/gdcmdll.dsp index dcb11081..afb88cf2 100644 --- a/src/win32/gdcmdll.dsp +++ b/src/win32/gdcmdll.dsp @@ -58,7 +58,7 @@ LINK32=link.exe # Begin Special Build Tool SOURCE="$(InputPath)" PostBuild_Desc=Copy for test -PostBuild_Cmds=copy ..\..\lib\gdcmdll.dll ..\..\gdcmPython\ copy ..\..\lib\gdcmdll.dll ..\..\test\ copy Release\gdcmdll.lib ..\..\lib\ +PostBuild_Cmds=copy ..\..\lib\gdcmdll.dll ..\..\gdcmPython\ copy ..\..\lib\gdcmdll.dll ..\..\test\ copy Release\gdcmdll.lib ..\..\lib\ # End Special Build Tool !ELSEIF "$(CFG)" == "gdcmdll - Win32 Debug" @@ -90,7 +90,7 @@ LINK32=link.exe # Begin Special Build Tool SOURCE="$(InputPath)" PostBuild_Desc=Copy for test -PostBuild_Cmds=copy ..\..\lib\gdcmdll.dll ..\..\gdcmPython\ copy ..\..\lib\gdcmdll.dll ..\..\test\ copy Debug\gdcmdll.lib ..\..\lib\ +PostBuild_Cmds=copy ..\..\lib\gdcmdll.dll ..\..\gdcmPython\ copy ..\..\lib\gdcmdll.dll ..\..\test\ copy Debug\gdcmdll.lib ..\..\lib\ # End Special Build Tool !ENDIF @@ -156,6 +156,10 @@ SOURCE=..\gdcmJpeg2000.cxx # End Source File # Begin Source File +SOURCE=..\gdcmObject.cxx +# End Source File +# Begin Source File + SOURCE=..\gdcmParsePixels.cxx # End Source File # Begin Source File @@ -164,6 +168,10 @@ SOURCE=..\gdcmParser.cxx # End Source File # Begin Source File +SOURCE=..\gdcmPatient.cxx +# End Source File +# Begin Source File + SOURCE=..\gdcmRLE.cxx # End Source File # Begin Source File @@ -248,6 +256,10 @@ SOURCE=..\gdcmParser.h # End Source File # Begin Source File +SOURCE=..\gdcmPatient.h +# End Source File +# Begin Source File + SOURCE=..\gdcmSerie.h # End Source File # Begin Source File -- 2.45.2