UNPKG

ami-cjs.js

Version:

<p align="center"> <img src="https://cloud.githubusercontent.com/assets/214063/23213764/78ade038-f90c-11e6-8208-4fcade5f3832.png" width="60%"> </p>

71 lines (52 loc) 7.02 kB
'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); var _shaders = require('../shaders.base'); var _shaders2 = _interopRequireDefault(_shaders); var _shadersInterpolation = require('./shaders.interpolation.identity'); var _shadersInterpolation2 = _interopRequireDefault(_shadersInterpolation); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } var InterpolationTrilinear = function (_ShadersBase) { _inherits(InterpolationTrilinear, _ShadersBase); function InterpolationTrilinear() { _classCallCheck(this, InterpolationTrilinear); var _this = _possibleConstructorReturn(this, (InterpolationTrilinear.__proto__ || Object.getPrototypeOf(InterpolationTrilinear)).call(this)); _this.name = 'interpolationTrilinear'; // default properties names _this._currentVoxel = 'currentVoxel'; _this._dataValue = 'dataValue'; _this._gradient = 'gradient'; return _this; } _createClass(InterpolationTrilinear, [{ key: 'api', value: function api() { var baseFragment = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : this._base; var currentVoxel = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : this._currentVoxel; var dataValue = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : this._dataValue; var gradient = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : this._gradient; this._base = baseFragment; return this.compute(currentVoxel, dataValue, gradient); } }, { key: 'compute', value: function compute(currentVoxel, dataValue, gradient) { this.computeDefinition(); this._base._functions[this._name] = this._definition; return this._name + '(' + currentVoxel + ', ' + dataValue + ', ' + gradient + ');'; } }, { key: 'computeDefinition', value: function computeDefinition() { this._definition = '\nvoid ' + this._name + '(in vec3 currentVoxel, out vec4 dataValue, out vec3 gradient){\n\n // https://en.wikipedia.org/wiki/Trilinear_interpolation\n vec3 lower_bound = vec3(floor(currentVoxel.x), floor(currentVoxel.y), floor(currentVoxel.z));\n if(lower_bound.x < 0.){\n lower_bound.x = 0.;\n }\n if(lower_bound.y < 0.){\n lower_bound.y = 0.;\n }\n if(lower_bound.z < 0.){\n lower_bound.z = 0.;\n }\n \n vec3 higher_bound = lower_bound + vec3(1);\n\n float xd = ( currentVoxel.x - lower_bound.x ) / ( higher_bound.x - lower_bound.x );\n float yd = ( currentVoxel.y - lower_bound.y ) / ( higher_bound.y - lower_bound.y );\n float zd = ( currentVoxel.z - lower_bound.z ) / ( higher_bound.z - lower_bound.z );\n\n //\n // c00\n //\n\n //\n\n vec4 v000 = vec4(0.0, 0.0, 0.0, 0.0);\n vec3 c000 = vec3(lower_bound.x, lower_bound.y, lower_bound.z);\n ' + _shadersInterpolation2.default.api(this._base, 'c000', 'v000') + '\n vec3 g000 = v000.r * vec3(-1., -1., -1.);\n\n //\n\n vec4 v100 = vec4(0.0, 0.0, 0.0, 0.0);\n vec3 c100 = vec3(higher_bound.x, lower_bound.y, lower_bound.z);\n ' + _shadersInterpolation2.default.api(this._base, 'c100', 'v100') + '\n vec3 g100 = v100.r * vec3(1., -1., -1.);\n\n vec4 c00 = v000 * ( 1.0 - xd ) + v100 * xd;\n\n //\n // c01\n //\n vec4 v001 = vec4(0.0, 0.0, 0.0, 0.0);\n vec3 c001 = vec3(lower_bound.x, lower_bound.y, higher_bound.z);\n ' + _shadersInterpolation2.default.api(this._base, 'c001', 'v001') + '\n vec3 g001 = v001.r * vec3(-1., -1., 1.);\n\n vec4 v101 = vec4(0.0, 0.0, 0.0, 0.0);\n vec3 c101 = vec3(higher_bound.x, lower_bound.y, higher_bound.z);\n ' + _shadersInterpolation2.default.api(this._base, 'c101', 'v101') + '\n vec3 g101 = v101.r * vec3(1., -1., 1.);\n\n vec4 c01 = v001 * ( 1.0 - xd ) + v101 * xd;\n\n //\n // c10\n //\n vec4 v010 = vec4(0.0, 0.0, 0.0, 0.0);\n vec3 c010 = vec3(lower_bound.x, higher_bound.y, lower_bound.z);\n ' + _shadersInterpolation2.default.api(this._base, 'c010', 'v010') + '\n vec3 g010 = v010.r * vec3(-1., 1., -1.);\n\n vec4 v110 = vec4(0.0, 0.0, 0.0, 0.0);\n vec3 c110 = vec3(higher_bound.x, higher_bound.y, lower_bound.z);\n ' + _shadersInterpolation2.default.api(this._base, 'c110', 'v110') + '\n vec3 g110 = v110.r * vec3(1., 1., -1.);\n\n vec4 c10 = v010 * ( 1.0 - xd ) + v110 * xd;\n\n //\n // c11\n //\n vec4 v011 = vec4(0.0, 0.0, 0.0, 0.0);\n vec3 c011 = vec3(lower_bound.x, higher_bound.y, higher_bound.z);\n ' + _shadersInterpolation2.default.api(this._base, 'c011', 'v011') + '\n vec3 g011 = v011.r * vec3(-1., 1., 1.);\n\n vec4 v111 = vec4(0.0, 0.0, 0.0, 0.0);\n vec3 c111 = vec3(higher_bound.x, higher_bound.y, higher_bound.z);\n ' + _shadersInterpolation2.default.api(this._base, 'c111', 'v111') + '\n vec3 g111 = v111.r * vec3(1., 1., 1.);\n\n vec4 c11 = v011 * ( 1.0 - xd ) + v111 * xd;\n\n // c0 and c1\n vec4 c0 = c00 * ( 1.0 - yd) + c10 * yd;\n vec4 c1 = c01 * ( 1.0 - yd) + c11 * yd;\n\n // c\n vec4 c = c0 * ( 1.0 - zd) + c1 * zd;\n dataValue = c;\n\n // compute gradient\n gradient = g000 + g100 + g010 + g110 + g011 + g111 + g110 + g011;\n // gradientMagnitude = length(gradient);\n // // https://en.wikipedia.org/wiki/Normal_(geometry)#Transforming_normals\n // vec3 localNormal = (-1. / gradientMagnitude) * gradient;\n // normal = normalize(normalPixelToPatient' + this.id + ' * localNormal);\n //normal = gradient;\n\n}\n '; } }]); return InterpolationTrilinear; }(_shaders2.default); exports.default = new InterpolationTrilinear(); module.exports = exports['default'];