[vtkusers] performance issue

David Gobbi david.gobbi at gmail.com
Wed Feb 23 19:54:48 EST 2011


How much did the time decrease when you switched to the DataSetSurfaceFilter?

The GetScalarComponentAsDouble() is very expensive and it should not
be called in a tight loop.  Honestly, I don't think that I can
emphasize strongly enough how expensive this method is
1) it makes at least two calls to the VTK pipeline
2) it has several "if" checks, as do the methods it calls
3) it has a big switch statement

Whenever you call GetScalarComponentAsDouble(), you are executing
hundreds of lines of C++ code.  Due to the pipeline changes, this
method is even more expensive in VTK 5.x than in VTK 4.x, but it was
expensive then, too.

To speed up your code, you should write a templated method that uses
pointer increments to access the pixels.  Doing everything inside the
loop with pointer arithmetic instead of method calls should speed it
up by two orders of magnitude.

As people have mentioned before, VTK really should have iterators to
make it easier to write efficient pixel access code.  I started
writing some VTK image iterators a couple months ago, maybe I'll try
to finish them after I complete my current project.

 - David



On Wed, Feb 23, 2011 at 4:42 PM, vlibertiaux <vlibertiaux at gmail.com> wrote:
>
> Hi David,
>
> thank you for your answer.  I implemented the code using
> PolyDataToImageStencil and DataSetSurfaceFilter and it dramatically
> decreased the computational time !!!
>
> May I ask you a last question regarding the computational time ?  This piece
> of code (http://codepad.org/hWUHd0Ac) was part of the previous code and I
> didn't modify it.  However, it is also longer to execute compiled against
> vtk5.6 than 4.4.
>
> It basically looks how many times a ray crosses fibers (i.e. scalar = 128 or
> 255).
>
> Could you please tell me what is time consuming in this code according to
> you ? The rest of the code is OK as far as the comput. time is concerned.
>
> Once again, thank you very much for your kind help.
>
> Best regards,
>
> Vincent
>
> --
> View this message in context: http://vtk.1045678.n5.nabble.com/performance-issue-tp3397693p3397891.html
> Sent from the VTK - Users mailing list archive at Nabble.com.
> _______________________________________________
> 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
>



More information about the vtkusers mailing list