mirror of
https://github.com/storytold/LiveScan3D.git
synced 2026-10-13 23:53:29 +00:00
Finished Temporal Sync Feature
This commit is contained in:
@@ -31,6 +31,7 @@ namespace KinectServer
|
||||
Socket oServerSocket;
|
||||
|
||||
bool bServerRunning = false;
|
||||
bool waitForSubToStart = false;
|
||||
|
||||
KinectSettings oSettings;
|
||||
object oClientSocketLock = new object();
|
||||
@@ -232,19 +233,71 @@ namespace KinectServer
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Send temporal Sync Data to all client
|
||||
/// </summary>
|
||||
public void SendTemporalSyncData()
|
||||
{
|
||||
lock (oClientSocketLock)
|
||||
{
|
||||
lClientSockets[0].SendTemporalSyncStatus(true, false);
|
||||
|
||||
for (int i = 1; i < lClientSockets.Count; i++)
|
||||
{
|
||||
if(lClientSockets.Count > 1 && oSettings.bEnableSync)
|
||||
{
|
||||
lClientSockets[i].SendTemporalSyncStatus(false, true);
|
||||
byte syncOffSetCounter = 1;
|
||||
|
||||
for (int i = 0; i < lClientSockets.Count; i++)
|
||||
{
|
||||
lClientSockets[i].SendTemporalSyncStatus(true, syncOffSetCounter);
|
||||
syncOffSetCounter++;
|
||||
}
|
||||
|
||||
waitForSubToStart = true;
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
for (int i = 0; i < lClientSockets.Count; i++)
|
||||
{
|
||||
lClientSockets[i].SendTemporalSyncStatus(false, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called when a sub client has started. This checks if all sub clients have already started. If yes, we initialize the master
|
||||
/// </summary>
|
||||
public void CheckForMasterStart()
|
||||
{
|
||||
if (!oSettings.bEnableSync || !waitForSubToStart)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
bool allSubsStarted = true;
|
||||
|
||||
lock (oClientSocketLock)
|
||||
{
|
||||
for (int i = 0; i < lClientSockets.Count; i++)
|
||||
{
|
||||
if (!lClientSockets[i].bSubStarted && lClientSockets[i].currentTempSyncState == KinectSocket.eTempSyncConfig.SUBORDINATE)
|
||||
{
|
||||
allSubsStarted = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (allSubsStarted)
|
||||
{
|
||||
for (int i = 0; i < lClientSockets.Count; i++)
|
||||
{
|
||||
lClientSockets[i].SendMasterInitialize();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
public bool GetStoredFrame(List<List<byte>> lFramesRGB, List<List<Single>> lFramesVerts)
|
||||
{
|
||||
bool bNoMoreStoredFrames;
|
||||
@@ -373,6 +426,8 @@ namespace KinectServer
|
||||
lClientSockets.Add(new KinectSocket(newClient));
|
||||
lClientSockets[lClientSockets.Count - 1].SendSettings(oSettings);
|
||||
lClientSockets[lClientSockets.Count - 1].eChanged += new SocketChangedHandler(SocketListChanged);
|
||||
lClientSockets[lClientSockets.Count - 1].eSubInitialized += new SubOrdinateInitialized(CheckForMasterStart);
|
||||
|
||||
if (eSocketListChanged != null)
|
||||
{
|
||||
eSocketListChanged(lClientSockets);
|
||||
|
||||
@@ -23,6 +23,7 @@ using System.Net.Sockets;
|
||||
namespace KinectServer
|
||||
{
|
||||
public delegate void SocketChangedHandler();
|
||||
public delegate void SubOrdinateInitialized();
|
||||
|
||||
public class KinectSocket
|
||||
{
|
||||
@@ -33,8 +34,10 @@ namespace KinectServer
|
||||
public bool bStoredFrameReceived = false;
|
||||
public bool bNoMoreStoredFrames = true;
|
||||
public bool bCalibrated = false;
|
||||
public bool bIsMaster = false;
|
||||
public bool bIsSubOrdinate = false;
|
||||
public bool bSubStarted = false;
|
||||
|
||||
public enum eTempSyncConfig { MASTER, SUBORDINATE, STANDALONE }
|
||||
public eTempSyncConfig currentTempSyncState = eTempSyncConfig.STANDALONE;
|
||||
//The pose of the sensor in the scene (used by the OpenGLWindow to show the sensor)
|
||||
public AffineTransform oCameraPose = new AffineTransform();
|
||||
//The transform that maps the vertices in the sensor coordinate system to the world corrdinate system.
|
||||
@@ -47,11 +50,14 @@ namespace KinectServer
|
||||
public List<Body> lBodies = new List<Body>();
|
||||
|
||||
public event SocketChangedHandler eChanged;
|
||||
public event SubOrdinateInitialized eSubInitialized;
|
||||
|
||||
public KinectSocket(Socket clientSocket)
|
||||
{
|
||||
oSocket = clientSocket;
|
||||
sSocketState = oSocket.RemoteEndPoint.ToString() + " Calibrated = false";
|
||||
|
||||
UpdateSocketState();
|
||||
}
|
||||
|
||||
public void CaptureFrame()
|
||||
@@ -123,23 +129,38 @@ namespace KinectServer
|
||||
SendByte();
|
||||
}
|
||||
|
||||
public void SendTemporalSyncStatus(bool isMaster, bool isSubOrdinate)
|
||||
{
|
||||
if (isMaster)
|
||||
/// <summary>
|
||||
/// Send the device the command to restart with Temporal Sync Enabled or Disabled
|
||||
/// </summary>
|
||||
/// <param name="tempSyncOn">Enable/Disable Temporal Sync</param>
|
||||
/// <param name="syncOffSetMultiplier">Only set when this device should be a subordinate. Should be a unique number in ascending order for each sub</param>
|
||||
public void SendTemporalSyncStatus(bool tempSyncOn, byte syncOffSetMultiplier)
|
||||
{
|
||||
if (tempSyncOn)
|
||||
{
|
||||
byteToSend[0] = 7;
|
||||
SendByte();
|
||||
return;
|
||||
byte[] data = new byte[2];
|
||||
data[0] = 7;
|
||||
data[1] = syncOffSetMultiplier;
|
||||
if (SocketConnected())
|
||||
oSocket.Send(data);
|
||||
}
|
||||
|
||||
if (isSubOrdinate)
|
||||
else
|
||||
{
|
||||
byteToSend[0] = 8;
|
||||
SendByte();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sends the master device the command to Start. Should only be called when all subs have started
|
||||
/// </summary>
|
||||
public void SendMasterInitialize()
|
||||
{
|
||||
byteToSend[0] = 9;
|
||||
SendByte();
|
||||
}
|
||||
|
||||
public void ReceiveCalibrationData()
|
||||
{
|
||||
bCalibrated = true;
|
||||
@@ -167,9 +188,10 @@ namespace KinectServer
|
||||
UpdateSocketState();
|
||||
}
|
||||
|
||||
//Gets the TemporalSyncStatus from the device
|
||||
public void ReceiveTemporalSyncStatus()
|
||||
{
|
||||
int nToRead;
|
||||
byte tempSyncState;
|
||||
byte[] buffer = new byte[1024];
|
||||
|
||||
while (oSocket.Available == 0)
|
||||
@@ -178,24 +200,40 @@ namespace KinectServer
|
||||
return;
|
||||
}
|
||||
|
||||
oSocket.Receive(buffer, 4, SocketFlags.None);
|
||||
nToRead = BitConverter.ToInt32(buffer, 0);
|
||||
oSocket.Receive(buffer, 3, SocketFlags.None);
|
||||
tempSyncState = buffer[0];
|
||||
|
||||
if (nToRead == -1)
|
||||
if (tempSyncState == 0)
|
||||
{
|
||||
bIsSubOrdinate = true;
|
||||
bIsMaster = false;
|
||||
return;
|
||||
currentTempSyncState = eTempSyncConfig.SUBORDINATE;
|
||||
bSubStarted = true;
|
||||
eSubInitialized?.Invoke();
|
||||
}
|
||||
|
||||
if(nToRead == 0)
|
||||
else if(tempSyncState == 1)
|
||||
{
|
||||
bIsMaster = true;
|
||||
bIsSubOrdinate = false;
|
||||
return;
|
||||
currentTempSyncState = eTempSyncConfig.MASTER;
|
||||
}
|
||||
|
||||
else if (tempSyncState == 2)
|
||||
{
|
||||
currentTempSyncState = eTempSyncConfig.STANDALONE;
|
||||
}
|
||||
|
||||
//MARKED FOR DELETION
|
||||
//if(currentTempSyncState == eTempSyncConfig.SUBORDINATE && confirmSubStarted == 1)
|
||||
//{
|
||||
|
||||
//}
|
||||
|
||||
//else if(currentTempSyncState == eTempSyncConfig.SUBORDINATE && confirmSubStarted == 0)
|
||||
//{
|
||||
// bSubStarted = false;
|
||||
// eSubInitialized?.Invoke();
|
||||
//}
|
||||
|
||||
UpdateSocketState();
|
||||
|
||||
}
|
||||
|
||||
public void ReceiveFrame()
|
||||
@@ -343,22 +381,23 @@ namespace KinectServer
|
||||
|
||||
public void UpdateSocketState()
|
||||
{
|
||||
string tempSyncStatus = "";
|
||||
string tempSyncMessage = "";
|
||||
|
||||
if (bIsMaster)
|
||||
switch (currentTempSyncState)
|
||||
{
|
||||
tempSyncStatus = "[Master]";
|
||||
case eTempSyncConfig.MASTER:
|
||||
tempSyncMessage = "[MASTER]";
|
||||
break;
|
||||
case eTempSyncConfig.SUBORDINATE:
|
||||
tempSyncMessage = "[SUBORDINATE]";
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if (bIsSubOrdinate)
|
||||
{
|
||||
tempSyncStatus = "[Subordinate]";
|
||||
}
|
||||
sSocketState = oSocket.RemoteEndPoint.ToString() + " Calibrated = " + bCalibrated + " " + tempSyncMessage;
|
||||
|
||||
sSocketState = oSocket.RemoteEndPoint.ToString() + " Calibrated = " + bCalibrated + " " + tempSyncStatus;
|
||||
|
||||
if (eChanged != null)
|
||||
eChanged();
|
||||
eChanged?.Invoke();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -75,6 +75,8 @@ namespace KinectServer
|
||||
IFormatter formatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
|
||||
Stream stream = new FileStream("settings.bin", FileMode.Open, FileAccess.Read);
|
||||
oSettings = (KinectSettings)formatter.Deserialize(stream);
|
||||
//This always needs to be set to false on startup, as we can only activate it when all Kinects are already connected
|
||||
oSettings.bEnableSync = false;
|
||||
stream.Close();
|
||||
}
|
||||
catch(Exception)
|
||||
@@ -496,6 +498,7 @@ namespace KinectServer
|
||||
for (int i = 0; i < socketList.Count; i++)
|
||||
listBoxItems.Add(socketList[i].sSocketState);
|
||||
|
||||
|
||||
lClientListBox.DataSource = listBoxItems;
|
||||
}
|
||||
}
|
||||
|
||||
Generated
+28
-14
@@ -28,13 +28,13 @@
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
System.Windows.Forms.Label lbSyncWarning;
|
||||
this.lbMerge = new System.Windows.Forms.Label();
|
||||
this.chMerge = new System.Windows.Forms.CheckBox();
|
||||
this.lbICPIters = new System.Windows.Forms.Label();
|
||||
this.txtICPIters = new System.Windows.Forms.TextBox();
|
||||
this.grClient = new System.Windows.Forms.GroupBox();
|
||||
this.grSync = new System.Windows.Forms.GroupBox();
|
||||
this.label1 = new System.Windows.Forms.Label();
|
||||
this.chSync = new System.Windows.Forms.CheckBox();
|
||||
this.grBody = new System.Windows.Forms.GroupBox();
|
||||
this.chSkeletons = new System.Windows.Forms.CheckBox();
|
||||
@@ -82,7 +82,7 @@
|
||||
this.rAsciiPly = new System.Windows.Forms.RadioButton();
|
||||
this.txtRefinIters = new System.Windows.Forms.TextBox();
|
||||
this.lbOuterIters = new System.Windows.Forms.Label();
|
||||
lbSyncWarning = new System.Windows.Forms.Label();
|
||||
this.label3 = new System.Windows.Forms.Label();
|
||||
this.grClient.SuspendLayout();
|
||||
this.grSync.SuspendLayout();
|
||||
this.grBody.SuspendLayout();
|
||||
@@ -145,24 +145,27 @@
|
||||
//
|
||||
// grSync
|
||||
//
|
||||
this.grSync.Controls.Add(lbSyncWarning);
|
||||
this.grSync.Controls.Add(this.label3);
|
||||
this.grSync.Controls.Add(this.label1);
|
||||
this.grSync.Controls.Add(this.chSync);
|
||||
this.grSync.Location = new System.Drawing.Point(271, 211);
|
||||
this.grSync.Name = "grSync";
|
||||
this.grSync.Size = new System.Drawing.Size(355, 66);
|
||||
this.grSync.Size = new System.Drawing.Size(355, 80);
|
||||
this.grSync.TabIndex = 48;
|
||||
this.grSync.TabStop = false;
|
||||
this.grSync.Text = "Temporal Sync (Azure Kinect Only)";
|
||||
this.grSync.Text = "Temporal Sync";
|
||||
this.grSync.Enter += new System.EventHandler(this.grSync_Enter);
|
||||
//
|
||||
// lbSyncWarning
|
||||
// label1
|
||||
//
|
||||
lbSyncWarning.AutoSize = true;
|
||||
lbSyncWarning.CausesValidation = false;
|
||||
lbSyncWarning.Location = new System.Drawing.Point(3, 41);
|
||||
lbSyncWarning.Name = "lbSyncWarning";
|
||||
lbSyncWarning.Size = new System.Drawing.Size(347, 13);
|
||||
lbSyncWarning.TabIndex = 1;
|
||||
lbSyncWarning.Text = "Notice: Devices need to be connected via sync cabel before enabeling!\r\n";
|
||||
this.label1.Location = new System.Drawing.Point(7, 41);
|
||||
this.label1.MaximumSize = new System.Drawing.Size(0, 60);
|
||||
this.label1.MinimumSize = new System.Drawing.Size(0, 30);
|
||||
this.label1.Name = "label1";
|
||||
this.label1.Size = new System.Drawing.Size(0, 30);
|
||||
this.label1.TabIndex = 1;
|
||||
this.label1.Text = "Notice: All devices need to be connected to the server and via sync cabel before" +
|
||||
" enabeling! First Device in Server List will become the master";
|
||||
//
|
||||
// chSync
|
||||
//
|
||||
@@ -174,7 +177,6 @@
|
||||
this.chSync.Text = "Enable Temporal Sync";
|
||||
this.chSync.UseVisualStyleBackColor = true;
|
||||
this.chSync.CheckedChanged += new System.EventHandler(this.chSync_CheckedChanged);
|
||||
|
||||
//
|
||||
// grBody
|
||||
//
|
||||
@@ -647,6 +649,16 @@
|
||||
this.lbOuterIters.Size = new System.Drawing.Size(118, 13);
|
||||
this.lbOuterIters.TabIndex = 26;
|
||||
this.lbOuterIters.Text = "Num of refinement iters:";
|
||||
//
|
||||
// label3
|
||||
//
|
||||
this.label3.Location = new System.Drawing.Point(7, 36);
|
||||
this.label3.Name = "label3";
|
||||
this.label3.Size = new System.Drawing.Size(342, 44);
|
||||
this.label3.TabIndex = 2;
|
||||
this.label3.Text = "Before activating, make sure that all Kinects are connected to the server and pro" +
|
||||
"perly connected via the sync cables. The first device in the server list will be" +
|
||||
"come the master!";
|
||||
//
|
||||
// SettingsForm
|
||||
//
|
||||
@@ -732,5 +744,7 @@
|
||||
private System.Windows.Forms.Label label2;
|
||||
private System.Windows.Forms.GroupBox grSync;
|
||||
private System.Windows.Forms.CheckBox chSync;
|
||||
private System.Windows.Forms.Label label1;
|
||||
private System.Windows.Forms.Label label3;
|
||||
}
|
||||
}
|
||||
@@ -355,6 +355,14 @@ namespace KinectServer
|
||||
UpdateClients();
|
||||
}
|
||||
|
||||
|
||||
private void grSync_Enter(object sender, EventArgs e)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private void lbSyncWarning_Click(object sender, EventArgs e)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -117,7 +117,4 @@
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<metadata name="lbSyncWarning.GenerateMember" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||
<value>False</value>
|
||||
</metadata>
|
||||
</root>
|
||||
Reference in New Issue
Block a user