-
Notifications
You must be signed in to change notification settings - Fork 115
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1061 from FNNDSC/niivue-preview
Replace cornerstone previewer with NiiVue for NIFTI
- Loading branch information
Showing
9 changed files
with
109 additions
and
12 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
.container { | ||
width: 100%; | ||
height: 100%; | ||
} | ||
|
||
|
||
.controlBar { | ||
position: absolute; | ||
top: -10px; | ||
height: 8px; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
import React from "react"; | ||
import { IFileBlob } from "../../../api/model.ts"; | ||
import { NVROptions, NVRVolume } from "niivue-react/src/model.ts"; | ||
import SizedNiivueCanvas from "../../SizedNiivueCanvas"; | ||
import { SLICE_TYPE } from "@niivue/niivue"; | ||
import styles from "./NiiVueDisplay.module.css"; | ||
|
||
type NiiVueDisplayProps = { | ||
fileItem: IFileBlob; | ||
}; | ||
|
||
type PreviewOptions = Required< | ||
Pick< | ||
NVROptions, | ||
| "sliceType" | ||
| "isColorbar" | ||
| "backColor" | ||
| "isRadiologicalConvention" | ||
| "crosshairWidth" | ||
> | ||
>; | ||
|
||
const SLICE_TYPES = { | ||
A: SLICE_TYPE.AXIAL, | ||
C: SLICE_TYPE.CORONAL, | ||
S: SLICE_TYPE.SAGITTAL, | ||
M: SLICE_TYPE.MULTIPLANAR, | ||
}; | ||
|
||
const NiiVueDisplay: React.FC<NiiVueDisplayProps> = ({ fileItem }) => { | ||
const [colormap, setColormap] = React.useState("gray"); | ||
const [sliceTypeName, setSliceTypeName] = | ||
React.useState<keyof typeof SLICE_TYPES>("M"); | ||
|
||
const volumes: NVRVolume[] = []; | ||
|
||
const options: PreviewOptions = { | ||
backColor: [0, 0, 0], | ||
isRadiologicalConvention: true, | ||
sliceType: SLICE_TYPES[sliceTypeName], | ||
isColorbar: false, | ||
crosshairWidth: sliceTypeName === "M" ? 0.5 : 0, | ||
}; | ||
|
||
if (fileItem.blob !== undefined && fileItem.file !== undefined) { | ||
volumes.push({ | ||
// NiiVue gets the file extension from name | ||
name: fileItem.file.data.fname, | ||
url: window.URL.createObjectURL(fileItem.blob), | ||
colormap: colormap, | ||
}); | ||
} | ||
|
||
const toggleColormap = () => { | ||
setColormap(colormap === "gray" ? "freesurfer" : "gray"); | ||
}; | ||
|
||
const rotateSliceType = () => { | ||
const names = Object.keys(SLICE_TYPES) as (keyof typeof SLICE_TYPES)[]; | ||
const i = names.indexOf(sliceTypeName); | ||
const next = i + 1 >= names.length ? 0 : i + 1; | ||
setSliceTypeName(names[next]); | ||
}; | ||
|
||
return ( | ||
<> | ||
{volumes.length === 0 ? ( | ||
<h1>error</h1> | ||
) : ( | ||
<div className={styles.container}> | ||
<div className={styles.controlBar}> | ||
<button onClick={toggleColormap}>{colormap}</button> | ||
<button onClick={rotateSliceType}>{sliceTypeName}</button> | ||
</div> | ||
<SizedNiivueCanvas size={8} volumes={volumes} options={options} /> | ||
</div> | ||
)} | ||
</> | ||
); | ||
}; | ||
|
||
const MemoedNiiVueDisplay = React.memo(NiiVueDisplay); | ||
export default MemoedNiiVueDisplay; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters