Program: gdcm
Module: $RCSfile: gdcmDicomDir.cxx,v $
Language: C++
- Date: $Date: 2004/10/12 04:35:44 $
- Version: $Revision: 1.73 $
+ Date: $Date: 2004/11/30 17:04:01 $
+ Version: $Revision: 1.83 $
Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
l'Image). All rights reserved. See Doc/License.txt or
#include "gdcmSQItem.h"
#include "gdcmValEntry.h"
+#include <fstream>
#include <string>
#include <algorithm>
#include <sys/types.h>
-#ifdef _MSC_VER
+#ifdef _MSC_VER
+#define getcwd _getcwd
+#endif
+
+#if defined( _MSC_VER) || defined(__BORLANDC__)
#include <direct.h>
#else
#include <unistd.h>
#endif
+
namespace gdcm
{
/// \todo FIXME : what do we do when the parsed file IS NOT a
/// DICOMDIR file ?
}
- CreateDicomDir();
+ else
+ CreateDicomDir();
}
}
SetStartMethod(NULL);
SetProgressMethod(NULL);
SetEndMethod(NULL);
+
+ TagHT.clear();
for(ListDicomDirPatient::iterator cc = Patients.begin();
cc!= Patients.end();
++cc)
/**
* \ingroup DicomDir
- * \brief Set the start method to call when the parsing of the directory starts
+ * \brief Set the start method to call when the parsing of the
+ * directory starts.
* @param method Method to call
* @param arg Argument to pass to the method
* @param argDelete Argument
* \warning In python : the arg parameter isn't considered
*/
-void DicomDir::SetStartMethod(Method* method, void* arg,
- Method* argDelete )
+void DicomDir::SetStartMethod( DicomDir::Method* method, void* arg,
+ DicomDir::Method* argDelete )
{
if( StartArg && StartMethodArgDelete )
{
* class is destroyed
* @param method Method to call to delete the argument
*/
-void DicomDir::SetStartMethodArgDelete(Method* method)
+void DicomDir::SetStartMethodArgDelete( DicomDir::Method* method )
{
StartMethodArgDelete = method;
}
/**
* \ingroup DicomDir
- * \brief Set the progress method to call when the parsing of the directory progress
+ * \brief Set the progress method to call when the parsing of the
+ * directory progress
* @param method Method to call
* @param arg Argument to pass to the method
* @param argDelete Argument
* \warning In python : the arg parameter isn't considered
*/
-void DicomDir::SetProgressMethod(Method* method, void* arg,
- Method* argDelete )
+void DicomDir::SetProgressMethod( DicomDir::Method* method, void* arg,
+ DicomDir::Method* argDelete )
{
if( ProgressArg && ProgressMethodArgDelete )
{
* class is destroyed
* @param method Method to call to delete the argument
*/
-void DicomDir::SetProgressMethodArgDelete(Method* method)
+void DicomDir::SetProgressMethodArgDelete( DicomDir::Method* method )
{
ProgressMethodArgDelete = method;
}
* @param argDelete Argument
* \warning In python : the arg parameter isn't considered
*/
-void DicomDir::SetEndMethod(Method* method, void* arg,
- Method* argDelete )
+void DicomDir::SetEndMethod( DicomDir::Method* method, void* arg,
+ DicomDir::Method* argDelete )
{
if( EndArg && EndMethodArgDelete )
{
/**
* \ingroup DicomDir
* \brief Set the method to delete the argument
- * The argument is destroyed when the method is changed or when the class
- * is destroyed
+ * The argument is destroyed when the method is changed or when
+ * the class is destroyed
* @param method Method to call to delete the argument
*/
-void DicomDir::SetEndMethodArgDelete(Method* method)
+void DicomDir::SetEndMethodArgDelete( DicomDir::Method* method )
{
EndMethodArgDelete = method;
}
/**
* \ingroup DicomDir
- * \brief writes on disc a DICOMDIR
+ * \brief writes on disc a DICOMDIR
* \ warning does NOT add the missing elements in the header :
* it's up to the user doing it !
* \todo : to be re-written using the DICOMDIR tree-like structure
bool DicomDir::WriteDicomDir(std::string const& fileName)
{
+ int i;
uint16_t sq[4] = { 0x0004, 0x1220, 0xffff, 0xffff };
uint16_t sqt[4]= { 0xfffe, 0xe0dd, 0xffff, 0xffff };
- FILE* fp = fopen(fileName.c_str(), "wb");
+ std::ofstream* fp = new std::ofstream(fileName.c_str(),
+ std::ios::out | std::ios::binary);
if( !fp )
{
- printf("Failed to open(write) File [%s] \n", fileName.c_str());
+ dbg.Verbose(2, "Failed to open(write) File: ", fileName.c_str());
return false;
}
- uint8_t filePreamble[128];
+ char filePreamble[128];
memset(filePreamble, 0, 128);
- fwrite(filePreamble,128,1,fp);
- fwrite("DICM",4,1,fp);
+ fp->write(filePreamble, 128); //FIXME
+ binary_write( *fp, "DICM");
DicomDirMeta *ptrMeta = GetDicomDirMeta();
- ptrMeta->Write(fp, ExplicitVR);
+ ptrMeta->WriteContent(fp, ExplicitVR);
// force writing 0004|1220 [SQ ], that CANNOT exist within DicomDirMeta
- fwrite(&sq[0],8,1,fp); // 0004 1220 ffff ffff
+ for(i=0;i<4;++i)
+ {
+ binary_write(*fp, sq[i]);
+ }
for(ListDicomDirPatient::iterator cc = Patients.begin();
cc != Patients.end();
++cc )
{
- (*cc)->Write( fp, ExplicitVR );
+ (*cc)->WriteContent( fp, ExplicitVR );
}
// force writing Sequence Delimitation Item
- fwrite(&sqt[0],8,1,fp); // fffe e0dd ffff ffff
+ for(i=0;i<4;++i)
+ {
+ binary_write(*fp, sqt[i]); // fffe e0dd ffff ffff
+ }
- fclose( fp );
+ fp->close();
return true;
}
VectDocument list;
Header *header;
- TagHT.clear();
- Patients.clear();
-
for( DirList::iterator it = fileList.begin();
it != fileList.end();
++it )
}
else // after root directory parsing
{
- std::list<Element> elemList;
- elemList=Global::GetDicomDirElements()->GetDicomDirMetaElements();
- m->FillObject(elemList);
- }
+ ListDicomDirMetaElem const & elemList =
+ Global::GetDicomDirElements()->GetDicomDirMetaElements();
+ m->FillObject(elemList);
+ }
m->SetSQItemNumber(0); // To avoid further missprinting
return m;
}
*/
DicomDirPatient * DicomDir::NewPatient()
{
- std::list<Element>::iterator it;
+ ListDicomDirPatientElem::const_iterator it;
uint16_t tmpGr,tmpEl;
DictEntry *dictEntry;
ValEntry *entry;
- std::list<Element> elemList;
- elemList=Global::GetDicomDirElements()->GetDicomDirPatientElements();
+ ListDicomDirPatientElem const & elemList =
+ Global::GetDicomDirElements()->GetDicomDirPatientElements();
SQItem *s = new SQItem(0);
// for all the DicomDirPatient Elements
DicomDirPatient *p = new DicomDirPatient(s, &TagHT);
Patients.push_front( p );
- return p;
+ return p;
}
/**
* GDCM_DICOMDIR_STUDY, GDCM_DICOMDIR_SERIE ...)
* @param header Header of the current file
*/
-void DicomDir::SetElement(std::string &path,DicomDirType type,
- Document *header)
+void DicomDir::SetElement(std::string const & path, DicomDirType type,
+ Document *header)
{
- std::list<Element> elemList;
- std::list<Element>::iterator it;
+ ListDicomDirElem elemList; //FIXME this is going to be a by copy operation
+ ListDicomDirElem::const_iterator it;
uint16_t tmpGr, tmpEl;
DictEntry *dictEntry;
ValEntry *entry;
std::string val;
SQItem *si = new SQItem(0); // all the items will be at level 1
+
switch( type )
{
case GDCM_DICOMDIR_IMAGE:
}
+//-----------------------------------------------------------------------------
/**
* \brief CallStartMethod
*/
}
}
+//-----------------------------------------------------------------------------
/**
* \ingroup DicomDir
* \brief CallProgressMethod
}
}
+//-----------------------------------------------------------------------------
/**
* \ingroup DicomDir
* \brief CallEndMethod
return;
}
- DicomDirType type = DicomDir::GDCM_DICOMDIR_META;
+ DicomDirType type; // = DicomDir::GDCM_DICOMDIR_META;
MetaElems = NewMeta();
ListSQItem listItems = s->GetSQItems();
if( (*itp)->GetDicomDirStudies().size() > 0 )
{
- ListDicomDirStudy::iterator itst=(*itp)->GetDicomDirStudies().end();
+ ListDicomDirStudy::const_iterator itst =
+ (*itp)->GetDicomDirStudies().end();
itst--;
(*itst)->AddDicomDirSerie(new DicomDirSerie(s, &TagHT));
}
if( (*itp)->GetDicomDirStudies().size() > 0 )
{
- ListDicomDirStudy::iterator itst = (*itp)->GetDicomDirStudies().end();
+ ListDicomDirStudy::const_iterator itst =
+ (*itp)->GetDicomDirStudies().end();
itst--;
if( (*itst)->GetDicomDirSeries().size() > 0 )
{
- ListDicomDirSerie::iterator its = (*itst)->GetDicomDirSeries().end();
+ ListDicomDirSerie::const_iterator its = (*itst)->GetDicomDirSeries().end();
its--;
(*its)->AddDicomDirImage(new DicomDirImage(s, &TagHT));
}
* @param path path of the root directory
* @param list chained list of Headers
*/
-void DicomDir::SetElements(std::string &path, VectDocument &list)
+void DicomDir::SetElements(std::string const & path, VectDocument const &list)
{
+ TagHT.clear();
+ Patients.clear();
+
std::string patPrevName = "", patPrevID = "";
std::string studPrevInstanceUID = "", studPrevID = "";
std::string serPrevInstanceUID = "", serPrevID = "";
std::string studCurInstanceUID, studCurID;
std::string serCurInstanceUID, serCurID;
- for( VectDocument::iterator it = list.begin();
- it != list.end(); ++it )
+ for( VectDocument::const_iterator it = list.begin();
+ it != list.end(); ++it )
{
// get the current file characteristics
patCurName = (*it)->GetEntryByNumber(0x0010,0x0010);