### Install Dependencies Source: https://github.com/cornerstonejs/cornerstone3d/blob/main/packages/docs/docs/getting-started/vue-angular-react-vite.md Install the necessary packages for your project. This is the first step for all framework setups. ```bash npm install # or: yarn ``` -------------------------------- ### Run Tutorial Locally via Yarn Source: https://github.com/cornerstonejs/cornerstone3d/blob/main/packages/docs/docs/tutorials/intro.md Commands to install dependencies and launch the tutorial example environment. ```bash # from the root of the library yarn install --frozen-lockfile # run the tutorial example yarn run example tutorial ``` -------------------------------- ### Run Cornerstone3D Example Locally Source: https://github.com/cornerstonejs/cornerstone3d/blob/main/packages/docs/docs/tutorials/examples.md Clone the repository, install dependencies with `--frozen-lockfile`, and run examples from the root directory using the `example` script with the example name as an argument. ```bash 1. Clone the repository 2. `yarn install --frozen-lockfile` 3. `yarn run example petct` \// this should be run from the root of the repository ``` -------------------------------- ### Full Video Rendering Example Source: https://github.com/cornerstonejs/cornerstone3d/blob/main/packages/docs/docs/tutorials/basic-video.md A complete example demonstrating how to initialize Cornerstone, set up a video viewport, load a video, and play it. This includes all necessary imports and setup. ```javascript import { init as coreInit, RenderingEngine, Enums } from '@cornerstonejs/core'; const { ViewportType } = Enums; const content = document.getElementById('content'); const element = document.createElement('div'); element.style.width = '500px'; element.style.height = '500px'; content.appendChild(element); // ============================= // /** * Runs the demo */ async function run() { await coreInit(); // Instantiate a rendering engine const renderingEngineId = 'myRenderingEngine'; const renderingEngine = new RenderingEngine(renderingEngineId); const viewportId = 'CT_AXIAL_STACK'; const viewportInput = { viewportId, element, type: ViewportType.VIDEO, }; renderingEngine.enableElement(viewportInput); const viewport = renderingEngine.getViewport(viewportId); await viewport.setVideoURL( 'https://ohif-assets.s3.us-east-2.amazonaws.com/video/rendered.mp4' ); await viewport.play(); } run(); ``` -------------------------------- ### Register New Example in example-info.json Source: https://github.com/cornerstonejs/cornerstone3d/blob/main/packages/docs/docs/contribute/playwright-tests.md Add new examples to the `examples` folder and register them in `utils/ExampleRunner/example-info.json`. This JSON structure shows how to add a new example to a category. ```json { "categories": { "tools-basic": { "description": "Tools library" }, "examplesByCategory": { "tools-basic": { "your_example_name": { "name": "Good title for your example", "description": "Good description of what your example demonstrates" } } } } } ``` -------------------------------- ### Run Segment Anything example Source: https://github.com/cornerstonejs/cornerstone3d/blob/main/packages/ai/README.md Execute the provided example command to initialize the SAM model in the browser. ```bash yarn run example segmentAnythingClientSide ``` -------------------------------- ### Build and Serve Static Examples Source: https://github.com/cornerstonejs/cornerstone3d/blob/main/packages/docs/docs/contribute/playwright-tests.md Manually build and serve static examples for development using the `bun build-and-serve-static-examples` command. This ensures the examples are available at `http://localhost:3000`, potentially speeding up development by allowing Playwright to skip the build and serve step. ```bash bun build-and-serve-static-examples ``` -------------------------------- ### Start Development Server (Angular) Source: https://github.com/cornerstonejs/cornerstone3d/blob/main/packages/docs/docs/getting-started/vue-angular-react-vite.md Starts the development server for an Angular project. Access the application at http://localhost:4200/. ```bash npm start ``` ```bash npm run dev ``` -------------------------------- ### Install Labelmap Interpolation Package Source: https://github.com/cornerstonejs/cornerstone3d/blob/main/packages/labelmap-interpolation/README.md Install the @cornerstonejs/labelmap-interpolation package using npm. ```bash npm install @cornerstonejs/labelmap-interpolation ``` -------------------------------- ### Install Cornerstone3D Core with npm Source: https://github.com/cornerstonejs/cornerstone3d/blob/main/packages/docs/docs/getting-started/installation.md Install the core Cornerstone3D package using npm. This is the foundational package for using Cornerstone3D. ```bash npm install @cornerstonejs/core ``` -------------------------------- ### VoxelManager Migration Guide Source: https://github.com/cornerstonejs/cornerstone3d/blob/main/packages/docs/docs/migration-guides/2x/3-core.md Steps and examples for migrating existing code to use the VoxelManager for accessing and manipulating volume data. ```APIDOC ## Migration to VoxelManager ### Description This section outlines the steps required to migrate your codebase from direct scalar data access to using the `VoxelManager` for improved performance and memory efficiency. ### General Migration Steps 1. **Replace Direct Scalar Data Access**: Instead of accessing `volume.getScalarData()`, use `volume.voxelManager` to interact with the data. 2. **Get Scalar Data Length**: Use `voxelManager.getScalarDataLength()` instead of `scalarData.length`. 3. **Scalar Data Manipulation**: Use `getAtIndex(index)` and `setAtIndex(index, value)` for accessing and modifying voxel data. For 3D coordinates, use `getAtIJK(i, j, k)` and `setAtIJK(i, j, k, value)`. 4. **Handling Modified Slices**: Use `voxelManager.getArrayOfModifiedSlices()` to get the list of modified slices. 5. **Iterating Over Voxels**: Use the `forEach` method for efficient iteration: ```javascript voxelManager.forEach( ({ value, index, pointIJK, pointLPS }) => { // Manipulate or process voxel data }, { boundsIJK: optionalBounds, imageData: optionalImageData, // for LPS calculations } ); ``` ### Specific Migration Scenarios #### For Volumes (IImageVolume) - Search for `getScalarData` or `scalarData` and replace with `voxelManager` access. - **Fallback (Not Recommended)**: If atomic data API is not feasible, use `voxelManager.getCompleteScalarDataArray()` or `.setCompleteScalarDataArray()` to rebuild the full scalar data array, but be aware of performance and memory concerns. #### For Stack Images (IImage) - You can still use `image.getPixelData()` or access scalar data via `image.voxelManager.getScalarData()`. ### Performance Considerations - Prefer `getAtIndex` and `setAtIndex` for bulk operations. - Use `forEach` for iterating over large portions of the volume. ### Example: Migrating a Volume Processing Function **Before:** ```javascript function processVolume(volume) { const scalarData = volume.getScalarData(); for (let i = 0; i < scalarData.length; i++) { if (scalarData[i] > 100) { scalarData[i] = 100; } } } ``` **After:** ```javascript function processVolume(volume) { const voxelManager = volume.voxelManager; const length = voxelManager.getScalarDataLength(); for (let i = 0; i < length; i++) { const value = voxelManager.getAtIndex(i); if (value > 100) { voxelManager.setAtIndex(i, 100); } } } ``` ``` -------------------------------- ### Full Stack Rendering Example Source: https://github.com/cornerstonejs/cornerstone3d/blob/main/packages/docs/docs/tutorials/basic-stack.md A complete example demonstrating the initialization, element creation, viewport enabling, image loading, and rendering of a stack of medical images. ```javascript import { RenderingEngine, Enums, init as coreInit } from '@cornerstonejs/core'; import { init as dicomImageLoaderInit } from '@cornerstonejs/dicom-image-loader'; import { createImageIdsAndCacheMetaData } from '../../../../utils/demo/helpers'; const content = document.getElementById('content'); const element = document.createElement('div'); element.style.width = '500px'; element.style.height = '500px'; content.appendChild(element); // ============================= // /** * Runs the demo */ async function run() { await coreInit(); await dicomImageLoaderInit(); // Get Cornerstone imageIds and fetch metadata into RAM const imageIds = await createImageIdsAndCacheMetaData({ StudyInstanceUID: '1.3.6.1.4.1.14519.5.2.1.7009.2403.334240657131972136850343327463', SeriesInstanceUID: '1.3.6.1.4.1.14519.5.2.1.7009.2403.226151125820845824875394858561', wadoRsRoot: 'https://d14fa38qiwhyfd.cloudfront.net/dicomweb', }); const renderingEngineId = 'myRenderingEngine'; const renderingEngine = new RenderingEngine(renderingEngineId); const viewportId = 'CT_AXIAL_STACK'; const viewportInput = { viewportId, element, type: Enums.ViewportType.STACK, }; renderingEngine.enableElement(viewportInput); const viewport = renderingEngine.getViewport(viewportId); viewport.setStack(imageIds, 60); viewport.render(); } run(); ``` -------------------------------- ### Install Node.js 20 with nvm Source: https://github.com/cornerstonejs/cornerstone3d/blob/main/packages/docs/docs/migration-guides/4x/5-node-20-upgrade.md Use Node Version Manager (nvm) to install and switch to Node.js version 20. Ensure your environment meets the minimum requirement. ```bash # Using nvm (Node Version Manager) nvm install 20 nvm use 20 ``` -------------------------------- ### Install Cornerstone3D Tools with pnpm Source: https://github.com/cornerstonejs/cornerstone3d/blob/main/packages/docs/docs/getting-started/installation.md Install the Cornerstone3D Tools package using pnpm. This adds the collection of interaction tools to your project. ```bash pnpm install @cornerstonejs/tools ``` -------------------------------- ### Test New Example with Playwright Source: https://github.com/cornerstonejs/cornerstone3d/blob/main/packages/docs/docs/contribute/playwright-tests.md Write Playwright tests for a newly added example. This snippet demonstrates how to use `visitExample` with a custom example name. ```typescript import { test } from '@playwright/test'; import { visitExample } from './utils/index'; test.beforeEach(async ({ page }) => { await visitExample(page, 'your_example_name'); }); test.describe('Your Example Name', async () => { test('should do something', async ({ page }) => { // Your test code here }); }); ``` -------------------------------- ### Install Polymorphic Segmentation Package Source: https://github.com/cornerstonejs/cornerstone3d/blob/main/packages/polymorphic-segmentation/README.md Install the package using npm. This command is used for adding the library to your project. ```bash npm install @cornerstonejs/polymorphic-segmentation ``` -------------------------------- ### Install Nifti Volume Loader with pnpm Source: https://github.com/cornerstonejs/cornerstone3d/blob/main/packages/docs/docs/getting-started/installation.md Install the NIfTI volume loader package for Cornerstone3D using pnpm. This supports loading NIfTI formatted volumes. ```bash pnpm install @cornerstonejs/nifti-volume-loader ``` -------------------------------- ### Install Dependencies with yarn Source: https://github.com/cornerstonejs/cornerstone3d/blob/main/packages/docs/docs/getting-started/vue-angular-react-vite.md Install project dependencies using yarn. This is an alternative to npm for managing project packages. ```bash yarn ``` -------------------------------- ### Install Cornerstone3D Tools with Yarn Source: https://github.com/cornerstonejs/cornerstone3d/blob/main/packages/docs/docs/getting-started/installation.md Install the Cornerstone3D Tools package using Yarn. This adds the collection of interaction tools to your project. ```bash yarn add @cornerstonejs/tools ``` -------------------------------- ### Configure Byte Range Options Source: https://github.com/cornerstonejs/cornerstone3d/blob/main/packages/docs/docs/concepts/progressive-loading/retrieve-Configuration.md Example configuration for initial byte range request with a custom chunk size. ```js { rangeIndex: 0, chunkSize: 256000, // 256kb } ``` -------------------------------- ### Install Cornerstone3D Core with pnpm Source: https://github.com/cornerstonejs/cornerstone3d/blob/main/packages/docs/docs/getting-started/installation.md Install the core Cornerstone3D package using pnpm. This command adds the foundational package to your project. ```bash pnpm install @cornerstonejs/core ``` -------------------------------- ### Install Nifti Volume Loader with npm Source: https://github.com/cornerstonejs/cornerstone3d/blob/main/packages/docs/docs/getting-started/installation.md Install the NIfTI volume loader package for Cornerstone3D using npm. This package supports loading NIfTI formatted volumes. ```bash npm install @cornerstonejs/nifti-volume-loader ``` -------------------------------- ### Install Nifti Volume Loader with Yarn Source: https://github.com/cornerstonejs/cornerstone3d/blob/main/packages/docs/docs/getting-started/installation.md Install the NIfTI volume loader package for Cornerstone3D using Yarn. This supports loading NIfTI formatted volumes. ```bash yarn add @cornerstonejs/nifti-volume-loader ``` -------------------------------- ### Install Cornerstone3D Core with Yarn Source: https://github.com/cornerstonejs/cornerstone3d/blob/main/packages/docs/docs/getting-started/installation.md Install the core Cornerstone3D package using Yarn. This command adds the foundational package to your project. ```bash yarn add @cornerstonejs/core ``` -------------------------------- ### Run Development Server (Vue) Source: https://github.com/cornerstonejs/cornerstone3d/blob/main/packages/docs/docs/getting-started/vue-angular-react-vite.md Starts the development server for a Vue project using Vite. Access the application at http://localhost:5173/. ```bash npm run dev ``` -------------------------------- ### Centralized Test Setup and Cleanup Source: https://github.com/cornerstonejs/cornerstone3d/blob/main/packages/docs/docs/migration-guides/2x/8-deverloper-experience.md Replaces scattered logic for test environment setup and teardown with a centralized utility function. Use this for cleaner and more reliable test execution. ```javascript beforeEach(function () { csTools3d.init(); csTools3d.addTool(BidirectionalTool); cache.purgeCache(); this.DOMElements = []; this.stackToolGroup = ToolGroupManager.createToolGroup('stack'); this.stackToolGroup.addTool(BidirectionalTool.toolName, { configuration: { volumeId: volumeId }, }); this.stackToolGroup.setToolActive(BidirectionalTool.toolName, { bindings: [{ mouseButton: 1 }], }); this.renderingEngine = new RenderingEngine(renderingEngineId); imageLoader.registerImageLoader('fakeImageLoader', fakeImageLoader); volumeLoader.registerVolumeLoader('fakeVolumeLoader', fakeVolumeLoader); metaData.addProvider(fakeMetaDataProvider, 10000); }); afterEach(function () { csTools3d.destroy(); cache.purgeCache(); eventTarget.reset(); this.renderingEngine.destroy(); metaData.removeProvider(fakeMetaDataProvider); imageLoader.unregisterAllImageLoaders(); ToolGroupManager.destroyToolGroup('stack'); this.DOMElements.forEach((el) => { if (el.parentNode) { el.parentNode.removeChild(el); } }); }); ``` ```javascript beforeEach(function () { const testEnv = testUtils.setupTestEnvironment({ renderingEngineId, toolGroupIds: ['default'], viewportIds: [viewportId], tools: [BidirectionalTool], toolConfigurations: { [BidirectionalTool.toolName]: { configuration: { volumeId: volumeId }, }, }, toolActivations: { [BidirectionalTool.toolName]: { bindings: [{ mouseButton: 1 }], }, }, }); renderingEngine = testEnv.renderingEngine; toolGroup = testEnv.toolGroups['default']; }); afterEach(function () { testUtils.cleanupTestEnvironment({ renderingEngineId, toolGroupIds: ['default'], }); }); ``` -------------------------------- ### Link Multiple Cornerstone Libraries Source: https://github.com/cornerstonejs/cornerstone3d/blob/main/packages/docs/docs/contribute/linking.md This example demonstrates the process of linking multiple Cornerstone libraries, such as core and tools, into the OHIF project. ```bash # In cornerstone/packages/core yarn unlink yarn link yarn dev # In cornerstone/packages/tools yarn unlink yarn link yarn dev # In OHIF yarn link @cornerstonejs/core yarn link @cornerstonejs/tools ``` -------------------------------- ### Install Cornerstone3D Tools with npm Source: https://github.com/cornerstonejs/cornerstone3d/blob/main/packages/docs/docs/getting-started/installation.md Install the Cornerstone3D Tools package using npm. This package provides a collection of tools for interacting with medical images. ```bash npm install @cornerstonejs/tools ``` -------------------------------- ### Run Development Server for Subpath (Vue) Source: https://github.com/cornerstonejs/cornerstone3d/blob/main/packages/docs/docs/getting-started/vue-angular-react-vite.md Starts the development server for a Vue project configured to run under a subpath (e.g., '/subpath/'). ```bash npm run dev:subpath ``` -------------------------------- ### Configure tool bindings for touch Source: https://github.com/cornerstonejs/cornerstone3d/blob/main/packages/docs/docs/concepts/cornerstone-tools/touch.md Setup tool groups and define active tools with specific touch point bindings. ```js // Add tools to Cornerstone3D cornerstoneTools.addTool(PanTool); cornerstoneTools.addTool(WindowLevelTool); cornerstoneTools.addTool(StackScrollTool); cornerstoneTools.addTool(ZoomTool); // Define a tool group, which defines how mouse events map to tool commands for // Any viewport using the group const toolGroup = ToolGroupManager.createToolGroup(toolGroupId); // Add tools to the tool group toolGroup.addTool(WindowLevelTool.toolName); toolGroup.addTool(PanTool.toolName); toolGroup.addTool(ZoomTool.toolName); toolGroup.addTool(StackScrollTool.toolName); // Set the initial state of the tools, here all tools are active and bound to // Different touch inputs // 5 touch points are possible => unlimited touch points are supported, but is generally limited by hardware. toolGroup.setToolActive(ZoomTool.toolName, { bindings: [{ numTouchPoints: 2 }], }); toolGroup.setToolActive(StackScrollTool.toolName, { bindings: [{ numTouchPoints: 3 }], }); toolGroup.setToolActive(WindowLevelTool.toolName, { bindings: [ { mouseButton: MouseBindings.Primary, // special condition for one finger touch }, ], }); ``` -------------------------------- ### Configure Byte Range with Decode Level Source: https://github.com/cornerstonejs/cornerstone3d/blob/main/packages/docs/docs/concepts/progressive-loading/retrieve-Configuration.md Example configuration for byte range request specifying a manual decode level. ```js { rangeIndex: 0, decodeLevel: 3 } // chunkSize is default 64kb ``` -------------------------------- ### Test Existing Example with Playwright Source: https://github.com/cornerstonejs/cornerstone3d/blob/main/packages/docs/docs/contribute/playwright-tests.md Use this snippet to write Playwright tests against an existing example. Ensure the example name is correctly referenced. ```typescript import { test } from '@playwright/test'; import { visitExample } from './utils/index'; test.beforeEach(async ({ page }) => { await visitExample(page, 'annotationToolModes'); }); test.describe('Annotation Tool Modes', async () => { test('should do something', async ({ page }) => { // Your test code here }); }); ``` -------------------------------- ### Run Documentation Server Source: https://github.com/cornerstonejs/cornerstone3d/blob/main/packages/docs/docs/contribute/documentation.md Navigate to the docs package and run the start script to launch the documentation server on port 3000. The first run may require `yarn docs:dev` to build necessary files. ```sh cd packages/docs/ yarn run start ``` ```sh yarn docs:dev ``` ```sh yarn docs ``` -------------------------------- ### Instantiating a RenderingEngine Source: https://github.com/cornerstonejs/cornerstone3d/blob/main/packages/docs/docs/concepts/cornerstone-core/renderingEngine.md Shows how to create a new instance of the RenderingEngine, which is responsible for managing viewports and rendering. ```APIDOC ## Instantiating a RenderingEngine ### Description Creates a new `RenderingEngine` instance. This engine will manage all viewports and their rendering processes. ### Method `new RenderingEngine(renderingEngineId)` ### Parameters #### Path Parameters - **renderingEngineId** (string) - Required - A unique identifier for this rendering engine instance. ### Request Example ```js import { RenderingEngine } from '@cornerstonejs/core'; const renderingEngineId = 'myEngine'; const renderingEngine = new RenderingEngine(renderingEngineId); ``` ``` -------------------------------- ### Load NIFTI Volume (Before) Source: https://github.com/cornerstonejs/cornerstone3d/blob/main/packages/docs/docs/migration-guides/2x/7-nifti-volume-loader.md Demonstrates the previous method of loading a NIFTI volume using `createAndCacheVolume` and setting it for viewports. ```javascript const niftiURL = 'https://ohif-assets.s3.us-east-2.amazonaws.com/nifti/MRHead.nii.gz'; const volumeId = 'nifti:' + niftiURL; const volume = await volumeLoader.createAndCacheVolume(volumeId); setVolumesForViewports( renderingEngine, [{ volumeId }], viewportInputArray.map((v) => v.viewportId) ); ``` -------------------------------- ### Install PolySeg Dependency Source: https://github.com/cornerstonejs/cornerstone3d/blob/main/packages/docs/docs/getting-started/vue-angular-react-vite.md Install the '@cornerstonejs/polymorphic-segmentation' package if you need to use PolySeg for converting segmentation representations. ```bash yarn add @cornerstonejs/polymorphic-segmentation ``` -------------------------------- ### Setup CornerstoneDICOMImageLoader and Event Listeners Source: https://github.com/cornerstonejs/cornerstone3d/blob/main/packages/dicomImageLoader/examplesOld/dicomfile/index.html Initializes the cornerstoneDICOMImageLoader, sets up drag-and-drop listeners for file selection, and configures the loader with optional beforeSend callbacks. This code should be run before any file loading occurs. ```javascript window.cornerstoneDICOMImageLoader || document.write('