Skip to content

Commit

Permalink
Update the view current position after a slice append. Fixes #200.
Browse files Browse the repository at this point in the history
  • Loading branch information
ivmartel committed Feb 9, 2016
1 parent 969e381 commit a0232e4
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 6 deletions.
4 changes: 4 additions & 0 deletions src/image/image.js
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,7 @@ dwv.image.Image = function(geometry, buffer)
* Append a slice to the image.
* @method appendSlice
* @param {Image} The slice to append.
* @return {Number} The number of the inserted slice.
*/
this.appendSlice = function(rhs)
{
Expand Down Expand Up @@ -329,6 +330,9 @@ dwv.image.Image = function(geometry, buffer)
// copy to class variables
buffer = newBuffer;
originalBuffer = new Int16Array(newBuffer);

// return the appended slice number
return newSliceNb;
};

/**
Expand Down
31 changes: 25 additions & 6 deletions src/image/view.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,14 +163,21 @@ dwv.image.View = function(image, isSigned)
* Set the current position. Returns false if not in bounds.
* @method setCurrentPosition
* @param {Object} pos The current position.
* @param {Boolean} silent If true, does not fire a slice-change event.
*/
this.setCurrentPosition = function(pos) {
this.setCurrentPosition = function(pos, silent) {
// default silent flag to false
if ( typeof silent === "undefined" ) {
silent = false;
}
// check if possible
if( !image.getGeometry().getSize().isInBounds(pos.i,pos.j,pos.k) ) {
return false;
}
var oldPosition = currentPosition;
currentPosition = pos;
// only display value for monochrome data

// fire a 'position-change' event
if( image.getPhotometricInterpretation().match(/MONOCHROME/) !== null )
{
this.fireEvent({"type": "position-change",
Expand All @@ -182,10 +189,15 @@ dwv.image.View = function(image, isSigned)
this.fireEvent({"type": "position-change",
"i": pos.i, "j": pos.j, "k": pos.k});
}
// slice change event (used to trigger redraw)
if( oldPosition.k !== currentPosition.k ) {
this.fireEvent({"type": "slice-change"});

// fire a slice change event (used to trigger redraw)
if ( !silent ) {
if( oldPosition.k !== currentPosition.k ) {
this.fireEvent({"type": "slice-change"});
}
}

// all good
return true;
};

Expand All @@ -197,7 +209,14 @@ dwv.image.View = function(image, isSigned)
this.append = function( rhs )
{
// append images
this.getImage().appendSlice( rhs.getImage() );
var newSLiceNumber = this.getImage().appendSlice( rhs.getImage() );
// update position if a slice was appended before
if ( newSLiceNumber <= this.getCurrentPosition().k ) {
this.setCurrentPosition(
{"i": this.getCurrentPosition().i,
"j": this.getCurrentPosition().j,
"k": this.getCurrentPosition().k + 1}, true );
}
// init to update self
this.setWindowLut(rhs.getWindowLut());
};
Expand Down

0 comments on commit a0232e4

Please sign in to comment.