8 #include "PlusConfigure.h" 13 #include <vtkMatrix4x4.h> 14 #include <vtkXMLDataElement.h> 16 #include <vtkSmartPointer.h> 38 , LeftControllerSource(nullptr)
39 , RightControllerSource(nullptr)
41 , SteamVRConnectionTimeout(10.0)
76 LOG_TRACE(
"Searching for Tracking System:")
78 if (vr::VR_IsHmdPresent())
80 LOG_TRACE(
"HMD found!");
85 LOG_TRACE(
"No HMD was found in the system.");
94 this->
VRContext = vr::VR_Init(&err, vr::EVRApplicationType::VRApplication_Scene);
98 LOG_ERROR(
"Unable to initialize SteamVR system: " << vr::VR_GetVRInitErrorAsEnglishDescription(err));
103 LOG_DEBUG(
"SteamVR runtime successfully initialized");
105 int baseStationsCount = 0;
106 for (uint32_t td = vr::k_unTrackedDeviceIndex_Hmd; td < vr::k_unMaxTrackedDeviceCount; td++)
108 if (this->
VRContext->IsTrackedDeviceConnected(td))
110 if (this->
VRContext->GetTrackedDeviceClass(td) == vr::ETrackedDeviceClass::TrackedDeviceClass_TrackingReference)
118 if (baseStationsCount < 2)
120 LOG_ERROR(
"There was a problem identifying the base stations, please check that they are powered on.");
130 LOG_TRACE(
"Shutting down SteamVR connection.");
139 vr::TrackedDevicePose_t trackedDevicePose[vr::k_unMaxTrackedDeviceCount];
142 this->
VRContext->GetDeviceToAbsoluteTrackingPose(vr::ETrackingUniverseOrigin::TrackingUniverseStanding, 0, trackedDevicePose, vr::k_unMaxTrackedDeviceCount);
144 vtkNew<vtkMatrix4x4> matrix;
145 for (vr::TrackedDeviceIndex_t nDevice = 0; nDevice < vr::k_unMaxTrackedDeviceCount; nDevice++)
147 if ((trackedDevicePose[nDevice].bDeviceIsConnected) && (trackedDevicePose[nDevice].bPoseIsValid))
149 float v[3] = { trackedDevicePose[nDevice].mDeviceToAbsoluteTracking.m[0][3], trackedDevicePose[nDevice].mDeviceToAbsoluteTracking.m[1][3], trackedDevicePose[nDevice].mDeviceToAbsoluteTracking.m[2][3] };
150 float r1[3] = { trackedDevicePose[nDevice].mDeviceToAbsoluteTracking.m[0][0], trackedDevicePose[nDevice].mDeviceToAbsoluteTracking.m[0][1], trackedDevicePose[nDevice].mDeviceToAbsoluteTracking.m[0][2] };
151 float r2[3] = { trackedDevicePose[nDevice].mDeviceToAbsoluteTracking.m[1][0], trackedDevicePose[nDevice].mDeviceToAbsoluteTracking.m[1][1], trackedDevicePose[nDevice].mDeviceToAbsoluteTracking.m[1][2] };
152 float r3[3] = { trackedDevicePose[nDevice].mDeviceToAbsoluteTracking.m[2][0], trackedDevicePose[nDevice].mDeviceToAbsoluteTracking.m[2][1], trackedDevicePose[nDevice].mDeviceToAbsoluteTracking.m[2][2] };
155 matrix->Element[0][0] = r1[0];
156 matrix->Element[0][1] = r1[1];
157 matrix->Element[0][2] = r1[2];
158 matrix->Element[1][0] = r2[0];
159 matrix->Element[1][1] = r2[1];
160 matrix->Element[1][2] = r2[2];
161 matrix->Element[2][0] = r3[0];
162 matrix->Element[2][1] = r3[1];
163 matrix->Element[2][2] = r3[2];
164 matrix->Element[0][3] =
v[0] * 1000;
165 matrix->Element[1][3] =
v[1] * 1000;
166 matrix->Element[2][3] =
v[2] * 1000;
168 if (this->
VRContext->GetTrackedDeviceClass(nDevice) == vr::TrackedDeviceClass_HMD && this->
HMDSource !=
nullptr)
172 if (this->
VRContext->GetTrackedDeviceClass(nDevice) == vr::TrackedDeviceClass_Controller)
174 if (this->
VRContext->GetControllerRoleForTrackedDeviceIndex(nDevice) == vr::TrackedControllerRole_LeftHand && this->
LeftControllerSource !=
nullptr)
178 else if (this->
VRContext->GetControllerRoleForTrackedDeviceIndex(nDevice) == vr::TrackedControllerRole_RightHand && this->
RightControllerSource !=
nullptr)
183 else if (this->
VRContext->GetTrackedDeviceClass(nDevice) == vr::TrackedDeviceClass_GenericTracker)
203 LOG_WARNING(
"Unable to locate tool with port name \"HMD\". Will not record HMD tracking for this session.");
212 LOG_WARNING(
"Unable to locate tool with port name \"LeftController\". Will not record left controller tracking for this session.");
221 LOG_WARNING(
"Unable to locate tool with port name \"RightController\". Will not record right controller tracking for this session.");
vtkPlusDataSource * HMDSource
virtual void PrintSelf(ostream &os, vtkIndent indent) VTK_OVERRIDE
Abstract interface for tracker and video devices.
void PrintSelf(ostream &os, vtkIndent indent)
virtual PlusStatus InternalDisconnect()
std::string GetSourceId() const
virtual PlusStatus ToolTimeStampedUpdate(const std::string &aToolSourceId, vtkMatrix4x4 *matrix, ToolStatus status, unsigned long frameNumber, double unfilteredtimestamp, const igsioFieldMapType *customFields=NULL)
vtkPlusDataSource * RightControllerSource
virtual PlusStatus Probe()
vtkPlusDataSource * LeftControllerSource
unsigned long FrameNumber
vr::IVRSystem * VRContext
PlusStatus GetToolByPortName(const char *aPortName, vtkPlusDataSource *&aSource)
virtual PlusStatus NotifyConfigured()
virtual PlusStatus InternalUpdate()
bool StartThreadForInternalUpdates
virtual PlusStatus InternalConnect()
vtkStandardNewMacro(vtkPlusSteamVRTracker)
Position vectors of rods v
Interface to a 3D positioning tool, video source, or generalized data stream.