# Vtk data to Point Gaussian

**URL:** https://discourse.vtk.org/t/vtk-data-to-point-gaussian/1018
**Category:** Support
**Created:** [May 24, 2019, 6:35am UTC](https://discourse.vtk.org/t/vtk-data-to-point-gaussian/1018 "2019-05-24T06:35:53Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Enemmi](https://discourse.vtk.org/user_avatar/discourse.vtk.org/enemmi/32/10446_2.png) [@Enemmi](https://discourse.vtk.org/u/Enemmi)
#### Post date: [May 24, 2019, 6:35am UTC](https://discourse.vtk.org/t/vtk-data-to-point-gaussian/1018/1 "2019-05-24T06:35:53Z")

</div>

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

---

<div class="post-metadata">

### Author: ![Kenichiro-Yoshimi](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/k/ecc23a/32.png) [@Kenichiro-Yoshimi](https://discourse.vtk.org/u/Kenichiro-Yoshimi)
#### Post date: [May 25, 2019, 8:21am UTC](https://discourse.vtk.org/t/vtk-data-to-point-gaussian/1018/2 "2019-05-25T08:21:16Z")

</div>

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:

```auto
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()

```

 ![points_gaussian](https://discourse.vtk.org/uploads/default/original/1X/56482cf3bca04bcc64c810a3fb6127b0adb8b8ad.png)

vtkPointGaussianMapper’s examples can be found here:  
[https://vtk.org/doc/nightly/html/c2\_vtk\_t\_15.html#c2\_vtk\_t\_vtkPointGaussianMapper](https://vtk.org/doc/nightly/html/c2_vtk_t_15.html#c2_vtk_t_vtkPointGaussianMapper)

---

<div class="post-metadata">

### Author: ![Enemmi](https://discourse.vtk.org/user_avatar/discourse.vtk.org/enemmi/32/10446_2.png) [@Enemmi](https://discourse.vtk.org/u/Enemmi)
#### Post date: [May 28, 2019, 6:34am UTC](https://discourse.vtk.org/t/vtk-data-to-point-gaussian/1018/3 "2019-05-28T06:34:14Z")

</div>

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.
