Browse Source

Examples: Clean up.

Mr.doob 4 years ago
parent
commit
2f6358dd55

+ 21 - 45
examples/js/loaders/NRRDLoader.js

@@ -359,80 +359,56 @@
 			volume.windowLow = min;
 			volume.windowLow = min;
 			volume.windowHigh = max; // get the image dimensions
 			volume.windowHigh = max; // get the image dimensions
 
 
-
-			// get the image dimensions
 			volume.dimensions = [ headerObject.sizes[ 0 ], headerObject.sizes[ 1 ], headerObject.sizes[ 2 ] ];
 			volume.dimensions = [ headerObject.sizes[ 0 ], headerObject.sizes[ 1 ], headerObject.sizes[ 2 ] ];
 			volume.xLength = volume.dimensions[ 0 ];
 			volume.xLength = volume.dimensions[ 0 ];
 			volume.yLength = volume.dimensions[ 1 ];
 			volume.yLength = volume.dimensions[ 1 ];
-			volume.zLength = volume.dimensions[ 2 ];
+			volume.zLength = volume.dimensions[ 2 ]; // Identify axis order in the space-directions matrix from the header if possible.
 
 
-			// Identify axis order in the space-directions matrix from the header if possible.
-			if (headerObject.vectors) {
-				const xIndex = headerObject.vectors.findIndex(vector => vector[0] !== 0);
-				const yIndex = headerObject.vectors.findIndex(vector => vector[1] !== 0);
-				const zIndex = headerObject.vectors.findIndex(vector => vector[2] !== 0);
+			if ( headerObject.vectors ) {
 
 
+				const xIndex = headerObject.vectors.findIndex( vector => vector[ 0 ] !== 0 );
+				const yIndex = headerObject.vectors.findIndex( vector => vector[ 1 ] !== 0 );
+				const zIndex = headerObject.vectors.findIndex( vector => vector[ 2 ] !== 0 );
 				const axisOrder = [];
 				const axisOrder = [];
-				axisOrder[xIndex] = 'x';
-				axisOrder[yIndex] = 'y';
-				axisOrder[zIndex] = 'z';
+				axisOrder[ xIndex ] = 'x';
+				axisOrder[ yIndex ] = 'y';
+				axisOrder[ zIndex ] = 'z';
 				volume.axisOrder = axisOrder;
 				volume.axisOrder = axisOrder;
-			}
-			else {
-				volume.axisOrder = ['x', 'y', 'z'];
-			}
 
 
-			// spacing
+			} else {
+
+				volume.axisOrder = [ 'x', 'y', 'z' ];
+
+			} // spacing
+
+
 			const spacingX = new THREE.Vector3().fromArray( headerObject.vectors[ 0 ] ).length();
 			const spacingX = new THREE.Vector3().fromArray( headerObject.vectors[ 0 ] ).length();
 			const spacingY = new THREE.Vector3().fromArray( headerObject.vectors[ 1 ] ).length();
 			const spacingY = new THREE.Vector3().fromArray( headerObject.vectors[ 1 ] ).length();
 			const spacingZ = new THREE.Vector3().fromArray( headerObject.vectors[ 2 ] ).length();
 			const spacingZ = new THREE.Vector3().fromArray( headerObject.vectors[ 2 ] ).length();
-			volume.spacing = [ spacingX, spacingY, spacingZ ];
+			volume.spacing = [ spacingX, spacingY, spacingZ ]; // Create IJKtoRAS matrix
 
 
-			// Create IJKtoRAS matrix
 			volume.matrix = new THREE.Matrix4();
 			volume.matrix = new THREE.Matrix4();
-
 			const transitionMatrix = new THREE.Matrix4();
 			const transitionMatrix = new THREE.Matrix4();
 
 
 			if ( headerObject.space === 'left-posterior-superior' ) {
 			if ( headerObject.space === 'left-posterior-superior' ) {
 
 
-				transitionMatrix.set(
-					- 1, 0, 0, 0,
-					0, -1, 0, 0,
-					0, 0, 1, 0,
-					0, 0, 0, 1 );
+				transitionMatrix.set( - 1, 0, 0, 0, 0, - 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 );
 
 
 			} else if ( headerObject.space === 'left-anterior-superior' ) {
 			} else if ( headerObject.space === 'left-anterior-superior' ) {
 
 
-				transitionMatrix.set(
-					1, 0, 0, 0,
-					0, 1, 0, 0,
-					0, 0, -1, 0,
-					0, 0, 0, 1 );
+				transitionMatrix.set( 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, - 1, 0, 0, 0, 0, 1 );
 
 
 			}
 			}
 
 
