@@ -3,10 +3,14 @@ import { Niivue, SLICE_TYPE, SHOW_RENDER, MULTIPLANAR_TYPE } from '@niivue/niivu
33import { Niimath } from "@niivue/niimath"
44
55// create niivue instance but don't setup the scene just yet
6- const nv = new Niivue ( ) ;
6+ const nv = new Niivue ( {
7+ logLevel : 'debug'
8+ } ) ;
79
810// create niimath instance (will be initialized later)
911const niimath = new Niimath ( ) ;
12+ console . log ( niimath ) ;
13+
1014
1115// store a reference to an unedited image for
1216// use when the user wants to change the command from the dropdown
@@ -16,24 +20,39 @@ async function processImage(isOverlay) {
1620 loadingCircle . classList . remove ( 'hidden' )
1721 try {
1822 const imageIndex = 0 ;
19- const niiBuffer = await nv . saveImage ( { volumeByIndex : imageIndex } ) . buffer
23+ const niiBuffer = await nv . saveImage ( { volumeByIndex : imageIndex } )
2024 const niiFile = new File ( [ niiBuffer ] , 'image.nii' )
2125 const input = document . getElementById ( 'command' ) ;
2226 const cmd = input . value ;
2327 const imageProcessor = niimath . image ( niiFile )
2428 // check if "mesh" is in the command, and set isMesh
2529 const isMesh = cmd . includes ( 'mesh' )
30+ // check if "bitmap" is in the command, and set isBitmap
31+ const isBitmap = cmd . includes ( 'bitmap' )
2632 // create array of commands by separating on spaces
2733 // trim any leading or trailing whitespace
2834 const commands = cmd . split ( ' ' ) . map ( ( c ) => c . trim ( ) )
2935 imageProcessor . commands = [ ...commands ]
30- const outName = isMesh ? 'mesh.mz3' : 'image.nii'
31- const processedBlob = await imageProcessor . run ( outName ) // don't use .gz
36+ const outName = isMesh ? 'mesh.mz3' : isBitmap ? 'bitmap.png' : 'image.nii.gz'
37+ console . log ( 'ismesh' , isMesh ) ;
38+ console . log ( imageProcessor ) ;
39+ const processedBlob = await imageProcessor . run ( outName )
40+ console . log ( processedBlob ) ;
41+
3242 const arrayBuffer = await processedBlob . arrayBuffer ( )
3343 if ( ! isOverlay ) {
3444 nv . removeVolume ( nv . volumes [ 0 ] ) ;
3545 }
36- await nv . loadFromArrayBuffer ( arrayBuffer , outName )
46+
47+ if ( isBitmap ) {
48+ // For bitmap outputs, use arrayBuffer with a name property ending in .png
49+ await nv . loadVolumes ( [ { url : arrayBuffer , name : outName } ] )
50+ } else {
51+ // For meshes and nifti files, use loadFromArrayBuffer
52+ console . log ( 'arrayBuffer' , arrayBuffer ) ;
53+ await nv . loadFromArrayBuffer ( arrayBuffer , outName )
54+ }
55+
3756 // set the colormap to the value of the color dropdown
3857 if ( isOverlay ) {
3958 setOverlayColor ( ) ;
@@ -128,6 +147,9 @@ function populateMoreCommands() {
128147 '-sobel_binary' ,
129148 '-otsu 5' ,
130149 '-recip' ,
150+ '-bitmap -x 0.33 0.66 -r -y 0.33 0.66 -r -z 0.33 0.66 basic.png' ,
151+ '-bitmap -y 0.33 0.66 -z 0.33 0.66 -X 0.5 -c viridis cross.png' ,
152+ '-bitmap -o 0.5 -c inferno optimal.png' ,
131153 ] ;
132154 for ( let i = 0 ; i < commands . length ; i ++ ) {
133155 let option = document . createElement ( "option" ) ;
@@ -277,6 +299,7 @@ async function main() {
277299
278300 // initialize niimath (loads wasm and sets up worker)
279301 await niimath . init ( ) ;
302+ console . log ( niimath ) ;
280303
281304 // enable our button after our WASM has been setup
282305 initializeImageProcessing ( ) ;
0 commit comments