[vtkusers] Cython

Nil Goyette nil.goyette at imeka.ca
Mon Jan 18 14:02:35 EST 2016


Hi Cory,

Thank you for the answer. Yes, I know that vtk is coded in C++ and that 
python-vtk is only a binding. I thought that maybe there was a way to 
avoid some of the expensive calls. For example, I have this loop in a 
cython file:

# streamline is a ndarray of 3d points
for i in range(nb_points):
     point_3d = streamline[i]
     vtk_points.InsertNextPoint(point_3d)

I know that InsertNextPoint is as fast as it can be, but the call itself 
is expensive. As you said, there's probably nothing to be done here 
using cython.

Which bring me to another question! As I said above, I have a 2D ndarray 
(list of 3d points) that I need to put in a vtkPoints object. I think 
it's a waste of time to copy the data in a loop because both vtk and 
numpy represent their data the same way and should be able to read the 
data of the other library.

I found the "VTK - numpy integration" posts this morning 
http://www.kitware.com/blog/home/post/709 and I thought that maybe there 
a way to create a vtkPoints from a numpy array without a loop. I 
couldn't find how to do it though. It seems we can only create 
vtkDataSets and put them in bbtk objects. Do you know if what I want to 
do is possible?

Nil

Le 2016-01-16 07:59, Cory Quammen a écrit :
> Nil,
>
> VTK is C++ library that provides Python language bindings, so all the
> VTK parts you call in your Python code are invoking compiled C++
> functions. There is no need to cythonize them.
>
> Cory
>
> On Fri, Jan 15, 2016 at 11:30 AM, Nil Goyette<nil.goyette at imeka.ca>  wrote:
>> Hi all,
>>
>> I tried making a part of my pytthon code faster and vtk is the only part
>> which I can't change anything. In fact, I can't find any information on
>> cythonizing vtk. Maybe because one should use C++ if he wants a fast version
>> :) or maybe because there's simply not much information on the subject.
>>
>> Is there some specific advices to vtk? Where to find the cdef?
>> Or it's simply the general advices like: get a pointer to the data asap to
>> be in C mode, then cdef everything?
>>
>> Nil
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20160118/c30f155b/attachment.html>


More information about the vtkusers mailing list