Exemplo n.º 1
0
    def get(self, bounding_box: BoundingBox) -> Data:
        """
        Requests a data sample from the volume. If the bounding box does
not exist, then the method raises a ValueError.

        :param bounding_box: The bounding box of the request data sample
        :return: The data sample requested
        """
        if bounding_box.isDisjoint(self.getBoundingBox()):
            error_string = ("Bounding box must be inside dataset " +
                            "dimensions instead bounding box is {} while " +
                            "the dataset dimensions are {}")
            error_string = error_string.format(bounding_box,
                                               self.getBoundingBox())
            raise ValueError(error_string)

        sub_bounding_box = bounding_box.intersect(self.getBoundingBox())
        array = self.getArray(sub_bounding_box)

        before_pad = bounding_box.getEdges()[0] - sub_bounding_box.getEdges(
        )[0]
        after_pad = bounding_box.getEdges()[1] - sub_bounding_box.getEdges()[1]

        if before_pad != Vector(0, 0, 0) or after_pad != Vector(0, 0, 0):
            pad_size = tuple(
                zip(before_pad.getNumpyDim(), after_pad.getNumpyDim()))
            array = np.pad(array, pad_width=pad_size, mode="constant")

        return Data(array, bounding_box)
Exemplo n.º 2
0
    def _queryBoundingBox(self, bounding_box: BoundingBox) -> Volume:
        if self.volumes_changed:
            self._rebuildIndexes()

        edge1 = [bounding_box.getEdges()[0].getComponents()]
        distances, indexes = self.edge1_list.query(edge1, k=8)
        indexes = [
            index for index, dist in zip(indexes[0], distances[0])
            if dist < float('Inf')
        ]
        indexes = filter(
            lambda index: not bounding_box.isDisjoint(self.volumes[
                index].getBoundingBox()), indexes)
        if not indexes:
            raise IndexError("bounding_box is not present in any indexes")

        return list(indexes)