[vtkusers] Fast element access of vtkImageData?
Joseph D. Wieber Jr.
jdwieber at gmail.com
Wed Jul 27 16:07:18 EDT 2011
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
More information about the vtkusers
mailing list