X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=src%2FgdcmDicomDir.cxx;h=6f80dfce2b7d19b98e1c92d63edf93ca73365ad9;hb=0b36f4932e894a1dde4a80e614755816b4b29218;hp=b5fba6876c1786d6912fc3e070ea8913d68a6b73;hpb=1a11accd11061d63d3c09db7b1445637207e81e4;p=gdcm.git diff --git a/src/gdcmDicomDir.cxx b/src/gdcmDicomDir.cxx index b5fba687..6f80dfce 100644 --- a/src/gdcmDicomDir.cxx +++ b/src/gdcmDicomDir.cxx @@ -1,15 +1,7 @@ // gdcmDicomDir.cxx //----------------------------------------------------------------------------- -#include "gdcmDicomDir.h" -#include "gdcmDicomDirStudy.h" -#include "gdcmDicomDirSerie.h" -#include "gdcmDicomDirImage.h" -#include "gdcmDirList.h" -#include "gdcmUtil.h" - #include #include - #include #include @@ -19,19 +11,28 @@ #include #endif +#include "gdcmDicomDir.h" +#include "gdcmDicomDirStudy.h" +#include "gdcmDicomDirSerie.h" +#include "gdcmDicomDirImage.h" +#include "gdcmDirList.h" +#include "gdcmUtil.h" +#include "gdcmDebug.h" +#include "gdcmGlobal.h" + //----------------------------------------------------------------------------- // For full DICOMDIR description, see: // PS 3.3-2003, pages 731-750 //----------------------------------------------------------------------------- + // Constructor / Destructor /** - * \ingroup gdcmDicomDir * \brief Constructor Parses recursively the directory and creates the DicomDir - * or uses an already built DICOMDIR, depending on 'parseDir' value + * or uses an already built DICOMDIR, depending on 'parseDir' value. * @param FileName name - - of the root directory (parseDir = true) + * - of the root directory (parseDir = true) * - of the DICOMDIR (parseDir = false) * @param parseDir boolean * - true if user passed an entry point @@ -73,27 +74,24 @@ gdcmDicomDir::gdcmDicomDir(const char *FileName, bool parseDir, if(strlen(FileName)==1 && FileName[0]=='.') { // user passed '.' as Name // we get current directory name - char*dummy=(char*) malloc(1000); -#ifdef _MSC_VER - _getcwd(dummy,(size_t)1000); -#else - getcwd(dummy,(size_t)1000); -#endif + char* dummy= new char[1000]; + getcwd(dummy, (size_t)1000); SetFileName(dummy); // will be converted into a string - free(dummy); // no longer needed + delete[] dummy; // no longer needed } if(parseDir) { - dbg.Verbose(0, "gdcmDicomDir::gdcmDicomDir : Parse directory and create the DicomDir"); - ParseDirectory(); + dbg.Verbose(0, "gdcmDicomDir::gdcmDicomDir : Parse directory" + " and create the DicomDir"); + ParseDirectory(); } } else { CreateDicomDir(); CheckBoundaries(); // to maintain consistency between // home-made gdcmDicomDir - // and the ones comming from a DICOMDIR file + // and the ones comming from a DICOMDIR file } } @@ -309,29 +307,26 @@ bool gdcmDicomDir::Write(std::string fileName) return(false); } - char * filePreamble; - filePreamble=(char*)calloc(128,1); + char * filePreamble = new char[128]; fwrite(filePreamble,128,1,fp1); fwrite("DICM",4,1,fp1); - free(filePreamble); + delete[] filePreamble; UpdateDirectoryRecordSequenceLength(); - WriteDicomDirEntries(fp1); + WriteEntries(fp1); fclose(fp1); return true; } /** - * \ingroup gdcmParser - * \brief writes on disc according to the DICOMDIR format - * using the tree-like structure + * \brief Writes in a file using the tree-like structure. * @param _fp already open file pointer */ -void gdcmDicomDir::WriteDicomDirEntries(FILE *_fp) +void gdcmDicomDir::WriteEntries(FILE *_fp) { - // TODO (?) tester les echecs en ecriture - // (apres chaque fwrite, dans le WriteEntry) + /// \todo (?) tester les echecs en ecriture + /// (apres chaque fwrite, dans le WriteEntry) gdcmDicomDirMeta *ptrMeta; ListDicomDirPatient::iterator itPatient; @@ -342,28 +337,28 @@ void gdcmDicomDir::WriteDicomDirEntries(FILE *_fp) ptrMeta= GetDicomDirMeta(); for(i=ptrMeta->debut();i!=ptrMeta->fin();++i) { - WriteEntry(*i,_fp,DICOMDIR); + WriteEntry(*i,_fp, ExplicitVR); } itPatient = GetDicomDirPatients().begin(); while ( itPatient != GetDicomDirPatients().end() ) { for(i=(*itPatient)->debut();i!=(*itPatient)->fin();++i) { - WriteEntry(*i,_fp,DICOMDIR); + WriteEntry(*i,_fp, ExplicitVR); } itStudy = ((*itPatient)->GetDicomDirStudies()).begin(); while (itStudy != (*itPatient)->GetDicomDirStudies().end() ) { for(i=(*itStudy)->debut();i!=(*itStudy)->fin();++i) { - WriteEntry(*i,_fp,DICOMDIR); + WriteEntry(*i,_fp, ExplicitVR); } itSerie = ((*itStudy)->GetDicomDirSeries()).begin(); while (itSerie != (*itStudy)->GetDicomDirSeries().end() ) { for(i=(*itSerie)->debut();i!=(*itSerie)->fin();++i) { - WriteEntry(*i,_fp,DICOMDIR); + WriteEntry(*i,_fp, ExplicitVR); } itImage = ((*itSerie)->GetDicomDirImages()).begin(); while (itImage != (*itSerie)->GetDicomDirImages().end() ) { for(i=(*itImage)->debut();i!=(*itImage)->fin();++i) { - WriteEntry(*i,_fp,DICOMDIR); + WriteEntry(*i,_fp, ExplicitVR); } ++itImage; } @@ -450,13 +445,13 @@ void gdcmDicomDir::CheckBoundaries() itImage = ((*itSerie)->GetDicomDirImages()).begin(); while (itImage != (*itSerie)->GetDicomDirImages().end() ) { (*itImage)->ResetBoundaries(1); - ++itImage; - } - ++itSerie; - } - ++itStudy; - } - ++itPatient; + ++itImage; + } + ++itSerie; + } + ++itStudy; + } + ++itPatient; } } @@ -490,9 +485,9 @@ gdcmDicomDirPatient * gdcmDicomDir::NewPatient(void) { entry->SetValue(it->value); if(dictEntry->GetGroup()==0xfffe) - { - entry->SetLength(entry->GetValue().length()); - } + { + entry->SetLength(entry->GetValue().length()); + } else if( (dictEntry->GetVR()=="UL") || (dictEntry->GetVR()=="SL") ) { entry->SetLength(4); @@ -646,6 +641,9 @@ void gdcmDicomDir::AddObjectToEnd(gdcmDicomDirType type,ListTag::iterator begin, case gdcmDicomDir::GDCM_DICOMDIR_IMAGE: AddDicomDirImageToEnd(begin,end); break; + case gdcmDicomDir::GDCM_DICOMDIR_NONE: + AddDicomDirImageToEnd(begin,end); //FIXME + break; } } @@ -933,7 +931,8 @@ void gdcmDicomDir::UpdateDirectoryRecordSequenceLength() { offset += 4; // delimiters don't have a value. } } - bool res=SetEntryLengthByNumber(offset, 0x0004, 0x1220); // Hope there is no dupps. + //bool res=SetEntryLengthByNumber(offset, 0x0004, 0x1220); // Hope there is no dupps. + SetEntryLengthByNumber(offset, 0x0004, 0x1220); // Hope there is no dupps. return; }