本文整理汇总了Golang中github.com/janelia-flyem/dvid/dvid.Geometry.NumVoxels方法的典型用法代码示例。如果您正苦于以下问题:Golang Geometry.NumVoxels方法的具体用法?Golang Geometry.NumVoxels怎么用?Golang Geometry.NumVoxels使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/janelia-flyem/dvid/dvid.Geometry
的用法示例。
在下文中一共展示了Geometry.NumVoxels方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: NewLabels
// NewLabels returns labelblk Labels, a representation of externally usable subvolume
// or slice data, given some geometry and optional image data.
// If img is passed in, the function will initialize Voxels with data from the image.
// Otherwise, it will allocate a zero buffer of appropriate size.
//
// TODO : Unlike the standard imageblk.NewVoxels, the labelblk version can modify the
// labels based on the z-coordinate of the given geometry for Raveler labeling.
// This will be removed when Raveler-specific labels are moved outside DVID.
func (d *Data) NewLabels(geom dvid.Geometry, img interface{}) (*Labels, error) {
bytesPerVoxel := d.Properties.Values.BytesPerElement()
stride := geom.Size().Value(0) * bytesPerVoxel
var data []byte
if img == nil {
numVoxels := geom.NumVoxels()
if numVoxels <= 0 {
return nil, fmt.Errorf("Illegal geometry requested: %s", geom)
}
requestSize := int64(bytesPerVoxel) * numVoxels
if requestSize > server.MaxDataRequest {
return nil, fmt.Errorf("Requested payload (%d bytes) exceeds this DVID server's set limit (%d)",
requestSize, server.MaxDataRequest)
}
data = make([]byte, requestSize)
} else {
switch t := img.(type) {
case image.Image:
var inputBytesPerVoxel, actualStride int32
var err error
data, inputBytesPerVoxel, actualStride, err = dvid.ImageData(t)
if err != nil {
return nil, err
}
if actualStride != stride {
// Need to do some conversion here.
switch d.Labeling {
case Standard64bit:
data, err = d.convertTo64bit(geom, data, int(inputBytesPerVoxel), int(actualStride))
if err != nil {
return nil, err
}
case RavelerLabel:
data, err = d.addLabelZ(geom, data, actualStride)
if err != nil {
return nil, err
}
default:
return nil, fmt.Errorf("unexpected label type in labelblk: %s", d.Labeling)
}
}
case []byte:
data = t
actualLen := int64(len(data))
expectedLen := int64(bytesPerVoxel) * geom.NumVoxels()
if actualLen != expectedLen {
return nil, fmt.Errorf("labels data was %d bytes, expected %d bytes for %s",
actualLen, expectedLen, geom)
}
default:
return nil, fmt.Errorf("unexpected image type given to NewVoxels(): %T", t)
}
}
labels := &Labels{
imageblk.NewVoxels(geom, d.Properties.Values, data, stride),
}
return labels, nil
}
示例2: NewVoxels
// NewVoxels returns Voxels with given geometry and optional image data.
// If img is passed in, the function will initialize the Voxels with data from the image.
// Otherwise, it will allocate a zero buffer of appropriate size.
func (d *Data) NewVoxels(geom dvid.Geometry, img interface{}) (*Voxels, error) {
bytesPerVoxel := d.Properties.Values.BytesPerElement()
stride := geom.Size().Value(0) * bytesPerVoxel
voxels := &Voxels{
Geometry: geom,
values: d.Properties.Values,
stride: stride,
}
if img == nil {
numVoxels := geom.NumVoxels()
if numVoxels <= 0 {
return nil, fmt.Errorf("Illegal geometry requested: %s", geom)
}
requestSize := int64(bytesPerVoxel) * numVoxels
if requestSize > server.MaxDataRequest {
return nil, fmt.Errorf("Requested payload (%d bytes) exceeds this DVID server's set limit (%d)",
requestSize, server.MaxDataRequest)
}
voxels.data = make([]uint8, requestSize)
} else {
switch t := img.(type) {
case image.Image:
var actualStride int32
var err error
voxels.data, _, actualStride, err = dvid.ImageData(t)
if err != nil {
return nil, err
}
if actualStride < stride {
return nil, fmt.Errorf("Too little data in input image (expected stride %d)", stride)
}
voxels.stride = actualStride
case []byte:
voxels.data = t
actualLen := int64(len(voxels.data))
expectedLen := int64(bytesPerVoxel) * geom.NumVoxels()
if actualLen != expectedLen {
return nil, fmt.Errorf("voxels data was %d bytes, expected %d bytes for %s",
actualLen, expectedLen, geom)
}
default:
return nil, fmt.Errorf("Unexpected image type given to NewVoxels(): %T", t)
}
}
return voxels, nil
}