Commit 067e9bfa authored by Duggan, John's avatar Duggan, John
Browse files

Reduce memory usage for defining volume dimensions and add lazy performance profiling

parent 3e4f95ec
Loading
Loading
Loading
Loading
+11 −13
Original line number Diff line number Diff line
@@ -55,26 +55,24 @@ class VisualizationPanel:

        start = time.time()
        # Merge the slices into one 3D array
        points = np.array([])
        x_range = 0
        y_range = 0
        z_range = 0
        scalars = np.array([])
        for index, path in enumerate(file_list):
        for path in file_list:
            slice_start = time.time()
            slice = get_reader(path).read()
            if len(points) == 0:
                points = slice.points
            if len(scalars) == 0:
                x_range = slice.dimensions[0]
                y_range = slice.dimensions[1]
                scalars = slice.active_scalars
            else:
                slice_points = slice.points
                slice_points[:, 2] += index
                points = np.concatenate((points, slice_points))
                scalars = np.concatenate((scalars, slice.active_scalars))
            z_range += 1
            print(f"Processed slice {z_range}/{len(file_list)} in {time.time() - slice_start:.2f}s")
        print(f"Numpy array creation: {time.time() - start:.2f}s")

        start = time.time()
        # Calculate the data extent
        x_range = int(np.amax(points[:, 0])) + 1
        y_range = int(np.amax(points[:, 1])) + 1
        z_range = int(np.amax(points[:, 2])) + 1

        # Define the 3D volume's extent
        volume = ImageData(dimensions=(x_range, y_range, z_range), origin=(0, 0, 0), spacing=(1, 1, 1))
        # Define the 3D volume's scalars for the color/opacity transfer functions
@@ -82,6 +80,6 @@ class VisualizationPanel:
        print(f"PyVista volume creation: {time.time() - start:.2f}s")

        start = time.time()
        self.plotter.add_volume(volume, clim=[0, 0.007], opacity="linear")
        self.plotter.add_volume(volume, opacity="sigmoid")
        self.plotter.view_isometric(self.plotter)
        print(f"PyVista volume rendering: {time.time() - start:.2f}s")