X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=src%2FgdcmHeader.cxx;h=2f7f998f7a807bc00272ee9d1894a9c5a231ab04;hb=c59ca11fe2e57b6c51dbaeaa8d0bf15f7c850c63;hp=799627476e3ce92a790bd8469e01cc3bed649fdc;hpb=62639a709293be6d165d83285d1856bf2667e3aa;p=gdcm.git diff --git a/src/gdcmHeader.cxx b/src/gdcmHeader.cxx index 79962747..2f7f998f 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/07/17 22:45:40 $ - Version: $Revision: 1.177 $ + Date: $Date: 2004/09/23 10:17:26 $ + Version: $Revision: 1.188 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -30,20 +30,9 @@ /** * \brief Constructor * @param filename name of the file whose header we want to analyze - * @param exception_on_error whether we want to throw an exception or not - * @param enable_sequences = true to allow the header - * to be parsed *inside* the SeQuences, when they have an actual length - * @param ignore_shadow = true if user wants to skip shadow groups - * during parsing, to save memory space */ -gdcmHeader::gdcmHeader( std::string const & filename, - bool exception_on_error, - bool enable_sequences, - bool ignore_shadow ): - gdcmDocument( filename, - exception_on_error, - enable_sequences, - ignore_shadow ) +gdcmHeader::gdcmHeader( std::string const & filename ): + gdcmDocument( filename ) { // for some ACR-NEMA images GrPixel, NumPixel is *not* 7fe0,0010 // We may encounter the 'RETired' (0x0028, 0x0200) tag @@ -53,8 +42,7 @@ gdcmHeader::gdcmHeader( std::string const & filename, // Inside the group pointed by "Image Location" the searched element // is conventionally the element 0x0010 (when the norm is respected). // When the "Image Location" is absent we default to group 0x7fe0. - - // This IS the right place for the code + // Note: this IS the right place for the code // Image Location std::string imgLocation = GetEntryByNumber(0x0028, 0x0200); @@ -89,10 +77,9 @@ gdcmHeader::gdcmHeader( std::string const & filename, /** * \brief Constructor - * @param exception_on_error whether we want to throw an exception or not */ -gdcmHeader::gdcmHeader(bool exception_on_error) : - gdcmDocument( exception_on_error ) +gdcmHeader::gdcmHeader() + :gdcmDocument() { } @@ -113,56 +100,69 @@ gdcmHeader::~gdcmHeader () * @param filetype Type of the File to be written * (ACR-NEMA, ExplicitVR, ImplicitVR) */ -void gdcmHeader::Write(FILE* fp,FileType filetype) { - +void gdcmHeader::Write(FILE* fp,FileType filetype) +{ // Bits Allocated - if ( GetEntryByNumber(0x0028,0x0100) == "12") { + if ( GetEntryByNumber(0x0028,0x0100) == "12") + { SetEntryByNumber("16", 0x0028,0x0100); } - // correct Pixel group Length if necessary - - // TODO : create a gdcmHeader::Write method and move this part. - // (only gdcmHeader knows GrPixel, NumPixel) + // TODO : correct 'Pixel group' Length if necessary int i_lgPix = GetEntryLengthByNumber(GrPixel, NumPixel); - if (i_lgPix != -2) { // no (GrPixel, NumPixel) element - char * dumm = new char[20]; + if (i_lgPix != -2) + { + // no (GrPixel, NumPixel) element + char* dumm = new char[20]; sprintf(dumm ,"%d", i_lgPix+12); std::string s_lgPix = dumm; - delete dumm; + delete[] dumm; ReplaceOrCreateByNumber(s_lgPix,GrPixel, 0x0000); } - + + // FIXME : should be nice if we could move it to gdcmFile + // (or in future gdcmPixelData class) + // Drop Palette Color, if necessary - if ( GetEntryByNumber(0x0028,0x0002).c_str()[0] == '3' ) { - // if SamplesPerPixel = 3, sure we don't need any LUT ! - // Drop 0028|1101, 0028|1102, 0028|1103 - // Drop 0028|1201, 0028|1202, 0028|1203 - - gdcmDocEntry *e; - e=GetDocEntryByNumber(0x0028,0x01101); - if (e) - RemoveEntry(e); - e=GetDocEntryByNumber(0x0028,0x1102); - if (e) - RemoveEntry(e); - e=GetDocEntryByNumber(0x0028,0x1103); - - if (e) - RemoveEntry(e); - e=GetDocEntryByNumber(0x0028,0x01201); - if (e) - RemoveEntry(e); - e=GetDocEntryByNumber(0x0028,0x1202); - if (e) - RemoveEntry(e); - e=GetDocEntryByNumber(0x0028,0x1203); - if (e) - RemoveEntry(e); - } + if ( GetEntryByNumber(0x0028,0x0002).c_str()[0] == '3' ) + { + // if SamplesPerPixel = 3, sure we don't need any LUT ! + // Drop 0028|1101, 0028|1102, 0028|1103 + // Drop 0028|1201, 0028|1202, 0028|1203 + gdcmDocEntry* e = GetDocEntryByNumber(0x0028,0x01101); + if (e) + { + RemoveEntryNoDestroy(e); + } + e = GetDocEntryByNumber(0x0028,0x1102); + if (e) + { + RemoveEntryNoDestroy(e); + } + e = GetDocEntryByNumber(0x0028,0x1103); + if (e) + { + RemoveEntryNoDestroy(e); + } + e = GetDocEntryByNumber(0x0028,0x01201); + if (e) + { + RemoveEntryNoDestroy(e); + } + e = GetDocEntryByNumber(0x0028,0x1202); + if (e) + { + RemoveEntryNoDestroy(e); + } + e = GetDocEntryByNumber(0x0028,0x1203); + if (e) + { + RemoveEntryNoDestroy(e); + } + } gdcmDocument::Write(fp,filetype); } @@ -405,7 +405,7 @@ float gdcmHeader::GetRescaleIntercept() } } - return resInter; + return resInter; } /** @@ -543,7 +543,7 @@ float gdcmHeader::GetXOrigin() if( sscanf( strImPos.c_str(), "%f\\%f\\%f", &xImPos, &yImPos, &zImPos) != 3 ) { - return 0.; + return 0.; } return xImPos; @@ -753,7 +753,6 @@ int gdcmHeader::GetBitsStored() return 0; // It's supposed to be mandatory // the caller will have to check } - return atoi( strSize.c_str() ); } @@ -773,7 +772,6 @@ int gdcmHeader::GetBitsAllocated() return 0; // It's supposed to be mandatory // the caller will have to check } - return atoi( strSize.c_str() ); } @@ -793,7 +791,6 @@ int gdcmHeader::GetSamplesPerPixel() return 1; // Well, it's supposed to be mandatory ... // but sometimes it's missing : *we* assume Gray pixels } - return atoi( strSize.c_str() ); } @@ -810,7 +807,6 @@ int gdcmHeader::GetPlanarConfiguration() { return 0; } - return atoi( strSize.c_str() ); } @@ -844,7 +840,6 @@ int gdcmHeader::GetPixelSize() { return 8; } - dbg.Verbose(0, "gdcmHeader::GetPixelSize: Unknown pixel type"); return 0; } @@ -903,7 +898,6 @@ std::string gdcmHeader::GetPixelType() { sign = "S"; } - return bitsAlloc + sign; } @@ -1121,9 +1115,9 @@ uint8_t* gdcmHeader::GetLUTRGBA() } // Load LUTs into memory, (as they were stored on disk) - uint8_t* lutR = (uint8_t*) GetEntryVoidAreaByNumber(0x0028,0x1201); - uint8_t* lutG = (uint8_t*) GetEntryVoidAreaByNumber(0x0028,0x1202); - uint8_t* lutB = (uint8_t*) GetEntryVoidAreaByNumber(0x0028,0x1203); + uint8_t* lutR = (uint8_t*) GetEntryBinAreaByNumber(0x0028,0x1201); + uint8_t* lutG = (uint8_t*) GetEntryBinAreaByNumber(0x0028,0x1202); + uint8_t* lutB = (uint8_t*) GetEntryBinAreaByNumber(0x0028,0x1203); if ( !lutR || !lutG || !lutB ) { @@ -1200,7 +1194,6 @@ uint8_t* gdcmHeader::GetLUTRGBA() *a = 1; // Alpha component a += 4; } - return LUTRGBA; } @@ -1213,6 +1206,13 @@ std::string gdcmHeader::GetTransfertSyntaxName() { // use the gdcmTS (TS : Transfert Syntax) std::string transfertSyntax = GetEntryByNumber(0x0002,0x0010); + + if ( transfertSyntax == GDCM_NOTLOADED ) { // fusible + std::cout << "Transfert Syntax not loaded. " << std::endl + << "Better you increase MAX_SIZE_LOAD_ELEMENT_VALUE" + << std::endl; + return "Uncompressed ACR-NEMA"; + } if ( transfertSyntax == GDCM_UNFOUND ) { dbg.Verbose(0, "gdcmHeader::GetTransfertSyntaxName:" @@ -1220,6 +1220,10 @@ std::string gdcmHeader::GetTransfertSyntaxName() return "Uncompressed ACR-NEMA"; } + while ( ! isdigit(transfertSyntax[transfertSyntax.length()-1]) ) + { + transfertSyntax.erase(transfertSyntax.length()-1, 1); + } // we do it only when we need it gdcmTS* ts = gdcmGlobal::GetTS(); std::string tsName = ts->GetValue( transfertSyntax ); @@ -1236,17 +1240,16 @@ std::string gdcmHeader::GetTransfertSyntaxName() */ void gdcmHeader::SetImageDataSize(size_t ImageDataSize) { - std::string content1; char car[20]; - sprintf(car,"%d",ImageDataSize); gdcmDocEntry *a = GetDocEntryByNumber(GrPixel, NumPixel); a->SetLength(ImageDataSize); - ImageDataSize+=8; + ImageDataSize += 8; sprintf(car,"%d",ImageDataSize); - content1=car; + + const std::string content1 = car; SetEntryByNumber(content1, GrPixel, NumPixel); } @@ -1259,13 +1262,14 @@ void gdcmHeader::SetImageDataSize(size_t ImageDataSize) */ bool gdcmHeader::AnonymizeHeader() { - gdcmDocEntry* patientNameHE = GetDocEntryByNumber (0x0010, 0x0010); + // If exist, replace by spaces + SetEntryByNumber (" ",0x0010, 0x2154); // Telephone + SetEntryByNumber (" ",0x0010, 0x1040); // Adress + SetEntryByNumber (" ",0x0010, 0x0020); // Patient ID - ReplaceIfExistByNumber (" ",0x0010, 0x2154); // Telephone - ReplaceIfExistByNumber (" ",0x0010, 0x1040); // Adress - ReplaceIfExistByNumber (" ",0x0010, 0x0020); // Patient ID + gdcmDocEntry* patientNameHE = GetDocEntryByNumber (0x0010, 0x0010); - if ( patientNameHE ) + if ( patientNameHE ) // we replace it by Study Instance UID (why not) { std::string studyInstanceUID = GetEntryByNumber (0x0020, 0x000d); if ( studyInstanceUID != GDCM_UNFOUND ) @@ -1338,43 +1342,33 @@ bool gdcmHeader::AnonymizeHeader() * @param iop adress of the (6)float aray to receive values * @return cosines of image orientation patient */ -void gdcmHeader::GetImageOrientationPatient( float* iop ) +void gdcmHeader::GetImageOrientationPatient( float iop[6] ) { + std::string strImOriPat; //iop is supposed to be float[6] - iop[0] = iop[1] = iop[2] = iop[3] = iop[4] = iop[5] = 0; + iop[0] = iop[1] = iop[2] = iop[3] = iop[4] = iop[5] = 0.; // 0020 0037 DS REL Image Orientation (Patient) - std::string strImOriPat = GetEntryByNumber(0x0020,0x0037); - if ( strImOriPat != GDCM_UNFOUND ) + if ( (strImOriPat = GetEntryByNumber(0x0020,0x0037)) != GDCM_UNFOUND ) { if( sscanf( strImOriPat.c_str(), "%f\\%f\\%f\\%f\\%f\\%f", &iop[0], &iop[1], &iop[2], &iop[3], &iop[4], &iop[5]) != 6 ) { dbg.Verbose(0, "gdcmHeader::GetImageOrientationPatient: wrong Image Orientation Patient (0020,0037)"); - return ; // bug in the element 0x0020,0x0037 - } - else - { - return ; + // bug in the element 0x0020,0x0037 } } - //For ACR-NEMA // 0020 0035 DS REL Image Orientation (RET) - strImOriPat = GetEntryByNumber(0x0020,0x0035); - if ( strImOriPat != GDCM_UNFOUND ) + else if ( (strImOriPat = GetEntryByNumber(0x0020,0x0035)) != GDCM_UNFOUND ) { if( sscanf( strImOriPat.c_str(), "%f\\%f\\%f\\%f\\%f\\%f", &iop[0], &iop[1], &iop[2], &iop[3], &iop[4], &iop[5]) != 6 ) { dbg.Verbose(0, "gdcmHeader::GetImageOrientationPatient: wrong Image Orientation Patient (0020,0035)"); - return ; // bug in the element 0x0020,0x0035 + // bug in the element 0x0020,0x0035 } } - else - { - return; - } } //-----------------------------------------------------------------------------