예제 #1
0
        /// <summary>
        /// Called when BodyCapture detects a new body.
        /// </summary>
        /// <param name="id">Unique ID of the body.</param>
        private void Body_OnDetected(ulong id)
        {
            Log.Information($"Body detected, creating body elements (Body={id}).");

            _bodyElements[id] = null;

            _network
            .Create(_kinectElement.Id, Util.CreateElementData($"Body {id}"))
            .ContinueWith(task =>
            {
                var rootElement = task.Result;

                Log.Information($"Created body root element (Body={id} Element={rootElement.Id}).");

                // Double check the body didn't disappear during the network op
                if (!_bodyElements.ContainsKey(id))
                {
                    Log.Information($"Matching body already gone. Destroying (Body={id} Element={rootElement.Id}).");
                    _network.Destroy(rootElement.Id);
                    return;
                }

                var bodyElements         = new BodyElements();
                bodyElements.RootElement = rootElement;

                var jointCreates = new Task <ElementData> [_trackList.Length];
                Log.Information($"Creating {jointCreates.Length} joint elements (Body={id}).");
                for (int i = 0, len = _trackList.Length; i < len; i++)
                {
                    var jointType   = _trackList[i];
                    jointCreates[i] = _network.Create(rootElement.Id,
                                                      Util.CreateElementData(jointType.ToString(), _assetMap[jointType]));
                }

                Task
                .WhenAll(jointCreates)
                .ContinueWith(_ =>
                {
                    for (int i = 0, len = _trackList.Length; i < len; i++)
                    {
                        var element = jointCreates[i].Result;
                        Log.Information($"Created joint element (Body={id}, Element={element.Id})");

                        bodyElements.JointElements[_trackList[i]] = element;
                    }

                    Log.Information($"All joint elements created (Body={id})");

                    _bodyElements[id] = bodyElements;
                });
            });
        }
예제 #2
0
 /// <summary>
 /// Destroys a body Element.
 /// </summary>
 /// <param name="body"></param>
 private void DestroyBody(BodyElements body)
 {
     Log.Information($"Destroying body (Element={body.RootElement.Id})");
     try
     {
         _network
         .Destroy(body.RootElement.Id)
         .ContinueWith(_ =>
         {
             Log.Information($"Destruction successful (Element={body.RootElement.Id}");
         });
     }
     catch (Exception e)
     {
         Log.Error($"Error destroying body (Element={body.RootElement.Id}, Exception={e}");
     }
 }
예제 #3
0
파일: Util.cs 프로젝트: enklu/mamba
        /// <summary>
        /// Creates a BodyElements object, populated with ElementData.
        /// </summary>
        /// <param name="name">Element's name.</param>
        /// <param name="jointMap">Joint asset registration</param>
        /// <returns></returns>
        public static BodyElements CreateBodyElements(string name, Dictionary <JointType, string> jointMap)
        {
            var bodyElements = new BodyElements
            {
                RootElement = new ElementData
                {
                    Schema = new ElementSchemaData
                    {
                        Strings = new Dictionary <string, string> {
                            { "name", name }
                        }
                    },
                    Children = new ElementData[jointMap.Keys.Count]
                }
            };

            var i = 0;

            foreach (var kvp in jointMap)
            {
                var jointElement = new ElementData
                {
                    Type   = ElementTypes.Asset,
                    Schema = new ElementSchemaData
                    {
                        Strings = new Dictionary <string, string>
                        {
                            { "name", kvp.Key.ToString() },
                            { "assetSrc", kvp.Value }
                        }
                    }
                };
                bodyElements.RootElement.Children[i++] = jointElement;
                bodyElements.JointElements[kvp.Key]    = jointElement;
            }

            return(bodyElements);
        }