我使用 VTK 作为 qvtkwidget 在 QT 中显示 3D 对象。我知道我可以通过修改自己的交互风格来改变它的交互风格。我想分别通过右键单击和左键单击来旋转和移动对象。并尝试在头文件中制作修改后的交互风格类,但在修改后的交互风格中使用其他类中声明的函数存在一些困难。这应该很简单。有人知道吗?
boxWidget.at(boxWidget.count()-1)->SetInput(reader->GetOutput());
boxWidget.at(boxWidget.count()-1)->SetScalingEnabled(0); //turn this on to be able to resize the model
boxWidget.at(boxWidget.count()-1)->SetRotationEnabled(0);
boxWidget.at(boxWidget.count()-1)->SetInteractor(this->ui->qvtkWidget->GetInteractor());
boxWidget.at(boxWidget.count()-1)->GetInteractor()->SetInteractorStyle(MyStyle::New()); /
BoxWidget 是我要应用的对象 'MyStyle' 以下是 MyStyle 类
class MyStyle : public vtkInteractorStyleTrackballCamera , public MainWindow
{
private:
unsigned int NumberOfClicks;
int PreviousPosition[2];
int ResetPixelDistance;
public:
static MyStyle *New();
vtkTypeMacro(MyStyle, vtkInteractorStyleTrackballCamera);
PeterStyle() : NumberOfClicks(0) , ResetPixelDistance(5)
{
this->PreviousPosition[0] = 0;
this->PreviousPosition[1] = 0;
}
virtual void OnLeftButtonDown()
{
qDebug() << "My Style Mouse Left Clicked";
//std::cout << "Pressed left mouse button." << std::endl;
this->NumberOfClicks++;
//std::cout << "NumberOfClicks = " << this->NumberOfClicks << std::endl;
int pickPosition[2];
this->GetInteractor()->GetEventPosition(pickPosition);
int xdist = pickPosition[0] - this->PreviousPosition[0];
int ydist = pickPosition[1] - this->PreviousPosition[1];
this->PreviousPosition[0] = pickPosition[0];
this->PreviousPosition[1] = pickPosition[1];
int moveDistance = (int)sqrt((double)(xdist*xdist + ydist*ydist));
// Reset numClicks - If mouse moved further than resetPixelDistance
if(moveDistance > this->ResetPixelDistance)
{
this->NumberOfClicks = 1;
}
if(this->NumberOfClicks == 2)
{
vtkSmartPointer<vtkCamera> camera =
vtkSmartPointer<vtkCamera>::New();
camera->SetPosition(140.0, 155.0, 590.0);
camera->SetFocalPoint(140.0, 155.0, 0.0);
camera->SetClippingRange(590.0, 600.0);
this->GetCurrentRenderer()->SetActiveCamera(camera);
qDebug() << "Double clicked.";
this->NumberOfClicks = 0;
}
// forward events
vtkInteractorStyleTrackballCamera::OnLeftButtonDown();
}
我不知道用左键单击要更改什么来移动对象。