/ndarray-grid-connectivity

[WIP] Extract grid connectivity from an ndarray, presumably for drawing

Primary LanguageJavaScript

ndarray-grid-connectivity

Extract grid connectivity from an ndarray, presumably for drawing

Experimental Build Status npm version Dependency Status Semistandard Style

Introduction

This module extracts grid conectivity data for a general n-dimensional ndarray. The presumed use-case is for drawing a grid, perhaps with OpenGL lines.

If you pass the ndarray information as a buffer, you'll also need the stride of the components (see example below). Since the stride is limited, it's highly recommended to store the spatial components (e.g. x, y, z) sequentially in the trailing dimension.

Finally, if you use the connectivity pairs with OpenGL, you will need the oes_element_index_uint extension if the size of the indices exceeds 2^16.

Example

The image below shows a 5 × 81 × 41 volumetric grid computed with transfinite interpolation and drawn with regl. The stride preserves smooth edges without actually plotting a a dense internal grid. The edges drawn in red represent the control curves and are plotted separately.

Contours extracted from a volumetric geometry

For the simple example of a 2 × 2 grid in three spatial dimensions:

var grid = require('ndarray-grid-connectivity');
var zeros = require('ndarray-scratch').zeros;
var A = zeros([2, 2, 3]);

// The index pairs for the first dimension:
grid(A.pick(null, null, 0));
// => [
//  0, 6,
//  3, 9,
//  0, 3,
//  6, 9
// ]

A.stride[2]
// => 1

Installation

Will publish to npm, pending additional testing.

$ npm install ndarray-grid-connectivity

Usage

require('ndarray-grid-connectivity')(A, options)

Extract connectivity information for the n-dimensional array A. The pairs are stored sequentially in a one-dimensional Array.

Options:

  • stride: Either one-dimensional Array containing the stride of the grid slices in each dimension, or else a two-dimensional array (indexed in this description as i, j) containing the j-stride of the slices in the ith dimension.
  • offset: Either one or two-dimensional array containing the offset of slice strides.
  • visible: An n-dimensional array of booleans indicating whether slices in the ith dimension are visible.

Returns: Packed connectivity information, for the n i-j line segments [i1, j1, i2, j2, ... in, jn].

License

© 2016 Ricky Reusser. MIT License.