Browse Source

NRRDLoader: Fix loading 16-bits file with custom axes. (#25367)

* reset code format style

* Update NRRDLoader.js

Clean up code style.

* Update NRRDLoader.js

---------

Co-authored-by: Michael Herzog <[email protected]>
Co-authored-by: mrdoob <[email protected]>
LinkunGao 2 years ago
parent
commit
f24db3d786
1 changed files with 27 additions and 5 deletions
  1. 27 5
      examples/jsm/loaders/NRRDLoader.js

+ 27 - 5
examples/jsm/loaders/NRRDLoader.js

@@ -50,6 +50,16 @@ class NRRDLoader extends Loader {
 
 	}
 
+	/**
+	 *
+	 * @param {boolean} segmentation is a option for user to choose
+   	 */
+	setSegmentation( segmentation ) {
+
+	    this.segmentation = segmentation;
+
+	}
+
 	parse( data ) {
 
 		// this parser is largely inspired from the XTK NRRD parser : https://github.com/xtk/X
@@ -378,10 +388,22 @@ class NRRDLoader extends Loader {
 			const yIndex = headerObject.vectors.findIndex( vector => vector[ 1 ] !== 0 );
 			const zIndex = headerObject.vectors.findIndex( vector => vector[ 2 ] !== 0 );
 
-			const axisOrder = [];
-			axisOrder[ xIndex ] = 'x';
-			axisOrder[ yIndex ] = 'y';
-			axisOrder[ zIndex ] = 'z';
+			let axisOrder = [];
+
+			if ( xIndex !== yIndex && xIndex !== zIndex && yIndex !== zIndex ) {
+
+				axisOrder[ xIndex ] = 'x';
+				axisOrder[ yIndex ] = 'y';
+				axisOrder[ zIndex ] = 'z';
+
+			} else {
+
+				axisOrder[ 0 ] = 'x';
+				axisOrder[ 1 ] = 'y';
+				axisOrder[ 2 ] = 'z';
+
+			}
+
 			volume.axisOrder = axisOrder;
 
 		} else {
@@ -423,7 +445,7 @@ class NRRDLoader extends Loader {
 		}
 
 
-		if ( ! headerObject.vectors ) {
+		if ( ! headerObject.vectors || this.segmentation ) {
 
 			volume.matrix.set(
 				1, 0, 0, 0,