Program: gdcm
Module: $RCSfile: gdcmDicomDir.cxx,v $
Language: C++
- Date: $Date: 2004/09/27 08:39:05 $
- Version: $Revision: 1.70 $
+ Date: $Date: 2004/10/09 03:21:55 $
+ Version: $Revision: 1.71 $
Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
l'Image). All rights reserved. See Doc/License.txt or
=========================================================================*/
-#include <string>
-#include <algorithm>
-#include <sys/types.h>
-
-#ifdef _MSC_VER
- #include <direct.h>
-#else
- #include <unistd.h>
-#endif
-
#include "gdcmDicomDir.h"
#include "gdcmDicomDirStudy.h"
#include "gdcmDicomDirSerie.h"
#include "gdcmSQItem.h"
#include "gdcmValEntry.h"
+#include <string>
+#include <algorithm>
+#include <sys/types.h>
+
+#ifdef _MSC_VER
+ #include <direct.h>
+#else
+ #include <unistd.h>
+#endif
+
//-----------------------------------------------------------------------------
// For full DICOMDIR description, see:
// PS 3.3-2003, pages 731-750
{
Initialize(); // sets all private fields to NULL
std::string pathBidon = "Bidon"; // Sorry, NULL not allowed ...
- metaElems = NewMeta();
+ MetaElems = NewMeta();
}
/**
{
// user passed '.' as Name
// we get current directory name
- char* dummy = new char[1000];
+ char dummy[1000];
getcwd(dummy, (size_t)1000);
SetFileName( dummy ); // will be converted into a string
- delete[] dummy; // no longer needed
}
if ( parseDir ) // user asked for a recursive parsing of a root directory
{
- metaElems = NewMeta();
+ MetaElems = NewMeta();
dbg.Verbose(0, "gdcmDicomDir::gdcmDicomDir : Parse directory"
" and create the DicomDir");
SetStartMethod(NULL);
SetProgressMethod(NULL);
SetEndMethod(NULL);
- for(ListDicomDirPatient::iterator cc = patients.begin();
- cc!= patients.end();
+ for(ListDicomDirPatient::iterator cc = Patients.begin();
+ cc!= Patients.end();
++cc)
{
delete *cc;
}
- if ( metaElems )
+ if ( MetaElems )
{
- delete metaElems;
+ delete MetaElems;
}
}
*/
void gdcmDicomDir::Print(std::ostream &os)
{
- if(metaElems)
+ if( MetaElems )
{
- metaElems->SetPrintLevel(PrintLevel);
- metaElems->Print(os);
+ MetaElems->SetPrintLevel(PrintLevel);
+ MetaElems->Print(os);
}
- for(ListDicomDirPatient::iterator cc = patients.begin();
- cc != patients.end();
+ for(ListDicomDirPatient::iterator cc = Patients.begin();
+ cc != Patients.end();
++cc)
{
(*cc)->SetPrintLevel( PrintLevel );
{
return false;
}
- if( !metaElems )
+ if( !MetaElems )
{
return false;
}
- if( patients.size() <= 0 )
+ if( Patients.size() <= 0 )
{
return false;
}
void gdcmDicomDir::Initialize()
{
- startMethod = NULL;
- progressMethod = NULL;
- endMethod = NULL;
- startMethodArgDelete = NULL;
- progressMethodArgDelete = NULL;
- endMethodArgDelete = NULL;
- startArg = NULL;
- progressArg = NULL;
- endArg = NULL;
-
- progress = 0.0;
- abort = false;
-
- metaElems = 0;
+ StartMethod = NULL;
+ ProgressMethod = NULL;
+ EndMethod = NULL;
+ StartMethodArgDelete = NULL;
+ ProgressMethodArgDelete = NULL;
+ EndMethodArgDelete = NULL;
+ StartArg = NULL;
+ ProgressArg = NULL;
+ EndArg = NULL;
+
+ Progress = 0.0;
+ Abort = false;
+
+ MetaElems = 0;
}
void gdcmDicomDir::SetStartMethod(gdcmMethod* method, void* arg,
gdcmMethod* argDelete )
{
- if( startArg && startMethodArgDelete )
+ if( StartArg && StartMethodArgDelete )
{
- startMethodArgDelete( startArg );
+ StartMethodArgDelete( StartArg );
}
- startMethod = method;
- startArg = arg;
- startMethodArgDelete = argDelete;
+ StartMethod = method;
+ StartArg = arg;
+ StartMethodArgDelete = argDelete;
}
/**
*/
void gdcmDicomDir::SetStartMethodArgDelete(gdcmMethod* method)
{
- startMethodArgDelete = method;
+ StartMethodArgDelete = method;
}
/**
void gdcmDicomDir::SetProgressMethod(gdcmMethod* method, void* arg,
gdcmMethod* argDelete )
{
- if( progressArg && progressMethodArgDelete )
+ if( ProgressArg && ProgressMethodArgDelete )
{
- progressMethodArgDelete( progressArg );
+ ProgressMethodArgDelete( ProgressArg );
}
- progressMethod = method;
- progressArg = arg;
- progressMethodArgDelete = argDelete;
+ ProgressMethod = method;
+ ProgressArg = arg;
+ ProgressMethodArgDelete = argDelete;
}
/**
*/
void gdcmDicomDir::SetProgressMethodArgDelete(gdcmMethod* method)
{
- progressMethodArgDelete = method;
+ ProgressMethodArgDelete = method;
}
/**
void gdcmDicomDir::SetEndMethod(gdcmMethod* method, void* arg,
gdcmMethod* argDelete )
{
- if( endArg && endMethodArgDelete )
+ if( EndArg && EndMethodArgDelete )
{
- endMethodArgDelete( endArg );
+ EndMethodArgDelete( EndArg );
}
- endMethod = method;
- endArg = arg;
- endMethodArgDelete = argDelete;
+ EndMethod = method;
+ EndArg = arg;
+ EndMethodArgDelete = argDelete;
}
/**
*/
void gdcmDicomDir::SetEndMethodArgDelete(gdcmMethod* method)
{
- endMethodArgDelete = method;
+ EndMethodArgDelete = method;
}
/**
return false;
}
- uint8_t* filePreamble = new uint8_t[128];
+ uint8_t filePreamble[128];
memset(filePreamble, 0, 128);
fwrite(filePreamble,128,1,fp);
fwrite("DICM",4,1,fp);
- delete[] filePreamble;
gdcmDicomDirMeta *ptrMeta = GetDicomDirMeta();
ptrMeta->Write(fp, gdcmExplicitVR);
// force writing 0004|1220 [SQ ], that CANNOT exist within gdcmDicomDirMeta
fwrite(&sq[0],8,1,fp); // 0004 1220 ffff ffff
- for(ListDicomDirPatient::iterator cc = patients.begin();cc!=patients.end();++cc)
+ for(ListDicomDirPatient::iterator cc = Patients.begin();
+ cc != Patients.end();
+ ++cc )
{
(*cc)->Write( fp, gdcmExplicitVR );
}
gdcmHeader *header;
TagHT.clear();
- patients.clear();
+ Patients.clear();
for( gdcmDirList::iterator it = fileList.begin();
it != fileList.end();
++it )
{
- progress = (float)(count+1)/(float)fileList.size();
+ Progress = (float)(count+1)/(float)fileList.size();
CallProgressMethod();
- if( abort )
+ if( Abort )
{
break;
}
// for all the DicomDirPatient Elements
for( it = elemList.begin(); it != elemList.end(); ++it )
{
- tmpGr = it->group;
- tmpEl = it->elem;
+ tmpGr = it->Group;
+ tmpEl = it->Elem;
dictEntry = GetPubDict()->GetDictEntryByNumber(tmpGr, tmpEl);
entry = new gdcmValEntry( dictEntry );
entry->SetOffset(0); // just to avoid further missprinting
- entry->SetValue( it->value );
+ entry->SetValue( it->Value );
// dealing with value length ...
}
gdcmDicomDirPatient *p = new gdcmDicomDirPatient(s, &TagHT);
- patients.push_front( p );
+ Patients.push_front( p );
return p;
}
for( it = elemList.begin(); it != elemList.end(); ++it)
{
- tmpGr = it->group;
- tmpEl = it->elem;
+ tmpGr = it->Group;
+ tmpEl = it->Elem;
dictEntry = GetPubDict()->GetDictEntryByNumber(tmpGr, tmpEl);
entry = new gdcmValEntry( dictEntry ); // Be sure it's never a BinEntry !
entry->SetOffset(0); // just to avoid further missprinting
entry->SetLength(0); // just to avoid further missprinting
- if( header ) // NULL when we Build Up (ex nihilo) a DICOMDIR
- // or when we add the META elems
+ if( header )
+ {
+ // NULL when we Build Up (ex nihilo) a DICOMDIR
+ // or when we add the META elems
val = header->GetEntryByNumber(tmpGr, tmpEl);
+ }
else
+ {
val = GDCM_UNFOUND;
+ }
if( val == GDCM_UNFOUND)
{
val = header->GetFileName();
}
else
+ {
val = &(header->GetFileName().c_str()[path.length()]);
+ }
}
else
- val = it->value;
+ {
+ val = it->Value;
+ }
}
else
{
if ( header->GetEntryLengthByNumber(tmpGr,tmpEl) == 0 )
- val = it->value;
+ val = it->Value;
}
// GDCM_UNFOUND or not !
*/
void gdcmDicomDir::CallStartMethod()
{
- progress = 0.0f;
- abort = false;
- if( startMethod )
+ Progress = 0.0f;
+ Abort = false;
+ if( StartMethod )
{
- startMethod( startArg );
+ StartMethod( StartArg );
}
}
*/
void gdcmDicomDir::CallProgressMethod()
{
- if( progressMethod )
+ if( ProgressMethod )
{
- progressMethod( progressArg );
+ ProgressMethod( ProgressArg );
}
}
*/
void gdcmDicomDir::CallEndMethod()
{
- progress = 1.0f;
- if( endMethod )
+ Progress = 1.0f;
+ if( EndMethod )
{
- endMethod( endArg );
+ EndMethod( EndArg );
}
}
}
gdcmDicomDirType type = gdcmDicomDir::GDCM_DICOMDIR_META;
- metaElems = NewMeta();
+ MetaElems = NewMeta();
ListSQItem listItems = s->GetSQItems();
*/
void gdcmDicomDir::AddDicomDirMeta()
{
- if( metaElems )
+ if( MetaElems )
{
- delete metaElems;
+ delete MetaElems;
}
- metaElems = new gdcmDicomDirMeta( &TagHT );
+ MetaElems = new gdcmDicomDirMeta( &TagHT );
}
/**
*/
void gdcmDicomDir::AddDicomDirPatientToEnd(gdcmSQItem *s)
{
- patients.push_back(new gdcmDicomDirPatient(s, &TagHT));
+ Patients.push_back(new gdcmDicomDirPatient(s, &TagHT));
}
/**
*/
void gdcmDicomDir::AddDicomDirStudyToEnd(gdcmSQItem *s)
{
- if( patients.size() > 0 )
+ if( Patients.size() > 0 )
{
- ListDicomDirPatient::iterator itp = patients.end();
+ ListDicomDirPatient::iterator itp = Patients.end();
itp--;
(*itp)->AddDicomDirStudy(new gdcmDicomDirStudy(s, &TagHT));
}
*/
void gdcmDicomDir::AddDicomDirSerieToEnd(gdcmSQItem *s)
{
- if( patients.size() > 0 )
+ if( Patients.size() > 0 )
{
- ListDicomDirPatient::iterator itp = patients.end();
+ ListDicomDirPatient::iterator itp = Patients.end();
itp--;
if( (*itp)->GetDicomDirStudies().size() > 0 )
*/
void gdcmDicomDir::AddDicomDirImageToEnd(gdcmSQItem *s)
{
- if( patients.size() > 0 )
+ if( Patients.size() > 0 )
{
- ListDicomDirPatient::iterator itp = patients.end();
+ ListDicomDirPatient::iterator itp = Patients.end();
itp--;
if( (*itp)->GetDicomDirStudies().size() > 0 )
Program: gdcm
Module: $RCSfile: gdcmDicomDir.h,v $
Language: C++
- Date: $Date: 2004/09/27 08:39:06 $
- Version: $Revision: 1.32 $
+ Date: $Date: 2004/10/09 03:21:55 $
+ Version: $Revision: 1.33 $
Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
l'Image). All rights reserved. See Doc/License.txt or
/// \sa SetPrintLevel
virtual void Print(std::ostream &os = std::cout);
-// Informations contained in the parser
+ /// Informations contained in the parser
virtual bool IsReadable();
/// Returns a pointer to the gdcmDicomDirMeta for this DICOMDIR.
- gdcmDicomDirMeta* GetDicomDirMeta() { return metaElems; };
+ gdcmDicomDirMeta* GetDicomDirMeta() { return MetaElems; };
/// Returns the PATIENT chained List for this DICOMDIR.
- ListDicomDirPatient &GetDicomDirPatients() { return patients; };
+ ListDicomDirPatient &GetDicomDirPatients() { return Patients; };
-// Parsing
+ /// Parsing
void ParseDirectory();
void SetStartMethod(gdcmMethod*, void* = NULL, gdcmMethod* = NULL);
void SetEndMethodArgDelete(gdcmMethod*);
/// GetProgress GetProgress
- float GetProgress() { return progress; };
+ float GetProgress() { return Progress; };
/// AbortProgress AbortProgress
- void AbortProgress() { abort = true; };
+ void AbortProgress() { Abort = true; };
/// IsAborted IsAborted
- bool IsAborted() { return abort; };
+ bool IsAborted() { return Abort; };
-// Adding
+ /// Adding
gdcmDicomDirMeta* NewMeta();
gdcmDicomDirPatient* NewPatient();
-// Write
+ /// Write
bool WriteDicomDir(std::string const & fileName);
/// Types of the gdcmDicomDirObject within the gdcmDicomDir
// Variables
/// Pointer on *the* gdcmDicomDirObject 'DicomDirMeta Elements'
- gdcmDicomDirMeta* metaElems;
+ gdcmDicomDirMeta* MetaElems;
/// Chained list of DicomDirPatient (to be exploited recursively)
- ListDicomDirPatient patients;
-
-/// pointer to the initialisation method for any progress bar
- gdcmMethod* startMethod;
-/// pointer to the incrementation method for any progress bar
- gdcmMethod* progressMethod;
-/// pointer to the termination method for any progress bar
- gdcmMethod* endMethod;
-/// pointer to the ??? method for any progress bar
- gdcmMethod* startMethodArgDelete;
-/// pointer to the ??? method for any progress bar
- gdcmMethod* progressMethodArgDelete;
-/// pointer to the ??? method for any progress bar
- gdcmMethod* endMethodArgDelete;
-/// pointer to the ??? for any progress bar
- void* startArg;
-/// pointer to the ??? for any progress bar
- void* progressArg;
-/// pointer to the ??? for any progress bar
- void* endArg;
-/// value of the ??? for any progress bar
- float progress;
-/// value of the ??? for any progress bar
- bool abort;
+ ListDicomDirPatient Patients;
+
+ /// pointer to the initialisation method for any progress bar
+ gdcmMethod* StartMethod;
+ /// pointer to the incrementation method for any progress bar
+ gdcmMethod* ProgressMethod;
+ /// pointer to the termination method for any progress bar
+ gdcmMethod* EndMethod;
+ /// pointer to the ??? method for any progress bar
+ gdcmMethod* StartMethodArgDelete;
+ /// pointer to the ??? method for any progress bar
+ gdcmMethod* ProgressMethodArgDelete;
+ /// pointer to the ??? method for any progress bar
+ gdcmMethod* EndMethodArgDelete;
+ /// pointer to the ??? for any progress bar
+ void* StartArg;
+ /// pointer to the ??? for any progress bar
+ void* ProgressArg;
+ /// pointer to the ??? for any progress bar
+ void* EndArg;
+ /// value of the ??? for any progress bar
+ float Progress;
+ /// value of the ??? for any progress bar
+ bool Abort;
};
//-----------------------------------------------------------------------------
Program: gdcm
Module: $RCSfile: gdcmDicomDirElement.cxx,v $
Language: C++
- Date: $Date: 2004/10/08 04:43:37 $
- Version: $Revision: 1.17 $
+ Date: $Date: 2004/10/09 03:21:55 $
+ Version: $Revision: 1.18 $
Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
l'Image). All rights reserved. See Doc/License.txt or
#include "gdcmDictSet.h"
#include <fstream>
-#include <stdio.h> // For sprintf
#include <iostream>
//-----------------------------------------------------------------------------
while (!from.eof())
{
- from >> std::ws; // used to be eatwhite(from);
+ from >> std::ws;
from.getline(buff, 1024, ' ');
type = buff;
(type=="studyElem") || (type=="serieElem") ||
(type=="imageElem") )
{
- from >> std::hex >> elem.group >> elem.elem;
+ from >> std::hex >> elem.Group >> elem.Elem;
- from >> std::ws; // used to be eatwhite(from);
+ from >> std::ws;
from.getline(buff, 1024, '"');
- from >> std::ws; // Used to be eatwhite(from);
+ from >> std::ws;
from.getline(buff, 1024, '"');
- elem.value = buff;
+ elem.Value = buff;
if( type == "metaElem" )
{
{
std::ostringstream s;
std::list<gdcmElement>::iterator it;
- char greltag[10]; //group element tag
+ //char greltag[10]; //group element tag
+ std::string greltag;
s << "Meta Elements :"<<std::endl;
for (it = DicomDirMetaList.begin(); it != DicomDirMetaList.end(); ++it)
{
- sprintf(greltag,"%04x|%04x ",it->group,it->elem);
- s << " ("<<greltag<<") = "<< it->value<<std::endl;
+ greltag = Format("%04x|%04x ",it->Group,it->Elem);
+ s << " (" << greltag << ") = " << it->Value << std::endl;
}
s << "Patient Elements :"<<std::endl;
for (it = DicomDirPatientList.begin(); it != DicomDirPatientList.end(); ++it)
{
- sprintf(greltag,"%04x|%04x ",it->group,it->elem);
- s << " ("<<greltag<<") = "<< it->value<<std::endl;
+ greltag = Format("%04x|%04x ",it->Group,it->Elem);
+ s << " (" << greltag << ") = " << it->Value << std::endl;
}
s << "Study Elements :"<<std::endl;
for (it = DicomDirStudyList.begin(); it != DicomDirStudyList.end(); ++it)
{
- sprintf(greltag,"%04x|%04x ",it->group,it->elem);
- s << " ("<<greltag<<") = "<< it->value<<std::endl;
+ greltag = Format("%04x|%04x ", it->Group, it->Elem);
+ s << " (" << greltag << ") = " << it->Value << std::endl;
}
s << "Serie Elements :"<<std::endl;
for (it = DicomDirSerieList.begin(); it != DicomDirSerieList.end(); ++it)
{
- sprintf(greltag,"%04x|%04x ",it->group,it->elem);
- s << " ("<<greltag<<") = "<< it->value<<std::endl;
+ greltag = Format("%04x|%04x ", it->Group, it->Elem);
+ s << " (" << greltag << ") = " << it->Value << std::endl;
}
s << "Image Elements :"<<std::endl;
for (it = DicomDirImageList.begin(); it != DicomDirImageList.end(); ++it)
{
- sprintf(greltag,"%04x|%04x ",it->group,it->elem);
- s << " ("<<greltag<<") = "<< it->value<<std::endl;
+ greltag = Format("%04x|%04x ", it->Group, it->Elem);
+ s << " (" << greltag << ") = " << it->Value << std::endl;
}
os << s.str();
Program: gdcm
Module: $RCSfile: gdcmDicomDirElement.h,v $
Language: C++
- Date: $Date: 2004/09/27 08:39:06 $
- Version: $Revision: 1.10 $
+ Date: $Date: 2004/10/09 03:21:55 $
+ Version: $Revision: 1.11 $
Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
l'Image). All rights reserved. See Doc/License.txt or
typedef struct
{
/// DicomGroup number
- unsigned short int group;
+ unsigned short int Group;
/// DicomElement number
- unsigned short int elem;
+ unsigned short int Elem;
/// value (coded as a std::string) of the Element
- std::string value;
+ std::string Value;
} gdcmElement;
typedef std::list<gdcmElement> ListDicomDirMetaElem;
/**
* \brief canonical Printer
* \sa SetPrintLevel
- */
+ */
void Print(std::ostream &os);
-/**
- * \ingroup gdcmDicomDirElement
- * \brief returns a reference to the chained List
- * related to the META Elements of a DICOMDIR.
- */
+
+ /**
+ * \ingroup gdcmDicomDirElement
+ * \brief returns a reference to the chained List
+ * related to the META Elements of a DICOMDIR.
+ */
ListDicomDirMetaElem &GetDicomDirMetaElements()
{ return DicomDirMetaList; };
-/**
- * \ingroup gdcmDicomDirElement
- * \brief returns a reference to the chained List
- * related to the PATIENT Elements of a DICOMDIR.
- */
+
+ /**
+ * \ingroup gdcmDicomDirElement
+ * \brief returns a reference to the chained List
+ * related to the PATIENT Elements of a DICOMDIR.
+ */
ListDicomDirPatientElem &GetDicomDirPatientElements()
{ return DicomDirPatientList; };
-/**
- * \ingroup gdcmDicomDirElement
- * \brief returns a reference to the chained List
- * related to the STUDY Elements of a DICOMDIR.
- */
+
+ /**
+ * \ingroup gdcmDicomDirElement
+ * \brief returns a reference to the chained List
+ * related to the STUDY Elements of a DICOMDIR.
+ */
ListDicomDirStudyElem &GetDicomDirStudyElements()
{ return DicomDirStudyList; };
-/**
- * \ingroup gdcmDicomDirElement
- * \brief returns a reference to the chained List
- * related to the SERIE Elements of a DICOMDIR.
- */
+
+ /**
+ * \ingroup gdcmDicomDirElement
+ * \brief returns a reference to the chained List
+ * related to the SERIE Elements of a DICOMDIR.
+ */
ListDicomDirSerieElem &GetDicomDirSerieElements()
{ return DicomDirSerieList; };
-/**
- * \ingroup gdcmDicomDirElement
- * \brief returns a reference to the chained List
- * related to the IMAGE Elements of a DICOMDIR.
- */
+
+ /**
+ * \ingroup gdcmDicomDirElement
+ * \brief returns a reference to the chained List
+ * related to the IMAGE Elements of a DICOMDIR.
+ */
ListDicomDirImageElem &GetDicomDirImageElements()
{ return DicomDirImageList; };
Program: gdcm
Module: $RCSfile: gdcmDicomDirObject.cxx,v $
Language: C++
- Date: $Date: 2004/09/27 08:39:06 $
- Version: $Revision: 1.2 $
+ Date: $Date: 2004/10/09 03:21:55 $
+ Version: $Revision: 1.3 $
Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
l'Image). All rights reserved. See Doc/License.txt or
// for all the Elements found in they own part of the DicomDir dict.
for(it = elemList.begin(); it != elemList.end(); ++it)
{
- tmpGr = it->group;
- tmpEl = it->elem;
+ tmpGr = it->Group;
+ tmpEl = it->Elem;
dictEntry = gdcmGlobal::GetDicts()->GetDefaultPubDict()->GetDictEntryByNumber(tmpGr,tmpEl);
entry = new gdcmValEntry(dictEntry);
entry->SetOffset(0); // just to avoid further missprinting
- entry->SetValue(it->value);
+ entry->SetValue(it->Value);
// dealing with value length ...