Skip to content

Commit e7d1573

Browse files
LinkunGaoskycocoMugen87
authored
NRRDLoader: Fix spacing issue when loading 16 bit images. (#25767)
* fixed the nrrd images' spacing issue on loading 16 bits images * undo the ijk_to_transition matrix4 changes, continue use set(row-major order) * Update NRRDLoader.js * Update Volume.js * using array instead of vector3 when creating RASDimensions --------- Co-authored-by: skycoco <skycoco1994@gmail.com> Co-authored-by: Michael Herzog <michael.herzog@human-interactive.org>
1 parent 9f8bb69 commit e7d1573

File tree

2 files changed

+28
-7
lines changed

2 files changed

+28
-7
lines changed

examples/jsm/loaders/NRRDLoader.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,7 @@ class NRRDLoader extends Loader {
363363

364364
const volume = new Volume();
365365
volume.header = headerObject;
366+
volume.segmentation = this.segmentation;
366367
//
367368
// parse the (unzipped) data to a datastream of the correct type
368369
//
@@ -445,7 +446,7 @@ class NRRDLoader extends Loader {
445446
}
446447

447448

448-
if ( ! headerObject.vectors || this.segmentation ) {
449+
if ( ! headerObject.vectors ) {
449450

450451
volume.matrix.set(
451452
1, 0, 0, 0,
@@ -472,7 +473,12 @@ class NRRDLoader extends Loader {
472473

473474
volume.inverseMatrix = new Matrix4();
474475
volume.inverseMatrix.copy( volume.matrix ).invert();
475-
volume.RASDimensions = new Vector3( volume.xLength, volume.yLength, volume.zLength ).applyMatrix4( volume.matrix ).round().toArray().map( Math.abs );
476+
477+
volume.RASDimensions = [
478+
Math.floor( volume.xLength * spacingX ),
479+
Math.floor( volume.yLength * spacingY ),
480+
Math.floor( volume.zLength * spacingZ )
481+
];
476482

477483
// .. and set the default threshold
478484
// only if the threshold was not already set

examples/jsm/misc/Volume.js

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -194,10 +194,18 @@ class Volume {
194194
this.sliceList = [];
195195

196196

197+
/**
198+
* @member {boolean} segmentation in segmentation mode, it can load 16-bits nrrds correctly
199+
*/
200+
this.segmentation = false;
201+
202+
197203
/**
198204
* @member {Array} RASDimensions This array holds the dimensions of the volume in the RAS space
199205
*/
200206

207+
208+
201209
}
202210

203211
/**
@@ -332,13 +340,20 @@ class Volume {
332340

333341
}
334342

335-
firstDirection.applyMatrix4( volume.inverseMatrix ).normalize();
343+
344+
let iLength, jLength;
345+
346+
if( ! this.segmentation ) {
347+
348+
firstDirection.applyMatrix4( volume.inverseMatrix ).normalize();
349+
secondDirection.applyMatrix4( volume.inverseMatrix ).normalize();
350+
axisInIJK.applyMatrix4( volume.inverseMatrix ).normalize();
351+
352+
}
336353
firstDirection.arglet = 'i';
337-
secondDirection.applyMatrix4( volume.inverseMatrix ).normalize();
338354
secondDirection.arglet = 'j';
339-
axisInIJK.applyMatrix4( volume.inverseMatrix ).normalize();
340-
const iLength = Math.floor( Math.abs( firstDirection.dot( dimensions ) ) );
341-
const jLength = Math.floor( Math.abs( secondDirection.dot( dimensions ) ) );
355+
iLength = Math.floor( Math.abs( firstDirection.dot( dimensions ) ) );
356+
jLength = Math.floor( Math.abs( secondDirection.dot( dimensions ) ) );
342357
const planeWidth = Math.abs( iLength * firstSpacing );
343358
const planeHeight = Math.abs( jLength * secondSpacing );
344359

0 commit comments

Comments
 (0)