[vtkusers] vtkImageData::GetScalarPointer is slow inside the loop?

Dominique Toepfer dominique at toepfer-web.de
Wed Nov 20 08:48:48 EST 2013


Hi Mengda,

yes, doing the computation yourself is faster. An example was given 
here: 
http://vtk.1045678.n5.nabble.com/Fast-element-access-of-vtkImageData-td4640137.html#a4640179

As also was pointed out in this thread another option are image 
iterators. However, I don't know if they are as fast as direct access.

Regards,
Dominique

Am 20.11.2013 05:30, schrieb Mengda Wu:
> Hi all,
>
>    I am trying to use vtkImageData::GetScalarPointer inside the loop 
> through all the voxels in a huge 3D image (512x512x300). But it seems 
> this function is pretty slow. A code sample is like this:
>
>    int* dims = aImage->GetDimensions();
>    int dim[3];
>    for(dim[2] = 0; dim[2] < dims[2]; dim[2]++)
>     {
>         for(dim[1] = 0; dim[1] < dims[1]; dim[1]++)
>         {
>             for(dim[0] = 0; dim[0] < dims[0]; dim[0]++)
>             {
>                 double* curr = 
> static_cast<double*>(aImage->GetScalarPointer(dim));
>                 *currhist = 1.0;
>                 }
>             }
>         }
>     }
>
>    I mean should I just get the pointer of the first vosel and compute 
> the poitner addresses for the rest of voxels myself? Should it be 
> faster? Does vtkImageData store all voxels continuously? What about if 
> I have multiple components per voxel?
>
> Thanks,
> Mengda
>
>
>
> _______________________________________________
> 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://www.vtk.org/pipermail/vtkusers/attachments/20131120/113a9512/attachment.htm>


More information about the vtkusers mailing list