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

Wes Turner wes.turner at kitware.com
Mon Feb 1 17:28:15 EST 2010


Ryven,

Are you looping through each point and doing an exhaustive search through
the remaining points for equality?  If so, you might want to try one of the
locators.  vtkPointLocator for example.  They use a spatial decomposition to
limit the number of points that must be tested to find the closest point.

http://www.vtk.org/doc/nightly/html/classvtkPointLocator.html

<http://www.vtk.org/doc/nightly/html/classvtkPointLocator.html>- Wes

On Mon, Feb 1, 2010 at 4:18 PM, David Doria
<daviddoria+vtk at gmail.com<daviddoria%2Bvtk at gmail.com>
> wrote:

> 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
>
> _______________________________________________
> 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
>
>


-- 
Wesley D. Turner, Ph.D.
Kitware, Inc.
Technical Leader
28 Corporate Drive
Clifton Park, NY 12065-8662
Phone: 518-881-4920
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20100201/25740881/attachment.htm>


More information about the vtkusers mailing list