feat(actions): simplify action corner api through the toolbarService (#5033)
This commit is contained in:
1 parent
f71b88e639
commit
7c15bb8901
246 files changed
+7930
-4270
No files matched your search
+116
@@ -0,0 +1,116 @@
|
||||
import { useToolbar, useViewportMousePosition } from '@ohif/core/src/hooks';
|
||||
import React, { useState, useEffect, useRef } from 'react';
|
||||
import { useViewportRendering } from '../../hooks';
|
||||
|
||||
function AdvancedRenderingControls({
|
||||
viewportId,
|
||||
location,
|
||||
buttonSection,
|
||||
}: {
|
||||
viewportId: string;
|
||||
location: number;
|
||||
buttonSection: string;
|
||||
}) {
|
||||
const {
|
||||
onInteraction,
|
||||
toolbarButtons,
|
||||
isItemOpen,
|
||||
isItemLocked,
|
||||
openItem,
|
||||
closeItem,
|
||||
toggleLock,
|
||||
} = useToolbar({
|
||||
buttonSection,
|
||||
});
|
||||
|
||||
const mousePosition = useViewportMousePosition(viewportId);
|
||||
const [isAtBottom, setIsAtBottom] = useState(false);
|
||||
const [showAllIcons, setShowAllIcons] = useState(true);
|
||||
const firstMountRef = useRef(true);
|
||||
const { hasColorbar } = useViewportRendering(viewportId);
|
||||
|
||||
useEffect(() => {
|
||||
if (firstMountRef.current) {
|
||||
firstMountRef.current = false;
|
||||
|
||||
const timer = setTimeout(() => {
|
||||
setShowAllIcons(false);
|
||||
}, 3000);
|
||||
|
||||
return () => clearTimeout(timer);
|
||||
}
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
if (!showAllIcons && mousePosition.isInViewport) {
|
||||
if (mousePosition.isInBottomPercentage(10)) {
|
||||
setIsAtBottom(true);
|
||||
} else {
|
||||
setIsAtBottom(false);
|
||||
}
|
||||
}
|
||||
}, [mousePosition, showAllIcons]);
|
||||
|
||||
if (!toolbarButtons?.length) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!hasColorbar) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="flex flex-row gap-2">
|
||||
{toolbarButtons.map(toolDef => {
|
||||
if (!toolDef) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const { id, Component, componentProps } = toolDef;
|
||||
|
||||
// Enhanced props with state and actions - respecting viewport specificity
|
||||
const enhancedProps = {
|
||||
...componentProps,
|
||||
isOpen: isItemOpen(id, viewportId),
|
||||
isLocked: isItemLocked(id, viewportId),
|
||||
onOpen: () => openItem(id, viewportId),
|
||||
onClose: () => closeItem(id, viewportId),
|
||||
onToggleLock: () => toggleLock(id, viewportId),
|
||||
viewportId,
|
||||
};
|
||||
|
||||
const tool = (
|
||||
<Component
|
||||
key={id}
|
||||
id={id}
|
||||
location={location}
|
||||
onInteraction={args => {
|
||||
onInteraction({
|
||||
...args,
|
||||
itemId: id,
|
||||
viewportId,
|
||||
});
|
||||
}}
|
||||
{...enhancedProps}
|
||||
/>
|
||||
);
|
||||
|
||||
// Always show all icons on first mount for 3 seconds
|
||||
// After that, always show Colorbar, show others only when mouse is at bottom
|
||||
const shouldBeVisible = showAllIcons || id === 'Colorbar' || isAtBottom;
|
||||
|
||||
return (
|
||||
<div
|
||||
key={id}
|
||||
className={shouldBeVisible ? 'opacity-100' : 'pointer-events-none opacity-0'}
|
||||
style={{ transition: 'opacity 0.2s ease-in-out' }}
|
||||
>
|
||||
{tool}
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default AdvancedRenderingControls;
|
||||
@@ -0,0 +1 @@
|
||||
export { default } from './AdvancedRenderingControls';
|
||||
@@ -0,0 +1,168 @@
|
||||
import React, { useMemo, useState, useEffect } from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { ViewportActionButton } from '@ohif/ui-next';
|
||||
import { Icons, Tooltip, TooltipTrigger, TooltipContent } from '@ohif/ui-next';
|
||||
import { useSystem } from '@ohif/core/src';
|
||||
import { useViewportDisplaySets } from '../../hooks/useViewportDisplaySets';
|
||||
import { useMeasurementTracking } from '../../hooks/useMeasurementTracking';
|
||||
|
||||
/**
|
||||
* ModalityLoadBadge displays the status and actionable buttons for viewports containing
|
||||
* special displaySets (SR, SEG, RTSTRUCT) or when tracking measurements
|
||||
*/
|
||||
function ModalityLoadBadge({ viewportId }: { viewportId: string }) {
|
||||
const { commandsManager } = useSystem();
|
||||
const { t } = useTranslation('Common');
|
||||
const loadStr = t('LOAD');
|
||||
|
||||
const { isTracked, isLocked } = useMeasurementTracking({ viewportId });
|
||||
|
||||
const { backgroundDisplaySet, overlayDisplaySets } = useViewportDisplaySets(viewportId);
|
||||
|
||||
const [specialDisplaySet, setSpecialDisplaySet] = useState(null);
|
||||
|
||||
const allDisplaySets = useMemo(() => {
|
||||
return [backgroundDisplaySet, ...overlayDisplaySets].filter(Boolean);
|
||||
}, [backgroundDisplaySet, overlayDisplaySets]);
|
||||
|
||||
useEffect(() => {
|
||||
const displaySet = allDisplaySets.find(ds => ds.isOverlayDisplaySet || ds?.Modality === 'SR');
|
||||
|
||||
setSpecialDisplaySet(displaySet || null);
|
||||
}, [allDisplaySets]);
|
||||
|
||||
const statusInfo = useMemo(() => {
|
||||
if (isTracked && !specialDisplaySet) {
|
||||
return {
|
||||
type: 'SR',
|
||||
isHydrated: true,
|
||||
isTracked,
|
||||
displaySet: null,
|
||||
tooltip: 'Currently tracking measurements in this viewport',
|
||||
};
|
||||
}
|
||||
|
||||
if (!specialDisplaySet) {
|
||||
return {
|
||||
type: null,
|
||||
};
|
||||
}
|
||||
|
||||
const type = specialDisplaySet.Modality;
|
||||
const isHydrated = specialDisplaySet.isHydrated || false;
|
||||
let tooltip = null;
|
||||
const isRehydratable = specialDisplaySet.isRehydratable || false;
|
||||
|
||||
if (type === 'SEG') {
|
||||
tooltip = isHydrated
|
||||
? 'This Segmentation is loaded in the segmentation panel'
|
||||
: 'Click LOAD to load segmentation.';
|
||||
} else if (type === 'RTSTRUCT') {
|
||||
tooltip = isHydrated
|
||||
? 'This RTSTRUCT is loaded in the segmentation panel'
|
||||
: 'Click LOAD to load RTSTRUCT.';
|
||||
} else if (type === 'SR') {
|
||||
if (!isRehydratable) {
|
||||
tooltip = 'This structured report is not compatible with this application.';
|
||||
} else if (isRehydratable && isLocked) {
|
||||
tooltip =
|
||||
'This structured report is currently read-only because you are tracking measurements in another viewport.';
|
||||
} else {
|
||||
tooltip = `Click ${loadStr} to restore measurements.`;
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
type,
|
||||
isHydrated,
|
||||
displaySet: specialDisplaySet,
|
||||
isRehydratable,
|
||||
tooltip,
|
||||
};
|
||||
}, [specialDisplaySet, loadStr, isLocked, isTracked]);
|
||||
|
||||
// Nothing to show if there's no special display set type or tracking
|
||||
if (!statusInfo.type && !isTracked) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const StatusIcon = () => {
|
||||
if (statusInfo.type === 'SR') {
|
||||
if (statusInfo.isRehydratable && !isLocked) {
|
||||
return (
|
||||
<Icons.ByName
|
||||
className="text-muted-foreground h-4 w-4"
|
||||
name="status-untracked"
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
if (statusInfo.isRehydratable && isLocked) {
|
||||
return (
|
||||
<Icons.ByName
|
||||
name="status-locked"
|
||||
className="h-4 w-4"
|
||||
/>
|
||||
);
|
||||
} else {
|
||||
return (
|
||||
<Icons.ByName
|
||||
name="status-alert"
|
||||
className="h-4 w-4"
|
||||
/>
|
||||
);
|
||||
}
|
||||
} else {
|
||||
return <Icons.StatusUntracked className="h-4 w-4" />;
|
||||
}
|
||||
};
|
||||
|
||||
const StatusArea = () => {
|
||||
if (!statusInfo.isHydrated) {
|
||||
return (
|
||||
<div className="flex h-6 cursor-default text-sm leading-6 text-white">
|
||||
<div className="bg-customgray-100 flex min-w-[45px] items-center rounded-l-xl rounded-r p-1">
|
||||
<StatusIcon />
|
||||
<span className="ml-1">{statusInfo.type}</span>
|
||||
</div>
|
||||
{/* We don't show the load button for SRs because we handle it in the SR extension
|
||||
via the tracked measurement context that works with state machine, this is not a regression right now */}
|
||||
{statusInfo.type !== 'SR' && (
|
||||
<ViewportActionButton
|
||||
onInteraction={() => {
|
||||
commandsManager.runCommand('hydrateSecondaryDisplaySet', {
|
||||
displaySet: statusInfo.displaySet,
|
||||
viewportId,
|
||||
});
|
||||
}}
|
||||
>
|
||||
{loadStr}
|
||||
</ViewportActionButton>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
return null;
|
||||
};
|
||||
|
||||
return (
|
||||
<>
|
||||
{statusInfo.tooltip && (
|
||||
<Tooltip>
|
||||
<TooltipTrigger asChild>
|
||||
<span>
|
||||
<StatusArea />
|
||||
</span>
|
||||
</TooltipTrigger>
|
||||
<TooltipContent side="bottom">
|
||||
<div>{statusInfo.tooltip}</div>
|
||||
</TooltipContent>
|
||||
</Tooltip>
|
||||
)}
|
||||
{!statusInfo.tooltip && <StatusArea />}
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
export default ModalityLoadBadge;
|
||||
@@ -0,0 +1 @@
|
||||
export { default } from './ModalityLoadBadge';
|
||||
@@ -0,0 +1,151 @@
|
||||
import React, { useCallback, useState } from 'react';
|
||||
import { ViewportActionArrows } from '@ohif/ui-next';
|
||||
import { useSystem } from '@ohif/core/src';
|
||||
import { utils } from '../..';
|
||||
import { useViewportSegmentations } from '../../hooks';
|
||||
import { useMeasurementTracking } from '../../hooks/useMeasurementTracking';
|
||||
import { useViewportDisplaySets } from '../../hooks/useViewportDisplaySets';
|
||||
|
||||
/**
|
||||
* NavigationComponent provides navigation controls for viewports containing
|
||||
* special displaySets (SR, SEG, RTSTRUCT) to navigate between segments or measurements
|
||||
*/
|
||||
function NavigationComponent({ viewportId }: { viewportId: string }) {
|
||||
const { servicesManager } = useSystem();
|
||||
const { segmentationService, cornerstoneViewportService, measurementService } =
|
||||
servicesManager.services;
|
||||
|
||||
// Get tracking information
|
||||
const { isTracked, trackedMeasurementUIDs } = useMeasurementTracking({ viewportId });
|
||||
const { viewportDisplaySets } = useViewportDisplaySets(viewportId);
|
||||
const [measurementSelected, setMeasurementSelected] = useState(0);
|
||||
const isSRDisplaySet = viewportDisplaySets.some(displaySet => displaySet?.Modality === 'SR');
|
||||
const cornerstoneViewport = cornerstoneViewportService.getCornerstoneViewport(viewportId);
|
||||
|
||||
// Get segmentation information
|
||||
const { segmentationsWithRepresentations } = useViewportSegmentations({
|
||||
viewportId,
|
||||
});
|
||||
|
||||
const hasSegmentations = segmentationsWithRepresentations.length > 0;
|
||||
|
||||
// prefer segment navigation if available
|
||||
const navigationMode = hasSegmentations
|
||||
? 'segment'
|
||||
: isSRDisplaySet
|
||||
? 'measurement'
|
||||
: isTracked
|
||||
? 'measurement'
|
||||
: null;
|
||||
|
||||
const handleMeasurementNavigation = useCallback(
|
||||
(direction: number) => {
|
||||
const measurementDisplaySet = viewportDisplaySets.find(
|
||||
displaySet => displaySet?.Modality === 'SR'
|
||||
);
|
||||
|
||||
if (measurementDisplaySet) {
|
||||
const measurements = measurementDisplaySet.measurements;
|
||||
if (measurements.length <= 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
const newIndex = getNextIndex(measurementSelected, direction, measurements.length);
|
||||
setMeasurementSelected(newIndex);
|
||||
|
||||
const measurement = measurements[newIndex];
|
||||
cornerstoneViewport.setViewReference({
|
||||
referencedImageId: measurement.imageId,
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
if (isTracked && trackedMeasurementUIDs.length > 0) {
|
||||
const newIndex = getNextIndex(
|
||||
measurementSelected,
|
||||
direction,
|
||||
trackedMeasurementUIDs.length
|
||||
);
|
||||
setMeasurementSelected(newIndex);
|
||||
measurementService.jumpToMeasurement(viewportId, trackedMeasurementUIDs[newIndex]);
|
||||
}
|
||||
},
|
||||
[
|
||||
viewportId,
|
||||
cornerstoneViewport,
|
||||
measurementSelected,
|
||||
measurementService,
|
||||
isTracked,
|
||||
trackedMeasurementUIDs,
|
||||
viewportDisplaySets,
|
||||
]
|
||||
);
|
||||
|
||||
const handleSegmentNavigation = useCallback(
|
||||
(direction: number) => {
|
||||
if (!segmentationsWithRepresentations.length) {
|
||||
return;
|
||||
}
|
||||
|
||||
const segmentationId = segmentationsWithRepresentations[0].segmentation.segmentationId;
|
||||
|
||||
utils.handleSegmentChange({
|
||||
direction,
|
||||
segmentationId,
|
||||
viewportId,
|
||||
selectedSegmentObjectIndex: 0,
|
||||
segmentationService,
|
||||
});
|
||||
},
|
||||
[segmentationsWithRepresentations, viewportId, segmentationService]
|
||||
);
|
||||
|
||||
// Handle navigation between segments/measurements
|
||||
const handleNavigate = useCallback(
|
||||
(direction: number) => {
|
||||
if (navigationMode === 'segment') {
|
||||
handleSegmentNavigation(direction);
|
||||
} else if (navigationMode === 'measurement') {
|
||||
handleMeasurementNavigation(direction);
|
||||
}
|
||||
},
|
||||
[navigationMode, handleSegmentNavigation, handleMeasurementNavigation]
|
||||
);
|
||||
|
||||
// Only render if we have a navigation mode
|
||||
if (!navigationMode) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (
|
||||
<ViewportActionArrows
|
||||
onArrowsClick={handleNavigate}
|
||||
className="h-6"
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate the next index with circular navigation support
|
||||
* @param currentIndex Current index position
|
||||
* @param direction Direction of movement (1 for next, -1 for previous)
|
||||
* @param totalItems Total number of items to navigate through
|
||||
* @returns The next index with wrap-around support
|
||||
*/
|
||||
function getNextIndex(currentIndex: number, direction: number, totalItems: number): number {
|
||||
if (totalItems <= 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Use modulo to handle circular navigation
|
||||
let nextIndex = (currentIndex + direction) % totalItems;
|
||||
|
||||
// Handle negative index when going backwards from index 0
|
||||
if (nextIndex < 0) {
|
||||
nextIndex = totalItems - 1;
|
||||
}
|
||||
|
||||
return nextIndex;
|
||||
}
|
||||
|
||||
export default NavigationComponent;
|
||||
@@ -0,0 +1,3 @@
|
||||
import NavigationComponent from './NavigationComponent';
|
||||
|
||||
export default NavigationComponent;
|
||||
@@ -1,55 +1,94 @@
|
||||
import React from 'react';
|
||||
import {
|
||||
useViewportActionCorners,
|
||||
ViewportActionCorners,
|
||||
ViewportActionCornersLocations,
|
||||
} from '@ohif/ui-next';
|
||||
import React, { memo } from 'react';
|
||||
import { ViewportActionCorners, IconPresentationProvider, ToolButton } from '@ohif/ui-next';
|
||||
import { Toolbar } from '@ohif/extension-default/src/Toolbar/Toolbar';
|
||||
import { ButtonLocation } from '@ohif/core/src/services/ToolBarService/ToolbarService';
|
||||
import { useViewportHover } from '../hooks';
|
||||
|
||||
export type OHIFViewportActionCornersProps = {
|
||||
viewportId: string;
|
||||
};
|
||||
|
||||
function OHIFViewportActionCorners({ viewportId }: OHIFViewportActionCornersProps) {
|
||||
const [state] = useViewportActionCorners();
|
||||
function OHIFViewportActionCornersComponent({ viewportId }: OHIFViewportActionCornersProps) {
|
||||
// Use the viewport hover hook to track if viewport is hovered or active
|
||||
const { isHovered, isActive } = useViewportHover(viewportId);
|
||||
|
||||
if (!state.viewports[viewportId]) {
|
||||
const shouldShowCorners = isHovered || isActive;
|
||||
|
||||
if (!shouldShowCorners) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const components = state.viewports[viewportId];
|
||||
|
||||
const renderCorner = (location: ViewportActionCornersLocations, CornerComponent) => {
|
||||
const cornerComponents = components[location];
|
||||
if (!cornerComponents?.length) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (
|
||||
<CornerComponent>
|
||||
{cornerComponents
|
||||
.filter(componentInfo => componentInfo.isVisible !== false)
|
||||
.map(componentInfo => (
|
||||
<div
|
||||
key={componentInfo.id}
|
||||
className={
|
||||
componentInfo.isLocked === true ? 'pointer-events-none opacity-50' : undefined
|
||||
}
|
||||
>
|
||||
{componentInfo.component}
|
||||
</div>
|
||||
))}
|
||||
</CornerComponent>
|
||||
);
|
||||
};
|
||||
|
||||
return (
|
||||
<ViewportActionCorners.Container>
|
||||
{renderCorner(ViewportActionCornersLocations.topLeft, ViewportActionCorners.TopLeft)}
|
||||
{renderCorner(ViewportActionCornersLocations.topRight, ViewportActionCorners.TopRight)}
|
||||
{renderCorner(ViewportActionCornersLocations.bottomLeft, ViewportActionCorners.BottomLeft)}
|
||||
{renderCorner(ViewportActionCornersLocations.bottomRight, ViewportActionCorners.BottomRight)}
|
||||
</ViewportActionCorners.Container>
|
||||
<IconPresentationProvider
|
||||
size="medium"
|
||||
IconContainer={ToolButton}
|
||||
containerProps={{
|
||||
size: 'tiny',
|
||||
className: 'font-normal text-primary hover:bg-primary/25',
|
||||
}}
|
||||
>
|
||||
<ViewportActionCorners.Container>
|
||||
<ViewportActionCorners.TopLeft>
|
||||
<Toolbar
|
||||
buttonSection="viewportActionMenu.topLeft"
|
||||
viewportId={viewportId}
|
||||
location={ButtonLocation.TopLeft}
|
||||
/>
|
||||
</ViewportActionCorners.TopLeft>
|
||||
<ViewportActionCorners.TopMiddle>
|
||||
<Toolbar
|
||||
buttonSection="viewportActionMenu.topMiddle"
|
||||
viewportId={viewportId}
|
||||
location={ButtonLocation.TopMiddle}
|
||||
/>
|
||||
</ViewportActionCorners.TopMiddle>
|
||||
<ViewportActionCorners.TopRight>
|
||||
<Toolbar
|
||||
buttonSection="viewportActionMenu.topRight"
|
||||
viewportId={viewportId}
|
||||
location={ButtonLocation.TopRight}
|
||||
/>
|
||||
</ViewportActionCorners.TopRight>
|
||||
<ViewportActionCorners.LeftMiddle>
|
||||
<Toolbar
|
||||
buttonSection="viewportActionMenu.leftMiddle"
|
||||
viewportId={viewportId}
|
||||
location={ButtonLocation.LeftMiddle}
|
||||
/>
|
||||
</ViewportActionCorners.LeftMiddle>
|
||||
<ViewportActionCorners.RightMiddle>
|
||||
<Toolbar
|
||||
buttonSection="viewportActionMenu.rightMiddle"
|
||||
viewportId={viewportId}
|
||||
location={ButtonLocation.RightMiddle}
|
||||
/>
|
||||
</ViewportActionCorners.RightMiddle>
|
||||
<ViewportActionCorners.BottomLeft>
|
||||
<Toolbar
|
||||
buttonSection="viewportActionMenu.bottomLeft"
|
||||
viewportId={viewportId}
|
||||
location={ButtonLocation.BottomLeft}
|
||||
/>
|
||||
</ViewportActionCorners.BottomLeft>
|
||||
<ViewportActionCorners.BottomMiddle>
|
||||
<Toolbar
|
||||
buttonSection="viewportActionMenu.bottomMiddle"
|
||||
viewportId={viewportId}
|
||||
location={ButtonLocation.BottomMiddle}
|
||||
/>
|
||||
</ViewportActionCorners.BottomMiddle>
|
||||
<ViewportActionCorners.BottomRight>
|
||||
<Toolbar
|
||||
buttonSection="viewportActionMenu.bottomRight"
|
||||
viewportId={viewportId}
|
||||
location={ButtonLocation.BottomRight}
|
||||
/>
|
||||
</ViewportActionCorners.BottomRight>
|
||||
</ViewportActionCorners.Container>
|
||||
</IconPresentationProvider>
|
||||
);
|
||||
}
|
||||
|
||||
const OHIFViewportActionCorners = memo(OHIFViewportActionCornersComponent);
|
||||
|
||||
export default OHIFViewportActionCorners;
|
||||
@@ -0,0 +1,54 @@
|
||||
import React from 'react';
|
||||
import { Numeric } from '@ohif/ui-next';
|
||||
import { useViewportDisplaySets, useViewportRendering } from '../../hooks';
|
||||
|
||||
interface OpacityMenuProps {
|
||||
viewportId: string;
|
||||
className?: string;
|
||||
}
|
||||
|
||||
function OpacityMenu({ viewportId, className }: OpacityMenuProps) {
|
||||
const { backgroundDisplaySet, foregroundDisplaySets } = useViewportDisplaySets(viewportId, {
|
||||
includeForeground: true,
|
||||
includeBackground: true,
|
||||
});
|
||||
const { opacityLinear, setOpacityLinear } = useViewportRendering(viewportId, {
|
||||
displaySetInstanceUID: foregroundDisplaySets[0].displaySetInstanceUID,
|
||||
});
|
||||
|
||||
const opacityValue = opacityLinear !== undefined ? opacityLinear : 0;
|
||||
const backgroundModality = backgroundDisplaySet?.Modality || '';
|
||||
const foregroundModality = foregroundDisplaySets[0]?.Modality || '';
|
||||
|
||||
return (
|
||||
<div className={className}>
|
||||
<div className="bg-popover w-72 rounded-lg p-3">
|
||||
<div className="mb-2 flex items-center justify-center">
|
||||
<span className="text-muted-foreground text-base">Opacity</span>
|
||||
</div>
|
||||
<div className="">
|
||||
<Numeric.Container
|
||||
mode="singleRange"
|
||||
value={opacityValue}
|
||||
onChange={(val: number | [number, number]) => {
|
||||
if (typeof val === 'number') {
|
||||
setOpacityLinear(val);
|
||||
}
|
||||
}}
|
||||
min={0}
|
||||
max={1}
|
||||
step={0.0001}
|
||||
>
|
||||
<div className="flex items-center">
|
||||
<span className="text-foreground mr-2 text-sm">{backgroundModality}</span>
|
||||
<Numeric.SingleRange showNumberInput={false} />
|
||||
<span className="text-foreground ml-2 text-sm">{foregroundModality}</span>
|
||||
</div>
|
||||
</Numeric.Container>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default OpacityMenu;
|
||||
@@ -0,0 +1,85 @@
|
||||
import React, { ReactNode } from 'react';
|
||||
import { useSystem } from '@ohif/core';
|
||||
import {
|
||||
Button,
|
||||
Icons,
|
||||
Popover,
|
||||
PopoverContent,
|
||||
PopoverTrigger,
|
||||
useIconPresentation,
|
||||
} from '@ohif/ui-next';
|
||||
import OpacityMenu from './OpacityMenu';
|
||||
|
||||
type OpacityMenuWrapperProps = {
|
||||
viewportId: string;
|
||||
location: string;
|
||||
isOpen?: boolean;
|
||||
onOpen?: () => void;
|
||||
onClose?: () => void;
|
||||
disabled?: boolean;
|
||||
};
|
||||
|
||||
export function OpacityMenuWrapper(props: OpacityMenuWrapperProps): ReactNode {
|
||||
const { viewportId, location, isOpen = false, onOpen, onClose, disabled, ...rest } = props;
|
||||
const { IconContainer, className: iconClassName, containerProps } = useIconPresentation();
|
||||
|
||||
const handleOpenChange = (openState: boolean) => {
|
||||
if (openState) {
|
||||
onOpen?.();
|
||||
} else {
|
||||
onClose?.();
|
||||
}
|
||||
};
|
||||
|
||||
const { servicesManager } = useSystem();
|
||||
const { toolbarService } = servicesManager.services;
|
||||
|
||||
const { align, side } = toolbarService.getAlignAndSide(location);
|
||||
|
||||
const Icon = <Icons.Opacity className={iconClassName} />;
|
||||
|
||||
return (
|
||||
<Popover
|
||||
open={isOpen}
|
||||
onOpenChange={handleOpenChange}
|
||||
>
|
||||
<PopoverTrigger
|
||||
asChild
|
||||
className="flex items-center justify-center"
|
||||
>
|
||||
<div>
|
||||
{IconContainer ? (
|
||||
<IconContainer
|
||||
disabled={disabled}
|
||||
icon="Opacity"
|
||||
{...rest}
|
||||
{...containerProps}
|
||||
>
|
||||
{Icon}
|
||||
</IconContainer>
|
||||
) : (
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
disabled={disabled}
|
||||
>
|
||||
{Icon}
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
</PopoverTrigger>
|
||||
<PopoverContent
|
||||
className="border-none bg-transparent p-0 shadow-none"
|
||||
side={side}
|
||||
align={align}
|
||||
alignOffset={0}
|
||||
sideOffset={5}
|
||||
>
|
||||
<OpacityMenu
|
||||
className="w-full"
|
||||
viewportId={viewportId}
|
||||
/>
|
||||
</PopoverContent>
|
||||
</Popover>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
export { OpacityMenuWrapper } from './OpacityMenuWrapper';
|
||||
export { default as OpacityMenu } from './OpacityMenu';
|
||||
@@ -0,0 +1,21 @@
|
||||
import React from 'react';
|
||||
|
||||
// should be used in a Select component
|
||||
const SelectItemWithModality = ({
|
||||
displaySet,
|
||||
showModality = true,
|
||||
}: {
|
||||
displaySet: AppTypes.DisplaySet;
|
||||
showModality?: boolean;
|
||||
}): JSX.Element => (
|
||||
<div className="flex w-[90%] items-center justify-between">
|
||||
<span className="text-foreground truncate text-base">{displaySet.label}</span>
|
||||
{showModality && displaySet.Modality && (
|
||||
<span className="text-muted-foreground flex-shrink-0 whitespace-nowrap text-xs">
|
||||
{displaySet.Modality}
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
|
||||
export default SelectItemWithModality;
|
||||
@@ -0,0 +1,104 @@
|
||||
import React, { useState, useEffect } from 'react';
|
||||
import {
|
||||
Numeric,
|
||||
Select,
|
||||
SelectTrigger,
|
||||
SelectValue,
|
||||
SelectContent,
|
||||
SelectItem,
|
||||
Button,
|
||||
} from '@ohif/ui-next';
|
||||
import { useViewportRendering } from '../../hooks';
|
||||
import { useViewportDisplaySets } from '../../hooks/useViewportDisplaySets';
|
||||
import SelectItemWithModality from '../SelectItemWithModality';
|
||||
|
||||
interface ThresholdMenuProps {
|
||||
viewportId: string;
|
||||
className?: string;
|
||||
}
|
||||
|
||||
function ThresholdMenu({ viewportId, className }: ThresholdMenuProps) {
|
||||
const { viewportDisplaySets, foregroundDisplaySets } = useViewportDisplaySets(viewportId);
|
||||
const [selectedDisplaySetUID, setSelectedDisplaySetUID] = useState<string | undefined>(
|
||||
foregroundDisplaySets.length > 0 ? foregroundDisplaySets[0].displaySetInstanceUID : undefined
|
||||
);
|
||||
|
||||
const { threshold, setThreshold, pixelValueRange } = useViewportRendering(viewportId, {
|
||||
displaySetInstanceUID: selectedDisplaySetUID,
|
||||
});
|
||||
|
||||
const { min, max } = pixelValueRange;
|
||||
const thresholdValue = threshold ?? min;
|
||||
|
||||
useEffect(() => {
|
||||
if (foregroundDisplaySets.length > 0 && !selectedDisplaySetUID) {
|
||||
setSelectedDisplaySetUID(foregroundDisplaySets[0].displaySetInstanceUID);
|
||||
}
|
||||
}, [foregroundDisplaySets, selectedDisplaySetUID]);
|
||||
|
||||
const selectedDisplaySet = viewportDisplaySets.find(
|
||||
ds => ds.displaySetInstanceUID === selectedDisplaySetUID
|
||||
);
|
||||
|
||||
return (
|
||||
<div className={className}>
|
||||
<div className="bg-popover w-72 rounded-lg p-4 shadow-md">
|
||||
<div className="mb-4 flex items-center justify-between">
|
||||
<div className="flex items-center space-x-2">
|
||||
<span className="text-muted-foreground text-base">Threshold</span>
|
||||
{viewportDisplaySets.length > 1 && (
|
||||
<div className="w-32">
|
||||
<Select
|
||||
value={selectedDisplaySetUID}
|
||||
onValueChange={setSelectedDisplaySetUID}
|
||||
>
|
||||
<SelectTrigger>
|
||||
<SelectValue>{selectedDisplaySet?.label || 'Select Display Set'}</SelectValue>
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
{viewportDisplaySets.map(ds => (
|
||||
<SelectItem
|
||||
key={ds.displaySetInstanceUID}
|
||||
value={ds.displaySetInstanceUID}
|
||||
>
|
||||
<SelectItemWithModality displaySet={ds} />
|
||||
</SelectItem>
|
||||
))}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
<Button
|
||||
size="sm"
|
||||
variant="ghost"
|
||||
onClick={() => setThreshold(min)}
|
||||
className="text-sm"
|
||||
>
|
||||
Reset
|
||||
</Button>
|
||||
</div>
|
||||
<Numeric.Container
|
||||
mode="singleRange"
|
||||
value={thresholdValue}
|
||||
onChange={(val: number | [number, number]) => {
|
||||
if (typeof val === 'number') {
|
||||
setThreshold(val);
|
||||
}
|
||||
}}
|
||||
min={min}
|
||||
max={max}
|
||||
step={0.01}
|
||||
>
|
||||
<Numeric.SingleRange />
|
||||
<div className="mt-1 flex justify-between">
|
||||
<span className="text-muted-foreground text-sm">{min.toFixed(0)}</span>
|
||||
<span className="text-muted-foreground text-sm">{max.toFixed(0)}</span>
|
||||
</div>
|
||||
</Numeric.Container>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default ThresholdMenu;
|
||||
@@ -0,0 +1,85 @@
|
||||
import React, { ReactNode } from 'react';
|
||||
import { useSystem } from '@ohif/core';
|
||||
import {
|
||||
Button,
|
||||
Icons,
|
||||
Popover,
|
||||
PopoverContent,
|
||||
PopoverTrigger,
|
||||
useIconPresentation,
|
||||
} from '@ohif/ui-next';
|
||||
import ThresholdMenu from './ThresholdMenu';
|
||||
|
||||
type ThresholdMenuWrapperProps = {
|
||||
viewportId: string;
|
||||
location: string;
|
||||
isOpen?: boolean;
|
||||
onOpen?: () => void;
|
||||
onClose?: () => void;
|
||||
disabled?: boolean;
|
||||
};
|
||||
|
||||
export function ThresholdMenuWrapper(props: ThresholdMenuWrapperProps): ReactNode {
|
||||
const { viewportId, location, isOpen = false, onOpen, onClose, disabled, ...rest } = props;
|
||||
const { IconContainer, className: iconClassName, containerProps } = useIconPresentation();
|
||||
|
||||
const handleOpenChange = (openState: boolean) => {
|
||||
if (openState) {
|
||||
onOpen?.();
|
||||
} else {
|
||||
onClose?.();
|
||||
}
|
||||
};
|
||||
|
||||
const { servicesManager } = useSystem();
|
||||
const { toolbarService } = servicesManager.services;
|
||||
|
||||
const { align, side } = toolbarService.getAlignAndSide(location);
|
||||
|
||||
const Icon = <Icons.Threshold className={iconClassName} />;
|
||||
|
||||
return (
|
||||
<Popover
|
||||
open={isOpen}
|
||||
onOpenChange={handleOpenChange}
|
||||
>
|
||||
<PopoverTrigger
|
||||
asChild
|
||||
className="flex items-center justify-center"
|
||||
>
|
||||
<div>
|
||||
{IconContainer ? (
|
||||
<IconContainer
|
||||
disabled={disabled}
|
||||
icon="Threshold"
|
||||
{...rest}
|
||||
{...containerProps}
|
||||
>
|
||||
{Icon}
|
||||
</IconContainer>
|
||||
) : (
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
disabled={disabled}
|
||||
>
|
||||
{Icon}
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
</PopoverTrigger>
|
||||
<PopoverContent
|
||||
className="border-none bg-transparent p-0 shadow-none"
|
||||
side={side}
|
||||
align={align}
|
||||
alignOffset={0}
|
||||
sideOffset={5}
|
||||
>
|
||||
<ThresholdMenu
|
||||
className="w-full"
|
||||
viewportId={viewportId}
|
||||
/>
|
||||
</PopoverContent>
|
||||
</Popover>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
export { ThresholdMenuWrapper } from './ThresholdMenuWrapper';
|
||||
export { default as ThresholdMenu } from './ThresholdMenu';
|
||||
@@ -0,0 +1,32 @@
|
||||
import React from 'react';
|
||||
import { Icons, Tooltip, TooltipTrigger, TooltipContent } from '@ohif/ui-next';
|
||||
import { useMeasurementTracking } from '../../hooks/useMeasurementTracking';
|
||||
|
||||
/**
|
||||
* TrackingStatus displays an indicator icon for viewports that have
|
||||
* tracked measurements
|
||||
*/
|
||||
function TrackingStatus({ viewportId }: { viewportId: string }) {
|
||||
const { isTracked } = useMeasurementTracking({ viewportId });
|
||||
|
||||
if (!isTracked) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
<Tooltip>
|
||||
<TooltipTrigger asChild>
|
||||
<span>
|
||||
<Icons.StatusTracking className="h-4 w-4" />
|
||||
</span>
|
||||
</TooltipTrigger>
|
||||
<TooltipContent side="bottom">
|
||||
<div>Tracking</div>
|
||||
</TooltipContent>
|
||||
</Tooltip>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
export default TrackingStatus;
|
||||
@@ -0,0 +1 @@
|
||||
export { default } from './TrackingStatus';
|
||||
@@ -0,0 +1,190 @@
|
||||
import React, { useState, useEffect } from 'react';
|
||||
import {
|
||||
Tabs,
|
||||
TabsList,
|
||||
TabsTrigger,
|
||||
TabsContent,
|
||||
Numeric,
|
||||
Select,
|
||||
SelectTrigger,
|
||||
SelectValue,
|
||||
SelectContent,
|
||||
SelectItem,
|
||||
} from '@ohif/ui-next';
|
||||
import { useViewportDisplaySets } from '../../hooks/useViewportDisplaySets';
|
||||
import { useViewportRendering } from '../../hooks/useViewportRendering';
|
||||
import { useSystem } from '@ohif/core';
|
||||
import { cache } from '@cornerstonejs/core';
|
||||
|
||||
interface VOIManualControlMenuProps {
|
||||
viewportId: string;
|
||||
className?: string;
|
||||
}
|
||||
|
||||
const TABS = {
|
||||
MINMAX: 'minmax',
|
||||
MANUAL: 'manual',
|
||||
};
|
||||
|
||||
function VOIManualControlMenu({ viewportId, className }: VOIManualControlMenuProps) {
|
||||
const { servicesManager } = useSystem();
|
||||
const { displaySetService } = servicesManager.services;
|
||||
const [activeTab, setActiveTab] = useState(TABS.MINMAX);
|
||||
const { viewportDisplaySets } = useViewportDisplaySets(viewportId);
|
||||
const [selectedDisplaySetUID, setSelectedDisplaySetUID] = useState<string | undefined>(
|
||||
viewportDisplaySets.length > 0 ? viewportDisplaySets[0].displaySetInstanceUID : undefined
|
||||
);
|
||||
|
||||
const { voiRange, setVOIRange, windowLevel, setWindowLevel } = useViewportRendering(viewportId, {
|
||||
displaySetInstanceUID: selectedDisplaySetUID,
|
||||
});
|
||||
|
||||
useEffect(() => {
|
||||
if (viewportDisplaySets.length > 0 && !selectedDisplaySetUID) {
|
||||
setSelectedDisplaySetUID(viewportDisplaySets[0].displaySetInstanceUID);
|
||||
}
|
||||
}, [viewportDisplaySets, selectedDisplaySetUID]);
|
||||
|
||||
if (!voiRange) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const { upper, lower } = voiRange;
|
||||
const { windowWidth, windowCenter } = windowLevel;
|
||||
|
||||
const selectedViewportImageIds =
|
||||
displaySetService.getDisplaySetByUID(selectedDisplaySetUID)?.imageIds;
|
||||
|
||||
let min = Infinity;
|
||||
let max = -Infinity;
|
||||
|
||||
if (selectedViewportImageIds) {
|
||||
for (const imageId of selectedViewportImageIds) {
|
||||
const image = cache.getImage(imageId);
|
||||
if (image) {
|
||||
min = Math.min(min, image.minPixelValue);
|
||||
max = Math.max(max, image.maxPixelValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Provide reasonable defaults if min/max couldn't be determined
|
||||
if (min === Infinity || max === -Infinity) {
|
||||
min = 0;
|
||||
max = 255;
|
||||
}
|
||||
|
||||
const selectedDisplaySet = viewportDisplaySets.find(
|
||||
ds => ds.displaySetInstanceUID === selectedDisplaySetUID
|
||||
);
|
||||
|
||||
return (
|
||||
<div className={className}>
|
||||
<div className="bg-popover w-72 rounded-lg p-4 shadow-md">
|
||||
<Tabs
|
||||
defaultValue={activeTab}
|
||||
onValueChange={setActiveTab}
|
||||
>
|
||||
<div className="mb-4 flex items-center space-x-2">
|
||||
{viewportDisplaySets.length > 1 && (
|
||||
<Select
|
||||
value={selectedDisplaySetUID}
|
||||
onValueChange={setSelectedDisplaySetUID}
|
||||
>
|
||||
<SelectTrigger>
|
||||
<SelectValue>{selectedDisplaySet?.label || 'Select Display Set'}</SelectValue>
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
{viewportDisplaySets.map(ds => (
|
||||
<SelectItem
|
||||
key={ds.displaySetInstanceUID}
|
||||
value={ds.displaySetInstanceUID}
|
||||
>
|
||||
{`${ds.SeriesDescription || ''}`.trim()}
|
||||
</SelectItem>
|
||||
))}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
)}
|
||||
<TabsList className="w-full flex-1">
|
||||
<TabsTrigger
|
||||
value={TABS.MINMAX}
|
||||
className="flex-1"
|
||||
>
|
||||
Min/Max
|
||||
</TabsTrigger>
|
||||
<TabsTrigger
|
||||
value={TABS.MANUAL}
|
||||
className="flex-1"
|
||||
>
|
||||
Manual
|
||||
</TabsTrigger>
|
||||
</TabsList>
|
||||
</div>
|
||||
|
||||
<TabsContent value={TABS.MINMAX}>
|
||||
<Numeric.Container
|
||||
mode="doubleRange"
|
||||
min={min}
|
||||
max={max}
|
||||
values={[lower, upper]}
|
||||
step={1}
|
||||
className="space-y-1"
|
||||
onChange={(vals: [number, number]) => {
|
||||
const [newLower, newUpper] = vals;
|
||||
if (newLower !== lower || newUpper !== upper) {
|
||||
setVOIRange({ lower: newLower, upper: newUpper });
|
||||
}
|
||||
}}
|
||||
>
|
||||
<Numeric.DoubleRange showNumberInputs />
|
||||
</Numeric.Container>
|
||||
</TabsContent>
|
||||
<TabsContent value={TABS.MANUAL}>
|
||||
<div className="space-y-1">
|
||||
<Numeric.Container
|
||||
mode="singleRange"
|
||||
min={0}
|
||||
max={max}
|
||||
step={1}
|
||||
value={windowWidth}
|
||||
className="space-y-1"
|
||||
onChange={(val: number) => {
|
||||
if (val !== windowWidth) {
|
||||
setWindowLevel({ windowWidth: val, windowCenter });
|
||||
}
|
||||
}}
|
||||
>
|
||||
<div className="flex items-center space-x-2">
|
||||
<Numeric.Label>W:</Numeric.Label>
|
||||
<Numeric.SingleRange showNumberInput />
|
||||
</div>
|
||||
</Numeric.Container>
|
||||
|
||||
<Numeric.Container
|
||||
mode="singleRange"
|
||||
min={min}
|
||||
max={max}
|
||||
step={1}
|
||||
value={windowCenter}
|
||||
className="space-y-1"
|
||||
onChange={(val: number) => {
|
||||
if (val !== windowCenter) {
|
||||
setWindowLevel({ windowWidth, windowCenter: val });
|
||||
}
|
||||
}}
|
||||
>
|
||||
<div className="flex items-center space-x-2">
|
||||
<Numeric.Label>L:</Numeric.Label>
|
||||
<Numeric.SingleRange showNumberInput />
|
||||
</div>
|
||||
</Numeric.Container>
|
||||
</div>
|
||||
</TabsContent>
|
||||
</Tabs>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default VOIManualControlMenu;
|
||||
+85
@@ -0,0 +1,85 @@
|
||||
import React, { ReactNode } from 'react';
|
||||
import { useSystem } from '@ohif/core';
|
||||
import {
|
||||
Button,
|
||||
Icons,
|
||||
Popover,
|
||||
PopoverContent,
|
||||
PopoverTrigger,
|
||||
useIconPresentation,
|
||||
} from '@ohif/ui-next';
|
||||
import VOIManualControlMenu from './VOIManualControlMenu';
|
||||
|
||||
type VOIManualControlMenuWrapperProps = {
|
||||
viewportId: string;
|
||||
location: string;
|
||||
isOpen?: boolean;
|
||||
onOpen?: () => void;
|
||||
onClose?: () => void;
|
||||
disabled?: boolean;
|
||||
};
|
||||
|
||||
export function VOIManualControlMenuWrapper(props: VOIManualControlMenuWrapperProps): ReactNode {
|
||||
const { viewportId, location, isOpen = false, onOpen, onClose, disabled, ...rest } = props;
|
||||
const { IconContainer, className: iconClassName, containerProps } = useIconPresentation();
|
||||
|
||||
const handleOpenChange = (openState: boolean) => {
|
||||
if (openState) {
|
||||
onOpen?.();
|
||||
} else {
|
||||
onClose?.();
|
||||
}
|
||||
};
|
||||
|
||||
const { servicesManager } = useSystem();
|
||||
const { toolbarService } = servicesManager.services;
|
||||
|
||||
const { align, side } = toolbarService.getAlignAndSide(location);
|
||||
|
||||
const Icon = <Icons.WindowLevelAdvanced className={iconClassName} />;
|
||||
|
||||
return (
|
||||
<Popover
|
||||
open={isOpen}
|
||||
onOpenChange={handleOpenChange}
|
||||
>
|
||||
<PopoverTrigger
|
||||
asChild
|
||||
className="flex items-center justify-center"
|
||||
>
|
||||
<div>
|
||||
{IconContainer ? (
|
||||
<IconContainer
|
||||
disabled={disabled}
|
||||
icon="WindowLevelAdvanced"
|
||||
{...rest}
|
||||
{...containerProps}
|
||||
>
|
||||
{Icon}
|
||||
</IconContainer>
|
||||
) : (
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
disabled={disabled}
|
||||
>
|
||||
{Icon}
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
</PopoverTrigger>
|
||||
<PopoverContent
|
||||
className="border-none bg-transparent p-0 shadow-none"
|
||||
side={side}
|
||||
align={align}
|
||||
alignOffset={0}
|
||||
sideOffset={5}
|
||||
>
|
||||
<VOIManualControlMenu
|
||||
className="w-full"
|
||||
viewportId={viewportId}
|
||||
/>
|
||||
</PopoverContent>
|
||||
</Popover>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
export { VOIManualControlMenuWrapper } from './VOIManualControlMenuWrapper';
|
||||
export { default as VOIManualControlMenu } from './VOIManualControlMenu';
|
||||
-117
@@ -1,117 +0,0 @@
|
||||
import React from 'react';
|
||||
import { Button, Icons } from '@ohif/ui-next';
|
||||
import ViewportColorbar from './ViewportColorbar';
|
||||
import {
|
||||
ColorbarCustomization,
|
||||
ColorbarPositionType,
|
||||
TickPositionType,
|
||||
} from '../../types/Colorbar';
|
||||
import type { ColorMapPreset } from '../../types/Colormap';
|
||||
|
||||
type ColorbarData = {
|
||||
colorbar: {
|
||||
activeColormapName: string;
|
||||
colormaps: ColorMapPreset[];
|
||||
volumeId?: string;
|
||||
};
|
||||
displaySetInstanceUID: string;
|
||||
};
|
||||
|
||||
type AdvancedColorbarWithControlsProps = {
|
||||
viewportId: string;
|
||||
colorbars: ColorbarData[];
|
||||
position: string;
|
||||
tickPosition: string;
|
||||
colorbarCustomization: ColorbarCustomization;
|
||||
onClose: (displaySetInstanceUID?: string) => void;
|
||||
viewportElementRef?: React.RefObject<HTMLDivElement>;
|
||||
};
|
||||
|
||||
/**
|
||||
* AdvancedColorbarWithControls Component
|
||||
* A specialized colorbar component with additional control buttons for advanced window level controls
|
||||
* This component handles the rendering portion of the ViewportColorbarsContainer
|
||||
*/
|
||||
const AdvancedColorbarWithControls = ({
|
||||
viewportId,
|
||||
colorbars,
|
||||
position,
|
||||
tickPosition,
|
||||
colorbarCustomization,
|
||||
onClose,
|
||||
viewportElementRef,
|
||||
}: AdvancedColorbarWithControlsProps) => {
|
||||
const handleClose = (displaySetInstanceUID?: string) => {
|
||||
onClose(displaySetInstanceUID);
|
||||
};
|
||||
|
||||
// Get bottom position styles from customization
|
||||
const positionStyles = colorbarCustomization?.positionStyles || {};
|
||||
const bottomPositionStyles = positionStyles.bottom || {};
|
||||
const heightStyle = bottomPositionStyles.height;
|
||||
|
||||
return (
|
||||
<div className="mx-auto flex h-[20px] w-1/2 flex-row items-center justify-between">
|
||||
<div className="flex flex-shrink-0 flex-row">
|
||||
<Button
|
||||
size="icon"
|
||||
variant="ghost"
|
||||
onClick={() => handleClose()}
|
||||
className="flex-shrink-0 p-0"
|
||||
>
|
||||
<Icons.Close />
|
||||
</Button>
|
||||
|
||||
<Button
|
||||
size="icon"
|
||||
variant="ghost"
|
||||
className="flex-shrink-0 p-0"
|
||||
>
|
||||
<Icons.ToolZoom />
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
<div
|
||||
className="mx-2"
|
||||
style={{ width: 'calc(75% - 16px)', height: heightStyle }}
|
||||
>
|
||||
{colorbars.map((colorbarInfo, index) => {
|
||||
const { colorbar, displaySetInstanceUID } = colorbarInfo;
|
||||
return (
|
||||
<ViewportColorbar
|
||||
key={`colorbar-${viewportId}-${displaySetInstanceUID}`}
|
||||
viewportId={viewportId}
|
||||
viewportElementRef={viewportElementRef}
|
||||
displaySetInstanceUID={displaySetInstanceUID}
|
||||
colormaps={colorbar.colormaps}
|
||||
activeColormapName={colorbar.activeColormapName}
|
||||
volumeId={colorbar.volumeId}
|
||||
position={position as ColorbarPositionType}
|
||||
tickPosition={tickPosition as TickPositionType}
|
||||
tickStyles={colorbarCustomization?.tickStyles}
|
||||
/>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
|
||||
<div className="flex flex-shrink-0 flex-row">
|
||||
<Button
|
||||
size="icon"
|
||||
variant="ghost"
|
||||
className="flex-shrink-0 p-0"
|
||||
>
|
||||
<Icons.Redo />
|
||||
</Button>
|
||||
<Button
|
||||
size="icon"
|
||||
variant="ghost"
|
||||
className="flex-shrink-0 p-0"
|
||||
>
|
||||
<Icons.Pencil />
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default AdvancedColorbarWithControls;
|
||||
@@ -1,6 +1,6 @@
|
||||
import React, { useEffect, useRef } from 'react';
|
||||
import React, { useEffect, useRef, useMemo, memo } from 'react';
|
||||
import { utilities } from '@cornerstonejs/tools';
|
||||
import { useSystem } from '@ohif/core';
|
||||
import { useSystem, useViewportRef, useViewportSize } from '@ohif/core';
|
||||
import {
|
||||
ColorbarPositionType,
|
||||
TickPositionType,
|
||||
@@ -24,6 +24,7 @@ type ColorbarProps = {
|
||||
tickStyles?: TickStyleType;
|
||||
containerStyles?: ContainerStyleType;
|
||||
viewportElementRef?: React.RefObject<HTMLDivElement>;
|
||||
numColorbars: number;
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -31,7 +32,7 @@ type ColorbarProps = {
|
||||
* A React wrapper for the cornerstone ViewportColorbar that adds a close button
|
||||
* positioned appropriately based on the colorbar position.
|
||||
*/
|
||||
const ViewportColorbar = ({
|
||||
const ViewportColorbar = memo(function ViewportColorbar({
|
||||
viewportId,
|
||||
displaySetInstanceUID,
|
||||
colormaps,
|
||||
@@ -40,11 +41,50 @@ const ViewportColorbar = ({
|
||||
position,
|
||||
tickPosition,
|
||||
tickStyles,
|
||||
viewportElementRef,
|
||||
}: ColorbarProps) => {
|
||||
numColorbars,
|
||||
}: ColorbarProps) {
|
||||
const containerRef = useRef<HTMLDivElement>(null);
|
||||
const { servicesManager } = useSystem();
|
||||
const { customizationService } = servicesManager.services;
|
||||
const viewportElementRef = useViewportRef(viewportId);
|
||||
const { height, width } = useViewportSize(viewportId);
|
||||
|
||||
// Memoize colorbar customization to prevent rerenders from unrelated customization changes
|
||||
const colorbarCustomization = useMemo(() => {
|
||||
return customizationService.getCustomization(
|
||||
'cornerstone.colorbar'
|
||||
) as unknown as ColorbarCustomization;
|
||||
}, [customizationService]);
|
||||
|
||||
const appropriateTickPosition = useMemo(() => {
|
||||
let tickPos = tickPosition;
|
||||
if (position === 'left' || position === 'right') {
|
||||
tickPos = position === 'left' ? 'right' : 'left';
|
||||
} else {
|
||||
tickPos = position === 'top' ? 'bottom' : 'top';
|
||||
}
|
||||
return tickPos;
|
||||
}, [position, tickPosition]);
|
||||
|
||||
const positionTickStyles = useMemo(() => {
|
||||
return colorbarCustomization?.positionTickStyles?.[position];
|
||||
}, [colorbarCustomization, position]);
|
||||
|
||||
const positionStylesFromConfig = useMemo(() => {
|
||||
return colorbarCustomization?.positionStyles?.[position] || {};
|
||||
}, [colorbarCustomization, position]);
|
||||
|
||||
const mergedTickStyles = useMemo(() => {
|
||||
return {
|
||||
...(colorbarCustomization?.tickStyles || {}),
|
||||
...(positionTickStyles?.style || {}),
|
||||
...(tickStyles || {}),
|
||||
};
|
||||
}, [colorbarCustomization, positionTickStyles, tickStyles]);
|
||||
|
||||
const colorbarId = useMemo(() => {
|
||||
return `Colorbar-${viewportId}-${displaySetInstanceUID}`;
|
||||
}, [viewportId, displaySetInstanceUID]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!containerRef.current || !colormaps || !activeColormapName) {
|
||||
@@ -53,29 +93,21 @@ const ViewportColorbar = ({
|
||||
|
||||
const viewportElement = viewportElementRef?.current;
|
||||
|
||||
if (!viewportElement) {
|
||||
if (!viewportElement || !colormaps?.length) {
|
||||
return;
|
||||
}
|
||||
|
||||
const colorbarCustomization = customizationService.getCustomization(
|
||||
'cornerstone.colorbar'
|
||||
) as unknown as ColorbarCustomization;
|
||||
|
||||
const positionTickStyles = colorbarCustomization?.positionTickStyles?.[position];
|
||||
// Using stable references from memoized values
|
||||
const csColorbar = new CornerstoneViewportColorbar({
|
||||
id: `Colorbar-${viewportId}-${displaySetInstanceUID}`,
|
||||
id: colorbarId,
|
||||
element: viewportElement,
|
||||
container: containerRef.current,
|
||||
colormaps: colormaps,
|
||||
activeColormapName: activeColormapName,
|
||||
volumeId,
|
||||
ticks: {
|
||||
position: tickPosition as ColorbarRangeTextPosition,
|
||||
style: {
|
||||
...(colorbarCustomization?.tickStyles || {}),
|
||||
...(positionTickStyles?.style || {}),
|
||||
...(tickStyles || {}),
|
||||
},
|
||||
position: appropriateTickPosition as ColorbarRangeTextPosition,
|
||||
style: mergedTickStyles,
|
||||
},
|
||||
});
|
||||
|
||||
@@ -90,37 +122,33 @@ const ViewportColorbar = ({
|
||||
colormaps,
|
||||
activeColormapName,
|
||||
volumeId,
|
||||
position,
|
||||
tickPosition,
|
||||
tickStyles,
|
||||
colorbarId,
|
||||
appropriateTickPosition,
|
||||
mergedTickStyles,
|
||||
viewportElementRef,
|
||||
customizationService,
|
||||
]);
|
||||
|
||||
// Get position styles from customization service
|
||||
const colorbarCustomization = customizationService.getCustomization(
|
||||
'cornerstone.colorbar'
|
||||
) as unknown as ColorbarCustomization;
|
||||
|
||||
const positionStylesFromConfig = colorbarCustomization?.positionStyles?.[position] || {};
|
||||
if (!height || !width) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (
|
||||
<div
|
||||
id={`colorbar-container-${viewportId}-${displaySetInstanceUID}`}
|
||||
ref={containerRef}
|
||||
style={{
|
||||
width: position === 'bottom' ? '100%' : '20px',
|
||||
height: position === 'bottom' ? '20px' : '100%',
|
||||
position: 'relative',
|
||||
zIndex: 1000,
|
||||
boxSizing: 'border-box',
|
||||
display: 'flex',
|
||||
alignItems: 'center',
|
||||
pointerEvents: 'auto',
|
||||
minWidth: position === 'bottom' ? width / 2.5 : '17px',
|
||||
minHeight: position === 'bottom' ? '20px' : numColorbars === 1 ? height / 3 : height / 4,
|
||||
...positionStylesFromConfig,
|
||||
}}
|
||||
></div>
|
||||
);
|
||||
};
|
||||
});
|
||||
|
||||
export default ViewportColorbar;
|
||||
+65
-77
@@ -1,14 +1,13 @@
|
||||
import React, { useEffect, useState } from 'react';
|
||||
import React, { useEffect, useState, useMemo, memo, useCallback } from 'react';
|
||||
import { useSystem } from '@ohif/core';
|
||||
import AdvancedColorbarWithControls from './AdvancedColorbarWithControls';
|
||||
import { ColorbarCustomization } from '../../types/Colorbar';
|
||||
import type { ColorMapPreset } from '../../types/Colormap';
|
||||
import ViewportColorbar from './ViewportColorbar';
|
||||
import { deepMerge } from '@cornerstonejs/core/utilities';
|
||||
|
||||
import useViewportRendering from '../../hooks/useViewportRendering';
|
||||
import { useViewportDisplaySets } from '../../hooks/useViewportDisplaySets';
|
||||
type ViewportColorbarsContainerProps = {
|
||||
viewportId: string;
|
||||
viewportElementRef?: React.RefObject<HTMLDivElement>;
|
||||
location: number;
|
||||
};
|
||||
|
||||
type ColorbarData = {
|
||||
@@ -24,18 +23,38 @@ type ColorbarData = {
|
||||
* Container component that manages multiple colorbars for a viewport
|
||||
* It interacts with the colorbarService to get/set colorbar states
|
||||
*/
|
||||
const ViewportColorbarsContainer = ({
|
||||
const ViewportColorbarsContainer = memo(function ViewportColorbarsContainer({
|
||||
viewportId,
|
||||
viewportElementRef,
|
||||
}: ViewportColorbarsContainerProps) => {
|
||||
location,
|
||||
}: ViewportColorbarsContainerProps) {
|
||||
const [colorbars, setColorbars] = useState<ColorbarData[]>([]);
|
||||
const { servicesManager } = useSystem();
|
||||
const { colorbarService, customizationService } = servicesManager.services;
|
||||
const { colorbarService, customizationService, displaySetService } = servicesManager.services;
|
||||
const { viewportDisplaySets, backgroundDisplaySet, foregroundDisplaySets } =
|
||||
useViewportDisplaySets(viewportId);
|
||||
const { colorbarPosition: position, opacity } = useViewportRendering(viewportId, {
|
||||
location,
|
||||
});
|
||||
|
||||
// Memoize the customization to prevent recomputation
|
||||
const colorbarCustomization = useMemo(() => {
|
||||
return customizationService.getCustomization(
|
||||
'cornerstone.colorbar'
|
||||
) as unknown as ColorbarCustomization;
|
||||
}, [customizationService]);
|
||||
|
||||
// Memoize tick position
|
||||
const tickPosition = useMemo(() => {
|
||||
const defaultTickPosition = colorbarCustomization?.colorbarTickPosition;
|
||||
return colorbarCustomization?.colorbarTickPosition || defaultTickPosition;
|
||||
}, [colorbarCustomization]);
|
||||
|
||||
// Initial load of colorbars
|
||||
useEffect(() => {
|
||||
setColorbars(colorbarService.getViewportColorbar(viewportId) || []);
|
||||
}, [viewportId, colorbarService]);
|
||||
|
||||
// Subscribe to colorbar state changes
|
||||
useEffect(() => {
|
||||
const { unsubscribe } = colorbarService.subscribe(
|
||||
colorbarService.EVENTS.STATE_CHANGED,
|
||||
@@ -51,90 +70,59 @@ const ViewportColorbarsContainer = ({
|
||||
};
|
||||
}, [viewportId, colorbarService]);
|
||||
|
||||
const handleClose = (displaySetInstanceUID?: string): void => {
|
||||
if (displaySetInstanceUID) {
|
||||
colorbarService.removeColorbar(viewportId, displaySetInstanceUID);
|
||||
} else {
|
||||
colorbarService.removeColorbar(viewportId);
|
||||
}
|
||||
};
|
||||
|
||||
if (!colorbars.length) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const colorbarCustomization = customizationService.getCustomization(
|
||||
'cornerstone.colorbar'
|
||||
) as unknown as ColorbarCustomization;
|
||||
const isBottom = position === 'bottom';
|
||||
|
||||
const defaultPosition = colorbarCustomization?.colorbarContainerPosition;
|
||||
const defaultTickPosition = colorbarCustomization?.colorbarTickPosition;
|
||||
const isSingleViewport = viewportDisplaySets.length === 1;
|
||||
const showFullList = isSingleViewport || !isBottom;
|
||||
|
||||
const position = colorbarCustomization?.colorbarContainerPosition || defaultPosition;
|
||||
const tickPosition = colorbarCustomization?.colorbarTickPosition || defaultTickPosition;
|
||||
const positionStyles = colorbarCustomization?.positionStyles;
|
||||
const colorbarsToUse = showFullList
|
||||
? colorbars
|
||||
: colorbars.filter(({ displaySetInstanceUID }) => {
|
||||
const { displaySetInstanceUID: dsUID } =
|
||||
displaySetService.getDisplaySetByUID(displaySetInstanceUID) ?? {};
|
||||
|
||||
const positionStyle = positionStyles?.[position];
|
||||
const targetUID =
|
||||
opacity === 0 || opacity == null
|
||||
? backgroundDisplaySet?.displaySetInstanceUID
|
||||
: foregroundDisplaySets[0].displaySetInstanceUID;
|
||||
|
||||
const defaultPositionStyle =
|
||||
position !== 'bottom'
|
||||
? {
|
||||
width: '20px',
|
||||
height: colorbars.length === 1 ? '55%' : '75%',
|
||||
top: '50%',
|
||||
transform: 'translateY(-50%)',
|
||||
}
|
||||
: {
|
||||
width: '100%',
|
||||
height: '20px',
|
||||
};
|
||||
|
||||
const finalPositionStyle = deepMerge(defaultPositionStyle, positionStyle);
|
||||
return dsUID === targetUID;
|
||||
});
|
||||
|
||||
return (
|
||||
<div
|
||||
className="absolute"
|
||||
style={{
|
||||
...finalPositionStyle,
|
||||
pointerEvents: 'auto',
|
||||
}}
|
||||
>
|
||||
{position !== 'bottom' ? (
|
||||
<div
|
||||
className="flex h-full flex-col items-center justify-center"
|
||||
style={{ pointerEvents: 'auto' }}
|
||||
>
|
||||
{colorbars.map((colorbarInfo, index) => {
|
||||
const { colorbar, displaySetInstanceUID } = colorbarInfo;
|
||||
return (
|
||||
<ViewportColorbar
|
||||
key={`colorbar-${viewportId}-${displaySetInstanceUID}`}
|
||||
viewportId={viewportId}
|
||||
displaySetInstanceUID={displaySetInstanceUID}
|
||||
colormaps={colorbar.colormaps}
|
||||
activeColormapName={colorbar.activeColormapName}
|
||||
volumeId={colorbar.volumeId}
|
||||
viewportElementRef={viewportElementRef}
|
||||
position={position}
|
||||
tickPosition={tickPosition}
|
||||
tickStyles={colorbarCustomization?.tickStyles}
|
||||
/>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
) : (
|
||||
<AdvancedColorbarWithControls
|
||||
viewportId={viewportId}
|
||||
colorbars={colorbars}
|
||||
position={position}
|
||||
tickPosition={defaultTickPosition}
|
||||
colorbarCustomization={colorbarCustomization}
|
||||
onClose={handleClose}
|
||||
viewportElementRef={viewportElementRef}
|
||||
/>
|
||||
)}
|
||||
<div
|
||||
className="flex h-full flex-col items-center justify-center"
|
||||
style={{ pointerEvents: 'auto' }}
|
||||
>
|
||||
{colorbarsToUse.map(colorbarInfo => {
|
||||
const { colorbar, displaySetInstanceUID } = colorbarInfo;
|
||||
return (
|
||||
<ViewportColorbar
|
||||
key={`colorbar-${viewportId}-${displaySetInstanceUID}`}
|
||||
viewportId={viewportId}
|
||||
displaySetInstanceUID={displaySetInstanceUID}
|
||||
colormaps={colorbar.colormaps}
|
||||
activeColormapName={colorbar.activeColormapName}
|
||||
volumeId={colorbar.volumeId}
|
||||
position={position}
|
||||
tickPosition={tickPosition}
|
||||
tickStyles={colorbarCustomization?.tickStyles}
|
||||
numColorbars={colorbars.length}
|
||||
/>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
});
|
||||
|
||||
export default ViewportColorbarsContainer;
|
||||
@@ -1,6 +1,5 @@
|
||||
import ViewportColorbar from './ViewportColorbar';
|
||||
import ViewportColorbarsContainer from './ViewportColorbarsContainer';
|
||||
import AdvancedColorbarWithControls from './AdvancedColorbarWithControls';
|
||||
|
||||
export { ViewportColorbar, ViewportColorbarsContainer, AdvancedColorbarWithControls };
|
||||
export { ViewportColorbar, ViewportColorbarsContainer };
|
||||
export default ViewportColorbarsContainer;
|
||||
+37
-29
@@ -16,14 +16,16 @@ import {
|
||||
import { useSystem } from '@ohif/core';
|
||||
|
||||
import { useViewportDisplaySets } from '../../hooks/useViewportDisplaySets';
|
||||
import SelectItemWithModality from '../SelectItemWithModality';
|
||||
import { useViewportRendering } from '../../hooks';
|
||||
|
||||
function ViewportDataOverlayMenu({ viewportId }: withAppTypes<{ viewportId: string }>) {
|
||||
const { commandsManager, servicesManager } = useSystem();
|
||||
const [pendingForegrounds, setPendingForegrounds] = useState<string[]>([]);
|
||||
const [pendingSegmentations, setPendingSegmentations] = useState<string[]>([]);
|
||||
const [thresholdOpacityEnabled, setThresholdOpacityEnabled] = useState(false);
|
||||
const { toggleColorbar } = useViewportRendering(viewportId);
|
||||
|
||||
const { hangingProtocolService } = servicesManager.services;
|
||||
const { hangingProtocolService, toolbarService } = servicesManager.services;
|
||||
|
||||
const {
|
||||
backgroundDisplaySet,
|
||||
@@ -34,6 +36,8 @@ function ViewportDataOverlayMenu({ viewportId }: withAppTypes<{ viewportId: stri
|
||||
foregroundDisplaySets,
|
||||
} = useViewportDisplaySets(viewportId);
|
||||
|
||||
const [thresholdOpacityEnabled, setThresholdOpacityEnabled] = useState(false);
|
||||
|
||||
/**
|
||||
* Change the background display set
|
||||
*/
|
||||
@@ -48,21 +52,6 @@ function ViewportDataOverlayMenu({ viewportId }: withAppTypes<{ viewportId: stri
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Handle threshold and opacity toggle
|
||||
*/
|
||||
const handleThresholdOpacityToggle = (checked: boolean) => {
|
||||
setThresholdOpacityEnabled(checked);
|
||||
|
||||
if (foregroundDisplaySets.length > 0) {
|
||||
// Example implementation of threshold/opacity adjustment
|
||||
commandsManager.runCommand('setForegroundThresholdOpacity', {
|
||||
viewportId,
|
||||
enabled: checked,
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Replace a display set layer with a new one
|
||||
*/
|
||||
@@ -182,6 +171,18 @@ function ViewportDataOverlayMenu({ viewportId }: withAppTypes<{ viewportId: stri
|
||||
}
|
||||
};
|
||||
|
||||
// Check if the advanced window level components exist in toolbar
|
||||
const hasAdvancedRenderingControls = !!toolbarService.getButton('advancedRenderingControls');
|
||||
const hasOpacityMenu = !!toolbarService.getButton('opacityMenu');
|
||||
|
||||
const handleThresholdOpacityToggle = () => {
|
||||
const newValue = !thresholdOpacityEnabled;
|
||||
if (hasAdvancedRenderingControls) {
|
||||
toggleColorbar();
|
||||
}
|
||||
setThresholdOpacityEnabled(newValue);
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="bg-popover flex h-full w-[275px] flex-col rounded rounded-md p-1.5">
|
||||
{/* Top buttons row */}
|
||||
@@ -232,15 +233,17 @@ function ViewportDataOverlayMenu({ viewportId }: withAppTypes<{ viewportId: stri
|
||||
<SelectItem
|
||||
key={displaySet.displaySetInstanceUID}
|
||||
value={displaySet.displaySetInstanceUID}
|
||||
className="pr-2"
|
||||
>
|
||||
{displaySet.label}
|
||||
<SelectItemWithModality displaySet={displaySet} />
|
||||
</SelectItem>
|
||||
{potentialOverlayDisplaySets.map(item => (
|
||||
<SelectItem
|
||||
key={item.displaySetInstanceUID}
|
||||
value={item.displaySetInstanceUID}
|
||||
className="pr-2"
|
||||
>
|
||||
{item.label}
|
||||
<SelectItemWithModality displaySet={item} />
|
||||
</SelectItem>
|
||||
))}
|
||||
</SelectContent>
|
||||
@@ -284,8 +287,9 @@ function ViewportDataOverlayMenu({ viewportId }: withAppTypes<{ viewportId: stri
|
||||
<SelectItem
|
||||
key={item.displaySetInstanceUID}
|
||||
value={item.displaySetInstanceUID}
|
||||
className="pr-2"
|
||||
>
|
||||
{item.label}
|
||||
<SelectItemWithModality displaySet={item} />
|
||||
</SelectItem>
|
||||
))}
|
||||
</SelectContent>
|
||||
@@ -334,15 +338,17 @@ function ViewportDataOverlayMenu({ viewportId }: withAppTypes<{ viewportId: stri
|
||||
<SelectItem
|
||||
key={displaySet.displaySetInstanceUID}
|
||||
value={displaySet.displaySetInstanceUID}
|
||||
className="pr-2"
|
||||
>
|
||||
{displaySet.label}
|
||||
<SelectItemWithModality displaySet={displaySet} />
|
||||
</SelectItem>
|
||||
{potentialForegroundDisplaySets.map(item => (
|
||||
<SelectItem
|
||||
key={item.displaySetInstanceUID}
|
||||
value={item.displaySetInstanceUID}
|
||||
className="pr-2"
|
||||
>
|
||||
{item.label}
|
||||
<SelectItemWithModality displaySet={item} />
|
||||
</SelectItem>
|
||||
))}
|
||||
</SelectContent>
|
||||
@@ -386,8 +392,9 @@ function ViewportDataOverlayMenu({ viewportId }: withAppTypes<{ viewportId: stri
|
||||
<SelectItem
|
||||
key={item.displaySetInstanceUID}
|
||||
value={item.displaySetInstanceUID}
|
||||
className="pr-2"
|
||||
>
|
||||
{item.label}
|
||||
<SelectItemWithModality displaySet={item} />
|
||||
</SelectItem>
|
||||
))}
|
||||
</SelectContent>
|
||||
@@ -420,7 +427,7 @@ function ViewportDataOverlayMenu({ viewportId }: withAppTypes<{ viewportId: stri
|
||||
<div className="mt-1 mb-1 flex items-center px-1">
|
||||
<Icons.LayerBackground className="text-muted-foreground mr-1 h-6 w-6 flex-shrink-0" />
|
||||
<Select
|
||||
value={backgroundDisplaySet.displaySetInstanceUID}
|
||||
value={backgroundDisplaySet?.displaySetInstanceUID}
|
||||
onValueChange={value => {
|
||||
const selectedDisplaySet = potentialBackgroundDisplaySets.find(
|
||||
ds => ds.displaySetInstanceUID === value
|
||||
@@ -433,8 +440,8 @@ function ViewportDataOverlayMenu({ viewportId }: withAppTypes<{ viewportId: stri
|
||||
<SelectTrigger className="flex-1">
|
||||
<SelectValue>
|
||||
{(
|
||||
backgroundDisplaySet.SeriesDescription ||
|
||||
backgroundDisplaySet.label ||
|
||||
backgroundDisplaySet?.SeriesDescription ||
|
||||
backgroundDisplaySet?.label ||
|
||||
'background'
|
||||
).toUpperCase()}
|
||||
</SelectValue>
|
||||
@@ -444,15 +451,16 @@ function ViewportDataOverlayMenu({ viewportId }: withAppTypes<{ viewportId: stri
|
||||
<SelectItem
|
||||
key={displaySet.displaySetInstanceUID}
|
||||
value={displaySet.displaySetInstanceUID}
|
||||
className="pr-2"
|
||||
>
|
||||
{displaySet.label}
|
||||
<SelectItemWithModality displaySet={displaySet} />
|
||||
</SelectItem>
|
||||
))}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
</div>
|
||||
{/* {foregroundDisplaySets.length > 0 && (
|
||||
{foregroundDisplaySets.length > 0 && (hasAdvancedRenderingControls || hasOpacityMenu) && (
|
||||
<div className="mt-1 ml-7">
|
||||
<div className="flex items-center">
|
||||
<Switch
|
||||
@@ -470,7 +478,7 @@ function ViewportDataOverlayMenu({ viewportId }: withAppTypes<{ viewportId: stri
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
)} */}
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
+40
-39
@@ -1,73 +1,74 @@
|
||||
import React, { ReactNode } from 'react';
|
||||
import { useSystem } from '@ohif/core';
|
||||
import {
|
||||
Button,
|
||||
cn,
|
||||
Icons,
|
||||
Popover,
|
||||
PopoverContent,
|
||||
PopoverTrigger,
|
||||
useViewportGrid,
|
||||
useViewportActionCorners,
|
||||
useIconPresentation,
|
||||
} from '@ohif/ui-next';
|
||||
import ViewportDataOverlayMenu from './ViewportDataOverlayMenu';
|
||||
import classNames from 'classnames';
|
||||
import { MENU_IDS } from '../menus/menu-ids';
|
||||
import { useViewportDisplaySets } from '../../hooks/useViewportDisplaySets';
|
||||
|
||||
export function ViewportDataOverlayMenuWrapper({
|
||||
viewportId,
|
||||
displaySets,
|
||||
location,
|
||||
}: withAppTypes<{
|
||||
type DataOverlayMenuProps = {
|
||||
viewportId: string;
|
||||
element: HTMLElement;
|
||||
location: string;
|
||||
}>): ReactNode {
|
||||
const [viewportGrid] = useViewportGrid();
|
||||
const [actionCornerState, viewportActionCornersAPI] = useViewportActionCorners();
|
||||
isOpen?: boolean;
|
||||
onOpen?: () => void;
|
||||
onClose?: () => void;
|
||||
disabled?: boolean;
|
||||
};
|
||||
|
||||
const isMenuOpen =
|
||||
actionCornerState.viewports[viewportId]?.[location]?.find(
|
||||
item => item.id === MENU_IDS.DATA_OVERLAY_MENU
|
||||
)?.isOpen ?? false;
|
||||
export function ViewportDataOverlayMenuWrapper(props: DataOverlayMenuProps): ReactNode {
|
||||
const { viewportId, location, isOpen = false, onOpen, onClose, disabled, ...rest } = props;
|
||||
const { viewportDisplaySets: displaySets } = useViewportDisplaySets(viewportId);
|
||||
const { IconContainer, className: iconClassName, containerProps } = useIconPresentation();
|
||||
|
||||
const handleOpenChange = (openState: boolean) => {
|
||||
if (openState) {
|
||||
viewportActionCornersAPI.openItem?.(viewportId, MENU_IDS.DATA_OVERLAY_MENU);
|
||||
onOpen?.();
|
||||
} else {
|
||||
viewportActionCornersAPI.closeItem?.(viewportId, MENU_IDS.DATA_OVERLAY_MENU);
|
||||
onClose?.();
|
||||
}
|
||||
};
|
||||
|
||||
// Get proper alignment and side based on the location
|
||||
let align = 'center';
|
||||
let side = 'bottom';
|
||||
const { servicesManager } = useSystem();
|
||||
const { toolbarService } = servicesManager.services;
|
||||
|
||||
if (location !== undefined) {
|
||||
const positioning = viewportActionCornersAPI.getAlignAndSide(location);
|
||||
align = positioning.align;
|
||||
side = positioning.side;
|
||||
}
|
||||
const { align, side } = toolbarService.getAlignAndSide(location);
|
||||
|
||||
const Icon = <Icons.ViewportViews className={iconClassName} />;
|
||||
|
||||
return (
|
||||
<Popover
|
||||
open={isMenuOpen}
|
||||
open={isOpen}
|
||||
onOpenChange={handleOpenChange}
|
||||
>
|
||||
<PopoverTrigger
|
||||
asChild
|
||||
className="flex items-center justify-center"
|
||||
>
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
className={cn(
|
||||
viewportGrid.activeViewportId === viewportId
|
||||
? 'visible'
|
||||
: 'invisible group-hover/pane:visible'
|
||||
<div>
|
||||
{IconContainer ? (
|
||||
<IconContainer
|
||||
disabled={disabled}
|
||||
icon="ViewportViews"
|
||||
{...rest}
|
||||
{...containerProps}
|
||||
>
|
||||
{Icon}
|
||||
</IconContainer>
|
||||
) : (
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
disabled={disabled}
|
||||
>
|
||||
{Icon}
|
||||
</Button>
|
||||
)}
|
||||
>
|
||||
<Icons.ViewportViews className={classNames('text-highlight')} />
|
||||
</Button>
|
||||
</div>
|
||||
</PopoverTrigger>
|
||||
<PopoverContent
|
||||
className="border-none bg-transparent p-0 shadow-none"
|
||||
|
||||
@@ -1,12 +0,0 @@
|
||||
import React, { ReactNode } from 'react';
|
||||
import { ViewportDataOverlayMenuWrapper } from './ViewportDataOverlayMenuWrapper';
|
||||
|
||||
export function getViewportDataOverlaySettingsMenu(
|
||||
props: withAppTypes<{
|
||||
viewportId: string;
|
||||
element: HTMLElement;
|
||||
location: string;
|
||||
}>
|
||||
): ReactNode {
|
||||
return <ViewportDataOverlayMenuWrapper {...props} />;
|
||||
}
|
||||
@@ -42,6 +42,14 @@ export function getModalityOverlayColormap(customizationService, modality) {
|
||||
export function getEnhancedDisplaySets({ viewportId, services }) {
|
||||
const { displaySetService, viewportGridService } = services;
|
||||
const displaySetsUIDs = viewportGridService.getDisplaySetsUIDsForViewport(viewportId);
|
||||
|
||||
if (!displaySetsUIDs?.length) {
|
||||
return {
|
||||
viewportDisplaySets: [],
|
||||
enhancedDisplaySets: [],
|
||||
};
|
||||
}
|
||||
|
||||
const allDisplaySets = displaySetService.getActiveDisplaySets();
|
||||
|
||||
const otherDisplaySets = allDisplaySets.filter(
|
||||
@@ -52,7 +60,7 @@ export function getEnhancedDisplaySets({ viewportId, services }) {
|
||||
displaySetService.getDisplaySetByUID(displaySetUID)
|
||||
);
|
||||
|
||||
const backgroundCanBeVolume = csUtils.isValidVolume(viewportDisplaySets[0].imageIds);
|
||||
const backgroundCanBeVolume = csUtils.isValidVolume(viewportDisplaySets[0].imageIds || []);
|
||||
const backgroundDisplaySet = viewportDisplaySets[0];
|
||||
|
||||
const enhancedDisplaySets = otherDisplaySets.map(displaySet => {
|
||||
|
||||
+97
-77
@@ -1,40 +1,37 @@
|
||||
import React from 'react';
|
||||
import { Icons, useViewportActionCorners, useViewportGrid } from '@ohif/ui-next';
|
||||
import { cn, Icons, ToolButton, useIconPresentation } from '@ohif/ui-next';
|
||||
import { useSystem } from '@ohif/core';
|
||||
import { Enums } from '@cornerstonejs/core';
|
||||
import {
|
||||
DropdownMenu,
|
||||
DropdownMenuTrigger,
|
||||
DropdownMenuContent,
|
||||
DropdownMenuItem,
|
||||
DropdownMenuLabel,
|
||||
Button,
|
||||
} from '@ohif/ui-next';
|
||||
import { MENU_IDS } from '../menus/menu-ids';
|
||||
import { Popover, PopoverTrigger, PopoverContent, Button, useViewportGrid } from '@ohif/ui-next';
|
||||
|
||||
function ViewportOrientationMenu({ location }: withAppTypes<{ location?: string }>) {
|
||||
function ViewportOrientationMenu({
|
||||
location,
|
||||
viewportId,
|
||||
displaySets,
|
||||
isOpen = false,
|
||||
onOpen,
|
||||
onClose,
|
||||
disabled,
|
||||
...props
|
||||
}: withAppTypes<{
|
||||
location?: string;
|
||||
viewportId: string;
|
||||
displaySets: AppTypes.DisplaySet[];
|
||||
isOpen?: boolean;
|
||||
onOpen?: () => void;
|
||||
onClose?: () => void;
|
||||
disabled?: boolean;
|
||||
}>) {
|
||||
const [gridState] = useViewportGrid();
|
||||
const viewportIdToUse = viewportId || gridState.activeViewportId;
|
||||
const { IconContainer, className: iconClassName, containerProps } = useIconPresentation();
|
||||
const { servicesManager, commandsManager } = useSystem();
|
||||
const [viewportGridState, viewportGridService] = useViewportGrid();
|
||||
const [actionCornerState, viewportActionCornersServiceAPI] = useViewportActionCorners();
|
||||
const { cornerstoneViewportService, displaySetService } = servicesManager.services;
|
||||
|
||||
const viewportId = viewportGridState.activeViewportId;
|
||||
|
||||
const isMenuOpen =
|
||||
actionCornerState.viewports[viewportId]?.[location]?.find(
|
||||
item => item.id === MENU_IDS.ORIENTATION_MENU
|
||||
)?.isOpen ?? false;
|
||||
const { cornerstoneViewportService, toolbarService } = servicesManager.services;
|
||||
|
||||
const handleOrientationChange = (orientation: string) => {
|
||||
const viewportInfo = cornerstoneViewportService.getViewportInfo(viewportId);
|
||||
const viewportInfo = cornerstoneViewportService.getViewportInfo(viewportIdToUse);
|
||||
const currentViewportType = viewportInfo?.getViewportType();
|
||||
|
||||
// Get the displaySets in this viewport
|
||||
const displaySetUIDs = viewportGridService.getDisplaySetsUIDsForViewport(viewportId);
|
||||
const displaySets = displaySetUIDs
|
||||
.map(uid => displaySetService.getDisplaySetByUID(uid))
|
||||
.filter(Boolean);
|
||||
|
||||
if (!displaySets.length) {
|
||||
return;
|
||||
}
|
||||
@@ -63,11 +60,13 @@ function ViewportOrientationMenu({ location }: withAppTypes<{ location?: string
|
||||
orientationEnum = Enums.OrientationAxis.ACQUISITION;
|
||||
}
|
||||
|
||||
const displaySetUIDs = displaySets.map(ds => ds.displaySetInstanceUID);
|
||||
|
||||
// If viewport is not already a volume type, we need to convert it
|
||||
if (currentViewportType !== Enums.ViewportType.ORTHOGRAPHIC) {
|
||||
// Configure the viewport to be a volume viewport with current display sets
|
||||
const updatedViewport = {
|
||||
viewportId,
|
||||
viewportId: viewportIdToUse,
|
||||
displaySetInstanceUIDs: displaySetUIDs,
|
||||
viewportOptions: {
|
||||
viewportType: Enums.ViewportType.ORTHOGRAPHIC,
|
||||
@@ -83,78 +82,99 @@ function ViewportOrientationMenu({ location }: withAppTypes<{ location?: string
|
||||
} else {
|
||||
// Set the viewport orientation
|
||||
commandsManager.runCommand('setViewportOrientation', {
|
||||
viewportId,
|
||||
viewportId: viewportIdToUse,
|
||||
orientation: orientationEnum,
|
||||
});
|
||||
}
|
||||
|
||||
// Close the menu after selection
|
||||
viewportActionCornersServiceAPI.closeItem?.(viewportId, MENU_IDS.ORIENTATION_MENU);
|
||||
onClose?.();
|
||||
};
|
||||
|
||||
const handleOpenChange = (openState: boolean) => {
|
||||
if (openState) {
|
||||
viewportActionCornersServiceAPI.openItem?.(viewportId, MENU_IDS.ORIENTATION_MENU);
|
||||
onOpen?.();
|
||||
} else {
|
||||
viewportActionCornersServiceAPI.closeItem?.(viewportId, MENU_IDS.ORIENTATION_MENU);
|
||||
onClose?.();
|
||||
}
|
||||
};
|
||||
|
||||
const displaySetUIDs = viewportGridService.getDisplaySetsUIDsForViewport(viewportId);
|
||||
const displaySets = displaySetUIDs
|
||||
.map(uid => displaySetService.getDisplaySetByUID(uid))
|
||||
.filter(Boolean);
|
||||
|
||||
if (!displaySets.length) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const hasReconstructableDisplaySet = displaySets.some(ds => ds.isReconstructable);
|
||||
|
||||
// Get proper alignment and side based on the location
|
||||
let align = 'center';
|
||||
let side = 'bottom';
|
||||
|
||||
if (location !== undefined) {
|
||||
const positioning = viewportActionCornersServiceAPI.getAlignAndSide(location);
|
||||
align = positioning.align;
|
||||
side = positioning.side;
|
||||
}
|
||||
// Get proper alignment and side based on the location using toolbar service
|
||||
const { align, side } = toolbarService.getAlignAndSide(Number(location));
|
||||
|
||||
const Icon = <Icons.OrientationSwitch className={iconClassName} />;
|
||||
return (
|
||||
<DropdownMenu
|
||||
open={isMenuOpen}
|
||||
<Popover
|
||||
open={isOpen}
|
||||
onOpenChange={handleOpenChange}
|
||||
>
|
||||
<DropdownMenuTrigger asChild>
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
className="text-highlight"
|
||||
disabled={!hasReconstructableDisplaySet}
|
||||
>
|
||||
<Icons.OrientationSwitch />
|
||||
</Button>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent
|
||||
className="min-w-[160px]"
|
||||
<PopoverTrigger
|
||||
asChild
|
||||
className={cn('flex items-center justify-center')}
|
||||
>
|
||||
<div>
|
||||
{IconContainer ? (
|
||||
<IconContainer
|
||||
disabled={disabled}
|
||||
icon="OrientationSwitch"
|
||||
{...props}
|
||||
{...containerProps}
|
||||
>
|
||||
{Icon}
|
||||
</IconContainer>
|
||||
) : (
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
disabled={disabled}
|
||||
onClick={() => {}}
|
||||
>
|
||||
{Icon}
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
</PopoverTrigger>
|
||||
<PopoverContent
|
||||
className="w-[100px] p-1"
|
||||
align={align}
|
||||
side={side}
|
||||
sideOffset={5}
|
||||
>
|
||||
<DropdownMenuLabel className="-ml-1">Orientation</DropdownMenuLabel>
|
||||
<DropdownMenuItem onClick={() => handleOrientationChange('axial')}>Axial</DropdownMenuItem>
|
||||
<DropdownMenuItem onClick={() => handleOrientationChange('sagittal')}>
|
||||
Sagittal
|
||||
</DropdownMenuItem>
|
||||
<DropdownMenuItem onClick={() => handleOrientationChange('coronal')}>
|
||||
Coronal
|
||||
</DropdownMenuItem>
|
||||
<DropdownMenuItem onClick={() => handleOrientationChange('acquisition')}>
|
||||
Acquisition
|
||||
</DropdownMenuItem>
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
<div className="flex flex-col">
|
||||
<Button
|
||||
variant="ghost"
|
||||
className="justify-start"
|
||||
onClick={() => handleOrientationChange('axial')}
|
||||
>
|
||||
Axial
|
||||
</Button>
|
||||
<Button
|
||||
variant="ghost"
|
||||
className="justify-start"
|
||||
onClick={() => handleOrientationChange('sagittal')}
|
||||
>
|
||||
Sagittal
|
||||
</Button>
|
||||
<Button
|
||||
variant="ghost"
|
||||
className="justify-start"
|
||||
onClick={() => handleOrientationChange('coronal')}
|
||||
>
|
||||
Coronal
|
||||
</Button>
|
||||
<Button
|
||||
variant="ghost"
|
||||
className="justify-start"
|
||||
onClick={() => handleOrientationChange('acquisition')}
|
||||
>
|
||||
Acquisition
|
||||
</Button>
|
||||
</div>
|
||||
</PopoverContent>
|
||||
</Popover>
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
+22
-20
@@ -1,27 +1,29 @@
|
||||
import React, { ReactNode } from 'react';
|
||||
import { useViewportGrid } from '@ohif/ui-next';
|
||||
import { cn } from '@ohif/ui-next';
|
||||
import ViewportOrientationMenu from './ViewportOrientationMenu';
|
||||
import { useViewportDisplaySets } from '../../hooks/useViewportDisplaySets';
|
||||
|
||||
export function ViewportOrientationMenuWrapper({
|
||||
viewportId,
|
||||
location,
|
||||
}: withAppTypes<{
|
||||
viewportId: string;
|
||||
element: HTMLElement;
|
||||
location: string;
|
||||
}>): ReactNode {
|
||||
const [viewportGrid] = useViewportGrid();
|
||||
const isActiveViewport = viewportId === viewportGrid.activeViewportId;
|
||||
export function ViewportOrientationMenuWrapper(
|
||||
props: withAppTypes<{
|
||||
viewportId: string;
|
||||
location: string;
|
||||
isOpen?: boolean;
|
||||
onOpen?: () => void;
|
||||
onClose?: () => void;
|
||||
iconSize?: number;
|
||||
disabled?: boolean;
|
||||
}>
|
||||
): ReactNode {
|
||||
const { viewportId } = props;
|
||||
const { viewportDisplaySets } = useViewportDisplaySets(viewportId);
|
||||
|
||||
if (!viewportDisplaySets.length) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (
|
||||
<div
|
||||
className={cn(
|
||||
'flex justify-end',
|
||||
isActiveViewport ? 'visible' : 'invisible group-hover/pane:visible'
|
||||
)}
|
||||
>
|
||||
<ViewportOrientationMenu location={location} />
|
||||
</div>
|
||||
<ViewportOrientationMenu
|
||||
{...props}
|
||||
displaySets={viewportDisplaySets}
|
||||
/>
|
||||
);
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
import React, { ReactNode } from 'react';
|
||||
import { ViewportOrientationMenuWrapper } from './ViewportOrientationMenuWrapper';
|
||||
|
||||
export function getViewportOrientationMenu(
|
||||
props: withAppTypes<{
|
||||
viewportId: string;
|
||||
element: HTMLElement;
|
||||
location: string;
|
||||
}>
|
||||
): ReactNode {
|
||||
return <ViewportOrientationMenuWrapper {...props} />;
|
||||
}
|
||||
|
||||
export * from './ViewportOrientationMenu';
|
||||
@@ -2,7 +2,7 @@ import React, { useEffect, useCallback, useState, ReactElement, useMemo } from '
|
||||
import PropTypes from 'prop-types';
|
||||
import debounce from 'lodash.debounce';
|
||||
import { PanelSection, WindowLevel } from '@ohif/ui-next';
|
||||
import { Enums, eventTarget } from '@cornerstonejs/core';
|
||||
import { BaseVolumeViewport, Enums, eventTarget } from '@cornerstonejs/core';
|
||||
import { useActiveViewportDisplaySets } from '@ohif/core';
|
||||
import {
|
||||
getNodeOpacity,
|
||||
@@ -22,7 +22,7 @@ const ViewportWindowLevel = ({
|
||||
const { cornerstoneViewportService } = servicesManager.services;
|
||||
const [windowLevels, setWindowLevels] = useState<any[]>([]);
|
||||
const [isLoading, setIsLoading] = useState(true);
|
||||
const displaySets = useActiveViewportDisplaySets({ servicesManager });
|
||||
const displaySets = useActiveViewportDisplaySets();
|
||||
|
||||
const getViewportsWithVolumeIds = useCallback(
|
||||
(volumeIds: string[]) => {
|
||||
@@ -30,7 +30,7 @@ const ViewportWindowLevel = ({
|
||||
const viewports = renderingEngine.getVolumeViewports();
|
||||
|
||||
return viewports.filter(vp => {
|
||||
const viewportVolumeIds = vp.getActors().map(actor => actor.referencedId);
|
||||
const viewportVolumeIds = vp instanceof BaseVolumeViewport ? vp.getAllVolumeIds() : [];
|
||||
return (
|
||||
volumeIds.length === viewportVolumeIds.length &&
|
||||
volumeIds.every(volumeId => viewportVolumeIds.includes(volumeId))
|
||||
@@ -124,7 +124,8 @@ const ViewportWindowLevel = ({
|
||||
return;
|
||||
}
|
||||
|
||||
const viewportVolumeIds = viewport.getActors().map(actor => actor.referencedId);
|
||||
const viewportVolumeIds =
|
||||
viewport instanceof BaseVolumeViewport ? viewport.getAllVolumeIds() : [];
|
||||
const viewports = getViewportsWithVolumeIds(viewportVolumeIds);
|
||||
|
||||
viewports.forEach(vp => {
|
||||
|
||||
@@ -1,103 +1,27 @@
|
||||
import React, { ReactElement, useCallback, useEffect, useState } from 'react';
|
||||
import React, { ReactElement, useCallback } from 'react';
|
||||
import { Switch } from '@ohif/ui-next';
|
||||
import { ColorbarProps, ColorbarOptions } from '../../types/Colorbar';
|
||||
import { utilities } from '@cornerstonejs/core';
|
||||
import { useSystem } from '@ohif/core';
|
||||
import { useViewportRendering } from '../../hooks/useViewportRendering';
|
||||
|
||||
export function setViewportColorbar(
|
||||
viewportId: string,
|
||||
commandsManager: any,
|
||||
servicesManager: AppTypes.ServicesManager,
|
||||
colorbarOptions: Partial<ColorbarOptions>
|
||||
) {
|
||||
const { cornerstoneViewportService, viewportGridService } = servicesManager.services;
|
||||
const displaySetInstanceUIDs = viewportGridService.getDisplaySetsUIDsForViewport(viewportId);
|
||||
export function Colorbar({ viewportId }: { viewportId?: string } = {}): ReactElement {
|
||||
const { hasColorbar, toggleColorbar } = useViewportRendering(viewportId);
|
||||
|
||||
const viewportInfo = cornerstoneViewportService.getViewportInfo(viewportId);
|
||||
const backgroundColor = viewportInfo.getViewportOptions().background;
|
||||
const isLight = backgroundColor ? utilities.isEqual(backgroundColor, [1, 1, 1]) : false;
|
||||
|
||||
if (isLight) {
|
||||
colorbarOptions.ticks = {
|
||||
position: 'left',
|
||||
style: {
|
||||
font: '13px Inter',
|
||||
color: '#000000',
|
||||
maxNumTicks: 8,
|
||||
tickSize: 5,
|
||||
tickWidth: 1,
|
||||
labelMargin: 3,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
commandsManager.run('toggleViewportColorbar', {
|
||||
viewportId,
|
||||
options: colorbarOptions,
|
||||
displaySetInstanceUIDs,
|
||||
});
|
||||
}
|
||||
|
||||
export function Colorbar({
|
||||
viewportId,
|
||||
colorbarProperties,
|
||||
}: withAppTypes<ColorbarProps>): ReactElement {
|
||||
const { servicesManager, commandsManager } = useSystem();
|
||||
const { colorbarService } = servicesManager.services;
|
||||
const {
|
||||
width: colorbarWidth,
|
||||
colorbarTickPosition,
|
||||
colorbarContainerPosition,
|
||||
colormaps,
|
||||
colorbarInitialColormap,
|
||||
} = colorbarProperties;
|
||||
const [showColorbar, setShowColorbar] = useState(colorbarService.hasColorbar(viewportId));
|
||||
|
||||
const onSetColorbar = useCallback(() => {
|
||||
setViewportColorbar(viewportId, commandsManager, servicesManager, {
|
||||
viewportId,
|
||||
colormaps,
|
||||
ticks: {
|
||||
position: colorbarTickPosition,
|
||||
},
|
||||
width: colorbarWidth,
|
||||
position: colorbarContainerPosition,
|
||||
activeColormapName: colorbarInitialColormap,
|
||||
});
|
||||
}, [commandsManager]);
|
||||
|
||||
useEffect(() => {
|
||||
const updateColorbarState = () => {
|
||||
setShowColorbar(colorbarService.hasColorbar(viewportId));
|
||||
};
|
||||
|
||||
const { unsubscribe } = colorbarService.subscribe(
|
||||
colorbarService.EVENTS.STATE_CHANGED,
|
||||
updateColorbarState
|
||||
);
|
||||
|
||||
return () => {
|
||||
unsubscribe();
|
||||
};
|
||||
}, [viewportId]);
|
||||
const handleToggle = useCallback(() => {
|
||||
toggleColorbar();
|
||||
}, [toggleColorbar]);
|
||||
|
||||
return (
|
||||
<div
|
||||
className="hover:bg-accent flex h-8 w-full flex-shrink-0 cursor-pointer items-center px-2 text-base hover:rounded"
|
||||
onClick={e => {
|
||||
e.stopPropagation();
|
||||
onSetColorbar();
|
||||
}}
|
||||
>
|
||||
<div className="hover:bg-accent flex h-8 w-full flex-shrink-0 cursor-pointer items-center px-2 text-base hover:rounded">
|
||||
<div className="flex w-7 flex-shrink-0 items-center justify-center"></div>
|
||||
<span className="flex-grow">Display Color bar</span>
|
||||
<span
|
||||
className="flex-grow"
|
||||
onClick={handleToggle}
|
||||
>
|
||||
Display Color bar
|
||||
</span>
|
||||
<Switch
|
||||
className="ml-2 flex-shrink-0"
|
||||
checked={showColorbar}
|
||||
onClick={e => {
|
||||
e.stopPropagation();
|
||||
onSetColorbar();
|
||||
}}
|
||||
checked={!!hasColorbar}
|
||||
onCheckedChange={handleToggle}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
|
||||
@@ -1,91 +1,66 @@
|
||||
import React, { ReactElement, useCallback, useEffect, useRef, useState } from 'react';
|
||||
import { AllInOneMenu, Switch, Tabs, TabsList, TabsTrigger } from '@ohif/ui-next';
|
||||
import React, { ReactElement, useEffect, useRef, useState } from 'react';
|
||||
import { AllInOneMenu, ScrollArea, Switch, Tabs, TabsList, TabsTrigger } from '@ohif/ui-next';
|
||||
import { useViewportRendering } from '../../hooks/useViewportRendering';
|
||||
|
||||
import { StackViewport, Types } from '@cornerstonejs/core';
|
||||
import { ColormapProps } from '../../types/Colormap';
|
||||
import { useSystem } from '@ohif/core';
|
||||
export function Colormap({ viewportId }: { viewportId?: string } = {}): ReactElement {
|
||||
const { viewportDisplaySets } = useViewportRendering(viewportId);
|
||||
|
||||
export function Colormap({ colormaps, viewportId, displaySets }: ColormapProps): ReactElement {
|
||||
const { servicesManager, commandsManager } = useSystem();
|
||||
const { cornerstoneViewportService } = servicesManager.services;
|
||||
const [activeDisplaySetUID, setActiveDisplaySetUID] = useState<string | undefined>(
|
||||
viewportDisplaySets?.[0]?.displaySetInstanceUID
|
||||
);
|
||||
|
||||
const [activeDisplaySet, setActiveDisplaySet] = useState(displaySets[0]);
|
||||
// Use the hook with the active display set
|
||||
const { colorbarProperties, setColormap } = useViewportRendering(viewportId, {
|
||||
displaySetInstanceUID: activeDisplaySetUID,
|
||||
});
|
||||
|
||||
const { colormaps } = colorbarProperties;
|
||||
|
||||
const [showPreview, setShowPreview] = useState(false);
|
||||
const [prePreviewColormap, setPrePreviewColormap] = useState(null);
|
||||
const [currentColormap, setCurrentColormap] = useState(null);
|
||||
|
||||
const showPreviewRef = useRef(showPreview);
|
||||
showPreviewRef.current = showPreview;
|
||||
const prePreviewColormapRef = useRef(prePreviewColormap);
|
||||
prePreviewColormapRef.current = prePreviewColormap;
|
||||
const activeDisplaySetRef = useRef(activeDisplaySet);
|
||||
activeDisplaySetRef.current = activeDisplaySet;
|
||||
|
||||
const onSetColorLUT = useCallback(
|
||||
props => {
|
||||
// TODO: Better way to check if it's a fusion
|
||||
const oneOpacityColormaps = ['Grayscale', 'X Ray'];
|
||||
const opacity =
|
||||
displaySets.length > 1 && !oneOpacityColormaps.includes(props.colormap.name) ? 0.5 : 1;
|
||||
commandsManager.run({
|
||||
commandName: 'setViewportColormap',
|
||||
commandOptions: {
|
||||
...props,
|
||||
opacity,
|
||||
immediate: true,
|
||||
},
|
||||
context: 'CORNERSTONE',
|
||||
});
|
||||
},
|
||||
[commandsManager]
|
||||
);
|
||||
|
||||
const getViewportColormap = (viewportId, displaySet) => {
|
||||
const { displaySetInstanceUID } = displaySet;
|
||||
const viewport = cornerstoneViewportService.getCornerstoneViewport(viewportId);
|
||||
if (viewport instanceof StackViewport) {
|
||||
const { colormap } = viewport.getProperties();
|
||||
if (!colormap) {
|
||||
return colormaps.find(c => c.Name === 'Grayscale') || colormaps[0];
|
||||
}
|
||||
return colormap;
|
||||
}
|
||||
const actorEntries = viewport.getActors();
|
||||
const actorEntry = actorEntries?.find(entry =>
|
||||
entry.referencedId.includes(displaySetInstanceUID)
|
||||
);
|
||||
const { colormap } = (viewport as Types.IVolumeViewport).getProperties(actorEntry.referencedId);
|
||||
if (!colormap) {
|
||||
return colormaps.find(c => c.Name === 'Grayscale') || colormaps[0];
|
||||
}
|
||||
return colormap;
|
||||
};
|
||||
|
||||
const activeIndex = displaySets.findIndex(
|
||||
ds => ds.displaySetInstanceUID === activeDisplaySetRef.current.displaySetInstanceUID
|
||||
);
|
||||
const currentColormapRef = useRef(currentColormap);
|
||||
currentColormapRef.current = currentColormap;
|
||||
|
||||
useEffect(() => {
|
||||
setActiveDisplaySet(displaySets[displaySets.length - 1]);
|
||||
}, [displaySets]);
|
||||
setCurrentColormap(null);
|
||||
setPrePreviewColormap(null);
|
||||
}, [activeDisplaySetUID]);
|
||||
|
||||
const handleSetColorLUT = (colormap, immediate = true) => {
|
||||
// Check if it's a fusion viewport
|
||||
const oneOpacityColormaps = ['Grayscale', 'X Ray'];
|
||||
const opacity =
|
||||
viewportDisplaySets.length > 1 && !oneOpacityColormaps.includes(colormap.name) ? 0.5 : 1;
|
||||
|
||||
setColormap({
|
||||
colormap,
|
||||
opacity,
|
||||
immediate,
|
||||
});
|
||||
};
|
||||
|
||||
return (
|
||||
<>
|
||||
{displaySets.length > 1 && (
|
||||
{viewportDisplaySets && viewportDisplaySets.length > 1 && (
|
||||
<div className="flex h-8 w-full flex-shrink-0 items-center justify-center px-2 text-base">
|
||||
<Tabs
|
||||
value={String(activeIndex)}
|
||||
onValueChange={val => {
|
||||
const index = parseInt(val, 10);
|
||||
setActiveDisplaySet(displaySets[index]);
|
||||
value={activeDisplaySetUID}
|
||||
onValueChange={displaySetUID => {
|
||||
setActiveDisplaySetUID(displaySetUID);
|
||||
setPrePreviewColormap(null);
|
||||
}}
|
||||
>
|
||||
<TabsList>
|
||||
{displaySets.map((ds, i) => (
|
||||
{viewportDisplaySets.map(ds => (
|
||||
<TabsTrigger
|
||||
key={i}
|
||||
value={String(i)}
|
||||
key={ds.displaySetInstanceUID}
|
||||
value={ds.displaySetInstanceUID}
|
||||
>
|
||||
{ds.Modality}
|
||||
</TabsTrigger>
|
||||
@@ -94,6 +69,7 @@ export function Colormap({ colormaps, viewportId, displaySets }: ColormapProps):
|
||||
</Tabs>
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div
|
||||
className="hover:bg-accent flex h-8 w-full flex-shrink-0 cursor-pointer items-center px-2 text-base hover:rounded"
|
||||
onClick={() => setShowPreview(!showPreview)}
|
||||
@@ -104,49 +80,47 @@ export function Colormap({ colormaps, viewportId, displaySets }: ColormapProps):
|
||||
checked={showPreview}
|
||||
onCheckedChange={checked => {
|
||||
setShowPreview(checked);
|
||||
|
||||
if (!checked && currentColormapRef.current) {
|
||||
handleSetColorLUT(currentColormapRef.current);
|
||||
}
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<AllInOneMenu.DividerItem />
|
||||
<AllInOneMenu.ItemPanel
|
||||
maxHeight="calc(100vh - 250px)"
|
||||
className="min-h-[200px] flex-grow"
|
||||
>
|
||||
{colormaps.map((colormap, index) => (
|
||||
<AllInOneMenu.Item
|
||||
key={index}
|
||||
label={colormap.description}
|
||||
useIconSpace={false}
|
||||
onClick={() => {
|
||||
onSetColorLUT({
|
||||
viewportId,
|
||||
colormap,
|
||||
displaySetInstanceUID: activeDisplaySetRef.current.displaySetInstanceUID,
|
||||
});
|
||||
setPrePreviewColormap(null);
|
||||
}}
|
||||
onMouseEnter={() => {
|
||||
if (showPreviewRef.current) {
|
||||
setPrePreviewColormap(getViewportColormap(viewportId, activeDisplaySetRef.current));
|
||||
onSetColorLUT({
|
||||
viewportId,
|
||||
colormap,
|
||||
displaySetInstanceUID: activeDisplaySetRef.current.displaySetInstanceUID,
|
||||
});
|
||||
}
|
||||
}}
|
||||
onMouseLeave={() => {
|
||||
if (showPreviewRef.current && prePreviewColormapRef.current) {
|
||||
onSetColorLUT({
|
||||
viewportId,
|
||||
colormap: prePreviewColormapRef.current,
|
||||
displaySetInstanceUID: activeDisplaySetRef.current.displaySetInstanceUID,
|
||||
});
|
||||
}
|
||||
}}
|
||||
></AllInOneMenu.Item>
|
||||
))}
|
||||
</AllInOneMenu.ItemPanel>
|
||||
|
||||
<div className="h-[300px] flex-grow">
|
||||
<ScrollArea className="h-full w-full">
|
||||
<div className="p-1">
|
||||
{colormaps.map((colormap, index) => (
|
||||
<AllInOneMenu.Item
|
||||
key={index}
|
||||
label={colormap.description}
|
||||
useIconSpace={false}
|
||||
onClick={() => {
|
||||
setCurrentColormap(colormap);
|
||||
handleSetColorLUT(colormap);
|
||||
setPrePreviewColormap(null);
|
||||
}}
|
||||
onMouseEnter={() => {
|
||||
if (showPreviewRef.current) {
|
||||
if (!prePreviewColormapRef.current) {
|
||||
setPrePreviewColormap(colormap);
|
||||
}
|
||||
handleSetColorLUT(colormap);
|
||||
}
|
||||
}}
|
||||
onMouseLeave={() => {
|
||||
if (showPreviewRef.current && prePreviewColormapRef.current) {
|
||||
handleSetColorLUT(prePreviewColormapRef.current);
|
||||
}
|
||||
}}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
</ScrollArea>
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
}
|
||||
+3
-5
@@ -1,15 +1,13 @@
|
||||
import React, { ReactElement, useState } from 'react';
|
||||
import { AllInOneMenu } from '@ohif/ui-next';
|
||||
import { VolumeRenderingOptionsProps } from '../../types/ViewportPresets';
|
||||
import { VolumeRenderingQuality } from './VolumeRenderingQuality';
|
||||
import { VolumeShift } from './VolumeShift';
|
||||
import { VolumeLighting } from './VolumeLighting';
|
||||
import { VolumeShade } from './VolumeShade';
|
||||
import { useViewportRendering } from '../../hooks/useViewportRendering';
|
||||
|
||||
export function VolumeRenderingOptions({
|
||||
viewportId,
|
||||
volumeRenderingQualityRange,
|
||||
}: VolumeRenderingOptionsProps): ReactElement {
|
||||
export function VolumeRenderingOptions({ viewportId }: { viewportId?: string } = {}): ReactElement {
|
||||
const { volumeRenderingQualityRange } = useViewportRendering(viewportId);
|
||||
const [hasShade, setShade] = useState(false);
|
||||
return (
|
||||
<AllInOneMenu.ItemPanel>
|
||||
|
||||
+3
-5
@@ -1,14 +1,12 @@
|
||||
import { AllInOneMenu } from '@ohif/ui-next';
|
||||
import { Icons } from '@ohif/ui-next';
|
||||
import React, { ReactElement } from 'react';
|
||||
import { VolumeRenderingPresetsProps } from '../../types/ViewportPresets';
|
||||
import { VolumeRenderingPresetsContent } from './VolumeRenderingPresetsContent';
|
||||
import { useSystem } from '@ohif/core';
|
||||
import { useViewportRendering } from '../../hooks/useViewportRendering';
|
||||
|
||||
export function VolumeRenderingPresets({
|
||||
viewportId,
|
||||
volumeRenderingPresets,
|
||||
}: VolumeRenderingPresetsProps): ReactElement {
|
||||
export function VolumeRenderingPresets({ viewportId }: { viewportId?: string } = {}): ReactElement {
|
||||
const { volumeRenderingPresets } = useViewportRendering(viewportId);
|
||||
const { servicesManager } = useSystem();
|
||||
const { uiDialogService } = servicesManager.services;
|
||||
|
||||
|
||||
@@ -1,54 +1,122 @@
|
||||
import React, { ReactElement, useCallback } from 'react';
|
||||
import { AllInOneMenu } from '@ohif/ui-next';
|
||||
import React, { ReactElement, useEffect, useRef, useState } from 'react';
|
||||
import { AllInOneMenu, ScrollArea, Switch, Tabs, TabsList, TabsTrigger } from '@ohif/ui-next';
|
||||
import { useViewportRendering } from '../../hooks/useViewportRendering';
|
||||
import { WindowLevelPreset } from '../../types/WindowLevel';
|
||||
import { useSystem } from '@ohif/core';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
|
||||
export type WindowLevelProps = {
|
||||
viewportId: string;
|
||||
presets: Array<Record<string, Array<WindowLevelPreset>>>;
|
||||
};
|
||||
|
||||
export function WindowLevel({ viewportId, presets }: WindowLevelProps): ReactElement {
|
||||
const { commandsManager } = useSystem();
|
||||
const { t } = useTranslation('WindowLevelActionMenu');
|
||||
|
||||
const onSetWindowLevel = useCallback(
|
||||
props => {
|
||||
commandsManager.run({
|
||||
commandName: 'setViewportWindowLevel',
|
||||
commandOptions: {
|
||||
...props,
|
||||
viewportId,
|
||||
},
|
||||
context: 'CORNERSTONE',
|
||||
});
|
||||
},
|
||||
[commandsManager, viewportId]
|
||||
export function WindowLevel({ viewportId }: { viewportId?: string } = {}): ReactElement {
|
||||
const { viewportDisplaySets } = useViewportRendering(viewportId);
|
||||
const [activeDisplaySetUID, setActiveDisplaySetUID] = useState<string | undefined>(
|
||||
viewportDisplaySets?.[0]?.displaySetInstanceUID
|
||||
);
|
||||
|
||||
// Use the hook with the active display set
|
||||
const { windowLevelPresets, setWindowLevel } = useViewportRendering(viewportId, {
|
||||
displaySetInstanceUID: activeDisplaySetUID,
|
||||
});
|
||||
|
||||
const [showPreview, setShowPreview] = useState(false);
|
||||
const [prePreviewPreset, setPrePreviewPreset] = useState<WindowLevelPreset | null>(null);
|
||||
const [currentPreset, setCurrentPreset] = useState<WindowLevelPreset | null>(null);
|
||||
|
||||
const showPreviewRef = useRef(showPreview);
|
||||
showPreviewRef.current = showPreview;
|
||||
const prePreviewPresetRef = useRef(prePreviewPreset);
|
||||
prePreviewPresetRef.current = prePreviewPreset;
|
||||
const currentPresetRef = useRef(currentPreset);
|
||||
currentPresetRef.current = currentPreset;
|
||||
|
||||
// Reset presets when active display set changes
|
||||
useEffect(() => {
|
||||
setCurrentPreset(null);
|
||||
setPrePreviewPreset(null);
|
||||
}, [activeDisplaySetUID]);
|
||||
|
||||
// Handle applying window level preset
|
||||
const handleSetWindowLevel = (preset: WindowLevelPreset, immediate = false) => {
|
||||
setWindowLevel({
|
||||
windowWidth: Number(preset.window),
|
||||
windowCenter: Number(preset.level),
|
||||
immediate,
|
||||
});
|
||||
};
|
||||
|
||||
return (
|
||||
<AllInOneMenu.ItemPanel>
|
||||
{presets.map((modalityPresets, modalityIndex) => (
|
||||
<React.Fragment key={modalityIndex}>
|
||||
{Object.entries(modalityPresets).map(([modality, presetsArray]) => (
|
||||
<React.Fragment key={modality}>
|
||||
<AllInOneMenu.HeaderItem>
|
||||
{t('Modality Presets', { modality })}
|
||||
</AllInOneMenu.HeaderItem>
|
||||
{presetsArray.map((preset, index) => (
|
||||
<AllInOneMenu.Item
|
||||
key={`${modality}-${index}`}
|
||||
label={preset.description}
|
||||
secondaryLabel={`${preset.window} / ${preset.level}`}
|
||||
useIconSpace={false}
|
||||
onClick={() => onSetWindowLevel(preset)}
|
||||
/>
|
||||
<>
|
||||
{viewportDisplaySets && viewportDisplaySets.length > 1 && (
|
||||
<div className="flex h-8 w-full flex-shrink-0 items-center justify-center px-2 text-base">
|
||||
<Tabs
|
||||
value={activeDisplaySetUID}
|
||||
onValueChange={displaySetUID => {
|
||||
setActiveDisplaySetUID(displaySetUID);
|
||||
}}
|
||||
>
|
||||
<TabsList>
|
||||
{viewportDisplaySets.map(ds => (
|
||||
<TabsTrigger
|
||||
key={ds.displaySetInstanceUID}
|
||||
value={ds.displaySetInstanceUID}
|
||||
>
|
||||
{ds.Modality}
|
||||
</TabsTrigger>
|
||||
))}
|
||||
</React.Fragment>
|
||||
))}
|
||||
</React.Fragment>
|
||||
))}
|
||||
</AllInOneMenu.ItemPanel>
|
||||
</TabsList>
|
||||
</Tabs>
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div
|
||||
className="hover:bg-accent flex h-8 w-full flex-shrink-0 cursor-pointer items-center px-2 text-base hover:rounded"
|
||||
onClick={() => setShowPreview(!showPreview)}
|
||||
>
|
||||
<span className="flex-shrink-0">Preview in viewport</span>
|
||||
<Switch
|
||||
className="ml-auto flex-shrink-0"
|
||||
checked={showPreview}
|
||||
onCheckedChange={checked => {
|
||||
setShowPreview(checked);
|
||||
|
||||
// When turning off preview, restore the current preset if one exists
|
||||
if (!checked && currentPresetRef.current) {
|
||||
handleSetWindowLevel(currentPresetRef.current, true);
|
||||
}
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<AllInOneMenu.DividerItem />
|
||||
|
||||
<div className="h-[175px] flex-grow">
|
||||
<ScrollArea className="h-full w-full">
|
||||
<div className="p-1">
|
||||
{windowLevelPresets.map((preset, index) => (
|
||||
<AllInOneMenu.Item
|
||||
key={index}
|
||||
label={preset.description}
|
||||
secondaryLabel={`${preset.window} / ${preset.level}`}
|
||||
useIconSpace={false}
|
||||
onClick={() => {
|
||||
setCurrentPreset(preset);
|
||||
handleSetWindowLevel(preset, true);
|
||||
setPrePreviewPreset(null);
|
||||
}}
|
||||
onMouseEnter={() => {
|
||||
if (showPreviewRef.current) {
|
||||
if (!prePreviewPresetRef.current) {
|
||||
setPrePreviewPreset(currentPresetRef.current || preset);
|
||||
}
|
||||
handleSetWindowLevel(preset, true);
|
||||
}
|
||||
}}
|
||||
onMouseLeave={() => {
|
||||
if (showPreviewRef.current && prePreviewPresetRef.current) {
|
||||
handleSetWindowLevel(prePreviewPresetRef.current, true);
|
||||
}
|
||||
}}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
</ScrollArea>
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
}
|
||||
+43
-124
@@ -1,114 +1,55 @@
|
||||
import React, { ReactElement, useCallback, useEffect, useState } from 'react';
|
||||
import React, { ReactElement, useMemo } from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { AllInOneMenu, cn } from '@ohif/ui-next';
|
||||
import { useViewportGrid } from '@ohif/ui-next';
|
||||
import { AllInOneMenu } from '@ohif/ui-next';
|
||||
import { Colormap } from './Colormap';
|
||||
import { Colorbar } from './Colorbar';
|
||||
import { setViewportColorbar } from './Colorbar';
|
||||
import { WindowLevelPreset } from '../../types/WindowLevel';
|
||||
import { ColorbarProperties } from '../../types/Colorbar';
|
||||
import { VolumeRenderingQualityRange } from '../../types/ViewportPresets';
|
||||
import { WindowLevel } from './WindowLevel';
|
||||
import { VolumeRenderingPresets } from './VolumeRenderingPresets';
|
||||
import { VolumeRenderingOptions } from './VolumeRenderingOptions';
|
||||
import { ViewportPreset } from '../../types/ViewportPresets';
|
||||
import { VolumeViewport3D } from '@cornerstonejs/core';
|
||||
import { utilities } from '@cornerstonejs/core';
|
||||
import { useSystem } from '@ohif/core';
|
||||
import { useViewportRendering } from '../../hooks/useViewportRendering';
|
||||
|
||||
export type WindowLevelActionMenuProps = {
|
||||
viewportId: string;
|
||||
element: HTMLElement;
|
||||
presets: Array<Record<string, Array<WindowLevelPreset>>>;
|
||||
colorbarProperties: ColorbarProperties;
|
||||
displaySets: Array<any>;
|
||||
volumeRenderingPresets: Array<ViewportPreset>;
|
||||
volumeRenderingQualityRange: VolumeRenderingQualityRange;
|
||||
location: string;
|
||||
element?: HTMLElement;
|
||||
align?: 'start' | 'end' | 'center';
|
||||
side?: 'top' | 'bottom' | 'left' | 'right';
|
||||
};
|
||||
|
||||
export function WindowLevelActionMenu({
|
||||
viewportId,
|
||||
element,
|
||||
presets,
|
||||
verticalDirection,
|
||||
horizontalDirection,
|
||||
colorbarProperties,
|
||||
displaySets,
|
||||
volumeRenderingPresets,
|
||||
volumeRenderingQualityRange,
|
||||
}: withAppTypes<WindowLevelActionMenuProps>): ReactElement {
|
||||
const { commandsManager, servicesManager } = useSystem();
|
||||
const {
|
||||
colormaps,
|
||||
colorbarContainerPosition,
|
||||
colorbarInitialColormap,
|
||||
colorbarTickPosition,
|
||||
width: colorbarWidth,
|
||||
} = colorbarProperties;
|
||||
|
||||
const { colorbarService, cornerstoneViewportService } = servicesManager.services;
|
||||
const viewportInfo = cornerstoneViewportService.getViewportInfo(viewportId);
|
||||
const viewport = cornerstoneViewportService.getCornerstoneViewport(viewportId);
|
||||
const backgroundColor = viewportInfo?.getViewportOptions().background;
|
||||
const isLight = backgroundColor ? utilities.isEqual(backgroundColor, [1, 1, 1]) : false;
|
||||
align,
|
||||
side,
|
||||
}: WindowLevelActionMenuProps): ReactElement {
|
||||
return (
|
||||
<WindowLevelActionMenuContent
|
||||
viewportId={viewportId}
|
||||
align={align}
|
||||
side={side}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
export function WindowLevelActionMenuContent({
|
||||
viewportId,
|
||||
align,
|
||||
side,
|
||||
}: {
|
||||
viewportId: string;
|
||||
align?: string;
|
||||
side?: string;
|
||||
}): ReactElement {
|
||||
const { t } = useTranslation('WindowLevelActionMenu');
|
||||
// Use a stable key for the menu to avoid infinite re-renders
|
||||
const menuKey = useMemo(() => `${viewportId}`, [viewportId]);
|
||||
|
||||
const [viewportGrid] = useViewportGrid();
|
||||
const { activeViewportId } = viewportGrid;
|
||||
|
||||
const [vpHeight, setVpHeight] = useState(element?.clientHeight);
|
||||
const [menuKey, setMenuKey] = useState(0);
|
||||
const [is3DVolume, setIs3DVolume] = useState(false);
|
||||
|
||||
const onSetColorbar = useCallback(() => {
|
||||
setViewportColorbar(viewportId, commandsManager, servicesManager, {
|
||||
colormaps,
|
||||
ticks: {
|
||||
position: colorbarTickPosition,
|
||||
},
|
||||
width: colorbarWidth,
|
||||
position: colorbarContainerPosition,
|
||||
activeColormapName: colorbarInitialColormap,
|
||||
});
|
||||
}, [commandsManager]);
|
||||
|
||||
useEffect(() => {
|
||||
const newVpHeight = element?.clientHeight;
|
||||
if (vpHeight !== newVpHeight) {
|
||||
setVpHeight(newVpHeight);
|
||||
}
|
||||
}, [element, vpHeight]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!colorbarService.hasColorbar(viewportId)) {
|
||||
return;
|
||||
}
|
||||
window.setTimeout(() => {
|
||||
colorbarService.removeColorbar(viewportId);
|
||||
onSetColorbar();
|
||||
}, 0);
|
||||
}, [viewportId, displaySets, viewport]);
|
||||
|
||||
useEffect(() => {
|
||||
setMenuKey(menuKey + 1);
|
||||
const viewport = cornerstoneViewportService.getCornerstoneViewport(viewportId);
|
||||
if (viewport instanceof VolumeViewport3D) {
|
||||
setIs3DVolume(true);
|
||||
} else {
|
||||
setIs3DVolume(false);
|
||||
}
|
||||
}, [
|
||||
displaySets,
|
||||
viewportId,
|
||||
presets,
|
||||
volumeRenderingQualityRange,
|
||||
volumeRenderingPresets,
|
||||
const {
|
||||
is3DVolume,
|
||||
colorbarProperties,
|
||||
activeViewportId,
|
||||
viewportGrid,
|
||||
]);
|
||||
windowLevelPresets,
|
||||
volumeRenderingPresets,
|
||||
volumeRenderingQualityRange,
|
||||
} = useViewportRendering(viewportId);
|
||||
|
||||
return (
|
||||
<AllInOneMenu.Menu
|
||||
@@ -116,60 +57,38 @@ export function WindowLevelActionMenu({
|
||||
key={menuKey}
|
||||
// the visibility is handled by the parent component
|
||||
isVisible={true}
|
||||
horizontalDirection={horizontalDirection}
|
||||
verticalDirection={verticalDirection}
|
||||
align={align}
|
||||
side={side}
|
||||
>
|
||||
<AllInOneMenu.ItemPanel>
|
||||
{!is3DVolume && (
|
||||
<Colorbar
|
||||
viewportId={viewportId}
|
||||
displaySets={displaySets.filter(ds => ds.supportsWindowLevel === true)}
|
||||
colorbarProperties={colorbarProperties}
|
||||
/>
|
||||
)}
|
||||
{!is3DVolume && <Colorbar viewportId={viewportId} />}
|
||||
|
||||
{colormaps && !is3DVolume && (
|
||||
{colorbarProperties?.colormaps && !is3DVolume && (
|
||||
<AllInOneMenu.SubMenu
|
||||
key="colorLUTPresets"
|
||||
itemLabel="Color LUT"
|
||||
itemIcon="icon-color-lut"
|
||||
className="flex h-[calc(100%-32px)] flex-col"
|
||||
>
|
||||
<Colormap
|
||||
className="flex h-full w-full flex-col"
|
||||
colormaps={colormaps}
|
||||
viewportId={viewportId}
|
||||
displaySets={displaySets.filter(ds => ds.supportsWindowLevel === true)}
|
||||
/>
|
||||
<Colormap viewportId={viewportId} />
|
||||
</AllInOneMenu.SubMenu>
|
||||
)}
|
||||
|
||||
{presets && presets.length > 0 && !is3DVolume && (
|
||||
{windowLevelPresets?.length > 0 && !is3DVolume && (
|
||||
<AllInOneMenu.SubMenu
|
||||
key="windowLevelPresets"
|
||||
itemLabel={t('Modality Window Presets')}
|
||||
itemIcon="viewport-window-level"
|
||||
>
|
||||
<WindowLevel
|
||||
viewportId={viewportId}
|
||||
presets={presets}
|
||||
/>
|
||||
<WindowLevel viewportId={viewportId} />
|
||||
</AllInOneMenu.SubMenu>
|
||||
)}
|
||||
|
||||
{volumeRenderingPresets && is3DVolume && (
|
||||
<VolumeRenderingPresets
|
||||
viewportId={viewportId}
|
||||
volumeRenderingPresets={volumeRenderingPresets}
|
||||
/>
|
||||
)}
|
||||
{volumeRenderingPresets && is3DVolume && <VolumeRenderingPresets viewportId={viewportId} />}
|
||||
|
||||
{volumeRenderingQualityRange && is3DVolume && (
|
||||
<AllInOneMenu.SubMenu itemLabel="Rendering Options">
|
||||
<VolumeRenderingOptions
|
||||
viewportId={viewportId}
|
||||
volumeRenderingQualityRange={volumeRenderingQualityRange}
|
||||
/>
|
||||
<VolumeRenderingOptions viewportId={viewportId} />
|
||||
</AllInOneMenu.SubMenu>
|
||||
)}
|
||||
</AllInOneMenu.ItemPanel>
|
||||
|
||||
+82
-87
@@ -2,63 +2,75 @@ import React, { ReactNode } from 'react';
|
||||
import { useSystem } from '@ohif/core';
|
||||
import {
|
||||
Button,
|
||||
cn,
|
||||
Icons,
|
||||
Popover,
|
||||
PopoverContent,
|
||||
PopoverTrigger,
|
||||
useViewportGrid,
|
||||
useViewportActionCorners,
|
||||
AllInOneMenu,
|
||||
useIconPresentation,
|
||||
} from '@ohif/ui-next';
|
||||
import { WindowLevelActionMenu } from './WindowLevelActionMenu';
|
||||
import { MENU_IDS } from '../menus/menu-ids';
|
||||
import { useViewportDisplaySets } from '../../hooks/useViewportDisplaySets';
|
||||
import { useViewportRendering } from '../../hooks';
|
||||
|
||||
export function WindowLevelActionMenuWrapper({
|
||||
viewportId,
|
||||
element,
|
||||
location,
|
||||
displaySets,
|
||||
}: withAppTypes<{
|
||||
viewportId: string;
|
||||
element: HTMLElement;
|
||||
location: string;
|
||||
displaySets: Array<AppTypes.DisplaySet>;
|
||||
}>): ReactNode {
|
||||
const [viewportGrid] = useViewportGrid();
|
||||
const [actionCornerState, viewportActionCornersAPI] = useViewportActionCorners();
|
||||
const isActiveViewport = viewportId === viewportGrid.activeViewportId;
|
||||
export function WindowLevelActionMenuWrapper(
|
||||
props: withAppTypes<{
|
||||
viewportId: string;
|
||||
element?: HTMLElement;
|
||||
location?: number;
|
||||
isOpen?: boolean;
|
||||
onOpen?: () => void;
|
||||
onClose?: () => void;
|
||||
displaySets?: Array<AppTypes.DisplaySet>;
|
||||
disabled?: boolean;
|
||||
isEmbedded?: boolean;
|
||||
}>
|
||||
): ReactNode {
|
||||
const {
|
||||
viewportId,
|
||||
element,
|
||||
location,
|
||||
isOpen = false,
|
||||
onOpen,
|
||||
onClose,
|
||||
disabled,
|
||||
isEmbedded = false,
|
||||
onInteraction: onInteractionProps,
|
||||
hasEmbeddedVariantToUse,
|
||||
...rest
|
||||
} = props;
|
||||
|
||||
const [gridState] = useViewportGrid();
|
||||
const viewportIdToUse = viewportId || gridState.activeViewportId;
|
||||
|
||||
const { viewportDisplaySets: displaySets } = useViewportDisplaySets(viewportIdToUse);
|
||||
const { servicesManager } = useSystem();
|
||||
const { customizationService } = servicesManager.services;
|
||||
|
||||
const presets = customizationService.getCustomization('cornerstone.windowLevelPresets');
|
||||
const colorbarProperties = customizationService.getCustomization('cornerstone.colorbar');
|
||||
const { volumeRenderingPresets, volumeRenderingQualityRange } =
|
||||
customizationService.getCustomization('cornerstone.3dVolumeRendering');
|
||||
|
||||
const isMenuOpen =
|
||||
actionCornerState.viewports[viewportId]?.[location]?.find(
|
||||
item => item.id === MENU_IDS.WINDOW_LEVEL_MENU
|
||||
)?.isOpen ?? false;
|
||||
const { toolbarService } = servicesManager.services;
|
||||
const { IconContainer, className: iconClassName, containerProps } = useIconPresentation();
|
||||
const { hasColorbar, toggleColorbar } = useViewportRendering(viewportId);
|
||||
|
||||
const handleOpenChange = (openState: boolean) => {
|
||||
const shouldToggleColorbar = hasColorbar && !isEmbedded;
|
||||
|
||||
if (isOpen && shouldToggleColorbar && openState) {
|
||||
toggleColorbar();
|
||||
onClose?.();
|
||||
return;
|
||||
}
|
||||
|
||||
if (!isOpen && openState && shouldToggleColorbar) {
|
||||
toggleColorbar();
|
||||
return;
|
||||
}
|
||||
|
||||
if (openState) {
|
||||
viewportActionCornersAPI.openItem?.(viewportId, MENU_IDS.WINDOW_LEVEL_MENU);
|
||||
onOpen?.();
|
||||
} else {
|
||||
viewportActionCornersAPI.closeItem?.(viewportId, MENU_IDS.WINDOW_LEVEL_MENU);
|
||||
onClose?.();
|
||||
}
|
||||
};
|
||||
|
||||
const { align, side, horizontalDirection, verticalDirection } = getMenuDirections(
|
||||
location,
|
||||
viewportActionCornersAPI
|
||||
);
|
||||
|
||||
const displaySetPresets = displaySets
|
||||
.filter(displaySet => presets[displaySet.Modality])
|
||||
.map(displaySet => {
|
||||
return { [displaySet.Modality]: presets[displaySet.Modality] };
|
||||
});
|
||||
const { align, side } = toolbarService.getAlignAndSide(location);
|
||||
|
||||
const modalities = displaySets.map(displaySet => displaySet.supportsWindowLevel);
|
||||
|
||||
@@ -66,25 +78,41 @@ export function WindowLevelActionMenuWrapper({
|
||||
return null;
|
||||
}
|
||||
|
||||
const Icon =
|
||||
hasColorbar && !isEmbedded && hasEmbeddedVariantToUse ? (
|
||||
<Icons.Close className={iconClassName} />
|
||||
) : (
|
||||
<Icons.ViewportWindowLevel className={iconClassName} />
|
||||
);
|
||||
|
||||
return (
|
||||
<Popover
|
||||
open={isMenuOpen}
|
||||
open={isOpen}
|
||||
onOpenChange={handleOpenChange}
|
||||
>
|
||||
<PopoverTrigger
|
||||
asChild
|
||||
className="flex items-center justify-center"
|
||||
>
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
className={cn(
|
||||
isActiveViewport ? 'visible' : 'invisible group-hover/pane:visible',
|
||||
'text-highlight'
|
||||
<div>
|
||||
{IconContainer ? (
|
||||
<IconContainer
|
||||
disabled={disabled}
|
||||
{...rest}
|
||||
{...containerProps}
|
||||
>
|
||||
{Icon}
|
||||
</IconContainer>
|
||||
) : (
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
disabled={disabled}
|
||||
>
|
||||
{Icon}
|
||||
</Button>
|
||||
)}
|
||||
>
|
||||
<Icons.ByName name="viewport-window-level" />
|
||||
</Button>
|
||||
</div>
|
||||
</PopoverTrigger>
|
||||
<PopoverContent
|
||||
className="border-none bg-transparent p-0 shadow-none"
|
||||
@@ -94,45 +122,12 @@ export function WindowLevelActionMenuWrapper({
|
||||
sideOffset={5}
|
||||
>
|
||||
<WindowLevelActionMenu
|
||||
viewportId={viewportId}
|
||||
viewportId={viewportIdToUse}
|
||||
element={element}
|
||||
presets={displaySetPresets}
|
||||
horizontalDirection={horizontalDirection}
|
||||
verticalDirection={verticalDirection}
|
||||
colorbarProperties={colorbarProperties}
|
||||
displaySets={displaySets}
|
||||
volumeRenderingPresets={volumeRenderingPresets}
|
||||
volumeRenderingQualityRange={volumeRenderingQualityRange}
|
||||
align={align}
|
||||
side={side}
|
||||
/>
|
||||
</PopoverContent>
|
||||
</Popover>
|
||||
);
|
||||
}
|
||||
|
||||
const getMenuDirections = (location, viewportActionCornersAPI) => {
|
||||
let align = 'center';
|
||||
let side = 'bottom';
|
||||
|
||||
if (location !== undefined) {
|
||||
const positioning = viewportActionCornersAPI.getAlignAndSide(location);
|
||||
align = positioning.align;
|
||||
side = positioning.side;
|
||||
}
|
||||
|
||||
let horizontalDirection;
|
||||
let verticalDirection;
|
||||
|
||||
if (side === 'bottom') {
|
||||
verticalDirection = AllInOneMenu.VerticalDirection.TopToBottom;
|
||||
} else {
|
||||
verticalDirection = AllInOneMenu.VerticalDirection.BottomToTop;
|
||||
}
|
||||
|
||||
if (align === 'start') {
|
||||
horizontalDirection = AllInOneMenu.HorizontalDirection.LeftToRight;
|
||||
} else {
|
||||
horizontalDirection = AllInOneMenu.HorizontalDirection.RightToLeft;
|
||||
}
|
||||
|
||||
return { align, side, horizontalDirection, verticalDirection };
|
||||
};
|
||||
-13
@@ -1,13 +0,0 @@
|
||||
import React from 'react';
|
||||
import { WindowLevelActionMenuWrapper } from './WindowLevelActionMenuWrapper';
|
||||
|
||||
export function getWindowLevelActionMenu(
|
||||
props: withAppTypes<{
|
||||
viewportId: string;
|
||||
element: HTMLElement;
|
||||
location: string;
|
||||
displaySets: Array<any>;
|
||||
}>
|
||||
) {
|
||||
return <WindowLevelActionMenuWrapper {...props} />;
|
||||
}
|
||||
@@ -6,8 +6,7 @@ export * from './MeasurementsMenu';
|
||||
export * from './SeriesMeasurements';
|
||||
export * from './StudyMeasurementsActions';
|
||||
export * from './MeasurementsOrAdditionalFindings';
|
||||
export * from './ViewportDataOverlaySettingMenu';
|
||||
export * from './ViewportOrientationMenu';
|
||||
export * from './WindowLevelActionMenu';
|
||||
export * from './ModalityLoadBadge';
|
||||
|
||||
export { DicomUpload };
|
||||
@@ -1,5 +0,0 @@
|
||||
export const MENU_IDS = {
|
||||
ORIENTATION_MENU: 'orientationMenu',
|
||||
DATA_OVERLAY_MENU: 'dataOverlayMenu',
|
||||
WINDOW_LEVEL_MENU: 'windowLevelActionMenu',
|
||||
};
|
||||
Reference in new issue
Block a user