[vtkusers] Picking specific vtkActor from vtkAssembly in Widget

Fahn, Maurice m.fahn at dkfz-heidelberg.de
Mon Aug 22 09:41:03 EDT 2016


Hello everyone,
I am working on a custom widget. For that purpose I am also creating my own subclass of vtkWidgetRepresentation.
I looked at the implementation of vtkImplicitPlaneRepresentation as a reference. To find out which vtkActor of my widget has been selected, I used the code below. this->Picker is a vtkCellPicker, because that's what is used in the vtkImplicitPlaneRepresentation.cpp. Everything works, but once I detect the vtkAssembly (ToolPaletteAssembly) I don't know how to find the specific vtkActor of that vtkAssembly that has been picked.

I also tried switching the vtkCellPicker to vtkPropPicker, but – in contrast to the working vtkCellPicker version – it didn't yield a successful pick. (And I'm not sure why...).

Any pointers on how to get the specific actor of the assembly would be greatly appreciated.
Kind Regards,
Maurice Fahn

CODE:

customPlaneRepresentation::customPlaneRepresentation()
{
  // [...]
  this->Picker = vtkCellPicker::New();
  this->Picker->SetTolerance(0.005);
  this->Picker->AddPickList(this->OBJPlaneActor)
  this->Picker->AddPickList(this->ToolPaletteAssembly)
  // I also tried adding the actors that have been added to the assembly here as well with no difference regarding the picking
  this->Picker->PickFromListOn();
  // [...]
}

// [...]

int customPlaneRepresentation::ComputeInteractionState(int X, int Y, int vtkNotUsed(modify))
{
  // See if anything has been selected
  vtkAssemblyPath* path = this->GetAssemblyPath(X, Y, 0.0, this->Picker);

  if (path == NULL) // Not picking this widget
  {
    this->SetRepresentationState(customPlaneRepresentation::Outside);
    this->InteractionState = customPlaneRepresentation::Outside;
    return this->InteractionState;
  }

  // Depending on the interaction state (set by the widget) we modify
  // this state based on what is picked.
  if (this->InteractionState == customPlaneRepresentation::Moving)
  {
    vtkProp* prop = path->GetFirstNode()->GetViewProp();
    if (prop == this->OBJPlaneActor)
    {
        this->InteractionState = customPlaneRepresentation::MovingOrigin;
        this->SetRepresentationState(customPlaneRepresentation::MovingOrigin);
    }
    else
    {
      this->InteractionState = customPlaneRepresentation::Outside;
      this->SetRepresentationState(customPlaneRepresentation::Outside);
    }
  }
  else if (this->InteractionState == customPlaneRepresentation::ToolPalette)
  {
    vtkProp* prop = path->GetFirstNode()->GetViewProp();

    // Here it only detects ToolPaletteAssembly, never any of the actors that are part of ToolPaletteAssembly
    std::cout << "Picked: " << prop << std::endl;
    if (prop == this->ToolPaletteAssembly)
    {
      // How do I get the specifc actor of ToolPaletteAssembly that was picked?
    }
    else
    {
      this->InteractionState = customPlaneRepresentation::Outside;
      this->SetRepresentationState(customPlaneRepresentation::Outside);
    }
  }
  else
  {
    this->InteractionState = customPlaneRepresentation::Outside;
  }

  return this->InteractionState;
}


More information about the vtkusers mailing list