[vtkusers] "reverse lookup" in vtkDataArray

Luke Dodd i.like.bread at gmail.com
Fri Aug 20 12:24:06 EDT 2010


You'd have to keep another array with the reversed mapping (or perhaps
hash map if there are a different number of old ids than new ids) to
lookup in reverse quickly.

A bidirectional map is a nicer way to do this. But of course that's
outside of vtk.

I'd say code it the lazy way and only change it if it actually slows
things down enough to warrant more attention.

On 20 August 2010 14:56, David Doria <daviddoria+vtk at gmail.com> wrote:
> I currently have the "forward mapping" from "new id" to "old id":
> vtkIdTypeArray* originalIds =
> vtkIdTypeArray::SafeDownCast(selected->GetPointData()->GetArray("vtkOriginalPointIds"));
>   for(vtkIdType i = 0; i < originalIds->GetNumberOfTuples(); i++)
>     {
>     std::cout << "Point " << i << " was originally point " <<
> originalIds->GetValue(i) << std::endl;
>     }
> If I want the reverse mapping, i.e. "Which new id corresponds to original id
> X?", is there a better way to do it than a linear search through the array?
>   for(vtkIdType i = 0; i < originalIds->GetNumberOfTuples(); i++)
>     {
>     if(originalIds->GetValue(i) == X)
>       {
>       cout << "current ID corresponding to original ID X is " << i << endl;
>       }
>     }
> This seems horribly inefficient!
> 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
>
>



More information about the vtkusers mailing list