3dmol
Version:
JavaScript/TypeScript molecular visualization library
651 lines (584 loc) • 95.5 kB
HTML
<!DOCTYPE html><html lang="en" style="font-size:16px"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><meta name="Author" content="David Koes & 3Dmoljs Contributors"><meta name="Description" content="A modern, object-oriented JavaScript library for visualizing molecular data"><title>Source: ProteinSurface4.ts</title><!--[if lt IE 9]>
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]--><script src="scripts/third-party/hljs.js" defer="defer"></script><script src="scripts/third-party/hljs-line-num.js" defer="defer"></script><script src="scripts/third-party/popper.js" defer="defer"></script><script src="scripts/third-party/tippy.js" defer="defer"></script><script src="scripts/third-party/tocbot.min.js"></script><script>var baseURL="/",locationPathname="";baseURL=(locationPathname=document.location.pathname).substr(0,locationPathname.lastIndexOf("/")+1)</script><link rel="stylesheet" href="styles/clean-jsdoc-theme.min.css"><style>article ul li{list-style:disc}</style><svg aria-hidden="true" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" style="display:none"><defs><symbol id="copy-icon" viewbox="0 0 488.3 488.3"><g><path d="M314.25,85.4h-227c-21.3,0-38.6,17.3-38.6,38.6v325.7c0,21.3,17.3,38.6,38.6,38.6h227c21.3,0,38.6-17.3,38.6-38.6V124 C352.75,102.7,335.45,85.4,314.25,85.4z M325.75,449.6c0,6.4-5.2,11.6-11.6,11.6h-227c-6.4,0-11.6-5.2-11.6-11.6V124 c0-6.4,5.2-11.6,11.6-11.6h227c6.4,0,11.6,5.2,11.6,11.6V449.6z"/><path d="M401.05,0h-227c-21.3,0-38.6,17.3-38.6,38.6c0,7.5,6,13.5,13.5,13.5s13.5-6,13.5-13.5c0-6.4,5.2-11.6,11.6-11.6h227 c6.4,0,11.6,5.2,11.6,11.6v325.7c0,6.4-5.2,11.6-11.6,11.6c-7.5,0-13.5,6-13.5,13.5s6,13.5,13.5,13.5c21.3,0,38.6-17.3,38.6-38.6 V38.6C439.65,17.3,422.35,0,401.05,0z"/></g></symbol><symbol id="search-icon" viewBox="0 0 512 512"><g><g><path d="M225.474,0C101.151,0,0,101.151,0,225.474c0,124.33,101.151,225.474,225.474,225.474 c124.33,0,225.474-101.144,225.474-225.474C450.948,101.151,349.804,0,225.474,0z M225.474,409.323 c-101.373,0-183.848-82.475-183.848-183.848S124.101,41.626,225.474,41.626s183.848,82.475,183.848,183.848 S326.847,409.323,225.474,409.323z"/></g></g><g><g><path d="M505.902,476.472L386.574,357.144c-8.131-8.131-21.299-8.131-29.43,0c-8.131,8.124-8.131,21.306,0,29.43l119.328,119.328 c4.065,4.065,9.387,6.098,14.715,6.098c5.321,0,10.649-2.033,14.715-6.098C514.033,497.778,514.033,484.596,505.902,476.472z"/></g></g></symbol><symbol id="font-size-icon" viewBox="0 0 24 24"><path fill="none" d="M0 0h24v24H0z"/><path d="M11.246 15H4.754l-2 5H.6L7 4h2l6.4 16h-2.154l-2-5zm-.8-2L8 6.885 5.554 13h4.892zM21 12.535V12h2v8h-2v-.535a4 4 0 1 1 0-6.93zM19 18a2 2 0 1 0 0-4 2 2 0 0 0 0 4z"/></symbol><symbol id="add-icon" viewBox="0 0 24 24"><path fill="none" d="M0 0h24v24H0z"/><path d="M11 11V5h2v6h6v2h-6v6h-2v-6H5v-2z"/></symbol><symbol id="minus-icon" viewBox="0 0 24 24"><path fill="none" d="M0 0h24v24H0z"/><path d="M5 11h14v2H5z"/></symbol><symbol id="dark-theme-icon" viewBox="0 0 24 24"><path fill="none" d="M0 0h24v24H0z"/><path d="M10 7a7 7 0 0 0 12 4.9v.1c0 5.523-4.477 10-10 10S2 17.523 2 12 6.477 2 12 2h.1A6.979 6.979 0 0 0 10 7zm-6 5a8 8 0 0 0 15.062 3.762A9 9 0 0 1 8.238 4.938 7.999 7.999 0 0 0 4 12z"/></symbol><symbol id="light-theme-icon" viewBox="0 0 24 24"><path fill="none" d="M0 0h24v24H0z"/><path d="M12 18a6 6 0 1 1 0-12 6 6 0 0 1 0 12zm0-2a4 4 0 1 0 0-8 4 4 0 0 0 0 8zM11 1h2v3h-2V1zm0 19h2v3h-2v-3zM3.515 4.929l1.414-1.414L7.05 5.636 5.636 7.05 3.515 4.93zM16.95 18.364l1.414-1.414 2.121 2.121-1.414 1.414-2.121-2.121zm2.121-14.85l1.414 1.415-2.121 2.121-1.414-1.414 2.121-2.121zM5.636 16.95l1.414 1.414-2.121 2.121-1.414-1.414 2.121-2.121zM23 11v2h-3v-2h3zM4 11v2H1v-2h3z"/></symbol><symbol id="reset-icon" viewBox="0 0 24 24"><path fill="none" d="M0 0h24v24H0z"/><path d="M18.537 19.567A9.961 9.961 0 0 1 12 22C6.477 22 2 17.523 2 12S6.477 2 12 2s10 4.477 10 10c0 2.136-.67 4.116-1.81 5.74L17 12h3a8 8 0 1 0-2.46 5.772l.997 1.795z"/></symbol><symbol id="down-icon" viewBox="0 0 16 16"><path fill-rule="evenodd" clip-rule="evenodd" d="M12.7803 6.21967C13.0732 6.51256 13.0732 6.98744 12.7803 7.28033L8.53033 11.5303C8.23744 11.8232 7.76256 11.8232 7.46967 11.5303L3.21967 7.28033C2.92678 6.98744 2.92678 6.51256 3.21967 6.21967C3.51256 5.92678 3.98744 5.92678 4.28033 6.21967L8 9.93934L11.7197 6.21967C12.0126 5.92678 12.4874 5.92678 12.7803 6.21967Z"></path></symbol><symbol id="codepen-icon" viewBox="0 0 24 24"><path fill="none" d="M0 0h24v24H0z"/><path d="M16.5 13.202L13 15.535v3.596L19.197 15 16.5 13.202zM14.697 12L12 10.202 9.303 12 12 13.798 14.697 12zM20 10.869L18.303 12 20 13.131V10.87zM19.197 9L13 4.869v3.596l3.5 2.333L19.197 9zM7.5 10.798L11 8.465V4.869L4.803 9 7.5 10.798zM4.803 15L11 19.131v-3.596l-3.5-2.333L4.803 15zM4 13.131L5.697 12 4 10.869v2.262zM2 9a1 1 0 0 1 .445-.832l9-6a1 1 0 0 1 1.11 0l9 6A1 1 0 0 1 22 9v6a1 1 0 0 1-.445.832l-9 6a1 1 0 0 1-1.11 0l-9-6A1 1 0 0 1 2 15V9z"/></symbol><symbol id="close-icon" viewBox="0 0 24 24"><path fill="none" d="M0 0h24v24H0z"/><path d="M12 10.586l4.95-4.95 1.414 1.414-4.95 4.95 4.95 4.95-1.414 1.414-4.95-4.95-4.95 4.95-1.414-1.414 4.95-4.95-4.95-4.95L7.05 5.636z"/></symbol><symbol id="menu-icon" viewBox="0 0 24 24"><path fill="none" d="M0 0h24v24H0z"/><path d="M3 4h18v2H3V4zm0 7h18v2H3v-2zm0 7h18v2H3v-2z"/></symbol></defs></svg></head><body data-theme="light"><div class="sidebar-container"><div class="sidebar" id="sidebar"><a href="/" class="sidebar-title sidebar-title-anchor">3Dmol.js</a><div class="sidebar-items-container"><div class="sidebar-section-title with-arrow" data-isopen="false" id="mei5HJjYKLn6aua5Z5PM5"><div>Classes</div><svg><use xlink:href="#down-icon"></use></svg></div><div class="sidebar-section-children-container"><div class="sidebar-section-children"><a href="$3Dmol.Label.html">Label</a></div><div class="sidebar-section-children"><a href="$3Dmol.StateManager.html">StateManager</a></div><div class="sidebar-section-children"><a href="$3Dmol.UI.html">UI</a></div><div class="sidebar-section-children"><a href="Color.html">Color</a></div><div class="sidebar-section-children"><a href="CustomLinear.html">CustomLinear</a></div><div class="sidebar-section-children"><a href="Cylinder.html">Cylinder</a></div><div class="sidebar-section-children"><a href="GLModel.html">GLModel</a></div><div class="sidebar-section-children"><a href="GLShape.html">GLShape</a></div><div class="sidebar-section-children"><a href="GLShape_GLShape.html">GLShape</a></div><div class="sidebar-section-children"><a href="GLViewer.html">GLViewer</a></div><div class="sidebar-section-children"><a href="GLVolumetricRender.html">GLVolumetricRender</a></div><div class="sidebar-section-children"><a href="Matrix3.html">Matrix3</a></div><div class="sidebar-section-children"><a href="Matrix4.html">Matrix4</a></div><div class="sidebar-section-children"><a href="Quaternion.html">Quaternion</a></div><div class="sidebar-section-children"><a href="ROYGB.html">ROYGB</a></div><div class="sidebar-section-children"><a href="RWB.html">RWB</a></div><div class="sidebar-section-children"><a href="Ray.html">Ray</a></div><div class="sidebar-section-children"><a href="Sinebow.html">Sinebow</a></div><div class="sidebar-section-children"><a href="Sphere.html">Sphere</a></div><div class="sidebar-section-children"><a href="Surface.html">Surface</a></div><div class="sidebar-section-children"><a href="Triangle.html">Triangle</a></div><div class="sidebar-section-children"><a href="Vector2.html">Vector2</a></div><div class="sidebar-section-children"><a href="Vector3.html">Vector3</a></div><div class="sidebar-section-children"><a href="VolumeData.html">VolumeData</a></div></div><div class="sidebar-section-title with-arrow" data-isopen="false" id="kv4Yx5z0THf_b8XR4Gje1"><div>Namespaces</div><svg><use xlink:href="#down-icon"></use></svg></div><div class="sidebar-section-children-container"><div class="sidebar-section-children"><a href="GLDraw.html">GLDraw</a></div></div><div class="sidebar-section-title with-arrow" data-isopen="false" id="ykThSufQWJcKGT1kXzr-A"><div>Tutorials</div><svg><use xlink:href="#down-icon"></use></svg></div><div class="sidebar-section-children-container"><div class="sidebar-section-children"><a href="tutorial-code.html">Using 3Dmol within your code</a></div><div class="sidebar-section-children"><a href="tutorial-embeddable.html">Embedding a 3Dmol Viewer</a></div><div class="sidebar-section-children"><a href="tutorial-home.html">3Dmol Tutorials - Home</a></div><div class="sidebar-section-children"><a href="tutorial-learning_environment.html">Active Learning with 3Dmol.js</a></div><div class="sidebar-section-children"><a href="tutorial-url.html">Viewing Molecules with the 3Dmol Server</a></div></div><div class="sidebar-section-title with-arrow" data-isopen="false" id="XcP4RUEg6tp7YKHbBVi9E"><div>Interfaces</div><svg><use xlink:href="#down-icon"></use></svg></div><div class="sidebar-section-children-container"><div class="sidebar-section-children"><a href="AmbientOcclusionStyle.html">AmbientOcclusionStyle</a></div><div class="sidebar-section-children"><a href="ArrowSpec.html">ArrowSpec</a></div><div class="sidebar-section-children"><a href="AtomSelectionSpec.html">AtomSelectionSpec</a></div><div class="sidebar-section-children"><a href="AtomSpec.html">AtomSpec</a></div><div class="sidebar-section-children"><a href="AtomStyleSpec.html">AtomStyleSpec</a></div><div class="sidebar-section-children"><a href="BondStyle.html">BondStyle</a></div><div class="sidebar-section-children"><a href="BoxSpec.html">BoxSpec</a></div><div class="sidebar-section-children"><a href="CartoonStyleSpec.html">CartoonStyleSpec</a></div><div class="sidebar-section-children"><a href="ClickSphereStyleSpec.html">ClickSphereStyleSpec</a></div><div class="sidebar-section-children"><a href="CrossStyleSpec.html">CrossStyleSpec</a></div><div class="sidebar-section-children"><a href="CurveSpec.html">CurveSpec</a></div><div class="sidebar-section-children"><a href="CustomShapeSpec.html">CustomShapeSpec</a></div><div class="sidebar-section-children"><a href="CylinderSpec.html">CylinderSpec</a></div><div class="sidebar-section-children"><a href="DashedBondSpec.html">DashedBondSpec</a></div><div class="sidebar-section-children"><a href="FogSpec.html">FogSpec</a></div><div class="sidebar-section-children"><a href="IsoSurfaceSpec.html">IsoSurfaceSpec</a></div><div class="sidebar-section-children"><a href="LabelSpec.html">LabelSpec</a></div><div class="sidebar-section-children"><a href="LineSpec.html">LineSpec</a></div><div class="sidebar-section-children"><a href="LineStyleSpec.html">LineStyleSpec</a></div><div class="sidebar-section-children"><a href="OutlineStyle.html">OutlineStyle</a></div><div class="sidebar-section-children"><a href="ParserOptionsSpec.html">ParserOptionsSpec</a></div><div class="sidebar-section-children"><a href="ShapeSpec.html">ShapeSpec</a></div><div class="sidebar-section-children"><a href="SphereSpec.html">SphereSpec</a></div><div class="sidebar-section-children"><a href="SphereStyleSpec.html">SphereStyleSpec</a></div><div class="sidebar-section-children"><a href="StickStyleSpec.html">StickStyleSpec</a></div><div class="sidebar-section-children"><a href="SurfaceStyleSpec.html">SurfaceStyleSpec</a></div><div class="sidebar-section-children"><a href="UnitCellStyleSpec.html">UnitCellStyleSpec</a></div><div class="sidebar-section-children"><a href="ViewStyle.html">ViewStyle</a></div><div class="sidebar-section-children"><a href="ViewerGridSpec.html">ViewerGridSpec</a></div><div class="sidebar-section-children"><a href="ViewerSpec.html">ViewerSpec</a></div><div class="sidebar-section-children"><a href="VolumetricRendererSpec.html">VolumetricRendererSpec</a></div><div class="sidebar-section-children"><a href="WithinSelectionSpec.html">WithinSelectionSpec</a></div><div class="sidebar-section-children"><a href="global.html#XYZ">XYZ</a></div></div><div class="sidebar-section-title with-arrow" data-isopen="false" id="jmKnIXRJjdjZ366ci7cdd"><div>Global</div><svg><use xlink:href="#down-icon"></use></svg></div><div class="sidebar-section-children-container"><div class="sidebar-section-children"><a href="global.html#BCIF">BCIF</a></div><div class="sidebar-section-children"><a href="global.html#CAP">CAP</a></div><div class="sidebar-section-children"><a href="global.html#CDJSON">CDJSON</a></div><div class="sidebar-section-children"><a href="global.html#CIF">CIF</a></div><div class="sidebar-section-children"><a href="global.html#CUBE">CUBE</a></div><div class="sidebar-section-children"><a href="global.html#ColorSpec">ColorSpec</a></div><div class="sidebar-section-children"><a href="global.html#ColorschemeSpec">ColorschemeSpec</a></div><div class="sidebar-section-children"><a href="global.html#GRO">GRO</a></div><div class="sidebar-section-children"><a href="global.html#GradientSpec">GradientSpec</a></div><div class="sidebar-section-children"><a href="global.html#MMTFparser">MMTFparser</a></div><div class="sidebar-section-children"><a href="global.html#MOL2">MOL2</a></div><div class="sidebar-section-children"><a href="global.html#OFFSETS">OFFSETS</a></div><div class="sidebar-section-children"><a href="global.html#PDB">PDB</a></div><div class="sidebar-section-children"><a href="global.html#PQR">PQR</a></div><div class="sidebar-section-children"><a href="global.html#PRMTOP">PRMTOP</a></div><div class="sidebar-section-children"><a href="global.html#SDF">SDF</a></div><div class="sidebar-section-children"><a href="global.html#SurfaceType">SurfaceType</a></div><div class="sidebar-section-children"><a href="global.html#VASP">VASP</a></div><div class="sidebar-section-children"><a href="global.html#XYZ">XYZ</a></div><div class="sidebar-section-children"><a href="global.html#assignPDBBonds">assignPDBBonds</a></div><div class="sidebar-section-children"><a href="global.html#builtinColorSchemes">builtinColorSchemes</a></div><div class="sidebar-section-children"><a href="global.html#builtinGradients">builtinGradients</a></div><div class="sidebar-section-children"><a href="global.html#conversionMatrix3">conversionMatrix3</a></div><div class="sidebar-section-children"><a href="global.html#createViewer">createViewer</a></div><div class="sidebar-section-children"><a href="global.html#createViewerGrid">createViewerGrid</a></div><div class="sidebar-section-children"><a href="global.html#decode">decode</a></div><div class="sidebar-section-children"><a href="global.html#dic">dic</a></div><div class="sidebar-section-children"><a href="global.html#download">download</a></div><div class="sidebar-section-children"><a href="global.html#elementColors">elementColors</a></div><div class="sidebar-section-children"><a href="global.html#get">get</a></div><div class="sidebar-section-children"><a href="global.html#getColorFromStyle">getColorFromStyle</a></div><div class="sidebar-section-children"><a href="global.html#getbin">getbin</a></div><div class="sidebar-section-children"><a href="global.html#parseV3000">parseV3000</a></div><div class="sidebar-section-children"><a href="global.html#setSyncSurface">setSyncSurface</a></div><div class="sidebar-section-children"><a href="global.html#ssColors">ssColors</a></div><div class="sidebar-section-children"><a href="global.html#syncSurface">syncSurface</a></div><div class="sidebar-section-children"><a href="global.html#viewers">viewers</a></div></div></div></div></div><div class="navbar-container" id="VuAckcnZhf"><nav class="navbar"><div class="navbar-left-items"><div class="navbar-item"><a id="" href="https://3dmol.org/doc/index.html" target="">Documentation</a></div><div class="navbar-item"><a id="" href="tutorial-home.html" target="">Tutorials</a></div><div class="navbar-item"><a id="" href="https://github.com/3dmol/3Dmol.js" target="_blank">GitHub</a></div></div><div class="navbar-right-items"><div class="navbar-right-item"><button class="icon-button search-button" aria-label="open-search"><svg><use xlink:href="#search-icon"></use></svg></button></div><div class="navbar-right-item"><button class="icon-button theme-toggle" aria-label="toggle-theme"><svg><use class="theme-svg-use" xlink:href="#dark-theme-icon"></use></svg></button></div><div class="navbar-right-item"><button class="icon-button font-size" aria-label="change-font-size"><svg><use xlink:href="#font-size-icon"></use></svg></button></div></div><nav></nav></nav></div><div class="toc-container"><div class="toc-content"><span class="bold">On this page</span><div id="eed4d2a0bfd64539bb9df78095dec881"></div></div></div><div class="body-wrapper"><div class="main-content"><div class="main-wrapper"><section id="source-page" class="source-page"><header><h1 id="title" class="has-anchor">ProteinSurface4.ts</h1></header><article><pre class="prettyprint source lang-js"><code>/* ProteinSurface.js by biochem_fan
Ported and modified for Javascript based on EDTSurf,
whose license is as follows.
Permission to use, copy, modify, and distribute this program for any
purpose, with or without fee, is hereby granted, provided that this
copyright notice and the reference information appear in all copies or
substantial portions of the Software. It is provided "as is" without
express or implied warranty.
Reference:
http://zhanglab.ccmb.med.umich.edu/EDTSurf/
D. Xu, Y. Zhang (2009) Generating Triangulated Macromolecular Surfaces
by Euclidean Distance Transform. PLoS ONE 4(12): e8140.
=======
*/
import {Vector3} from "./WebGL/math"
/**
* Surface types
* @readonly
* @enum {number}
* @property VDW - van der Waals surface
* @property MS - Molecular surface
* @property SAS - Solvent accessible surface
* @property SES - Solvent exposed surface
*/
export enum SurfaceType {
VDW = 1,
MS = 2,
SAS = 3,
SES = 4
};
/**
* Render surface synchronously if true
* @param {boolean} [$3Dmol.syncSurface=false]
* @type {boolean} */
export var syncSurface = false;
/**
*
* @param {boolean} val - Whether surfaces should be rendered synchronously or in parallel.
*/
export function setSyncSurface(val:boolean) {
syncSurface = val;
}
// Internet Explorer refuses to allow webworkers in data blobs. I can find
// no way of checking for this feature directly, so must do a browser check
if (window.navigator.userAgent.indexOf('MSIE ') >= 0 ||
window.navigator.userAgent.indexOf('Trident/') >= 0) {
syncSurface = true; // can't use webworkers
}
//Encapsulate marching cube algorithm for isosurface generation
// (currently used by protein surface rendering and generic volumetric data reading)
export class MarchingCubeInitializer {
//Marching cube algorithm - assume data has been pre-treated so isovalue is 0
// (i.e. select points greater than 0)
//origin - vector of origin of volumetric data (default is (0,0,0))
// nX, nY, nZ - specifies number of voxels in each dimension
// scale - cube diagonal unit vector scale (3Dmol vector) (specifying distance between data points); diagonal of cube
// - default is 1 - assumes unit cube (1,1,1) diag)
// fulltable - if true, use full marching cubes and tritables - else use trimmed table (e.g. surf render)
// voxel - if true, draws with a blocky voxel style (default false)
// verts, faces - vertex and face arrays to fill up
//to match with protein surface...
ISDONE: number = 2;
constructor() {
}
march(data, verts, faces, spec) {
let fulltable = !!(spec.fulltable);
let origin = (spec.hasOwnProperty('origin') && spec.origin.hasOwnProperty('x')) ? spec.origin : {x:0, y:0, z:0};
let voxel = !!(spec.voxel);
let transform = spec.matrix; //if this is set, it overrides origin and unitCube
let nX = spec.nX || 0;
let nY = spec.nY || 0;
let nZ = spec.nZ || 0;
let scale = spec.scale || 1.0;
let unitCube = null;
if(spec.unitCube) {
unitCube = spec.unitCube;
} else {
unitCube = {x:scale,y:scale,z:scale};
}
//keep track of calculated vertices to avoid repeats
let vertnums = new Int32Array(nX*nY*nZ);
let i, il;
for (i = 0, il = vertnums.length; i < il; ++i)
vertnums[i] = -1;
// create (or retrieve) a vertex at the appropriate point for
// the edge (p1,p2)
let getVertex = function(i, j, k, code, p1, p2) {
let pt = {x:0,y:0,z:0};
let val1 = !!(code & (1 << p1));
let val2 = !!(code & (1 << p2));
// p1 if they are the same or if !val1
let p = p1;
if (!val1 && val2)
p = p2;
// adjust i,j,k by p
if (p & 1)
k++;
if (p & 2)
j++;
if (p & 4)
i++;
if(transform) {
let vpt = new Vector3(i,j,k);
vpt = vpt.applyMatrix4(transform);
pt = {x: vpt.x, y: vpt.y, z: vpt.z}; //remove vector gunk
} else {
pt.x = origin.x+unitCube.x*i;
pt.y = origin.y+unitCube.y*j;
pt.z = origin.z+unitCube.z*k;
}
let index = ((nY * i) + j) * nZ + k;
//Have to add option to do voxels
if (!voxel) {
if (vertnums[index] < 0) // not created yet
{
vertnums[index] = verts.length;
verts.push( pt );
}
return vertnums[index];
}
else {
verts.push(pt);
return verts.length - 1;
}
};
let intersects = new Int32Array(12);
let etable = (fulltable) ? this.edgeTable2 : this.edgeTable;
let tritable = (fulltable) ? this.triTable2 : this.triTable;
//Run marching cubes algorithm
for (i = 0; i < nX-1; ++i) {
for (let j = 0; j < nY-1; ++j){
for (let k = 0; k < nZ-1; ++k){
let code = 0;
for (let p = 0; p < 8; ++p) {
let index = ((nY * (i + ((p & 4) >> 2))) + j + ((p & 2) >> 1)) *
nZ + k + (p & 1);
//TODO: Need to fix vpBits in protein surface for this to work
let val:any = !!(data[index] & this.ISDONE);
//let val = !!(data[index] > 0);
code |= val << p;
}
if (code === 0 || code === 255)
continue;
let ecode = etable[code];
if (ecode === 0)
continue;
let ttable = tritable[code];
if (ecode & 1)
intersects[0] = getVertex(i, j, k, code, 0, 1);
if (ecode & 2)
intersects[1] = getVertex(i, j, k, code, 1, 3);
if (ecode & 4)
intersects[2] = getVertex(i, j, k, code, 3, 2);
if (ecode & 8)
intersects[3] = getVertex(i, j, k, code, 2, 0);
if (ecode & 16)
intersects[4] = getVertex(i, j, k, code, 4, 5);
if (ecode & 32)
intersects[5] = getVertex(i, j, k, code, 5, 7);
if (ecode & 64)
intersects[6] = getVertex(i, j, k, code, 7, 6);
if (ecode & 128)
intersects[7] = getVertex(i, j, k, code, 6, 4);
if (ecode & 256)
intersects[8] = getVertex(i, j, k, code, 0, 4);
if (ecode & 512)
intersects[9] = getVertex(i, j, k, code, 1, 5);
if (ecode & 1024)
intersects[10] = getVertex(i, j, k, code, 3, 7);
if (ecode & 2048)
intersects[11] = getVertex(i, j, k, code, 2, 6);
for (let t = 0; t < ttable.length; t += 3) {
let a = intersects[ttable[t]],
b = intersects[ttable[t+1]],
c = intersects[ttable[t+2]];
if (voxel && t >= 3) {
verts.push(verts[a]); a = verts.length - 1;
verts.push(verts[b]); b = verts.length - 1;
verts.push(verts[c]); c = verts.length - 1;
}
faces.push(a); faces.push(b); faces.push(c);
}
}
}
}
};
laplacianSmooth (numiter, verts, faces) {
let tps = new Array(verts.length);
let i, il, j, jl, k;
for (i = 0, il = verts.length; i < il; i++)
tps[i] = {
x : 0,
y : 0,
z : 0
};
let vertdeg = new Array(20);
let flagvert;
for (i = 0; i < 20; i++)
vertdeg[i] = new Array(verts.length);
for (i = 0, il = verts.length; i < il; i++)
vertdeg[0][i] = 0;
for (i = 0, il = faces.length / 3; i < il; i++) {
let aoffset = i*3, boffset = i*3 + 1, coffset = i*3 + 2;
flagvert = true;
for (j = 0, jl = vertdeg[0][faces[aoffset]]; j < jl; j++) {
if (faces[boffset] == vertdeg[j + 1][faces[aoffset]]) {
flagvert = false;
break;
}
}
if (flagvert) {
vertdeg[0][faces[aoffset]]++;
vertdeg[vertdeg[0][faces[aoffset]]][faces[aoffset]] = faces[boffset];
}
flagvert = true;
for (j = 0, jl = vertdeg[0][faces[aoffset]]; j < jl; j++) {
if (faces[coffset] == vertdeg[j + 1][faces[aoffset]]) {
flagvert = false;
break;
}
}
if (flagvert) {
vertdeg[0][faces[aoffset]]++;
vertdeg[vertdeg[0][faces[aoffset]]][faces[aoffset]] = faces[coffset];
}
// b
flagvert = true;
for (j = 0, jl = vertdeg[0][faces[boffset]]; j < jl; j++) {
if (faces[aoffset] == vertdeg[j + 1][faces[boffset]]) {
flagvert = false;
break;
}
}
if (flagvert) {
vertdeg[0][faces[boffset]]++;
vertdeg[vertdeg[0][faces[boffset]]][faces[boffset]] = faces[aoffset];
}
flagvert = true;
for (j = 0, jl = vertdeg[0][faces[boffset]]; j < jl; j++) {
if (faces[coffset] == vertdeg[j + 1][faces[boffset]]) {
flagvert = false;
break;
}
}
if (flagvert) {
vertdeg[0][faces[boffset]]++;
vertdeg[vertdeg[0][faces[boffset]]][faces[boffset]] = faces[coffset];
}
// c
flagvert = true;
for (j = 0; j < vertdeg[0][faces[coffset]]; j++) {
if (faces[aoffset] == vertdeg[j + 1][faces[coffset]]) {
flagvert = false;
break;
}
}
if (flagvert) {
vertdeg[0][faces[coffset]]++;
vertdeg[vertdeg[0][faces[coffset]]][faces[coffset]] = faces[aoffset];
}
flagvert = true;
for (j = 0, jl = vertdeg[0][faces[coffset]]; j < jl; j++) {
if (faces[boffset] == vertdeg[j + 1][faces[coffset]]) {
flagvert = false;
break;
}
}
if (flagvert) {
vertdeg[0][faces[coffset]]++;
vertdeg[vertdeg[0][faces[coffset]]][faces[coffset]] = faces[boffset];
}
}
let wt = 1.00;
let wt2 = 0.50;
for (k = 0; k < numiter; k++) {
for (i = 0, il = verts.length; i < il; i++) {
if (vertdeg[0][i] < 3) {
tps[i].x = verts[i].x;
tps[i].y = verts[i].y;
tps[i].z = verts[i].z;
} else if (vertdeg[0][i] == 3 || vertdeg[0][i] == 4) {
tps[i].x = 0;
tps[i].y = 0;
tps[i].z = 0;
for (j = 0, jl = vertdeg[0][i]; j < jl; j++) {
tps[i].x += verts[vertdeg[j + 1][i]].x;
tps[i].y += verts[vertdeg[j + 1][i]].y;
tps[i].z += verts[vertdeg[j + 1][i]].z;
}
tps[i].x += wt2 * verts[i].x;
tps[i].y += wt2 * verts[i].y;
tps[i].z += wt2 * verts[i].z;
tps[i].x /= wt2 + vertdeg[0][i];
tps[i].y /= wt2 + vertdeg[0][i];
tps[i].z /= wt2 + vertdeg[0][i];
} else {
tps[i].x = 0;
tps[i].y = 0;
tps[i].z = 0;
for (j = 0, jl = vertdeg[0][i]; j < jl; j++) {
tps[i].x += verts[vertdeg[j + 1][i]].x;
tps[i].y += verts[vertdeg[j + 1][i]].y;
tps[i].z += verts[vertdeg[j + 1][i]].z;
}
tps[i].x += wt * verts[i].x;
tps[i].y += wt * verts[i].y;
tps[i].z += wt * verts[i].z;
tps[i].x /= wt + vertdeg[0][i];
tps[i].y /= wt + vertdeg[0][i];
tps[i].z /= wt + vertdeg[0][i];
}
}
for (i = 0, il = verts.length; i < il; i++) {
verts[i].x = tps[i].x;
verts[i].y = tps[i].y;
verts[i].z = tps[i].z;
}
/*
* computenorm(); for (let i = 0; i < vertnumber; i++) { if
* (verts[i].inout) ssign = 1; else ssign = -1; verts[i].x += ssign *
* outwt * verts[i].pn.x; verts[i].y += ssign * outwt *
* verts[i].pn.y; verts[i].z += ssign * outwt * verts[i].pn.z; }
*/
}
};
/*
* These tables are based off those by Paul Bourke and Geoffrey Heller:
* http://paulbourke.net/geometry/polygonise/
* http://paulbourke.net/geometry/polygonise/table2.txt
*
* However, they have been substantially modified to reflect a more
* sensible corner numbering scheme and the discrete nature of our voxel data
* (resulting in fewer faces).
*/
edgeTable: Uint32Array = new Uint32Array([ 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
0xb00, 0x0, 0x0, 0x0, 0x700, 0x0, 0xd00, 0xe00, 0xf00, 0x0, 0x0, 0x0,
0x8a, 0x0, 0x15, 0x0, 0x86, 0x0, 0x0, 0x0, 0x28c, 0x0, 0x813, 0xf19,
0xe10, 0x0, 0x0, 0x0, 0x2a, 0x0, 0x0, 0x0, 0x126, 0x0, 0x0, 0x15, 0x1c,
0x0, 0xf23, 0x419, 0xd20, 0x0, 0xa8, 0xa2, 0xaa, 0x0, 0x285, 0x9ab,
0x8a2, 0x0, 0x2af, 0x125, 0xac, 0xfaa, 0xea3, 0xda9, 0xca0, 0x0, 0x0,
0x0, 0x0, 0x0, 0x45, 0x0, 0x384, 0x0, 0x0, 0x0, 0x700, 0x8a, 0x83,
0x648, 0x780, 0x0, 0x51, 0x0, 0x81a, 0x54, 0x55, 0x54, 0x56, 0x0, 0x51,
0x0, 0xe5c, 0x14a, 0x451, 0x759, 0x650, 0x0, 0x0, 0x0, 0x2a, 0x0, 0x45,
0x0, 0x1f6, 0x0, 0x0, 0x15, 0xdfc, 0x8a, 0x7f3, 0x4f9, 0x5f0, 0xb00,
0x68, 0x921, 0x6a, 0x348, 0x245, 0x16f, 0x66, 0xb00, 0xe6f, 0xd65,
0xc6c, 0x76a, 0x663, 0x569, 0x460, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
0xf46, 0x0, 0x0, 0x45, 0x24c, 0x2a, 0x823, 0x29, 0xb40, 0x0, 0x0, 0x0,
0x6ba, 0x0, 0x8f5, 0xfff, 0xef6, 0x0, 0xff, 0x2f5, 0x2fc, 0x9ea, 0x8f3,
0xbf9, 0xaf0, 0x0, 0x0, 0x51, 0x152, 0x0, 0xf55, 0x45f, 0xd56, 0x54,
0x357, 0x55, 0x154, 0x852, 0xb53, 0x59, 0x950, 0x700, 0x2c8, 0xc2,
0x48a, 0xfc4, 0xec5, 0xdcf, 0xcc6, 0x2c4, 0x2cf, 0xc5, 0xcc, 0xbca,
0xac3, 0x9c9, 0x8c0, 0x0, 0x0, 0x0, 0x0, 0xa8, 0x1a4, 0xa8, 0x7a6,
0xa2, 0xa2, 0x2a4, 0xbac, 0xaa, 0xa3, 0x2a8, 0x3a0, 0xd00, 0xc18,
0xd00, 0xe3a, 0x34, 0x35, 0x73f, 0x636, 0x924, 0x83f, 0xb35, 0xa3c,
0x12a, 0x33, 0x339, 0x230, 0xe00, 0xe00, 0xc12, 0xd9a, 0x684, 0x795,
0x49f, 0x596, 0x92, 0xb9f, 0x815, 0x99c, 0x9a, 0x393, 0x99, 0x190,
0xf00, 0xe08, 0xd01, 0xc0a, 0x704, 0x605, 0x50f, 0x406, 0xb02, 0xa0f,
0x905, 0x80c, 0x30a, 0x203, 0x109, 0x0 ]);
triTable = [ [], [], [], [], [], [], [], [ 11, 9, 8 ], [], [], [],
[ 8, 10, 9 ], [], [ 10, 8, 11 ], [ 9, 11, 10 ],
[ 8, 10, 9, 8, 11, 10 ], [], [], [], [ 1, 7, 3 ], [], [ 4, 2, 0 ], [],
[ 2, 1, 7 ], [], [], [], [ 2, 7, 3, 2, 9, 7 ], [],
[ 1, 4, 11, 1, 0, 4 ], [ 3, 8, 0, 11, 9, 4, 11, 10, 9 ],
[ 4, 11, 9, 11, 10, 9 ], [], [], [], [ 5, 3, 1 ], [], [], [],
[ 2, 5, 8, 2, 1, 5 ], [], [], [ 2, 4, 0 ], [ 3, 2, 4 ], [],
[ 0, 9, 1, 8, 10, 5, 8, 11, 10 ], [ 3, 4, 0, 3, 10, 4 ],
[ 5, 8, 10, 8, 11, 10 ], [], [ 3, 5, 7 ], [ 7, 1, 5 ],
[ 1, 7, 3, 1, 5, 7 ], [], [ 9, 2, 0, 9, 7, 2 ],
[ 0, 3, 8, 1, 7, 11, 1, 5, 7 ], [ 11, 1, 7, 1, 5, 7 ], [],
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,
0xbca, 0xcc, 0x1c5, 0x2cf, 0x3c6, 0xcc6, 0xdcf, 0xec5, 0xfcc, 0x4ca,
0x5c3, 0x6c9, 0x7c0, 0x950, 0x859, 0xb53, 0xa5a, 0x15c, 0x55, 0x35f,
0x256, 0xd56, 0xc5f, 0xf55, 0xe5c, 0x55a, 0x453, 0x759, 0x650, 0xaf0,
0xbf9, 0x8f3, 0x9fa, 0x2fc, 0x3f5, 0xff, 0x1f6, 0xef6, 0xfff, 0xcf5,
0xdfc, 0x6fa, 0x7f3, 0x4f9, 0x5f0, 0xb60, 0xa69, 0x963, 0x86a, 0x36c,
0x265, 0x16f, 0x66, 0xf66, 0xe6f, 0xd65, 0xc6c, 0x76a, 0x663, 0x569,
0x460, 0x460, 0x569, 0x663, 0x76a, 0xc6c, 0xd65, 0xe6f, 0xf66, 0x66,
0x16f, 0x265, 0x36c, 0x86a, 0x963, 0xa69, 0xb60, 0x5f0, 0x4f9, 0x7f3,
0x6fa, 0xdfc, 0xcf5, 0xfff, 0xef6, 0x1f6, 0xff, 0x3f5, 0x2fc, 0x9fa,
0x8f3, 0xbf9, 0xaf0, 0x650, 0x759, 0x453, 0x55a, 0xe5c, 0xf55, 0xc5f,
0xd56, 0x256, 0x35f, 0x55, 0x15c, 0xa5a, 0xb53, 0x859, 0x950, 0x7c0,
0x6c9, 0x5c3, 0x4ca, 0xfcc, 0xec5, 0xdcf, 0xcc6, 0x3c6, 0x2cf, 0x1c5,
0xcc, 0xbca, 0xac3, 0x9c9, 0x8c0, 0xca0, 0xda9, 0xea3, 0xfaa, 0x4ac,
0x5a5, 0x6af, 0x7a6, 0x8a6, 0x9af, 0xaa5, 0xbac, 0xaa, 0x1a3, 0x2a9,
0x3a0, 0xd30, 0xc39, 0xf33, 0xe3a, 0x53c, 0x435, 0x73f, 0x636, 0x936,
0x83f, 0xb35, 0xa3c, 0x13a, 0x33, 0x339, 0x230, 0xe90, 0xf99, 0xc93,
0xd9a, 0x69c, 0x795, 0x49f, 0x596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