Skip to content

Commit

Permalink
ROIs started. Meta data fixed.
Browse files Browse the repository at this point in the history
  • Loading branch information
mi-kas committed Apr 23, 2013
1 parent fef8464 commit 0b4b405
Show file tree
Hide file tree
Showing 4 changed files with 123 additions and 4 deletions.
35 changes: 34 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
<script type="text/javascript" src="js/tools/WindowLevel.js"></script>
<script type="text/javascript" src="js/tools/Zoom.js"></script>
<script type="text/javascript" src="js/tools/Move.js"></script>
<script type="text/javascript" src="js/tools/Roi.js"></script>

<script>
$(document).ready(function() {
Expand Down Expand Up @@ -139,13 +140,32 @@
if(e.shiftKey) {
$('#zoom').click();
}

return;
});

$('#buttonSet').buttonset();
$('#resetButton').button();
$('#metaButton').button();
// $('#roi').button();
// $('#roiSelect').button({
// text: false,
// icons: {
// primary: "ui-icon-triangle-1-s"
// }
// }).click(function() {
// var menu = $('#roiMenu').show().position({
// my: "left top",
// at: "left bottom",
// of: this
// });
// $(document).one("click", function() {
// menu.hide();
// });
// return false;
// });
// $('#roiDiv').buttonset();
// $('#roiMenu').menu().hide();
$('#showStudyData').button();
$('#matrixView').selectBoxIt();
$("#slider").slider({
Expand Down Expand Up @@ -202,7 +222,20 @@
<input type="radio" id="windowLevel" name="toolbox-buttons" value="Window level" checked="checked" /><label for="windowLevel">Window level</label>
<input type="radio" id="move" name="toolbox-buttons" value="Move" /><label for="move">Move</label>
<input type="radio" id="zoom" name="toolbox-buttons" value="Zoom" /><label for="zoom">Zoom</label>
<input type="radio" id="roi" name="toolbox-buttons" value="Roi" /><label for="roi">ROI</label>
<!--<button id="roi" value="Roi">ROI</button>-->
</div>
<!-- <div id="roiDiv">
<button id="roi" value="Roi">ROI</button>
<button id="roiSelect" value="Roi"></button>
</div>
<ul id="roiMenu">
<li><a>Green</a></li>
<li><a>Red</a></li>
<li><a>Blue</a></li>
<li><a>Yellow</a></li>
</ul>-->

<div id="singleButtons">
<select id="matrixView" name="matrixView">
Expand Down
4 changes: 2 additions & 2 deletions js/DcmViewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ DcmViewer.prototype.eventHandler = function(e) {
// pass the event to the currentTool of the toolbox
var eventFunc = this.toolbox.currentTool[e.type];
if(eventFunc) {
eventFunc(e.x, e.y, this.painters);
eventFunc(e.x, e.y, this.painters, e.target);
}
}
};
Expand Down Expand Up @@ -193,7 +193,7 @@ DcmViewer.prototype.openMetaDialog = function() {
var body = document.createElement('tbody');

$.each(file, function(key, value) {
if(value !== undefined && typeof value !== 'object' && !$.isFunction(value)) {
if(!$.isFunction(value)) { //value !== undefined && typeof value !== 'object' &&
var currentRow = document.createElement("tr");
var cell1 = document.createElement("td");
var text1 = document.createTextNode(key);
Expand Down
3 changes: 2 additions & 1 deletion js/Toolbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ function Toolbox(painter) {
this.tools = {
'Window level': new WindowLevel(),
'Zoom': new Zoom(),
'Move': new Move()
'Move': new Move(),
'Roi': new Roi()
};
this.currentTool = this.tools['Window level'];
}
Expand Down
85 changes: 85 additions & 0 deletions js/tools/Roi.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/*
* All tools must implement following functions
* click(x, y, painters)
* dblclick(x, y, painters)
* mousedown(x, y, painters)
* mouseup(x, y, painters)
* mousemove(x, y, painters)
* mouseout(x, y, painters)
*/
function Roi() {
this.started = false;
this.startX = 0;
this.startY = 0;
this.color = '#0f0';
}

Roi.prototype.setColor = function(hex) {
this.color = hex;
};

Roi.prototype.click = function() {
};

Roi.prototype.mousedown = function(x, y) {
this.startX = x;
this.startY = y;
this.started = true;
};

Roi.prototype.mouseup = function(x, y, painters, target) {
if(this.started) {
// calculate and show length
var painter = getPainterFromId(target.id, painters);
var context = painter.context;
var dist = calculateDist(painter, this.startX, this.startY, x, y);
context.font = "10px Helvetica";
context.fillStyle = this.color;
context.fillText(dist, x + 3, y + 3);
this.started = false;
}
};

Roi.prototype.mousemove = function(x, y, painters, target) {
if(this.started) {
var painter = getPainterFromId(target.id, painters);
var context = painter.context;
getPainterFromId(target.id, painters).drawImg();
context.beginPath();
context.moveTo(this.startX, this.startY);
context.lineTo(x, y);
context.strokeStyle = this.color;
context.stroke();
context.closePath();
}
};

Roi.prototype.mouseout = function() {
this.started = false;
};

//var drawLine = function(x, y, context) {
// painters[0].context.clearRect(0, 0, painters[0].canvas.width, painters[0].canvas.height);
// context.beginPath();
// context.moveTo(this.startX, this.startY);
// context.lineTo(x, y);
// context.strokeStyle = '#0f0';
// context.stroke();
// context.closePath();
//};

var getPainterFromId = function(id, painters) {
for(var i = 0, len = painters.length; i < len; i++) {
if(painters[i].canvas.id === id) {
return painters[i];
}
}
return null;
};

var calculateDist = function(painter, startX, startY, endX, endY) {
var pixelSpacing = painter.currentFile.PixelSpacing ? painter.currentFile.PixelSpacing : [1, 1];
var a = (endX - startX) * pixelSpacing[0] / painter.getScale();
var b = (endY - startY) * pixelSpacing[1] / painter.getScale();
return Math.sqrt(Math.abs(a^2 + b^2)).toFixed(2) + 'mm';
};

0 comments on commit 0b4b405

Please sign in to comment.