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
9 changes: 5 additions & 4 deletions src/components/Preview/displays/NiiVueDisplay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,6 @@ export default (props: Props) => {
onChange={safeSetColorMap}
style={selectStyle}
/>
<span>{crosshairText}</span>
<InputNumber
style={inputStyle}
placeholder={`minimum value`}
Expand All @@ -233,6 +232,7 @@ export default (props: Props) => {
isChecked={isRadiologistView}
onChange={onChangeRadiologistView}
/>
<span> {crosshairText} </span>
</div>
<SizedNiivueCanvas
size={8}
Expand All @@ -241,9 +241,10 @@ export default (props: Props) => {
colormapLabel={colormapLabel}
calMax={calMax}
calMin={calMin}
onLocationChange={(c: CrosshairLocation) =>
setCrosshairText(c.string)
}
onLocationChange={(c: CrosshairLocation) => {
console.info("NiiVueDisplay: onLocationChange: c:", c);
setCrosshairText(c.string);
}}
sliceType={sliceTypeName}
isRadiologistView={isRadiologistView}
isHide={isHide}
Expand Down
5 changes: 5 additions & 0 deletions src/components/Preview/displays/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ import type { SLICE_TYPE } from "@niivue/niivue";
*/
export type CrosshairLocation = {
string: string;
axCorSag: SLICE_TYPE;
frac: Float32Array;
mm: Float32Array;
vox: Float32Array;
xy: [number, number];
};

export enum DisplayType {
Expand Down
75 changes: 61 additions & 14 deletions src/components/SizedNiivueCanvas/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ type Props = {
isScaling?: boolean;
onLocationChange?: (location: CrosshairLocation) => void;
urls?: string[];
colormap?: string;
calMin?: number;
calMax?: number;
colormap: string;
calMin: number;
calMax: number;
colormapLabel?: ColorMap | null;

sliceType?: SliceType;
Expand Down Expand Up @@ -78,14 +78,15 @@ export default (props: Props) => {
const glRef = useRef<HTMLCanvasElement>(null);
const [theNiivue, setTheNiivue] = useState<Niivue | null>(null);

const [[canvasWidth, canvasHeight], setCanvasDimensions] = useState<
[number, number]
>([400, 400]);
const [[canvasWidth, canvasHeight], setCanvasDimensions] = useState([
400, 400,
]);

const [volumeUrl, setVolumeUrl] = useState("");

const isLoggedIn = useAppSelector(({ user }) => user.isLoggedIn);

// useEffect
// biome-ignore lint/correctness/useExhaustiveDependencies: no need for the onLocationChange
useEffect(() => {
if (isHide) {
return;
Expand All @@ -103,16 +104,17 @@ export default (props: Props) => {
crosshairWidth: 1,
isRadiologicalConvention: isRadiologistView,
sliceType: SLICE_TYPE_MAP[sliceType],
isNearestInterpolation: true,
});
nv.attachToCanvas(glRef.current);
if (onLocationChange) {
nv.onLocationChange = (location) => {
// console.info("SizedNiivueCanvas: location:", location);
// onLocationChange(location as CrosshairLocation);
};
}
nv.onLocationChange = (location) => {
console.info("SizedNiivueCanvas: location:", location);
if (onLocationChange) {
onLocationChange(location as CrosshairLocation);
}
};
setTheNiivue(nv);
}, [theNiivue, isHide]);
}, [theNiivue, glRef.current, isHide]);

useEffect(() => {
if (!theNiivue) {
Expand All @@ -129,6 +131,46 @@ export default (props: Props) => {
theNiivue.setRadiologicalConvention(isRadiologistView);
}, [theNiivue, isRadiologistView]);

useEffect(() => {
if (!theNiivue) {
return;
}

console.info(
"SizedNiivueCanvas: updated colormap: volumes:",
theNiivue.volumes.length,
);
if (!theNiivue.volumes.length) {
return;
}

theNiivue.volumes[0].setColormap(colormap);
if (colormapLabel) {
theNiivue.volumes[0].setColormapLabel(colormapLabel);
}

theNiivue.volumes[0].cal_min = calMin;
theNiivue.volumes[0].cal_max = calMax;

console.info(
"SizedNiivueCanvas: to refreshLayers: colormap:",
colormap,
"calMax:",
calMax,
"volumes[0].cal_max:",
theNiivue.volumes[0].cal_max,
"calMin:",
calMin,
"volumes[0].cal_min:",
theNiivue.volumes[0].cal_min,
"volumes:",
theNiivue.volumes[0],
);

theNiivue.refreshLayers(theNiivue.volumes[0], 0);
theNiivue.refreshDrawing(true);
}, [theNiivue, calMin, calMax, colormap, colormapLabel]);

useEffect(() => {
if (isHide) {
return;
Expand All @@ -141,6 +183,10 @@ export default (props: Props) => {
return;
}

if (urls[0] === volumeUrl) {
return;
}

const volumes = urls.map((url) =>
NVImageFromUrlOptions(
url, // url
Expand Down Expand Up @@ -179,6 +225,7 @@ export default (props: Props) => {
};
});

setVolumeUrl(urls[0]);
(async () => {
await theNiivue.loadVolumes(authedVolumes);
console.info("after theNiivue.loadVolumes:", theNiivue.volumes.length);
Expand Down