X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=src%2FgdcmFile.cxx;h=8a11ae809b4ea8faa92ef44c35938dce8db43e51;hb=c95e0f505e46f71f658c62901c68521ac4afeccb;hp=e992c0e02dd70e55a3c469b23fcfca9003fb32ad;hpb=a968cfd811dee721ca480c61bab6d610b5baa2ae;p=gdcm.git diff --git a/src/gdcmFile.cxx b/src/gdcmFile.cxx index e992c0e0..8a11ae80 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/06/24 10:50:20 $ - Version: $Revision: 1.244 $ + Date: $Date: 2005/09/07 08:55:23 $ + Version: $Revision: 1.268 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -26,6 +26,65 @@ // as the Z coordinate, // 0. for all the coordinates if nothing is found // +// Image Position (Patient) (0020,0032) VM=3 What is it used for? +// --> +// The attribute Patient Orientation (0020,0020) from the General Image Module +// is of type 2C and has the condition Required if image does not require +// Image Orientation (0020,0037) and Image Position (0020,0032). +// However, if the image does require the attributes +// - Image Orientation (Patient) (0020,0037), VM=6 +// - Image Position Patient (0020,0032), VM=3 +// then attribute Patient Orientation (0020,0020) should not be present +// in the images. +// +// Remember also : +// Patient Position (0018,5100) values : + +// HFS = Head First-Supine, where increasing (positive axis direction) : +// X -> to the direction pointed to by the patient's oustretched left arm +// Y -> to the anterior-to-posterior direction in the patient's body +// Z -> to the feet-to-head direction in the patient's body + +// HFP = Head First-Prone, where increasing (positive axis direction) : +// X -> to the direction pointed to by the patient's oustretched left arm +// Y -> to the anterior-to-posterior direction in the patient's body +// Z -> to the feet-to-head direction in the patient's body + +// FFS = Feet First-Supine, where increasing (positive axis direction) : +// X -> to the direction pointed to by the patient's oustretched left arm +// Y -> to the anterior-to-posterion direction in the patient's body +// Z -> to the feet-to-head direction in the patient's body + +// FFP = Feet First-Prone, where increasing (positive axis direction) : +// X -> to the direction pointed to by the patient's oustretched left arm +// Y -> to the posterior-to-anterior direction in the patient's body +// Z -> to the feet-to-head direction in the patient's body + +// HFDR = Head First-Decubitus Right +// HFDL = Head First-Decubitus Left +// FFDR = Feet First-Decubitus Right +// FFDL = Feet First-Decubitus Left + +// we can also find + +// SEMIERECT +// SUPINE + +// CS 2 Patient Orientation (0020 0020) +// When the coordinates of the image +// are always present, this field is almost never used. +// Better we don't trust it too much ... +// Found Values are : +// L\P +// L\FP +// P\F +// L\F +// P\FR +// R\F +// +// (0020|0037) [Image Orientation (Patient)] [1\0\0\0\1\0 ] + + // --------------------------------------------------------------- // #include "gdcmFile.h" @@ -39,11 +98,13 @@ #include "gdcmRLEFramesInfo.h" #include "gdcmJPEGFragmentsInfo.h" -#include //sscanf #include +#include //sscanf +#include // for atoi namespace gdcm { + //----------------------------------------------------------------------------- // Constructor / Destructor @@ -59,18 +120,6 @@ File::File(): NumPixel = 0x0010; } -/** - * \brief Constructor - * @param filename name of the file whose header we want to analyze - */ -File::File( std::string const &filename ) - :Document(filename) -{ - RLEInfo = new RLEFramesInfo; - JPEGInfo = new JPEGFragmentsInfo; - - Load( filename ); -} /** * \brief Canonical destructor. @@ -85,16 +134,26 @@ File::~File () //----------------------------------------------------------------------------- // Public - /** * \brief Loader - * @param fileName file to be open for parsing * @return false if file cannot be open or no swap info was found, * or no tag was found. */ -bool File::Load( std::string const &fileName ) +bool File::Load( ) +{ + if ( ! this->Document::Load( ) ) + return false; + + return DoTheLoadingJob( ); +} + +/** + * \brief Does the Loading Job (internal use only) + * @return false if file cannot be open or no swap info was found, + * or no tag was found. + */ +bool File::DoTheLoadingJob( ) { - this->Document::Load( fileName ); // for some ACR-NEMA images GrPixel, NumPixel is *not* 7fe0,0010 // We may encounter the 'RETired' (0x0028, 0x0200) tag @@ -206,26 +265,41 @@ bool File::IsReadable() gdcmWarningMacro("Wrong Image Dimensions" << res); return false; // Image Dimensions } + bool b0028_0100 = true; if ( !GetDocEntry(0x0028, 0x0100) ) { gdcmWarningMacro("Bits Allocated (0028|0100) not found"); - return false; // "Bits Allocated" + //return false; // "Bits Allocated" + b0028_0100 = false; } + bool b0028_0101 = true; if ( !GetDocEntry(0x0028, 0x0101) ) { gdcmWarningMacro("Bits Stored (0028|0101) not found"); - return false; // "Bits Stored" + //return false; // "Bits Stored" + b0028_0101 = false; } + bool b0028_0102 = true; if ( !GetDocEntry(0x0028, 0x0102) ) { gdcmWarningMacro("Hight Bit (0028|0102) not found"); - return false; // "High Bit" + //return false; // "High Bit" + b0028_0102 = false; } + bool b0028_0103 = true; if ( !GetDocEntry(0x0028, 0x0103) ) { gdcmWarningMacro("Pixel Representation (0028|0103) not found"); - return false; // "Pixel Representation" i.e. 'Sign' ( 0 : unsigned, 1 : signed) + //return false; // "Pixel Representation" i.e. 'Sign' ( 0 : unsigned, 1 : signed) + b0028_0103 = false; } + + if ( !b0028_0100 && !b0028_0101 && !b0028_0102 && !b0028_0103) + { + gdcmWarningMacro("Too much mandatory Tags missing !"); + return false; + } + if ( !GetDocEntry(GrPixel, NumPixel) ) { gdcmWarningMacro("Pixel Dicom Element " << std::hex << @@ -684,7 +758,7 @@ float File::GetZOrigin() * @param iop adress of the (6)float array to receive values * @return cosines of image orientation patient */ -void File::GetImageOrientationPatient( float iop[6] ) +bool File::GetImageOrientationPatient( float iop[6] ) { std::string strImOriPat; //iop is supposed to be float[6] @@ -697,6 +771,7 @@ void File::GetImageOrientationPatient( float iop[6] ) &iop[0], &iop[1], &iop[2], &iop[3], &iop[4], &iop[5]) != 6 ) { gdcmWarningMacro( "Wrong Image Orientation Patient (0020,0037). Less than 6 values were found." ); + return false; } } //For ACR-NEMA @@ -707,8 +782,10 @@ void File::GetImageOrientationPatient( float iop[6] ) &iop[0], &iop[1], &iop[2], &iop[3], &iop[4], &iop[5]) != 6 ) { gdcmWarningMacro( "wrong Image Orientation Patient (0020,0035). Less than 6 values were found." ); + return false; } } + return true; } /** @@ -731,8 +808,8 @@ int File::GetBitsStored() /** * \brief Retrieve the number of Bits Allocated - * (8, 12 -compacted ACR-NEMA files-, 16, ...) - * @return The encountered number of Bits Allocated, 0 by default. + * (8, 12 -compacted ACR-NEMA files-, 16, 24 -old RGB ACR-NEMA files-,) + * @return The encountered Number of Bits Allocated, 0 by default. * 0 means the file is NOT USABLE. The caller has to check it ! */ int File::GetBitsAllocated() @@ -866,8 +943,8 @@ std::string File::GetPixelType() } else if ( bitsAlloc == "24" ) { - // (in order no to be messed up - bitsAlloc = "8"; // by old RGB images) + // (in order no to be messed up by old RGB images) + bitsAlloc = "8"; } std::string sign = GetEntryValue(0x0028, 0x0103);//"Pixel Representation" @@ -1235,7 +1312,7 @@ void File::AddAnonymizeElement (uint16_t group, uint16_t elem, el.Group = group; el.Elem = elem; el.Value = value; - AnonymizeList.push_back(el); + UserAnonymizeList.push_back(el); } /** @@ -1251,8 +1328,8 @@ void File::AnonymizeNoLoad() uint32_t lgth; uint32_t valLgth = 0; std::string *spaces; - for (ListElements::iterator it = AnonymizeList.begin(); - it != AnonymizeList.end(); + for (ListElements::iterator it = UserAnonymizeList.begin(); + it != UserAnonymizeList.end(); ++it) { d = GetDocEntry( (*it).Group, (*it).Elem); @@ -1260,9 +1337,11 @@ void File::AnonymizeNoLoad() if ( d == NULL) continue; - if ( dynamic_cast(d) - || dynamic_cast(d) ) + if ( dynamic_cast(d) ) + { + gdcmWarningMacro( "You cannot 'Anonymize' a SeqEntry "); continue; + } offset = d->GetOffset(); lgth = d->GetLength(); @@ -1283,11 +1362,12 @@ void File::AnonymizeNoLoad() /** * \brief anonymize a File (remove Patient's personal info passed with * AddAnonymizeElement() + * \note You cannot Anonymize a BinEntry (to be fixed) */ bool File::AnonymizeFile() { // If Anonymisation list is empty, let's perform some basic anonymization - if ( AnonymizeList.begin() == AnonymizeList.end() ) + if ( UserAnonymizeList.begin() == UserAnonymizeList.end() ) { // If exist, replace by spaces SetValEntry (" ",0x0010, 0x2154); // Telephone @@ -1305,15 +1385,15 @@ bool File::AnonymizeFile() } else { - SetValEntry("anonymised", 0x0010, 0x0010); + SetValEntry("anonymized", 0x0010, 0x0010); } } } else { gdcm::DocEntry *d; - for (ListElements::iterator it = AnonymizeList.begin(); - it != AnonymizeList.end(); + for (ListElements::iterator it = UserAnonymizeList.begin(); + it != UserAnonymizeList.end(); ++it) { d = GetDocEntry( (*it).Group, (*it).Elem); @@ -1321,11 +1401,19 @@ bool File::AnonymizeFile() if ( d == NULL) continue; - if ( dynamic_cast(d) - || dynamic_cast(d) ) + if ( dynamic_cast(d) ) + { + gdcmWarningMacro( "You cannot 'Anonymize' a SeqEntry "); continue; + } - SetValEntry ((*it).Value, (*it).Group, (*it).Elem); + if ( dynamic_cast(d) ) + { + gdcmWarningMacro( "To 'Anonymize' a BinEntry, better use AnonymizeNoLoad (FIXME) "); + continue; + } + else + SetValEntry ((*it).Value, (*it).Group, (*it).Elem); } } @@ -1407,7 +1495,7 @@ bool File::Write(std::string fileName, FileType writetype) if ( e0000 ) { std::ostringstream sLen; - sLen << ComputeGroup0002Length(writetype); + sLen << ComputeGroup0002Length( ); e0000->SetValue(sLen.str()); } @@ -1685,6 +1773,43 @@ void File::ReadAndSkipEncapsulatedBasicOffsetTable() } } +// These are the deprecated method that one day should be removed (after the next release) + +#ifndef GDCM_LEGACY_REMOVE +/** + * \brief Constructor (DEPRECATED : temporaryly kept not to break the API) + * @param filename name of the file whose header we want to analyze + * @deprecated do not use any longer + */ +File::File( std::string const &filename ) + :Document( ) +{ + RLEInfo = new RLEFramesInfo; + JPEGInfo = new JPEGFragmentsInfo; + + SetFileName( filename ); + Load( ); // gdcm::Document is first Loaded, then the 'File part' +} + +/** + * \brief Loader. (DEPRECATED : temporaryly kept not to break the API) + * @param fileName file to be open for parsing + * @return false if file cannot be open or no swap info was found, + * or no tag was found. + * @deprecated Use the Load() [ + SetLoadMode() ] + SetFileName() functions instead + */ +bool File::Load( std::string const &fileName ) +{ + GDCM_LEGACY_REPLACED_BODY(File::Load(std::string), "1.2", + File::Load()); + SetFileName( fileName ); + if ( ! this->Document::Load( ) ) + return false; + + return DoTheLoadingJob( ); +} +#endif + //----------------------------------------------------------------------------- // Print