TomographicImaging / CILViewer

A simple Viewer for 3D data built with VTK
Apache License 2.0
8 stars 6 forks source link

Error when image of dimension 1 is visualised #435

Open DanicaSTFC opened 1 month ago

DanicaSTFC commented 1 month ago

Problem:

When image of dimension 1 is visualised in the viewer, the following error appears:

(  66.076s) [4AF751E35EBAFEBC]vtkDataSetAttributes.cx:619    ERR| vtkPointData (0000014DA79FB4A0): Input extent (0, 1023, 0, 1023, 0, 0) does not match array length: 1048576

Debugging:

This error appears only the first time the viewer is launched. Even when mamba is restarted the error disappears

This error does not appear when the CILViewer2D class is used.

from ccpi.viewer.CILViewer2D import CILViewer2D
import vtk

DATASET_TO_READ = r'C:\Users\zvm34551\Coding_environment\DATA\DVC_dataset\TIFF\TIFF\Frame 0\frame_00_f_crop_idx_0600.tiff'

reader = vtk.vtkTIFFReader()
reader.SetFileName(DATASET_TO_READ)
reader.Update()

v = CILViewer2D()
print(reader.GetOutput())
v.setInputData(reader.GetOutput())
v.startRenderLoop()

To print information:

        print(self.voi.GetOutput())
        output = self.voi.GetOutput()
        print("Extent: ", output.GetExtent())
        print("Number of Points: ", output.GetNumberOfPoints())
        print("Number of Tuples in Scalars: ", output.GetPointData().GetScalars().GetNumberOfTuples())

Proposed solution:

The error is NOT raised inside the converter numpy2vtkImage, but it is generated inside this method. Here, the array vtkarray is added to an existing array e.g. Extent: (760, 760, 0, 1120, 0, 0) Number of Points: 1121 Number of Tuples in Scalars: 1121 Array 0 name = ImageScalars, Number of Tuples = 1121Image.

The number or arrays can be checked with the following:

point_data = img_data.GetPointData()

        # Print available scalar arrays
        for i in range(point_data.GetNumberOfArrays()):
            array_name = point_data.GetArrayName(i)
            array = point_data.GetArray(i)
            print(f"Array {i} name = {array_name}, Number of Tuples = {array.GetNumberOfTuples()}")

To resolve the bug the first array needs to be deleted.

The error is raised inside:

the method _visualise in CIL-GUI

It is inside displayImage in MainWindow in CIL-GUI, hence the method is in the viewer.

NOT in updateViewerCoordsDockWidgetWithCoords

It is in viewer.setInputData(image)

It is in viewer.installPipeline() (the error is shown 2 times because there is 2d viewer and a 3D viewer and both have this method)

It is in viewer.installImageWithOverlayPipeline ---> self.ia.Update()

paskino commented 1 month ago

What is an image of dimension 1? A vector?

DanicaSTFC commented 3 weeks ago

What is an image of dimension 1? A vector?

It means a 2D image, where the third dimension is 1. This is related to single image reconstruction and visualisation of the average slice in the CIL-GUI.