[vtkusers] quadratic comparison of points in a polyData mesh, a faster way?

David Doria daviddoria+vtk at gmail.com
Mon Feb 1 16:18:18 EST 2010


On Mon, Feb 1, 2010 at 4:07 PM, David Gobbi <david.gobbi at gmail.com> wrote:

> Hi Ryven,
>
> The GetPoint() method involves a virtual method call, since it needs
> some way to resolve whether the underlying data is double or float.
> You can increase the efficiency by calling points->GetData() in order
> to get the underlying data array:
>
> vtkDoubleArray *doubleArray =
> vtkDoubleArray::SafeDownCast(points->GetData());
> vtkFloatArray *floatArray = vtkFloatArray::SafeDownCast(points->GetData());
>
> if (doubleArray != NULL)
>  {
>  // write a loop that uses doubleArray->GetTupleValue() to get each point
>  }
> else if (floatArray != NULL)
>  {
>  // write a loop that uses floatArray->GetTupleValue() to get each point
>  }
>
> By doing this, you will be calling the inline method "GetTupleValue()"
> instead of the virtual method "GetPoint()".  You can go even further
> by calling GetPointer() on the array to get a pointer to the
> underlying floats or doubles, but that probably won't be any more
> efficient that the inline GetTupleValue() methods.
>
>   David
>
>
>
>
>
Ryven,

When you try this, can you report the resulting speed increase? Maybe you
could setup a little experiment where all you do is read the data and
iterate through all the points and let us know the timing of each?

Thanks,

David
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20100201/5167be08/attachment.htm>


More information about the vtkusers mailing list