dvid

package
v0.0.0-...-2551dc1 Latest Latest
Warning

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

Go to latest
Published: Jun 25, 2013 License: BSD-3-Clause Imports: 21 Imported by: 0

Documentation

Overview

Package dvid provides types, constants, and functions that have no other dependencies and can be used by all packages within DVID. This includes core data structures, command string handling, and command packaging. Since these elements are used at multiple DVID layers, we separate them here and allow reuse in layer-specific types through embedding.

Index

Constants

View Source
const (
	KeyUuid  = "uuid"
	KeyPlane = "plane"
)

Keys for setting various arguments within the command line via "key=value" strings.

View Source
const (
	Kilo = 1 << 10
	Mega = 1 << 20
	Giga = 1 << 30
	Tera = 1 << 40
)
View Source
const DefaultJPEGQuality = 80

DefaultJPEGQuality is the quality of images returned if requesting JPEG images and an explicit Quality amount is omitted.

Variables

This section is empty.

Functions

func DecodeSerializationFormat

func DecodeSerializationFormat(s SerializationFormat) (compress Compression, checksum Checksum)

func Deserialize

func Deserialize(s Serialization, object interface{}) (err error)

Deserializes a Go object using Gob encoding

func ElapsedTime

func ElapsedTime(mode ModeFlag, startTime time.Time, p ...interface{})

ElapsedTime prints the time elapsed from the start time with Printf arguments afterwards. Example: ElapsedTime(dvid.Debug, startTime, "Time since launch of %s", funcName)

func Error

func Error(p ...interface{})

Error prints a message to the Error Log File, which is useful to mark potential issues but not ones that should crash the DVID server. Basically, you should opt to crash the server if a mistake can propagate and corrupt data. If not, you can use this function. Note that Error logging to a file only occurs if DVID is running as a server, otherwise this function will print to stdout.

func Fmt

func Fmt(mode ModeFlag, p ...interface{})

Fmt prints a message via fmt.Print() depending on the Mode of DVID.

func ImageData

func ImageData(img image.Image) (data []uint8, stride int32, err error)

ImageData returns the underlying pixel data for an image or an error if the image doesn't have the requisite []uint8 pixel data.

func ImageFromFile

func ImageFromFile(filename string) (img image.Image, format string, err error)

ImageFromFile returns an image and its format name given a file name.

func ImageFromPost

func ImageFromPost(r *http.Request, key string) (img image.Image, format string, err error)

ImageFromPost returns and image and its format name given a key to a POST request. The image should be the first file in a POSTed form.

func ImageGrayFromData

func ImageGrayFromData(data []uint8, nx, ny int) (img *image.Gray)

ImageGrayFromData returns a Gray image given data and image size.

func ListDataShapes

func ListDataShapes() (shapes []string)

ListDataShapes returns a slice of shape names

func Log

func Log(mode ModeFlag, p ...interface{})

Log prints a message via log.Print() depending on the Mode of DVID.

func PrintNonZero

func PrintNonZero(message string, value []byte)

PrintNonZero prints the number of non-zero bytes in a slice of bytes.

func Prompt

func Prompt(message, defaultValue string) string

Prompt returns a string entered by the user after displaying message. If the user just hits ENTER (or enters an empty string), then the defaultValue is returned.

func ReadJSONFile

func ReadJSONFile(filename string) (value map[string]interface{}, err error)

ReadJSONFile returns a map[string]interface{} with decoded JSON from a file. If a file is not organized as a JSON object, an error will be returned.

func SetErrorLoggingFile

func SetErrorLoggingFile(out io.Writer)

SetErrorLoggingFile creates an error logger to the given file for this DVID process.

func WaitToComplete

func WaitToComplete(wg *sync.WaitGroup, mode ModeFlag, startTime time.Time, p ...interface{})

Wait for WaitGroup then print message including time for operation. The last arguments are fmt.Printf arguments and should not include the newline since one is added in this function.

func WriteImageHttp

func WriteImageHttp(w http.ResponseWriter, img image.Image, formatStr string) (err error)

WriteImageHttp writes an image to a HTTP response writer using a format and optional compression strength specified in a string, e.g., "png", "jpg:80".

func WriteJSONFile

func WriteJSONFile(filename string, value interface{}) error

WriteJSONFile writes an arbitrary but exportable Go object to a JSON file.

Types

type BlockCoord

type BlockCoord [3]int32

BlockCoord is the (X,Y,Z) of a Block.

func (BlockCoord) Add

