vtkLagrangianParticleTracker python commands

I am trying to understand and implement how the vtkLagrangianParticleTracker (LPT) works. I tried to modify the kitchen example. Basically, replaced the vtkStreamTracer arguments with the LPT arguments. My issue is how the particle data is inputted.

I tried something like this…

paths = vtk.LagrangianParticleTracker()
matida = vtk.vtkLagrangianMatidaIntegrationModel()

The reader comes from the kitchen example and I replaced the line with point. In the code, I am missing particle arguments. I need help with creating a particle with random specifications and inputting this data into the LPT.

Thanks for your help in advance!!

This example is for the stream tracer.

The LPT is a very special filter that let you define your own integration model, are you sure you need it ?

In any case, you will find an example usage here:

Thanks! :slightly_smiling_face: This really helped me in understanding of how to implement LPT. Could you also elaborate on where the particles are spawned? For example, in the test case you provided, the spawn locations for the particles are not specified. Are they being spawned at random?

To elaborate,
If I have a (x,y,z) location, how would I input it to spawn particles at this location?
If I have a line object, how would I make particles spawn along the line?

Ther are specified here:


You need to create a source input or dataset.

Thanks for the quick reply. That clarifies things! Could you help me understand what this part of the code is doing?

Code link


I am trying to better understand the code. I was able to port your test code to python and modify the kitchen example. I will post the codes to both for reference shortly.


With this option to on, the path will be generated, not only the interactions


Set the volumic flow input


Set the number of maximum of steps per paticle to 30 (quite a low number for real life data)


See here: https://vtk.org/doc/nightly/html/classvtkLagrangianParticleTracker.html#a931ba3f4ef4258e95fa1fc521a474478


Actual computation

Hello again,

Sorry for the delayed reply. As I have mentioned, I have been trying to get the kitchen example to work. For some reason, creating a surface and setting it’s component to vtk.vtkLagrangianBasicIntegrationModel.SURFACE_TYPE_BOUNCE is not working as expected. Here’s a part of the code I have written, trying to replicate the test code you provided…

# Create a plane
surfaceBounce = vtk.vtkPlaneSource()
surfaceBounce.SetOrigin(4, 0, 0)
surfaceBounce.SetPoint1(4, 3, 0)
surfaceBounce.SetPoint2(4, 0, 1)
bouncePd = surfaceBounce.GetOutput()

# Plane actor
surfaceMapper = vtk.vtkPolyDataMapper()
surfaceActor = vtk.vtkActor()

# Set the surface tpe to bounce
surfaceTypeBounce = vtk.vtkDoubleArray()
surfaceTypeBounce.FillComponent(0, vtk.vtkLagrangianBasicIntegrationModel.SURFACE_TYPE_BOUNCE)

# Group it to send it to tracker
groupSurface = vtk.vtkMultiBlockDataGroupFilter()

The rest of the code is same as yours! Below is the result I am getting, the blue surface is the one I created. Do you have any debugging steps/ideas I could use to figure out what’s happening? Thanks!

I’d put a breakpoint in the surface interaction code to see what is going on.

I think it’s an issue with using jupyter-notebook. When I ran the same code in PyCharm, it worked fine. I tried running the whole code from a single cell in jupyter-notebook, still did not work. Do you know of any reasons what might cause this issue?

Here’s the result from PyCharm…

I do not see any reasons for this, but I’m not using LPT with python.

Thanks for all the help! I really appreciate it. :+1:

I made a mistake in the code. Forgot to do surfaceBounce.Update(). The code works fine now. Nothing to do with the IDEs. I’ll post links to the code as soon as I am done cleaning it up.

1 Like

I added the test-cases in python here. Hope this will help anyone wanting to do LPT in python

@amaclean : this may be of interest to you

@kal this would make a nice addition to the VTK Examples. You would need to convert it to a Python script, and create a MR. Please see ForDevelopers for instructions and Guidelines for guidelines. I would recommend calling it KitchenLPT and putting it in the Visualization folder where the original Kitchen example is.