[vtkusers] In vtkCellPicker assertion from GetCellType fails

Jaspar Löchte jstach at uni-osnabrueck.de
Mon Sep 17 16:16:12 EDT 2018

Hello there!

I use VTK 6.3 in a project for my thesis in an Qt desktop application.

I am storing Pointclouds and do some manipulation, calculating hulls, etc.
For the hulls I display some vtkLines in an extra vtkActor and wanted to create a possiblity to modify the polygon.

Therfore i want to be able to move points AND want to pick lines and create a new Point on the line to be able to move that one to.

So I wanted to use the vtkCellPicker to pick the lines (which works quite well so far …).

Since I needed a ContextMenu in Qt I manipulated the MouseEvents and use them allready in the Qt MainWindow. Like this: https://www.vtk.org/Wiki/VTK/Examples/Cxx/Qt/EventQtSlotConnect <https://www.vtk.org/Wiki/VTK/Examples/Cxx/Qt/EventQtSlotConnect>

In my Code I want to detect a vtkLine with this vtkCellPicker, like this:

m_picker->Pick(x, y, 0, m_mainStyle->GetDefaultRenderer());
long l = m_cicker->GetCellId();
if(l > 0)
  vtkSmartPointer<vtkActor> actor = m_picker->GetActor();
  long O = actor->GetMapper()->GetInput()->GetCellType(l);

  if(O == 3)
    vtkSmartPointer<vtkLine> line = vtkLine::SafeDownCast(actor->GetMapper()->GetInput()->GetCell(l));
    vtkSmartPointer<vtkPoints> points = line->GetPoints();
    double p[3];
    if(points->GetNumberOfPoints() > 0)
      for(int i = 0; i < points->GetNumberOfPoints(); i++)
        points->GetPoint(i, p);
        std::cout << "(" << p[0] << ", " << p[1] << ", " << p[2] << ")" << std::endl;

As I said … this works pretty well, except for any random points, the CellPicker also picks vertices from the Pointcloud (CellType == 1) and on random points my program crashes, because of an assertion fail …

I found out that the call to vtkCellPicker::Pick() calls superclass vtkPicker::Pick() and there is a call to IntersectWithLine() from the CellPicker, in this function the call to IntersectActorWithLine() calls in line 414 this one int cellType = data->GetCellType(cellId); … and here I get the assertion fail:

viewer: /build/vtk6-YpT4yb/vtk6-6.2.0+dfsg1/Common/Core/vtkDataArrayTemplate.h:191: T vtkDataArrayTemplate<T>::GetValue(vtkIdType) [with T = unsigned char; vtkIdType = long long int]: Assertion `id >= 0 && id < this->Size' failed.

Refered to https://github.com/Kitware/VTK/blob/release-6.3/Rendering/Core/vtkCellPicker.cxx#L414 <https://github.com/Kitware/VTK/blob/release-6.3/Rendering/Core/vtkCellPicker.cxx#L414>

I really don’t know how to debug this, and why this happens.

Any Ideas for me?

If there is anything not clear - ask me, I can try to go more into detail, give more Code, or something like that.

Thank you!

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://public.kitware.com/pipermail/vtkusers/attachments/20180917/ce30f05f/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 874 bytes
Desc: Message signed with OpenPGP
URL: <https://public.kitware.com/pipermail/vtkusers/attachments/20180917/ce30f05f/attachment.sig>

More information about the vtkusers mailing list