From 69671ddcbdab5850cb3442afcb638b4577a3e89a Mon Sep 17 00:00:00 2001 From: Thiago Franco de Moraes Date: Wed, 6 Sep 2017 10:41:35 -0300 Subject: [PATCH] Checking if a tag element has undefined length --- invesalius/reader/dicom_reader.py | 73 ++++++++++++++++++++++++++++++++++++------------------------------------- 1 file changed, 36 insertions(+), 37 deletions(-) diff --git a/invesalius/reader/dicom_reader.py b/invesalius/reader/dicom_reader.py index f569ca2..78a17b2 100644 --- a/invesalius/reader/dicom_reader.py +++ b/invesalius/reader/dicom_reader.py @@ -118,11 +118,11 @@ class LoadDicom: # Retrieve header header = file.GetHeader() stf = gdcm.StringFilter() + stf.SetFile(file) field_dict = {} data_dict = {} - tag = gdcm.Tag(0x0008, 0x0005) ds = reader.GetFile().GetDataSet() if ds.FindDataElement(tag): @@ -138,53 +138,52 @@ class LoadDicom: else: encoding = "ISO_IR 100" - # Iterate through the Header iterator = header.GetDES().begin() while (not iterator.equal(header.GetDES().end())): dataElement = iterator.next() - stf.SetFile(file) - tag = dataElement.GetTag() - data = stf.ToStringPair(tag) - stag = tag.PrintAsPipeSeparatedString() - - group = str(tag.GetGroup()) - field = str(tag.GetElement()) + if not dataElement.IsUndefinedLength(): + tag = dataElement.GetTag() + data = stf.ToStringPair(tag) + stag = tag.PrintAsPipeSeparatedString() - tag_labels[stag] = data[0] - - if not group in data_dict.keys(): - data_dict[group] = {} + group = str(tag.GetGroup()) + field = str(tag.GetElement()) - if not(utils.VerifyInvalidPListCharacter(data[1])): - data_dict[group][field] = data[1].decode(encoding) - else: - data_dict[group][field] = "Invalid Character" + tag_labels[stag] = data[0] + + if not group in data_dict.keys(): + data_dict[group] = {} + + if not(utils.VerifyInvalidPListCharacter(data[1])): + data_dict[group][field] = data[1].decode(encoding) + else: + data_dict[group][field] = "Invalid Character" - # Iterate through the Data set iterator = dataSet.GetDES().begin() while (not iterator.equal(dataSet.GetDES().end())): dataElement = iterator.next() - - stf.SetFile(file) - tag = dataElement.GetTag() - data = stf.ToStringPair(tag) - stag = tag.PrintAsPipeSeparatedString() - - group = str(tag.GetGroup()) - field = str(tag.GetElement()) - - tag_labels[stag] = data[0] - - if not group in data_dict.keys(): - data_dict[group] = {} - - if not(utils.VerifyInvalidPListCharacter(data[1])): - data_dict[group][field] = data[1].decode(encoding, 'replace') - else: - data_dict[group][field] = "Invalid Character" - + if not dataElement.IsUndefinedLength(): + tag = dataElement.GetTag() + # if (tag.GetGroup() == 0x0009 and tag.GetElement() == 0x10e3) \ + # or (tag.GetGroup() == 0x0043 and tag.GetElement() == 0x1027): + # continue + data = stf.ToStringPair(tag) + stag = tag.PrintAsPipeSeparatedString() + + group = str(tag.GetGroup()) + field = str(tag.GetElement()) + + tag_labels[stag] = data[0] + + if not group in data_dict.keys(): + data_dict[group] = {} + + if not(utils.VerifyInvalidPListCharacter(data[1])): + data_dict[group][field] = data[1].decode(encoding, 'replace') + else: + data_dict[group][field] = "Invalid Character" # -------------- To Create DICOM Thumbnail ----------- -- libgit2 0.21.2