-
 			if ( ! headerObject.vectors ) {
 			if ( ! headerObject.vectors ) {
 
 
-				volume.matrix.set(
-					1, 0, 0, 0,
-					0, 1, 0, 0,
-					0, 0, 1, 0,
-					0, 0, 0, 1 );
+				volume.matrix.set( 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 );
 
 
 			} else {
 			} else {
 
 
 				const v = headerObject.vectors;
 				const v = headerObject.vectors;
-
-				const ijk_to_transition = ( new THREE.Matrix4() ).set(
-					v[ 0 ][ 0 ], v[ 1 ][ 0 ], v[ 2 ][ 0 ], 0,
-					v[ 0 ][ 1 ], v[ 1 ][ 1 ], v[ 2 ][ 1 ], 0,
-					v[ 0 ][ 2 ], v[ 1 ][ 2 ], v[ 2 ][ 2 ], 0,
-					0, 0, 0, 1
-				)
-
-				const transition_to_ras = (new THREE.Matrix4()).multiplyMatrices( ijk_to_transition, transitionMatrix );
-
+				const ijk_to_transition = new THREE.Matrix4().set( v[ 0 ][ 0 ], v[ 1 ][ 0 ], v[ 2 ][ 0 ], 0, v[ 0 ][ 1 ], v[ 1 ][ 1 ], v[ 2 ][ 1 ], 0, v[ 0 ][ 2 ], v[ 1 ][ 2 ], v[ 2 ][ 2 ], 0, 0, 0, 0, 1 );
+				const transition_to_ras = new THREE.Matrix4().multiplyMatrices( ijk_to_transition, transitionMatrix );
 				volume.matrix = transition_to_ras;
 				volume.matrix = transition_to_ras;
 
 
 			}
 			}

+ 10 - 12
examples/js/misc/Volume.js

@@ -13,7 +13,7 @@
  * @param   {ArrayBuffer}   arrayBuffer     The buffer with volume data
  * @param   {ArrayBuffer}   arrayBuffer     The buffer with volume data
  */
  */
 
 
