Example #1
0
    def get(self, bounding_box: BoundingBox) -> Data:
        indexes = self._queryBoundingBox(bounding_box)

        data = []

        stack_volumes = [volume for i, volume in self.stack if i in indexes]
        stack_disjoint = list(set(indexes) - set([i for i, v in self.stack]))

        for volume in stack_volumes:
            sub_bbox = bounding_box.intersect(volume.getBoundingBox())
            data.append(volume.get(sub_bbox))

        for index in stack_disjoint:
            volume = self.volumes[index]
            i = self._pushStack(index, volume)

            sub_bbox = bounding_box.intersect(volume.getBoundingBox())
            data.append(volume.get(sub_bbox))

        shape = bounding_box.getNumpyDim()
        array = Array(np.zeros(shape).astype(np.uint16),
                      bounding_box=bounding_box,
                      iteration_size=BoundingBox(Vector(0, 0, 0),
                                                 bounding_box.getSize()),
                      stride=bounding_box.getSize())
        [array.set(item) for item in data]
        return Data(array.getArray(), bounding_box)
Example #2
0
    def setIteration(self, iteration_size: BoundingBox, stride: Vector):
        if not isinstance(iteration_size, BoundingBox):
            error_string = ("iteration_size must have type BoundingBox" +
                            " instead it has type {}")
            error_string = error_string.format(type(iteration_size))
            raise ValueError(error_string)

        if not isinstance(stride, Vector):
            raise ValueError("stride must have type Vector")

        if not iteration_size.isSubset(
                BoundingBox(Vector(0, 0, 0),
                            self.getBoundingBox().getSize())):
            raise ValueError(
                "iteration_size must be smaller than volume size " +
                "instead the iteration size is {} ".format(
                    iteration_size.getSize()) +
                "and the volume size is {}".format(
                    self.getBoundingBox().getSize()))

        self.setIterationSize(iteration_size)
        self.setStride(stride)

        def ceil(x):
            return int(round(x))

        self.element_vec = Vector(
            *map(lambda L, l, s: ceil((L - l) / s + 1),
                 self.getBoundingBox().getSize().getComponents(),
                 self.iteration_size.getSize().getComponents(),
                 self.stride.getComponents()))

        self.index = 0