Press "t" to cycle through tools

Active Tool: Brush

          
          

function triggerHandleToggle() { let isMultiImage = larvitar.DEFAULT_TOOLS["WSToggle"].configuration.multiImage === false ? true : false; larvitar.DEFAULT_TOOLS["WSToggle"].configuration.multiImage = isMultiImage; toggleButton.innerHTML = isMultiImage === true ? "Multi Image" : "Current Image"; startInput.style.display = isMultiImage === true ? "block" : "none"; endInput.style.display = isMultiImage === true ? "block" : "none"; } const bindInputEvent = (inputElement, configKey) => { inputElement.addEventListener("input", function (event) { larvitar.DEFAULT_TOOLS["WSToggle"].configuration[configKey] = event.target.value; }); }; masksNumberInput.addEventListener("input", function (event) { larvitar.DEFAULT_TOOLS["WSToggle"].configuration.masksNumber = event.target.value; }); bindInputEvent(startInput, "startIndex"); bindInputEvent(endInput, "endIndex"); toggleButton.addEventListener("click", triggerHandleToggle); let demoFiles = []; let counter = 0; const getDemoFileNames = function () { let demoFileList = []; for (let i = 1; i < 25; i++) { let filename = "anon" + i; demoFileList.push(filename); } return demoFileList; }; // init all larvitar.initializeImageLoader(); larvitar.initializeCSTools(); larvitar.store.initialize(); larvitar.store.addViewport("viewer"); larvitar.registerNRRDImageLoader(); larvitar.initSegmentationModule(); async function createFile(fileName, cb) { let response = await fetch("./demo/" + fileName); let data = await response.blob(); let file = new File([data], fileName); demoFiles.push(file); counter++; if (counter == 24) { cb(); } } async function renderSerie() { larvitar.resetLarvitarManager(); larvitar .readFiles(demoFiles) .then(seriesStack => { // render the first series of the study let seriesId = _.keys(seriesStack)[0]; let serie = seriesStack[seriesId]; larvitar.renderImage(serie, "viewer").then(() => { console.log("Image has been rendered"); }); // optionally cache the series larvitar.populateLarvitarManager(seriesId, serie); larvitar .cacheImages(serie, function (resp) { if (resp.loading == 100) { let cache = larvitar.cornerstone.imageCache; console.log( "Cache size: ", cache.getCacheInfo().cacheSizeInBytes / 1e6, "Mb" ); } }) .then(() => { setTimeout(function () { console.log("Cache has been loaded. Calling loadMasks."); larvitar.addDefaultTools(); larvitar.setToolActive("Brush"); loadMasks(); }, 3000); }); let mouseConfig = { mouse_button_right: { ctrl: "Pan", default: "Zoom" }, debug: true }; // NOTE: this also activate the tools marked as default for each mouse button larvitar.addMouseKeyHandlers(mouseConfig); }) .catch(err => console.error(err)); } async function loadMasks() { let data = new Int16Array(768 * 768 * 24); //fix dimensions based on loaded images dimensions let properties = { // color: "#00ff00", opacity: 0.2, labelId: 0 }; // add to viewport await larvitar .addSegmentationMask(properties, data, "viewer") .then(() => { // activate brush on this labelmap larvitar.setActiveLabelmap(0, "viewer"); }); } let demoFileList = getDemoFileNames(); _.each(demoFileList, function (demoFile) { createFile(demoFile, renderSerie); }); let element = document.getElementById("viewer"); let tool_counter = 0; let tool; document.onkeypress = function (e) { e = e || window.event; //larvitar.clearSegmentationState(); if (e.keyCode == 116 || e.keyCode == 84) { if (tool != undefined) { //clearToolData(element, tool); } const selectedNames = [ "Brush", "RectangleScissors", "FreehandScissors", "CircleScissors", "CorrectionScissors", "PolylineScissors", "WSToggle" ]; // Replace with your selected names const selectedTools = _.filter(larvitar.DEFAULT_TOOLS, tool => _.includes(selectedNames, tool.name) ); const tools = _.map(selectedTools, "name"); let increment = e.shiftKey ? -1 : 1; tool_counter = tool_counter == tools.length - 1 ? 0 : tool_counter + increment; tool_counter = tool_counter < 0 ? 0 : tool_counter; tool = tools[tool_counter]; larvitar.setToolActive(tool); if (tool === "WSToggle") { larvitar.clearSegmentationState(); document.getElementById("info").innerHTML = "ctrl+mouse wheel to change brush radius
" + "click to activate watershed segmentation of features with greyscale " + "value of interest
" + "ctrl+click for Label Eraser: erases selected label
" + "alt+click for LabelPicker: allows you to pick a label, click again to " + "apply the picked label
" + "shift+click+drag for Manual Eraser"; buttonBar.style.removeProperty("display"); // make it visible //TODO: do not use block, delete display parameter from style instead //to make it return to boostrap's default (flex) //remove flex grow for buttonDiv.style.removeProperty("display"); loader.style.display = "none"; [maskDiv, loaderDiv, startDiv, endDiv, buttonDiv].forEach(div => { div.style.flexGrow = 0; div.style.paddingLeft = "3px"; }); element.addEventListener("click", rotateLoader); } else { document.getElementById("info").innerHTML = "
"; buttonBar.style.display = "none"; // make it invisible element.removeEventListener("click", rotateLoader); } $("#active-tool").html("Active Tool: " + tool); } };