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( 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 (
Threshold {viewportDisplaySets.length > 1 && (
)}
{ if (typeof val === 'number') { setThreshold(val); } }} min={min} max={max} step={0.01} >
{min.toFixed(0)} {max.toFixed(0)}
); } export default ThresholdMenu;