X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=src%2FgdcmHeader.cxx;h=c46ddb0f91c78decda2c1e17121b5c7d911625d7;hb=3ba8c03aa6cb08add6599a1ec7b2b693a967db62;hp=002c20ff1de1c4f6d218ccac423288976068e59d;hpb=4d7376a96afa365371c33a2fa7f814e9d81fad9f;p=gdcm.git diff --git a/src/gdcmHeader.cxx b/src/gdcmHeader.cxx index 002c20ff..c46ddb0f 100644 --- a/src/gdcmHeader.cxx +++ b/src/gdcmHeader.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmHeader.cxx,v $ Language: C++ - Date: $Date: 2004/11/16 16:49:01 $ - Version: $Revision: 1.202 $ + Date: $Date: 2004/11/30 16:24:31 $ + Version: $Revision: 1.209 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -22,7 +22,7 @@ #include "gdcmDebug.h" #include "gdcmTS.h" #include "gdcmValEntry.h" -#include +#include //sscanf #include @@ -48,7 +48,7 @@ Header::Header( std::string const & filename ): // Note: this IS the right place for the code // Image Location - std::string imgLocation = GetEntryByNumber(0x0028, 0x0200); + const std::string &imgLocation = GetEntryByNumber(0x0028, 0x0200); if ( imgLocation == GDCM_UNFOUND ) { // default value @@ -102,8 +102,16 @@ Header::~Header () * @param filetype Type of the File to be written * (ACR-NEMA, ExplicitVR, ImplicitVR) */ -void Header::Write(std::ofstream* fp,FileType filetype) +bool Header::Write(std::string fileName,FileType filetype) { + std::ofstream* fp = new std::ofstream(fileName.c_str(), + std::ios::out | std::ios::binary); + if (fp == NULL) + { + dbg.Verbose(2, "Failed to open (write) File: " , fileName.c_str()); + return false; + } + // Bits Allocated if ( GetEntryByNumber(0x0028,0x0100) == "12") { @@ -163,7 +171,12 @@ void Header::Write(std::ofstream* fp,FileType filetype) RemoveEntryNoDestroy(e); } } - Document::Write(fp,filetype); + Document::WriteContent(fp,filetype); + + fp->close(); + delete fp; + + return true; } //----------------------------------------------------------------------------- @@ -188,7 +201,7 @@ bool Header::IsReadable() return false; } - std::string res = GetEntryByNumber(0x0028, 0x0005); + const std::string &res = GetEntryByNumber(0x0028, 0x0005); if ( res != GDCM_UNFOUND && atoi(res.c_str()) > 4 ) { return false; // Image Dimensions @@ -220,8 +233,7 @@ bool Header::IsReadable() */ int Header::GetXSize() { - std::string strSize; - strSize = GetEntryByNumber(0x0028,0x0011); + const std::string &strSize = GetEntryByNumber(0x0028,0x0011); if ( strSize == GDCM_UNFOUND ) { return 0; @@ -238,7 +250,7 @@ int Header::GetXSize() */ int Header::GetYSize() { - std::string strSize = GetEntryByNumber(0x0028,0x0010); + const std::string &strSize = GetEntryByNumber(0x0028,0x0010); if ( strSize != GDCM_UNFOUND ) { return atoi( strSize.c_str() ); @@ -265,17 +277,17 @@ int Header::GetZSize() { // Both DicomV3 and ACR/Nema consider the "Number of Frames" // as the third dimension. - std::string strSize = GetEntryByNumber(0x0028,0x0008); + const std::string &strSize = GetEntryByNumber(0x0028,0x0008); if ( strSize != GDCM_UNFOUND ) { return atoi( strSize.c_str() ); } // We then consider the "Planes" entry as the third dimension - strSize = GetEntryByNumber(0x0028,0x0012); - if ( strSize != GDCM_UNFOUND ) + const std::string &strSize2 = GetEntryByNumber(0x0028,0x0012); + if ( strSize2 != GDCM_UNFOUND ) { - return atoi( strSize.c_str() ); + return atoi( strSize2.c_str() ); } return 1; @@ -289,7 +301,7 @@ int Header::GetZSize() float Header::GetXSpacing() { float xspacing, yspacing; - std::string strSpacing = GetEntryByNumber(0x0028,0x0030); + const std::string &strSpacing = GetEntryByNumber(0x0028,0x0030); if ( strSpacing == GDCM_UNFOUND ) { @@ -380,6 +392,7 @@ float Header::GetZSpacing() { return (float)atof( strSpacingBSlices.c_str() ); } + return 1.; } /** @@ -1163,27 +1176,6 @@ std::string Header::GetTransfertSyntaxName() return tsName; } -/** - * \brief Sets the Pixel Area size in the Header - * --> not-for-rats function - * @param ImageDataSize new Pixel Area Size - * warning : nothing else is checked - */ -void Header::SetImageDataSize(size_t ImageDataSize) -{ - ///FIXME I don't understand this code why do we set two times 'car' ? - std::string car = Util::Format("%d", ImageDataSize); - - DocEntry *a = GetDocEntryByNumber(GrPixel, NumPixel); - a->SetLength(ImageDataSize); - - ImageDataSize += 8; - car = Util::Format("%d", ImageDataSize); - car = Util::DicomString( car.c_str() ); - - SetEntryByNumber(car, GrPixel, NumPixel); -} - //----------------------------------------------------------------------------- // Protected