func (c BlockCoord) Add(x BlockCoord) (result BlockCoord)

func (BlockCoord) Max

func (c BlockCoord) Max(x BlockCoord) (result BlockCoord)

BoundMin returns a block coordinate where each of its elements are not smaller than the corresponding element in x.

func (BlockCoord) Min

func (c BlockCoord) Min(x BlockCoord) (result BlockCoord)

BoundMax returns a block coordinate where each of its elements are not greater than the corresponding element in x.

func (BlockCoord) String

func (c BlockCoord) String() string

func (BlockCoord) Sub

func (c BlockCoord) Sub(x BlockCoord) (result BlockCoord)

type Checksum

type Checksum uint8

Checksum is the type of checksum employed for error checking stored data

const (
	NoChecksum Checksum = 0
	CRC32               = 1 << iota
)

func (Checksum) String

func (checksum Checksum) String() string

type Command

type Command []string

Command supports command-line interaction with DVID. The first item in the string slice is the command, which may be "help" or the name of DVID data name ("grayscale8"). If the first item is the name of a data type, the second item will have a type-specific command like "get". The other arguments are command arguments or optional settings of the form "<key>=<value>".

func (Command) CommandArgs

func (cmd Command) CommandArgs(startPos int, targets ...*string) (overflow []string)

CommandArgs sets a variadic argument set of string pointers to data command arguments, ignoring setting arguments of the form "<key>=<value>". If there aren't enough arguments to set a target, the target is set to the empty string. It returns an 'overflow' slice that has all arguments beyond those needed for targets.

Example: Given the command string "add param1 param2 42 data/*.png"

var s1, s2, s3, s4 string
filenames := CommandArgs(0, &s1, &s2, &s3, &s4)
fmt.Println(filenames)
fmt.Println(s1)
fmt.Println(s2, s3)
fmt.Println(s4)

Would print out:
   ["data/foo-1.png", "data/foo-2.png", "data/foo-3.png"]
   add
   param1 param2
   42

func (Command) Name

func (cmd Command) Name() string

Name returns the first argument of the command (in lower case) which is assumed to be the name of the command.

func (Command) Parameter

func (cmd Command) Parameter(key string) (value string, found bool)

Parameter scans a command for any "key=value" argument and returns the value of the passed 'key'.

func (Command) String

func (cmd Command) String() string

String returns a space-separated command line

func (Command) TypeCommand

func (cmd Command) TypeCommand() string

TypeCommand returns the name of a type-specific command (in lower case).

type Compression

type Compression uint8

Compression is the format of compression for storing data

const (
	Uncompressed Compression = 0
	Snappy                   = 1 << iota
)

func DeserializeData

func DeserializeData(s Serialization, uncompress bool) (data []byte, compress Compression, err error)

DeserializeData deserializes a slice of bytes using stored compression, checksum. If uncompress parameter is false, the data is not uncompressed.

func (Compression) String

func (compress Compression) String() string

type Config

type Config map[string]interface{}

Config is a map of keyword to arbitrary data to specify configurations via keyword.

type DataShape

type DataShape byte

DataShape describes the way data is positioned in 3d space

const (
	// XY describes a rectangle of voxels that share a z-coord.
	XY DataShape = iota

	// XZ describes a rectangle of voxels that share a y-coord.
	XZ

	// YZ describes a rectangle of voxels that share a x-coord.
	YZ

	// Arb describes a rectangle of voxels with arbitrary 3d orientation.
	Arb

	// Vol describes a Subvolume of voxels
	Vol
)

func (DataShape) String

func (shape DataShape) String() string

type DataShapeString

type DataShapeString string

String for specifying a slice orientation or subvolume

func (DataShapeString) DataShape

func (s DataShapeString) DataShape() (shape DataShape, err error)

DataShape returns the data shape constant associated with the string.

type Geometry

type Geometry interface {
	// DataShape describes the shape of the data.
	DataShape() DataShape

	// Origin returns the offset to the voxel at the top left corner of the data.
	Origin() VoxelCoord

	// Size returns the size as a Point3d that shows the extent in each dimension.
	Size() Point3d

	// Width is defined as size along different axis per shape:
	//   x for Vol, XY, and XZ shapes
	//   y for the YZ shape.
	Width() int32

	// Height is defined as size along different axis per shape:
	//   y for Vol, XY shapes
	//   z for XZ, YZ
	Height() int32

	// Depth is defined as 1 for XY, XZ, YZ, and Arb shapes.  Depth returns
	// the size along z for Vol shapes.
	Depth() int32

	// NumVoxels returns the number of voxels within this space.
	NumVoxels() int64

	// EndVoxel returns the last voxel coordinate usually traversed so that
	// iteration from Origin->EndVoxel will visit all the voxels.
	EndVoxel() VoxelCoord

	String() string
}

