Skip to content

Commit

Permalink
Merge input data tags into tags object. Fixes #690.
Browse files Browse the repository at this point in the history
  • Loading branch information
ivmartel committed Nov 30, 2019
1 parent 8baca82 commit fffafc1
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 16 deletions.
21 changes: 16 additions & 5 deletions src/app/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -1386,6 +1386,22 @@ dwv.App = function ()
*/
function postLoadInit(data)
{
// append the DICOM tags table
var dataInfo = new dwv.dicom.DicomElementsWrapper(data.info);
var dataInfoObj = dataInfo.dumpToObject();
if (tags) {
tags = dwv.utils.mergeObjects(
tags,
dataInfoObj,
"InstanceNumber",
"value");
} else {
tags = dataInfoObj;
}
if ( tagsGui ) {
tagsGui.update(dwv.dicom.objectToArray(tags));
}

// only initialise the first time
if ( view ) {
return;
Expand All @@ -1395,11 +1411,6 @@ dwv.App = function ()
view = data.view;
viewController = new dwv.ViewController(view);

// append the DICOM tags table
tags = data.info;
if ( tagsGui ) {
tagsGui.update(data.info);
}
// store image
originalImage = view.getImage();
image = originalImage;
Expand Down
35 changes: 27 additions & 8 deletions src/dicom/dicomElementsWrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,27 @@
var dwv = dwv || {};
dwv.dicom = dwv.dicom || {};

/**
* Dump the DICOM tags to an array.
* @input {Object} obj A dicom tag object: {tagname: {tagKey0: tagValue0, ...}, ...}
* @return {Array} An array in the form [{name: tagname, tagKey0: tagValue0}, ...]
*/
dwv.dicom.objectToArray = function (obj) {
var array = [];
var keys = Object.keys(obj);
for (var i = 0; i < keys.length; ++i ) {
var key = keys[i];
var row = {name: key};
var innerKeys = Object.keys(obj[key]);
for (var j = 0; j < innerKeys.length; ++j ) {
var innerKey = innerKeys[j];
row[innerKey] = obj[key][innerKey];
}
array.push(row);
}
return array;
};

/**
* DicomElements wrapper.
* @constructor
Expand Down Expand Up @@ -47,10 +68,10 @@ dwv.dicom.DicomElementsWrapper = function (dicomElements) {
* Dump the DICOM tags to an array.
* @return {Array}
*/
this.dumpToTable = function () {
this.dumpToObject = function () {
var keys = Object.keys(dicomElements);
var dict = dwv.dicom.dictionary;
var table = [];
var obj = {};
var dicomElement = null;
var dictElement = null;
var row = null;
Expand All @@ -64,11 +85,9 @@ dwv.dicom.DicomElementsWrapper = function (dicomElements) {
dictElement = dict[dicomElement.tag.group][dicomElement.tag.element];
}
// name
var name = "Unknown Tag & Data";
if ( dictElement !== null ) {
row.name = dictElement[2];
}
else {
row.name = "Unknown Tag & Data";
name = dictElement[2];
}
// value
row.value = this.getElementValueAsString(dicomElement);
Expand All @@ -78,9 +97,9 @@ dwv.dicom.DicomElementsWrapper = function (dicomElements) {
row.vr = dicomElement.vr;
row.vl = dicomElement.vl;

table.push( row );
obj[name] = row;
}
return table;
return obj;
};

/**
Expand Down
10 changes: 10 additions & 0 deletions src/gui/html.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,16 @@ dwv.html.appendCell = function (row, content)
content[10] = "...";
}
str = Array.prototype.join.call( content, ', ' );
} else if (dwv.utils.isObject(content)) {
str = "";
var keys = Object.keys(content);
for (var i = 0; i < keys.length; ++i ) {
var key = keys[i];
if (str.length !== 0) {
str += ", ";
}
str += key + ": " + content[key];
}
}
// append
cell.appendChild(document.createTextNode(str));
Expand Down
2 changes: 1 addition & 1 deletion src/image/dicomBufferToView.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ dwv.image.DicomBufferToView = function ()
var viewFactory = new dwv.image.ViewFactory();
var view = viewFactory.create( dicomParser.getDicomElements(), image );
// return
self.onload({"view": view, "info": dicomParser.getDicomElements().dumpToTable()});
self.onload({"view": view, "info": dicomParser.getRawDicomElements()});
};

if ( needDecompression ) {
Expand Down
2 changes: 1 addition & 1 deletion tests/dicom/dicomElementsWrapper.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ QUnit.test("Test simple DICOM wrapping.", function (assert) {
// wrapped tags
var tags = dicomParser.getDicomElements();
// dump to table
var table = tags.dumpToTable();
var table = dwv.dicom.objectToArray(tags.dumpToObject());

// regression table
var teoTable = [
Expand Down
2 changes: 1 addition & 1 deletion tests/dicom/dicomParser.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ QUnit.test("Test sequence DICOM parsing.", function (assert) {
assert.ok((Object.keys(rawTags).length!==0), "Got raw tags.");
// wrapped tags
var tags = dicomParser.getDicomElements();
assert.ok((tags.dumpToTable().length!==0), "Got wrapped tags.");
assert.ok((tags.dumpToObject().length!==0), "Got wrapped tags.");

// ReferencedImageSequence: explicit sequence
var seq00 = tags.getFromName("ReferencedImageSequence");
Expand Down

0 comments on commit fffafc1

Please sign in to comment.