[vtkusers] How to get the IDs of min and max from a GetRange() ?

Utkarsh Ayachit utkarsh.ayachit at kitware.com
Wed Jul 8 09:41:37 EDT 2015


Note that LookupValue uses internal data structures to speed repeated
queries (at the cost of more memory). If basically does a binary search in
a sorted array using std::lower_bound()[1] after sorting the array on first
call.

[1] http://www.sgi.com/tech/stl/lower_bound.html

On Wed, Jul 8, 2015 at 8:08 AM Cory Quammen <cory.quammen at kitware.com>
wrote:

> Very nice, Jean.
>
> On Wed, Jul 8, 2015 at 4:21 AM, Favre Jean <jfavre at cscs.ch> wrote:
>
>>  my preference goes towards using numpy for this type to query
>>
>> use the where() function.
>>
>> # example 1:
>>
>> import vtk
>> from vtk.numpy_interface import dataset_adapter as dsa
>>
>> # assuming your mesh data is in the object 'vtkgrid'
>> np_grid = dsa.WrapDataObject(vtkgrid)
>>
>> # assuming your scalar variable is called 'scalars'
>> np_scalars = np_grid.PointData['scalars']
>>
>> # min and max are:
>> print np.min(np_scalars), np.max(np_scalars)
>>
>> #Their position(s) in the array is(are):
>> np.where(np_scalars == np.max(np_scalars))
>> np.where(np_scalars == np.min(np_scalars))
>>
>> # example 2:
>>
>> a = np.array([0, 0, 1, 2, 8, 9, 10, 9, 0, 0, 0, 9, 10, 9, 8, 6, 4, 3, 0,
>> 0])
>>
>> In [51]: np.where(a == a.min())
>> Out[51]: (array([ 0,  1,  8,  9, 10, 18, 19]),)
>>
>> In [52]: np.where(a == a.max())
>> Out[52]: (array([ 6, 12]),)
>>
>> References:
>>
>> http://kitware.com/blog/home/post/714
>>
>>  -----------------
>> Jean
>> CSCS
>>
>
>
>
> --
> Cory Quammen
> R&D Engineer
> Kitware, Inc.
>  _______________________________________________
> 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
>
> Search the list archives at: http://markmail.org/search/?q=vtkusers
>
> Follow this link to subscribe/unsubscribe:
> http://public.kitware.com/mailman/listinfo/vtkusers
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20150708/b62183d4/attachment.html>


More information about the vtkusers mailing list