VS QT VTK 左下角显示同步小坐标轴
主要参考
https://blog.csdn.net/qq_37996632/article/details/106415402
https://kitware.github.io/vtk-examples/site/Cxx/Qt/BorderWidgetQt
主要代码
#include "BorderWidgetQt.h"
#include <vtkBorderWidget.h>
#include <vtkCommand.h>
#include <vtkGenericOpenGLRenderWindow.h>
#include <vtkNamedColors.h>
#include <vtkNew.h>
#include <vtkPolyDataMapper.h>
#include <vtkProperty.h>
#include <vtkRenderWindow.h>
#include <vtkRenderer.h>
#include <vtkSphereSource.h>
#include <vtkVersion.h>
#include <vtkAxesActor.h>
#include <vtkCamera.h>
class BorderCallback : public vtkCommand
{
public:
BorderCallback()
{
}
static BorderCallback* New()
{
return new BorderCallback;
}
virtual void Execute(vtkObject* vtkNotUsed(caller), unsigned long, void*)
{
// vtkBorderWidget *borderWidget =
// reinterpret_cast<vtkBorderWidget*>(caller);
}
};
// Constructor
BorderWidgetQt::BorderWidgetQt(QWidget* parent)
: QMainWindow(parent)
{
this->resize(600, 400);
this->vtkWidget = new QVTKOpenGLNativeWidget(this);
this->setCentralWidget(vtkWidget);
vtkNew<vtkNamedColors> colors;
// Sphere
vtkNew<vtkSphereSource> sphereSource;
sphereSource->Update();
vtkNew<vtkPolyDataMapper> sphereMapper;
sphereMapper->SetInputConnection(sphereSource->GetOutputPort());
vtkNew<vtkActor> sphereActor;
sphereActor->SetMapper(sphereMapper);
sphereActor->GetProperty()->SetColor(colors->GetColor4d("Tomato").GetData());
// VTK Renderer
vtkNew<vtkRenderer> renderer;
renderer->AddActor(sphereActor);
renderer->SetBackground(colors->GetColor3d("SteelBlue").GetData());
// 相机拉远
renderer->ResetCamera();
renderer->GetActiveCamera()->Zoom(1.5);
// Connect VTK with Qt
this->vtkWidget->renderWindow()->AddRenderer(renderer);
// Add a border widget to the renderer
//vtkNew<vtkBorderWidget> bw;
//this->BorderWidget = bw;
//this->BorderWidget->SetInteractor(this->vtkWidget->interactor());
//this->BorderWidget->On();
vtkSmartPointer<vtkAxesActor> axes_actor = vtkSmartPointer<vtkAxesActor>::New();
axes_actor->SetPosition(0, 0, 0);
axes_actor->SetTotalLength(2, 2, 2);
axes_actor->SetShaftType(0);
axes_actor->SetCylinderRadius(0.02);
vtkSmartPointer<vtkOrientationMarkerWidget> widget =
vtkSmartPointer<vtkOrientationMarkerWidget>::New();;
this->BorderWidget = widget;
widget->SetOrientationMarker(axes_actor);
widget->SetInteractor(this->vtkWidget->interactor());
widget->SetEnabled(1);
widget->InteractiveOn();
}