Skip to content

Commit

Permalink
Added trilinear interpolation to VolumeColormaker
Browse files Browse the repository at this point in the history
  • Loading branch information
fredludlow committed May 31, 2017
1 parent 5525166 commit 7cfdbd6
Showing 1 changed file with 45 additions and 5 deletions.
50 changes: 45 additions & 5 deletions src/color/volume-colormaker.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@


import { Vector3 } from "../../lib/three.es6.js";
import { lerp } from "../math/math-utils.js";

import { ColormakerRegistry } from "../globals.js";
import Colormaker from "./colormaker.js";


/**
* Color by volume position
*/
Expand All @@ -29,17 +29,57 @@ class VolumeColormaker extends Colormaker{
var data = volume.data;
var nx = volume.nx;
var ny = volume.ny;
var nxy = nx * ny;
var vec = new Vector3();

this.positionColor = function( coords ){

vec.copy( coords );
vec.applyMatrix4( inverseMatrix );
vec.round();

var index = ( ( ( ( vec.z * ny ) + vec.y ) * nx ) + vec.x );

return valueScale( data[ index ] );
// Trilinear interpolation test
var x0 = Math.floor( vec.x );
var y0 = Math.floor( vec.y );
var z0 = Math.floor( vec.z );

// Indices
var i = ( ( ( ( z0 * ny ) + y0 ) * nx ) + x0 );
var i1 = i + 1;
var iy = i + nx;
var iz = i + nxy;
var i1y = iy + 1;
var i1z = iz + 1;
var iyz = iy + nxy;
var i1yz = iyz + 1;

// Values
var v = data[ i ];
var v1 = data[ i1 ];
var vy = data[ iy ];
var vz = data[ iz ];
var v1y = data[ i1y ];
var v1z = data[ i1z ];
var vyz = data[ iyz ];
var v1yz = data[ i1yz ];

var xd = vec.x - x0;
var yd = vec.y - y0;
var zd = vec.z - z0;

var c00 = lerp( v, v1, xd );
var c01 = lerp( vz, v1z, xd );
var c10 = lerp( vy, v1y, xd );
var c11 = lerp( vyz, v1yz, xd );

var c0 = lerp( c00, c10, yd );
var c1 = lerp( c01, c11, yd );
var c = lerp( c0, c1, zd );

return valueScale( c );

//vec.round();
//var index = ( ( ( ( vec.z * ny ) + vec.y ) * nx ) + vec.x );
//return valueScale( data[ index ] );

};

Expand Down

0 comments on commit 7cfdbd6

Please sign in to comment.