# OSPRay colouring materials by scalar

**URL:** https://discourse.paraview.org/t/ospray-colouring-materials-by-scalar/1846
**Category:** Development
**Tags:** vtk
**Created:** [May 13, 2019, 3:57pm UTC](https://discourse.paraview.org/t/ospray-colouring-materials-by-scalar/1846 "2019-05-13T15:57:37Z")
**Posts on this page:** 1
**Showing post:** 5

<div class="post-metadata">

### Author: ![Daan\_van\_Vugt](https://discourse.paraview.org/user_avatar/discourse.paraview.org/daan_van_vugt/32/51_2.png) [@Daan\_van\_Vugt](https://discourse.paraview.org/u/Daan_van_Vugt)
#### Post date: [May 14, 2019, 3:08pm UTC](https://discourse.paraview.org/t/ospray-colouring-materials-by-scalar/1846/5 "2019-05-14T15:08:36Z")

</div>

Hi Dave,

This is how I create the dataset (particle positions at many times)

```
# n_p * n_t, 3
pcoords = npvtk.numpy_to_vtk(xyz[:,:,:].reshape(-1,3), deep=True, array_type=vtk.VTK_FLOAT)

self.points = vtk.vtkPoints()
self.points.SetData(pcoords)

# n_p * n_t
q = npvtk.numpy_to_vtk(np.asarray(self.particles.q[0:n_p,:]).ravel(), deep=True, array_type=vtk.VTK_FLOAT)
q.SetName('q')

vtk_points.poly = vtk.vtkPolyData()
vtk_points.poly.SetPoints(self.points)
vtk_points.poly.GetPointData().AddArray(q)
vtk_points.poly.GetPointData().SetActiveScalars('q')

# Set connectivity data per particle
lines = vtk.vtkCellArray()
# See https://vtk.org/Wiki/VTK/Examples/Python/GeometricObjects/Display/PolyLine
for i in range(n_p):
  lines.InsertNextCell(n_t, range(n_t*i, n_t*i+n_t))
vtk_points.poly.SetLines(lines)

vtk_points.lut = vtk_lut.W_lut() #as in first post on discourse

tube = vtk.vtkTubeFilter()
tube.SetInputData(vtk_points.poly)
tube.SetNumberOfSides(6)
tube.SetVaryRadiusToVaryRadiusOff()
tube.SetRadius(0.015)

vtk_points.mapper = vtk.vtkPolyDataMapper()
vtk_points.mapper.SetInputConnection(tube.GetOutputPort())
vtk_points.mapper.ScalarVisibilityOn()
vtk_points.mapper.SetScalarRange(vtk_points.poly.GetPointData().GetArray('q').GetRange())
vtk_points.mapper.SetLookupTable(vtk_points.lut)

vtk_points.actor = vtk.vtkActor() 
vtk_points.actor.SetMapper(vtk_points.mapper)
#vtk_points.actor.GetProperty().SetMaterialName("Value Indexed")
vtk_points.actor.GetProperty().SetMaterialName("OBJMaterial")

vtk_points.colorbar = vtk_color_bar()
vtk_points.colorbar.SetLookupTable(vtk_points.lut)
vtk_points.colorbar.SetTitle('q')
vtk_points.colorbar.SetPosition(0.05, 0.1)

return vtk_points
```

---

_[View the full topic](https://discourse.paraview.org/t/ospray-colouring-materials-by-scalar/1846)._