Geometry describes the shape, size, and position of data in the DVID volume.

func NewSlice

func NewSlice(shape DataShape, offset VoxelCoord, size Point2d) (slice Geometry, err error)

NewSlice returns a Geometry object for a XY, XZ, or YZ slice given the data's orientation, offset, and size.

func NewSliceArb

func NewSliceArb(origin, topRight, bottomLeft VoxelCoord) Geometry

func NewSliceFromStrings

func NewSliceFromStrings(shapeStr, offsetStr, sizeStr string) (slice Geometry, err error)

NewSliceFromStrings returns a Geometry object for a XY, XZ, or YZ slice given string representations of shape ("xy"), offset ("0,10,20"), and size ("250,250").

func NewSliceXY

func NewSliceXY(origin VoxelCoord, size Point2d) Geometry

func NewSliceXZ

func NewSliceXZ(origin VoxelCoord, size Point2d) Geometry

func NewSliceYZ

func NewSliceYZ(origin VoxelCoord, size Point2d) Geometry

type LocalID

type LocalID uint16

LocalID is a unique id for some data in a DVID instance. This unique id is presumably a much smaller representation than the actual data (e.g., a version UUID or dataset description) and can be represented with fewer bytes in keys.

func GetLocalID

func GetLocalID(b []byte) (id LocalID, err error)

GetLocalID parses a slice of bytes into a LocalID.

func (LocalID) Bytes

func (id LocalID) Bytes() []byte

Bytes returns a sequence of bytes encoding this LocalID.

type ModeFlag

type ModeFlag uint
const (
	Normal ModeFlag = iota
	Debug
	Benchmark
)
var Mode ModeFlag

Mode is a global variable set to the run modes of this DVID process.

type Point2d

type Point2d [2]int32

Point2d is a 2d point.

func SizeFromRect

func SizeFromRect(rect image.Rectangle) (size Point2d)

func (Point2d) String

func (pt Point2d) String() string

type Point3d

type Point3d [3]int32

Point3d is a 3d point.

func (Point3d) String

func (pt Point3d) String() string

type PointStr

type PointStr string

PointStr is a n-dimensional coordinate in string format "x,y,z,..." where each coordinate is a 32-bit integer.

func (PointStr) Point2d

func (s PointStr) Point2d() (point Point2d, err error)

func (PointStr) Point3d

func (s PointStr) Point3d() (coord Point3d, err error)

func (PointStr) VoxelCoord

func (s PointStr) VoxelCoord() (coord VoxelCoord, err error)

type Response

type Response struct {
	ContentType string
	Text        string
	Status      string
}

Response provides a few string fields to pass information back from a remote operation.

type Serializable

type Serializable interface {
	Serialize() (Serialization, error)
	Deserialize(Serialization) error
}

Serializable can be serialized to and deserialized from bytes.

type Serialization

type Serialization []byte

Serialization should be a slice of bytes.

func Serialize

func Serialize(object interface{}, compress Compression, checksum Checksum) (s Serialization, err error)

Serializes an arbitrary Go object using Gob encoding and optional compression, checksum

func SerializeData

func SerializeData(data []byte, compress Compression, checksum Checksum) (s Serialization, err error)

Serialize a slice of bytes using optional compression, checksum

type SerializationFormat

type SerializationFormat uint8

SerializationFormat is a single byte combining both compression and checksum methods.

func EncodeSerializationFormat

func EncodeSerializationFormat(compress Compression, checksum Checksum) SerializationFormat

type SliceArb

type SliceArb struct {
	// contains filtered or unexported fields
}

SliceArb is an arbitray slice in 3d space.

func (*SliceArb) BottomLeft

func (s *SliceArb) BottomLeft() VoxelCoord

func (*SliceArb) DataShape

func (s *SliceArb) DataShape() DataShape

func (*SliceArb) Depth

func (s *SliceArb) Depth() int32

func (*SliceArb) EndVoxel

func (s *SliceArb) EndVoxel() VoxelCoord

func (*SliceArb) Height

func (s *SliceArb) Height() int32

func (*SliceArb) NumVoxels

