Пример #1
0
    def test_blockwise(self):
        data_box = np.array(self.data_box)
        blocks = []
        boxes = []
        for z in range(0, 100, 20):
            for y in range(0, 100, 20):
                for x in range(0, 100, 20):
                    OVERLAP = 1
                    box = np.asarray([(z, y, x), (z + 20, y + 20, x + 20)],
                                     dtype=int)
                    box[0] -= OVERLAP
                    box[1] += OVERLAP
                    box = np.maximum(box, 0)
                    box = np.minimum(box, 1 + data_box[1])

                    block = self.binary_vol[box_to_slicing(*box)]
                    if block.any():
                        blocks.append(block)
                        boxes.append(box)

        mesh = Mesh.from_binary_blocks(blocks, boxes)
        data_box = np.array(self.data_box)
        mesh_box = np.array(
            [mesh.vertices_zyx.min(axis=0),
             mesh.vertices_zyx.max(axis=0)])
        assert (mesh_box == self.nonzero_box
                ).all(), f"{mesh_box.tolist()} != {self.nonzero_box.tolist()}"
Пример #2
0
    def test_blockwise_simple(self):
        """
        Simple test case to manually explore the output
        of marching cubes as computed in blocks without halo.
        """
        _ = 0
        img = [[_, _, _, _, _, 1, _, _], [_, 1, _, _, _, _, _, _],
               [_, _, 1, 1, 1, 1, 1, _], [_, 1, 1, 1, 1, 1, 1, _],
               [_, 1, 1, 1, 1, 1, 1, _], [_, 1, 1, 1, 1, 1, 1, _],
               [_, 1, 1, 1, 1, 1, 1, _], [_, _, _, _, _, _, _, _]]

        vol = np.zeros((3, 8, 8), dtype=bool)
        vol[1] = img

        blocks = (vol[:, 0:4, 0:4], vol[:, 0:4, 4:8], vol[:, 4:8,
                                                          0:4], vol[:, 4:8,
                                                                    4:8])

        starts = [[0, 0, 0], [0, 0, 4], [0, 4, 0], [0, 4, 4]]

        starts = np.array(starts)
        boxes = np.zeros((4, 2, 3), np.uint32)
        boxes[:, 0, :] = starts
        boxes[:, 1, :] = starts + (3, 4, 4)

        _mesh = Mesh.from_binary_blocks(blocks[3:4], boxes[3:4], stitch=False)