├── .gitignore ├── .npmignore ├── LICENSE ├── README.md ├── example └── example.js ├── index.js ├── package.json └── test └── test.js /.gitignore: -------------------------------------------------------------------------------- 1 | lib-cov 2 | *.seed 3 | *.log 4 | *.csv 5 | *.dat 6 | *.out 7 | *.pid 8 | *.gz 9 | 10 | pids 11 | logs 12 | results 13 | 14 | npm-debug.log 15 | node_modules/* -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | lib-cov 2 | *.seed 3 | *.log 4 | *.csv 5 | *.dat 6 | *.out 7 | *.pid 8 | *.gz 9 | 10 | pids 11 | logs 12 | results 13 | 14 | npm-debug.log 15 | node_modules/* 16 | test/* 17 | example/* -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | 2 | The MIT License (MIT) 3 | 4 | Copyright (c) 2013 Mikola Lysenko 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in 14 | all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | THE SOFTWARE. 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | voxelize 2 | ======== 3 | Voxelize a triangulated mesh into an [ndarray](https://github.com/mikolalysenko/ndarray). 4 | 5 | ## Example 6 | 7 | ```javascript 8 | //Load bunny 9 | var bunny = require("bunny") 10 | 11 | //Voxelize the mesh 12 | var result = require("voxelize")(bunny.cells, bunny.positions, 0.1) 13 | 14 | //Unpack result 15 | var voxels = result.voxels 16 | var origin = result.origin 17 | var resolution = result.resolution 18 | ``` 19 | 20 | ## Install 21 | 22 | npm install voxelize 23 | 24 | ### `require("voxelize")(cells, positions[, resolution])` 25 | Voxelizes a triangulated mesh into an ndarray 26 | 27 | * `cells` are the indexed faces of the mesh 28 | * `positions` are the locations of the vertices in the mesh 29 | * `resolution` is the resolution at which the mesh needs to be voxelized 30 | 31 | **Returns** An object with the following properties 32 | 33 | * `voxels` the binary voxel image of the mesh 34 | * `origin` the coordinate of the bottm left back corner of the voxel array 35 | * `resolution` the resolution of the voxel array 36 | 37 | The real location of a voxel (i,j,k) in the mesh coordinates is given by: 38 | 39 | [ resolution * i + origin[0], resolution * j + origin[1], resolution * k + origin[2] ] 40 | 41 | ## Credits 42 | (c) 2013 Mikola Lysenko. MIT License -------------------------------------------------------------------------------- /example/example.js: -------------------------------------------------------------------------------- 1 | var bunny = require("bunny") 2 | 3 | var result = require("../index.js")(bunny.cells, bunny.positions, 1.0) 4 | 5 | console.log(require("ndarray-unpack")(result.voxels)) -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | "use strict" 2 | 3 | var rasterize = require("rle-rasterize") 4 | var rle2array = require("rle-ndarray").rle2array 5 | 6 | function voxelize(cells, positions, resolution) { 7 | var lo = [Infinity, Infinity, Infinity], 8 | hi = [-Infinity, -Infinity, -Infinity], 9 | n = positions.length, i, j, p 10 | for(i=0; i