I am using VTK as qvtkwidget to display 3D objects in QT. I know I can change its interaction style by making my own modified interaction style. I wanna rotate and move an object by right click and holding left click respectively. And tried to make the modified interaction style class in header file, but there are some difficulties using functions declared in other classes in the modified interaction style. This should be simple. Does anyone know about this?
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 is the object I am trying to apply 'MyStyle' And the following is the MyStyle class
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();
}
I don't know what to change to move objects with leftclick.