[Paraview] pvpython rendering

Berk Geveci berk.geveci at gmail.com
Mon Apr 10 17:27:49 EDT 2006


pvpython was not designed to be run interactively so it does not
support 3d interaction well. That part is taken care of by the GUI
code. To get this working you have to run your own event loop (for
example, using tkinter or pyqt) and pass the event to the server
manager. For example, from vtkPVWindow.cxx:

//-----------------------------------------------------------------------------
void vtkPVWindow::MouseAction(int action,int button,
                              int x,int y, int shift,int control)
{
  if ( !this->MainView->GetEnabled() || !this->Interactor )
    {
    return;
    }
  if ( action == 0 )
    {
    if (button == 1)
      {
      this->Interactor->OnLeftPress(x, y, control, shift);
      }
    else if (button == 2)
      {
      this->Interactor->OnMiddlePress(x, y, control, shift);
      }
    else if (button == 3)
      {
      this->Interactor->OnRightPress(x, y, control, shift);
      }
    }
  else if ( action == 1 )
    {
    if (button == 1)
      {
      this->Interactor->OnLeftRelease(x, y, control, shift);
      }
    else if (button == 2)
      {
      this->Interactor->OnMiddleRelease(x, y, control, shift);
      }
    else if (button == 3)
      {
      this->Interactor->OnRightRelease(x, y, control, shift);
      }
    vtkCamera* cam = this->MainView->GetRenderer()->GetActiveCamera();
    //float* parallelScale = cam->GetParallelScale();
    double* position      = cam->GetPosition();
    double* focalPoint    = cam->GetFocalPoint();
    double* viewUp        = cam->GetViewUp();

    this->GetTraceHelper()->AddEntry(
      "$kw(%s) SetCameraState "
      "%.3lf %.3lf %.3lf  %.3lf %.3lf %.3lf  %.3lf %.3lf %.3lf",
      this->MainView->GetTclName(),
      position[0], position[1], position[2],
      focalPoint[0], focalPoint[1], focalPoint[2],
      viewUp[0], viewUp[1], viewUp[2]);
    }
  else
    {
    this->Interactor->OnMove(x, y);
    }
}

//-----------------------------------------------------------------------------
void vtkPVWindow::KeyAction(char keyCode, int x, int y)
{
  if ( !this->MainView->GetEnabled()  )
    {
    return;
    }
  this->Interactor->OnKeyPress(keyCode, x, y);
}

//-----------------------------------------------------------------------------
void vtkPVWindow::Configure(int vtkNotUsed(width), int vtkNotUsed(height))
{
  if (!this->MainView)
    {
    return;
    }
  this->MainView->Configured();
  // The above Configured call could have changed the size of the render
  // window, so get the size from there instead of using the input width and
  // height.
  int *size = this->MainView->GetRenderWindowSize();
  if (this->Interactor)
    {
    this->Interactor->UpdateSize(size[0], size[1]);
    this->Interactor->ConfigureEvent();
    }
}

Also, you have to give the interactor an instance of
vtkPVRenderViewProxy. This requires subclassing (vtkPVRenderViewProxy
is abstract) and implement the pure virtual methods.

I am sorry for the lack of documentation. The paraview guide has a
section on the server manager that is useful to get started. Beyond
that, you have to read the code and it's documentation from doxygen.
We will write a more comprehensive guide in the future.

-Berk


On 4/10/06, Milan Frank <milan.frank at gmail.com> wrote:
> Hi Berk,
>
> I tried the "GetInteractor" method already. The resulting object is an
> instance of "vtkPVGenericRenderWindowInteractor". It is a bit strange
> because it is a subclass of "vtkRenderWindowInteractor" but it do not
> implement the "Start" method.
>
> I'll be happy if you could send me any code using the "pvpython"
> interface. It is not easy to learn how to use this interface ...
>
> Thanks in advance,
> Milan.
>


More information about the ParaView mailing list