Vtk data to Point Gaussian

Hello,

I’m new with vtk, I would like to read a vtk file that contains coordinates and radii of spheres.
In paraview, I am able to read it and make the data to be represented with Point Gaussian with the correct radius (Use Scalar Array, Gaussian Radius = 1).

I want to do the same with vtk and Python if possible.
I guess I should use vtkUnstructuredGridReader() to read the file but I don’t know how to manage the data then.
Do you know a way to do it ?

Here is the vtk file :

# vtk DataFile Version 2.0
Unstructured grid legacy vtk file with point scalar data
ASCII

DATASET UNSTRUCTURED_GRID
POINTS 4 double
0.0 0.5 0.1
-1.0 0.3 0.0
0.0 1.0 0.0
1.0 1.0 1.0

POINT_DATA 4
SCALARS radius double
LOOKUP_TABLE default
1.
1.5
2.
0.5

Thank you

Hi,

If loading the points with vtkPolyDataReader as a polygonal data object instead of unstructured grid, where the type of dataset is POLYDATA in vtk file, vtkPointGaussianMapper can directly draw Gaussian splats of them. For example:

import argparse
import vtk


def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('--input-file', type=str)
    args = parser.parse_args()

    colors = vtk.vtkNamedColors()

    input_file_name = args.input_file

    # Create the reader for the data.
    reader = vtk.vtkPolyDataReader()
    reader.SetFileName(input_file_name)
    reader.Update()

    points = reader.GetOutput()
    range = points.GetPointData().GetArray('radius').GetRange()

    lut = vtk.vtkLookupTable()
    lut.SetHueRange(.667,0)

    point_mapper = vtk.vtkPointGaussianMapper()
    point_mapper.SetInputData(points)
    point_mapper.SetScaleArray('radius')
    point_mapper.SetScalarRange(range)
    point_mapper.SetLookupTable(lut)
    point_mapper.SetScaleFactor(0.1)
    point_mapper.EmissiveOff()
    point_mapper.SetSplatShaderCode(
        "//VTK::Color::Impl\n"
        "float dist = dot(offsetVCVSOutput.xy,offsetVCVSOutput.xy);\n"
        "if (dist > 1.0) {\n"
        "  discard;\n"
        "} else {\n"
        "  float scale = (1.0 - dist);\n"
        "  ambientColor *= scale;\n"
        "  diffuseColor *= scale;\n"
        "}\n"    
    )

    point_actor = vtk.vtkActor()
    point_actor.SetMapper(point_mapper)

    renderer = vtk.vtkRenderer()
    ren_win = vtk.vtkRenderWindow()
    ren_win.AddRenderer(renderer)
    iren = vtk.vtkRenderWindowInteractor()
    iren.SetRenderWindow(ren_win)

    renderer.AddActor(point_actor)
    renderer.SetBackground(colors.GetColor3d("SlateGray"))

    renderer.ResetCamera()

    iren.Initialize()

    ren_win.Render()
    iren.Start()


if __name__ == '__main__':
    main()

vtkPointGaussianMapper’s examples can be found here:
https://vtk.org/doc/nightly/html/c2_vtk_t_15.html#c2_vtk_t_vtkPointGaussianMapper

Hi,

Thanks, it’s perfect !
I changed UNSTRUCTURED_GRID to POLYDATA in my vtk file.
Scale Factor must be 1 to follow radii mentioned in vtk file.