[4de1c7]: / app / resources / LeapSDK / v3_python27 / src / Bone.cs

Download this file

235 lines (220 with data), 7.1 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
/******************************************************************************\
* Copyright (C) 2012-2016 Leap Motion, Inc. All rights reserved. *
* Leap Motion proprietary and confidential. Not for distribution. *
* Use subject to the terms of the Leap Motion SDK Agreement available at *
* https://developer.leapmotion.com/sdk_agreement, or another agreement *
* between Leap Motion and you, your company or other organization. *
\******************************************************************************/
namespace Leap
{
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
/**
* The Bone class represents a tracked bone.
*
* All fingers contain 4 bones that make up the anatomy of the finger.
* Get valid Bone objects from a Finger object.
*
* Bones are ordered from base to tip, indexed from 0 to 3. Additionally, the
* bone's Type enum may be used to index a specific bone anatomically.
*
* \include Bone_iteration.txt
*
* The thumb does not have a base metacarpal bone and therefore contains a valid,
* zero length bone at that location.
* @since 2.0
*/
[Serializable]
public class Bone
{
/**
* Constructs a default Bone object.
*
* @since 2.0
*/
public Bone()
{
Type = BoneType.TYPE_INVALID;
}
/**
* Constructs a new Bone object.
*
* @param prevJoint The proximal end of the bone (closest to the body)
* @param nextJoint The distal end of the bone (furthest from the body)
* @param center The midpoint of the bone
* @param direction The unit direction vector pointing from prevJoint to nextJoint.
* @param length The estimated length of the bone.
* @param width The estimated average width of the bone.
* @param type The type of finger bone.
* @param basis The matrix representing the orientation of the bone.
* @since 3.0
*/
public Bone(Vector prevJoint,
Vector nextJoint,
Vector center,
Vector direction,
float length,
float width,
Bone.BoneType type,
LeapQuaternion rotation)
{
PrevJoint = prevJoint;
NextJoint = nextJoint;
Center = center;
Direction = direction;
Rotation = rotation;
Length = length;
Width = width;
Type = type;
}
/**
* Compare Bone object equality.
*
* Two Bone objects are equal if and only if both Bone objects represent the
* exact same physical bone in the same frame and both Bone objects are valid.
* @since 2.0
*/
public bool Equals(Bone other)
{
return Center == other.Center && Direction == other.Direction && Length == other.Length;
}
/**
* A string containing a brief, human readable description of the Bone object.
*
* \include Bone_toString.txt
*
* @returns A description of the Bone object as a string.
* @since 2.0
*/
public override string ToString()
{
return Enum.GetName(typeof(BoneType), this.Type) + " bone";
}
/**
* The base of the bone, closest to the wrist.
*
* In anatomical terms, this is the proximal end of the bone.
* \include Bone_prevJoint.txt
*
* @returns The Vector containing the coordinates of the previous joint position.
* @since 2.0
*/
public Vector PrevJoint;
/**
* The end of the bone, closest to the finger tip.
*
* In anatomical terms, this is the distal end of the bone.
*
* \include Bone_nextJoint.txt
*
* @returns The Vector containing the coordinates of the next joint position.
* @since 2.0
*/
public Vector NextJoint;
/**
* The midpoint of the bone.
*
* \include Bone_center.txt
*
* @returns The midpoint in the center of the bone.
* @since 2.0
*/
public Vector Center;
/**
* The normalized direction of the bone from base to tip.
*
* \include Bone_direction.txt
*
* @returns The normalized direction of the bone from base to tip.
* @since 2.0
*/
public Vector Direction;
/**
* The estimated length of the bone in millimeters.
*
* \include Bone_length.txt
*
* @returns The length of the bone in millimeters.
* @since 2.0
*/
public float Length;
/**
* The average width of the flesh around the bone in millimeters.
*
* \include Bone_width.txt
*
* @returns The width of the flesh around the bone in millimeters.
* @since 2.0
*/
public float Width;
/**
* The name of this bone.
*
* \include Bone_type.txt
*
* @returns The anatomical type of this bone as a member of the Bone::Type
* enumeration.
* @since 2.0
*/
public Bone.BoneType Type;
/**
* The orientation of this Bone as a Quaternion.
*
* @returns The Quaternion.
* @since 2.0
*/
public LeapQuaternion Rotation;
/**
* The orthonormal basis vectors for this Bone as a Matrix.
* The orientation of this Bone as a Quaternion.
*
* Basis vectors specify the orientation of a bone.
*
* **xBasis** Perpendicular to the longitudinal axis of the
* bone; exits the sides of the finger.
*
* **yBasis or up vector** Perpendicular to the longitudinal
* axis of the bone; exits the top and bottom of the finger. More positive
* in the upward direction.
*
* **zBasis** Aligned with the longitudinal axis of the bone.
* More positive toward the base of the finger.
*
* The bases provided for the right hand use the right-hand rule; those for
* the left hand use the left-hand rule. Thus, the positive direction of the
* x-basis is to the right for the right hand and to the left for the left
* hand. You can change from right-hand to left-hand rule by multiplying the
* z basis vector by -1.
*
* You can use the basis vectors for such purposes as measuring complex
* finger poses and skeletal animation.
*
* Note that converting the basis vectors directly into a quaternion
* representation is not mathematically valid. If you use quaternions,
* create them from the derived rotation matrix not directly from the bases.
*
* \include Bone_basis.txt
*
* @returns The basis of the bone as a matrix.
* @returns The Quaternion.
* @since 2.0
*/
public LeapTransform Basis { get { return new LeapTransform(PrevJoint, Rotation); } }
/**
* Enumerates the names of the bones.
*
* Members of this enumeration are returned by Bone::type() to identify a
* Bone object.
* @since 2.0
*/
public enum BoneType
{
TYPE_INVALID = -1,
TYPE_METACARPAL = 0,
TYPE_PROXIMAL = 1,
TYPE_INTERMEDIATE = 2,
TYPE_DISTAL = 3
}
}
}