MCPcopy Create free account
hub / github.com/Kitware/VTK / WidgetInteraction

Method WidgetInteraction

Interaction/Widgets/vtkMagnifierRepresentation.cxx:88–143  ·  view source on GitHub ↗

------------------------------------------------------------------------------ Move the magnifier around. This method is invoked every time the mouse moves.

Source from the content-addressed store, hash-verified

86// Move the magnifier around. This method is invoked every time the mouse
87// moves.
88void 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//------------------------------------------------------------------------------

Callers

nothing calls this directly

Calls 12

BuildRepresentationMethod · 0.95
IsInViewportMethod · 0.80
GetActiveCameraMethod · 0.80
SetViewAngleMethod · 0.80
GetComputedWorldValueMethod · 0.80
GetRenderWindowMethod · 0.45
GetSizeMethod · 0.45
SetViewportMethod · 0.45
DeepCopyMethod · 0.45
SetValueMethod · 0.45
SetFocalPointMethod · 0.45
SetPointMethod · 0.45

Tested by

no test coverage detected