[vtkusers] Cython

Berk Geveci berk.geveci at kitware.com
Mon Jan 18 14:06:47 EST 2016


I am assuming that there is a way of passing numpy arrays from regular
Python to Cython compiled code? If there is, you can always get access to
VTK pointers as numpy arrays through the numpy interface. This would look
like this:

In (C) Python:

Get VTK object
Get various data structures (arrays, cell arrays etc.) as numpy arrays
Call Cython code

In Cython

Do some processing
Generate new arrays
Return as numpy arrays to (C) Python

In (C) Python

Stick numpy arrays back into VTK data structures such as arrays, cell
arrays etc.

Best,
-berk


On Mon, Jan 18, 2016 at 2:02 PM, Nil Goyette <nil.goyette at imeka.ca> wrote:

> 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> <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
>
>
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the VTK FAQ at:
> http://www.vtk.org/Wiki/VTK_FAQ
>
> Search the list archives at: http://markmail.org/search/?q=vtkusers
>
> Follow this link to subscribe/unsubscribe:
> http://public.kitware.com/mailman/listinfo/vtkusers
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20160118/3f04b168/attachment.html>


More information about the vtkusers mailing list