<div dir="ltr"><div><div><div><span style="font-family:monospace,monospace">Dear all,<br><br>I have just tested the new paraview 5.2 with a python script.<br><br></span></div><div><span style="font-family:monospace,monospace">With versions 4.4.0 and 5.1.2, this script worked fine.<br><br></span></div><div><span style="font-family:monospace,monospace">In this script, I have a ProgrammableSource where I compute the maximum values of two scalars with max function.<br></span></div><span style="font-family:monospace,monospace"><br>The code looks like this in the Script of the </span><span style="font-family:monospace,monospace">ProgrammableSource </span></div><div><span style="font-family:monospace,monospace"><br></span></div><span style="font-family:monospace,monospace">maxValue = max(1,2)<br><br></span></div><span style="font-family:monospace,monospace">This
instruction creates an error: instead of using built-in max function,
ParaView5.2 uses a max function defined with vtk and numpy:<br></span><div><span style="font-family:monospace,monospace"><br>ParaView-5.2.0-Qt4-OpenGL2-<wbr>Windows-64bit\bin\Lib\site-<wbr>packages\vtk\numpy_interface\<wbr>algorithms.py line 315<br><br></span></div><div><span style="font-family:monospace,monospace">And apparently, it does not work (whereas in 4.4.0 and 5.1.2 it worked, maybe these versions did not use this function).<br></span></div><span style="font-family:monospace,monospace"></span><div><span style="font-family:monospace,monospace"></span><div><span style="font-family:monospace,monospace"><br>For the time being, I have created a dirty workaround where I have defined new min / max functions<br><br> fmin = lambda x,y:x if x<y else y<br> fmax = lambda x,y:x if x>y else y<br><br><br><br></span></div><div><span style="font-family:monospace,monospace">Below are the message error and a python script that reproduces the bug<br></span></div><br><div><span style="font-family:monospace,monospace"><br>Traceback (most recent call last):<br> File "<string>", line 20, in <module><br> File "<string>", line 326, in RequestData<br> File "D:\ParaView-5.2.0-Qt4-<wbr>OpenGL2-Windows-64bit\bin\lib\<wbr>site-packages\vtk\numpy_<wbr>interface\algorithms.py", line 354, in max<br> return _global_func(MaxImpl(), array, axis, controller)<br> File "D:\ParaView-5.2.0-Qt4-<wbr>OpenGL2-Windows-64bit\bin\lib\<wbr>site-packages\vtk\numpy_<wbr>interface\algorithms.py", line 182, in _global_func<br> res = impl.op()(array, axis)<br> File "D:\ParaView-5.2.0-Qt4-<wbr>OpenGL2-Windows-64bit\bin\lib\<wbr>site-packages\vtk\numpy_<wbr>interface\internal_algorithms.<wbr>py", line 363, in max<br> ans = numpy.max(narray, axis)<br> File "D:\ParaView-5.2.0-Qt4-<wbr>OpenGL2-Windows-64bit\bin\lib\<wbr>site-packages\numpy\core\<wbr>fromnumeric.py", line 2125, in amax<br> out=out, keepdims=keepdims)<br> File "D:\ParaView-5.2.0-Qt4-<wbr>OpenGL2-Windows-64bit\bin\lib\<wbr>site-packages\numpy\core\_<wbr>methods.py", line 17, in _amax<br> out=out, keepdims=keepdims)<br><br><br><br><br></span></div><span style="font-family:monospace,monospace">Test case reproducing the bug:<br><br><br><br>from paraview.simple import *<br>paraview.simple._<wbr>DisableFirstRenderCameraReset(<wbr>)<br>programmableSource1 = ProgrammableSource()<br>programmableSource1.Script = \<br>"""gg=max(5.0,6.0)<br>#This script generates a helix curve.<br>#This is intended as the script of a 'Programmable Source'<br>import math<br> <br>numPts = 80 # Points along Helix<br>length = 8.0 # Length of Helix<br>rounds = 3.0 # Number of times around<br> <br>#Get a vtk.PolyData object for the output<br>pdo = self.GetPolyDataOutput()<br> <br>#This will store the points for the Helix<br>newPts = vtk.vtkPoints()<br>for i in range(0, numPts):<br> #Generate the Points along the Helix<br> x = i*length/numPts<br> y = math.sin(i*rounds*2*math.pi/<wbr>numPts)<br> z = math.cos(i*rounds*2*math.pi/<wbr>numPts)<br> #Insert the Points into the vtkPoints object<br> #The first parameter indicates the reference.<br> #value for the point. Here we add them sequentially.<br> #Note that the first point is at index 0 (not 1).<br> newPts.InsertPoint(i, x,y,z)<br> <br>#Add the points to the vtkPolyData object<br>#Right now the points are not associated with a line - <br>#it is just a set of unconnected points. We need to<br>#create a 'cell' object that ties points together<br>#to make a curve (in this case). This is done below.<br>#A 'cell' is just an object that tells how points are<br>#connected to make a 1D, 2D, or 3D object.<br>pdo.SetPoints(newPts)<br> <br>#Make a vtkPolyLine which holds the info necessary<br>#to create a curve composed of line segments. This<br>#really just hold constructor data that will be passed<br>#to vtkPolyData to add a new line.<br>aPolyLine = vtk.vtkPolyLine()<br> <br>#Indicate the number of points along the line<br>aPolyLine.GetPointIds().<wbr>SetNumberOfIds(numPts)<br>for i in range(0,numPts):<br> #Add the points to the line. The first value indicates<br> #the order of the point on the line. The second value<br> #is a reference to a point in a vtkPoints object. Depends<br> #on the order that Points were added to vtkPoints object.<br> #Note that this will not be associated with actual points<br> #until it is added to a vtkPolyData object which holds a<br> #vtkPoints object.<br> aPolyLine.GetPointIds().SetId(<wbr>i, i)<br> <br>#Allocate the number of 'cells' that will be added. We are just<br>#adding one vtkPolyLine 'cell' to the vtkPolyData object.<br>pdo.Allocate(1, 1)<br> <br>#Add the poly line 'cell' to the vtkPolyData object.<br>pdo.InsertNextCell(aPolyLine.<wbr>GetCellType(), aPolyLine.GetPointIds())<br> <br>#The Helix is ready to plot! Click 'Apply'.<br>"""<br>renderView1 = GetActiveViewOrCreate('<wbr>RenderView')<br>programmableSource1Display = Show(programmableSource1, renderView1)<br>renderView1.ResetCamera()<br>Render()<br><br><br><br></span></div><span style="font-family:monospace,monospace">Guillaume Jacquenot</span></div>