rordenlab / niimath

niimath - a clone of fslmaths. Try the live demo:
https://niivue.github.io/niivue-niimath/
Other
53 stars 15 forks source link

Enable mesh suboptions in javascript API #29

Closed hanayik closed 3 weeks ago

hanayik commented 3 weeks ago

The -mesh option is unique in that it takes a variable number of suboptions.

This breaks the niimath help text parser that the npm package build relied on. Therefore, I have updated the niimath CLI help text to indent the -mesh suboptions using 4 spaces and I have updated the help text parser to use this as a check for mesh suboptions.

Here's the new help text:

The mesh option has multiple sub-options:
 -mesh                    : meshify requires 'd'ark, 'm'edium, 'b'right or numeric isosurface ('niimath bet -mesh -i d mesh.gii')
        -i <isovalue>            : 'd'ark, 'm'edium, 'b'right or numeric isosurface
        -a <atlasFile>           : roi based atlas to mesh
        -b <fillBubbles>         : fill bubbles
        -l <onlyLargest>         : only largest
        -o <originalMC>          : original marching cubes
        -q <quality>             : quality
        -s <postSmooth>          : post smooth
        -r <reduceFraction>      : reduce fraction
        -v <verbose>             : verbose

Given that the use of -mesh suboptions is unique to that option, the JavaScript API follows suit in its uniqueness and uses an object as input to the mesh() function rather than use the method chaining API implemented for normal (non mesh options).

And here's an example of how to use the mesh function in the Javascript wrapper:

import { Niimath } from '@niivue/niimath';
const niimath = new Niimath();
await niimath.init();
const outName = 'out.mz3'; // outname must be a mesh format!
const outMesh = await niimath.image(selectedFile)
  .mesh({
    i: 'm', // 'd'ark, 'm'edium, 'b'right or numeric (e.g. 128) isosurface
    b: 1, // fill bubbles
  })
  .run(outName);