surface-nets
Extract a simplicial level set from an ndarray in any dimension using naive surface nets. This module works in both node.js and with browserify!
Example
Here is a 2D example:
//Load modulesvar surfaceNets = var ndarray = var fill = //Initialize array to a circlevar array = //Extract 2D contour (this is all there is to it!)var complex = //Write SVG image to stdoutvar svgFile = '<svg xmlns="http://www.w3.org/2000/svg" width="320" height="320">'complexcellscomplexpositionssvgFileconsole
And here is the output SVG:
This module also works in 3D. Here is an example:
//Load modulesvar surfaceNets = var ndarray = var fill = var mat4 = mat4 //Initialize arrayvar array = //Generate surface! (again, just one line)var complex = //Render the implicit surface to stdoutconsoleconsoleconsole
And here is the result:
And while it is a bit trivial, you can also generate surfaces in 1D:
var surfaceNets = var ndarray = console
Output:
positions: 05 2 33333333333333335 cells: 0 1 2
The code should work in 4D and higher dimensions, but this is not well tested and it is harder to visualize. (Also, why would you want to bother!?!)
Install
npm install surface-nets
API
require("surface-nets")(array[,level])
Extracts the level set at level
from array
as a simplicial complex.
array
is an ndarraylevel
is an optional number which determines the level at which the levelset is evaluated (default0
)
Returns An object with a pair of properties representing a simplicial complex:
positions
is an array encoding the positions of the vertices. The coordinates of the positions are with respect to the indices inarray
.cells
is an array encoding the cells of the simplicial complex as tuples of indices into theposition
array.
Credits
(c) 2014 Mikola Lysenko. MIT License