func (s *SliceArb) NumVoxels() int64

func (*SliceArb) Origin

func (s *SliceArb) Origin() VoxelCoord

func (*SliceArb) Size

func (s *SliceArb) Size() Point3d

func (*SliceArb) String

func (s *SliceArb) String() string

func (*SliceArb) TopRight

func (s *SliceArb) TopRight() VoxelCoord

func (*SliceArb) Width

func (s *SliceArb) Width() int32

type SliceData

type SliceData struct {
	// contains filtered or unexported fields
}

SliceData specifies a rectangle in 3d space that is orthogonal to an axis.

func (*SliceData) Depth

func (s *SliceData) Depth() int32

func (*SliceData) EndVoxel

func (s *SliceData) EndVoxel() VoxelCoord

func (*SliceData) NumVoxels

func (s *SliceData) NumVoxels() int64

func (*SliceData) Origin

func (s *SliceData) Origin() VoxelCoord

func (*SliceData) Size

func (s *SliceData) Size() Point3d

type SliceXY

type SliceXY struct {
	SliceData
}

SliceXY is a slice in the XY plane.

func (*SliceXY) BottomLeft

func (s *SliceXY) BottomLeft() VoxelCoord

func (*SliceXY) DataShape

func (s *SliceXY) DataShape() DataShape

func (*SliceXY) Height

func (s *SliceXY) Height() int32

func (*SliceXY) Normal

func (s *SliceXY) Normal() Vector3d

func (*SliceXY) String

func (s *SliceXY) String() string

func (*SliceXY) TopRight

func (s *SliceXY) TopRight() VoxelCoord

func (*SliceXY) Width

func (s *SliceXY) Width() int32

type SliceXZ

type SliceXZ struct {
	SliceData
}

SliceXZ is a slice in the XZ plane.

func (*SliceXZ) BottomLeft

func (s *SliceXZ) BottomLeft() VoxelCoord

func (*SliceXZ) DataShape

func (s *SliceXZ) DataShape() DataShape

func (*SliceXZ) Height

func (s *SliceXZ) Height() int32

func (*SliceXZ) Normal

func (s *SliceXZ) Normal() Vector3d

func (*SliceXZ) String

func (s *SliceXZ) String() string

func (*SliceXZ) TopRight

func (s *SliceXZ) TopRight() VoxelCoord

func (*SliceXZ) Width

func (s *SliceXZ) Width() int32

type SliceYZ

type SliceYZ struct {
	SliceData
}

SliceYZ is a slice in the YZ plane.

func (*SliceYZ) BottomLeft

func (s *SliceYZ) BottomLeft() VoxelCoord

func (*SliceYZ) DataShape

func (s *SliceYZ) DataShape() DataShape

func (*SliceYZ) Height

func (s *SliceYZ) Height() int32

func (*SliceYZ) Normal

func (s *SliceYZ) Normal() Vector3d

func (*SliceYZ) String

func (s *SliceYZ) String() string

func (*SliceYZ) TopRight

func (s *SliceYZ) TopRight() VoxelCoord

func (*SliceYZ) Width

func (s *SliceYZ) Width() int32

type Subvolume

type Subvolume struct {
	// contains filtered or unexported fields
}

Subvolume describes the Geometry for a rectangular box of voxels. The "Sub" prefix emphasizes that the data is usually a smaller portion of the volume held by the DVID datastore. Note that the 3d coordinate system is a Right-Hand system and works with OpenGL. The origin is considered the top left corner of an XY slice. X increases as you move from left to right. Y increases as you move down from the origin. Z increases as you add more slices deeper than the current slice.

func NewSubvolume

func NewSubvolume(origin VoxelCoord, size Point3d) *Subvolume

NewSubvolume returns a Subvolume given a subvolume's origin and size.

func NewSubvolumeFromStrings

func NewSubvolumeFromStrings(originStr, sizeStr string) (subvol *Subvolume, err error)

NewSubvolumeFromStrings returns a Subvolume given string representations of origin ("0,10,20") and size ("250,250,250").

func (*Subvolume) BottomLeft

func (s *Subvolume) BottomLeft() VoxelCoord

func (*Subvolume) DataShape

func (s *Subvolume) DataShape() DataShape

func (*Subvolume) Depth

func (s *Subvolume) Depth() int32

func (*Subvolume) EndVoxel

func (s *Subvolume) EndVoxel() VoxelCoord

func (*Subvolume) Height

func (s *Subvolume) Height() int32

