binvox

package
v4.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 20, 2020 License: Apache-2.0 Imports: 12 Imported by: 2

Documentation

Overview

Package binvox provides functions for reading and writing binvox files. See: http://www.patrickmin.com/binvox/binvox.html for more information.

Index

Constants

This section is empty.

Variables

View Source
var (
	Black = Color{0, 0, 0, 1}
	White = Color{1, 1, 1, 1}
)

Functions

func TriangleLess

func TriangleLess(t []*gl.Triangle) func(a, b int) bool

TriangleLess provides a Less function for sort.Slice.

Types

type BinVOX

type BinVOX struct {
	NX, NY, NZ int     // number of voxels in each dimension
	TX, TY, TZ float64 // translation (location of origin in world space)
	Scale      float64 // uniform scale in millimeters

	// WhiteVoxels represents a map of (white) voxels.
	WhiteVoxels WhiteVoxelMap

	// ColorVoxels represents a map of full-color voxels.
	ColorVoxels ColorVoxelMap
}

BinVOX represents a voxel model (or subregion) in binvox format. Voxels have uniform dimensions in X, Y, and Z and can be thought of as 3D "pixels".

NX, NY, and NZ are the number of voxels in each dimension and must be positive (non-zero).

Scale represents the uniform scale of this subregion's largest dimension (in millimeters). So if "dim = max(NX,NY,NZ)", then there are dim/Scale voxels per millimeter in each direction.

Translating the subregion to (TX,TY,TZ) will correctly place this region in world space (in millimeters).

func New

func New(nx, ny, nz int, offx, offy, offz, scale float64, fullColor bool) *BinVOX

New returns a new BinVOX struct.

func Read

func Read(filename string, sx, sy, sz, nx, ny, nz int) (*BinVOX, error)

Read reads a binvox file and returns a BinVOX using WhiteVoxels. sx, sy, sz are the starting indices for reading a model. nx, ny, nz are the number of voxels to read in each direction (0=all).

func (*BinVOX) Add

func (b *BinVOX) Add(x, y, z int)

Add adds a (white) voxel to the BinVOX WhiteVoxels map.

func (*BinVOX) AddColor

func (b *BinVOX) AddColor(x, y, z int, c Color)

AddColor adds a full-color voxel to the BinVOX ColorVoxels map.

func (*BinVOX) Dim

func (b *BinVOX) Dim() int

Dim returns the maximum dimension (the max of NX, NY, and NZ).

func (*BinVOX) Get

func (b *BinVOX) Get(x, y, z int) (color Color, ok bool)

Get gets a voxel from either the WhiteVoxelMap (first), or the ColorVoxel Map.

func (*BinVOX) MBB

func (b *BinVOX) MBB() *gl.Box

MBB returns the minimum bounding box of the subregion in millimeters.

func (*BinVOX) ManifoldMesh

func (b *BinVOX) ManifoldMesh() *gl.Mesh

func (*BinVOX) MarchingCubes

func (b *BinVOX) MarchingCubes() *gl.Mesh

func (*BinVOX) String

func (b *BinVOX) String() string

String returns a summary string of the BinVOX.

func (*BinVOX) ToMesh

func (b *BinVOX) ToMesh() *gl.Mesh

ToMesh converts a BinVOX to a mesh.

func (*BinVOX) Voxelize

func (b *BinVOX) Voxelize(mesh *gl.Mesh) error

Voxelize voxelizes a subregion of the mesh using (b.TX,b.TY,b.TZ) as the origin. The voxelized subregion will be: (0,0,0)-(b.NX-1,b.NY-1,b.NZ-1) (inclusive). b.Scale determines the scale of the voxelization. See Dim and VoxelsPerMM.

Voxelize overwrites the WhiteVoxels slice in b.

func (*BinVOX) VoxelizeZ

func (b *BinVOX) VoxelizeZ(mesh *gl.Mesh, zi int) error

func (*BinVOX) VoxelsPerMM

func (b *BinVOX) VoxelsPerMM() float64

VoxelsPerMM returns the number of voxels per millimeter.

func (*BinVOX) Write

func (b *BinVOX) Write(filename string, sx, sy, sz, nx, ny, nz int) error

Write writes a binvox file. sx, sy, sz are the starting indices of the model. nx, ny, nz are the number of voxels to write in each direction (0=all).

type Color

type Color struct {
	R, G, B, A float64
}

Color represents a voxel color.

type ColorVoxelMap

type ColorVoxelMap map[Key]Color

ColorVoxelMap respresents the voxel model as a map of full-color voxels.

type Key

type Key struct {
	X, Y, Z int
}

Key represents the location of a voxel.

type WhiteVoxelMap

type WhiteVoxelMap map[Key]struct{}

WhiteVoxelMap respresents the voxel model as a map of (white) voxels.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL