Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
41b5fa5
commit aaeeff5
Showing
3 changed files
with
105 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,51 @@ | ||
rle-stencils | ||
============ | ||
|
||
Stencil generator code for the rle libraries | ||
Stencil generator code for the rle libraries | ||
|
||
|
||
Basic Usage | ||
=========== | ||
|
||
To install the library, just do: | ||
|
||
npm install rle-stencils | ||
|
||
Then in your code you can import the stencils by: | ||
|
||
//Import stencil library | ||
var stencils = require('rle-stencils'); | ||
|
||
Example: Moore | ||
-------------- | ||
|
||
Here is how to create a stencil for a [Moore neighborhood](http://en.wikipedia.org/wiki/Moore_neighborhood) with radius 2: | ||
|
||
var moore_neighborhood = stencils.moore(2); | ||
|
||
Example: von Neumann | ||
-------------------- | ||
|
||
And here is the same idea applied to a [von Neumann neighborhood](http://en.wikipedia.org/wiki/Von_Neumann_neighborhood) | ||
|
||
var von_eumann_neighborhood = stencils.vonNeumann(1); | ||
|
||
Example: Sphere | ||
--------------- | ||
|
||
var ball_neighborhood = stencils.ball(5); | ||
|
||
Example: L^p | ||
------------ | ||
|
||
More generally, you can create a stencil for any [Lp ball](http://en.wikipedia.org/wiki/Lp_space), with p being some fixed power. For example, here is how to make an L^3 ball with radius 6: | ||
|
||
var cubic_neighborhood = stencils.lp(3, 6); | ||
|
||
In general, calls to `lp(p, r)` return the collection of all integer lattice points `x` satisfying the inequality: | ||
|
||
Math.pow(Math.abs(x[0]), p) + Math.pow(Math.abs(x[1]), p) + Math.pow(Math.abs(x[2]), p) <= Math.pow(r, p) | ||
|
||
Acknowledgements | ||
================ | ||
(c) 2013 Mikola Lysenko. MIT License |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
"name": "rle-stencils", | ||
"version": "0.0.0", | ||
"description": "Stencils for use with rle library", | ||
"main": "stencils.js", | ||
"repository": { | ||
"type": "git", | ||
"url": "git://github.com/mikolalysenko/rle-stencils.git" | ||
}, | ||
"keywords": [ | ||
"stencil", | ||
"narrowband", | ||
"levelset" | ||
], | ||
"author": "Mikola Lysenko", | ||
"license": "MIT", | ||
"readmeFilename": "README.md", | ||
"gitHead": "41b5fa5b369a8894a6196fdea2efce0e94daead5" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
//Generates a Moore neighborhood with given radius | ||
function moore(radius_) { | ||
var result = [] | ||
, radius = Math.ceil(radius_); | ||
for(var i=-radius; i<=radius; ++i) { | ||
for(var j=-radius; j<=radius; ++j) { | ||
for(var k=-radius; k<=radius; ++k) { | ||
result.push([i,j,k]); | ||
} | ||
} | ||
} | ||
return result; | ||
} | ||
|
||
//Creates an Lp ball stencil | ||
function lp(p, radius_) { | ||
if(p === Number.POSITIVE_INFINITY) { | ||
return moore(radius_); | ||
} | ||
var result = [] | ||
, radius = Math.ceil(radius_) | ||
, rp = Math.pow(radius_, p); | ||
for(var i=-radius; i<=radius; ++i) { | ||
for(var j=-radius; j<=radius; ++j) { | ||
for(var k=-radius; k<=radius; ++k) { | ||
if(Math.pow(Math.abs(i), p) + Math.pow(Math.abs(i), p) + Math.pow(Math.abs(i), p) <= rp) { | ||
result.push([i,j,k]); | ||
} | ||
} | ||
} | ||
} | ||
return result; | ||
} | ||
|
||
exports.lp = lp; | ||
exports.moore = moore; | ||
exports.vonNeumann = lp.bind(this, 1); | ||
exports.ball = lp.bind(this, 2); |