+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
# else
# include <sstream>
#endif
+#include <string>
+#include <iostream>
#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"<<std::endl;
+ return(1);
+ }
// Exemples exploitation de la structure
-
-ListTag::iterator deb , fin;
-lPatient::iterator itPatient;
-
- cout << std::endl << std::endl
- << " = Liste des PATIENT =========================================="
- << std::endl<< std::endl;
+// PATIENT
+/* cout << std::endl << std::endl
+ << " = Liste des PATIENT =========================================="
+ << std::endl<< std::endl;
- 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);
- 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 ==========================================" <<std::endl;
- deb = (*itStudy)->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 ==========================================" <<std::endl;
+ deb = (*itStudy)->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);
}
###############################################################################
+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>
# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"\r
# Begin Source File\r
\r
+SOURCE=..\..\src\gdcmDicomDir.cxx\r
+# End Source File\r
+# Begin Source File\r
+\r
SOURCE=..\..\src\gdcmDict.cxx\r
# End Source File\r
# Begin Source File\r
# End Source File\r
# Begin Source File\r
\r
+SOURCE=..\..\src\gdcmImage.cxx\r
+# End Source File\r
+# Begin Source File\r
+\r
SOURCE=..\..\src\gdcmJpeg.cxx\r
# End Source File\r
# Begin Source File\r
# End Source File\r
# Begin Source File\r
\r
+SOURCE=..\..\src\gdcmObject.cxx\r
+# End Source File\r
+# Begin Source File\r
+\r
SOURCE=..\..\src\gdcmParsePixels.cxx\r
# End Source File\r
# Begin Source File\r
# End Source File\r
# Begin Source File\r
\r
+SOURCE=..\..\src\gdcmPatient.cxx\r
+# End Source File\r
+# Begin Source File\r
+\r
SOURCE=..\..\src\gdcmRLE.cxx\r
# End Source File\r
# Begin Source File\r
\r
+SOURCE=..\..\src\gdcmSerie.cxx\r
+# End Source File\r
+# Begin Source File\r
+\r
+SOURCE=..\..\src\gdcmStudy.cxx\r
+# End Source File\r
+# Begin Source File\r
+\r
SOURCE=..\..\src\gdcmTS.cxx\r
# End Source File\r
# Begin Source File\r
# Begin Special Build Tool\r
ProjDir=.\r
SOURCE="$(InputPath)"\r
-PostBuild_Cmds=move $(ProjDir)\gdcm.py $(ProjDir)\..\ \r
+PostBuild_Cmds=move $(ProjDir)\gdcm.py $(ProjDir)\..\ \r
# End Special Build Tool\r
# Begin Target\r
\r
# End Source File\r
# Begin Source File\r
\r
+SOURCE=..\..\src\gdcmDicomDir.cxx\r
+# End Source File\r
+# Begin Source File\r
+\r
SOURCE=..\..\src\gdcmDict.cxx\r
# End Source File\r
# Begin Source File\r
# End Source File\r
# Begin Source File\r
\r
+SOURCE=..\..\src\gdcmImage.cxx\r
+# End Source File\r
+# Begin Source File\r
+\r
SOURCE=..\..\src\gdcmJpeg.cxx\r
# End Source File\r
# Begin Source File\r
# End Source File\r
# Begin Source File\r
\r
+SOURCE=..\..\src\gdcmObject.cxx\r
+# End Source File\r
+# Begin Source File\r
+\r
SOURCE=..\..\src\gdcmParsePixels.cxx\r
# End Source File\r
# Begin Source File\r
# End Source File\r
# Begin Source File\r
\r
+SOURCE=..\..\src\gdcmPatient.cxx\r
+# End Source File\r
+# Begin Source File\r
+\r
SOURCE=..\..\src\gdcmRLE.cxx\r
# End Source File\r
# Begin Source File\r
\r
+SOURCE=..\..\src\gdcmSerie.cxx\r
+# End Source File\r
+# Begin Source File\r
+\r
+SOURCE=..\..\src\gdcmStudy.cxx\r
+# End Source File\r
+# Begin Source File\r
+\r
SOURCE=..\..\src\gdcmTS.cxx\r
# End Source File\r
# Begin Source File\r
// gdcmDicomDir.cxx
//-----------------------------------------------------------------------------
#include "gdcmDicomDir.h"
-#include "gdcmPatient.h"
#include "gdcmStudy.h"
#include "gdcmSerie.h"
#include "gdcmImage.h"
+#include "gdcmUtil.h"
#include <string>
+//-----------------------------------------------------------------------------
+// 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"<<std::endl;
+ end=i;
+ AddObjectToEnd(type,begin,end);
+
+ type=gdcmDicomDir::GDCM_PATIENT;
+ begin=end;
+ }
+
+ if (v == "STUDY ")
+ {
+// std::cout<<"STUDY"<<std::endl;
+ end=i;
+ AddObjectToEnd(type,begin,end);
+
+ type=gdcmDicomDir::GDCM_STUDY;
+ begin=end;
+ }
+
+ if (v == "SERIES")
+ {
+// std::cout<<"SERIES"<<std::endl;
+ end=i;
+ AddObjectToEnd(type,begin,end);
+
+ type=gdcmDicomDir::GDCM_SERIE;
+ begin=end;
+ }
+
+ if (v == "IMAGE ")
+ {
+// std::cout<<"IMAGE"<<std::endl;
+ end=i;
+ AddObjectToEnd(type,begin,end);
+
+ type=gdcmDicomDir::GDCM_IMAGE;
+ begin=end;
+ }
+ }
+
+ end=i;
+ AddObjectToEnd(type,begin,end);
+}
+
+void gdcmDicomDir::AddObjectToEnd(gdcmDicomDirType type,ListTag::iterator begin,ListTag::iterator end)
+{
+ if(begin==end)
+ return;
+
+ switch(type)
+ {
+ case gdcmDicomDir::GDCM_PATIENT:
+ AddPatientToEnd(begin,end);
+ break;
+ case gdcmDicomDir::GDCM_STUDY:
+ AddStudyToEnd(begin,end);
+ break;
+ case gdcmDicomDir::GDCM_SERIE:
+ AddSerieToEnd(begin,end);
+ break;
+ case gdcmDicomDir::GDCM_IMAGE:
+ AddImageToEnd(begin,end);
+ break;
+ }
+}
+
+void gdcmDicomDir::AddPatientToEnd(ListTag::iterator begin,ListTag::iterator end)
+{
+ patients.push_back(new gdcmPatient(begin,end));
+}
+
+void gdcmDicomDir::AddStudyToEnd(ListTag::iterator begin,ListTag::iterator end)
+{
+ if(patients.size()>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));
+ }
+ }
+ }
+}
+
+//-----------------------------------------------------------------------------
#include "gdcmPatient.h"
//-----------------------------------------------------------------------------
-
-typedef std::list<gdcmPatient *> lPatient;
+typedef std::list<gdcmPatient *> ListPatient;
//-----------------------------------------------------------------------------
/*
* \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;
};
//-----------------------------------------------------------------------------
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();
else
sprintf(st," x(%08x)",atoi(v.c_str()));
s << st;
- }
+ }
s << std::endl;
os << s.str();
}
//-----------------------------------------------------------------------------
#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"<<std::endl;
+ gdcmObject::Print(os);
}
+//-----------------------------------------------------------------------------
+// Public
-gdcmImage::~gdcmImage() {
+//-----------------------------------------------------------------------------
+// Protected
-}
+//-----------------------------------------------------------------------------
+// Private
+//-----------------------------------------------------------------------------
#include "gdcmObject.h"
//-----------------------------------------------------------------------------
-
-
-//-----------------------------------------------------------------------------
-
-class GDCM_EXPORT gdcmImage : public gdcmObject {
+class GDCM_EXPORT gdcmImage : public gdcmObject
+{
public:
+ gdcmImage(ListTag::iterator begin,ListTag::iterator end);
+ ~gdcmImage(void);
- gdcmImage();
- ~gdcmImage();
-
+ virtual void Print(std::ostream &os = std::cout);
};
//-----------------------------------------------------------------------------
#include "gdcmObject.h"
#include "gdcmUtil.h"
-
-/*
-gdcmObject::gdcmObject() {
-
+//-----------------------------------------------------------------------------
+// Constructor / Destructor
+gdcmObject::gdcmObject(ListTag::iterator begin,ListTag::iterator end)
+{
+ beginObj=begin;
+ endObj=end;
+
+ if(beginObj==endObj)
+ dbg.Verbose(0, "gdcmObject::gdcmObject empty list");
}
+gdcmObject::~gdcmObject(void)
+{
+}
-gdcmObject::~gdcmObject() {
-
+//-----------------------------------------------------------------------------
+// Print
+void gdcmObject::Print(std::ostream &os)
+{
+ for(ListTag::iterator i=beginObj;i!=endObj;++i)
+ {
+ (*i)->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!" <<endl;
- while ( i!= fin) {
- gr = (*(*i)).GetGroup();
- el = (*(*i)).GetElement();
- if ( gr==group && el==element)
- return (*(*i)).GetValue();;
- ++i;
- }
+
+//-----------------------------------------------------------------------------
+// Public
+std::string gdcmObject::GetEntryByNumber(guint16 group, guint16 element)
+{
+ for(ListTag::iterator i=beginObj;i!=endObj;++i)
+ {
+ if ( (*i)->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
+
+//-----------------------------------------------------------------------------
typedef std::list<gdcmObject *> 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:
};
//-----------------------------------------------------------------------------
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);
// 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;
};
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
#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"<<std::endl;
+ gdcmObject::Print(os);
-gdcmPatient::~gdcmPatient() {
- lStudy::iterator cc = GetStudies().begin();
- while (cc != GetStudies().end() ) {
- delete *cc;
- ++cc;
+ for(ListStudy::iterator cc = studies.begin();cc!=studies.end();++cc)
+ {
+ (*cc)->SetPrintLevel(printLevel);
+ (*cc)->Print(os);
}
}
+//-----------------------------------------------------------------------------
+// Public
+
+//-----------------------------------------------------------------------------
+// Protected
+
+//-----------------------------------------------------------------------------
+// Private
+
+//-----------------------------------------------------------------------------
#include "gdcmStudy.h"
//-----------------------------------------------------------------------------
-
-typedef std::list<gdcmStudy *> lStudy;
+typedef std::list<gdcmStudy *> 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;
};
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
#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"<<std::endl;
+ gdcmObject::Print(os);
-gdcmSerie::~gdcmSerie() {
- lImage::iterator cc = GetImages().begin();
- while (cc != GetImages().end() ) {
- delete *cc;
- ++cc;
+ for(ListImage::iterator cc = images.begin();cc != images.end();++cc)
+ {
+ (*cc)->SetPrintLevel(printLevel);
+ (*cc)->Print(os);
}
}
+//-----------------------------------------------------------------------------
+// Public
+
+//-----------------------------------------------------------------------------
+// Protected
+
+//-----------------------------------------------------------------------------
+// Private
+
+//-----------------------------------------------------------------------------
#include "gdcmImage.h"
//-----------------------------------------------------------------------------
-
-typedef std::list<gdcmImage *> lImage;
+typedef std::list<gdcmImage *> 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;
};
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
#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"<<std::endl;
+ gdcmObject::Print(os);
-gdcmStudy::~gdcmStudy() {
- lSerie::iterator cc = GetSeries().begin();
- while (cc != GetSeries().end() ) {
- delete *cc;
- ++cc;
+ for(ListSerie::iterator cc = series.begin();cc != series.end();++cc)
+ {
+ (*cc)->SetPrintLevel(printLevel);
+ (*cc)->Print(os);
}
}
+
+//-----------------------------------------------------------------------------
+// Public
+
+//-----------------------------------------------------------------------------
+// Protected
+
+//-----------------------------------------------------------------------------
+// Private
+
+//-----------------------------------------------------------------------------
#include "gdcmSerie.h"
//-----------------------------------------------------------------------------
-
-typedef std::list<gdcmSerie *> lSerie;
+typedef std::list<gdcmSerie *> 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;
};
//-----------------------------------------------------------------------------
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');
int i, l;
l = strlen(v);
for (i=0,d=v;
- i<l ;
- i++,d++) {
- if (!isprint(*d))
+ i<l ;
+ i++,d++) {
+ if (!isprint(*d))
*d = '.';
- }
+ }
return v;
}
///////////////////////////////////////////////////////////////////////////
// to prevent a flashing screen when non-printable character
std::string _CreateCleanString(std::string s) {
- std::string str=s;
- int n = str.size();
- for(int i=0;i<n-1;i++)
- {
- if(!isprint(str[i]))
- str[i]='.';
- }
- if(!isprint(str[n])) { // to avoid trouble with odd length fields
- // padded with zeo to become even
-
- if (str[n] == '\0')
- str[n] = ' ';
- else
- str[n] = '.';
- }
- return(str);
-}
+ std::string str=s;
+
+ for(int i=0;i<str.size();i++)
+ {
+ if(!isprint(str[i]))
+ str[i]='.';
+ }
+
+ if(str.size()>0)
+ if(!isprint(s[str.size()-1]))
+ if(s[str.size()-1]==0)
+ str[str.size()-1]=' ';
+
+ return(str);
+}
# Begin Special Build Tool\r
SOURCE="$(InputPath)"\r
PostBuild_Desc=Copy for test\r
-PostBuild_Cmds=copy ..\..\lib\gdcmdll.dll ..\..\gdcmPython\ copy ..\..\lib\gdcmdll.dll ..\..\test\ copy Release\gdcmdll.lib ..\..\lib\ \r
+PostBuild_Cmds=copy ..\..\lib\gdcmdll.dll ..\..\gdcmPython\ copy ..\..\lib\gdcmdll.dll ..\..\test\ copy Release\gdcmdll.lib ..\..\lib\ \r
# End Special Build Tool\r
\r
!ELSEIF "$(CFG)" == "gdcmdll - Win32 Debug"\r
# Begin Special Build Tool\r
SOURCE="$(InputPath)"\r
PostBuild_Desc=Copy for test\r
-PostBuild_Cmds=copy ..\..\lib\gdcmdll.dll ..\..\gdcmPython\ copy ..\..\lib\gdcmdll.dll ..\..\test\ copy Debug\gdcmdll.lib ..\..\lib\ \r
+PostBuild_Cmds=copy ..\..\lib\gdcmdll.dll ..\..\gdcmPython\ copy ..\..\lib\gdcmdll.dll ..\..\test\ copy Debug\gdcmdll.lib ..\..\lib\ \r
# End Special Build Tool\r
\r
!ENDIF \r
# End Source File\r
# Begin Source File\r
\r
+SOURCE=..\gdcmObject.cxx\r
+# End Source File\r
+# Begin Source File\r
+\r
SOURCE=..\gdcmParsePixels.cxx\r
# End Source File\r
# Begin Source File\r
# End Source File\r
# Begin Source File\r
\r
+SOURCE=..\gdcmPatient.cxx\r
+# End Source File\r
+# Begin Source File\r
+\r
SOURCE=..\gdcmRLE.cxx\r
# End Source File\r
# Begin Source File\r
# End Source File\r
# Begin Source File\r
\r
+SOURCE=..\gdcmPatient.h\r
+# End Source File\r
+# Begin Source File\r
+\r
SOURCE=..\gdcmSerie.h\r
# End Source File\r
# Begin Source File\r