X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=src%2FgdcmFile.cxx;h=fda7c94f9011bc1967a208a8373d0c9372823b9e;hb=e022eedb7541761440c9f21343db626d918d4980;hp=0644f92018c46f739ecf18e11103476ced81a41f;hpb=f5c24f2018ff4775ff6ae006de753a394d8cae0f;p=gdcm.git diff --git a/src/gdcmFile.cxx b/src/gdcmFile.cxx index 0644f920..fda7c94f 100644 --- a/src/gdcmFile.cxx +++ b/src/gdcmFile.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmFile.cxx,v $ Language: C++ - Date: $Date: 2005/02/06 14:39:35 $ - Version: $Revision: 1.213 $ + Date: $Date: 2005/02/10 10:12:16 $ + Version: $Revision: 1.220 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -370,7 +370,7 @@ float File::GetXSpacing() float xspacing, yspacing; const std::string &strSpacing = GetEntryValue(0x0028,0x0030); - if ( strSpacing == GDCM_UNFOUND ) + if( strSpacing == GDCM_UNFOUND ) { gdcmWarningMacro( "Unfound Pixel Spacing (0028,0030)" ); return 1.; @@ -380,11 +380,12 @@ float File::GetXSpacing() if( ( nbValues = sscanf( strSpacing.c_str(), "%f\\%f", &yspacing, &xspacing)) != 2 ) { + // if no values, xspacing is set to 1.0 + if( nbValues == 0 ) + xspacing = 1.0; // if single value is found, xspacing is defaulted to yspacing - if ( nbValues == 1 ) - { + if( nbValues == 1 ) xspacing = yspacing; - } if ( xspacing == 0.0 ) xspacing = 1.0; @@ -425,7 +426,11 @@ float File::GetYSpacing() } // if sscanf cannot read any float value, it won't affect yspacing - sscanf( strSpacing.c_str(), "%f", &yspacing); + int nbValues = sscanf( strSpacing.c_str(), "%f", &yspacing); + + // if no values, xspacing is set to 1.0 + if( nbValues == 0 ) + yspacing = 1.0; if ( yspacing == 0.0 ) yspacing = 1.0; @@ -1096,7 +1101,7 @@ int File::GetNumberOfScalarComponentsRaw() */ size_t File::GetPixelOffset() { - DocEntry* pxlElement = GetDocEntry(GrPixel,NumPixel); + DocEntry *pxlElement = GetDocEntry(GrPixel, NumPixel); if ( pxlElement ) { return pxlElement->GetOffset(); @@ -1118,7 +1123,7 @@ size_t File::GetPixelOffset() */ size_t File::GetPixelAreaLength() { - DocEntry* pxlElement = GetDocEntry(GrPixel,NumPixel); + DocEntry *pxlElement = GetDocEntry(GrPixel, NumPixel); if ( pxlElement ) { return pxlElement->GetLength(); @@ -1131,13 +1136,12 @@ size_t File::GetPixelAreaLength() } } - /** * \brief Adds the characteristics of a new element we want to anonymize * */ void File::AddAnonymizeElement (uint16_t group, uint16_t elem, - std::string const &value) + std::string const &value) { Element el; @@ -1155,6 +1159,7 @@ void File::AnonymizeNoLoad() { std::fstream *fp = new std::fstream(Filename.c_str(), std::ios::in | std::ios::out | std::ios::binary); + // TODO : FIXME // how to white out disk space if longer than 50 ? char spaces[50] = " "; @@ -1166,8 +1171,11 @@ void File::AnonymizeNoLoad() for (ListElements::iterator it = AnonymizeList.begin(); it != AnonymizeList.end(); ++it) - { - d = GetDocEntry( (*it).Group, (*it).Elem); + { + d = GetDocEntry( (*it).Group, (*it).Elem); + + if ( d == NULL) + continue; if ( dynamic_cast(d) || dynamic_cast(d) ) @@ -1191,9 +1199,9 @@ void File::AnonymizeNoLoad() fp->write( (char *)(*it).Value.c_str(), lgtToWrite ); } - fp->close(); - delete fp; } + fp->close(); + delete fp; } /** @@ -1234,6 +1242,9 @@ bool File::AnonymizeFile() { d = GetDocEntry( (*it).Group, (*it).Elem); + if ( d == NULL) + continue; + if ( dynamic_cast(d) || dynamic_cast(d) ) continue; @@ -1381,40 +1392,8 @@ bool File::Write(std::string fileName, FileType filetype) } } - -#ifdef GDCM_WORDS_BIGENDIAN - // Super Super hack that will make gdcm a BOMB ! but should - // Fix temporarily the dashboard - BinEntry *b = GetBinEntry(GrPixel,NumPixel); - if ( GetPixelSize() == 16 ) - { - uint16_t *im16 = (uint16_t *)b->GetBinArea(); - int lgth = b->GetLength(); - for( int i = 0; i < lgth / 2; i++ ) - { - im16[i]= (im16[i] >> 8) | (im16[i] << 8 ); - } - } -#endif //GDCM_WORDS_BIGENDIAN - - Document::WriteContent(fp, filetype); - -#ifdef GDCM_WORDS_BIGENDIAN - // Flip back the pixel ... I told you this is a hack - if ( GetPixelSize() == 16 ) - { - uint16_t *im16 = (uint16_t*)b->GetBinArea(); - int lgth = b->GetLength(); - for( int i = 0; i < lgth / 2; i++ ) - { - im16[i]= (im16[i] >> 8) | (im16[i] << 8 ); - } - } -#endif //GDCM_WORDS_BIGENDIAN - - fp->close(); delete fp; @@ -1445,7 +1424,7 @@ void File::InitializeDefaultFile() // Media Storage SOP Class UID (CT Image Storage) InsertValEntry("1.2.840.10008.5.1.4.1.1.2", 0x0002, 0x0002); // Media Storage SOP Instance UID - InsertValEntry(uidClass.c_str(), 0x0002, 0x0003); + InsertValEntry(uidMedia.c_str(), 0x0002, 0x0003); // Transfer Syntax UID (Explicit VR Little Endian) InsertValEntry("1.2.840.10008.1.2.1 ", 0x0002, 0x0010); // META Implementation Class UID @@ -1664,7 +1643,7 @@ bool File::ReadTag(uint16_t testGroup, uint16_t testElement) long positionOnEntry = Fp->tellg(); long currentPosition = Fp->tellg(); // On debugging purposes - //// Read the Item Tag group and element, and make + // Read the Item Tag group and element, and make // sure they are what we expected: uint16_t itemTagGroup; uint16_t itemTagElement;