2

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.

user3734823
  • 99
  • 1
  • 1
  • 10
  • I have made my own interaction styles when I needed to do this (5+ years ago). Maybe you should show what you have done with your own interaction style and what the problems are. – drescherjm Dec 30 '14 at 18:51
  • You may want to not forward the left click to vtkInteractorStyleTrackballCamera or at least only do this conditionally. – drescherjm Dec 30 '14 at 19:44

1 Answers1

1

If you're looking only to move objects with left buttons, you don't need to subclass your own interaction style, vtk already implements vtkInteractorStyleTrackballActor style that allows controlling actors by mouse, without interacting with camera. You can then override it to do whatever you want.

SAAD
  • 759
  • 1
  • 9
  • 23