void InitProcessor() { userIssues = new Dictionary <int, UserIssues>(); for (int i = 0; i < checkedUserIds.Length; i++) { UserIssues tmpIssue = new UserIssues(); tmpIssue.isOccluded = false; tmpIssue.onBorderLeft = false; tmpIssue.onBorderRight = false; tmpIssue.onBorderTop = false; userIssues.Add(checkedUserIds[i], tmpIssue); } FrameBorderIssue issue = new FrameBorderIssue(true, true, true); // just to get fov values const float maxDepth = 10f; Vector3 topLeft = new Vector3(-maxDepth * Mathf.Tan(0.5f * issue.hFov), maxDepth * Mathf.Tan(0.5f * issue.vFov), maxDepth); Vector3 topRight = new Vector3(maxDepth * Mathf.Tan(0.5f * issue.hFov), maxDepth * Mathf.Tan(0.5f * issue.vFov), maxDepth); Vector3 bottomLeft = new Vector3(-maxDepth * Mathf.Tan(0.5f * issue.hFov), -maxDepth * Mathf.Tan(0.5f * issue.vFov), maxDepth); Vector3 bottomRight = new Vector3(maxDepth * Mathf.Tan(0.5f * issue.hFov), -maxDepth * Mathf.Tan(0.5f * issue.vFov), maxDepth); borders = new GameObject[3]; for (int i = 0; i < 3; i++) { borders[i] = new GameObject(); borders[i].transform.position = Vector3.zero; borders[i].transform.rotation = Quaternion.identity; MeshFilter meshFilter = borders[i].AddComponent <MeshFilter>(); MeshRenderer meshRenderer = borders[i].AddComponent <MeshRenderer>(); meshRenderer.material = bordersMaterial; Mesh mesh = new Mesh(); borders[i].name = (i == 0) ? "LeftBorder" : (i == 1) ? "RightBorder" : "TopBorder"; mesh.name = borders[i].name; List <Vector3> verts = new List <Vector3>(); verts.Add(Vector3.zero); verts.Add((i == 0) ? topLeft : (i == 1) ? bottomRight : topRight); verts.Add((i == 0) ? bottomLeft : (i == 1) ? topRight : topLeft); List <int> tris = new List <int>(); tris.Add(0); tris.Add(1); tris.Add(2); mesh.SetVertices(verts); mesh.SetTriangles(tris, 0); mesh.RecalculateNormals(); mesh.RecalculateBounds(); meshFilter.mesh = mesh; borders[i].SetActive(false); } nuitrack.Nuitrack.onIssueUpdateEvent += OnIssuesUpdate; }
void OnIssuesUpdate(nuitrack.issues.IssuesData issuesData) { borderedLeft = false; borderedRight = false; borderedTop = false; for (int i = 0; i < checkedUserIds.Length; i++) { if (issuesData.GetUserIssue <OcclusionIssue>(checkedUserIds[i]) != null) { userIssues[checkedUserIds[i]].isOccluded = true; } else { userIssues[checkedUserIds[i]].isOccluded = false; } FrameBorderIssue frameBorderIssue = issuesData.GetUserIssue <FrameBorderIssue>(checkedUserIds[i]); if (frameBorderIssue != null) { userIssues[checkedUserIds[i]].onBorderLeft = frameBorderIssue.Left; userIssues[checkedUserIds[i]].onBorderRight = frameBorderIssue.Right; userIssues[checkedUserIds[i]].onBorderTop = frameBorderIssue.Top; } else { userIssues[checkedUserIds[i]].onBorderLeft = false; userIssues[checkedUserIds[i]].onBorderRight = false; userIssues[checkedUserIds[i]].onBorderTop = false; } borderedLeft |= userIssues[checkedUserIds[i]].onBorderLeft; borderedRight |= userIssues[checkedUserIds[i]].onBorderRight; borderedTop |= userIssues[checkedUserIds[i]].onBorderTop; } }
// Event handler for the UserTrackerUpdate event private void onUserTrackerUpdate(UserFrame userFrame) { using (UserFrame _userFrame = (UserFrame)userFrame.Clone()) { if (_visualizeColorImage && _colorStreamEnabled) { return; } if (_depthFrame == null) { return; } const int MAX_LABELS = 7; bool[] labelIssueState = new bool[MAX_LABELS]; for (UInt16 label = 0; label < MAX_LABELS; ++label) { labelIssueState[label] = false; if (_issuesData != null) { FrameBorderIssue frameBorderIssue = _issuesData.GetUserIssue <FrameBorderIssue>(label); labelIssueState[label] = (frameBorderIssue != null); } } float wStep = (float)_bitmap.Width / _depthFrame.Cols; float hStep = (float)_bitmap.Height / _depthFrame.Rows; float nextVerticalBorder = hStep; unsafe { byte * dataDepth = (byte *)_depthFrame.Data.ToPointer(); byte * dataUser = (byte *)_userFrame.Data.ToPointer(); int dataPtr = 0; int bitmapPtr = 0; const int elemSizeInBytes = 2; for (int i = 0; i < _bitmap.Height; ++i) { if (i == (int)nextVerticalBorder) { dataPtr += _depthFrame.Cols * elemSizeInBytes; nextVerticalBorder += hStep; } int offset = 0; int argb = 0; int label = dataUser[dataPtr] | dataUser[dataPtr + 1] << 8; int depth = Math.Min(255, (dataDepth[dataPtr] | dataDepth[dataPtr + 1] << 8) / 32); float nextHorizontalBorder = wStep; for (int j = 0; j < _bitmap.Width; ++j) { if (j == (int)nextHorizontalBorder) { offset += elemSizeInBytes; label = dataUser[dataPtr + offset] | dataUser[dataPtr + offset + 1] << 8; if (label == 0) { depth = Math.Min(255, (dataDepth[dataPtr + offset] | dataDepth[dataPtr + offset + 1] << 8) / 32); } nextHorizontalBorder += wStep; } if (label > 0) { int user = label * 40; if (!labelIssueState[label]) { user += 40; } argb = 0 | (user << 8) | (0 << 16) | (0xFF << 24); } else { argb = depth | (depth << 8) | (depth << 16) | (0xFF << 24); } _bitmap.Bits[bitmapPtr++] = argb; } } } } }