------------------------------------------------------------------------------ Move the magnifier around. This method is invoked every time the mouse moves.
| 86 | // Move the magnifier around. This method is invoked every time the mouse |
| 87 | // moves. |
| 88 | void vtkMagnifierRepresentation::WidgetInteraction(double eventPos[2]) |
| 89 | { |
| 90 | int XF = eventPos[0]; |
| 91 | int YF = eventPos[1]; |
| 92 | |
| 93 | // Make sure the renderer and render window have been defined |
| 94 | vtkRenderWindow* renWin; |
| 95 | if (!this->Renderer || !(renWin = this->Renderer->GetRenderWindow())) |
| 96 | { |
| 97 | return; |
| 98 | } |
| 99 | |
| 100 | // If event outside of this window, turn off magnify renderer |
| 101 | this->InsideRenderer = (this->Renderer->IsInViewport(XF, YF) != 0); |
| 102 | |
| 103 | // Build the representation as necessary |
| 104 | this->BuildRepresentation(); |
| 105 | |
| 106 | // Move the viewport /renderer to the current mouse position |
| 107 | int* winSize = this->Renderer->GetRenderWindow()->GetSize(); |
| 108 | int* vpSize = this->Renderer->GetSize(); |
| 109 | double vpxMax = static_cast<double>(vpSize[0]) / winSize[0]; |
| 110 | double vpyMax = static_cast<double>(vpSize[1]) / winSize[1]; |
| 111 | double viewPort[4]; |
| 112 | viewPort[0] = eventPos[0] / winSize[0]; |
| 113 | viewPort[1] = eventPos[1] / winSize[1]; |
| 114 | viewPort[2] = viewPort[0] + static_cast<double>(this->Size[0]) / winSize[0]; |
| 115 | viewPort[3] = viewPort[1] + static_cast<double>(this->Size[1]) / winSize[1]; |
| 116 | viewPort[2] = ((viewPort[2] - viewPort[0]) > vpxMax ? vpxMax : viewPort[2]); |
| 117 | viewPort[3] = ((viewPort[3] - viewPort[1]) > vpyMax ? vpyMax : viewPort[3]); |
| 118 | |
| 119 | this->MagnificationRenderer->SetViewport(viewPort); |
| 120 | |
| 121 | // Update the magnificationcamera |
| 122 | // Grab the containing renderer's camera and copy it. Adjust the view angle |
| 123 | vtkCamera* cam = this->Renderer->GetActiveCamera(); |
| 124 | double viewAngle = cam->GetViewAngle(); |
| 125 | vtkCamera* magCam = this->MagnificationRenderer->GetActiveCamera(); |
| 126 | magCam->DeepCopy(cam); |
| 127 | magCam->SetViewAngle(viewAngle / this->MagnificationFactor); |
| 128 | |
| 129 | // Specify the focal point |
| 130 | this->Coordinate->SetValue(XF, YF); |
| 131 | double* focal = this->Coordinate->GetComputedWorldValue(this->Renderer); |
| 132 | this->MagnificationRenderer->GetActiveCamera()->SetFocalPoint(focal); |
| 133 | |
| 134 | // Setup the border if requested. We offset the border slightly to |
| 135 | // accommodate the width of the line. |
| 136 | if (this->Border) |
| 137 | { |
| 138 | this->BorderPoints->SetPoint(0, 1, 1, 0.0); |
| 139 | this->BorderPoints->SetPoint(1, (this->Size[0] - 1), 1, 0.0); |
| 140 | this->BorderPoints->SetPoint(2, (this->Size[0] - 1), (this->Size[1] - 1), 0.0); |
| 141 | this->BorderPoints->SetPoint(3, 1, (this->Size[1] - 1), 0.0); |
| 142 | } |
| 143 | } |
| 144 | |
| 145 | //------------------------------------------------------------------------------ |
nothing calls this directly
no test coverage detected