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

Method LoadCamera

IO/Geometry/vtkGLTFDocumentLoaderInternals.cxx:512–607  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

510
511//------------------------------------------------------------------------------
512bool vtkGLTFDocumentLoaderInternals::LoadCamera(
513 const nlohmann::json& root, vtkGLTFDocumentLoader::Camera& camera)
514{
515 if (root.is_null() || !root.is_object())
516 {
517 vtkErrorWithObjectMacro(this->Self, "Invalid camera object");
518 return false;
519 }
520
521 std::string type;
522 if (!vtkGLTFUtils::GetStringValue(root, "type", type))
523 {
524 vtkErrorWithObjectMacro(this->Self, "camera.type field is required but not found");
525 return false;
526 }
527 camera.Name = "";
528 vtkGLTFUtils::GetStringValue(root, "name", camera.Name);
529
530 nlohmann::json camRoot; // used to extract zfar and znear, can be either camera.orthographic or
531 // camera.perspective objects.
532
533 if (type == "orthographic")
534 {
535 camRoot = root.value("orthographic", nlohmann::json::object());
536 camera.IsPerspective = false;
537 }
538 else if (type == "perspective")
539 {
540 camRoot = root.value("perspective", nlohmann::json::object());
541 camera.IsPerspective = true;
542 }
543 else
544 {
545 vtkErrorWithObjectMacro(
546 this->Self, "Invalid camera.type value. Expecting 'orthographic' or 'perspective'");
547 return false;
548 }
549
550 if (!vtkGLTFUtils::GetDoubleValue(camRoot, "znear", camera.Znear))
551 {
552 vtkErrorWithObjectMacro(this->Self, "Invalid camera.znear value.");
553 return false;
554 }
555
556 // zfar is only required for orthographic cameras
557 // znear is required for both types, and has to be positive
558 if (!vtkGLTFUtils::GetDoubleValue(camRoot, "zfar", camera.Zfar) && type == "orthographic")
559 {
560 vtkErrorWithObjectMacro(this->Self, "Invalid camera.zfar value.");
561 return false;
562 }
563 if (camera.Znear <= 0 && type == "orthographic" &&
564 (camera.Zfar <= camera.Znear || camera.Zfar <= 0))
565 {
566 vtkErrorWithObjectMacro(this->Self, "Invalid camera.orthographic znear and zfar values");
567 return false;
568 }
569

Callers 1

LoadModelMetaDataMethod · 0.95

Calls 4

objectClass · 0.85
GetStringValueFunction · 0.70
GetDoubleValueFunction · 0.70
valueMethod · 0.45

Tested by

no test coverage detected