X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=src%2FgdcmParser.cxx;h=ad61419132e4bc03917241f98abd6e0d7defe346;hb=d3e997d981d84fece924c52c8b513bccc6cd371a;hp=d987a847ed5cddf58dfbb055f2c34a98db2b665d;hpb=76f7307f9485e39bba565423a91989f8c9c18c21;p=gdcm.git diff --git a/src/gdcmParser.cxx b/src/gdcmParser.cxx index d987a847..ad614191 100644 --- a/src/gdcmParser.cxx +++ b/src/gdcmParser.cxx @@ -19,6 +19,11 @@ #endif # include +#define UI1_2_840_10008_1_2 "1.2.840.10008.1.2" +#define UI1_2_840_10008_1_2_1 "1.2.840.10008.1.2.1" +#define UI1_2_840_10008_1_2_2 "1.2.840.10008.1.2.2" +#define UI1_2_840_10008_1_2_1_99 "1.2.840.10008.1.2.1.99" + //----------------------------------------------------------------------------- // Refer to gdcmParser::CheckSwap() const unsigned int gdcmParser::HEADER_LENGTH_TO_READ = 256; @@ -52,14 +57,12 @@ gdcmParser::gdcmParser(const char *InFilename, if ( !OpenFile(exception_on_error)) return; - Parse(); LoadHeaderEntries(); - CloseFile(); wasUpdated = 0; // will be set to 1 if user adds an entry - printLevel = 1; // 'Medium' header print by default + printLevel = 1; // 'Heavy' header print by default } /** @@ -69,7 +72,7 @@ gdcmParser::gdcmParser(const char *InFilename, */ gdcmParser::gdcmParser(bool exception_on_error) { - //enableSequences=0; + enableSequences=0; SetMaxSizeLoadEntry(MAX_SIZE_LOAD_ELEMENT_VALUE); Initialise(); @@ -100,7 +103,7 @@ void gdcmParser::PrintEntry(std::ostream & os) { std::ostringstream s; - s << "------------ gdcmParser::Print, using listEntries ----------------" << std::endl; + s << "------------ using listEntries ----------------" << std::endl; for (ListTag::iterator i = listEntries.begin(); i != listEntries.end(); ++i) @@ -123,7 +126,7 @@ void gdcmParser::PrintPubDict(std::ostream & os) /** * \ingroup gdcmParser - * \brief Prints The Dict Entries of the current shadow Dicom Dictionnry + * \brief Prints The Dict Entries of THE shadow Dicom Dictionnry * @return */ void gdcmParser::PrintShaDict(std::ostream & os) @@ -135,7 +138,7 @@ void gdcmParser::PrintShaDict(std::ostream & os) // Public /** * \ingroup gdcmParser - * \brief Get THE public dictionary used + * \brief Get the public dictionary used */ gdcmDict *gdcmParser::GetPubDict(void) { @@ -144,7 +147,7 @@ gdcmDict *gdcmParser::GetPubDict(void) /** * \ingroup gdcmParser - * \brief Get the current shadow dictionary + * \brief Get the shadow dictionary used */ gdcmDict *gdcmParser::GetShaDict(void) { @@ -167,7 +170,8 @@ bool gdcmParser::SetShaDict(gdcmDict *dict) * \brief Set the shadow dictionary used * \param dictName name of the dictionary to use in shadow */ -bool gdcmParser::SetShaDict(DictKey dictName) { +bool gdcmParser::SetShaDict(DictKey dictName) +{ RefShaDict=gdcmGlobal::GetDicts()->GetDict(dictName); return(!RefShaDict); } @@ -183,29 +187,13 @@ bool gdcmParser::SetShaDict(DictKey dictName) { */ bool gdcmParser::IsReadable(void) { - std::string res = GetEntryByNumber(0x0028, 0x0005); - if ( res != GDCM_UNFOUND && atoi(res.c_str()) > 4 ) { - //std::cout << "error on : 28 5" << std::endl; - return false; // Image Dimensions - } + if(filetype==Unknown) + return(false); - if ( !GetHeaderEntryByNumber(0x0028, 0x0100) ) { - //std::cout << "error on : 28 100" << std::endl; - return false; // "Bits Allocated" - } - if ( !GetHeaderEntryByNumber(0x0028, 0x0101) ){ - // std::cout << "error on : 28 101" << std::endl; - return false; // "Bits Stored" - } - if ( !GetHeaderEntryByNumber(0x0028, 0x0102) ) { - //std::cout << "error on : 28 102" << std::endl; - return false; // "High Bit" - } - if ( !GetHeaderEntryByNumber(0x0028, 0x0103) ) { - //std::cout << "error on : 28 103" << std::endl; - return false; // "Pixel Representation" - } - return true; + if(listEntries.size()<=0) + return(false); + + return(true); } /** @@ -215,14 +203,15 @@ bool gdcmParser::IsReadable(void) * * @return True when ImplicitVRLittleEndian found. False in all other cases. */ -bool gdcmParser::IsImplicitVRLittleEndianTransferSyntax(void) { +bool gdcmParser::IsImplicitVRLittleEndianTransferSyntax(void) +{ gdcmHeaderEntry *Element = GetHeaderEntryByNumber(0x0002, 0x0010); if ( !Element ) return false; LoadHeaderEntrySafe(Element); std::string Transfer = Element->GetValue(); - if ( Transfer == "1.2.840.10008.1.2" ) + if ( Transfer == UI1_2_840_10008_1_2 ) return true; return false; } @@ -242,7 +231,7 @@ bool gdcmParser::IsExplicitVRLittleEndianTransferSyntax(void) LoadHeaderEntrySafe(Element); std::string Transfer = Element->GetValue(); - if ( Transfer == "1.2.840.10008.1.2.1" ) + if ( Transfer == UI1_2_840_10008_1_2_1 ) return true; return false; } @@ -262,7 +251,7 @@ bool gdcmParser::IsDeflatedExplicitVRLittleEndianTransferSyntax(void) LoadHeaderEntrySafe(Element); std::string Transfer = Element->GetValue(); - if ( Transfer == "1.2.840.10008.1.2.1.99" ) + if ( Transfer == UI1_2_840_10008_1_2_1_99 ) return true; return false; } @@ -282,7 +271,7 @@ bool gdcmParser::IsExplicitVRBigEndianTransferSyntax(void) LoadHeaderEntrySafe(Element); std::string Transfer = Element->GetValue(); - if ( Transfer == "1.2.840.10008.1.2.2" ) //1.2.2 ??? A verifier ! + if ( Transfer == UI1_2_840_10008_1_2_2 ) //1.2.2 ??? A verifier ! return true; return false; } @@ -383,7 +372,7 @@ bool gdcmParser::Write(FILE *fp, FileType type) if (type == ImplicitVR) { - std::string implicitVRTransfertSyntax = "1.2.840.10008.1.2"; + std::string implicitVRTransfertSyntax = UI1_2_840_10008_1_2; ReplaceOrCreateByNumber(implicitVRTransfertSyntax,0x0002, 0x0010); //FIXME Refer to standards on page 21, chapter 6.2 "Value representation": @@ -395,7 +384,7 @@ bool gdcmParser::Write(FILE *fp, FileType type) if (type == ExplicitVR) { - std::string explicitVRTransfertSyntax = "1.2.840.10008.1.2.1"; + std::string explicitVRTransfertSyntax = UI1_2_840_10008_1_2_1; ReplaceOrCreateByNumber(explicitVRTransfertSyntax,0x0002, 0x0010); //FIXME Refer to standards on page 21, chapter 6.2 "Value representation": @@ -498,6 +487,7 @@ int gdcmParser::CheckIfEntryExistByNumber(guint16 group, guint16 element ) * \brief Searches within Header Entries (Dicom Elements) parsed with * the public and private dictionaries * for the element value of a given tag. + * \warning Don't use any longer : use GetPubEntryByName * @param tagName name of the searched element. * @return Corresponding element value when it exists, * and the string GDCM_UNFOUND ("gdcm::Unfound") otherwise. @@ -1327,7 +1317,11 @@ void gdcmParser::LoadHeaderEntry(gdcmHeaderEntry *Entry) Entry->SetValue("gdcm::UnRead"); return; } - Entry->SetValue(NewValue); + + if( (vr == "UI") ) // Because of correspondance with the VR dic + Entry->SetValue(NewValue.c_str()); + else + Entry->SetValue(NewValue); } /** @@ -1610,7 +1604,8 @@ std::string gdcmParser::GetHeaderEntryValue(gdcmHeaderEntry *Entry) { if(i!=0) s << '\\'; - NewInt32=(val[4*i+0]&0xFF)+((val[4*i+1]&0xFF)<<8)+((val[4*i+2]&0xFF)<<16)+((val[4*i+3]&0xFF)<<24); + NewInt32= (val[4*i+0]&0xFF)+((val[4*i+1]&0xFF)<<8)+ + ((val[4*i+2]&0xFF)<<16)+((val[4*i+3]&0xFF)<<24); NewInt32=SwapLong(NewInt32); s << NewInt32; } @@ -1641,7 +1636,6 @@ std::string gdcmParser::GetHeaderEntryUnvalue(gdcmHeaderEntry *Entry) std::string vr=Entry->GetVR(); std::ostringstream s; std::vector tokens; - unsigned char *ptr; if (vr == "US" || vr == "SS") { @@ -2264,11 +2258,11 @@ gdcmHeaderEntry *gdcmParser::NewHeaderEntryByName(std::string Name) /** * \ingroup gdcmParser * \brief Request a new virtual dict entry to the dict set - * @param group group of the underlying DictEntry - * @param element element of the underlying DictEntry - * @param vr VR of the underlying DictEntry - * @param fourth owner group - * @param name english name + * @param group group of the underlying DictEntry + * @param elem element of the underlying DictEntry + * @param vr VR of the underlying DictEntry + * @param fourth owner group + * @param name english name */ gdcmDictEntry *gdcmParser::NewVirtualDictEntry(guint16 group, guint16 element, std::string vr,