[vtkusers] VTK wrapping

Andrew J. Dolgert ajd27 at tc.cornell.edu
Sun Apr 15 14:33:54 EDT 2007


Hi RT,

1) Is it possible to use VTK under VC++ 8.0 in conjunction with windows
form, without wrapping?

You can use VTK in a managed C++ program without writing any wrapper code. The VC++ 8.0 compiler knows how to mix native and managed C++ classes smoothly-enough that they call this ability "IJW" for "it just works." If you want to use VTK from C#, then you really do need wrapper code.

Even if you don't need to do anything special to use VTK with managed C++, you do need to look at examples in the VTK source tree to figure out how to make the VTK window appear in a managed program. It's a little tricky to hook the VTK OpenGL display to a Windows Form. I worked from the samples for MFC in order to figure this out, but it took a fair amount of work, so I recommend you steal it.

2) Is windows form in VC 8.0 works only for managed codes?

"Windows Form" is a marketing name for a part of the .NET libraries that shows windows on the screen for user input. If you want to avoid .NET, then you can either use a Win32 window or MFC, which is a library that sits on top of Win32 windows. Either way, there are examples for this in the VTK source tree.

3) Is any performance leak due to wrapping?

Wrapping a library like VTK means that, for each VTK class, you create a similar class that converts arguments and return values from .NET to native and back. It also looks after the lifetime of the native VTK class. Every call from managed code to native code not only has to do argument conversion but also has to execute thousands of machine instructions just to leave the managed world and return. Each transition takes thousands of cycles. Even IJW pays some of this price.

The good news is that the VTK library does most of its work entirely inside the native code. For instance, you redraw by calling Update(), which is one call that executes every object in the pipeline and draws it all before coming back. That's not a bad performance hit. However, if you use something like dataset.SetPoint(i,value) a million times in a loop, then that will be relatively slow. You just have to see if you do that on initialization or somewhere that matters.

4) Is it limitation for wrapping (e.g. some classes can't be wrapped)?

VTK is designed to be wrapped in lots of languages, so they have devised ways to wrap every class you want to use.

5) does managed code tools (e.g. automatice memory maneger) work for wrapped
code?

When you, or the compiler's IJW, mix managed and native code, automatic memory management works only for managed code. A pointer to a native object, vtkDataSet* ds, will be on the native stack, and you will lose memory if you neglect to free it.

I said before that wrappers perform two main tasks: marshaling of arguments and managing the lifetime of the native class. This second responsibility means that, when using wrapper code, vtkDataSetWrap* ds can be treated as a regular managed pointer. It will take care of making sure that the native object underneath is freed. That's an advantage of using wrapper classes, even in managed C++.

- Drew

-----Original Message-----
From: Rohallah Tavakoli [mailto:rohtav at gmail.com]
Sent: Sun 4/15/2007 1:18 AM
To: Andrew J. Dolgert
Subject: VTK wrapping
 
Dear Andrew

Some question regarding to VTK wrapping for MSVC 8.0

1) Is it possible to use VTK under VC++ 8.0 in conjunction with windows
form, without wrapping?
2) Is windows form in VC 8.0 works only for managed codes?
3) Is any performance leake due to wrapping?
4) Is it limitation for wrapping (e.g. some classes can't be wrapped)?
5) does managed code tools (e.g. automatice memory maneger) work for wrapped
code?

Best Regards, ...   rt.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20070415/e21e8849/attachment.htm>


More information about the vtkusers mailing list