func (*Subvolume) NumVoxels

func (s *Subvolume) NumVoxels() int64

func (*Subvolume) Origin

func (s *Subvolume) Origin() VoxelCoord

func (*Subvolume) Size

func (s *Subvolume) Size() Point3d

func (*Subvolume) String

func (s *Subvolume) String() string

func (*Subvolume) TopRight

func (s *Subvolume) TopRight() VoxelCoord

func (*Subvolume) Width

func (s *Subvolume) Width() int32

type Vector3d

type Vector3d [3]float32

Vector3d is a floating point 3d vector.

type VectorStr

type VectorStr string

VectorStr is a n-dimensional coordinate in string format "x,y,z,...."" where each coordinate is a 32-bit float.

func (VectorStr) Vector3d

func (s VectorStr) Vector3d() (v Vector3d, err error)

type Volume

type Volume struct {
	// Volume extents
	VolumeMax VoxelCoord

	// Relative resolution of voxels in volume
	VoxelRes VoxelResolution

	// Units of resolution, e.g., "nanometers"
	VoxelResUnits VoxelResolutionUnits
}

Volume defines the extent and resolution of a volume.

func (*Volume) WriteJSON

func (vol *Volume) WriteJSON(filename string) error

WriteJSON writes a Volume to a JSON file.

type VoxelCoord

type VoxelCoord [3]int32

VoxelCoord is the (X,Y,Z) of a Voxel.

func (VoxelCoord) Add

func (c VoxelCoord) Add(x VoxelCoord) (result VoxelCoord)

func (VoxelCoord) AddSize

func (c VoxelCoord) AddSize(s Point3d) (result VoxelCoord)

AddSize returns a voxel coordinate that is moved by the s vector minus one. If s is the size of a box, this has the effect of returning the maximum voxel coordinate still within the box.

func (VoxelCoord) BlockCoord

func (c VoxelCoord) BlockCoord(blockSize Point3d) (bc BlockCoord)

BlockCoord returns the coordinate of the block containing the voxel coordinate.

func (VoxelCoord) BlockVoxel

func (c VoxelCoord) BlockVoxel(blockSize Point3d) (bc VoxelCoord)

BlockVoxel returns the voxel coordinate within a containing block for the given voxel coordinate.

func (VoxelCoord) Distance

func (c VoxelCoord) Distance(x VoxelCoord) int32

Distance returns the integer distance (rounding down) between two voxel coordinates.

func (VoxelCoord) Div

func (c VoxelCoord) Div(x VoxelCoord) (result VoxelCoord)

func (VoxelCoord) Max

func (c VoxelCoord) Max(x VoxelCoord) (result VoxelCoord)

BoundMin returns a voxel coordinate where each of its elements are not smaller than the corresponding element in x.

func (VoxelCoord) Min

func (c VoxelCoord) Min(x VoxelCoord) (result VoxelCoord)

BoundMax returns a voxel coordinate where each of its elements are not greater than the corresponding element in x.

func (VoxelCoord) Mod

func (c VoxelCoord) Mod(x VoxelCoord) (result VoxelCoord)

func (*VoxelCoord) Prompt

func (c *VoxelCoord) Prompt(message, defaultValue string)

Prompt asks the user to enter components of a voxel coordinate with empty entries returning the numerical equivalent of defaultValue.

func (VoxelCoord) String

func (c VoxelCoord) String() string

func (VoxelCoord) Sub

func (c VoxelCoord) Sub(x VoxelCoord) (result VoxelCoord)

func (VoxelCoord) ToBlockIndex

func (c VoxelCoord) ToBlockIndex(blockSize Point3d) (index int)

ToBlockIndex returns an index into a block's data that corresponds to a given voxel coordinate. Note that the index is NOT multiplied by BytesPerVoxel but gives the element number, since we also want to set dirty flags.

type VoxelResolution

type VoxelResolution [3]float32

VoxelResolution holds the relative resolutions along each dimension. Since voxel resolutions should be fixed for the lifetime of a datastore, we assume there is one base unit of resolution (e.g., nanometers) and all resolutions are based on that.

func (*VoxelResolution) Prompt

func (res *VoxelResolution) Prompt(message, defaultValue string)

Prompt asks the user to enter components of a voxel's resolution with empty entries returning the numerical equivalent of defaultValue.

type VoxelResolutionUnits

type VoxelResolutionUnits string

The description of the units of voxel resolution, e.g., "nanometer".

Jump to

Keyboard shortcuts

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