github.com/janelia-flyem/dvid@v1.0.0/datatype/common/labels/events.go (about) 1 package labels 2 3 import ( 4 "fmt" 5 6 pb "google.golang.org/protobuf/proto" 7 8 "github.com/janelia-flyem/dvid/datatype/common/proto" 9 "github.com/janelia-flyem/dvid/datatype/imageblk" 10 "github.com/janelia-flyem/dvid/dvid" 11 ) 12 13 // MergeOp represents the merging of a set of labels into a target label. 14 type MergeOp struct { 15 MutID uint64 16 Target uint64 17 Merged Set 18 } 19 20 // MappingOp represents a mapping of a set of original labels into a mapped lapel. 21 type MappingOp struct { 22 MutID uint64 23 Mapped uint64 24 Original Set 25 } 26 27 // Marshal returns a proto.MappingOp serialization 28 func (op MappingOp) Marshal() (serialization []byte, err error) { 29 original := make([]uint64, len(op.Original)) 30 var i int 31 for label := range op.Original { 32 original[i] = label 33 i++ 34 } 35 pop := &proto.MappingOp{ 36 Mutid: op.MutID, 37 Mapped: op.Mapped, 38 Original: original, 39 } 40 return pb.Marshal(pop) 41 } 42 43 // SplitOp represents a split with the sparse volume of the new label. 44 type SplitOp struct { 45 MutID uint64 46 Target uint64 47 NewLabel uint64 48 RLEs dvid.RLEs 49 Coarse bool // true if the RLEs are block coords (coarse split), not voxels. 50 SplitMap map[uint64]SVSplit 51 } 52 53 // CleaveOp represents a cleave of a label using supervoxels. 54 type CleaveOp struct { 55 MutID uint64 56 Target uint64 57 CleavedLabel uint64 58 CleavedSupervoxels []uint64 59 } 60 61 // SplitSupervoxelOp describes a supervoxel split. 62 type SplitSupervoxelOp struct { 63 MutID uint64 64 Supervoxel uint64 65 SplitSupervoxel uint64 66 RemainSupervoxel uint64 67 Split dvid.BlockRLEs 68 } 69 70 // Affinity represents a float value associated with a two-tuple of labels. 71 type Affinity struct { 72 Label1 uint64 73 Label2 uint64 74 Value float32 75 } 76 77 // SplitFineOp is a split using RLEs for a block. 78 79 func (op MergeOp) String() string { 80 return fmt.Sprintf("merge %s -> label %d", op.Merged, op.Target) 81 } 82 83 // MergeTuple represents a merge of labels. Its first element is the destination label 84 // and all later elements in the slice are labels to be merged. It's an easy JSON 85 // representation as a list of labels. 86 type MergeTuple []uint64 87 88 // Op converts a MergeTuple into a MergeOp. 89 func (t MergeTuple) Op() (MergeOp, error) { 90 var op MergeOp 91 if t == nil || len(t) == 1 { 92 return op, fmt.Errorf("invalid merge tuple %v, need at least target and to-merge labels", t) 93 } 94 op.Target = t[0] 95 op.Merged = make(Set, len(t)-1) 96 for _, label := range t[1:] { 97 if label == 0 { 98 return op, fmt.Errorf("invalid merge tuple %v -- cannot contain background label 0", t) 99 } 100 op.Merged[label] = struct{}{} 101 } 102 return op, nil 103 } 104 105 // DeltaNewSize is a new label being introduced. 106 type DeltaNewSize struct { 107 Label uint64 108 Size uint64 109 } 110 111 // DeltaDeleteSize gives info to delete a label's size. 112 type DeltaDeleteSize struct { 113 Label uint64 114 OldSize uint64 115 OldKnown bool // true if OldSize is valid, otherwise delete all size k/v for this label. 116 } 117 118 // DeltaModSize gives info to modify an existing label size without knowing the old size. 119 type DeltaModSize struct { 120 Label uint64 121 SizeChange int64 // Adds to old label size 122 } 123 124 // DeltaReplaceSize gives info to precisely remove an old label size and add the updated size. 125 type DeltaReplaceSize struct { 126 Label uint64 127 OldSize uint64 128 NewSize uint64 129 } 130 131 // DeltaMerge describes the labels and blocks affected by a merge operation. It is sent 132 // during a MergeBlockEvent. 133 type DeltaMerge struct { 134 MergeOp 135 Blocks dvid.IZYXSlice // not nil if labelarray used. 136 BlockMap map[dvid.IZYXString]struct{} // not nil if labelblk used, to be deprecated. 137 TargetVoxels uint64 138 MergedVoxels uint64 139 } 140 141 // DeltaMergeStart is the data sent during a MergeStartEvent. 142 type DeltaMergeStart struct { 143 MergeOp 144 } 145 146 // DeltaMergeEnd is the data sent during a MergeEndEvent. 147 type DeltaMergeEnd struct { 148 MergeOp 149 } 150 151 // DeltaSplit describes the voxels modified during a split operation. 152 // The Split field may be null if this is a coarse split only defined by block indices. 153 type DeltaSplit struct { 154 MutID uint64 155 OldLabel uint64 156 NewLabel uint64 157 Split dvid.BlockRLEs 158 SortedBlocks dvid.IZYXSlice 159 SplitVoxels uint64 160 } 161 162 // DeltaSplitStart is the data sent during a SplitStartEvent. 163 type DeltaSplitStart struct { 164 OldLabel uint64 165 NewLabel uint64 166 } 167 168 // DeltaSplitEnd is the data sent during a SplitEndEvent. 169 type DeltaSplitEnd struct { 170 OldLabel uint64 171 NewLabel uint64 172 } 173 174 // DeltaSparsevol describes a change to an existing label. 175 type DeltaSparsevol struct { 176 Label uint64 177 Mods dvid.BlockRLEs 178 } 179 180 // Label change event identifiers 181 const ( 182 IngestBlockEvent = imageblk.IngestBlockEvent 183 MutateBlockEvent = imageblk.MutateBlockEvent 184 DeleteBlockEvent = imageblk.DeleteBlockEvent 185 SparsevolStartEvent = "SPARSEVOL_START" 186 SparsevolModEvent = "SPARSEVOL_MOD" 187 SparsevolEndEvent = "SPARSEVOL_END" 188 ChangeSizeEvent = "LABEL_SIZE_CHANGE" 189 MergeStartEvent = "MERGE_START" 190 MergeBlockEvent = "MERGE_BLOCK" 191 MergeEndEvent = "MERGE_END" 192 SplitStartEvent = "SPLIT_START" 193 SplitLabelEvent = "SPLIT_LABEL" 194 SplitEndEvent = "SPLIT_END" 195 CleaveStartEvent = "CLEAVE_START" 196 CleaveLabelEvent = "CLEAVE_LABEL" 197 CleaveEndEvent = "CLEAVE_END" 198 SupervoxelSplitStartEvent = "SV_SPLIT_START" 199 SupervoxelSplitEvent = "SV_SPLIT" 200 SupervoxelSplitEndEvent = "SV_SPLIT_END" 201 )