Skip to content
/ VTK Public

Commit 6083532

Browse files
committed
ENH: Exposing the generic tracker openvr device type to downstream projects
Refactor VTK interface to enable index based device querying (necessary to access multiple generic trackers) Add implementation of device count function in vtkOpenVRRenderWindow.cxx Adding count function for tracked devices by device type vtkOpenVRRenderWindow.h
1 parent 2ab904c commit 6083532

File tree

3 files changed

+56
-8
lines changed

3 files changed

+56
-8
lines changed

Common/Core/vtkEventData.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ enum class vtkEventDataDevice {
2727
HeadMountedDisplay,
2828
RightController,
2929
LeftController,
30+
GenericTracker,
3031
NumberOfDevices
3132
};
3233

Rendering/OpenVR/vtkOpenVRRenderWindow.cxx

Lines changed: 45 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -766,7 +766,7 @@ void vtkOpenVRRenderWindow::RenderOverlay()
766766
this->DashboardOverlay->Render();
767767
}
768768

769-
vr::TrackedDeviceIndex_t vtkOpenVRRenderWindow::GetTrackedDeviceIndexForDevice(vtkEventDataDevice dev)
769+
vr::TrackedDeviceIndex_t vtkOpenVRRenderWindow::GetTrackedDeviceIndexForDevice(vtkEventDataDevice dev, uint32_t index)
770770
{
771771
if (dev == vtkEventDataDevice::HeadMountedDisplay)
772772
{
@@ -780,12 +780,50 @@ vr::TrackedDeviceIndex_t vtkOpenVRRenderWindow::GetTrackedDeviceIndexForDevice(v
780780
{
781781
return this->HMD->GetTrackedDeviceIndexForControllerRole(vr::TrackedControllerRole_RightHand);
782782
}
783+
if (dev == vtkEventDataDevice::GenericTracker)
784+
{
785+
bool notDone = true;
786+
uint32_t arraySize(1024);
787+
vr::TrackedDeviceIndex_t* devices = new vr::TrackedDeviceIndex_t[arraySize];
788+
uint32_t deviceCount(0);
789+
while (notDone)
790+
{
791+
deviceCount = this->HMD->GetSortedTrackedDeviceIndicesOfClass(vr::TrackedDeviceClass_GenericTracker, devices, 1024);
792+
if (deviceCount > arraySize)
793+
{
794+
delete[] devices;
795+
arraySize *= 2;
796+
devices = new vr::TrackedDeviceIndex_t[arraySize];
797+
continue;
798+
}
799+
else
800+
{
801+
notDone = false;
802+
}
803+
}
804+
805+
uint32_t devIndex = devices[index];
806+
delete[] devices;
807+
808+
if (index > deviceCount)
809+
{
810+
return vr::k_unTrackedDeviceIndexInvalid;
811+
}
812+
813+
return devIndex;
814+
}
783815
return vr::k_unTrackedDeviceIndexInvalid;
784816
}
785817

786-
vtkOpenVRModel *vtkOpenVRRenderWindow::GetTrackedDeviceModel(vtkEventDataDevice dev)
818+
uint32_t vtkOpenVRRenderWindow::GetNumberOfTrackedDevicesForDevice(vtkEventDataDevice dev)
819+
{
820+
vr::TrackedDeviceIndex_t devices[1];
821+
return this->HMD->GetSortedTrackedDeviceIndicesOfClass(vr::TrackedDeviceClass_GenericTracker, devices, 1);
822+
}
823+
824+
vtkOpenVRModel *vtkOpenVRRenderWindow::GetTrackedDeviceModel(vtkEventDataDevice dev, uint32_t index)
787825
{
788-
vr::TrackedDeviceIndex_t idx = this->GetTrackedDeviceIndexForDevice(dev);
826+
vr::TrackedDeviceIndex_t idx = this->GetTrackedDeviceIndexForDevice(dev, index);
789827
if (idx != vr::k_unTrackedDeviceIndexInvalid)
790828
{
791829
return this->GetTrackedDeviceModel(idx);
@@ -794,9 +832,11 @@ vtkOpenVRModel *vtkOpenVRRenderWindow::GetTrackedDeviceModel(vtkEventDataDevice
794832
}
795833

796834
void vtkOpenVRRenderWindow::GetTrackedDevicePose(
797-
vtkEventDataDevice dev, vr::TrackedDevicePose_t **pose)
835+
vtkEventDataDevice dev,
836+
uint32_t index,
837+
vr::TrackedDevicePose_t **pose)
798838
{
799-
vr::TrackedDeviceIndex_t idx = this->GetTrackedDeviceIndexForDevice(dev);
839+
vr::TrackedDeviceIndex_t idx = this->GetTrackedDeviceIndexForDevice(dev, index);
800840
*pose = nullptr;
801841
if (idx < vr::k_unMaxTrackedDeviceCount)
802842
{

Rendering/OpenVR/vtkOpenVRRenderWindow.h

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,9 +132,11 @@ class VTKRENDERINGOPENVR_EXPORT vtkOpenVRRenderWindow : public vtkOpenGLRenderWi
132132
/**
133133
* Get the VRModel corresponding to the tracked device
134134
*/
135-
vtkOpenVRModel *GetTrackedDeviceModel(vtkEventDataDevice idx);
135+
vtkOpenVRModel *GetTrackedDeviceModel(vtkEventDataDevice idx) {
136+
return this->GetTrackedDeviceModel(idx, 0); };
136137
vtkOpenVRModel *GetTrackedDeviceModel(vr::TrackedDeviceIndex_t idx) {
137138
return this->TrackedDeviceToRenderModel[idx]; };
139+
vtkOpenVRModel* GetTrackedDeviceModel(vtkEventDataDevice idx, uint32_t index);
138140

139141
/**
140142
* Get the openVR Render Models
@@ -145,12 +147,17 @@ class VTKRENDERINGOPENVR_EXPORT vtkOpenVRRenderWindow : public vtkOpenGLRenderWi
145147
/**
146148
* Get the index corresponding to the tracked device
147149
*/
148-
vr::TrackedDeviceIndex_t GetTrackedDeviceIndexForDevice(vtkEventDataDevice dev);
150+
vr::TrackedDeviceIndex_t GetTrackedDeviceIndexForDevice(vtkEventDataDevice dev) {
151+
return this->GetTrackedDeviceIndexForDevice(dev, 0); };
152+
vr::TrackedDeviceIndex_t GetTrackedDeviceIndexForDevice(vtkEventDataDevice dev, uint32_t index);
153+
uint32_t GetNumberOfTrackedDevicesForDevice(vtkEventDataDevice dev);
149154

150155
/**
151156
* Get the most recent pose corresponding to the tracked device
152157
*/
153-
void GetTrackedDevicePose(vtkEventDataDevice idx, vr::TrackedDevicePose_t **pose);
158+
void GetTrackedDevicePose(vtkEventDataDevice idx, vr::TrackedDevicePose_t **pose) {
159+
return this->GetTrackedDevicePose(idx, 0, pose); };
160+
void GetTrackedDevicePose(vtkEventDataDevice idx, uint32_t index, vr::TrackedDevicePose_t **pose);
154161
vr::TrackedDevicePose_t &GetTrackedDevicePose(vr::TrackedDeviceIndex_t idx) {
155162
return this->TrackedDevicePose[idx]; };
156163

0 commit comments

Comments
 (0)