Ejemplo n.º 1
0
// setDefault sets Voxels properties to default values.
func (p *Properties) setDefault(values dvid.DataValues, interpolable bool) error {
	p.Values = make([]dvid.DataValue, len(values))
	copy(p.Values, values)
	p.Interpolable = interpolable

	dimensions := 3
	size := make([]int32, dimensions)
	for d := 0; d < dimensions; d++ {
		size[d] = DefaultBlockSize
	}
	var err error
	p.BlockSize, err = dvid.NewPoint(size)
	if err != nil {
		return err
	}
	p.Resolution.VoxelSize = make(dvid.NdFloat32, dimensions)
	for d := 0; d < dimensions; d++ {
		p.Resolution.VoxelSize[d] = DefaultRes
	}
	p.Resolution.VoxelUnits = make(dvid.NdString, dimensions)
	for d := 0; d < dimensions; d++ {
		p.Resolution.VoxelUnits[d] = DefaultUnits
	}
	return nil
}
Ejemplo n.º 2
0
// NdDataSchema returns the metadata in JSON for this Data
func (p *Properties) NdDataMetadata() (string, error) {
	var err error
	var size, offset dvid.Point

	dims := int(p.BlockSize.NumDims())
	if p.MinPoint == nil || p.MaxPoint == nil {
		zeroPt := make([]int32, dims)
		size, err = dvid.NewPoint(zeroPt)
		if err != nil {
			return "", err
		}
		offset = size
	} else {
		size = p.MaxPoint.Sub(p.MinPoint).AddScalar(1)
		offset = p.MinPoint
	}

	var axesName = []string{"X", "Y", "Z", "t", "c"}
	var metadata metadataT
	metadata.Axes = []axisT{}
	for dim := 0; dim < dims; dim++ {
		metadata.Axes = append(metadata.Axes, axisT{
			Label:      axesName[dim],
			Resolution: p.Resolution.VoxelSize[dim],
			Units:      p.Resolution.VoxelUnits[dim],
			Size:       size.Value(uint8(dim)),
			Offset:     offset.Value(uint8(dim)),
		})
	}
	metadata.Properties = *p

	m, err := json.Marshal(metadata)
	if err != nil {
		return "", err
	}
	return string(m), nil
}