-
Notifications
You must be signed in to change notification settings - Fork 7
/
Leap.h
1617 lines (1425 loc) · 73 KB
/
Leap.h
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
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/******************************************************************************\
* Copyright (C) 2012-2013 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. *
\******************************************************************************/
#if !defined(__Leap_h__)
#define __Leap_h__
#include "LeapMath.h"
#include <string>
#include <vector>
// Define integer types for Visual Studio 2008 and earlier
#if defined(_MSC_VER) && (_MSC_VER < 1600)
typedef __int32 int32_t;
typedef __int64 int64_t;
typedef unsigned __int32 uint32_t;
typedef unsigned __int64 uint64_t;
#else
#include <stdint.h>
#endif
// Define Leap export macros
#if defined(_WIN32) // Windows
#if LEAP_API_INTERNAL
#define LEAP_EXPORT
#elif LEAP_API_IMPLEMENTATION
#define LEAP_EXPORT __declspec(dllexport)
#else
#define LEAP_EXPORT __declspec(dllimport)
#endif
#define LEAP_EXPORT_CLASS
#define LEAP_EXPORT_PLUGIN __declspec(dllexport)
#elif defined(__APPLE__) // Mac OS
#define LEAP_EXPORT __attribute__((visibility("default")))
#define LEAP_EXPORT_CLASS __attribute__((visibility("default")))
#define LEAP_EXPORT_PLUGIN __attribute__((visibility("default")))
#else // GNU/Linux
#define LEAP_EXPORT
#define LEAP_EXPORT_CLASS
#define LEAP_EXPORT_PLUGIN
#endif
namespace Leap {
// Interface for internal use only
class LEAP_EXPORT_CLASS Interface {
public:
struct Implementation {
LEAP_EXPORT virtual ~Implementation() {}
};
protected:
LEAP_EXPORT Interface(void* owner);
LEAP_EXPORT Interface(Implementation* reference, void* owner);
LEAP_EXPORT Interface(const Interface& rhs);
LEAP_EXPORT Interface& operator=(const Interface& rhs);
LEAP_EXPORT virtual ~Interface();
template<typename T> T* get() const { return static_cast<T*>(reference()); }
class SharedObject* m_object;
private:
LEAP_EXPORT Implementation* reference() const;
};
// Forward declarations for internal use only
class PointableImplementation;
class FingerImplementation;
class ToolImplementation;
class HandImplementation;
class ScreenImplementation;
class FrameImplementation;
class ControllerImplementation;
template<typename T> class ListBaseImplementation;
// Forward declarations
class PointableList;
class FingerList;
class ToolList;
class Hand;
class Frame;
class Screen;
class Listener;
/// The Pointable class reports the physical characteristics of a detected finger or tool.
///
/// Both fingers and tools are classified as Pointable objects. Use the Pointable::isFinger()
/// function to determine whether a Pointable object represents a finger. Use the
/// Pointable::isTool() function to determine whether a Pointable object represents a tool.
/// The Leap classifies a detected entity as a tool when it is thinner, straighter, and longer
/// than a typical finger.
///
/// Note that Pointable objects can be invalid, which means that they do not contain
/// valid tracking data and do not correspond to a physical entity. Invalid Pointable
/// objects can be the result of asking for a Pointable object using an ID from an
/// earlier frame when no Pointable objects with that ID exist in the current frame.
/// A Pointable object created from the Pointable constructor is also invalid.
/// Test for validity with the Pointable::isValid() function.
class Pointable : public Interface {
public:
#if !defined(SWIG)
// For internal use only.
Pointable(PointableImplementation*);
// For internal use only.
Pointable(FingerImplementation*);
// For internal use only.
Pointable(ToolImplementation*);
#endif
/// Constructs a Pointable object.
///
/// An uninitialized pointable is considered invalid.
/// Get valid Pointable objects from a Frame or a Hand object.
LEAP_EXPORT Pointable();
/// A unique ID assigned to this Pointable object, whose value remains the
/// same across consecutive frames while the tracked finger or tool remains
/// visible. If tracking is lost (for example, when a finger is occluded by
/// another finger or when it is withdrawn from the Leap field of view), the
/// Leap may assign a new ID when it detects the entity in a future frame.
///
/// Use the ID value with the Frame::pointable() function to find this
/// Pointable object in future frames.
///
/// @returns The ID assigned to this Pointable object.
LEAP_EXPORT int32_t id() const;
/// The Frame associated with this Pointable object.
///
/// @returns The associated Frame object, if available; otherwise,
/// an invalid Frame object is returned.
LEAP_EXPORT Frame frame() const;
/// The Hand associated with this finger or tool.
///
/// @returns The associated Hand object, if available; otherwise,
/// an invalid Hand object is returned.
LEAP_EXPORT Hand hand() const;
/// The tip position in millimeters from the Leap origin.
///
/// @returns The Vector containing the coordinates of the tip position.
LEAP_EXPORT Vector tipPosition() const;
/// The rate of change of the tip position in millimeters/second.
///
/// @returns The Vector containing the coordinates of the tip velocity.
LEAP_EXPORT Vector tipVelocity() const;
/// The direction in which this finger or tool is pointing.
///
/// The direction is expressed as a unit vector pointing in the same
/// direction as the tip.
///
/// \image html images/Leap_Finger_Model.png
///
/// @returns The Vector pointing in the same direction as the tip of this
/// Pointable object.
LEAP_EXPORT Vector direction() const;
/// The estimated width of the finger or tool in millimeters.
///
/// The reported width is the average width of the visible portion of the
/// finger or tool from the hand to the tip. If the width isn't known,
/// then a value of 0 is returned.
///
/// @returns The estimated width of this Pointable object.
LEAP_EXPORT float width() const;
/// The estimated length of the finger or tool in millimeters.
///
/// The reported length is the visible length of the finger or tool from the
/// hand to tip. If the length isn't known, then a value of 0 is returned.
///
/// @returns The estimated length of this Pointable object.
LEAP_EXPORT float length() const;
/// Whether or not the Pointable is believed to be a finger.
/// Fingers are generally shorter, thicker, and less straight than tools.
///
/// @returns True, if this Pointable is classified as a finger.
LEAP_EXPORT bool isFinger() const;
/// Whether or not the Pointable is believed to be a tool.
/// Tools are generally longer, thinner, and straighter than fingers.
///
/// @returns True, if this Pointable is classified as a tool.
LEAP_EXPORT bool isTool() const;
/// Reports whether this is a valid Pointable object.
///
/// @returns True, if this Pointable object contains valid tracking data.
LEAP_EXPORT bool isValid() const;
/// Returns an invalid Pointable object.
///
/// You can use the instance returned by this function in comparisons testing
/// whether a given Pointable instance is valid or invalid. (You can also use the
/// Pointable::isValid() function.)
///
/// @returns The invalid Pointable instance.
LEAP_EXPORT static const Pointable& invalid();
/// Compare Pointable object equality.
/// Two Pointable objects are equal if and only if both Pointable objects represent the
/// exact same physical entities in the same frame and both Pointable objects are valid.
LEAP_EXPORT bool operator==(const Pointable&) const;
/// Compare Pointable object inequality.
/// Two Pointable objects are equal if and only if both Pointable objects represent the
/// exact same physical entities in the same frame and both Pointable objects are valid.
LEAP_EXPORT bool operator!=(const Pointable&) const;
/// Writes a brief, human readable description of the Pointable object to an output stream.
LEAP_EXPORT friend std::ostream& operator<<(std::ostream&, const Pointable&);
/// A string containing a brief, human readable description of the Pointable object.
///
/// @returns A description of the Pointable object as a string.
LEAP_EXPORT std::string toString() const;
};
/// The Finger class represents a tracked finger.
///
/// Fingers are Pointable objects that the Leap has classified as a finger.
/// Get valid Finger objects from a Frame or a Hand object.
///
/// Note that Finger objects can be invalid, which means that they do not contain
/// valid tracking data and do not correspond to a physical finger. Invalid Finger
/// objects can be the result of asking for a Finger object using an ID from an
/// earlier frame when no Finger objects with that ID exist in the current frame.
/// A Finger object created from the Finger constructor is also invalid.
/// Test for validity with the Finger::isValid() function.
class Finger : public Pointable {
public:
#if !defined(SWIG)
// For internal use only.
Finger(FingerImplementation*);
#endif
/// Constructs a Finger object.
///
/// An uninitialized finger is considered invalid.
/// Get valid Finger objects from a Frame or a Hand object.
LEAP_EXPORT Finger();
/// If the specified Pointable object represents a finger, creates a copy
/// of it as a Finger object; otherwise, creates an invalid Finger object.
LEAP_EXPORT explicit Finger(const Pointable&);
/// Returns an invalid Finger object.
///
/// You can use the instance returned by this function in comparisons testing
/// whether a given Finger instance is valid or invalid. (You can also use the
/// Finger::isValid() function.)
///
/// @returns The invalid Finger instance.
LEAP_EXPORT static const Finger& invalid();
/// A string containing a brief, human readable description of the Finger object.
///
/// @returns A description of the Finger object as a string.
LEAP_EXPORT std::string toString() const;
};
/// The Tool class represents a tracked tool.
///
/// Tools are Pointable objects that the Leap has classified as a tool.
/// Tools are longer, thinner, and straighter than a typical finger.
/// Get valid Tool objects from a Frame or a Hand object.
///
/// \image html images/Leap_Tool.png
///
/// Note that Tool objects can be invalid, which means that they do not contain
/// valid tracking data and do not correspond to a physical tool. Invalid Tool
/// objects can be the result of asking for a Tool object using an ID from an
/// earlier frame when no Tool objects with that ID exist in the current frame.
/// A Tool object created from the Tool constructor is also invalid.
/// Test for validity with the Tool::isValid() function.
class Tool : public Pointable {
public:
#if !defined(SWIG)
// For internal use only.
Tool(ToolImplementation*);
#endif
/// Constructs a Tool object.
///
/// An uninitialized tool is considered invalid.
/// Get valid Tool objects from a Frame or a Hand object.
LEAP_EXPORT Tool();
/// If the specified Pointable object represents a tool, creates a copy
/// of it as a Tool object; otherwise, creates an invalid Tool object.
LEAP_EXPORT explicit Tool(const Pointable&);
/// Returns an invalid Tool object.
///
/// You can use the instance returned by this function in comparisons testing
/// whether a given Tool instance is valid or invalid. (You can also use the
/// Tool::isValid() function.)
///
/// @returns The invalid Tool instance.
LEAP_EXPORT static const Tool& invalid();
/// A string containing a brief, human readable description of the Tool object.
///
/// @returns A description of the Tool object as a string.
LEAP_EXPORT std::string toString() const;
};
/// The Hand class reports the physical characteristics of a detected hand.
///
/// Hand tracking data includes a palm position and velocity; vectors for
/// the palm normal and direction to the fingers; properties of a sphere fit
/// to the hand; and lists of the attached fingers and tools.
///
/// Note that Hand objects can be invalid, which means that they do not contain
/// valid tracking data and do not correspond to a physical entity. Invalid Hand
/// objects can be the result of asking for a Hand object using an ID from an
/// earlier frame when no Hand objects with that ID exist in the current frame.
/// A Hand object created from the Hand constructor is also invalid.
/// Test for validity with the Hand::isValid() function.
class Hand : public Interface {
public:
#if !defined(SWIG)
// For internal use only.
Hand(HandImplementation*);
#endif
/// Constructs a Hand object.
///
/// An uninitialized hand is considered invalid.
/// Get valid Hand objects from a Frame object.
LEAP_EXPORT Hand();
/// A unique ID assigned to this Hand object, whose value remains the same
/// across consecutive frames while the tracked hand remains visible. If
/// tracking is lost (for example, when a hand is occluded by another hand
/// or when it is withdrawn from or reaches the edge of the Leap field of view),
/// the Leap may assign a new ID when it detects the hand in a future frame.
///
/// Use the ID value with the Frame::hand() function to find this Hand object
/// in future frames.
///
/// @returns The ID of this hand.
LEAP_EXPORT int32_t id() const;
/// The Frame associated with this Hand.
///
/// @returns The associated Frame object, if available; otherwise,
/// an invalid Frame object is returned.
LEAP_EXPORT Frame frame() const;
/// The list of Pointable objects (fingers and tools) detected in this frame
/// that are associated with this hand, given in arbitrary order. The list
/// can be empty if no fingers or tools associated with this hand are detected.
///
/// Use the Pointable::isFinger() function to determine whether or not an
/// item in the list represents a finger. Use the Pointable::isTool() function
/// to determine whether or not an item in the list represents a tool.
/// You can also get only fingers using the Hand::fingers() function or
/// only tools using the Hand::tools() function.
///
/// @returns The PointableList containing all Pointable objects associated with this hand.
LEAP_EXPORT PointableList pointables() const;
/// The Pointable object with the specified ID associated with this hand.
///
/// Use the Hand::pointable() function to retrieve a Pointable object
/// associated with this hand using an ID value obtained from a previous frame.
/// This function always returns a Pointable object, but if no finger or tool
/// with the specified ID is present, an invalid Pointable object is returned.
///
/// Note that ID values persist across frames, but only until tracking of a
/// particular object is lost. If tracking of a finger or tool is lost and subsequently
/// regained, the new Pointable object representing that finger or tool may have a
/// different ID than that representing the finger or tool in an earlier frame.
///
/// @param id The ID value of a Pointable object from a previous frame.
/// @returns The Pointable object with the matching ID if one exists for this
/// hand in this frame; otherwise, an invalid Pointable object is returned.
LEAP_EXPORT Pointable pointable(int32_t id) const;
/// The list of Finger objects detected in this frame that are attached to
/// this hand, given in arbitrary order.
/// The list can be empty if no fingers attached to this hand are detected.
///
/// @returns The FingerList containing all Finger objects attached to this hand.
LEAP_EXPORT FingerList fingers() const;
/// The Finger object with the specified ID attached to this hand.
///
/// Use the Hand::finger() function to retrieve a Finger object attached to
/// this hand using an ID value obtained from a previous frame.
/// This function always returns a Finger object, but if no finger
/// with the specified ID is present, an invalid Finger object is returned.
///
/// Note that ID values persist across frames, but only until tracking of a
/// particular object is lost. If tracking of a finger is lost and subsequently
/// regained, the new Finger object representing that finger may have a
/// different ID than that representing the finger in an earlier frame.
///
/// @param id The ID value of a Finger object from a previous frame.
/// @returns The Finger object with the matching ID if one exists for this
/// hand in this frame; otherwise, an invalid Finger object is returned.
LEAP_EXPORT Finger finger(int32_t id) const;
/// The list of Tool objects detected in this frame that are held by this
/// hand, given in arbitrary order.
/// The list can be empty if no tools held by this hand are detected.
///
/// @returns The ToolList containing all Tool objects held by this hand.
LEAP_EXPORT ToolList tools() const;
/// The Tool object with the specified ID held by this hand.
///
/// Use the Hand::tool() function to retrieve a Tool object held by
/// this hand using an ID value obtained from a previous frame.
/// This function always returns a Tool object, but if no tool
/// with the specified ID is present, an invalid Tool object is returned.
///
/// Note that ID values persist across frames, but only until tracking of a
/// particular object is lost. If tracking of a tool is lost and subsequently
/// regained, the new Tool object representing that tool may have a
/// different ID than that representing the tool in an earlier frame.
///
/// @param id The ID value of a Tool object from a previous frame.
/// @returns The Tool object with the matching ID if one exists for this
/// hand in this frame; otherwise, an invalid Tool object is returned.
LEAP_EXPORT Tool tool(int32_t id) const;
/// The center position of the palm in millimeters from the Leap origin.
///
/// @returns The Vector representing the coordinates of the palm position.
LEAP_EXPORT Vector palmPosition() const;
/// The rate of change of the palm position in millimeters/second.
///
/// @returns The Vector representing the coordinates of the palm velocity.
LEAP_EXPORT Vector palmVelocity() const;
/// The normal vector to the palm. If your hand is flat, this vector will
/// point downward, or "out" of the front surface of your palm.
///
/// \image html images/Leap_Palm_Vectors.png
///
/// The direction is expressed as a unit vector pointing in the same
/// direction as the palm normal (that is, a vector orthogonal to the palm).
///
/// @returns The Vector normal to the plane formed by the palm.
LEAP_EXPORT Vector palmNormal() const;
/// The direction from the palm position toward the fingers.
///
/// The direction is expressed as a unit vector pointing in the same
/// direction as the directed line from the palm position to the fingers.
///
/// @returns The Vector pointing from the palm position toward the fingers.
LEAP_EXPORT Vector direction() const;
/// The center of a sphere fit to the curvature of this hand.
///
/// This sphere is placed roughly as if the hand were holding a ball.
///
/// \image html images/Leap_Hand_Ball.png
///
/// @returns The Vector representing the center position of the sphere.
LEAP_EXPORT Vector sphereCenter() const;
/// The radius of a sphere fit to the curvature of this hand.
///
/// This sphere is placed roughly as if the hand were holding a ball. Thus the
/// size of the sphere decreases as the fingers are curled into a fist.
/// @returns The radius of the sphere in millimeters.
LEAP_EXPORT float sphereRadius() const;
/// The change of position of this hand between the current frame and
/// the specified frame.
///
/// The returned translation vector provides the magnitude and direction of
/// the movement in millimeters.
///
/// If a corresponding Hand object is not found in sinceFrame, or if either
/// this frame or sinceFrame are invalid Frame objects, then this method
/// returns a zero vector.
///
/// @param sinceFrame The starting frame for computing the translation.
/// @returns A Vector representing the heuristically determined change in
/// hand position between the current frame and that specified in the
/// sinceFrame parameter.
LEAP_EXPORT Vector translation(const Frame& sinceFrame) const;
/// The axis of rotation derived from the change in orientation of this
/// hand, and any associated fingers and tools, between the current frame
/// and the specified frame.
///
/// The returned direction vector is normalized.
///
/// If a corresponding Hand object is not found in sinceFrame, or if either
/// this frame or sinceFrame are invalid Frame objects, then this method
/// returns a zero vector.
///
/// @param sinceFrame The starting frame for computing the relative rotation.
/// @returns A normalized direction Vector representing the heuristically
/// determined axis of rotational change of the hand between the current
/// frame and that specified in the sinceFrame parameter.
LEAP_EXPORT Vector rotationAxis(const Frame& sinceFrame) const;
/// The angle of rotation around the rotation axis derived from the change
/// in orientation of this hand, and any associated fingers and tools,
/// between the current frame and the specified frame.
///
/// The returned angle is expressed in radians measured clockwise around the
/// rotation axis (using the right-hand rule) between the start and end frames.
/// The value is always between 0 and pi radians (0 and 180 degrees).
///
/// If a corresponding Hand object is not found in sinceFrame, or if either
/// this frame or sinceFrame are invalid Frame objects, then the angle of
/// rotation is zero.
///
/// @param sinceFrame The starting frame for computing the relative rotation.
/// @returns A positive value representing the heuristically determined
/// rotational change of the hand between the current frame and that
/// specified in the sinceFrame parameter.
LEAP_EXPORT float rotationAngle(const Frame& sinceFrame) const;
/// The angle of rotation around the specified axis derived from the change
/// in orientation of this hand, and any associated fingers and tools,
/// between the current frame and the specified frame.
///
/// The returned angle is expressed in radians measured clockwise around the
/// rotation axis (using the right-hand rule) between the start and end frames.
/// The value is always between -pi and pi radians (-180 and 180 degrees).
///
/// If a corresponding Hand object is not found in sinceFrame, or if either
/// this frame or sinceFrame are invalid Frame objects, then the angle of
/// rotation is zero.
///
/// @param sinceFrame The starting frame for computing the relative rotation.
/// @param axis The axis to measure rotation around.
/// @returns A value representing the heuristically determined rotational
/// change of the hand between the current frame and that specified in the
/// sinceFrame parameter around the specified axis.
LEAP_EXPORT float rotationAngle(const Frame& sinceFrame, const Vector& axis) const;
/// The transform matrix expressing the rotation derived from the change
/// in orientation of this hand, and any associated fingers and tools,
/// between the current frame and the specified frame.
///
/// If a corresponding Hand object is not found in sinceFrame, or if either
/// this frame or sinceFrame are invalid Frame objects, then this method
/// returns an identity matrix.
///
/// @param sinceFrame The starting frame for computing the relative rotation.
/// @returns A transformation Matrix representing the heuristically determined
/// rotational change of the hand between the current frame and that specified
/// in the sinceFrame parameter.
LEAP_EXPORT Matrix rotationMatrix(const Frame& sinceFrame) const;
/// The scale factor derived from this hand's motion between the current frame
/// and the specified frame.
///
/// The scale factor is always positive. A value of 1.0 indicates no
/// scaling took place. Values between 0.0 and 1.0 indicate contraction
/// and values greater than 1.0 indicate expansion.
///
/// The Leap derives scaling from the relative inward or outward motion of
/// a hand and its associated fingers and tools (independent of translation
/// and rotation).
///
/// If a corresponding Hand object is not found in sinceFrame, or if either
/// this frame or sinceFrame are invalid Frame objects, then this method
/// returns 1.0.
///
/// @param sinceFrame The starting frame for computing the relative scaling.
/// @returns A positive value representing the heuristically determined
/// scaling change ratio of the hand between the current frame and that
/// specified in the sinceFrame parameter.
LEAP_EXPORT float scaleFactor(const Frame& sinceFrame) const;
/// Reports whether this is a valid Hand object.
///
/// @returns True, if this Hand object contains valid tracking data.
LEAP_EXPORT bool isValid() const;
/// Returns an invalid Hand object.
///
/// You can use the instance returned by this function in comparisons testing
/// whether a given Hand instance is valid or invalid. (You can also use the
/// Hand::isValid() function.)
///
/// @returns The invalid Hand instance.
LEAP_EXPORT static const Hand& invalid();
/// Compare Hand object equality.
/// Two Hand objects are equal if and only if both Hand objects represent the
/// exact same physical hand in the same frame and both Hand objects are valid.
LEAP_EXPORT bool operator==(const Hand&) const;
/// Compare Hand object inequality.
/// Two Hand objects are equal if and only if both Hand objects represent the
/// exact same physical hand in the same frame and both Hand objects are valid.
LEAP_EXPORT bool operator!=(const Hand&) const;
/// Writes a brief, human readable description of the Hand object to an output stream.
LEAP_EXPORT friend std::ostream& operator<<(std::ostream&, const Hand&);
/// A string containing a brief, human readable description of the Hand object.
///
/// @returns A description of the Hand as a string.
LEAP_EXPORT std::string toString() const;
};
// For internal use only.
template<typename L, typename T>
class ConstListIterator {
public:
ConstListIterator<L,T>(const L& list, int index) : m_list(list), m_index(index) {}
const T operator*() const { return m_list[m_index]; }
const ConstListIterator<L,T>& operator++() { ++m_index; return *this; }
bool operator!=(const ConstListIterator<L,T>& rhs) const { return m_index != rhs.m_index; }
private:
const L& m_list;
int m_index;
};
/// The PointableList class represents a list of Pointable objects.
///
/// Pointable objects include entities that can be pointed, such as fingers and tools.
///
/// Get a PointableList object by calling Frame::pointables().
class PointableList : public Interface {
public:
// For internal use only.
PointableList(const ListBaseImplementation<Pointable>&);
/// Constructs an empty list of pointable entities.
LEAP_EXPORT PointableList();
/// Returns the number of pointable entities in this list.
/// @returns The number of pointable entities in this list.
LEAP_EXPORT int count() const;
/// Reports whether the list is empty.
/// @returns True, if the list has no members.
LEAP_EXPORT bool empty() const;
/// Access a list member by its position in the list.
/// @param index The zero-based list position index.
/// @returns The Pointable object at the specified index.
LEAP_EXPORT Pointable operator[](int index) const;
/// Appends the members of the specifed PointableList to this PointableList.
/// @param other A PointableList object containing Pointable objects
/// to append to the end of this PointableList.
LEAP_EXPORT PointableList& append(const PointableList& other);
/// Appends the members of the specifed FingerList to this PointableList.
/// @param other A FingerList object containing Finger objects
/// to append to the end of this PointableList.
LEAP_EXPORT PointableList& append(const FingerList& other);
/// Appends the members of the specifed ToolList to this PointableList.
/// @param other A ToolList object containing Tool objects
/// to append to the end of this PointableList.
LEAP_EXPORT PointableList& append(const ToolList& other);
/// A C++ iterator type for PointableList objects.
typedef ConstListIterator<PointableList, Pointable> const_iterator;
/// The C++ iterator set to the beginning of this PointableList.
LEAP_EXPORT const_iterator begin() const;
/// The C++ iterator set to the end of this PointableList.
LEAP_EXPORT const_iterator end() const;
};
/// The FingerList class represents a list of Finger objects.
///
/// Get a FingerList object by calling Frame::fingers().
class FingerList : public Interface {
public:
// For internal use only.
FingerList(const ListBaseImplementation<Finger>&);
/// Constructs an empty list of fingers.
LEAP_EXPORT FingerList();
/// Returns the number of fingers in this list.
/// @returns The number of fingers in this list.
LEAP_EXPORT int count() const;
/// Reports whether the list is empty.
/// @returns True, if the list has no members.
LEAP_EXPORT bool empty() const;
/// Access a list member by its position in the list.
/// @param index The zero-based list position index.
/// @returns The Finger object at the specified index.
LEAP_EXPORT Finger operator[](int index) const;
/// Appends the members of the specifed FingerList to this FingerList.
/// @param other A FingerList object containing Finger objects
/// to append to the end of this FingerList.
LEAP_EXPORT FingerList& append(const FingerList& other);
/// A C++ iterator type for FingerList objects.
typedef ConstListIterator<FingerList, Finger> const_iterator;
/// The C++ iterator set to the beginning of this FingerList.
LEAP_EXPORT const_iterator begin() const;
/// The C++ iterator set to the end of this FingerList.
LEAP_EXPORT const_iterator end() const;
};
/// The ToolList class represents a list of Tool objects.
///
/// Get a ToolList object by calling Frame::tools().
class ToolList : public Interface {
public:
// For internal use only.
ToolList(const ListBaseImplementation<Tool>&);
/// Constructs an empty list of tools.
LEAP_EXPORT ToolList();
/// Returns the number of tools in this list.
/// @returns The number of tools in this list.
LEAP_EXPORT int count() const;
/// Reports whether the list is empty.
/// @returns True, if the list has no members.
LEAP_EXPORT bool empty() const;
/// Access a list member by its position in the list.
/// @param index The zero-based list position index.
/// @returns The Tool object at the specified index.
LEAP_EXPORT Tool operator[](int index) const;
/// Appends the members of the specifed ToolList to this ToolList.
/// @param other A ToolList object containing Tool objects
/// to append to the end of this ToolList.
LEAP_EXPORT ToolList& append(const ToolList& other);
/// A C++ iterator type for ToolList objects.
typedef ConstListIterator<ToolList, Tool> const_iterator;
/// The C++ iterator set to the beginning of this ToolList.
LEAP_EXPORT const_iterator begin() const;
/// The C++ iterator set to the end of this ToolList.
LEAP_EXPORT const_iterator end() const;
};
/// The HandList class represents a list of Hand objects.
///
/// Get a HandList object by calling Frame::hands().
class HandList : public Interface {
public:
// For internal use only.
HandList(const ListBaseImplementation<Hand>&);
/// Constructs an empty list of hands.
LEAP_EXPORT HandList();
/// Returns the number of hands in this list.
/// @returns The number of hands in this list.
LEAP_EXPORT int count() const;
/// Reports whether the list is empty.
/// @returns True, if the list has no members.
LEAP_EXPORT bool empty() const;
/// Access a list member by its position in the list.
/// @param index The zero-based list position index.
/// @returns The Hand object at the specified index.
LEAP_EXPORT Hand operator[](int index) const;
/// Appends the members of the specifed HandList to this HandList.
/// @param other A HandList object containing Hand objects
/// to append to the end of this HandList.
LEAP_EXPORT HandList& append(const HandList& other);
/// A C++ iterator type for this HandList objects.
typedef ConstListIterator<HandList, Hand> const_iterator;
/// The C++ iterator set to the beginning of this HandList.
LEAP_EXPORT const_iterator begin() const;
/// The C++ iterator set to the end of this HandList.
LEAP_EXPORT const_iterator end() const;
};
/// The ScreenList class represents a list of Screen objects.
///
/// Get a ScreenList object by calling Controller::calibratedScreens().
class ScreenList : public Interface {
public:
// For internal use only.
ScreenList(const ListBaseImplementation<Screen>&);
/// Constructs an empty list of screens.
LEAP_EXPORT ScreenList();
/// Returns the number of screens in this list.
/// @returns The number of screens in this list.
LEAP_EXPORT int count() const;
/// Reports whether the list is empty.
/// @returns True, if the list has no members.
LEAP_EXPORT bool empty() const;
/// Access a list member by its position in the list.
/// @param index The zero-based list position index.
/// @returns The Screen object at the specified index.
LEAP_EXPORT Screen operator[](int index) const;
/// A C++ iterator type for this ScreenList objects.
typedef ConstListIterator<ScreenList, Screen> const_iterator;
/// The C++ iterator set to the beginning of this ScreenList.
LEAP_EXPORT const_iterator begin() const;
/// The C++ iterator set to the end of this ScreenList.
LEAP_EXPORT const_iterator end() const;
/// Gets the closest Screen intercepting a ray projecting from the specified
/// Pointable object.
///
/// The projected ray emanates from the Pointable tipPosition along the
/// Pointable's direction vector. If the projected ray does not intersect
/// any screen surface directly, then the Leap checks for intersection with
/// the planes extending from the surfaces of the known screens
/// and returns the Screen with the closest intersection.
///
/// If no intersections are found (i.e. the ray is directed parallel to or
/// away from all known screens), then an invalid Screen object is
/// returned.
///
/// @param pointable The Pointable object to check for screen intersection.
/// @returns The closest Screen the specified Pointable object is pointing
/// toward.
LEAP_EXPORT Screen closestScreenHit(const Pointable& pointable) const;
};
/// The Screen class represents a computer monitor screen.
///
/// The Screen class reports characteristics describing the position and
/// orientation of the monitor screen within the Leap coordinate system. These
/// characteristics include the bottom-left corner position of the screen,
/// direction vectors for the horizontal and vertical axes of the screen, and
/// the screen's normal vector. The screen must be properly registered with the
/// Screen Locator tool for the Leap to report these characteristics accurately.
/// The Screen class also reports the size of the screen in pixels, using
/// information obtained from the operating system.
///
/// You can get the point of intersection between the screen and a ray
/// projected from a Pointable object using the Screen::intersect() function.
/// Likewise, you can get the closest point on the screen to a point in space
/// using the Screen::distanceToPoint() function. Again, the screen location
/// must be registered with the Screen Locator tool for these functions to
/// return accurate values.
///
/// Note that Screen objects can be invalid, which means that they do not contain
/// valid screen coordinate data and do not correspond to a physical entity.
/// Test for validity with the Screen::isValid() function.
class Screen : public Interface {
public:
#if !defined(SWIG)
// For internal use only.
Screen(ScreenImplementation*);
#endif
/// Constructs a Screen object.
///
/// An uninitialized screen is considered invalid.
/// Get valid Screen objects from a ScreenList object obtained using the
/// Controller::calibratedScreens() method.
LEAP_EXPORT Screen();
/// A unique identifier for this screen based on the screen
/// information in the configuration. A default screen with ID, *Screen 0*,
/// always exists and contains default characteristics, even if no screens
/// have been located.
LEAP_EXPORT int32_t id() const;
/// Returns the intersection between this screen and a ray projecting from a
/// Pointable object.
///
/// The projected ray emanates from the Pointable tipPosition along the
/// Pointable's direction vector.
///
/// Set the normalize parameter to true to request the intersection point in
/// normalized screen coordinates. Normalized screen coordinates are usually
/// values between 0 and 1, where 0 represents the screen's origin at the
/// bottom-left corner and 1 represents the opposite edge (either top or
/// right). When you request normalized coordinates, the z-component of the
/// returned vector is zero. Multiply a normalized coordinate by the values
/// returned by Screen::widthPixels() or Screen::heightPixels() to calculate
/// the screen position in pixels (remembering that many other computer
/// graphics coordinate systems place the origin in the top-left corner).
///
/// Set the normalize parameter to false to request the intersection point
/// in Leap coordinates (millimeters from the Leap origin).
///
/// If the Pointable object points outside the screen's border (but still
/// intersects the plane in which the screen lies), the returned intersection
/// point is clamped to the nearest point on the edge of the screen.
///
/// You can use the clampRatio parameter to contract or expand the area in
/// which you can point. For example, if you set the clampRatio parameter to
/// 0.5, then the positions reported for intersection points outside the
/// central 50% of the screen are moved to the border of this smaller area.
/// If, on the other hand, you expanded the area by setting clampRatio to
/// a value such as 3.0, then you could point well outside screen's physical
/// boundary before the intersection points would be clamped. The positions
/// for any points clamped would also be placed on this larger outer border.
/// The positions reported for any intersection points inside the clamping
/// border are unaffected by clamping.
///
/// If the Pointable object does not point toward the plane of the screen
/// (i.e. it is pointing parallel to or away from the screen), then the
/// components of the returned vector are all set to NaN (not-a-number).
///
/// @param normalize If true, return normalized coordinates representing
/// the intersection point as a percentage of the screen's width and height.
/// If false, return Leap coordinates (millimeters from the Leap origin,
/// which is located at the center of the top surface of the Leap device).
/// If true and the clampRatio parameter is set to 1.0, coordinates will be
/// of the form (0..1, 0..1, 0). Setting the clampRatio to a different value
/// changes the range for normalized coordinates. For example, a clampRatio
/// of 5.0 changes the range of values to be of the form (-2..3, -2..3, 0).
///
/// @param clampRatio Adjusts the clamping border around this screen.
/// By default this ratio is 1.0, and the border corresponds to the actual
/// boundaries of the screen. Setting clampRatio to 0.5 would reduce the
/// interaction area. Likewise, setting the ratio to 2.0 would increase the
/// interaction area, adding 50% around each edge of the physical monitor.
/// Intersection points outside the interaction area are repositioned to
/// the closest point on the clamping border before the vector is returned.
///
/// @returns A Vector containing the coordinates of the intersection between
/// this Screen and a ray projecting from the specified Pointable object.
LEAP_EXPORT Vector intersect(const Pointable& pointable, bool normalize, float clampRatio = 1.0f) const;
/// A Vector representing the horizontal axis of this Screen within the
/// Leap coordinate system.
///
/// The magnitude of this vector estimates the physical width of this Screen
/// in millimeters. The direction of this vector is parallel to the bottom
/// edge of the screen and points toward the right edge of the screen.
///
/// Together, horizontalAxis(), verticalAxis(), and bottomLeftCorner()
/// describe the physical position, size and orientation of this Screen.
///
/// @returns A Vector representing the bottom, horizontal edge of this Screen.
LEAP_EXPORT Vector horizontalAxis() const;
/// A Vector representing the vertical axis of this Screen within the
/// Leap coordinate system.
///
/// The magnitude of this vector estimates the physical height of this Screen
/// in millimeters. The direction of this vector is parallel to the left
/// edge of the screen and points toward the top edge of the screen.
///
/// Together, horizontalAxis(), verticalAxis(), and bottomLeftCorner()
/// describe the physical position, size and orientation of this screen.
///
/// @returns A Vector representing the left, vertical edge of this Screen.
LEAP_EXPORT Vector verticalAxis() const;
/// A Vector representing the bottom left corner of this Screen within the
/// Leap coordinate system.
///
/// The point represented by this vector defines the origin of the screen
/// in the Leap coordinate system.
///
/// Together, horizontalAxis(), verticalAxis(), and bottomLeftCorner()
/// describe the physical position, size and orientation of this Screen.
///
/// @returns A Vector containing the coordinates of the bottom-left corner
/// of this Screen.
LEAP_EXPORT Vector bottomLeftCorner() const;
/// A Vector normal to the plane in which this Screen lies.
///
/// The normal vector is a unit direction vector orthogonal to the screen's
/// surface plane. It points toward a viewer positioned for typical use of
/// the monitor.
///
/// @returns A Vector representing this Screen's normal vector.
LEAP_EXPORT Vector normal() const;
/// The horizontal resolution of this screen, in pixels.
///