[vtkusers] Questions on wrapping a C++ library for use in VTK Scripting (eg. TCL)

KenLists ken-lists at nycap.rr.com
Thu Oct 24 13:38:52 EDT 2002


> I have a C++ class library (already using some VTK objects like
> "vtkImageData" in its interface) that I want to make usable from
> within VTK/TCL or VTK/Python etc. scripts. This library however
> uses standard C++ exceptions for error reporting to its users and
> things like std::string to pass strings in and out.
> There is a hierarchy of C++ classes that could be thrown in the
> case of some error condition.
> 
> I probably have to write a small C++ class derived from
> "vtkObject" that internally uses the C++ class library and
> translate the interface of the C++ class library to a simpler
> form that the VTK Wrapper generator can understand but before
> starting to write this class, I wanted to ask you some questions:
> 
> 1. Is there a way of automatically wrapping C++ exceptions to the
>    corresponding exception mechanisms of TCL / JAVA /Python etc. ?
>    If there is no such thing (I guess there is nothing like that
>    by now) what would be the best way to provide sophisticated error
>    handling facilities to the script writers ?
> 
> 
> 2. Is there support for automatically wrapping "std::string" or
>    "std::vector" arguments in C++ class-methods ?
 
Not with the VTK wrappers. There is a new wrapper called cable
http://public.kitware.com/Cable/HTML/Index.html that I believe can
handle this and most other C++ features.

> 3. Has someone ever used SWIG together with VTK and some scripting
>    language (because it seams to support some of the features
>    I am asking about) ?

This usually gets tried or mentioned once a year or so and last I knew
it didn't really work. But I haven't checked up on it in the last year
so, feel free to give it a shot.

> 4. Is it possible to pass out multiple strings to the scripting
>    languages with just one call similar to the following C++ code:
> 
>    void passOutTwoStrings(std::string& string1, std::string& string2)
>    {
>      string1 = std::string( "one" );
>      string2 = std::string( "two" );
>    }

Not with the VTK wrappers. With Cable I believe you can do this.
 
> 4. I was playing with the wrapper generator and it seamed that it
>    considers the use of the C/C++ keyword "volatile" as a syntax
>    error. Is there a reason for this behaviour ? I just used
>    the keyword for a private attribute of a class.

That is just a goober (technical term) and the VTK wrappers could be
fairly easily modified to handle this if necessary.

Thanks
Ken






More information about the vtkusers mailing list