ソースを参照

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 <[email protected]>
Co-authored-by: Michael Herzog <[email protected]>
LinkunGao 2 年 前
コミット
e7d1573389
2 ファイル変更28 行追加7 行削除
  1. 8 2
      examples/jsm/loaders/NRRDLoader.js
  2. 20 5
      examples/jsm/misc/Volume.js

+ 8 - 2
examples/jsm/loaders/NRRDLoader.js

@@ -363,6 +363,7 @@ class NRRDLoader extends Loader {
 
 		const volume = new Volume();
 		volume.header = headerObject;
+		volume.segmentation = this.segmentation;
 		//
 		// parse the (unzipped) data to a datastream of the correct type
 		//
@@ -445,7 +446,7 @@ class NRRDLoader extends Loader {
 		}
 
 
-		if ( ! headerObject.vectors || this.segmentation ) {
+		if ( ! headerObject.vectors ) {
 
 			volume.matrix.set(
 				1, 0, 0, 0,
@@ -472,7 +473,12 @@ class NRRDLoader extends Loader {
 
 		volume.inverseMatrix = new Matrix4();
 		volume.inverseMatrix.copy( volume.matrix ).invert();
-		volume.RASDimensions = new Vector3( volume.xLength, volume.yLength, volume.zLength ).applyMatrix4( volume.matrix ).round().toArray().map( Math.abs );
+		
+		volume.RASDimensions = [
+			Math.floor( volume.xLength * spacingX ), 
+			Math.floor( volume.yLength * spacingY ), 
+			Math.floor( volume.zLength * spacingZ )
+		];
 
 		// .. and set the default threshold
 		// only if the threshold was not already set

+ 20 - 5
examples/jsm/misc/Volume.js

@@ -194,10 +194,18 @@ class Volume {
 		this.sliceList = [];
 
 
+		/**
+		 * @member {boolean} segmentation in segmentation mode, it can load 16-bits nrrds correctly
+		 */
+		this.segmentation = false;
+
+
 		/**
 		 * @member {Array} RASDimensions This array holds the dimensions of the volume in the RAS space
 		 */
 
+
+
 	}
 
 	/**
@@ -332,13 +340,20 @@ class Volume {
 
 		}
 
-		firstDirection.applyMatrix4( volume.inverseMatrix ).normalize();
+
+		let iLength, jLength;
+
+		if( ! this.segmentation ) {
+
+			firstDirection.applyMatrix4( volume.inverseMatrix ).normalize();
+			secondDirection.applyMatrix4( volume.inverseMatrix ).normalize();
+			axisInIJK.applyMatrix4( volume.inverseMatrix ).normalize();
+
+		}
 		firstDirection.arglet = 'i';
-		secondDirection.applyMatrix4( volume.inverseMatrix ).normalize();
 		secondDirection.arglet = 'j';
-		axisInIJK.applyMatrix4( volume.inverseMatrix ).normalize();
-		const iLength = Math.floor( Math.abs( firstDirection.dot( dimensions ) ) );
-		const jLength = Math.floor( Math.abs( secondDirection.dot( dimensions ) ) );
+		iLength = Math.floor( Math.abs( firstDirection.dot( dimensions ) ) );
+		jLength = Math.floor( Math.abs( secondDirection.dot( dimensions ) ) );
 		const planeWidth = Math.abs( iLength * firstSpacing );
 		const planeHeight = Math.abs( jLength * secondSpacing );