Measuring a 3D-model using vtk in Qt

  c++, qt, qvtkwidget, vtk

Im trying to somewhat create a ruler of some sort as seen in this resource which is made to measure models within vtk itself: https://www.weiy.city/2019/08/vtk-measurement-widgets/

My goal is to try and implement that within my Qt application where models can be measured within the QVTKOpenGLWidget. The render window was initialized using the follow:

vtkNew<vtkGenericOpenGLRenderWindow> renderWindow;
    ui->qvtkWidget->SetRenderWindow(renderWindow); 

and the rest was copied from the resource above as everything was already setup in my project with the same names as seen below:

vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor =
            vtkSmartPointer<vtkRenderWindowInteractor>::New();
    renderWindowInteractor->SetRenderWindow(renderWindow);

    vtkSmartPointer<vtkPointHandleRepresentation3D> handle =
            vtkSmartPointer<vtkPointHandleRepresentation3D>::New();
    vtkSmartPointer<vtkDistanceRepresentation3D> rep =
            vtkSmartPointer<vtkDistanceRepresentation3D>::New();
    rep->SetHandleRepresentation(handle);

    vtkSmartPointer<vtkDistanceWidget> widget =
            vtkSmartPointer<vtkDistanceWidget>::New();
    widget->SetInteractor(renderWindowInteractor);
    widget->SetRepresentation(rep);
    widget->SetWidgetStateToManipulate();
    widget->EnabledOn();
    widget->ProcessEventsOn();

    renderer->ResetCamera();
    renderWindow->Render();
    renderWindowInteractor->Initialize();

The problem I am facing with this is that the application loads up fine however I cant interact with the application which makes sense because in the above piece of code I’m somewhat overwriting the interactor so I made the following change:

    vtkSmartPointer<vtkPointHandleRepresentation3D> handle =
            vtkSmartPointer<vtkPointHandleRepresentation3D>::New();
    vtkSmartPointer<vtkDistanceRepresentation3D> rep =
            vtkSmartPointer<vtkDistanceRepresentation3D>::New();
    rep->SetHandleRepresentation(handle);

    vtkSmartPointer<vtkDistanceWidget> widget =
            vtkSmartPointer<vtkDistanceWidget>::New();
    widget->SetInteractor(ui->qvtkWidget->GetInteractor());
    widget->SetRepresentation(rep);
    widget->SetWidgetStateToManipulate();
    widget->EnabledOn();
    widget->ProcessEventsOn();

    renderer->ResetCamera();
    renderWindow->Render();
    ui->qvtkWidget->GetInteractor()->Initialize();

This would let me interact with the model; however, it doesnt add the measurement functionality but I also get a popup saying the following.

QVTKInteractor cannot control the event loop

Which got me really confused. I am doing this all in the MainWindow of my Qt application so this theoretically should work but any suggestions is appreciated.

Source: Windows Questions C++

LEAVE A COMMENT