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

Function LoadRenderModelMapping

Rendering/OpenXR/vtkOpenXRRenderWindow.cxx:51–131  ·  view source on GitHub ↗

---------------------------------------------------------------------------- OpenXR does not yet have a way to load and render controller models. This workaround maps known/tested interaction profiles to local assets.

Source from the content-addressed store, hash-verified

49 // models. This workaround maps known/tested interaction profiles
50 // to local assets.
51 void LoadRenderModelMapping()
52 {
53 std::string modelsFile = "openxr_controllermodels.json";
54
55 // Look for where the function "GetVTKVersion." lives.
56 auto vtklib = vtkGetLibraryPathForSymbol(GetVTKVersion);
57
58 if (vtklib.empty())
59 {
60 vtkWarningWithObjectMacro(nullptr, << "Unable to locate runtime library location.");
61 return;
62 }
63
64 // Search for the controller models json file in the parent of the
65 // directory containing the library/executable.
66 const std::string libPath = vtksys::SystemTools::GetFilenamePath(vtklib);
67 const std::string rootSearchDir = vtksys::SystemTools::GetParentDirectory(libPath);
68 vtkNew<vtkGlobFileNames> fileGlobber;
69 fileGlobber->SetDirectory(rootSearchDir.c_str());
70 fileGlobber->SetRecurse(true);
71 fileGlobber->AddFileNames(modelsFile.c_str());
72 if (!this->ModelsManifestDirectory.empty())
73 {
74 std::string fullpath =
75 vtksys::SystemTools::JoinPath({ this->ModelsManifestDirectory, modelsFile });
76 fileGlobber->AddFileNames(fullpath.c_str());
77 }
78 if (fileGlobber->GetNumberOfFileNames() <= 0)
79 {
80 vtkWarningWithObjectMacro(
81 nullptr, << "Unable to locate model mapping file in: " << rootSearchDir);
82 return;
83 }
84
85 const char* match = fileGlobber->GetNthFileName(0);
86 const std::string modelFile(&match[0]);
87
88 // Get the directory containing the controller models json file, since
89 // we found it.
90 std::string modelsDirectory = vtksys::SystemTools::GetFilenamePath(modelFile);
91
92 // Open the profile->asset mapping file
93 vtksys::ifstream file;
94 file.open(modelFile.c_str());
95 if (!file.is_open())
96 {
97 vtkWarningWithObjectMacro(nullptr, << "Unable to open model mapping file : " << modelFile);
98 return;
99 }
100
101 Json::Value root;
102 Json::CharReaderBuilder builder;
103 std::string formattedErrors;
104 if (!Json::parseFromStream(builder, file, &root, &formattedErrors))
105 {
106 // Report failures and their locations in the document
107 vtkWarningWithObjectMacro(nullptr, << "Failed to parse file with errors :" << endl
108 << formattedErrors);

Callers

nothing calls this directly

Calls 10

parseFromStreamFunction · 0.85
AddFileNamesMethod · 0.80
GetNthFileNameMethod · 0.80
is_openMethod · 0.80
asStringMethod · 0.80
emptyMethod · 0.45
c_strMethod · 0.45
GetNumberOfFileNamesMethod · 0.45
openMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected