1 | // -----------------------------------------------------------------------
|
---|
2 | // <copyright file="MessageHandPointer.cs" company="Microsoft">
|
---|
3 | // Copyright (c) Microsoft Corporation. All rights reserved.
|
---|
4 | // </copyright>
|
---|
5 | // -----------------------------------------------------------------------
|
---|
6 |
|
---|
7 | namespace Microsoft.Samples.Kinect.Webserver.Sensor.Serialization
|
---|
8 | {
|
---|
9 | using System;
|
---|
10 | using System.Collections.Generic;
|
---|
11 | using System.Diagnostics.CodeAnalysis;
|
---|
12 | using System.Globalization;
|
---|
13 |
|
---|
14 | /// <summary>
|
---|
15 | /// Serializable representation of a hand pointer.
|
---|
16 | /// </summary>
|
---|
17 | [SuppressMessage("StyleCop.CSharp.NamingRules", "SA1300:ElementMustBeginWithUpperCaseLetter", Justification = "Lower case names allowed for JSON serialization.")]
|
---|
18 | [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode", Justification = "Used by serialization code")]
|
---|
19 | public class MessageHandPointer
|
---|
20 | {
|
---|
21 | /// <summary>
|
---|
22 | /// User tracking Id corresponding to this hand pointer.
|
---|
23 | /// </summary>
|
---|
24 | [SuppressMessage("Microsoft.Naming", "CA1709:IdentifiersShouldBeCasedCorrectly", MessageId = "tracking", Justification = "Lower case names allowed for JSON serialization.")]
|
---|
25 | public int trackingId { get; set; }
|
---|
26 |
|
---|
27 | /// <summary>
|
---|
28 | /// Indicates whether this hand pointer refers to right or left hand.
|
---|
29 | /// </summary>
|
---|
30 | [SuppressMessage("Microsoft.Naming", "CA1709:IdentifiersShouldBeCasedCorrectly", MessageId = "hand", Justification = "Lower case names allowed for JSON serialization.")]
|
---|
31 | public string handType { get; set; }
|
---|
32 |
|
---|
33 | /// <summary>
|
---|
34 | /// Indicates which event type (grip/release) is currently triggered, if any.
|
---|
35 | /// </summary>
|
---|
36 | [SuppressMessage("Microsoft.Naming", "CA1709:IdentifiersShouldBeCasedCorrectly", MessageId = "hand", Justification = "Lower case names allowed for JSON serialization.")]
|
---|
37 | public string handEventType { get; set; }
|
---|
38 |
|
---|
39 | /// <summary>
|
---|
40 | /// Indicates whether this hand pointer is currently being tracked.
|
---|
41 | /// </summary>
|
---|
42 | [SuppressMessage("Microsoft.Naming", "CA1709:IdentifiersShouldBeCasedCorrectly", MessageId = "is", Justification = "Lower case names allowed for JSON serialization.")]
|
---|
43 | public bool isTracked { get; set; }
|
---|
44 |
|
---|
45 | /// <summary>
|
---|
46 | /// Indicates whether hand is one of possibly several candidates to be labeled as
|
---|
47 | /// the primary hand for the user.
|
---|
48 | /// </summary>
|
---|
49 | [SuppressMessage("Microsoft.Naming", "CA1709:IdentifiersShouldBeCasedCorrectly", MessageId = "is", Justification = "Lower case names allowed for JSON serialization.")]
|
---|
50 | public bool isActive { get; set; }
|
---|
51 |
|
---|
52 | /// <summary>
|
---|
53 | /// Indicates whether hand is within physical interaction region that maps to the
|
---|
54 | /// user interface.
|
---|
55 | /// </summary>
|
---|
56 | [SuppressMessage("Microsoft.Naming", "CA1709:IdentifiersShouldBeCasedCorrectly", MessageId = "is", Justification = "Lower case names allowed for JSON serialization.")]
|
---|
57 | public bool isInteractive { get; set; }
|
---|
58 |
|
---|
59 | /// <summary>
|
---|
60 | /// Indicates whether hand is currently performing "press" action.
|
---|
61 | /// </summary>
|
---|
62 | [SuppressMessage("Microsoft.Naming", "CA1709:IdentifiersShouldBeCasedCorrectly", MessageId = "is", Justification = "Lower case names allowed for JSON serialization.")]
|
---|
63 | public bool isPressed { get; set; }
|
---|
64 |
|
---|
65 | /// <summary>
|
---|
66 | /// Indicates whether this hand is the primary hand for corresponding user.
|
---|
67 | /// </summary>
|
---|
68 | [SuppressMessage("Microsoft.Naming", "CA1709:IdentifiersShouldBeCasedCorrectly", MessageId = "is", Justification = "Lower case names allowed for JSON serialization.")]
|
---|
69 | public bool isPrimaryHandOfUser { get; set; }
|
---|
70 |
|
---|
71 | /// <summary>
|
---|
72 | /// Indicates whether corresponding user is the primary user.
|
---|
73 | /// </summary>
|
---|
74 | [SuppressMessage("Microsoft.Naming", "CA1709:IdentifiersShouldBeCasedCorrectly", MessageId = "is", Justification = "Lower case names allowed for JSON serialization.")]
|
---|
75 | public bool isPrimaryUser { get; set; }
|
---|
76 |
|
---|
77 | /// <summary>
|
---|
78 | /// Gets interaction-adjusted X-coordinate of hand pointer position.
|
---|
79 | /// </summary>
|
---|
80 | /// <remarks>
|
---|
81 | /// 0.0 corresponds to left edge of interaction region and 1.0 corresponds to right edge
|
---|
82 | /// of interaction region, but values could be outside of this range.
|
---|
83 | /// </remarks>
|
---|
84 | [SuppressMessage("Microsoft.Naming", "CA1709:IdentifiersShouldBeCasedCorrectly", MessageId = "x", Justification = "Lower case names allowed for JSON serialization.")]
|
---|
85 | public double x { get; set; }
|
---|
86 |
|
---|
87 | /// <summary>
|
---|
88 | /// Gets interaction-adjusted Y-coordinate of hand pointer position.
|
---|
89 | /// </summary>
|
---|
90 | /// <remarks>
|
---|
91 | /// 0.0 corresponds to top edge of interaction region and 1.0 corresponds to bottom edge
|
---|
92 | /// of interaction region, but values could be outside of this range.
|
---|
93 | /// </remarks>
|
---|
94 | [SuppressMessage("Microsoft.Naming", "CA1709:IdentifiersShouldBeCasedCorrectly", MessageId = "y", Justification = "Lower case names allowed for JSON serialization.")]
|
---|
95 | public double y { get; set; }
|
---|
96 |
|
---|
97 | /// <summary>
|
---|
98 | /// Gets a interaction-adjusted measure of how much pressing is being performed by hand.
|
---|
99 | /// </summary>
|
---|
100 | /// <remarks>
|
---|
101 | /// 0.0 means that hand is not performing a press action at all, and 1.0 means that
|
---|
102 | /// hand is at the trigger point for press action, but values could be greater than 1.0.
|
---|
103 | /// </remarks>
|
---|
104 | [SuppressMessage("Microsoft.Naming", "CA1709:IdentifiersShouldBeCasedCorrectly", MessageId = "press", Justification = "Lower case names allowed for JSON serialization.")]
|
---|
105 | public double pressExtent { get; set; }
|
---|
106 |
|
---|
107 | /// <summary>
|
---|
108 | /// Gets X-coordinate of hand pointer position.
|
---|
109 | /// </summary>
|
---|
110 | /// <remarks>
|
---|
111 | /// 0.0 corresponds to left edge of interaction region and 1.0 corresponds to right edge
|
---|
112 | /// of interaction region, but values could be outside of this range.
|
---|
113 | /// </remarks>
|
---|
114 | [SuppressMessage("Microsoft.Naming", "CA1709:IdentifiersShouldBeCasedCorrectly", MessageId = "raw", Justification = "Lower case names allowed for JSON serialization.")]
|
---|
115 | public double rawX { get; set; }
|
---|
116 |
|
---|
117 | /// <summary>
|
---|
118 | /// Gets Y-coordinate of hand pointer position.
|
---|
119 | /// </summary>
|
---|
120 | /// <remarks>
|
---|
121 | /// 0.0 corresponds to top edge of interaction region and 1.0 corresponds to bottom edge
|
---|
122 | /// of interaction region, but values could be outside of this range.
|
---|
123 | /// </remarks>
|
---|
124 | [SuppressMessage("Microsoft.Naming", "CA1709:IdentifiersShouldBeCasedCorrectly", MessageId = "raw", Justification = "Lower case names allowed for JSON serialization.")]
|
---|
125 | public double rawY { get; set; }
|
---|
126 |
|
---|
127 | /// <summary>
|
---|
128 | /// Gets a measure of how much pressing is being performed by hand.
|
---|
129 | /// </summary>
|
---|
130 | /// <remarks>
|
---|
131 | /// 0.0 means that hand is not performing a press action at all, and 1.0 means that
|
---|
132 | /// hand is at the trigger point for press action, but values could be greater than 1.0.
|
---|
133 | /// </remarks>
|
---|
134 | [SuppressMessage("Microsoft.Naming", "CA1709:IdentifiersShouldBeCasedCorrectly", MessageId = "raw", Justification = "Lower case names allowed for JSON serialization.")]
|
---|
135 | public double rawZ { get; set; }
|
---|
136 |
|
---|
137 | public static implicit operator MessageHandPointer(Dictionary<string, object> handPointerDictionary)
|
---|
138 | {
|
---|
139 | return FromDictionary(handPointerDictionary);
|
---|
140 | }
|
---|
141 |
|
---|
142 | public static MessageHandPointer FromDictionary(Dictionary<string, object> handPointerDictionary)
|
---|
143 | {
|
---|
144 | if (handPointerDictionary == null)
|
---|
145 | {
|
---|
146 | throw new ArgumentNullException("handPointerDictionary");
|
---|
147 | }
|
---|
148 |
|
---|
149 | var messageHandPointer = new MessageHandPointer
|
---|
150 | {
|
---|
151 | trackingId = (int)handPointerDictionary["trackingId"],
|
---|
152 | handType = (string)handPointerDictionary["handType"],
|
---|
153 | handEventType = (string)handPointerDictionary["handEventType"],
|
---|
154 | isTracked = (bool)handPointerDictionary["isTracked"],
|
---|
155 | isActive = (bool)handPointerDictionary["isActive"],
|
---|
156 | isInteractive = (bool)handPointerDictionary["isInteractive"],
|
---|
157 | isPressed = (bool)handPointerDictionary["isPressed"],
|
---|
158 | isPrimaryHandOfUser = (bool)handPointerDictionary["isPrimaryHandOfUser"],
|
---|
159 | isPrimaryUser = (bool)handPointerDictionary["isPrimaryUser"],
|
---|
160 | x =
|
---|
161 | double.Parse(
|
---|
162 | handPointerDictionary["x"].ToString(), CultureInfo.InvariantCulture),
|
---|
163 | y =
|
---|
164 | double.Parse(
|
---|
165 | handPointerDictionary["y"].ToString(), CultureInfo.InvariantCulture),
|
---|
166 | pressExtent =
|
---|
167 | double.Parse(
|
---|
168 | handPointerDictionary["pressExtent"].ToString(),
|
---|
169 | CultureInfo.InvariantCulture),
|
---|
170 | rawX =
|
---|
171 | double.Parse(
|
---|
172 | handPointerDictionary["rawX"].ToString(), CultureInfo.InvariantCulture),
|
---|
173 | rawY =
|
---|
174 | double.Parse(
|
---|
175 | handPointerDictionary["rawY"].ToString(), CultureInfo.InvariantCulture),
|
---|
176 | rawZ =
|
---|
177 | double.Parse(
|
---|
178 | handPointerDictionary["rawZ"].ToString(), CultureInfo.InvariantCulture)
|
---|
179 | };
|
---|
180 | return messageHandPointer;
|
---|
181 | }
|
---|
182 | }
|
---|
183 | } |
---|