You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

88 lines
3.0 KiB

// namespaces
var dwvOemr = dwvOemr || {};
dwvOemr.gui = dwvOemr.gui || {};
dwvOemr.gui.info = dwvOemr.gui.info || {};
/**
* MiniColourMap info layer.
* @constructor
* @param {Object} div The HTML element to add colourMap info to.
* @param {Object} app The associated application.
*/
dwvOemr.gui.info.MiniColourMap = function ( div, app )
{
/**
* Create the mini colour map info div.
*/
this.create = function ()
{
// clean div
var elems = div.getElementsByClassName("colour-map-info");
if ( elems.length !== 0 ) {
dwvOemr.html.removeNodes(elems);
}
// colour map
var canvas = document.createElement("canvas");
canvas.className = "colour-map-info";
canvas.width = 98;
canvas.height = 10;
// add canvas to div
div.appendChild(canvas);
};
/**
* Update the mini colour map info div.
* @param {Object} event The windowing change event containing the new values.
* Warning: expects the mini colour map div to exist (use after createMiniColourMap).
*/
this.update = function (event)
{
var windowCenter = event.wc;
var windowWidth = event.ww;
// retrieve canvas and context
var canvas = div.getElementsByClassName("colour-map-info")[0];
var context = canvas.getContext('2d');
// fill in the image data
var colourMap = app.getViewController().getColourMap();
var imageData = context.getImageData(0,0,canvas.width, canvas.height);
// histogram sampling
var c = 0;
var minInt = app.getImage().getRescaledDataRange().min;
var range = app.getImage().getRescaledDataRange().max - minInt;
var incrC = range / canvas.width;
// Y scale
var y = 0;
var yMax = 255;
var yMin = 0;
// X scale
var xMin = windowCenter - 0.5 - (windowWidth-1) / 2;
var xMax = windowCenter - 0.5 + (windowWidth-1) / 2;
// loop through values
var index;
for ( var j = 0; j < canvas.height; ++j ) {
c = minInt;
for ( var i = 0; i < canvas.width; ++i ) {
if ( c <= xMin ) {
y = yMin;
}
else if ( c > xMax ) {
y = yMax;
}
else {
y = ( (c - (windowCenter-0.5) ) / (windowWidth-1) + 0.5 ) *
(yMax-yMin) + yMin;
y = parseInt(y,10);
}
index = (i + j * canvas.width) * 4;
imageData.data[index] = colourMap.red[y];
imageData.data[index+1] = colourMap.green[y];
imageData.data[index+2] = colourMap.blue[y];
imageData.data[index+3] = 0xff;
c += incrC;
}
}
// put the image data in the context
context.putImageData(imageData, 0, 0);
};
}; // class dwvOemr.gui.info.MiniColourMap