#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include namespace { struct MyVtkItem : QQuickVTKItem { struct Data : vtkObject { static Data* New(); vtkTypeMacro(Data, vtkObject); vtkNew boxWidget; }; struct Callback : vtkCommand { static Callback* New(); void Execute(vtkObject* caller, unsigned long, void*) override { vtkNew t; auto widget = reinterpret_cast(caller); widget->GetTransform(t); widget->GetProp3D()->SetUserTransform(t); } }; vtkUserData initializeVTK(vtkRenderWindow* renderWindow) override { // Create our vtk user data vtkNew vtk; // Create a cone pipeline and add it to the view vtkNew cone; cone->SetHeight(3.0); cone->SetRadius(1.0); cone->SetResolution(10); vtkNew mapper; mapper->SetInputConnection(cone->GetOutputPort()); vtkNew colors; vtkNew actor; actor->SetMapper(mapper); actor->GetProperty()->SetColor(colors->GetColor3d("Bisque").GetData()); vtkNew renderer; renderer->AddActor(actor); renderer->ResetCamera(); renderer->SetBackground(colors->GetColor3d("LightBlue").GetData()); renderWindow->AddRenderer(renderer); renderWindow->SetMultiSamples(16); vtk->boxWidget->SetInteractor(renderWindow->GetInteractor()); vtk->boxWidget->SetPlaceFactor(1.25); vtk->boxWidget->GetOutlineProperty()->SetColor(colors->GetColor3d("Gold").GetData()); vtk->boxWidget->SetProp3D(actor); vtk->boxWidget->PlaceWidget(); vtk->boxWidget->On(); vtkNew callback; vtk->boxWidget->AddObserver(vtkCommand::InteractionEvent, callback); return vtk; } }; vtkStandardNewMacro(MyVtkItem::Data); vtkStandardNewMacro(MyVtkItem::Callback); } int main(int argc, char* argv[]) { QQuickVTKItem::setGraphicsApi(); #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling); #endif QGuiApplication app(argc, argv); qmlRegisterType("com.vtk.example", 1, 0, "MyVtkItem"); QQmlApplicationEngine engine; engine.load(QUrl(QStringLiteral("qrc:/main.qml"))); if (engine.rootObjects().isEmpty()) return -1; return app.exec(); }