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

Method InitializeViewFromCamera

Rendering/VR/vtkVRRenderWindow.cxx:223–281  ·  view source on GitHub ↗

------------------------------------------------------------------------------

Source from the content-addressed store, hash-verified

221
222//------------------------------------------------------------------------------
223void vtkVRRenderWindow::InitializeViewFromCamera(vtkCamera* srccam)
224{
225 vtkRenderer* ren = vtkRenderer::SafeDownCast(this->GetRenderers()->GetItemAsObject(0));
226 if (!ren)
227 {
228 vtkErrorMacro("The renderer must be set prior to calling InitializeViewFromCamera");
229 return;
230 }
231
232 vtkVRCamera* cam = vtkVRCamera::SafeDownCast(ren->GetActiveCamera());
233 if (!cam)
234 {
235 vtkErrorMacro(
236 "The renderer's active camera must be set prior to calling InitializeViewFromCamera");
237 return;
238 }
239
240 // make sure the view up is reasonable based on the view up
241 // that was set in PV
242 double distance = sin(vtkMath::RadiansFromDegrees(srccam->GetViewAngle()) / 2.0) *
243 srccam->GetDistance() / sin(vtkMath::RadiansFromDegrees(cam->GetViewAngle()) / 2.0);
244
245 double* oldVup = srccam->GetViewUp();
246 // NOLINTNEXTLINE(readability-avoid-nested-conditional-operator)
247 int maxIdx = fabs(oldVup[0]) > fabs(oldVup[1]) ? (fabs(oldVup[0]) > fabs(oldVup[2]) ? 0 : 2)
248 : (fabs(oldVup[1]) > fabs(oldVup[2]) ? 1 : 2);
249
250 // NOLINTNEXTLINE(readability-avoid-nested-conditional-operator)
251 cam->SetViewUp((maxIdx == 0 ? (oldVup[0] > 0 ? 1 : -1) : 0.0),
252 // NOLINTNEXTLINE(readability-avoid-nested-conditional-operator)
253 (maxIdx == 1 ? (oldVup[1] > 0 ? 1 : -1) : 0.0), (maxIdx == 2 ? (oldVup[2] > 0 ? 1 : -1) : 0.0));
254 // NOLINTNEXTLINE(readability-avoid-nested-conditional-operator)
255 this->SetPhysicalViewUp((maxIdx == 0 ? (oldVup[0] > 0 ? 1 : -1) : 0.0),
256 // NOLINTNEXTLINE(readability-avoid-nested-conditional-operator)
257 (maxIdx == 1 ? (oldVup[1] > 0 ? 1 : -1) : 0.0), (maxIdx == 2 ? (oldVup[2] > 0 ? 1 : -1) : 0.0));
258
259 double* oldFP = srccam->GetFocalPoint();
260 double* cvup = cam->GetViewUp();
261 cam->SetFocalPoint(oldFP);
262 this->SetPhysicalTranslation(
263 cvup[0] * distance - oldFP[0], cvup[1] * distance - oldFP[1], cvup[2] * distance - oldFP[2]);
264 this->SetPhysicalScale(distance);
265
266 double* oldDOP = srccam->GetDirectionOfProjection();
267 // NOLINTNEXTLINE(readability-avoid-nested-conditional-operator)
268 int dopMaxIdx = fabs(oldDOP[0]) > fabs(oldDOP[1]) ? (fabs(oldDOP[0]) > fabs(oldDOP[2]) ? 0 : 2)
269 : (fabs(oldDOP[1]) > fabs(oldDOP[2]) ? 1 : 2);
270 // NOLINTNEXTLINE(readability-avoid-nested-conditional-operator)
271 this->SetPhysicalViewDirection((dopMaxIdx == 0 ? (oldDOP[0] > 0 ? 1 : -1) : 0.0),
272 // NOLINTNEXTLINE(readability-avoid-nested-conditional-operator)
273 (dopMaxIdx == 1 ? (oldDOP[1] > 0 ? 1 : -1) : 0.0),
274 // NOLINTNEXTLINE(readability-avoid-nested-conditional-operator)
275 (dopMaxIdx == 2 ? (oldDOP[2] > 0 ? 1 : -1) : 0.0));
276 double* idop = this->GetPhysicalViewDirection();
277 cam->SetPosition(
278 -idop[0] * distance + oldFP[0], -idop[1] * distance + oldFP[1], -idop[2] * distance + oldFP[2]);
279
280 ren->ResetCameraClippingRange();

Callers

nothing calls this directly

Calls 15

GetItemAsObjectMethod · 0.80
GetRenderersMethod · 0.80
GetActiveCameraMethod · 0.80
GetViewUpMethod · 0.80
SetViewUpMethod · 0.80
sinFunction · 0.50
GetDistanceMethod · 0.45
SetPhysicalViewUpMethod · 0.45
SetFocalPointMethod · 0.45
SetPhysicalScaleMethod · 0.45

Tested by

no test coverage detected