Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion apps/visr/src/components/tomography/SliceViewer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@ interface Props {
volumeShape: [number, number, number];
plane: Plane;
slice: number;
threshold?: number; // raw 0–255; values at or below render as the bottom of the colormap
resizeKey?: string; //if this depends on a value, the plot will remount every time that value changes. If no need for it to remound, leave as undefined
}
export default function SliceViewer({
volumeData,
volumeShape,
plane,
slice,
threshold = 0,
resizeKey,
}: Props) {
if (volumeData == undefined || volumeShape == undefined) {
Expand Down Expand Up @@ -46,7 +48,7 @@ export default function SliceViewer({
aspect={"equal"}
plotConfig={{}}
values={sliceNdarray}
domain={[0, 255]}
domain={[threshold, 255]}
customToolbarChildren={null}
/>
);
Expand Down
19 changes: 19 additions & 0 deletions apps/visr/src/components/tomography/TomographyControls.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,20 @@ import { Plane } from "./PlaneEnum";
interface Props {
onSlide: (event: Event, newValue: number | number[]) => void;
onSetDirection: (event: React.ChangeEvent<HTMLInputElement>) => void;
onThreshold: (event: Event, newValue: number | number[]) => void;
plane: Plane;
slice: number;
threshold: number;
volumeShape: [number, number, number];
}

export default function Controls({
onSlide,
onSetDirection,
onThreshold,
plane,
slice,
threshold,
volumeShape,
}: Props) {
const maxSlice: Record<Plane, number> = {
Expand All @@ -38,6 +42,21 @@ export default function Controls({
p: 3,
}}
>
<Box sx={{ display: "flex", flexDirection: "column", gap: 1 }}>
<Typography variant="body2" color="primary">
Threshold
</Typography>
<Slider
min={0}
max={254}
step={1}
value={threshold}
onChange={onThreshold}
valueLabelDisplay="auto"
aria-label="Threshold"
/>
</Box>

<Typography variant="overline" color="primary">
Slice View
</Typography>
Expand Down
9 changes: 8 additions & 1 deletion apps/visr/src/components/tomography/TomographyPlots.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ interface Props {
volumeVisible: boolean;
slice: number;
plane: Plane;
threshold: number;
}

// ---------------------------------------------------------------------------
Expand Down Expand Up @@ -47,6 +48,7 @@ function TomographyPlots({
volumeShape,
plane,
slice,
threshold,
drawerOpen,
}: Props) {
const { width, containerRef, mounted } = useContainerWidth();
Expand Down Expand Up @@ -96,12 +98,17 @@ function TomographyPlots({
// -------------------------------------------------------------------------
const views = [
<CamPva />,
<VolumeRenderer volumeData={volumeData} volumeShape={volumeShape} />,
<VolumeRenderer
volumeData={volumeData}
volumeShape={volumeShape}
threshold={threshold / 255}
/>,
<SliceViewer
volumeData={volumeData}
volumeShape={volumeShape}
slice={slice}
plane={plane}
threshold={threshold}
/>,
];

Expand Down
8 changes: 8 additions & 0 deletions apps/visr/src/components/tomography/TomographyView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ function TomographyView() {
// const [revolve, setRevolve] = useState(false);
const [slice, setSlice] = useState<number>(0);
const [plane, setPlane] = useState<Plane>(Plane.Z);
const [threshold, setThreshold] = useState<number>(38); // 38/255 ≈ 0.15, the renderer's old default
const [drawerOpen, setDrawerOpen] = useState(true);

// -------------------------------------------------------------------------
Expand Down Expand Up @@ -95,6 +96,10 @@ function TomographyView() {
setPlane(radioValue);
};

const handleThreshold = (event: Event, newValue: number | number[]) => {
setThreshold(typeof newValue == "number" ? newValue : newValue[0]);
};

// revolve to be implemented

if (!volume) return <Box />;
Expand All @@ -116,6 +121,7 @@ function TomographyView() {
volumeVisible={volumeVisible}
plane={plane}
slice={slice}
threshold={threshold}
volumeShape={volume.volumeShape}
drawerOpen={drawerOpen}
/>
Expand All @@ -127,8 +133,10 @@ function TomographyView() {
<TomographyControls
onSlide={handleSlider}
onSetDirection={handlePlane}
onThreshold={handleThreshold}
plane={plane}
slice={slice}
threshold={threshold}
volumeShape={volume.volumeShape}
/>,
]}
Expand Down
3 changes: 3 additions & 0 deletions apps/visr/src/components/tomography/VolumeRenderer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,21 @@
opacityScale: { value: opacityScale },
steps: { value: steps },
}),
[],

Check warning on line 38 in apps/visr/src/components/tomography/VolumeRenderer.tsx

View workflow job for this annotation

GitHub Actions / ci

React Hook useMemo has missing dependencies: 'opacityScale', 'steps', and 'threshold'. Either include them or remove the dependency array
); // eslint-disable-line react-hooks/exhaustive-deps

// Sync scalar uniforms when props change
useEffect(() => {
uniforms.threshold.value = threshold;
invalidate();
}, [threshold, uniforms]);
useEffect(() => {
uniforms.opacityScale.value = opacityScale;
invalidate();
}, [opacityScale, uniforms]);
useEffect(() => {
uniforms.steps.value = steps;
invalidate();
}, [steps, uniforms]);

// Upload volume data to GPU texture
Expand Down
Loading