implementation of dynamic point source

Hi,

I would like to create dynamic point source to feed “Stream Tracer with Custom Source” filter. In my case, a centroid of a shape is calculated by “IntegrateVariables” filter and I would like to use this point to define point source using a “Programmable Source” (disk or sphere source). The problem is that I could not reach the points calculated by “IntegrateVariables” to use under “Programmable Source” because they are belong to different data sources. So, it it possible to get those values via Python code inside of “Programmable Source”.

Regards,

–ufuk

Why not use a Programmable Filter instead? The Integrate Variables output can be passed as an input to the filter and then in the Script you can access your input to what you need.

Yes. You are right? So, I implemented following code to create circular source points (z = 0 for all) but it creates only one stream line not many. In my case, I am creating 88 points in given radius and displacement (dx, dy) around centroid point. Do you think that something wrong in the following code?

import math

inp = self.GetInput()
out = vtk.vtkPolyData()

radius = 1.0
dx = 0.1
dy = 0.1

point = inp.GetPoint(0)

newPts = vtk.vtkPoints()
vrt = vtk.vtkCellArray()

for i in xrange(0, int(radius/dx)):
  for j in xrange(0, int(radius/dy)):
     p1 = (point[0], point[1], 0)
     p2 = (point[0]+i*dx, point[1]+j*dy, 0)
     dist = math.sqrt(vtk.vtkMath.Distance2BetweenPoints(p1, p2))
     if (dist <= radius):   
       idx = newPts.InsertNextPoint(p2[0], p2[1], p2[2])
       vrt.InsertNextCell(1)
       vrt.InsertCellPoint(idx)

out.SetPoints(newPts)
out.SetVerts(vrt)

BTW, is there any way to define global variable inside of the Programmable Filter. How can I save information between different time steps?

Don’t create your own output, use the filters. out = self.GetOutput(). I am surpised you’re seeing anything generated as the output of the filter since the output is never passed to the filter’s output.

setattr(self, "foo", val_to_save) and getattr(self, "foo") together with hasattr(self, "foo") can be used to save/restore state.

Thanks for your help. I implemented the output port as you suggest but input data is in vtkUnstructuredGrid and output will be same. The loop indices are fine and working well 1.0/0.1 = 10.0 = int(10.0) = 10 I also fix another minor bug because the previous code was generating only one quarter. Now, I could create full circle. The problem is that I could only see the single point but not all of them. If I change output port to PolyData (and need to add vertices also) and try to write to file using vtkXMLPolyDataWriter i could see the right points when i open the file. So, points are created fine.

import math
import vtk

inp = self.GetInput()
out = self.GetOutput()

radius = 1.0
dx = 0.025
dy = 0.025

point = inp.GetPoint(0)

newPts = vtk.vtkPoints()
 
np = 0
for i in xrange(-int(radius/dx), int(radius/dx)):
  for j in xrange(-int(radius/dy), int(radius/dy)):
     p1 = (point[0], point[1], 0.0)
     p2 = (point[0]+float(i)*dx, point[1]+float(j)*dy, 0.0)
     dist = math.sqrt(vtk.vtkMath.Distance2BetweenPoints(p1, p2))
     if (dist <= radius):   
       idx = newPts.InsertNextPoint(p2[0], p2[1], p2[2])
       np = np+1
       #print np, p2[0], p2[1], p2[2]

out.SetPoints(newPts)

I am not sure but it might be an issue of IntegrateVariables filter. When i add Streamline with Custom Source filter to the pipeline that has 3d vector field and select source as Programmable Filter linked to Integrate Variable then streamline filter tries to get vector field from Programmable Filter but in this case Integrate Variable integrates field and create only one value. I might be wrong but this is what i think. I am not sure source of vector field that will be pass to the streamline filter. Programmable Filter or filter that has 3d vector field (in my case it is Python Calculator to provide voriticty vector)?

Do you have state file to reproduce the issue with a dataset that you can share or from ParaViewData. It’s not clear to me what’s going on.

Yes. It is hard to explain with text. You can find simple data (only one time step) and state file created in PV 5.4.1 (1.2 GB).

I just want to create a streamlines of vorticity field that uses programmable source as a starting point. At the end, I could manage to get some results.

In this case, the centroid is calculated by IntegrateVariable but it might be calculated also spicy or just regular mean. The programmable source is creating create circular source in the bottom of the shape cerated by Contour filter.

When I load and run the pipeline, I am also getting following errors but I could get some results. Do you think that they are related with Programmable source or any bug in 5.4.1.

Thanks for your kindly help,
Regards,

ERROR: In /RS/progs/paraview/5.4.1/src/VTK/Common/ExecutionModel/vtkDemandDrivenPipeline.cxx, line 810
vtkPVDataRepresentationPipeline (0xef191b0): Input for connection index 0 on input port index 0 for algorithm vtknvindex_irregular_volume_representation(0xef1ada0) is of type vtkPolyData, but a vtkUnstructuredGridBase is required.

Warning: In /RS/progs/paraview/5.4.1/src/VTK/Filters/Modeling/vtkRibbonFilter.cxx, line 341
vtkRibbonFilter (0x11e20220): Using alternate bevel vector