Skip to content

Commit

Permalink
Removing unecessary additions to retimed Clinet
Browse files Browse the repository at this point in the history
  • Loading branch information
omangbaheti committed Jul 6, 2024
1 parent a0fe085 commit aef5bc3
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 169 deletions.
13 changes: 3 additions & 10 deletions Assets/Plugins/IViconClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,11 @@ public interface IViconClient
[Serializable]
public class ClientConfigArgs
{
//Too lazy to create a editor drawer based on gapfilling strategies
[Header("CommonConfig")]
[Header("Client Config")]
public bool useLightweightData;
public GapFillingStrategy gapFillingStrategy;

[Header("Retimed Client Config")]
public float retimedOffset = 0;

[Header("Normal Client Config")]
public StreamMode clientStreamMode;
public bool configureWireless = true;

public StreamMode clientStreamMode;

}

//Temporary Fix -- Assembly definition issue
Expand Down
149 changes: 4 additions & 145 deletions Assets/Plugins/RetimingClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,16 @@
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using UnityEngine;

namespace ViconDataStreamSDK.CSharp
{

public class RetimingClient : IDisposable, IViconClient
public class RetimingClient : IDisposable
{
private IntPtr mImpl;
private const string VICON_C_DLL = "ViconDataStreamSDK_C";
private const int MAX_STRING = 64; //all strings read from Vicon will be truncated to this length (includes '\0')
private ClientConfigArgs _clientConfigArgs;


public RetimingClient()
{
mImpl = RetimingClient_Create();
Expand Down Expand Up @@ -50,42 +48,7 @@ protected virtual void Dispose(bool bDisposing)
Dispose(false);
}
#endregion Destructors

#region IViconClientMethods

public void ConfigureClient(ClientConfigArgs args)
{
_clientConfigArgs = args;
}

public void ConnectClient(string baseURI)
{
Output_Connect OC = Connect(baseURI);
Debug.LogWarning("Attempt to Connect: " + OC.Result);
}

public Output_IsMarkerDataEnabled IsMarkerDataEnabled()
{
throw new NotImplementedException();
}

public Output_EnableMarkerData EnableMarkerData()
{
throw new NotImplementedException();
}

public void GetNewFrame()
{
UpdateFrame(_clientConfigArgs.retimedOffset);
}

public uint GetFrameNumber()
{
return 0;
}

#endregion

public Output_GetVersion GetVersion()
{
Output_GetVersion outp = new Output_GetVersion();
Expand Down Expand Up @@ -118,7 +81,7 @@ public Output_Connect Connect(string HostName, double FrameRate)

public Output_IsConnected IsConnected()
{
Output_IsConnected outp = new();
Output_IsConnected outp = new Output_IsConnected();
outp.Connected = RetimingClient_IsConnected(mImpl);
return outp;
}
Expand Down Expand Up @@ -191,50 +154,6 @@ public Output_GetSubjectName GetSubjectName(uint SubjectIndex)
Marshal.FreeHGlobal(ptr);
}
}

public Output_GetSegmentLocalTranslation GetScaledSegmentTranslation(string SubjectName, string SegmentName)
{
double[] OutputScale = new double[3];
OutputScale[0] = OutputScale[1] = OutputScale[2] = 1.0;

// Check first whether we have a parent, as we don't wish to scale the root node's position
Output_GetSegmentParentName Parent = GetSegmentParentName(SubjectName, SegmentName);

string CurrentSegmentName = SegmentName;
if ( Parent.Result == Result.Success)
{

do
{
// We have a parent. First get our scale, and then iterate through the nodes above us
Output_GetSegmentStaticScale Scale = GetSegmentStaticScale(SubjectName, CurrentSegmentName);
if (Scale.Result == Result.Success)
{
for (uint i = 0; i < 3; ++i)
{
if (Scale.Scale[i] != 0.0) OutputScale[i] = OutputScale[i] * Scale.Scale[i];
}
}

Parent = GetSegmentParentName(SubjectName, CurrentSegmentName);
if( Parent.Result == Result.Success )
{
CurrentSegmentName = Parent.SegmentName;
}
} while (Parent.Result == Result.Success);
}

Output_GetSegmentLocalTranslation Translation = GetSegmentLocalTranslation(SubjectName, SegmentName);
if( Translation.Result == Result.Success )
{
for (uint i = 0; i < 3; ++i)
{
Translation.Translation[i] = Translation.Translation[i] / OutputScale[i];
}
}
return Translation;
}

public Output_GetSubjectRootSegmentName GetSubjectRootSegmentName(string SubjectName)
{
Output_GetSubjectRootSegmentName outp = new Output_GetSubjectRootSegmentName();
Expand All @@ -250,7 +169,6 @@ public Output_GetSubjectRootSegmentName GetSubjectRootSegmentName(string Subject
Marshal.FreeHGlobal(ptr);
}
}

public Output_GetSegmentCount GetSegmentCount(string SubjectName)
{
Output_GetSegmentCount outp = new Output_GetSegmentCount();
Expand Down Expand Up @@ -280,23 +198,6 @@ public Output_GetSegmentName GetSegmentName(string SubjectName, uint SegmentInde
Marshal.FreeHGlobal(ptr);
}
}

//DK if this will work
public Output_GetMarkerName GetMarkerName(string SubjectName, uint MarkerIndex)
{
Output_GetMarkerName outp = new Output_GetMarkerName();
IntPtr ptr = Marshal.AllocHGlobal(MAX_STRING);
try
{
outp.Result = RetimingClient_GetMarkerName(mImpl, SubjectName, MarkerIndex, MAX_STRING, ptr);
outp.MarkerName = Marshal.PtrToStringAnsi(ptr);
return outp;
}
finally
{
Marshal.FreeHGlobal(ptr);
}
}
public Output_GetSegmentChildCount GetSegmentChildCount(string SubjectName, string SegmentName)
{
Output_GetSegmentChildCount outp = new Output_GetSegmentChildCount();
Expand All @@ -311,37 +212,6 @@ public Output_GetSegmentChildCount GetSegmentChildCount(string SubjectName, stri
}
return outp;
}

public Output_GetMarkerCount GetMarkerCount(string SubjectName)
{
Output_GetMarkerCount outp = new Output_GetMarkerCount();
GCHandle gch = GCHandle.Alloc(outp, GCHandleType.Pinned);
try
{
RetimingClient_GetMarkerCount(mImpl, SubjectName, gch.AddrOfPinnedObject());
}
finally
{
gch.Free();
}
return outp;
}

public Output_GetMarkerGlobalTranslation GetMarkerGlobalTranslation(string SubjectName, string MarkerName)
{
Type cType = typeof(Output_GetMarkerGlobalTranslation);
IntPtr ptr = Marshal.AllocHGlobal(Marshal.SizeOf(cType));
try
{
RetimingClient_GetMarkerGlobalTranslation(mImpl, SubjectName, MarkerName, ptr);
return (Output_GetMarkerGlobalTranslation)Marshal.PtrToStructure(ptr, cType);
}
finally
{
Marshal.FreeHGlobal(ptr);
}
}

public Output_GetSegmentChildName GetSegmentChildName(string SubjectName, string SegmentName, uint SegmentIndex)
{
Output_GetSegmentChildName outp = new Output_GetSegmentChildName();
Expand Down Expand Up @@ -724,9 +594,7 @@ static private extern Result RetimingClient_GetSegmentName(IntPtr client, [Marsh
[DllImport(VICON_C_DLL, CallingConvention = CallingConvention.Cdecl)]
static private extern void RetimingClient_GetSegmentChildCount(IntPtr client, [MarshalAs(UnmanagedType.LPStr)]string SubjectName,
[MarshalAs(UnmanagedType.LPStr)]string SegmentName, IntPtr outptr);
[DllImport(VICON_C_DLL, CallingConvention = CallingConvention.Cdecl)]
static private extern void RetimingClient_GetMarkerCount(IntPtr client, [MarshalAs(UnmanagedType.LPStr)]string SubjectName, IntPtr outptr);


[DllImport(VICON_C_DLL, CallingConvention = CallingConvention.Cdecl)]
static private extern Result RetimingClient_GetSegmentChildName(IntPtr client, [MarshalAs(UnmanagedType.LPStr)]string SubjectName,
[MarshalAs(UnmanagedType.LPStr)]string SegmentName,
Expand Down Expand Up @@ -817,15 +685,6 @@ static private extern void RetimingClient_GetSegmentLocalRotationEulerXYZ(IntPtr
static private extern Result RetimingClient_AddToSubjectFilter(IntPtr client, [MarshalAs(UnmanagedType.LPStr)]string i_rSubjectName);
[DllImport(VICON_C_DLL, CallingConvention = CallingConvention.Cdecl)]
static private extern Result RetimingClient_SetTimingLogFile(IntPtr client, [MarshalAs(UnmanagedType.LPStr)]string i_rClientLog, [MarshalAs(UnmanagedType.LPStr)]string i_rStreamLog);

[DllImport(VICON_C_DLL, CallingConvention = CallingConvention.Cdecl)]
static private extern Result RetimingClient_GetMarkerName(IntPtr client, [MarshalAs(UnmanagedType.LPStr)]string SubjectName,
uint MarkerIndex, int sizeOffBuffer, IntPtr outstr);

[DllImport(VICON_C_DLL, CallingConvention = CallingConvention.Cdecl)]
static private extern void RetimingClient_GetMarkerGlobalTranslation(IntPtr client, [MarshalAs(UnmanagedType.LPStr)]string SubjectName,
[MarshalAs(UnmanagedType.LPStr)]string MarkerName, IntPtr outptr);


#endregion PInvokes
}
Expand Down
20 changes: 6 additions & 14 deletions Assets/Scripts/ViconNexusUnityStream/SubjectDataManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,7 @@ public bool UseDefaultData
private bool isConnectionThreadRunning;
private static bool isConnected;

private IViconClient viconClient;
private Client viconClient2;
private Client viconClient;
private Thread connectThread;
private FusionService coordinateUtils;
public List<string> markerNames;
Expand Down Expand Up @@ -95,8 +94,10 @@ private void Update()
{
position = ProcessData(subject, markerCount.MarkerCount)
};
if(!streamedData.TryAdd(subject, viconPositionData));
streamedData[subject] = viconPositionData;
if (!streamedData.TryAdd(subject, viconPositionData))
{
streamedData[subject] = viconPositionData;
}
//Debug.Log(streamedData[subject].position["base1"][0]);

}
Expand Down Expand Up @@ -150,16 +151,7 @@ private void MaybeSetupConnection()
return;
}

if (clientConfig.gapFillingStrategy == GapFillingStrategy.ReTimed)
{
viconClient = new RetimingClient();
}
else
{
viconClient = new Client();
}


viconClient = new Client();
viconClient.ConfigureClient(clientConfig);

connectThread = new Thread(ConnectClient);
Expand Down

0 comments on commit aef5bc3

Please sign in to comment.