0
votes

can someone help me with this?

pts.InsertPoint(fl[i+1][j+1][k+1], xx[0][i+1], yy[0][j+1], zz[0][k+1])
TypeError: InsertPoint argument 1: integer argument expected, got float

fl is supposed to have float, I have the array from real world experiment, I can't change the values to int.

Is this an issue related to InsertPoint, is it only taking int? Can someone help me fix it?

Also, I don't have experience in Python, never wrote a program, this is the first program I am working with, I made changes to an old program to get it work for my purposes, but can't figure out what I did wrong

Thanks :)

3

3 Answers

0
votes

If you look at the documentation of vtkpoints::InsertPoint you will see that the expected arguments are (id,x,y,z). You use this method when you have to want to set the value of the point at position id (that's why it must be an integer). http://www.vtk.org/doc/nightly/html/classvtkPoints.html#ab7f990c73fb291737abe4203994ce2a2

from the python shell, you can also check help(pts.InsertPoint) - but since these are wrapped objects sometimes the help appears a bit obscure.

The method InsertNextPoint, instead, just requires x,y,z and can be used as you are doing. It doesn't require an explicit id because it will just your point at the end

Specifically for python , you could be interested also in vtk.util.numpy_support which makes conversions between numpy and vtk elements easier (you can convert your points from numpy to a vtkdoublearray, then assign it to a vtkpoints with the method setdata )

0
votes

The problem is not whether or not fl is composed of floats. The problem is that the method signature for InsertPoint expects each value to be an int.

From the python documentation:

exception TypeError:

Raised when an operation or function is applied to an object of inappropriate type. The associated value is a string giving details about the type mismatch.

This information is clearly available in the error message you pasted - it has both the exception type (TypeError) and the object by which it was thrown (InsertPoint). Had you accidentally included a float in your array indexers, the exception would have been thrown by something other than InsertPoint.

In the future, you should do some research on Google based on your exception error. I'm not telling you anything you couldn't find there.

If you still want to use InsertPoints, you have two options:

  1. You can use the (int) cast to truncate edit: the first of your arguments to the whole, integer value (1.2 truncates to 1, 2.67 to 2, etc.), like so:

    int(fl[i+1][j+1][k+1])

  2. You can do #1, but round the value to the nearest integer value, like below (keep in mind that you'll need to import Math):

    int(Math.Round(fl[i+1][j+1][k+1]))

-1
votes

Try wrapping each or your values in int(), like so:

pts.InsertPoint(int(fl[i+1][j+1][k+1]), int(xx[0][i+1]), int(yy[0][j+1]), int(zz[0][k+1]))