OHIF with Cornerstone3D 2.0 (#4347)

This commit is contained in:
Alireza authored and GitHub committed 2024-11-06 07:15:27 -05:00
1 parent 8981a61b8c
commit 7ce7127d7c
803 files changed
+32760 -15893

No files matched your search

@@ -0,0 +1,80 @@
import React from 'react';
import { Button, Icons } from '@ohif/ui-next';
import { useSegmentationTableContext } from './SegmentationTableContext';
/**
* Props interface for the AddSegmentRow component
*/
interface AddSegmentRowProps {
/** Optional child elements to render within the row */
children?: React.ReactNode;
/** Optional segmentation object to override the active segmentation */
segmentation?: unknown;
}
/**
* A component that renders a row with controls for adding segments and toggling visibility
* in the segmentation table.
*
* @param props - Component properties
* @param props.children - Optional child elements to render within the row
* @param props.segmentation - Optional segmentation object to override the active segmentation
*/
export const AddSegmentRow: React.FC<AddSegmentRowProps> = ({ children = null, segmentation }) => {
const {
activeRepresentation,
disableEditing,
activeSegmentationId,
onSegmentAdd,
onToggleSegmentationRepresentationVisibility,
data,
showAddSegment,
} = useSegmentationTableContext('SegmentationTable');
const allSegmentsVisible = Object.values(activeRepresentation?.segments || {}).every(
segment => segment?.visible !== false
);
const segmentationIdToUse = segmentation ? segmentation.segmentationId : activeSegmentationId;
if (!data?.length) {
return null;
}
const Icon = allSegmentsVisible ? (
<Icons.Hide className="h-6 w-6" />
) : (
<Icons.Show className="h-6 w-6" />
);
const allowAddSegment = showAddSegment && !disableEditing;
return (
<div className="bg-primary-dark my-px flex h-7 w-full items-center justify-between rounded pl-0.5 pr-7">
{allowAddSegment ? (
<Button
size="sm"
variant="ghost"
className="pr pl-0.5"
onClick={() => onSegmentAdd(segmentationIdToUse)}
>
<Icons.Add />
Add Segment
</Button>
) : null}
<Button
size="icon"
variant="ghost"
onClick={() =>
onToggleSegmentationRepresentationVisibility(
segmentationIdToUse,
activeRepresentation?.type
)
}
>
{Icon}
</Button>
{children}
</div>
);
};
@@ -0,0 +1,40 @@
import React from 'react';
import { Icons } from '../Icons';
import { useTranslation } from 'react-i18next';
import { useSegmentationTableContext } from './SegmentationTableContext';
export const AddSegmentationRow: React.FC<{ children?: React.ReactNode }> = ({
children = null,
}) => {
const { t } = useTranslation('SegmentationTable');
const { onSegmentationAdd, data, disableEditing, mode, disabled } =
useSegmentationTableContext('SegmentationTable');
const isEmpty = data.length === 0;
if (!isEmpty && mode === 'collapsed') {
return null;
}
if (disableEditing) {
return null;
}
return (
<div
className={`group ${disabled ? 'pointer-events-none cursor-not-allowed opacity-70' : ''}`}
onClick={() => !disabled && onSegmentationAdd('')}
>
{children}
<div className="text-primary-active group-hover:bg-secondary-dark flex items-center rounded-[4px] pl-1 group-hover:cursor-pointer">
<div className="grid h-[28px] w-[28px] place-items-center">
{disabled ? <Icons.Info /> : <Icons.Add />}
</div>
<span className="text-[13px]">
{t(`${disabled ? 'Segmentation Not Supported' : 'Add Segmentation'}`)}
</span>
</div>
</div>
);
};
@@ -0,0 +1,7 @@
import React from 'react';
export const SegmentationCollapsed: React.FC<{ children?: React.ReactNode }> = ({
children = null,
}) => {
return <div>{children}</div>;
};
@@ -0,0 +1,51 @@
import React from 'react';
import { useSegmentationTableContext } from './SegmentationTableContext';
import { PanelSection } from '../PanelSection';
import { SegmentationHeader } from './SegmentationHeader';
import { SegmentationTable } from './SegmentationTable';
export const SegmentationExpanded: React.FC<{ children?: React.ReactNode }> = ({ children }) => {
const { data } = useSegmentationTableContext('SegmentationExpanded');
// Separate the Header component from other children
const headerComponent = React.Children.toArray(children).find(
child => React.isValidElement(child) && child.type === SegmentationTable.Header
);
const otherChildren = React.Children.toArray(children).filter(
child => !(React.isValidElement(child) && child.type === SegmentationTable.Header)
);
return (
<>
{data.map(segmentationInfo => (
<PanelSection key={segmentationInfo.segmentation.segmentationId}>
<PanelSection.Header className="border-input border-t-2 bg-transparent pl-1">
{headerComponent ? (
React.cloneElement(headerComponent as React.ReactElement, {
segmentation: segmentationInfo.segmentation,
representation: segmentationInfo.representation,
})
) : (
<SegmentationHeader
segmentation={segmentationInfo.segmentation}
representation={segmentationInfo.representation}
/>
)}
</PanelSection.Header>
<PanelSection.Content>
<div className="segmentation-expanded-section">
{React.Children.map(otherChildren, child =>
React.isValidElement(child)
? React.cloneElement(child, {
segmentation: segmentationInfo.segmentation,
representation: segmentationInfo.representation,
})
: child
)}
</div>
</PanelSection.Content>
</PanelSection>
))}
</>
);
};
@@ -0,0 +1,144 @@
import React from 'react';
import { Button } from '../Button';
import { Icons } from '../Icons/Icons';
import {
DropdownMenu,
DropdownMenuTrigger,
DropdownMenuContent,
DropdownMenuItem,
DropdownMenuSeparator,
DropdownMenuSub,
DropdownMenuSubTrigger,
DropdownMenuSubContent,
DropdownMenuPortal,
} from '../DropdownMenu';
import { Tooltip, TooltipTrigger, TooltipContent } from '../Tooltip/Tooltip';
import { useSegmentationTableContext } from './SegmentationTableContext';
import { useTranslation } from 'react-i18next';
export const SegmentationHeader: React.FC<{
segmentation?: any;
}> = ({ segmentation }) => {
const { t } = useTranslation('SegmentationTable');
const {
onSegmentAdd,
onSegmentationRemoveFromViewport,
onSegmentationEdit,
onSegmentationDelete,
onSegmentationDownload,
onSegmentationDownloadRTSS,
storeSegmentation,
} = useSegmentationTableContext('SegmentationHeader');
if (!segmentation) {
return null;
}
return (
<div className="text-foreground flex h-8 w-full items-center justify-between">
<div className="flex items-center space-x-1">
<DropdownMenu>
<DropdownMenuTrigger asChild>
<Button
variant="ghost"
size="icon"
className="ml-1"
onClick={e => e.stopPropagation()}
>
<Icons.More />
</Button>
</DropdownMenuTrigger>
<DropdownMenuContent align="start">
<DropdownMenuItem
onClick={e => {
e.stopPropagation();
onSegmentAdd(segmentation.segmentationId);
}}
>
<Icons.Add className="text-foreground" />
<span className="pl-2">{t('Add Segment')}</span>
</DropdownMenuItem>
<DropdownMenuSeparator />
<DropdownMenuItem
onClick={e => {
e.stopPropagation();
onSegmentationRemoveFromViewport(segmentation.segmentationId);
}}
>
<Icons.Series className="text-foreground" />
<span className="pl-2">{t('Remove from Viewport')}</span>
</DropdownMenuItem>
<DropdownMenuItem
onClick={e => {
e.stopPropagation();
onSegmentationEdit(segmentation.segmentationId);
}}
>
<Icons.Rename className="text-foreground" />
<span className="pl-2">{t('Rename')}</span>
</DropdownMenuItem>
<DropdownMenuItem onClick={e => e.stopPropagation()}>
<Icons.Hide className="text-foreground" />
<span className="pl-2">{t('Hide or Show all Segments')}</span>
</DropdownMenuItem>
<DropdownMenuSub>
<DropdownMenuSubTrigger onClick={e => e.stopPropagation()}>
<Icons.Export className="text-foreground" />
<span className="pl-2">{t('Export & Download')}</span>
</DropdownMenuSubTrigger>
<DropdownMenuPortal>
<DropdownMenuSubContent>
<DropdownMenuItem
onClick={e => {
e.stopPropagation();
storeSegmentation(segmentation.segmentationId);
}}
>
{t('Export DICOM SEG')}
</DropdownMenuItem>
<DropdownMenuItem
onClick={e => {
e.stopPropagation();
onSegmentationDownload(segmentation.segmentationId);
}}
>
{t('Download DICOM SEG')}
</DropdownMenuItem>
<DropdownMenuItem
onClick={e => {
e.stopPropagation();
onSegmentationDownloadRTSS(segmentation.segmentationId);
}}
>
{t('Download DICOM RTSTRUCT')}
</DropdownMenuItem>
</DropdownMenuSubContent>
</DropdownMenuPortal>
</DropdownMenuSub>
<DropdownMenuSeparator />
<DropdownMenuItem onClick={() => onSegmentationDelete(segmentation.segmentationId)}>
<Icons.Delete className="text-red-600" />
<span className="pl-2 text-red-600">{t('Delete')}</span>
</DropdownMenuItem>
</DropdownMenuContent>
</DropdownMenu>
<div className="pl-1.5">{segmentation.label}</div>
</div>
<div className="mr-1 flex items-center">
<Tooltip>
<TooltipTrigger asChild>
<Button
variant="ghost"
size="icon"
>
<Icons.Info className="h-6 w-6" />
</Button>
</TooltipTrigger>
<TooltipContent>
<p>{segmentation.cachedStats.info}</p>
</TooltipContent>
</Tooltip>
</div>
</div>
);
};
@@ -0,0 +1,82 @@
import React from 'react';
import { ScrollArea, DataRow } from '../../components';
import { useSegmentationTableContext } from './SegmentationTableContext';
export const SegmentationSegments: React.FC<{
segmentation?: unknown;
representation?: unknown;
}> = ({ segmentation, representation }) => {
const {
activeSegmentationId,
disableEditing,
onSegmentColorClick,
onToggleSegmentVisibility,
onToggleSegmentLock,
onSegmentClick,
mode,
onSegmentEdit,
onSegmentDelete,
data,
} = useSegmentationTableContext('SegmentationTable.Segments');
let segmentationToUse = segmentation;
let representationToUse = representation;
let segmentationIdToUse = activeSegmentationId;
if (!segmentationToUse || !representationToUse) {
const entry = data.find(seg => seg.segmentation.segmentationId === activeSegmentationId);
segmentationToUse = entry?.segmentation;
representationToUse = entry?.representation;
segmentationIdToUse = entry?.segmentation.segmentationId;
}
if (!representationToUse || !segmentationToUse) {
return null;
}
const segmentCount = Object.keys(representationToUse.segments).length;
const height = mode === 'collapsed' ? 'h-[600px]' : `h-[${segmentCount * 200}px]`;
return (
<ScrollArea
className={`ohif-scrollbar invisible-scrollbar bg-bkg-low space-y-px ${height}`}
showArrows={true}
>
{Object.values(representationToUse.segments).map(segment => {
if (!segment) {
return null;
}
const { segmentIndex, color, visible } = segment;
const segmentFromSegmentation = segmentationToUse.segments[segmentIndex];
if (!segmentFromSegmentation) {
return null;
}
const { locked, active, label, displayText } = segmentFromSegmentation;
const cssColor = `rgb(${color[0]},${color[1]},${color[2]})`;
return (
<DataRow
key={segmentIndex}
number={segmentIndex}
title={label}
details={displayText}
colorHex={cssColor}
isSelected={active}
isVisible={visible}
isLocked={locked}
disableEditing={disableEditing}
onColor={() => onSegmentColorClick(segmentationIdToUse, segmentIndex)}
onToggleVisibility={() =>
onToggleSegmentVisibility(segmentationIdToUse, segmentIndex, representationToUse.type)
}
onToggleLocked={() => onToggleSegmentLock(segmentationIdToUse, segmentIndex)}
onSelect={() => onSegmentClick(segmentationIdToUse, segmentIndex)}
onRename={() => onSegmentEdit(segmentationIdToUse, segmentIndex)}
onDelete={() => onSegmentDelete(segmentationIdToUse, segmentIndex)}
/>
);
})}
</ScrollArea>
);
};
@@ -0,0 +1,159 @@
import React from 'react';
import {
Icons,
Button,
DropdownMenu,
DropdownMenuTrigger,
DropdownMenuItem,
DropdownMenuContent,
DropdownMenuSeparator,
DropdownMenuSub,
DropdownMenuPortal,
DropdownMenuSubContent,
DropdownMenuSubTrigger,
Tooltip,
TooltipTrigger,
TooltipContent,
DropdownMenuLabel,
} from '../../components';
import { useTranslation } from 'react-i18next';
import { Select, SelectTrigger, SelectContent, SelectItem, SelectValue } from '@ohif/ui-next';
import { useSegmentationTableContext } from './SegmentationTableContext';
export const SegmentationSelectorHeader: React.FC<{ children?: React.ReactNode }> = ({
children = null,
}) => {
const { t } = useTranslation('SegmentationTable.HeaderCollapsed');
const {
data,
activeSegmentationId,
mode,
onSegmentationClick,
onSegmentationAdd,
onSegmentationRemoveFromViewport,
onSegmentationEdit,
onSegmentationDelete,
onSegmentationDownload,
onSegmentationDownloadRTSS,
storeSegmentation,
exportOptions,
} = useSegmentationTableContext('SegmentationTable.HeaderCollapsed');
if (mode !== 'collapsed' || !data?.length) {
return null;
}
const activeSegmentationObj = data.find(
seg => seg.segmentation.segmentationId === activeSegmentationId
);
const activeSegmentation = {
id: activeSegmentationObj?.segmentation.segmentationId,
label: activeSegmentationObj?.segmentation.label,
info: activeSegmentationObj?.segmentation.cachedStats?.info,
};
const segmentations = data.map(seg => ({
id: seg.segmentation.segmentationId,
label: seg.segmentation.label,
info: seg.segmentation.cachedStats?.info,
}));
const allowExport = exportOptions.find(
({ segmentationId }) => segmentationId === activeSegmentation.id
)?.isExportable;
return (
<div className="bg-primary-dark flex h-10 w-full items-center space-x-1 rounded-t px-1.5">
<DropdownMenu>
<DropdownMenuTrigger asChild>
<Button
variant="ghost"
size="icon"
>
<Icons.More className="h-6 w-6" />
</Button>
</DropdownMenuTrigger>
<DropdownMenuContent align="start">
<DropdownMenuItem onClick={() => onSegmentationAdd(activeSegmentation.id)}>
<Icons.Add className="text-foreground" />
<span className="pl-2">{t('Create New Segmentation')}</span>
</DropdownMenuItem>
<DropdownMenuSeparator />
<DropdownMenuLabel>{t('Manage Current Segmentation')}</DropdownMenuLabel>
<DropdownMenuItem onClick={() => onSegmentationRemoveFromViewport(activeSegmentation.id)}>
<Icons.Series className="text-foreground" />
<span className="pl-2">{t('Remove from Viewport')}</span>
</DropdownMenuItem>
<DropdownMenuItem onClick={() => onSegmentationEdit(activeSegmentation.id)}>
<Icons.Rename className="text-foreground" />
<span className="pl-2">{t('Rename')}</span>
</DropdownMenuItem>
<DropdownMenuSub>
<DropdownMenuSubTrigger
disabled={!allowExport}
className="pl-1"
>
<Icons.Export className="text-foreground" />
<span className="pl-2">{t('Export & Download')}</span>
</DropdownMenuSubTrigger>
<DropdownMenuPortal>
<DropdownMenuSubContent>
<DropdownMenuItem onClick={() => storeSegmentation(activeSegmentation.id)}>
{t('Export DICOM SEG')}
</DropdownMenuItem>
<DropdownMenuItem onClick={() => onSegmentationDownload(activeSegmentation.id)}>
{t('Download DICOM SEG')}
</DropdownMenuItem>
<DropdownMenuItem onClick={() => onSegmentationDownloadRTSS(activeSegmentation.id)}>
{t('Download DICOM RTSTRUCT')}
</DropdownMenuItem>
</DropdownMenuSubContent>
</DropdownMenuPortal>
</DropdownMenuSub>
<DropdownMenuSeparator />
<DropdownMenuItem onClick={() => onSegmentationDelete(activeSegmentation.id)}>
<Icons.Delete className="text-red-600" />
<span className="pl-2 text-red-600">{t('Delete')}</span>
</DropdownMenuItem>
</DropdownMenuContent>
</DropdownMenu>
<Select
onValueChange={value => onSegmentationClick(value)}
value={activeSegmentation.id}
>
<SelectTrigger className="w-full overflow-hidden">
<SelectValue placeholder={t('Select a segmentation')} />
</SelectTrigger>
<SelectContent>
{segmentations.map(seg => (
<SelectItem
key={seg.id}
value={seg.id}
>
{seg.label}
</SelectItem>
))}
</SelectContent>
</Select>
<Tooltip>
<TooltipTrigger asChild>
<Button
variant="ghost"
size="icon"
>
<Icons.Info className="h-6 w-6" />
</Button>
</TooltipTrigger>
<TooltipContent
side="bottom"
align="end"
>
{activeSegmentation.info}
</TooltipContent>
</Tooltip>
</div>
);
};
@@ -0,0 +1,76 @@
import React, { ReactNode } from 'react';
import { useTranslation } from 'react-i18next';
import { PanelSection } from '../PanelSection';
import { SegmentationTableProvider, SegmentationTableContext } from './SegmentationTableContext';
import { SegmentationSegments } from './SegmentationSegments';
import { SegmentationTableConfig } from './SegmentationTableConfig';
import { AddSegmentRow } from './AddSegmentRow';
import { AddSegmentationRow } from './AddSegmentationRow';
import { SegmentationSelectorHeader } from './SegmentationSelectorHeader';
import { SegmentationHeader } from './SegmentationHeader';
import { SegmentationCollapsed } from './SegmentationCollapsed';
import { SegmentationExpanded } from './SegmentationExpanded';
interface SegmentationTableProps extends SegmentationTableContext {
disabled?: boolean;
title?: string;
children?: ReactNode;
}
interface SegmentationTableComponent extends React.FC<SegmentationTableProps> {
Segments: typeof SegmentationSegments;
Config: typeof SegmentationTableConfig;
AddSegmentRow: typeof AddSegmentRow;
AddSegmentationRow: typeof AddSegmentationRow;
SelectorHeader: typeof SegmentationSelectorHeader;
Header: typeof SegmentationHeader;
Collapsed: typeof SegmentationCollapsed;
Expanded: typeof SegmentationExpanded;
}
export const SegmentationTable: SegmentationTableComponent = (props: SegmentationTableProps) => {
const { t } = useTranslation('SegmentationTable');
const { data = [], mode, title, disableEditing, disabled, children, ...contextProps } = props;
const activeSegmentationInfo = data.find(info => info.representation?.active);
const activeSegmentationId = activeSegmentationInfo?.segmentation?.segmentationId;
const activeRepresentation = activeSegmentationInfo?.representation;
const activeSegmentation = activeSegmentationInfo?.segmentation;
const { fillAlpha, fillAlphaInactive, outlineWidth, renderFill, renderOutline } =
activeRepresentation?.styles ?? {};
return (
<SegmentationTableProvider
data={data}
mode={mode}
disabled={disabled}
disableEditing={disableEditing}
fillAlpha={fillAlpha}
fillAlphaInactive={fillAlphaInactive}
outlineWidth={outlineWidth}
renderFill={renderFill}
renderOutline={renderOutline}
activeSegmentationId={activeSegmentationId}
activeSegmentation={activeSegmentation}
activeRepresentation={activeRepresentation}
{...contextProps}
>
<PanelSection defaultOpen={true}>
<PanelSection.Header>
<span>{t(title)}</span>
</PanelSection.Header>
<PanelSection.Content>{children}</PanelSection.Content>
</PanelSection>
</SegmentationTableProvider>
);
};
SegmentationTable.Segments = SegmentationSegments;
SegmentationTable.Config = SegmentationTableConfig;
SegmentationTable.AddSegmentRow = AddSegmentRow;
SegmentationTable.AddSegmentationRow = AddSegmentationRow;
SegmentationTable.SelectorHeader = SegmentationSelectorHeader;
SegmentationTable.Header = SegmentationHeader;
SegmentationTable.Collapsed = SegmentationCollapsed;
SegmentationTable.Expanded = SegmentationExpanded;
@@ -0,0 +1,177 @@
import React from 'react';
import { useTranslation } from 'react-i18next';
import { PanelSection } from '../PanelSection';
import { Tabs, TabsList, TabsTrigger } from '../Tabs';
import { Slider } from '../Slider';
import { Icons } from '../Icons';
import { Switch } from '../Switch';
import { Label } from '../Label';
import { Input } from '../Input';
import { useSegmentationTableContext } from './SegmentationTableContext';
export const SegmentationTableConfig: React.FC<{ children?: React.ReactNode }> = ({ children }) => {
const { t } = useTranslation('SegmentationTable.AppearanceSettings');
const {
renderFill,
renderOutline,
setRenderFill,
setRenderOutline,
activeRepresentation,
fillAlpha,
fillAlphaInactive,
outlineWidth,
setFillAlpha,
setFillAlphaInactive,
setOutlineWidth,
renderInactiveSegmentations,
toggleRenderInactiveSegmentations,
data,
} = useSegmentationTableContext('styles');
if (!data?.length) {
return null;
}
return (
<PanelSection defaultOpen={false}>
<PanelSection.Header>
<div className="flex items-center">
<Icons.Settings className="mr-2 h-4 w-4" />
<span>{t('Appearance Settings')}</span>
</div>
</PanelSection.Header>
<PanelSection.Content>
<div className="bg-muted mb-0.5 space-y-2 rounded-b px-1.5 pt-0.5 pb-3">
<div className="my-1 flex items-center justify-between">
<span className="text-aqua-pale text-xs">
{t('Show')}:{' '}
{renderFill && renderOutline
? t('Fill & Outline')
: renderOutline
? t('Outline Only')
: t('Fill Only')}
</span>
<Tabs
value={
renderFill && renderOutline
? 'fill-and-outline'
: renderOutline
? 'outline'
: 'fill'
}
onValueChange={value => {
if (value === 'fill-and-outline') {
setRenderFill({ type: activeRepresentation.type }, true);
setRenderOutline({ type: activeRepresentation.type }, true);
} else if (value === 'outline') {
setRenderFill({ type: activeRepresentation.type }, false);
setRenderOutline({ type: activeRepresentation.type }, true);
} else {
setRenderFill({ type: activeRepresentation.type }, true);
setRenderOutline({ type: activeRepresentation.type }, false);
}
}}
>
<TabsList>
<TabsTrigger value="fill-and-outline">
<Icons.FillAndOutline className="text-primary-active" />
</TabsTrigger>
<TabsTrigger value="outline">
<Icons.OutlineOnly className="text-primary-active" />
</TabsTrigger>
<TabsTrigger value="fill">
<Icons.FillOnly className="text-primary-active" />
</TabsTrigger>
</TabsList>
</Tabs>
</div>
<div className="space-y-2">
<div className="my-2 flex items-center">
<Label className="text-muted-foreground w-14 flex-none whitespace-nowrap text-xs">
Opacity
</Label>
<Slider
className="mx-1 flex-1"
value={[fillAlpha]}
onValueChange={([value]) =>
setFillAlpha({ type: activeRepresentation.type }, value)
}
max={1}
min={0}
step={0.1}
/>
<Input
className="mx-1 w-10 flex-none"
value={fillAlpha}
onChange={e =>
setFillAlpha({ type: activeRepresentation.type }, Number(e.target.value))
}
/>
</div>
<div className="my-2 flex items-center">
<Label className="text-muted-foreground w-14 flex-none whitespace-nowrap text-xs">
{t('Border')}
</Label>
<Slider
value={[outlineWidth]}
onValueChange={([value]) =>
setOutlineWidth({ type: activeRepresentation.type }, value)
}
max={10}
min={0}
step={0.1}
className="mx-1 flex-1"
/>
<Input
value={outlineWidth}
onChange={e =>
setOutlineWidth({ type: activeRepresentation.type }, Number(e.target.value))
}
className="mx-1 w-10 flex-none text-center"
/>
</div>
</div>
<div className="border-input w-full border"></div>
<div className="my-2 flex items-center pl-1">
<Switch
checked={renderInactiveSegmentations}
onCheckedChange={toggleRenderInactiveSegmentations}
/>
<Label className="text-muted-foreground mx-2 text-xs">
{t('Display inactive segmentations')}
</Label>
</div>
{renderInactiveSegmentations && (
<div className="my-2 flex items-center">
<Label className="text-muted-foreground w-14 flex-none whitespace-nowrap text-xs">
Opacity
</Label>
<Slider
className="mx-1 flex-1"
value={[fillAlphaInactive]}
onValueChange={([value]) =>
setFillAlphaInactive({ type: activeRepresentation.type }, value)
}
max={1}
min={0}
step={0.1}
/>
<Input
className="mx-1 w-10 flex-none"
value={fillAlphaInactive}
onChange={e =>
setFillAlphaInactive({ type: activeRepresentation.type }, Number(e.target.value))
}
/>
</div>
)}
</div>
{children}
</PanelSection.Content>
</PanelSection>
);
};
@@ -0,0 +1,80 @@
import { createContext } from '../../lib/createContext';
interface Segmentation {
segmentationId: string;
label: string;
cachedStats: {
info: string;
};
}
interface Representation {
active: boolean;
visible: boolean;
type: string;
styles: {
fillAlpha: number;
fillAlphaInactive: number;
outlineWidth: number;
renderFill: boolean;
renderOutline: boolean;
};
}
interface ViewportSegmentationInfo {
segmentation: Segmentation;
representation: Representation;
}
interface SegmentationTableContext {
data: ViewportSegmentationInfo[];
disabled: boolean;
mode: 'collapsed' | 'expanded';
fillAlpha: number;
exportOptions: {
segmentationId: string;
isExportable: boolean;
}[];
fillAlphaInactive: number;
outlineWidth: number;
renderFill: boolean;
renderOutline: boolean;
activeSegmentationId: string;
activeRepresentation: Representation;
activeSegmentation: Segmentation;
setRenderFill: ({ type }, value: boolean) => void;
setRenderOutline: ({ type }, value: boolean) => void;
setOutlineWidth: ({ type }, value: number) => void;
setFillAlpha: ({ type }, value: number) => void;
setFillAlphaInactive: ({ type }, value: number) => void;
renderInactiveSegmentations: boolean;
toggleRenderInactiveSegmentations: () => void;
onSegmentationAdd: (segmentationId: string) => void;
onSegmentationClick: (segmentationId: string) => void;
onSegmentationDelete: (segmentationId: string) => void;
onSegmentAdd: (segmentationId: string) => void;
onSegmentClick: (segmentationId: string, segmentIndex: number) => void;
onSegmentEdit: (segmentationId: string, segmentIndex: number) => void;
onSegmentationEdit: (segmentationId: string) => void;
onSegmentColorClick: (segmentationId: string, segmentIndex: number) => void;
onSegmentDelete: (segmentationId: string, segmentIndex: number) => void;
onToggleSegmentVisibility: (segmentationId: string, segmentIndex: number) => void;
onToggleSegmentLock: (segmentationId: string, segmentIndex: number) => void;
onToggleSegmentationRepresentationVisibility: (segmentationId: string, type: string) => void;
onSegmentationDownload: (segmentationId: string) => void;
storeSegmentation: (segmentationId: string) => void;
onSegmentationDownloadRTSS: (segmentationId: string) => void;
setStyle: (
segmentationId: string,
representationType: string,
styleKey: string,
value: unknown
) => void;
onSegmentationRemoveFromViewport: (segmentationId: string) => void;
disableEditing: boolean;
}
const [SegmentationTableProvider, useSegmentationTableContext] =
createContext<SegmentationTableContext>('SegmentationTable');
export { SegmentationTableProvider, useSegmentationTableContext, SegmentationTableContext };
@@ -0,0 +1,22 @@
import { SegmentationTable } from './SegmentationTable';
import { SegmentationTableConfig } from './SegmentationTableConfig';
import { AddSegmentationRow } from './AddSegmentationRow';
import { AddSegmentRow } from './AddSegmentRow';
import { SegmentationSegments } from './SegmentationSegments';
import { SegmentationSelectorHeader } from './SegmentationSelectorHeader';
import { SegmentationHeader } from './SegmentationHeader';
import { useSegmentationTableContext } from './SegmentationTableContext';
SegmentationTable.Segments = SegmentationSegments;
SegmentationTable.Config = SegmentationTableConfig;
SegmentationTable.AddSegmentRow = AddSegmentRow;
SegmentationTable.AddSegmentationRow = AddSegmentationRow;
SegmentationTable.SelectorHeader = SegmentationSelectorHeader;
SegmentationTable.Header = SegmentationHeader;
export {
// context
useSegmentationTableContext,
// components
SegmentationTable,
};