[vtkusers] Selecting one out of multiple boxwidgets

Tamim tamim.boubou at gmail.com
Mon Feb 26 04:04:36 EST 2018


Hello all,

In my project I have multiple boxwidgets and I want to move them with
keyboard arrows.....the problem I'm facing is whenever I press a key(for
example the "up" arrow)all the boxes are moved together....
is there any solution to move only one box?
Here are the main parts of the code (Some variables are not declared here
but they are declared elsewhere ):

*The observers :*

    m_boxWidget->AddObserver(vtkCallbackCommand::StartInteractionEvent,
boxCallback);
    m_boxWidget->AddObserver(vtkCallbackCommand::InteractionEvent,
boxCallback);

RenderWindow()->GetInteractor()->AddObserver(vtkCallbackCommand::KeyPressEvent,
boxCallback);

*The execute function :*

  virtual void Execute(vtkObject* caller, unsigned long event, void* data)
    {
      m_orientation = new double[3];
      vtkSmartPointer<vtkBoxRepresentation> boxRep =
       
reinterpret_cast<vtkBoxRepresentation*>(m_boxWidget->GetRepresentation());

      vtkSmartPointer<vtkMatrix4x4> boxMatrix = m_boxTransform->GetMatrix();
      vtkSmartPointer<vtkMatrix4x4> tempMatrix =
vtkSmartPointer<vtkMatrix4x4>::New();
      switch (event) {
        case vtkCallbackCommand::StartInteractionEvent:
        case vtkCallbackCommand::InteractionEvent: {        
          boxRep->GetTransform(m_boxTransform);    // get the transformation
of the box
          boxMatrix = m_boxTransform->GetMatrix(); // convert the transform
into a transformation matrix
          this->m_actor->SetUserTransform(m_boxTransform);
          break;
        }
        case vtkCallbackCommand::KeyPressEvent: {
          keypressed = RenderWindow()->GetInteractor()->GetKeySym(); //get
the pressed key from the user
        std:cout << "Pressed : " << keypressed << std::endl;
          
          if (keypressed == "Up") {
            m_tempTransform->Translate(m_xDistance, m_yDistance, 0);
          }
          else if (keypressed == "Down") {
            m_tempTransform->Translate(-m_xDistance, -m_yDistance, 0);
          }
          else if (keypressed == "Left") {
            m_tempTransform->Translate(-m_yDistance, m_xDistance, 0);
          }
          else if (keypressed == "Right") {
            m_tempTransform->Translate(m_yDistance, -m_xDistance, 0);
          }
          boxRep->SetTransform(m_tempTransform);
          this->m_actor->SetUserTransform(m_tempTransform);
.....
Thanks a lot.



--
Sent from: http://vtk.1045678.n5.nabble.com/VTK-Users-f1224199.html


More information about the vtkusers mailing list