[vtkusers] Fast element access of vtkImageData?
Dominique Töpfer
dominique at toepfer-web.de
Wed Jul 27 16:22:57 EDT 2011
Hi Joseph,
you could use GetScalarPointer(), which gives you a void * pointer to
the actual image data. After casting it to the pixel type you are using,
you can access the array directly, which should be much faster. To
access a certain point you could use ComputePointID() to get the correct
index.
HTH
Dominique
On 27.07.2011 22:07, Joseph D. Wieber Jr. wrote:
>
> Hello,
>
> Is there a fast way to access (get and set) elements in a vtkImageData
> object? For instance I have two image data object with dimensions
> 512x512x1 that I'm using as part of a cost table (it's convenient) for
> an algorithm. One of them gets the output of a convolution filter and
> I do lookups into it. The other one has to be initialized to all 1.0
> values at the beginning of the algorithm. Then based on information
> from the first one, I set values in the second one. The algorithm is
> a specialized Laplacian zero crossing. I've been using the following
> template to initialize all the values to 1.0:
>
> //-----------------------------------------------------------------------------
>
> //TODO: This is horribly slow. Find a smarter way!
>
> template< typename T >
> void
> fillImageData( ImageDataPtr pImageData, const T& val )
> {
> int dims[ 3 ];
> pImageData->GetDimensions ( dims );
> int& xMax = dims[ 0 ];
> int& yMax = dims[ 1 ];
> int& zMax = dims[ 2 ];
> int numComponents = pImageData->GetNumberOfScalarComponents ();
>
> for( int z = 0; z < zMax; ++z )
> {
> for ( int y = 0; y < yMax; ++y )
> {
> for( int x = 0; x < xMax; ++x )
> {
> for( int c = 0; c < numComponents; ++c )
> {
> pImageData->SetScalarComponentFromFloat ( x, y, z,
> c, val );
> }
> }
> }
> }
> }
>
> To get and set values during the zero crossing computation I've been
> using combinations of GetScalarComponentAsFloat, and
> SetScalarComponentFromFloat and this part is also very slow.
>
> Can someone please point me to an example that accomplishes similar
> tasks in a more efficient manner, or offer a suggestion on where to
> look? Thank you.
>
> Regards,
>
> Joseph
>
> _______________________________________________
> 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