| 216 | } |
| 217 | |
| 218 | void mitk::AffineImageCropperInteractor::RotateObject(StateMachineAction *, InteractionEvent *interactionEvent) |
| 219 | { |
| 220 | auto *positionEvent = dynamic_cast<InteractionPositionEvent *>(interactionEvent); |
| 221 | if (positionEvent == nullptr) |
| 222 | return; |
| 223 | |
| 224 | Point2D currentPickedDisplayPoint = positionEvent->GetPointerPositionOnScreen(); |
| 225 | if (currentPickedDisplayPoint.EuclideanDistanceTo(m_InitialPickedDisplayPoint) < 1) |
| 226 | return; |
| 227 | |
| 228 | vtkRenderer *currentVtkRenderer = interactionEvent->GetSender()->GetVtkRenderer(); |
| 229 | |
| 230 | if (currentVtkRenderer && currentVtkRenderer->GetActiveCamera()) |
| 231 | { |
| 232 | double vpn[3]; |
| 233 | currentVtkRenderer->GetActiveCamera()->GetViewPlaneNormal(vpn); |
| 234 | |
| 235 | Vector3D rotationAxis; |
| 236 | rotationAxis[0] = vpn[0]; |
| 237 | rotationAxis[1] = vpn[1]; |
| 238 | rotationAxis[2] = vpn[2]; |
| 239 | rotationAxis.Normalize(); |
| 240 | |
| 241 | Vector2D move = currentPickedDisplayPoint - m_InitialPickedDisplayPoint; |
| 242 | |
| 243 | double rotationAngle = -57.3 * atan(move[0] / move[1]); |
| 244 | if (move[1] < 0) |
| 245 | rotationAngle += 180; |
| 246 | |
| 247 | // Use center of data bounding box as center of rotation |
| 248 | Point3D rotationCenter = m_OriginalGeometry->GetCenter(); |
| 249 | if (positionEvent->GetSender()->GetMapperID() == BaseRenderer::Standard2D) |
| 250 | rotationCenter = m_InitialPickedPoint; |
| 251 | |
| 252 | // Reset current Geometry3D to original state (pre-interaction) and |
| 253 | // apply rotation |
| 254 | RotationOperation op(OpROTATE, rotationCenter, rotationAxis, rotationAngle); |
| 255 | Geometry3D::Pointer newGeometry = static_cast<Geometry3D *>(m_OriginalGeometry->Clone().GetPointer()); |
| 256 | newGeometry->ExecuteOperation(&op); |
| 257 | m_SelectedNode->GetData()->SetGeometry(newGeometry); |
| 258 | |
| 259 | RenderingManager::GetInstance()->RequestUpdateAll(); |
| 260 | } |
| 261 | } |
nothing calls this directly
no test coverage detected