[vtkusers] Dealing with QTBUG-40889

David Gobbi david.gobbi at gmail.com
Sat Jul 2 08:03:17 EDT 2016


On Sat, Jul 2, 2016 at 4:12 AM, Elvis Stansvik <elvis.stansvik at orexplore.com
> wrote:

>
>> However, since VTK no longer renders for every input event, I have to be
>> careful when I use the VTK picker.  I wrote a method called
>> UpdatePropsForPick() that I call for every input event, and it ensures that
>> the picking works correctly regardless of whether the Render()s are
>> actually happening.
>>
>
> Ah, this is good advice. Would you mind sharing how it ensures this? Not
> necessarily in code, but just in a few words? I'm quite new to VTK and
> haven't done any picking yet.
>

Here's the code.  It is only for pickers derived from vtkPicker (I use it
with vtkCellPicker).  Pickers derived from vtkPicker work by interrogating
the data, i.e. they don't use OpenGL for the picking.  Perhaps I should
contribute this to VTK as a vtkPicker method.

void UpdatePropsForPick(vtkPicker *picker, vtkRenderer *renderer)
{
  // Go through all Prop3Ds that might be picked and update their data.
  // This is necessary if any data has changed since the last render.
  vtkPropCollection *props;
  if (picker->GetPickFromList()) {
    props = picker->GetPickList();
  }
  else {
    props = renderer->GetViewProps();
  }

  vtkProp *prop;
  vtkCollectionSimpleIterator pit;
  props->InitTraversal(pit);
  while ((prop = props->GetNextProp(pit)) != 0) {
    if (!prop->GetPickable() || !prop->GetVisibility()) {
      continue;
    }
    vtkAssemblyPath *path;
    prop->InitPathTraversal();
    while ((path = prop->GetNextPath()) != 0) {
      vtkProp *anyProp = path->GetLastNode()->GetViewProp();

      vtkActor *actor;
      vtkVolume *volume;
      vtkImageSlice *imageActor;

      if ((actor = vtkActor::SafeDownCast(anyProp)) != 0) {
        actor->GetMapper()->Update();
      }
      else if ((volume = vtkVolume::SafeDownCast(anyProp)) != 0) {
        volume->GetMapper()->Update();
      }
      else if ((imageActor = vtkImageSlice::SafeDownCast(anyProp)) != 0) {
        imageActor->GetMapper()->Update();
      }
    }
  }
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20160702/d8a9509c/attachment.html>


More information about the vtkusers mailing list