# Cornerstone3D Documentation > Cornerstone3D is a modern, high-performance JavaScript library for medical imaging, designed for building web-based medical imaging applications. It provides tools for rendering, manipulating, and analyzing medical images in various formats including DICOM. This file contains the complete documentation for Cornerstone3D, concatenated for easy reference and searching. Each section is clearly marked with its source URL. # Root Documentation ## Core Concepts Source: https://cornerstonejs.org/docs/llm/concepts #### Rendering _index.html_ ```html ``` _app.js_ ```js import { RenderingEngine, // class ORIENTATION, // constant ViewportType, // enum } from 'vtkjs-viewport'; // RENDER const renderingEngine = new RenderingEngine('ExampleRenderingEngineID'); const volumeId = 'VOLUME_ID '; const viewports = []; const viewport = { sceneUID, viewportId: 'viewportUID_0', type: ViewportType.ORTHOGRAPHIC, canvas: document.querySelector('.target-canvas'), defaultOptions: { orientation: Enums.OrientationAxis.AXIAL, background: [Math.random(), Math.random(), Math.random()], }, }; // Kick-off rendering viewports.push(viewport); renderingEngine.setViewports(viewports); // Render backgrounds renderingEngine.render(); // Create and load our image volume // See: `./examples/helpers/getImageIdsAndCacheMetadata.js` for inspiration const imageIds = [ 'wadors:https://wadoRsRoot.com/studies/studyInstanceUID/series/SeriesInstanceUID/instances/SOPInstanceUID/frames/1', 'wadors:https://wadoRsRoot.com/studies/studyInstanceUID/series/SeriesInstanceUID/instances/SOPInstanceUID/frames/2', 'wadors:https://wadoRsRoot.com/studies/studyInstanceUID/series/SeriesInstanceUID/instances/SOPInstanceUID/frames/3', ]; imageCache.makeAndCacheImageVolume(imageIds, volumeId); imageCache.loadVolume(volumeId, (event) => { if (event.framesProcessed === event.numFrames) { console.log('done loading!'); } }); // Tie scene to one or more image volumes const scene = renderingEngine.getScene(sceneUID); scene.setVolumes([ { volumeId, callback: ({ volumeActor, volumeId }) => { // Where you might setup a transfer function or PET colormap console.log('volume loaded!'); }, }, ]); const viewport = scene.getViewport(viewports[0].viewportId); // This will initialise volumes in GPU memory renderingEngine.render(); ``` For the most part, updating is as simple as using: - `RenderingEngine.setViewports` and - `Scene.setVolumes` If you're using clientside routing and/or need to clean up resources more aggressively, most constructs have a `.destroy` method. For example: ```js renderingEngine.destroy(); ``` #### Tools A tool is an uninstantiated class that implements at least the `BaseTool` interface. Tools can be configured via their constructor. To use a tool, one must: A tool is an uninstantiated class that implements at least the `BaseTool` interface. Tools can be configured via their constructor. To use a tool, one must: A tool is an uninstantiated class that implements at least the `BaseTool` interface. Tools can be configured via their constructor. To use a tool, one must: A tool is an uninstantiated class that implements at least the `BaseTool` interface. Tools can be configured via their constructor. To use a tool, one must: - Add the uninstantiated tool using the library's top level `addTool` function - Add that same tool, by name, to a ToolGroup The tool's behavior is then dependent on which rendering engines, scenes, and viewports are associated with its Tool Group; as well as the tool's current mode. #### Adding Tools The @Tools library comes packaged with several common tools. All implement either the `BaseTool` or `AnnotationTool`. Adding a tool makes it available to ToolGroups. A high level `.removeTool` also exists. ```js import * as csTools3d from '@cornerstonejs/tools'; // Add uninstantiated tool classes to the library // These will be used to initialize tool instances when we explicitly add each // tool to one or more tool groups const { PanTool, StackScrollMouseWheelTool, ZoomTool, LengthTool } = csTools3d; csTools3d.addTool(PanTool); csTools3d.addTool(StackScrollMouseWheelTool); csTools3d.addTool(ZoomTool); csTools3d.addTool(LengthTool); ``` #### Tool Group Manager Tool Groups are a way to share tool configuration, state, and modes across a set of `RengeringEngine`s, `Scene`s, and/or `Viewport`s. Tool Groups are managed by a Tool Group Manager. Tool Group Managers are used to create, search for, and destroy Tool Groups. ```js import { ToolGroupManager } from '@cornerstonejs/tools'; import { ctVolumeId } from './constants'; const toolGroupId = 'TOOL_GROUP_ID'; const sceneToolGroup = ToolGroupManager.createToolGroup(TOOL_GROUP_ID); // Add tools to ToolGroup sceneToolGroup.addTool(PanTool.toolName); sceneToolGroup.addTool(ZoomTool.toolName); sceneToolGroup.addTool(StackScrollMouseWheelTool.toolName); sceneToolGroup.addTool(LengthTool.toolName, { configuration: { volumeId: ctVolumeId }, }); ``` #### Tool Modes Tools can be in one of four modes. Each mode impacts how the tool responds to interactions. Those modes are:
| Tool Mode | Description |
| Active |
|
| Passive (default) |
|
| Enabled |
|
| Disabled |
|
| Feature | Reason |
|---|---|
| Cornerstone Modules | In CornerstoneTools these are namespaced plugins used to store tool-wide metadata in a custom manner, whilst also having initialization hooks for enabled/disabled events. They are not necessary for simple planar tools and as such will not be available in the first version. |
| Mixins | Mixins are self registering addons for tools introduced in CornerstoneTools 3.0+. We found there are more useful design patterns for making tools by composition, such as wrapping common utility functions. We intend to deprecate this feature. |
| Registered third-party content other than tools (custom manipulators, utils, etc). | We feel utils should just be wrapped up in NPM libraries and imported, and the old framework was probably too heavy for its use cases. |
| Tool Mode | Description |
| Active |
|
| Passive (default) |
|
| Enabled |
|
| Disabled |
|
| CornerstoneTools | CornerstoneTools3D | Explanation for schema change |
|---|---|---|
| N/A | renderingEngineId | The Id of the rendering engine instance driving the viewport. |
| N/A | viewportId | The Id of the viewport itself. |
|
```js
viewport: {
scale,
translation: { x, y },
voi: { windowWidth, windowCenter, windowWidth, windowCenter},
invert,
pixelReplication,
rotation,
hflip,
vflip,
modalityLUT,
voiLUT,
colormap,
labelmap,
displayedArea: {
tlhc: { x, y },
brhc: { x, y },
rowPixelSpacing,
columnPixelSpacing,
presentationSizeMode: 'NONE'
}
}
```
|
```js
camera: {
(viewUp,
viewPlaneNormal,
position,
focalPoint,
orthogonalOrPerspective,
viewAngle);
}
```
|
The viewport previously described the state in 2D, and we need additional information to uniquely define 3D views. Horizontal and vertical flipping is no longer a change to the view, but rather a transform applied to the volume actor itself in the scene. |
|
```js
// Location in 2D within the image
startPoints / lastPoints / currentPoints / deltaPoints: {
Page,
Image,
Client,
}
```
|
```js
// Location in 3D in world space
{
(CanvasCoord, WorldCoord);
}
```
|
The canvas coordinates define where on the 2D canvas the event occurred. We also give the projected world coordinate (3D) at the plane defined by the focal point and the camera normal. |