MCPcopy Create free account
hub / github.com/MITK/MITK / RotateObject

Method RotateObject

Modules/DataTypesExt/src/mitkAffineBaseDataInteractor3D.cpp:422–486  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

420}
421
422void mitk::AffineBaseDataInteractor3D::RotateObject(StateMachineAction *, InteractionEvent *interactionEvent)
423{
424 auto *positionEvent = dynamic_cast<InteractionPositionEvent *>(interactionEvent);
425 if (positionEvent == nullptr)
426 return;
427
428 Point2D currentPickedDisplayPoint = positionEvent->GetPointerPositionOnScreen();
429 Point3D currentWorldPoint = positionEvent->GetPositionInWorld();
430
431 vtkCamera *camera = nullptr;
432 vtkRenderer *currentVtkRenderer = nullptr;
433
434 if ((interactionEvent->GetSender()) != nullptr)
435 {
436 camera = interactionEvent->GetSender()->GetVtkRenderer()->GetActiveCamera();
437 currentVtkRenderer = interactionEvent->GetSender()->GetVtkRenderer();
438 }
439 if (camera && currentVtkRenderer)
440 {
441 double vpn[3];
442 camera->GetViewPlaneNormal(vpn);
443
444 Vector3D viewPlaneNormal;
445 viewPlaneNormal[0] = vpn[0];
446 viewPlaneNormal[1] = vpn[1];
447 viewPlaneNormal[2] = vpn[2];
448
449 Vector3D interactionMove;
450 interactionMove[0] = currentWorldPoint[0] - m_InitialPickedWorldPoint[0];
451 interactionMove[1] = currentWorldPoint[1] - m_InitialPickedWorldPoint[1];
452 interactionMove[2] = currentWorldPoint[2] - m_InitialPickedWorldPoint[2];
453
454 if (interactionMove[0] == 0 && interactionMove[1] == 0 && interactionMove[2] == 0)
455 return;
456
457 Vector3D rotationAxis = itk::CrossProduct(viewPlaneNormal, interactionMove);
458 rotationAxis.Normalize();
459
460 int *size = currentVtkRenderer->GetSize();
461 double l2 = (currentPickedDisplayPoint[0] - m_InitialPickedDisplayPoint[0]) *
462 (currentPickedDisplayPoint[0] - m_InitialPickedDisplayPoint[0]) +
463 (currentPickedDisplayPoint[1] - m_InitialPickedDisplayPoint[1]) *
464 (currentPickedDisplayPoint[1] - m_InitialPickedDisplayPoint[1]);
465
466 double rotationAngle = 360.0 * sqrt(l2 / (size[0] * size[0] + size[1] * size[1]));
467
468 // Use center of data bounding box as center of rotation
469 Point3D rotationCenter = m_OriginalGeometry->GetCenter();
470
471 int timeStep = 0;
472 if ((interactionEvent->GetSender()) != nullptr)
473 timeStep = interactionEvent->GetSender()->GetTimeStep(this->GetDataNode()->GetData());
474
475 // Reset current Geometry3D to original state (pre-interaction) and
476 // apply rotation
477 RotationOperation op(OpROTATE, rotationCenter, rotationAxis, rotationAngle);
478 Geometry3D::Pointer newGeometry = static_cast<Geometry3D *>(m_OriginalGeometry->Clone().GetPointer());
479 newGeometry->ExecuteOperation(&op);

Callers

nothing calls this directly

Calls 15

GetPositionInWorldMethod · 0.80
GetSenderMethod · 0.80
NormalizeMethod · 0.80
GetCenterMethod · 0.80
GetPointerMethod · 0.80
IsNotNullMethod · 0.80
GetVtkRendererMethod · 0.45
GetSizeMethod · 0.45
GetTimeStepMethod · 0.45
GetDataMethod · 0.45
GetDataNodeMethod · 0.45

Tested by

no test coverage detected