-	var Volume = function ( xLength, yLength, zLength, type, arrayBuffer ) {
+	function Volume( xLength, yLength, zLength, type, arrayBuffer ) {
 
 
 		if ( arguments.length > 0 ) {
 		if ( arguments.length > 0 ) {
 
 
@@ -31,13 +31,11 @@
      */
      */
 
 
 			this.zLength = Number( zLength ) || 1;
 			this.zLength = Number( zLength ) || 1;
-
 			/**
 			/**
-			 * @member {Array<string>} The order of the Axis dictated by the NRRD header
-			 */
+     * @member {Array<string>} The order of the Axis dictated by the NRRD header
+     */
 
 
 			this.axisOrder = [ 'x', 'y', 'z' ];
 			this.axisOrder = [ 'x', 'y', 'z' ];
-
 			/**
 			/**
      * @member {TypedArray} data Data of the volume
      * @member {TypedArray} data Data of the volume
      */
      */
@@ -209,7 +207,7 @@
    * @member {Array} RASDimensions This array holds the dimensions of the volume in the RAS space
    * @member {Array} RASDimensions This array holds the dimensions of the volume in the RAS space
    */
    */
 
 
-	};
+	}
 
 
 	Volume.prototype = {
 	Volume.prototype = {
 		constructor: Volume,
 		constructor: Volume,
@@ -313,8 +311,8 @@
 					axisInIJK.set( 1, 0, 0 );
 					axisInIJK.set( 1, 0, 0 );
 					firstDirection.set( 0, 0, - 1 );
 					firstDirection.set( 0, 0, - 1 );
 					secondDirection.set( 0, - 1, 0 );
 					secondDirection.set( 0, - 1, 0 );
-					firstSpacing = this.spacing[ this.axisOrder.indexOf('z') ];
-					secondSpacing = this.spacing[ this.axisOrder.indexOf('y') ];
+					firstSpacing = this.spacing[ this.axisOrder.indexOf( 'z' ) ];
+					secondSpacing = this.spacing[ this.axisOrder.indexOf( 'y' ) ];
 					IJKIndex = new THREE.Vector3( RASIndex, 0, 0 );
 					IJKIndex = new THREE.Vector3( RASIndex, 0, 0 );
 					planeMatrix.multiply( new THREE.Matrix4().makeRotationY( Math.PI / 2 ) );
 					planeMatrix.multiply( new THREE.Matrix4().makeRotationY( Math.PI / 2 ) );
 					positionOffset = ( volume.RASDimensions[ 0 ] - 1 ) / 2;
 					positionOffset = ( volume.RASDimensions[ 0 ] - 1 ) / 2;
@@ -325,8 +323,8 @@
 					axisInIJK.set( 0, 1, 0 );
 					axisInIJK.set( 0, 1, 0 );
 					firstDirection.set( 1, 0, 0 );
 					firstDirection.set( 1, 0, 0 );
 					secondDirection.set( 0, 0, 1 );
 					secondDirection.set( 0, 0, 1 );
-					firstSpacing = this.spacing[ this.axisOrder.indexOf('x') ];
-					secondSpacing = this.spacing[ this.axisOrder.indexOf('z') ];
+					firstSpacing = this.spacing[ this.axisOrder.indexOf( 'x' ) ];
+					secondSpacing = this.spacing[ this.axisOrder.indexOf( 'z' ) ];
 					IJKIndex = new THREE.Vector3( 0, RASIndex, 0 );
 					IJKIndex = new THREE.Vector3( 0, RASIndex, 0 );
 					planeMatrix.multiply( new THREE.Matrix4().makeRotationX( - Math.PI / 2 ) );
 					planeMatrix.multiply( new THREE.Matrix4().makeRotationX( - Math.PI / 2 ) );
 					positionOffset = ( volume.RASDimensions[ 1 ] - 1 ) / 2;
 					positionOffset = ( volume.RASDimensions[ 1 ] - 1 ) / 2;
@@ -338,8 +336,8 @@
 					axisInIJK.set( 0, 0, 1 );
 					axisInIJK.set( 0, 0, 1 );
 					firstDirection.set( 1, 0, 0 );
 					firstDirection.set( 1, 0, 0 );
 					secondDirection.set( 0, - 1, 0 );
 					secondDirection.set( 0, - 1, 0 );
-					firstSpacing = this.spacing[ this.axisOrder.indexOf('x') ];
-					secondSpacing = this.spacing[ this.axisOrder.indexOf('y') ];
+					firstSpacing = this.spacing[ this.axisOrder.indexOf( 'x' ) ];
+					secondSpacing = this.spacing[ this.axisOrder.indexOf( 'y' ) ];
 					IJKIndex = new THREE.Vector3( 0, 0, RASIndex );
 					IJKIndex = new THREE.Vector3( 0, 0, RASIndex );
 					positionOffset = ( volume.RASDimensions[ 2 ] - 1 ) / 2;
 					positionOffset = ( volume.RASDimensions[ 2 ] - 1 ) / 2;
 					planeMatrix.setPosition( new THREE.Vector3( 0, 0, RASIndex - positionOffset ) );
 					planeMatrix.setPosition( new THREE.Vector3( 0, 0, RASIndex - positionOffset ) );

+ 2 - 2
examples/js/misc/VolumeSlice.js

@@ -9,7 +9,7 @@
  * @see Volume
  * @see Volume
  */
  */
 
 
-	var VolumeSlice = function ( volume, index, axis ) {
+	function VolumeSlice( volume, index, axis ) {
 
 
 		var slice = this;
 		var slice = this;
 		/**
 		/**
@@ -96,7 +96,7 @@
    * @returns {Number} the index corresponding to the voxel in volume.data of the given position in the slice
    * @returns {Number} the index corresponding to the voxel in volume.data of the given position in the slice
    */
    */
 
 
-	};
+	}
 
 
 	VolumeSlice.prototype = {
 	VolumeSlice.prototype = {
 		constructor: VolumeSlice,
 		constructor: VolumeSlice,

+ 23 - 18
examples/jsm/loaders/NRRDLoader.js

@@ -365,19 +365,22 @@ class NRRDLoader extends Loader {
 		volume.zLength = volume.dimensions[ 2 ];
 		volume.zLength = volume.dimensions[ 2 ];
 
 
 		// Identify axis order in the space-directions matrix from the header if possible.
 		// Identify axis order in the space-directions matrix from the header if possible.
-		if (headerObject.vectors) {
-			const xIndex = headerObject.vectors.findIndex(vector => vector[0] !== 0);
-			const yIndex = headerObject.vectors.findIndex(vector => vector[1] !== 0);
-			const zIndex = headerObject.vectors.findIndex(vector => vector[2] !== 0);
+		if ( headerObject.vectors ) {
+
+			const xIndex = headerObject.vectors.findIndex( vector => vector[ 0 ] !== 0 );
+			const yIndex = headerObject.vectors.findIndex( vector => vector[ 1 ] !== 0 );
+			const zIndex = headerObject.vectors.findIndex( vector => vector[ 2 ] !== 0 );
 
 
 			const axisOrder = [];
 			const axisOrder = [];
-			axisOrder[xIndex] = 'x';
-			axisOrder[yIndex] = 'y';
-			axisOrder[zIndex] = 'z';
+			axisOrder[ xIndex ] = 'x';
+			axisOrder[ yIndex ] = 'y';
+			axisOrder[ zIndex ] = 'z';
 			volume.axisOrder = axisOrder;
 			volume.axisOrder = axisOrder;
-		}
-		else {
-			volume.axisOrder = ['x', 'y', 'z'];
+
+		} else {
+
+			volume.axisOrder = [ 'x', 'y', 'z' ];
+
 		}
 		}
 
 
 		// spacing
 		// spacing
@@ -396,17 +399,19 @@ class NRRDLoader extends Loader {
 
 
 			transitionMatrix.set(
 			transitionMatrix.set(
 				- 1, 0, 0, 0,
 				- 1, 0, 0, 0,
-				0, -1, 0, 0,
+				0, - 1, 0, 0,
 				0, 0, 1, 0,
 				0, 0, 1, 0,
-				0, 0, 0, 1 );
+				0, 0, 0, 1
+			);
 
 
 		} else if ( headerObject.space === 'left-anterior-superior' ) {
 		} else if ( headerObject.space === 'left-anterior-superior' ) {
 
 
 			transitionMatrix.set(
 			transitionMatrix.set(
 				1, 0, 0, 0,
 				1, 0, 0, 0,
 				0, 1, 0, 0,
 				0, 1, 0, 0,
-				0, 0, -1, 0,
-				0, 0, 0, 1 );
+				0, 0, - 1, 0,
+				0, 0, 0, 1
+			);
 
 
 		}
 		}
 
 
@@ -423,14 +428,14 @@ class NRRDLoader extends Loader {
 
 
 			const v = headerObject.vectors;
 			const v = headerObject.vectors;
 
 
-			const ijk_to_transition = ( new Matrix4() ).set(
+			const ijk_to_transition = new Matrix4().set(
 				v[ 0 ][ 0 ], v[ 1 ][ 0 ], v[ 2 ][ 0 ], 0,
 				v[ 0 ][ 0 ], v[ 1 ][ 0 ], v[ 2 ][ 0 ], 0,
 				v[ 0 ][ 1 ], v[ 1 ][ 1 ], v[ 2 ][ 1 ], 0,
 				v[ 0 ][ 1 ], v[ 1 ][ 1 ], v[ 2 ][ 1 ], 0,
 				v[ 0 ][ 2 ], v[ 1 ][ 2 ], v[ 2 ][ 2 ], 0,
 				v[ 0 ][ 2 ], v[ 1 ][ 2 ], v[ 2 ][ 2 ], 0,
 				0, 0, 0, 1
 				0, 0, 0, 1
-			)
+			);
 
 
-			const transition_to_ras = (new Matrix4()).multiplyMatrices( ijk_to_transition, transitionMatrix );
+			const transition_to_ras = new Matrix4().multiplyMatrices( ijk_to_transition, transitionMatrix );
 
 
 			volume.matrix = transition_to_ras;
 			volume.matrix = transition_to_ras;
 
 
@@ -438,7 +443,7 @@ class NRRDLoader extends Loader {
 
 
 		volume.inverseMatrix = new Matrix4();
 		volume.inverseMatrix = new Matrix4();
 		volume.inverseMatrix.copy( volume.matrix ).invert();
 		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 = new Vector3( volume.xLength, volume.yLength, volume.zLength ).applyMatrix4( volume.matrix ).round().toArray().map( Math.abs );
 
 
 		// .. and set the default threshold
 		// .. and set the default threshold
 		// only if the threshold was not already set
 		// only if the threshold was not already set

+ 8 - 8
examples/jsm/misc/Volume.js

@@ -17,7 +17,7 @@ import { VolumeSlice } from '../misc/VolumeSlice.js';
  * @param   {string}        type            The type of data (uint8, uint16, ...)
  * @param   {string}        type            The type of data (uint8, uint16, ...)
  * @param   {ArrayBuffer}   arrayBuffer     The buffer with volume data
  * @param   {ArrayBuffer}   arrayBuffer     The buffer with volume data
  */
  */
-var Volume = function ( xLength, yLength, zLength, type, arrayBuffer ) {
+function Volume( xLength, yLength, zLength, type, arrayBuffer ) {
 
 
 	if ( arguments.length > 0 ) {
 	if ( arguments.length > 0 ) {
 
 
@@ -196,7 +196,7 @@ var Volume = function ( xLength, yLength, zLength, type, arrayBuffer ) {
 	 * @member {Array} RASDimensions This array holds the dimensions of the volume in the RAS space
 	 * @member {Array} RASDimensions This array holds the dimensions of the volume in the RAS space
 	 */
 	 */
 
 
-};
+}
 
 
 Volume.prototype = {
 Volume.prototype = {
 
 
@@ -304,8 +304,8 @@ Volume.prototype = {
 				axisInIJK.set( 1, 0, 0 );
 				axisInIJK.set( 1, 0, 0 );
 				firstDirection.set( 0, 0, - 1 );
 				firstDirection.set( 0, 0, - 1 );
 				secondDirection.set( 0, - 1, 0 );
 				secondDirection.set( 0, - 1, 0 );
-				firstSpacing = this.spacing[ this.axisOrder.indexOf('z') ];
-				secondSpacing = this.spacing[ this.axisOrder.indexOf('y') ];
+				firstSpacing = this.spacing[ this.axisOrder.indexOf( 'z' ) ];
+				secondSpacing = this.spacing[ this.axisOrder.indexOf( 'y' ) ];
 				IJKIndex = new Vector3( RASIndex, 0, 0 );
 				IJKIndex = new Vector3( RASIndex, 0, 0 );
 
 
 				planeMatrix.multiply( ( new Matrix4() ).makeRotationY( Math.PI / 2 ) );
 				planeMatrix.multiply( ( new Matrix4() ).makeRotationY( Math.PI / 2 ) );
@@ -316,8 +316,8 @@ Volume.prototype = {
 				axisInIJK.set( 0, 1, 0 );
 				axisInIJK.set( 0, 1, 0 );
 				firstDirection.set( 1, 0, 0 );
 				firstDirection.set( 1, 0, 0 );
 				secondDirection.set( 0, 0, 1 );
 				secondDirection.set( 0, 0, 1 );
-				firstSpacing = this.spacing[ this.axisOrder.indexOf('x') ];
-				secondSpacing = this.spacing[ this.axisOrder.indexOf('z') ];
+				firstSpacing = this.spacing[ this.axisOrder.indexOf( 'x' ) ];
+				secondSpacing = this.spacing[ this.axisOrder.indexOf( 'z' ) ];
 				IJKIndex = new Vector3( 0, RASIndex, 0 );
 				IJKIndex = new Vector3( 0, RASIndex, 0 );
 
 
 				planeMatrix.multiply( ( new Matrix4() ).makeRotationX( - Math.PI / 2 ) );
 				planeMatrix.multiply( ( new Matrix4() ).makeRotationX( - Math.PI / 2 ) );
@@ -329,8 +329,8 @@ Volume.prototype = {
 				axisInIJK.set( 0, 0, 1 );
 				axisInIJK.set( 0, 0, 1 );
 				firstDirection.set( 1, 0, 0 );
 				firstDirection.set( 1, 0, 0 );
 				secondDirection.set( 0, - 1, 0 );
 				secondDirection.set( 0, - 1, 0 );
-				firstSpacing = this.spacing[ this.axisOrder.indexOf('x') ];
-				secondSpacing = this.spacing[ this.axisOrder.indexOf('y') ];
+				firstSpacing = this.spacing[ this.axisOrder.indexOf( 'x' ) ];
+				secondSpacing = this.spacing[ this.axisOrder.indexOf( 'y' ) ];
 				IJKIndex = new Vector3( 0, 0, RASIndex );
 				IJKIndex = new Vector3( 0, 0, RASIndex );
 
 
 				positionOffset = ( volume.RASDimensions[ 2 ] - 1 ) / 2;
 				positionOffset = ( volume.RASDimensions[ 2 ] - 1 ) / 2;

+ 2 - 2
examples/jsm/misc/VolumeSlice.js

@@ -16,7 +16,7 @@ import {
  * @param   {string}       [axis='z']      For now only 'x', 'y' or 'z' but later it will change to a normal vector
  * @param   {string}       [axis='z']      For now only 'x', 'y' or 'z' but later it will change to a normal vector
  * @see Volume
  * @see Volume
  */
  */
-var VolumeSlice = function ( volume, index, axis ) {
+function VolumeSlice( volume, index, axis ) {
 
 
 	var slice = this;
 	var slice = this;
 	/**
 	/**
@@ -95,7 +95,7 @@ var VolumeSlice = function ( volume, index, axis ) {
 	 */
 	 */
 
 
 
 
-};
+}
 
 
 VolumeSlice.prototype = {
 VolumeSlice.prototype = {