2019-12-06 22:31:46 +01:00
# Module: Viewport
2021-06-15 17:15:29 +02:00
## Overview
Viewports consume a displaySet and display/allow the user to interact with data. An extension can register a Viewport Module by defining a `getViewportModule`
2019-12-09 07:02:02 +01:00
method that returns a React component. Currently, we use viewport components to
add support for:
- 2D Medical Image Viewing (cornerstone ext.)
2021-06-15 17:15:29 +02:00
- Structured Reports as SR (DICOM SR ext.)
- Structured Reports as HTML (DICOM html ext.)
- Encapsulated PDFs as PDFs (DICOM pdf ext.)
2019-12-09 07:02:02 +01:00
- Whole Slide Microscopy Viewing (whole slide ext.)
- etc.
2021-06-15 17:15:29 +02:00
The general pattern is that a mode can define which `Viewport` to use for which specific
`SOPClassHandlerUID` , so if you want to fork just a single Viewport component for a specialized mode, this is possible.
```JSX
// displaySet, viewportIndex, dataSource
const getViewportModule = () => {
const wrappedViewport = props => {
return (
< ExampleViewport
{...props}
onEvent={data => {
commandsManager.runCommand('commandName', data);
}}
/>
);
};
return [{ name: 'example', component: wrappedViewport }];
};
```
## Example Viewport Component
A simplified version of the tracked CornerstoneViewport is shown below, which creates
a cornerstone viewport and and action bar on top of it.
```JSX
function TrackedCornerstoneViewport({
children,
dataSource,
displaySet,
viewportIndex,
servicesManager,
extensionManager,
commandsManager,
}) {
const renderViewport = () => {
const { component: Component } = extensionManager.getModuleEntry(
'org.ohif.cornerstone.viewportModule.cornerstone'
)
return (
< Component
onElementEnabled={onElementEnabled}
element={element}
{...props}
>< / Component >
)
}
return (
< >
< ViewportActionBar onDoubleClick onSeriesChange / >
< div className = "relative flex flex-row w-full h-full overflow-hidden" >
{renderViewport()}
< / div >
< />
)
}
2019-12-09 07:02:02 +01:00
2019-12-06 22:31:46 +01:00
```
2019-12-09 07:02:02 +01:00
2021-06-15 17:15:29 +02:00

2019-12-09 07:02:02 +01:00
### `@ohif/viewer`
2019-12-06 22:31:46 +01:00
Viewport components are managed by the `ViewportGrid` Component. Which Viewport
component is used depends on:
2021-06-15 17:15:29 +02:00
- Hanging Protocols
2019-12-06 22:31:46 +01:00
- The Layout Configuration
- Registered SopClassHandlers
2021-06-15 17:15:29 +02:00

2019-12-09 07:02:02 +01:00
< center > < i > An example of three cornerstone Viewports< / i > < / center >