### Start Larvitar Development Server Source: https://github.com/dvisionlab/larvitar/blob/master/README.md Starts the development server for Larvitar, allowing for local development and testing of the library and its examples. ```bash yarn run dev ``` -------------------------------- ### Basic Viewer Setup Source: https://github.com/dvisionlab/larvitar/blob/master/docs/guide/examples.md Demonstrates how to set up a simple viewer using Larvitar's core functionalities. Covers initialization, loading an image, basic viewer controls, inspecting and modifying image metadata, and drag-and-drop image loading. ```html
Larvitar
# Larvitar Examples Explore these examples to learn how to use Larvitar for various medical imaging tasks. Each example demonstrates a specific functionality, making it easy to get started and see Larvitar in action. --- ## Examples List ### 1. Basic Viewer Setup Learn how to set up a simple viewer using Larvitar’s core functionalities. This example covers initialization, loading an image, and basic viewer controls. In this example you can also: - inspect the metadata of the loaded image - change some metadata of the loaded image - drag and drop an image to the viewer [View Example ➔](https://larvitar.dvisionlab.com/examples/base.html) ``` -------------------------------- ### Larvitar Initialization and Setup Source: https://github.com/dvisionlab/larvitar/blob/master/docs/examples/segmentationTools.html Initializes various Larvitar modules, registers loaders, and sets the log level. ```JavaScript // init all larvitar.initializeImageLoader(); larvitar.initializeCSTools(); larvitar.store.initialize(); larvitar.store.addViewport("viewer"); larvitar.registerNRRDImageLoader(); larvitar.initSegmentationModule(); // set log level to debug larvitar.setLogLevel("debug"); showSpinner(); ``` -------------------------------- ### Larvitar Initialization and Viewer Setup Source: https://github.com/dvisionlab/larvitar/blob/master/docs/examples/4d.html Initializes Larvitar components, sets the log level, and adds a viewer to the application. This sets up the basic environment for using Larvitar's functionalities. ```javascript larvitar.initializeImageLoader(); larvitar.initializeCSTools(); larvitar.store.initialize(); larvitar.store.addViewport("viewer"); larvitar.setLogLevel("debug"); ``` -------------------------------- ### Base HTML Loading and Setup (Cypress) Source: https://github.com/dvisionlab/larvitar/blob/master/docs/api/modules/tests/cypress.md Tests the initial loading and setup of the base.html page for the Larvitar DICOM viewer. It verifies viewer visibility and waits for all files to load before proceeding. ```javascript it("visits the base.html page", () => { cy.visit("examples/base.html"); cy.get("#viewer").should("be.visible"); cy.wait(1000); }); it("waits for all files to load", () => { cy.wait(1000); }); ``` -------------------------------- ### Larvitar Initialization and UI Control Source: https://github.com/dvisionlab/larvitar/blob/master/docs/examples/singleFrame.html This snippet shows the basic setup for using the Larvitar library. It includes initializing image loaders, registering viewports, setting the log level, and controlling a loading spinner. It also demonstrates how to clear the cache and prepare for image loading. ```javascript const spinner = document.getElementById("spinner"); // Show spinner function showSpinner() { spinner.style.display = "block"; } // Hide spinner function hideSpinner() { spinner.style.display = "none"; } let demoFiles = []; // init all larvitar.initializeImageLoader(); larvitar.registerSingleFrameImageLoader(); larvitar.initializeCSTools(); larvitar.store.initialize(); larvitar.store.addViewport("viewer-1"); larvitar.store.addViewport("viewer-2"); larvitar.store.addViewport("viewer-3"); larvitar.store.addViewport("viewer-4"); larvitar.store.addViewport("viewer-5"); // set log level to debug larvitar.setLogLevel("debug"); showSpinner(); larvitar.clearSingleFrameCache(); ``` -------------------------------- ### Install Larvitar using npm Source: https://github.com/dvisionlab/larvitar/blob/master/docs/guide/installation.md Add the Larvitar library to your project's dependencies using npm. Ensure you have Node.js and npm installed. ```bash npm install larvitar ``` -------------------------------- ### Larvitar Initialization and Image Loading Example Source: https://github.com/dvisionlab/larvitar/blob/master/docs/examples/external.html This snippet shows the initialization of Larvitar, including setting the log level, registering an external tool, and a detailed example of loading demo files, rendering an image, and managing the image cache. It also includes functions for showing and hiding a spinner. ```javascript const spinner = document.getElementById("spinner"); function showSpinner() { spinner.style.display = "block"; } function hideSpinner() { spinner.style.display = "none"; } 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"); // set log level to debug larvitar.setLogLevel("debug"); larvitar.registerExternalTool("Test", TestTool); showSpinner(); 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(); } } function renderSerie() { larvitar.resetImageManager(); larvitar .readFiles(demoFiles) .then(seriesStack => { // render the first series of the study let seriesId = Object.keys(seriesStack)[0]; let serie = seriesStack[seriesId]; larvitar.renderImage(serie, "viewer").then(() => { hideSpinner(); larvitar.logger.debug("Image has been rendered"); larvitar.addDefaultTools("viewer"); larvitar.addTool("Test"); larvitar.setToolActive("Test"); }); // optionally cache the series larvitar.populateImageManager(seriesId, serie); larvitar.cacheImages(serie, function (resp) { if (resp.loading == 100) { let cache = larvitar.cornerstone.imageCache; larvitar.logger.debug( "Cache size: ", cache.getCacheInfo().cacheSizeInBytes / 1e6, "Mb" ); } }); }) .catch(err => larvitar.logger.error(err)); } let demoFileList = getDemoFileNames(); demoFileList.forEach(demoFile => { createFile(demoFile, renderSerie); }); ``` -------------------------------- ### Run Development Server Source: https://github.com/dvisionlab/larvitar/blob/master/CONTRIBUTING.md Command to start the development server for previewing changes. ```bash yarn run dev ``` -------------------------------- ### Check Node.js and npm Versions Source: https://github.com/dvisionlab/larvitar/blob/master/docs/guide/installation.md Verify that Node.js and npm are installed on your system by checking their respective versions. This is a prerequisite for installing Larvitar. ```bash node -v npm -v ``` -------------------------------- ### Multiframe Rendering Setup (Cypress) Source: https://github.com/dvisionlab/larvitar/blob/master/docs/api/modules/tests/cypress.md Tests the initial loading and setup of the multiframe.html page for the Larvitar DICOM viewer. It verifies viewer visibility and waits for all files to load. ```javascript it("visits the multiframe.html page", () => { cy.visit("examples/multiframe.html"); cy.get("#viewer").should("be.visible"); cy.wait(1000); }); it("waits for all files to load", () => { cy.wait(1000); }); ``` -------------------------------- ### Dynamic Script Loading and Initialization Source: https://github.com/dvisionlab/larvitar/blob/master/docs/examples/defaultTools.html Dynamically loads the Larvitar.js script based on the host environment and initializes Larvitar functionalities, including image loading, CSTools, and viewport setup. It also sets up event listeners for displaying and copying code snippets. ```javascript const script = document.createElement("script"); if (window.location.host === "larvitar.dvisionlab.com") { document.write( '