Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VTK 9: the pick marker is not positioned on the picked location, instead it is now placed in a plane orthogonal to the camera. #273

Open
PauloCarvalhoRJ opened this issue Mar 15, 2022 · 7 comments
Labels
defect Nuisance or problem with an workaround. Issue in dependency Problem is caused by bug or defect in a external library or program GammaRay uses to work.

Comments

@PauloCarvalhoRJ
Copy link
Owner

This defect was introduced by VTK 9.

@PauloCarvalhoRJ PauloCarvalhoRJ added OPEN This issue is currently unattended (e.g. without an associated code branch). defect Nuisance or problem with an workaround. labels Mar 15, 2022
@PauloCarvalhoRJ
Copy link
Owner Author

@PauloCarvalhoRJ PauloCarvalhoRJ removed the OPEN This issue is currently unattended (e.g. without an associated code branch). label Mar 15, 2022
@PauloCarvalhoRJ
Copy link
Owner Author

Also an issue opened in VTK upstream: https://gitlab.kitware.com/vtk/vtk/-/issues/18503 .

@PauloCarvalhoRJ PauloCarvalhoRJ added the Issue in dependency Problem is caused by bug or defect in a external library or program GammaRay uses to work. label Apr 2, 2022
@PauloCarvalhoRJ
Copy link
Owner Author

Prepare a minimum example reproducing the issue and post it to the forums above. Suggestion: use the working pick example as a starting point: https://kitware.github.io/vtk-examples/site/Cxx/Picking/CellPicking/ (it even reports the world coordinates).

@PauloCarvalhoRJ
Copy link
Owner Author

Rewriting VTK's vtkRenderer::GetZ(int x, int y) solves the issue:

// Given a pixel location, return the Z value
double vtkRenderer::GetZ(int x, int y)
{
  double z;

  // use a hardware selector beacuse calling this->RenderWindow->GetZbufferData(int,int,int,int) directly
  // from here always results in a z-buffer value of 1.0, meaning it is using a cleared depth buffer.
  {
      vtkNew<vtkHardwareSelector> hsel;
      hsel->SetActorPassOnly(true);
      hsel->SetCaptureZValues(true);
      hsel->SetRenderer(this);
      hsel->SetArea(x, y, x, y);
      vtkSmartPointer<vtkSelection> sel;
      sel.TakeReference(hsel->Select());

      // find the closest z-buffer value
      if (sel && sel->GetNode(0))
      {
        vtkProp* closestProp = nullptr;
        double closestDepth = 1.0;
        unsigned int numPicked = sel->GetNumberOfNodes();
        for (unsigned int pIdx = 0; pIdx < numPicked; pIdx++)
        {
          vtkSelectionNode* selnode = sel->GetNode(pIdx);
          double adepth = selnode->GetProperties()->Get(vtkSelectionNode::ZBUFFER_VALUE());
          if (adepth < closestDepth)
            closestDepth = adepth;
        }
        z = closestDepth;
      }
  }

  return z;
}

Calling vtkRenderWindow::GetZbufferData(int,int,int,int) in that context always results in Z-buffer values of 1.0, meaning the depth buffer is reset in that context.

@PauloCarvalhoRJ
Copy link
Owner Author

Merge request to fix issue in VTK source code: https://gitlab.kitware.com/vtk/vtk/-/merge_requests/9125

@PauloCarvalhoRJ
Copy link
Owner Author

GammaRay branch to generate the figures that appear in the discussion threads: https://github.com/PauloCarvalhoRJ/gammaray/tree/DebugVTK9PickingIssue .

@PauloCarvalhoRJ
Copy link
Owner Author

It seems the problem maybe related to whether the VTK rendering window has two or more renderers: https://discourse.vtk.org/t/vtkproppicker-in-vtk-9-1-is-now-returning-wrong-world-coordinates/8061/41?u=paulo_carvalho

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
defect Nuisance or problem with an workaround. Issue in dependency Problem is caused by bug or defect in a external library or program GammaRay uses to work.
Projects
None yet
Development

No branches or pull requests

1 participant