Skip to content

Commit

Permalink
Updated pixel value info when changing frame. Protect dicom parser.
Browse files Browse the repository at this point in the history
Protect for when there is no pixels...
  • Loading branch information
ivmartel committed Jun 23, 2016
1 parent e4eb1ca commit 4c69e57
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 20 deletions.
32 changes: 17 additions & 15 deletions src/dicom/dicomParser.js
Original file line number Diff line number Diff line change
Expand Up @@ -997,21 +997,23 @@ dwv.dicom.DicomParser.prototype.parse = function (buffer)
}

// pixel buffer
if (this.dicomElements.x7FE00010.vl !== "u/l") {
this.pixelBuffer = this.dicomElements.x7FE00010.value;
}
else {
// concatenate pixel data items
// concat does not work on typed arrays
//this.pixelBuffer = this.pixelBuffer.concat( dataElement.data );
// manual concat...
var items = this.dicomElements.x7FE00010.value;
for (var i = 0; i < items.length; ++i) {
var size = items[i].value.length + this.pixelBuffer.length;
var newBuffer = new Uint16Array(size);
newBuffer.set( this.pixelBuffer, 0 );
newBuffer.set( items[i].value, this.pixelBuffer.length );
this.pixelBuffer = newBuffer;
if (typeof this.dicomElements.x7FE00010 !== "undefined") {
if (this.dicomElements.x7FE00010.vl !== "u/l") {
this.pixelBuffer = this.dicomElements.x7FE00010.value;
}
else {
// concatenate pixel data items
// concat does not work on typed arrays
//this.pixelBuffer = this.pixelBuffer.concat( dataElement.data );
// manual concat...
var items = this.dicomElements.x7FE00010.value;
for (var i = 0; i < items.length; ++i) {
var size = items[i].value.length + this.pixelBuffer.length;
var newBuffer = new Uint16Array(size);
newBuffer.set( this.pixelBuffer, 0 );
newBuffer.set( items[i].value, this.pixelBuffer.length );
this.pixelBuffer = newBuffer;
}
}
}
};
Expand Down
23 changes: 19 additions & 4 deletions src/image/image.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,19 @@ dwv.image.RescaleSlopeAndIntercept.prototype.toString = function () {
*/
dwv.image.Image = function(geometry, buffer, numberOfFrames)
{
/**
* Number of frames.
* @private
* @type Number
*/
if (typeof numberOfFrames === "undefined" ) {
numberOfFrames = 1;
}

/**
* Get the number of frames.
* @returns {Number} The number of frames.
*/
this.getNumberOfFrames = function () {
return numberOfFrames;
};
Expand Down Expand Up @@ -351,26 +361,31 @@ dwv.image.Image = function(geometry, buffer, numberOfFrames)
* @param {Number} i The X index.
* @param {Number} j The Y index.
* @param {Number} k The Z index.
* @param {Number} f The frame number.
* @return {Number} The value at the desired position.
* Warning: No size check...
*/
dwv.image.Image.prototype.getValue = function( i, j, k )
dwv.image.Image.prototype.getValue = function( i, j, k, f )
{
var frame = (f || 0);
var index = new dwv.math.Index3D(i,j,k);
return this.getValueAtOffset( this.getGeometry().indexToOffset(index) );
return this.getValueAtOffset( this.getGeometry().getSize().getTotalSize() * frame +
this.getGeometry().indexToOffset(index) );
};

/**
* Get the rescaled value of the image at a specific coordinate.
* @param {Number} i The X index.
* @param {Number} j The Y index.
* @param {Number} k The Z index.
* @param {Number} f The frame number.
* @return {Number} The rescaled value at the desired position.
* Warning: No size check...
*/
dwv.image.Image.prototype.getRescaledValue = function( i, j, k )
dwv.image.Image.prototype.getRescaledValue = function( i, j, k, f )
{
return this.getRescaleSlopeAndIntercept(k).apply( this.getValue(i,j,k) );
var frame = (f || 0);
return this.getRescaleSlopeAndIntercept(k).apply( this.getValue(i,j,k,frame) );
};

/**
Expand Down
4 changes: 3 additions & 1 deletion src/image/view.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ dwv.image.View = function(image, isSigned)
{
this.fireEvent({"type": "position-change",
"i": pos.i, "j": pos.j, "k": pos.k,
"value": image.getRescaledValue(pos.i,pos.j,pos.k)});
"value": image.getRescaledValue(pos.i,pos.j,pos.k, this.getCurrentFrame())});
}
else
{
Expand Down Expand Up @@ -211,6 +211,8 @@ dwv.image.View = function(image, isSigned)
// fire event
if( oldFrame !== currentFrame ) {
this.fireEvent({"type": "frame-change", "frame": currentFrame});
// silent set current position to update info text
this.setCurrentPosition(this.getCurrentPosition(),true);
}
// all good
return true;
Expand Down

0 comments on commit 4c69e57

Please sign in to comment.