hanayik / niivue

a WebGL2 based NIFTI volume viewer.
https://hanayik.github.io/niivue
BSD 3-Clause "New" or "Revised" License
11 stars 7 forks source link

mm2frac() #69

Closed neurolabusc closed 3 years ago

neurolabusc commented 3 years ago

New function mm2frac() converts object space (in millimeters) to normalized texture space (where each dimension is in range 0..1). This is the reverse transform of frac2mm(). Used together, this can allow yoking of niivue instances (e.g. when the mm value of one image is changed, the other one can be updated to show the equivalent location on a different image). This function is also the basis for loading overlays where the dimensions do not match the background image.

The formula is clearer in Matlab. Assuming a NIfTI image with dimensions dim and storm matrix m, we can convert any coordinates in millimeters (mm) to fractional object space (result):

dim = [207 256 215]
mm = [0 0 0]
m = [0.737463 0.000000 0.000000 -75.762535; 0.000000 0.737463 0.000000 -110.762535; 0.000000 0.000000 0.737463 -71.762535; 0.000000 0.000000 0.000000 1.000000];
v = [mm, 1]
invm = inv(m);
result = invm * v';
result = result(1:3) + 0.5;
result = result ./ dim'
neurolabusc commented 3 years ago

Also adds clipPlaneUpdate() that allows you to specify the clip plane with 3 parameters: azimuth (in range -180..180 or 0..360) elevation (in range -90..+90) depth: 0..+1.73 (e.g. 0.0 means clip plane at center of volume, 2 means clip plane too far away to cut object).

Example:

  clipPlaneUpdate([90, 0, 0.1]);