// namespaces var dwv = dwv || {}; dwv.gui = dwv.gui || {}; dwv.gui.base = dwv.gui.base || {}; dwv.gui.info = dwv.gui.info || {}; /** * Plot some data in a given div. * @param {Object} div The HTML element to add WindowLevel info to. * @param {Array} data The data array to plot. * @param {Object} options Plot options. */ dwv.gui.base.plot = function (/*div, data, options*/) { // default does nothing... }; /** * MiniColourMap info layer. * @constructor * @param {Object} div The HTML element to add colourMap info to. * @param {Object} app The associated application. */ dwv.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 ) { dwv.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 dwv.gui.info.MiniColourMap /** * Plot info layer. * @constructor * @param {Object} div The HTML element to add colourMap info to. * @param {Object} app The associated application. */ dwv.gui.info.Plot = function (div, app) { /** * Create the plot info. */ this.create = function() { // clean div if ( div ) { dwv.html.cleanNode(div); } // plot dwv.gui.plot(div, app.getImage().getHistogram()); }; /** * Update plot. * @param {Object} event The windowing change event containing the new values. * Warning: expects the plot to exist (use after createPlot). */ this.update = function (event) { var wc = event.wc; var ww = event.ww; var half = parseInt( (ww-1) / 2, 10 ); var center = parseInt( (wc-0.5), 10 ); var min = center - half; var max = center + half; var markings = [ { "color": "#faa", "lineWidth": 1, "xaxis": { "from": min, "to": min } }, { "color": "#aaf", "lineWidth": 1, "xaxis": { "from": max, "to": max } } ]; // plot dwv.gui.plot(div, app.getImage().getHistogram(), {markings: markings}); }; }; // class dwv.gui.info.Plot /** * DICOM Header overlay info layer. * @constructor * @param {Object} div The HTML element to add Header overlay info to. * @param {String} pos The string to specify the corner position. (tl,tc,tr,cl,cr,bl,bc,br) */ dwv.gui.info.Overlay = function ( div, pos, app ) { // closure to self var self = this; /** * Get the overlay array of the current position. * @return {Array} The overlay information. */ this.getOverlays = function () { var image = app.getImage(); if (!image) { return; } var allOverlays = image.getOverlays(); if (!allOverlays) { return; } var position = app.getViewController().getCurrentPosition(); var sliceOverlays = allOverlays[position.k]; if (!sliceOverlays) { return; } return sliceOverlays[pos]; }; /** * Create the overlay info div. */ this.create = function () { // remove all