[vtk-developers] [vtkusers] Visual Studio CLR makes VTK really slow ...

Shashwath T.R. trshash at gmail.com
Thu Mar 3 08:31:09 EST 2011


Hi,

I've run into this problem multiple times, and evolved a solution that I use
in general now.

1. Derive from Control, not UserControl. UserControl is meant for things
that combine other controls, while Control is a better place to start for
custom-painted things.
2. In the constructor, ensure that you set these style parameters to the
control:
    this->SetStyle(ControlStyles::AllPaintingInWmPaint, true);
    this->SetStyle(ControlStyles::UserPaint, true);
    this->SetStyle(ControlStyles::UserMouse, true);

You can also set the vtkWindow's parent in the ctor (or OnHandleCreated if
you like).

This should give you complete control over all rendering that goes on inside
the control. .Net will not attempt to do anything during rendering now.

*Override* (instead of listening to events) OnPaint, OnResize and
OnHandleDestroyed. Do nothing in OnPaint, resize your render window in
OnResize, and unparent and delete your render window in OnHandleDestroyed.

This usually gives me better performance...

HTH

Shash

On Fri, Feb 25, 2011 at 3:35 AM, Frederic DANESI <frederic.danesi at dinccs.com
> wrote:

> Thanks for your reply.
> That's exactly what we are doing : vtkPanel is the entry point of our DLL
> (native C++). It is a simple class which receive as input the handle of a
> panel (hence the name), itself attached in a Form.
>
> When using this method with MFC/WinForm, the result are very good. When
> switching to .NET 2008, the results are dropping dramatically ...
>
> I will try with a PictureBox just to be sure...
>
> Fred.
>
>
> 2011/2/24 Joseph Melnyk <JMelnyk at pile.com>
>
>  I’ve done something similar: CLR (by way of C++/CLI) to interface with
>> native C++ vtk, create a DLL from this and link it into a .NET windows
>> form.  Within the DLL, I’m simply assigning the vtk RenderWindows to
>> passed-in .NET PictureBox controls, however.  What is this vtkPanel that you
>> mention?
>>
>>
>>
>> I’m getting frame rates close to what you mention (80-100 fps), but this
>> could simply be my application, machine, etc.  I’ve not tested these various
>> other scenarios to see if it improves/degrades otherwise.
>>
>>
>>
>>
>>
>> *From:* vtkusers-bounces at vtk.org [mailto:vtkusers-bounces at vtk.org] *On
>> Behalf Of *Frederic DANESI
>>
>>
>>
>> We came accross something weird when using Visual Studio CLR.
>>
>>
>>
>> We have created a very simple VTK pipeline (load a STL file => render =>
>> move the camera around while taking screen shots).
>>
>> Those operation are integrated in a vtkPanel, build as a C++ DLL.
>>
>>
>>
>> When using this DLL in a console application (with the VTK default
>> RenderWindow), we get a framerate of 100 fps.
>>
>> When using this DLL in a winform application (Visual Studio 6,MFC, no
>> CLR), we get the same framerate.
>>
>>
>>
>> When using this DLL in a .Net Windows Form (Visual Studio 10, CLR) we get
>> a framerate of 26 fps, which is not acceptable.
>>
>> (Obvisously, if we use directly the VTK classes inside the CLR project
>> without building a library, the framerate is even worse : 6 fps).
>>
>>
>>
>> Does anyone have knowledge about using VTK inside a CLR application
>> without such a loss of performance ? Are we missing something ?
>>
>> __Scanned by MessageLabs
>>
>
>
>
> --
>
>
> Cordialement,
> F.Danesi
> --
> Responsable Développement Informatique et Travail Collaboratif
> Centre Technique DINCCS (Centre Technique Dédié à l’Ingénierie Numérique,
> la Conception Collaborative et la Simulation)
> MICADO / DINCCS
> Pôle de Haute Technologie, BP 90005
> 08005 Charleville-Mézières Cedex
> Tel. : +33 (0) 3.24.41.69.55 / +33 (0) 6.62.76.13.32
> Email : frederic.danesi at dinccs.com
> Web : www.afmicado.com / www.dinccs.com
>
> -----
>
> DISCLAIMER :
> This email and any files transmitted with it are confidential and intended
> solely for the use of the individual or entity to whom they are addressed.
> If you have received this email in error please notify the system manager.
> This message contains confidential information and is intended only for the
> individual named. If you are not the named addressee you should not
> disseminate, distribute or copy this e-mail. Please notify the sender
> immediately by e-mail if you have received this e-mail by mistake and delete
> this e-mail from your system. If you are not the intended recipient you are
> notified that disclosing, copying, distributing or taking any action in
> reliance on the contents of this information is strictly prohibited.
>
>
> _______________________________________________
> 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
>
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtkusers
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtk-developers/attachments/20110303/84587827/attachment.html>


More information about the vtk-developers mailing list