提交 2f6358dd 编写于 作者: M Mr.doob

Examples: Clean up.

上级 4e0669ae
......@@ -359,80 +359,56 @@
volume.windowLow = min;
volume.windowHigh = max; // get the image dimensions
// get the image dimensions
volume.dimensions = [ headerObject.sizes[ 0 ], headerObject.sizes[ 1 ], headerObject.sizes[ 2 ] ];
volume.xLength = volume.dimensions[ 0 ];
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 = [];
axisOrder[xIndex] = 'x';
axisOrder[yIndex] = 'y';
axisOrder[zIndex] = 'z';
axisOrder[ xIndex ] = 'x';
axisOrder[ yIndex ] = 'y';
axisOrder[ zIndex ] = 'z';
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 spacingY = new THREE.Vector3().fromArray( headerObject.vectors[ 1 ] ).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();
const transitionMatrix = new THREE.Matrix4();
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' ) {
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 ) {
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 {
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;
}
......
......@@ -13,7 +13,7 @@
* @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 ) {
......@@ -31,13 +31,11 @@
*/
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' ];
/**
* @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
*/
};
}
Volume.prototype = {
constructor: Volume,
......@@ -313,8 +311,8 @@
axisInIJK.set( 1, 0, 0 );
firstDirection.set( 0, 0, - 1 );
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 );
planeMatrix.multiply( new THREE.Matrix4().makeRotationY( Math.PI / 2 ) );
positionOffset = ( volume.RASDimensions[ 0 ] - 1 ) / 2;
......@@ -325,8 +323,8 @@
axisInIJK.set( 0, 1, 0 );
firstDirection.set( 1, 0, 0 );
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 );
planeMatrix.multiply( new THREE.Matrix4().makeRotationX( - Math.PI / 2 ) );
positionOffset = ( volume.RASDimensions[ 1 ] - 1 ) / 2;
......@@ -338,8 +336,8 @@
axisInIJK.set( 0, 0, 1 );
firstDirection.set( 1, 0, 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 );
positionOffset = ( volume.RASDimensions[ 2 ] - 1 ) / 2;
planeMatrix.setPosition( new THREE.Vector3( 0, 0, RASIndex - positionOffset ) );
......
......@@ -9,7 +9,7 @@
* @see Volume
*/
var VolumeSlice = function ( volume, index, axis ) {
function VolumeSlice( volume, index, axis ) {
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
*/
};
}
VolumeSlice.prototype = {
constructor: VolumeSlice,
......
......@@ -365,19 +365,22 @@ class NRRDLoader extends Loader {
volume.zLength = volume.dimensions[ 2 ];
// 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 = [];
axisOrder[xIndex] = 'x';
axisOrder[yIndex] = 'y';
axisOrder[zIndex] = 'z';
axisOrder[ xIndex ] = 'x';
axisOrder[ yIndex ] = 'y';
axisOrder[ zIndex ] = 'z';
volume.axisOrder = axisOrder;
}
else {
volume.axisOrder = ['x', 'y', 'z'];
} else {
volume.axisOrder = [ 'x', 'y', 'z' ];
}
// spacing
......@@ -396,17 +399,19 @@ class NRRDLoader extends Loader {
transitionMatrix.set(
- 1, 0, 0, 0,
0, -1, 0, 0,
0, - 1, 0, 0,
0, 0, 1, 0,
0, 0, 0, 1 );
0, 0, 0, 1
);
} 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 );
0, 0, - 1, 0,
0, 0, 0, 1
);
}
......@@ -423,14 +428,14 @@ class NRRDLoader extends Loader {
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 ][ 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 Matrix4()).multiplyMatrices( ijk_to_transition, transitionMatrix );
const transition_to_ras = new Matrix4().multiplyMatrices( ijk_to_transition, transitionMatrix );
volume.matrix = transition_to_ras;
......@@ -438,7 +443,7 @@ 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 = new Vector3( volume.xLength, volume.yLength, volume.zLength ).applyMatrix4( volume.matrix ).round().toArray().map( Math.abs );
// .. and set the default threshold
// only if the threshold was not already set
......
......@@ -17,7 +17,7 @@ import { VolumeSlice } from '../misc/VolumeSlice.js';
* @param {string} type The type of data (uint8, uint16, ...)
* @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 ) {
......@@ -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
*/
};
}
Volume.prototype = {
......@@ -304,8 +304,8 @@ Volume.prototype = {
axisInIJK.set( 1, 0, 0 );
firstDirection.set( 0, 0, - 1 );
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 );
planeMatrix.multiply( ( new Matrix4() ).makeRotationY( Math.PI / 2 ) );
......@@ -316,8 +316,8 @@ Volume.prototype = {
axisInIJK.set( 0, 1, 0 );
firstDirection.set( 1, 0, 0 );
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 );
planeMatrix.multiply( ( new Matrix4() ).makeRotationX( - Math.PI / 2 ) );
......@@ -329,8 +329,8 @@ Volume.prototype = {
axisInIJK.set( 0, 0, 1 );
firstDirection.set( 1, 0, 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 );
positionOffset = ( volume.RASDimensions[ 2 ] - 1 ) / 2;
......
......@@ -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
* @see Volume
*/
var VolumeSlice = function ( volume, index, axis ) {
function VolumeSlice( volume, index, axis ) {
var slice = this;
/**
......@@ -95,7 +95,7 @@ var VolumeSlice = function ( volume, index, axis ) {
*/
};
}
VolumeSlice.prototype = {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册