| 109 | } |
| 110 | |
| 111 | void mitk::GizmoInteractor::DecideInteraction(StateMachineAction *, InteractionEvent *interactionEvent) |
| 112 | { |
| 113 | assert(m_PickedHandle != Gizmo::NoHandle); |
| 114 | |
| 115 | auto positionEvent = dynamic_cast<const InteractionPositionEvent *>(interactionEvent); |
| 116 | if (positionEvent == nullptr) |
| 117 | { |
| 118 | return; |
| 119 | } |
| 120 | |
| 121 | // if something relevant was picked, we calculate a number of |
| 122 | // important points and axes for the upcoming geometry manipulations |
| 123 | |
| 124 | // note initial state |
| 125 | m_InitialClickPosition2D = positionEvent->GetPointerPositionOnScreen(); |
| 126 | m_InitialClickPosition3D = positionEvent->GetPositionInWorld(); |
| 127 | |
| 128 | auto renderer = positionEvent->GetSender()->GetVtkRenderer(); |
| 129 | renderer->SetWorldPoint(m_InitialClickPosition3D[0], m_InitialClickPosition3D[1], m_InitialClickPosition3D[2], 0); |
| 130 | renderer->WorldToDisplay(); |
| 131 | m_InitialClickPosition2DZ = renderer->GetDisplayPoint()[2]; |
| 132 | |
| 133 | m_InitialGizmoCenter3D = m_Gizmo->GetCenter(); |
| 134 | positionEvent->GetSender()->WorldToDisplay(m_InitialGizmoCenter3D, m_InitialGizmoCenter2D); |
| 135 | |
| 136 | m_InitialManipulatedObjectGeometry = m_ManipulatedObjectGeometry->Clone(); |
| 137 | |
| 138 | switch ( m_PickedHandle ) { |
| 139 | case Gizmo::MoveAlongAxisX: |
| 140 | case Gizmo::RotateAroundAxisX: |
| 141 | case Gizmo::ScaleX: |
| 142 | m_AxisOfMovement = m_InitialManipulatedObjectGeometry->GetAxisVector(0); |
| 143 | break; |
| 144 | case Gizmo::MoveAlongAxisY: |
| 145 | case Gizmo::RotateAroundAxisY: |
| 146 | case Gizmo::ScaleY: |
| 147 | m_AxisOfMovement = m_InitialManipulatedObjectGeometry->GetAxisVector(1); |
| 148 | break; |
| 149 | case Gizmo::MoveAlongAxisZ: |
| 150 | case Gizmo::RotateAroundAxisZ: |
| 151 | case Gizmo::ScaleZ: |
| 152 | m_AxisOfMovement = m_InitialManipulatedObjectGeometry->GetAxisVector(2); |
| 153 | break; |
| 154 | default: |
| 155 | break; |
| 156 | } |
| 157 | m_AxisOfMovement.Normalize(); |
| 158 | m_AxisOfRotation = m_AxisOfMovement; |
| 159 | |
| 160 | // for translation: test whether the user clicked into the "object's real" axis direction |
| 161 | // or into the other one |
| 162 | Vector3D intendedAxis = m_InitialClickPosition3D - m_InitialGizmoCenter3D; |
| 163 | |
| 164 | if ( intendedAxis * m_AxisOfMovement < 0 ) { |
| 165 | m_AxisOfMovement *= -1.0; |
| 166 | } |
| 167 | |
| 168 | // for rotation: test whether the axis of rotation is more looking in the direction |
nothing calls this directly
no test coverage detected