Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How do I create a VTK object from Perl using Inline::Python?

11 views
Skip to first unread message

Jason McVeigh

unread,
May 20, 2016, 1:30:03 PM5/20/16
to inl...@perl.org
How do I create a VTK object from Perl using Inline::Python?

I am using the Visualization Toolkit (http://vtk.org) for 3D visualizations.  I had hoped to use Perl to call the Python bindings for VTK.  I have some example code below, however, I get a segmentation fault due to something wrong.

#!/bin/perl

use strict;
use warnings;

use feature 'say';

package Graphics::VTK {
    use Moose;

    use Inline::Python qw(py_call_function);
    use Inline Python => "import vtk";

    sub main {
        my $self = shift;
        my $o = \py_call_function("vtk","vtkPoints", @_);       
        my $p = [0,0,0];
        bless $o, 'vtk::vtkPoints';
        {
            no strict 'refs';
            push @{ "vtk::vtkPoints::ISA" }, 'Inline::Python::Object';
        }
       
        $o->InsertNextPoint($p);
    }

    __PACKAGE__->meta->make_immutable;
}

Graphics::VTK->new->main unless caller;

1;

Stefan Seifert

unread,
May 20, 2016, 3:15:03 PM5/20/16
to inl...@perl.org, Jason McVeigh
Hi!

On Freitag, 20. Mai 2016 13:16:59 CEST Jason McVeigh wrote:
> How do I create a VTK object from Perl using Inline::Python?
>
> I am using the Visualization Toolkit (http://vtk.org) for 3D visualizations.
> I had hoped to use Perl to call the Python bindings for VTK. I have some
> example code below, however, I get a segmentation fault due to something
> wrong.
>
> my $o = \py_call_function("vtk","vtkPoints", @_);
> my $p = [0,0,0];
> bless $o, 'vtk::vtkPoints';
> {
> no strict 'refs';
> push @{ "vtk::vtkPoints::ISA" }, 'Inline::Python::Object';
> }

This looks like very low level trickery. Have you tried the high level
interface?

use common::sense;
use Inline 'Python';

package Foo::Bar {
use base qw(Foo);
}

say Foo::Bar->new->bar;

__END__
__Python__

class Foo:
def bar(self):
return 1

Regards,
Stefan

Konovalov, Vadim

unread,
May 21, 2016, 2:30:01 PM5/21/16
to Jason McVeigh, inl...@perl.org

> From: Jason McVeigh

>

> How do I create a VTK object from Perl using

> Inline::Python?

>

> I am using the Visualization Toolkit (http://vtk.org) for

> 3D visualizations.  I had hoped to use Perl to call the

> Python bindings for VTK.  I have some example code below,

> however, I get a segmentation fault due to something wrong.

 

I used Tcl from Perl – at moment when vTk had close bindings to Tcl, and even made a talk at our Spb perl conference

 

This provided me with just fine perl OO classes, but this relied on vTk<->tcl binding, which no more supported by vtk.org, (very unfortunately)

 

Can provide more information if this is a possible way for you

 

Regards,

Vadim.

0 new messages