本文整理汇总了Golang中github.com/janelia-flyem/dvid/dvid.RLEs.Split方法的典型用法代码示例。如果您正苦于以下问题:Golang RLEs.Split方法的具体用法?Golang RLEs.Split怎么用?Golang RLEs.Split使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/janelia-flyem/dvid/dvid.RLEs
的用法示例。
在下文中一共展示了RLEs.Split方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: SplitLabels
// SplitLabels splits a portion of a label's voxels into a given split label or, if the given split
// label is 0, a new label, which is returned. The input is a binary sparse volume and should
// preferably be the smaller portion of a labeled region. In other words, the caller should chose
// to submit for relabeling the smaller portion of any split. It is assumed that the given split
// voxels are within the fromLabel set of voxels and will generate unspecified behavior if this is
// not the case.
//
// EVENTS
//
// labels.SplitStartEvent occurs at very start of split and transmits labels.DeltaSplitStart struct.
//
// labels.SplitBlockEvent occurs for every block of a split label and transmits labels.DeltaSplit struct.
//
// labels.SplitEndEvent occurs at end of split and transmits labels.DeltaSplitEnd struct.
//
func (d *Data) SplitLabels(v dvid.VersionID, fromLabel, splitLabel uint64, r io.ReadCloser) (toLabel uint64, err error) {
store, err := d.GetOrderedKeyValueDB()
if err != nil {
err = fmt.Errorf("Data type labelvol had error initializing store: %v\n", err)
return
}
batcher, ok := store.(storage.KeyValueBatcher)
if !ok {
err = fmt.Errorf("Data type labelvol requires batch-enabled store, which %q is not\n", store)
return
}
// Create a new label id for this version that will persist to store
if splitLabel != 0 {
toLabel = splitLabel
dvid.Debugf("Splitting subset of label %d into given label %d ...\n", fromLabel, splitLabel)
} else {
toLabel, err = d.NewLabel(v)
if err != nil {
return
}
dvid.Debugf("Splitting subset of label %d into new label %d ...\n", fromLabel, toLabel)
}
evt := datastore.SyncEvent{d.DataUUID(), labels.SplitStartEvent}
splitOpStart := labels.DeltaSplitStart{fromLabel, toLabel}
splitOpEnd := labels.DeltaSplitEnd{fromLabel, toLabel}
// Make sure we can split given current merges in progress
if err := labels.SplitStart(d.getMergeIV(v), splitOpStart); err != nil {
return toLabel, err
}
defer labels.SplitStop(d.getMergeIV(v), splitOpEnd)
// Signal that we are starting a split.
msg := datastore.SyncMessage{labels.SplitStartEvent, v, splitOpStart}
if err := datastore.NotifySubscribers(evt, msg); err != nil {
return 0, err
}
// Read the sparse volume from reader.
var split dvid.RLEs
split, err = dvid.ReadRLEs(r)
if err != nil {
return
}
toLabelSize, _ := split.Stats()
// Partition the split spans into blocks.
var splitmap dvid.BlockRLEs
splitmap, err = split.Partition(d.BlockSize)
if err != nil {
return
}
// Get a sorted list of blocks that cover split.
splitblks := splitmap.SortedKeys()
// Iterate through the split blocks, read the original block. If the RLEs
// are identical, just delete the original. If not, modify the original.
// TODO: Modifications should be transactional since it's GET-PUT, therefore use
// hash on block coord to direct it to blockLabel, splitLabel-specific goroutine; we serialize
// requests to handle concurrency.
ctx := datastore.NewVersionedCtx(d, v)
batch := batcher.NewBatch(ctx)
for _, splitblk := range splitblks {
// Get original block
tk := NewTKey(fromLabel, splitblk)
val, err := store.Get(ctx, tk)
if err != nil {
return toLabel, err
}
if val == nil {
return toLabel, fmt.Errorf("Split RLEs at block %s are not part of original label %d", splitblk, fromLabel)
}
var rles dvid.RLEs
if err := rles.UnmarshalBinary(val); err != nil {
return toLabel, fmt.Errorf("Unable to unmarshal RLE for original labels in block %s", splitblk)
}
// Compare and process based on modifications required.
remain, err := rles.Split(splitmap[splitblk])
//.........这里部分代码省略.........