Skip to content

Commit

Permalink
Minor Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
omangbaheti committed Jul 7, 2024
1 parent aef5bc3 commit cb0502b
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 57 deletions.
26 changes: 14 additions & 12 deletions Assets/Scripts/ViconNexusUnityStream/CustomHandScript.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using UnityEngine.XR.Hands;
Expand Down Expand Up @@ -96,7 +97,6 @@ public class CustomHandScript : CustomSubjectScript

protected Dictionary<string, string> segmentChild;
protected Dictionary<string, string> segmentParents;
protected Dictionary<string, List<string>> fingerSegments;

protected Dictionary<string, XRHandJointID> segmentToJointMapping;
protected Dictionary<XRHandJointID, Pose> xrJointPoses;
Expand Down Expand Up @@ -242,7 +242,7 @@ protected override void Start()
{ segment_5D4, new List<string>(){marker_PF3}}
};

fingerSegments = new Dictionary<string, List<string>>()
new Dictionary<string, List<string>>()
{
{finger_1, new List<string>{segment_1D1, segment_1D2, segment_1D3, segment_1D4}},
{finger_2, new List<string>{segment_2D1, segment_2D2, segment_2D3, segment_2D4}},
Expand Down Expand Up @@ -373,21 +373,21 @@ protected override Dictionary<string, Vector3> ProcessSegments(Dictionary<string
{
var p1 = data.position[marker_TH3P];
var p2 = data.position[marker_TH3];
Vector3 p1Position = new Vector3(p1[0], p1[2], p1[1]);
Vector3 p2Position = new Vector3(p2[0], p2[2], p2[1]);
Vector3 p1Position = new(p1[0], p1[2], p1[1]);
Vector3 p2Position = new(p2[0], p2[2], p2[1]);

/// If one of the datapoints is missing, use the previous values, do this by not modifying the baseVectors
if (p1[0] != 0 || p2[0] != 0)
{
/// Ensure p1 and p2 are not switched, as it can happen when accuracy is low
/// PalmBase's Transform.up should be pointing into the palm.
/// This is based on the assumption that the RTH3P->RTH3 vector, relative to
/// PlamBase.up will be negative (pointing up from palm)
/// PalmBase.up will be negative (pointing up from palm)

Vector3 p1p2Vector = p2Position - p1Position;
float dotPrduct = Vector3.Dot(p1p2Vector, isRightHand() ? normal : -normal);
float dotProduct = Vector3.Dot(p1p2Vector, isRightHand() ? normal : -normal);

if (dotPrduct < 0)
if (dotProduct < 0)
{
p1p2Vector = -p1p2Vector;
}
Expand Down Expand Up @@ -433,14 +433,14 @@ private Vector3 FillWithRelativeAdjacent(string boneName, Dictionary<string, Vec

string fingerId = boneName.Substring(0, 2);

string childName, parentName; // Thisrd wheel being the other segment of the 4 segments in the finger
string childName, parentName; // Third wheel being the other segment of the 4 segments in the finger
Vector3 childPos, parentPos, childPosPrevious, parentPosPrevious, segmentPosPrevious;
segmentChild.TryGetValue(boneName, out childName);
segmentParents.TryGetValue(boneName, out parentName);

if (previousSegments.ContainsKey(boneName))
if (previousSegments.TryGetValue(boneName, out Vector3 segment))
{
segmentPosPrevious = previousSegments[boneName];
segmentPosPrevious = segment;
if (segmentPosPrevious == Vector3.zero)
{
return Vector3.zero;
Expand Down Expand Up @@ -591,6 +591,8 @@ protected override void ApplyBoneTransform(Transform Bone)
if (Bone.name == segment_Hand)
handWorldToLocalMatrix = Bone.worldToLocalMatrix;
}



/// <inheritdoc />
protected override void FindAndTransform(Transform iTransform, string BoneName)
Expand All @@ -602,7 +604,7 @@ protected override void FindAndTransform(Transform iTransform, string BoneName)
xrJointPoses.Clear();
base.FindAndTransform(iTransform, BoneName);

ViconXRLoader.TrySetHandSbsystemData(handedness, xrJointPoses);
ViconXRLoader.TrySetHandSubsystemData(handedness, xrJointPoses);
}

protected override bool TestSegmentsQuality(Dictionary<string, Vector3> segments)
Expand Down
4 changes: 3 additions & 1 deletion Assets/Scripts/ViconNexusUnityStream/CustomSubjectScript.cs
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,9 @@ protected virtual string ConstructFinalWriterString()
"}";
}
#endregion



//TO DO: Removed the rawData parameter. It might break things in future
void ProcessData(Data data)
{
//rawData = text;
Expand Down
43 changes: 1 addition & 42 deletions Assets/Scripts/ViconNexusUnityStream/SubjectDataManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ public bool UseDefaultData
/// </summary>
public bool EnableWriteData { get => enableWriteData; set => enableWriteData = value; }
public Dictionary<string, Data> StreamedData => streamedData;
public Dictionary<string, string> StreamedRawData => rawData;
public IViconClient ViconClient => viconClient;

[SerializeField] private ClientConfigArgs clientConfig;
Expand Down Expand Up @@ -98,8 +97,6 @@ private void Update()
{
streamedData[subject] = viconPositionData;
}
//Debug.Log(streamedData[subject].position["base1"][0]);

}
}

Expand Down Expand Up @@ -168,7 +165,6 @@ private void ConnectClient()
viconClient.ConnectClient(baseURI);
Thread.Sleep(200);
}
print($"Connected. Retiming Client:{clientConfig.useLightweightData}");

if (clientConfig.useLightweightData)
{
Expand All @@ -179,7 +175,6 @@ private void ConnectClient()
viconClient.SetAxisMapping(Direction.Forward, Direction.Left, Direction.Up);
ConnectionHandler( true);
viconClient.EnableMarkerData();
//Debug.Log("Marker Data Status: " + viconClient.IsMarkerDataEnabled().Enabled);
isConnectionThreadRunning = false;
}

Expand All @@ -189,53 +184,17 @@ private Dictionary<string, List<float>> ProcessData(string subject, uint markerC
for(uint i = 0; i < markerCount; i++)
{
string markerName = viconClient.GetMarkerName(subject, i).MarkerName;
var globalTranslation = viconClient.GetMarkerGlobalTranslation(subject, markerName);
// if (globalTranslation.Result != Result.Success)
// {
// Debug.LogWarning("Failed");
// }
Output_GetMarkerGlobalTranslation globalTranslation = viconClient.GetMarkerGlobalTranslation(subject, markerName);
markerPositionsDict[markerName] = new List<float>()
{
(float)globalTranslation.Translation[0],
(float)globalTranslation.Translation[1],
(float)globalTranslation.Translation[2]
};
//Debug.Log($"{markerName}: {globalTranslation.Translation[0]}");
}

return markerPositionsDict;
}

private void ProcessData(string subject, string segmentName)
{
double[] translationData = viconClient.GetSegmentLocalTranslation(subject, segmentName).Translation;
double[] orientationData = viconClient.GetSegmentLocalRotationQuaternion(subject, segmentName).Rotation;
FusionService.Quat viconOrientation = new(orientationData[0], orientationData[1], orientationData[2], orientationData[3]);
FusionService.Vec viconTranslation = new(translationData[0], translationData[1], translationData[2]);
FusionService.Pose posData = FusionService.GetMappedVicon(viconOrientation, viconTranslation);
List<float> positionData = new()
{(float)posData.Position.X, (float)posData.Position.Y, (float)posData.Position.Z};
Output_GetSegmentChildCount childCount = viconClient.GetSegmentChildCount(subject, segmentName);
streamedData[subject].position[segmentName] = positionData;
if(childCount.SegmentCount <= 0) return;
for (uint i = 0; i < childCount.SegmentCount; i++)
{
Output_GetSegmentChildName childSegment = viconClient.GetSegmentChildName(subject, segmentName, i);
ProcessData(subject, childSegment.SegmentName);
}
}

private void ProcessChildData(string subject, string segmentName)
{


coordinateUtils.Create();
//HMDUtils.FusionService.Pose ViconInHMD = FusionService.GetMappedVicon(ViconOrientation, translationData);



}

/// <summary>
/// Disable connection
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ protected bool UpdateJointData(Handedness handedness, NativeArray<XRHandJoint> h

if (handPoseCache.TryGetValue(jointID, out Pose pose))
{

if (recompute)
{
pose.rotation = Quaternion.LookRotation(pose.up, -pose.forward); // Accounting for the different coordinate system used.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ internal static void Initialize()
/// <summary>
/// Set hand subsystem data.
/// </summary>
public static void TrySetHandSbsystemData(Handedness handedness, Dictionary<XRHandJointID, Pose> poses)
public static void TrySetHandSubsystemData(Handedness handedness, Dictionary<XRHandJointID, Pose> poses)
{
if (loader != null)
{
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit cb0502b

Please sign in to comment.