Exemple #1
0
// ImmutableBySpec returns an Immutable ROI (or nil if not available) given
// a name and uuid using string format "<roiname>,<uuid>"
func ImmutableBySpec(spec string) (*Immutable, error) {
	d, v, found, err := DataBySpec(spec)
	if err != nil {
		return nil, err
	}
	if !found {
		return nil, nil
	}

	// Read the ROI from this version.
	spans, err := d.GetSpans(v)
	if err != nil {
		return nil, err
	}

	// Setup the immutable.
	im := Immutable{
		version:   v,
		blockSize: d.BlockSize,
		blocks:    make(map[dvid.IZYXString]struct{}),
	}
	for _, span := range spans {
		z, y, x0, x1 := span[0], span[1], span[2], span[3]
		for x := x0; x <= x1; x++ {
			c := dvid.ChunkPoint3d{x, y, z}
			izyx := c.ToIZYXString()
			im.blocks[izyx] = struct{}{}
		}
	}
	return &im, nil
}
Exemple #2
0
// Adds subvolumes using simple algorithm centers fixed-sized subvolumes across active blocks.
func (d *Data) addSubvolumesGrid(layer *layerT, subvolumes *subvolumesT, batchsize int32) {
	minY, maxY, found := getYRange(layer.activeBlocks)
	if !found {
		return
	}
	subvolumes.ROI.ExtendDim(1, minY)
	subvolumes.ROI.ExtendDim(1, maxY)
	dy := maxY - minY + 1
	yleft := dy % batchsize

	addYtoBeg := yleft / 2
	addYtoEnd := yleft - addYtoBeg
	begY := minY - addYtoBeg
	endY := maxY + addYtoEnd

	// Iterate through Y, block by block, and determine the X range.  Then center subvolumes
	// along that X.
	for y0 := begY; y0 <= endY; y0 += batchsize {
		y1 := y0 + batchsize - 1
		minX, maxX, actives := getXRange(layer.activeBlocks, y0, y1)
		if len(actives) == 0 {
			continue
		}
		subvolumes.ROI.ExtendDim(0, minX)
		subvolumes.ROI.ExtendDim(0, maxX)

		// For this row of subvolumes along X, position them to encompass the X range.
		dx := maxX - minX + 1
		xleft := dx % batchsize

		addXtoBeg := xleft / 2
		addXtoEnd := xleft - addXtoBeg
		begX := minX - addXtoBeg
		endX := maxX + addXtoEnd

		// Create the subvolumes along X
		for x0 := begX; x0 <= endX; x0 += batchsize {
			x1 := x0 + batchsize - 1
			minCorner := dvid.ChunkPoint3d{x0, y0, layer.minZ}
			maxCorner := dvid.ChunkPoint3d{x1, y1, layer.maxZ}

			numTotal := totalBlocks(minCorner, maxCorner)
			numActive := findActives(actives, x0, x1)
			if numActive > 0 {
				subvolume := subvolumeT{
					Extents3d: dvid.Extents3d{
						minCorner.MinPoint(d.BlockSize).(dvid.Point3d),
						maxCorner.MaxPoint(d.BlockSize).(dvid.Point3d),
					},
					ChunkExtents3d: dvid.ChunkExtents3d{minCorner, maxCorner},
					TotalBlocks:    numTotal,
					ActiveBlocks:   numActive,
				}
				subvolumes.Subvolumes = append(subvolumes.Subvolumes, subvolume)
			}
			subvolumes.NumActiveBlocks += numActive
			subvolumes.NumTotalBlocks += numTotal
		}
	}
}
Exemple #3
0
// Adds subvolumes based on given extents for a layer.
func (d *Data) addSubvolumes(layer *layerT, subvolumes *subvolumesT, batchsize int32, merge bool) {
	// mergeThreshold := batchsize * batchsize * batchsize / 10
	minY, maxY, found := getYRange(layer.activeBlocks)
	if !found {
		return
	}
	subvolumes.ROI.ExtendDim(1, minY)
	subvolumes.ROI.ExtendDim(1, maxY)
	dy := maxY - minY + 1
	yleft := dy % batchsize

	begY := minY
	for {
		if begY > maxY {
			break
		}
		endY := begY + batchsize - 1
		if yleft > 0 {
			endY++
			yleft--
		}
		minX, maxX, actives := getXRange(layer.activeBlocks, begY, endY)
		if len(actives) > 0 {
			subvolumes.ROI.ExtendDim(0, minX)
			subvolumes.ROI.ExtendDim(0, maxX)

			dx := maxX - minX + 1
			xleft := dx % batchsize

			// Create subvolumes along this row.
			begX := minX
			for {
				if begX > maxX {
					break
				}
				endX := begX + batchsize - 1
				if xleft > 0 {
					endX++
					xleft--
				}
				minCorner := dvid.ChunkPoint3d{begX, begY, layer.minZ}
				maxCorner := dvid.ChunkPoint3d{endX, endY, layer.maxZ}
				holeBeg, holeEnd, found := findXHoles(actives, begX, endX)
				var numActive, numTotal int32
				if found && merge {
					// MinCorner stays same since we are extended in X
					if holeBeg-1 >= begX {
						lastI := len(subvolumes.Subvolumes) - 1
						subvolume := subvolumes.Subvolumes[lastI]
						lastCorner := dvid.ChunkPoint3d{holeBeg - 1, endY, layer.maxZ}
						subvolume.MaxPoint = lastCorner.MinPoint(d.BlockSize).(dvid.Point3d)
						subvolume.MaxChunk = lastCorner
						numTotal = totalBlocks(minCorner, lastCorner)
						numActive = findActives(actives, begX, holeBeg-1)
						subvolume.TotalBlocks += numTotal
						subvolume.ActiveBlocks += numActive
						subvolumes.Subvolumes[lastI] = subvolume
					}
					begX = holeEnd + 1
				} else {
					numTotal = totalBlocks(minCorner, maxCorner)
					numActive = findActives(actives, begX, endX)
					subvolume := subvolumeT{
						Extents3d: dvid.Extents3d{
							minCorner.MinPoint(d.BlockSize).(dvid.Point3d),
							maxCorner.MaxPoint(d.BlockSize).(dvid.Point3d),
						},
						ChunkExtents3d: dvid.ChunkExtents3d{minCorner, maxCorner},
						TotalBlocks:    numTotal,
						ActiveBlocks:   numActive,
					}
					subvolumes.Subvolumes = append(subvolumes.Subvolumes, subvolume)
					begX = endX + 1
				}
				subvolumes.NumActiveBlocks += numActive
				subvolumes.NumTotalBlocks += numTotal
			}
		}
		begY = endY + 1
	}
}