custom-cornerstone-tools
Version:
Medical imaging tools for the Cornerstone library - customized for DrNuvem
268 lines (228 loc) • 9.46 kB
HTML
<html>
<head>
<!-- support for mobile touch devices -->
<meta name="viewport" content="user-scalable=no, width=device-width, initial-scale=1, maximum-scale=1">
<!-- twitter bootstrap CSS stylesheet - not required by cornerstoneTools -->
<link href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css" rel="stylesheet">
<link href="../dialogPolyfill.css" rel="stylesheet">
<link href="../cornerstone.min.css" rel="stylesheet">
<style>
/* prevents selection when left click dragging */
.disable-selection {
-moz-user-select: none; -webkit-user-select: none; -ms-user-select:none; user-select:none;
}
/* prevents cursor from changing to the i bar on the overlays*/
.noIbar {
cursor:default;
}
.annotationDialog, .relabelDialog {
z-index: 1000;
position: absolute;
margin: 0px;
left: 40%;
top: 40%;
width: 300px;
border: 1px black solid;
border-radius: 5px;
}
.annotationTextInputOptions {
padding: 5px 0px;
}
.annotationTextInput {
margin-left: 5px;
}
.annotationDialogConfirm {
float: right;
}
</style>
</head>
<body>
<div class="container">
<div class="page-header">
<h1>
Annotation Example
</h1>
<p>
This page contains an example of the text annotation tool
</p>
<a href="../index.html">Go back to the Examples page</a>
</div>
<div class="row">
<div class="col-xs-12 col-sm-2">
<ul class="list-group">
<a id="enable" class="list-group-item">Enable</a>
<a id="activate" class="list-group-item">Activate</a>
<a id="deactivate" class="list-group-item">Deactivate</a>
<a id="disable" class="list-group-item">Disable</a>
</ul>
</div>
<div class="col-xs-6">
<div style="width:256px;height:256px;position:relative;display:inline-block;color:white;"
oncontextmenu="return false"
class='cornerstone-enabled-image disable-selection noIbar'
unselectable='on'
onselectstart='return false;'
onmousedown='return false;'>
<div id="dicomImage"
style="width:256px;height:256px;top:0px;left:0px; position:absolute;">
</div>
</div>
<dialog class="annotationDialog">
<h5>Enter your annotation</h5>
<div class="annotationTextInputOptions">
<label for="annotationTextInput">New label</label>
<input name="annotationTextInput" class="annotationTextInput" type="text"/>
</div>
<a class="annotationDialogConfirm btn btn-sm btn-primary">OK</a>
</dialog>
<dialog class="relabelDialog" oncontextmenu="return false">
<h5>Edit your annotation</h5>
<div class="annotationTextInputOptions">
<label for="annotationTextInput">New label</label>
<input name="annotationTextInput" class="annotationTextInput" type="text"/>
</div>
<div>
<a class="relabelRemove btn btn-sm btn-secondary">Remove marker</a>
<a class="relabelConfirm btn btn-sm btn-primary">OK</a>
</div>
</dialog>
</div>
</div>
</body>
<!-- jquery - included to make things easier to demo, not needed or used by the cornerstone library but
is used by our example image loader-->
<script src="../jquery.min.js"></script>
<!-- include the hammer.js library for touch gestures-->
<script src="../hammer.min.js"></script>
<!-- include the cornerstone library -->
<script src="../cornerstone.min.js"></script>
<script src="../cornerstoneMath.min.js"></script>
<!-- include the cornerstone tools library -->
<script src="../../dist/cornerstoneTools.js"></script>
<!-- include special code for these examples which provides images -->
<script src="../exampleImageLoader.js"></script>
<script src="../dialogPolyfill.js"></script>
<script>
// Register the dialogs using the HTML5 Dialog Polyfill
var annotationDialog = document.querySelector('.annotationDialog');
var relabelDialog = document.querySelector('.relabelDialog');
dialogPolyfill.registerDialog(annotationDialog);
dialogPolyfill.registerDialog(relabelDialog);
var element = $('#dicomImage').get(0);
var imageId = 'example://1';
// Define a callback to get your text annotation
// This could be used, e.g. to open a modal
function getTextCallback(doneChangingTextCallback) {
var annotationDialog = $('.annotationDialog');
var getTextInput = annotationDialog .find('.annotationTextInput');
var confirm = annotationDialog .find('.annotationDialogConfirm');
annotationDialog .get(0).showModal();
confirm.off('click');
confirm.on('click', function() {
closeHandler();
});
annotationDialog .off("keydown");
annotationDialog .on('keydown', keyPressHandler);
function keyPressHandler(e) {
// If Enter is pressed, close the dialog
if (e.which === 13) {
closeHandler();
}
}
function closeHandler() {
annotationDialog .get(0).close();
doneChangingTextCallback(getTextInput.val());
// Reset the text value
getTextInput.val("");
}
}
// Define a callback to edit your text annotation
// This could be used, e.g. to open a modal
function changeTextCallback(data, eventData, doneChangingTextCallback) {
var relabelDialog = $('.relabelDialog');
var getTextInput = relabelDialog.find('.annotationTextInput');
var confirm = relabelDialog.find('.relabelConfirm');
var remove = relabelDialog.find('.relabelRemove');
getTextInput.val(data.annotationText);
relabelDialog.get(0).showModal();
confirm.off('click');
confirm.on('click', function() {
relabelDialog.get(0).close();
doneChangingTextCallback(data, getTextInput.val());
});
// If the remove button is clicked, delete this marker
remove.off('click');
remove.on('click', function() {
relabelDialog.get(0).close();
doneChangingTextCallback(data, undefined, true);
});
relabelDialog.off("keydown");
relabelDialog.on('keydown', keyPressHandler);
function keyPressHandler(e) {
// If Enter is pressed, close the dialog
if (e.which === 13) {
closeHandler();
}
}
function closeHandler() {
relabelDialog.get(0).close();
doneChangingTextCallback(data, getTextInput.val());
// Reset the text value
getTextInput.val("");
}
}
var config = {
getTextCallback : getTextCallback,
changeTextCallback : changeTextCallback,
drawHandles : false,
drawHandlesOnHover : true,
arrowFirst : true
}
// image enable the dicomImage element
cornerstone.enable(element);
cornerstoneTools.mouseInput.enable(element);
cornerstoneTools.touchInput.enable(element);
cornerstone.loadImage(imageId).then(function(image) {
cornerstone.displayImage(element, image);
// Try commenting this out to see the default behaviour
// By default, the tool uses Javascript's Prompt function
// to ask the user for the annotation. This example uses a
// slightly nicer HTML5 dialog element.
cornerstoneTools.arrowAnnotate.setConfiguration(config);
// Enable all tools we want to use with this element
cornerstoneTools.arrowAnnotate.activate(element, 1);
cornerstoneTools.arrowAnnotateTouch.activate(element);
activate("#activate");
function activate(id) {
$('a').removeClass('active');
$(id).addClass('active');
}
// Tool button event handlers that set the new active tool
$('#enable').click(function() {
activate("#enable");
cornerstoneTools.arrowAnnotate.enable(element);
cornerstoneTools.arrowAnnotateTouch.enable(element);
return false;
});
$('#disable').click(function() {
activate("#disable");
cornerstoneTools.arrowAnnotate.disable(element);
cornerstoneTools.arrowAnnotateTouch.disable(element);
return false;
});
$('#activate').click(function() {
activate("#activate");
cornerstoneTools.arrowAnnotate.activate(element, 1);
cornerstoneTools.arrowAnnotateTouch.activate(element);
return false;
});
$('#deactivate').click(function() {
activate("#deactivate");
cornerstoneTools.arrowAnnotate.deactivate(element, 1);
cornerstoneTools.arrowAnnotateTouch.deactivate(element);
return false;
});
});
</script>
</html>