diff --git a/LiveScanServer/KinectSettings.cs b/LiveScanServer/KinectSettings.cs index 56330f3..5366760 100644 --- a/LiveScanServer/KinectSettings.cs +++ b/LiveScanServer/KinectSettings.cs @@ -34,6 +34,7 @@ namespace KinectServer public BindingList lMarkerPoses = new BindingList(); public bool bStreamOnlyBodies = false; + public bool bShowSkeletons = true; public int nNumICPIterations = 10; public int nNumRefineIters = 2; diff --git a/LiveScanServer/OpenGLWindow.cs b/LiveScanServer/OpenGLWindow.cs index 2ce54e2..b8e3f64 100644 --- a/LiveScanServer/OpenGLWindow.cs +++ b/LiveScanServer/OpenGLWindow.cs @@ -259,7 +259,7 @@ namespace KinectServer if ((DateTime.Now - tFPSUpdateTimer).Seconds >= 1) { double FPS = nTickCounter / (DateTime.Now - tFPSUpdateTimer).TotalSeconds; - this.Title = "FPS: " + string.Format("{0:F}", FPS); + //this.Title = "FPS: " + string.Format("{0:F}", FPS); tFPSUpdateTimer = DateTime.Now; nTickCounter = 0; @@ -292,42 +292,43 @@ namespace KinectServer lock (vertices) { - lock (settings) - { - PointCount = vertices.Count / 3; - //bounding box - LineCount = 12; - //markers - LineCount += settings.lMarkerPoses.Count * 3; - //cameras - LineCount += cameraPoses.Count * 3; + bool bShowSkeletons = settings.bShowSkeletons; + + PointCount = vertices.Count / 3; + //bounding box + LineCount = 12; + //markers + LineCount += settings.lMarkerPoses.Count * 3; + //cameras + LineCount += cameraPoses.Count * 3; + if (bShowSkeletons) LineCount += 24 * bodies.Count; - VBO = new VertexC4ubV3f[PointCount + 2 * LineCount]; + VBO = new VertexC4ubV3f[PointCount + 2 * LineCount]; - for (int i = 0; i < PointCount; i++) - { - VBO[i].R = (byte)colors[i * 3]; - VBO[i].G = (byte)colors[i * 3 + 1]; - VBO[i].B = (byte)colors[i * 3 + 2]; - VBO[i].A = 255; - VBO[i].Position.X = vertices[i * 3]; - VBO[i].Position.Y = vertices[i * 3 + 1]; - VBO[i].Position.Z = vertices[i * 3 + 2]; - } - - int iCurLineCount = 0; - iCurLineCount += AddBoundingBox(PointCount + 2 * iCurLineCount); - for (int i = 0; i < settings.lMarkerPoses.Count; i++) - { - iCurLineCount += AddMarker(PointCount + 2 * iCurLineCount, settings.lMarkerPoses[i].pose); - } - for (int i = 0; i < cameraPoses.Count; i++) - { - iCurLineCount += AddCamera(PointCount + 2 * iCurLineCount, cameraPoses[i]); - } - iCurLineCount += AddBodies(PointCount + 2 * iCurLineCount); + for (int i = 0; i < PointCount; i++) + { + VBO[i].R = (byte)colors[i * 3]; + VBO[i].G = (byte)colors[i * 3 + 1]; + VBO[i].B = (byte)colors[i * 3 + 2]; + VBO[i].A = 255; + VBO[i].Position.X = vertices[i * 3]; + VBO[i].Position.Y = vertices[i * 3 + 1]; + VBO[i].Position.Z = vertices[i * 3 + 2]; } + + int iCurLineCount = 0; + iCurLineCount += AddBoundingBox(PointCount + 2 * iCurLineCount); + for (int i = 0; i < settings.lMarkerPoses.Count; i++) + { + iCurLineCount += AddMarker(PointCount + 2 * iCurLineCount, settings.lMarkerPoses[i].pose); + } + for (int i = 0; i < cameraPoses.Count; i++) + { + iCurLineCount += AddCamera(PointCount + 2 * iCurLineCount, cameraPoses[i]); + } + if (bShowSkeletons) + iCurLineCount += AddBodies(PointCount + 2 * iCurLineCount); } } @@ -574,6 +575,9 @@ namespace KinectServer for (int bodyIdx = 0; bodyIdx < bodies.Count; bodyIdx++) { + if (bodies[bodyIdx].bTracked == false) + continue; + //Torso n += AddBone(bodyIdx, JointType.JointType_Head, JointType.JointType_Neck, startIdx + n); n += AddBone(bodyIdx, JointType.JointType_Neck, JointType.JointType_SpineShoulder, startIdx + n); @@ -607,7 +611,8 @@ namespace KinectServer n += AddBone(bodyIdx, JointType.JointType_HipLeft, JointType.JointType_KneeLeft, startIdx + n); n += AddBone(bodyIdx, JointType.JointType_KneeLeft, JointType.JointType_AnkleLeft, startIdx + n); n += AddBone(bodyIdx, JointType.JointType_AnkleLeft, JointType.JointType_FootLeft, startIdx + n); - } + } + return nLinesToAdd; } diff --git a/LiveScanServer/SettingsForm.Designer.cs b/LiveScanServer/SettingsForm.Designer.cs index 1e44d44..ef9c06c 100644 --- a/LiveScanServer/SettingsForm.Designer.cs +++ b/LiveScanServer/SettingsForm.Designer.cs @@ -77,6 +77,7 @@ this.rAsciiPly = new System.Windows.Forms.RadioButton(); this.txtRefinIters = new System.Windows.Forms.TextBox(); this.lbOuterIters = new System.Windows.Forms.Label(); + this.chSkeletons = new System.Windows.Forms.CheckBox(); this.grClient.SuspendLayout(); this.grBody.SuspendLayout(); this.grMarkers.SuspendLayout(); @@ -137,6 +138,7 @@ // // grBody // + this.grBody.Controls.Add(this.chSkeletons); this.grBody.Controls.Add(this.label1); this.grBody.Controls.Add(this.chBodyData); this.grBody.Location = new System.Drawing.Point(9, 211); @@ -149,7 +151,7 @@ // label1 // this.label1.AutoSize = true; - this.label1.Location = new System.Drawing.Point(11, 43); + this.label1.Location = new System.Drawing.Point(8, 61); this.label1.Name = "label1"; this.label1.Size = new System.Drawing.Size(187, 13); this.label1.TabIndex = 20; @@ -570,6 +572,17 @@ this.lbOuterIters.TabIndex = 26; this.lbOuterIters.Text = "Num of refinement iters:"; // + // chSkeletons + // + this.chSkeletons.AutoSize = true; + this.chSkeletons.Location = new System.Drawing.Point(11, 41); + this.chSkeletons.Name = "chSkeletons"; + this.chSkeletons.Size = new System.Drawing.Size(154, 17); + this.chSkeletons.TabIndex = 21; + this.chSkeletons.Text = "show skeletons in live view"; + this.chSkeletons.UseVisualStyleBackColor = true; + this.chSkeletons.CheckedChanged += new System.EventHandler(this.chSkeletons_CheckedChanged); + // // SettingsForm // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); @@ -648,6 +661,7 @@ private System.Windows.Forms.RadioButton rBinaryPly; private System.Windows.Forms.Label lbFormat; private System.Windows.Forms.RadioButton rAsciiPly; + private System.Windows.Forms.CheckBox chSkeletons; } } \ No newline at end of file diff --git a/LiveScanServer/SettingsForm.cs b/LiveScanServer/SettingsForm.cs index 066f8b5..0ec42c6 100644 --- a/LiveScanServer/SettingsForm.cs +++ b/LiveScanServer/SettingsForm.cs @@ -51,7 +51,8 @@ namespace KinectServer lisMarkers.DataSource = oSettings.lMarkerPoses; - chBodyData.Checked = oSettings.bStreamOnlyBodies; + chBodyData.Checked = oSettings.bStreamOnlyBodies; + chSkeletons.Checked = oSettings.bShowSkeletons; chMerge.Checked = oSettings.bMergeScansForSave; txtICPIters.Text = oSettings.nNumICPIterations.ToString(); @@ -310,5 +311,10 @@ namespace KinectServer oSettings.bSaveAsBinaryPLY = true; } } + + private void chSkeletons_CheckedChanged(object sender, EventArgs e) + { + oSettings.bShowSkeletons = chSkeletons.Checked; + } } } diff --git a/include/LiveScanClient/iCapture.h b/include/LiveScanClient/iCapture.h index 67b24ea..247b30a 100644 --- a/include/LiveScanClient/iCapture.h +++ b/include/LiveScanClient/iCapture.h @@ -19,6 +19,12 @@ struct Body { + Body() + { + bTracked = false; + vJoints.resize(JointType_Count); + vJointsInColorSpace.resize(JointType_Count); + } bool bTracked; std::vector vJoints; std::vector vJointsInColorSpace; diff --git a/src/LiveScanClient/kinectCapture.cpp b/src/LiveScanClient/kinectCapture.cpp index 0ca7e20..737d277 100644 --- a/src/LiveScanClient/kinectCapture.cpp +++ b/src/LiveScanClient/kinectCapture.cpp @@ -187,11 +187,11 @@ void KinectCapture::GetBodyFrame(IMultiSourceFrame* pMultiFrame) if (SUCCEEDED(hr)) { - IBody* bodies[6] = { NULL }; - pBodyFrame->GetAndRefreshBodyData(6, bodies); + IBody* bodies[BODY_COUNT] = { NULL }; + pBodyFrame->GetAndRefreshBodyData(BODY_COUNT, bodies); vBodies = std::vector(BODY_COUNT); - for (int i = 0; i < 6; i++) + for (int i = 0; i < BODY_COUNT; i++) { if (bodies[i]) { diff --git a/src/LiveScanClient/liveScanClient.cpp b/src/LiveScanClient/liveScanClient.cpp index c9450c2..96e2b8a 100644 --- a/src/LiveScanClient/liveScanClient.cpp +++ b/src/LiveScanClient/liveScanClient.cpp @@ -721,23 +721,25 @@ void LiveScanClient::StoreFrame(Point3f *vertices, Point2f *mapping, RGB *color, } } - for (unsigned int i = 0; i < bodies.size(); i++) + vector tempBodies = bodies; + + for (unsigned int i = 0; i < tempBodies.size(); i++) { - for (unsigned int j = 0; j < bodies[i].vJoints.size(); j++) + for (unsigned int j = 0; j < tempBodies[i].vJoints.size(); j++) { if (calibration.bCalibrated) { - bodies[i].vJoints[j].Position.X += calibration.worldT[0]; - bodies[i].vJoints[j].Position.Y += calibration.worldT[1]; - bodies[i].vJoints[j].Position.Z += calibration.worldT[2]; + tempBodies[i].vJoints[j].Position.X += calibration.worldT[0]; + tempBodies[i].vJoints[j].Position.Y += calibration.worldT[1]; + tempBodies[i].vJoints[j].Position.Z += calibration.worldT[2]; - Point3f tempPoint(bodies[i].vJoints[j].Position.X, bodies[i].vJoints[j].Position.Y, bodies[i].vJoints[j].Position.Z); + Point3f tempPoint(tempBodies[i].vJoints[j].Position.X, tempBodies[i].vJoints[j].Position.Y, tempBodies[i].vJoints[j].Position.Z); tempPoint = RotatePoint(tempPoint, calibration.worldR); - bodies[i].vJoints[j].Position.X = tempPoint.X; - bodies[i].vJoints[j].Position.Y = tempPoint.Y; - bodies[i].vJoints[j].Position.Z = tempPoint.Z; + tempBodies[i].vJoints[j].Position.X = tempPoint.X; + tempBodies[i].vJoints[j].Position.Y = tempPoint.Y; + tempBodies[i].vJoints[j].Position.Z = tempPoint.Z; } } } @@ -752,7 +754,7 @@ void LiveScanClient::StoreFrame(Point3f *vertices, Point2f *mapping, RGB *color, goodVerticesShort[i] = goodVertices[i]; } - m_vLastFrameBody = bodies; + m_vLastFrameBody = tempBodies; m_vLastFrameVertices = goodVerticesShort; m_vLastFrameRGB = goodColorPoints; }