From 81e328d78c2028a7c2ecb86e6cee04839f4d56b2 Mon Sep 17 00:00:00 2001 From: frog Date: Mon, 29 Mar 2004 12:20:46 +0000 Subject: [PATCH] * src/gdcmCommon.h: FileType enum entry DICOMDIR removed (since equivalent to ExplicitVR in existing code). * code clean up. --- ChangeLog | 2 + src/gdcmCommon.h | 5 +- src/gdcmDicomDir.cxx | 10 ++-- src/gdcmFile.cxx | 6 +- src/gdcmParser.cxx | 132 +++++++++++++++++++++---------------------- 5 files changed, 76 insertions(+), 79 deletions(-) diff --git a/ChangeLog b/ChangeLog index 9f405207..cdfd23c0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,6 +1,8 @@ 2004-03-29 Eric Boix * src/gdcmParser.cxx: removal of all TAB character. Indentation fixed. * src/gdcmUtil.cxx: added forgotten iostream include. + * src/gdcmCommon.h: FileType enum entry DICOMDIR removed (since + equivalent to ExplicitVR in existing code). 2004-03-27 Eric Boix * src/gdcmUtil.[cxx|h] split in two. Additional file gdcmGlobal.[cxx|h] diff --git a/src/gdcmCommon.h b/src/gdcmCommon.h index 56c64a2b..173fba77 100644 --- a/src/gdcmCommon.h +++ b/src/gdcmCommon.h @@ -67,11 +67,10 @@ typedef std::string TagName; enum FileType { Unknown = 0, - ExplicitVR, + ExplicitVR, // gdcmDicomDir are in this case ImplicitVR, ACR, - ACR_LIBIDO, - DICOMDIR + ACR_LIBIDO }; //For now gdcm is not willing cmake, try to be more quiet diff --git a/src/gdcmDicomDir.cxx b/src/gdcmDicomDir.cxx index db6f357f..44214cbb 100644 --- a/src/gdcmDicomDir.cxx +++ b/src/gdcmDicomDir.cxx @@ -340,28 +340,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; } diff --git a/src/gdcmFile.cxx b/src/gdcmFile.cxx index 633d4d2f..2ae2bd09 100644 --- a/src/gdcmFile.cxx +++ b/src/gdcmFile.cxx @@ -646,16 +646,14 @@ bool gdcmFile::WriteAcr (std::string fileName) { * (used by WriteDcmExplVR, WriteDcmImplVR, WriteAcr, etc) * @param fileName name of the file to be created * (any already existing file is overwritten) - * @param type file type (ExplicitVR, ImplicitVR, DICOMDIR, ...) + * @param type file type (ExplicitVR, ImplicitVR, ...) * @return false if write fails */ bool gdcmFile::WriteBase (std::string fileName, FileType type) { FILE * fp1; - if (PixelRead==-1 && type != DICOMDIR) { -/* std::cout << "U never Read the pixels; U cannot write the file" - << std::endl;*/ + if (PixelRead==-1 && type != ExplicitVR) { return false; } diff --git a/src/gdcmParser.cxx b/src/gdcmParser.cxx index 8c3ca926..24669fdc 100644 --- a/src/gdcmParser.cxx +++ b/src/gdcmParser.cxx @@ -989,59 +989,44 @@ void gdcmParser::UpdateGroupLength(bool SkipSequence, FileType type) { */ void gdcmParser::WriteEntry(gdcmHeaderEntry *tag, FILE *_fp,FileType type) { - guint16 gr, el; - guint32 lgr; - std::string value; - const char * val; - std::string vr; - guint32 val_uint32; - guint16 val_uint16; - guint16 valZero =0; - void *voidArea; - std::vector tokens; - - void *ptr; - int ff=0xffffffff; - // TODO (?) tester les echecs en ecriture (apres chaque fwrite) - int compte =0; - itsTimeToWritePixels = false; + guint16 group = tag->GetGroup(); + std::string vr = tag->GetVR(); + guint32 length = tag->GetLength(); + guint16 el = tag->GetElement(); + guint32 lgr = tag->GetReadLength(); - gr = tag->GetGroup(); - el = tag->GetElement(); - lgr = tag->GetReadLength(); - val = tag->GetValue().c_str(); - vr = tag->GetVR(); - voidArea = tag->GetVoidArea(); - // === Deal with the length // -------------------- - if((tag->GetLength())%2==1) + if(length%2==1) { tag->SetValue(tag->GetValue()+"\0"); tag->SetLength(tag->GetReadLength()+1); } - fwrite ( &gr,(size_t)2 ,(size_t)1 ,_fp); //group + fwrite ( &group,(size_t)2 ,(size_t)1 ,_fp); //group fwrite ( &el,(size_t)2 ,(size_t)1 ,_fp); //element - if ( (type == ExplicitVR) || (type == DICOMDIR) ) { - // EXPLICIT VR - guint16 z=0, shortLgr; - - if (gr == 0xfffe) { // NO Value Representation for 'delimiters' - // no length : write ffffffff - - // special patch to make some MR PHILIPS images e-film readable - // see gdcmData/gdcm-MR-PHILIPS-16-Multi-Seq.dcm - // from Hospital Guy de Chauliac, Montpellier - // we just ignore spurious fffe|0000 tag ! - if (el == 0x0000) return; + if ( type == ExplicitVR ) { + + // Special case of delimiters: + if (group == 0xfffe) { + // Delimiters have NO Value Representation and have NO length. + // Hence we skip writing the VR and length and we pad by writing + // 0xffffffff + + if (el == 0x0000) + // Fix in order to make some MR PHILIPS images e-film readable + // see gdcmData/gdcm-MR-PHILIPS-16-Multi-Seq.dcm: + // we just ignore spurious fffe|0000 tag ! + return; + int ff=0xffffffff; fwrite (&ff,(size_t)4 ,(size_t)1 ,_fp); - return; // NO value for 'delimiters' + return; } - shortLgr=lgr; + guint16 z=0; + guint16 shortLgr = lgr; if (vr == "unkn") { // Unknown was 'written' // deal with Little Endian fwrite ( &shortLgr,(size_t)2 ,(size_t)1 ,_fp); @@ -1065,8 +1050,24 @@ void gdcmParser::WriteEntry(gdcmHeaderEntry *tag, FILE *_fp,FileType type) // === Deal with the value // ------------------- if (vr == "SQ") return; // no "value" to write for the SEQuences - if (gr == 0xfffe)return; // no "value" to write for the delimiters + if (group == 0xfffe)return; // no "value" to write for the delimiters + + // Pixels are never loaded in the element ! + // we stop writting when Pixel are processed + // FIX : we loose trailing elements (RAB, right now) + + int compte =0; + itsTimeToWritePixels = false; + if ((group == GrPixel) && (el == NumPixel) ) { + compte++; + if (compte == countGrPixel) {// we passed *all* the GrPixel,NumPixel + itsTimeToWritePixels = true; + return; + } + } + void *voidArea; + voidArea = tag->GetVoidArea(); if (voidArea != NULL) { // there is a 'non string' LUT, overlay, etc fwrite ( voidArea,(size_t)lgr ,(size_t)1 ,_fp); // Elem value @@ -1075,12 +1076,13 @@ void gdcmParser::WriteEntry(gdcmHeaderEntry *tag, FILE *_fp,FileType type) if (vr == "US" || vr == "SS") { + std::vector tokens; tokens.erase(tokens.begin(),tokens.end()); // clean any previous value Tokenize (tag->GetValue(), tokens, "\\"); for (unsigned int i=0; i tokens; tokens.erase(tokens.begin(),tokens.end()); // clean any previous value Tokenize (tag->GetValue(), tokens, "\\"); for (unsigned int i=0; iGetValue().c_str(), (size_t)lgr ,(size_t)1, _fp); // Elem value } /** @@ -1140,17 +1132,23 @@ void gdcmParser::WriteEntries(FILE *_fp,FileType type) ++tag2) { if ( type == ACR ){ - if ((*tag2)->GetGroup() < 0x0008) continue; // ignore pure DICOM V3 groups - if ((*tag2)->GetElement() %2) continue; // ignore shadow groups - if ((*tag2)->GetVR() == "SQ" ) continue; // ignore Sequences - // TODO : find a trick to *skip* the SeQuences ! - // Not only ignore the SQ element - // --> will be done with the next organization - if ((*tag2)->GetGroup() == 0xfffe ) continue; // ignore delimiters - } - WriteEntry(*tag2,_fp,type); - if (itsTimeToWritePixels) - break; + if ((*tag2)->GetGroup() < 0x0008) + // Ignore pure DICOM V3 groups + continue; + if ((*tag2)->GetElement() %2) + // Ignore the "shadow" groups + continue; + if ((*tag2)->GetVR() == "SQ" ) + // For the time being sequences are simply ignored + // TODO : find a trick not to *skip* the SeQuences ! + continue; + if ((*tag2)->GetGroup() == 0xfffe ) + // Ignore the documented delimiter + continue; + } + WriteEntry(*tag2,_fp,type); + if (itsTimeToWritePixels) + break; } } -- 2.48.1