Kinect Scol plugin
openNiScolPlugin.cpp
1 /*
2 -----------------------------------------------------------------------------
3 This source file is part of OpenSpace3D
4 For the latest info, see http://www.openspace3d.com
5 
6 Copyright (c) 2012 I-maginer
7 
8 This program is free software; you can redistribute it and/or modify it under
9 the terms of the GNU Lesser General Public License as published by the Free Software
10 Foundation; either version 2 of the License, or (at your option) any later
11 version.
12 
13 This program is distributed in the hope that it will be useful, but WITHOUT
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
16 
17 You should have received a copy of the GNU Lesser General Public License along with
18 this program; if not, write to the Free Software Foundation, Inc., 59 Temple
19 Place - Suite 330, Boston, MA 02111-1307, USA, or go to
20 http://www.gnu.org/copyleft/lesser.txt
21 
22 -----------------------------------------------------------------------------
23 */
24 
32 #include "DeviceManager.h"
33 #include "core/DataSkeleton.h"
34 #include "objects/KinectDevice.h"
35 #include "generator/User.h"
36 
37 #include <ScolPlugin.h>
38 #include <scolMemoryHelper.hpp>
39 
41 #ifdef SCOL_STATIC
42 extern cbmachine ww;
43 extern mmachine mm;
44 #else
45 cbmachine ww;
46 mmachine mm;
47 #endif
48 
50 int OBJ_KINECT_SCOL;
51 
52 //===== CB Kinect CONNECTION ===
53 int SCOL_KINECT_CONNECTED_CB = 0;
54 int KINECT_CONNECTED_CB;
55 
56 //===== CB Kinect DISCONNECTION ===
57 int SCOL_KINECT_DISCONNECTED_CB = 1;
58 int KINECT_DISCONNECTED_CB;
59 
60 
62 int OBJ_KINECT_USER_SCOL;
63 
64 //===== CB Kinect User Calibration Start ===
65 int SCOL_KINECT_USER_CALIBRATION_START_CB = 0;
66 int KINECT_USER_CALIBRATION_START_CB;
67 
68 //===== CB Kinect User Calibration End ===
69 int SCOL_KINECT_USER_CALIBRATION_END_CB = 1;
70 int KINECT_USER_CALIBRATION_END_CB;
71 
72 //===== CB Kinect User Pose Detected ===
73 int SCOL_KINECT_USER_POSE_DETECTED_CB = 2;
74 int KINECT_USER_POSE_DETECTED_CB;
75 
76 //===== CB Kinect User Pose lost ===
77 int SCOL_KINECT_USER_POSE_LOST_CB = 3;
78 int KINECT_USER_POSE_LOST_CB;
79 
80 //===== CB Kinect User NEW USER ===
81 int SCOL_KINECT_NEW_USER_CB = 4;
82 int KINECT_NEW_USER_CB;
83 
84 //===== CB Kinect User LOST USER ===
85 int SCOL_KINECT_LOST_USER_CB = 5;
86 int KINECT_LOST_USER_CB;
87 
88 //===== CB Kinect User HAND FOUND ===
89 int SCOL_KINECT_USER_HAND_FOUND_CB = 6;
90 int KINECT_USER_HAND_FOUND_CB;
91 
92 //===== CB Kinect User HAND LOST ===
93 int SCOL_KINECT_USER_HAND_LOST_CB = 7;
94 int KINECT_USER_HAND_LOST_CB;
95 
96 //===== CB Kinect User HAND MOVE ===
97 int SCOL_KINECT_USER_HAND_MOVE_CB = 8;
98 int KINECT_USER_HAND_MOVE_CB;
99 
100 
123 int destroyKinectUserObj(mmachine m, SCOL_PTR_TYPE handsys, int objTab)
124 {
125  // Read the first element of a TAB element (table of objects)
126  KinectUser* kinectUserObject = MMgetPointer<KinectUser*>(m, MTOP(objTab));
127 
128  if (kinectUserObject != 0)
129  kinectUserObject->GetParentDevice()->DestroyKinectUser(kinectUserObject);
130 
131  MMsetPointer(m, MTOP(objTab), NULL);
132 
133  // Display debug message
134  MMechostr(MSKDEBUG,"ObjKinectUser destroyed.\n");
135  return 0;
136 }
137 
138 
148 int destroyKinectObj(mmachine m, SCOL_PTR_TYPE handsys, int objTab)
149 {
150  // Read the first element of a TAB element (table of objects)
151  KinectDevice* kinectObject = MMgetPointer<KinectDevice*>(m, MTOP(objTab));
152 
153  if (kinectObject != 0)
154  DeviceManager::GetSingletonPtr()->DestroyKinectDevice(kinectObject);
155 
156  MMsetPointer(m, MTOP(objTab), NULL);
157 
158  // Display debug message
159  MMechostr(MSKDEBUG,"ObjKinect destroyed.\n");
160  return 0;
161 }
162 
163 
173 int _CRKinectDevice(mmachine m)
174 {
175 #ifdef _SCOL_DEBUG_
176  MMechostr(MSKDEBUG,"_CRKinectDevice\n");
177 #endif
178 
179  // Declare local variables
180  int k = 0;
181 
182  if ((DeviceManager::GetSingletonPtr()) == 0)
183  {
184  MMset(m, 0, NIL); // NIL on the stack
185  return 0;
186  }
187 
188  // Create KinectObject instance
189  KinectDevice* newKinectDevice = DeviceManager::GetSingletonPtr()->CreateKinectDevice();
190  if (newKinectDevice == 0)
191  {
192  MMechostr(MSKDEBUG, "_CRobjKinect ...creation failed\n");
193  SAFE_DELETE(newKinectDevice);
194  MMset(m, 0, NIL); // NIL on the stack
195  return 0;
196  }
197  MMechostr(MSKDEBUG,"_CRobjKinect ...creation successful\n");
198 
199  if ((MMpushPointer(m, newKinectDevice) != 0))
200  {
201  SAFE_DELETE(newKinectDevice);
202  MMset(m, 0, NIL);
203  return MERRMEM;
204  }
205 
206  // Create a new scol object
207  k = OBJcreate(m, OBJ_KINECT_SCOL, SCOL_PTR newKinectDevice, NIL, 0);
208  MMechostr(MSKDEBUG,"_CRobjKinectDevice ...object creation successful\n");
209 
210 #ifdef _SCOL_DEBUG_
211  MMechostr(MSKDEBUG,"ok\n");
212 #endif
213  // Return object
214  return k;
215 }
216 
226 int _DSKinectDevice(mmachine m)
227 {
228 #ifdef _SCOL_DEBUG_
229  MMechostr(MSKDEBUG,"_DSKinectDevice\n");
230 #endif
231 
232  int objTab = MMget(m, 0);
233  if (objTab == NIL)
234  {
235  MMset(m, 0, NIL);
236  return 0;
237  }
238 
239  OBJdelTM( m, OBJ_KINECT_SCOL, objTab);
240  MMset(m, 0, ITOM(1));
241 
242 #ifdef _SCOL_DEBUG_
243  MMechostr(MSKDEBUG,"ok\n");
244 #endif
245  return 0;
246 }
247 
257 int _GETKinectDeviceById(mmachine m)
258 {
259 #ifdef _SCOL_DEBUG_
260  MMechostr(MSKDEBUG,"_GETKinectDeviceById\n");
261 #endif
262 
263  // Get the Name
264  int kId = MMget(m, 0);
265 
266  if (kId == NIL)
267  kId = 0;
268  else
269  kId = MTOI(kId);
270 
271  KinectDevice* newKinectDevice = DeviceManager::GetSingletonPtr()->GetKinectDevice(kId);
272  if (newKinectDevice == 0)
273  {
274  MMechostr(MSKDEBUG, "_GETKinectDeviceById ... not found\n");
275  MMset(m, 0, NIL);
276  return 0;
277  }
278 
279  int kin = OBJfindTH(m, OBJ_KINECT_SCOL, SCOL_PTR newKinectDevice);
280  if(kin!=NIL)
281  kin = MMfetch(m, kin, OFFOBJMAG);
282 
283  MMset(m, 0, kin);
284 
285 #ifdef _SCOL_DEBUG_
286  MMechostr(MSKDEBUG,"ok\n");
287 #endif
288 
289  return 0;
290 }
291 
299 int _GETKinectDeviceId(mmachine m)
300 {
301  #ifdef _SCOL_DEBUG_
302  MMechostr(MSKDEBUG,"_GETKinectDeviceId\n");
303  #endif
304 
305  int objTab = MMget(m, 0);
306  if (objTab == NIL)
307  {
308  MMset(m, 0, NIL);
309  return 0;
310  }
311 
312  KinectDevice* kinectObject = MMgetPointer<KinectDevice*>(m, MTOP(objTab));
313  if(kinectObject==NULL)
314  {
315  MMset(m, 0, NIL);
316  return 0;
317  }
318 
319  MMset(m, 0, ITOM(kinectObject->GetId()));
320 
321 #ifdef _SCOL_DEBUG_
322  MMechostr(MSKDEBUG,"ok\n");
323 #endif
324 
325  return 0;
326 }
327 
335 int _GETKinectDeviceSize(mmachine m)
336 {
337  #ifdef _SCOL_DEBUG_
338  MMechostr(MSKDEBUG,"_GETKinectDeviceSize\n");
339  #endif
340 
341  int objTab = MMget(m, 0);
342  if (objTab == NIL)
343  {
344  MMset(m, 0, NIL);
345  return 0;
346  }
347 
348  KinectDevice* kinectObject = MMgetPointer<KinectDevice*>(m, MTOP(objTab));
349  if(kinectObject==NULL)
350  {
351  MMset(m, 0, NIL);
352  return 0;
353  }
354 
355  int tuple = MMmalloc(m, 2, TYPETAB);
356  if(tuple==NIL)
357  {
358  MMset(m, 0, NIL);
359  return MERRMEM;
360  }
361  else
362  {
363  int width = 0;
364  int height = 0;
365 
366  kinectObject->GetGeneratorsSize(width, height);
367  MMstore(m, tuple, 0, ITOM(width));
368  MMstore(m, tuple, 1, ITOM(height));
369  MMset(m, 0, PTOM(tuple));
370  }
371 
372 #ifdef _SCOL_DEBUG_
373  MMechostr(MSKDEBUG,"ok\n");
374 #endif
375 
376  return 0;
377 }
378 
387 int _BLTKinectDeviceDepth(mmachine m)
388 {
389 #ifdef SCOL_DEBUG
390  MMechostr(MSKDEBUG, "_BLTKinectDeviceDepth\n");
391 #endif
392 
393  int bitmap = MMpull(m);
394  int kinect = MMget(m, 0);
395  if (kinect == NIL || bitmap == NIL)
396  {
397  MMset(m, 0, NIL);
398  return 0;
399  }
400 
401  KinectDevice* KinectOBJ = MMgetPointer<KinectDevice*>(m, MTOP(kinect));
402  if (KinectOBJ == NULL)
403  {
404  MMset(m, 0, NIL);
405  return 0;
406  }
407 
408  if(!KinectOBJ->IsConnected())
409  {
410  MMset(m, 0, NIL);
411  return 0;
412  }
413 
414  // Retrieve bitmap object and its data
415  PtrObjVoid OB = (PtrObjVoid) MMstart(m, MTOP(bitmap));
416  PtrObjBitmap B = (PtrObjBitmap) MMstart(m, MTOP(OB->Buffer));
417 
418  KinectOBJ->GetDepthBuffer(B);
419 
420  // Add bitmap object to Scol stack
421  MMset(m, 0, bitmap);
422 
423 #ifdef SCOL_DEBUG
424  MMechostr(MSKDEBUG, "ok\n");
425 #endif
426  return 0;
427 }
428 
437 int _BLTKinectDeviceRGB(mmachine m)
438 {
439 #ifdef SCOL_DEBUG
440  MMechostr(MSKDEBUG, "_BLTKinectDeviceRGB\n");
441 #endif
442 
443  int bitmap = MMpull(m);
444  int kinect = MMget(m, 0);
445  if (kinect == NIL || bitmap == NIL)
446  {
447  MMset(m, 0, NIL);
448  return 0;
449  }
450 
451  // Get Kinect device
452  KinectDevice* KinectOBJ = MMgetPointer<KinectDevice*>(m, MTOP(kinect));
453  if (KinectOBJ == NULL)
454  {
455  MMset(m, 0, NIL);
456  return 0;
457  }
458 
459  if(!KinectOBJ->IsConnected())
460  {
461  MMset(m, 0, NIL);
462  return 0;
463  }
464 
465  // Create a pointer to ObjBitmap
466  PtrObjVoid OB = (PtrObjVoid) MMstart(m, MTOP(bitmap));
467  PtrObjBitmap B = (PtrObjBitmap) MMstart(m, MTOP(OB->Buffer));
468 
469  KinectOBJ->GetImageBuffer(B);
470 
471  MMset(m, 0, bitmap);
472 
473 #ifdef SCOL_DEBUG
474  MMechostr(MSKDEBUG, "ok\n");
475 #endif
476  return 0;
477 }
478 
488 {
489 #ifdef SCOL_DEBUG
490  MMechostr(MSKDEBUG, "_BLTKinectDeviceGrayscale\n");
491 #endif
492 
493  int bitmap = MMpull(m);
494  int kinect = MMget(m, 0);
495  if (kinect == NIL || bitmap == NIL)
496  {
497  MMset(m, 0, NIL);
498  return 0;
499  }
500 
501  // Get Kinect device
502  KinectDevice* KinectOBJ = MMgetPointer<KinectDevice*>(m, MTOP(kinect));
503  if (KinectOBJ == NULL)
504  {
505  MMset(m, 0, NIL);
506  return 0;
507  }
508 
509  if(!KinectOBJ->IsConnected())
510  {
511  MMset(m, 0, NIL);
512  return 0;
513  }
514 
515  // Create a pointer to ObjBitmap
516  PtrObjVoid OB = (PtrObjVoid) MMstart(m, MTOP(bitmap));
517  PtrObjBitmap B = (PtrObjBitmap) MMstart(m, MTOP(OB->Buffer));
518 
519  KinectOBJ->GetImageGreyBuffer(B);
520 
521  MMset(m, 0, PTOM(bitmap));
522 
523 #ifdef SCOL_DEBUG
524  MMechostr(MSKDEBUG, "ok\n");
525 #endif
526  return 0;
527 }
528 
537 int _BLTKinectDeviceUsers(mmachine m)
538 {
539 #ifdef SCOL_DEBUG
540  MMechostr(MSKDEBUG, "_BLTKinectDeviceRGB\n");
541 #endif
542 
543  int bitmap = MMpull(m);
544  int kinect = MMget(m, 0);
545  if (kinect == NIL || bitmap == NIL)
546  {
547  MMset(m, 0, NIL);
548  return 0;
549  }
550 
551  // Get Kinect device
552  KinectDevice* KinectOBJ = MMgetPointer<KinectDevice*>(m, MTOP(kinect));
553  if (KinectOBJ == NULL)
554  {
555  MMset(m, 0, NIL);
556  return 0;
557  }
558 
559  if(!KinectOBJ->IsConnected())
560  {
561  MMset(m, 0, NIL);
562  return 0;
563  }
564 
565  // Create a pointer to ObjBitmap
566  int colorLayer = MMfetch(m, MTOP(bitmap), 0);
567  int alphaLayer = MMfetch(m, MTOP(bitmap), 1);
568 
569  PtrObjVoid OBcolor;
570  PtrObjBitmap Bcolor;
571  OBcolor = (PtrObjVoid) MMstart(m, MTOP(colorLayer));
572  if(OBcolor->Type != OBJ_TYPE_BITMAP << 1)
573  {
574  MMset(m, 0, NIL);
575  return 0;
576  }
577  Bcolor = (PtrObjBitmap) MMstart(m, MTOP(OBcolor->Buffer));
578 
579  PtrObjVoid OBalpha;
580  PtrObjBitmap Balpha;
581  OBalpha = (PtrObjVoid) MMstart(m, MTOP(alphaLayer));
582  if(OBalpha->Type != OBJ_TYPE_BITMAP << 1)
583  {
584  MMset(m, 0, NIL);
585  return 0;
586  }
587  Balpha = (PtrObjBitmap) MMstart(m,MTOP(OBalpha->Buffer));
588 
589  KinectOBJ->GetValidUserPixels(Bcolor, Balpha);
590 
591  MMset(m, 0, bitmap);
592 
593 #ifdef SCOL_DEBUG
594  MMechostr(MSKDEBUG, "ok\n");
595 #endif
596  return 0;
597 }
598 
608 {
609 #ifdef SCOL_DEBUG
610  MMechostr(MSKDEBUG, "_BLTKinectDeviceUsersRGB\n");
611 #endif
612 
613  int bitmap = MMpull(m);
614  int kinect = MMget(m, 0);
615  if (kinect == NIL || bitmap == NIL)
616  {
617  MMset(m, 0, NIL);
618  return 0;
619  }
620 
621  // Get Kinect device
622  KinectDevice* KinectOBJ = MMgetPointer<KinectDevice*>(m, MTOP(kinect));
623  if (KinectOBJ == NULL)
624  {
625  MMset(m, 0, NIL);
626  return 0;
627  }
628 
629  if(!KinectOBJ->IsConnected())
630  {
631  MMset(m, 0, NIL);
632  return 0;
633  }
634 
635  // Create a pointer to ObjBitmap
636  int colorLayer = MMfetch(m, MTOP(bitmap), 0);
637  int alphaLayer = MMfetch(m, MTOP(bitmap), 1);
638 
639  PtrObjVoid OBcolor;
640  PtrObjBitmap Bcolor;
641  OBcolor = (PtrObjVoid) MMstart(m, MTOP(colorLayer));
642  if(OBcolor->Type != OBJ_TYPE_BITMAP << 1)
643  {
644  MMset(m, 0, NIL);
645  return 0;
646  }
647  Bcolor = (PtrObjBitmap) MMstart(m, MTOP(OBcolor->Buffer));
648 
649  PtrObjVoid OBalpha;
650  PtrObjBitmap Balpha;
651  OBalpha = (PtrObjVoid) MMstart(m, MTOP(alphaLayer));
652  if(OBalpha->Type != OBJ_TYPE_BITMAP << 1)
653  {
654  MMset(m, 0, NIL);
655  return 0;
656  }
657  Balpha = (PtrObjBitmap) MMstart(m,MTOP(OBalpha->Buffer));
658 
659  KinectOBJ->GetValidUserPixelsRGB(Bcolor, Balpha);
660 
661  MMset(m, 0, bitmap);
662 
663 #ifdef SCOL_DEBUG
664  MMechostr(MSKDEBUG, "ok\n");
665 #endif
666  return 0;
667 }
668 
677 int _BLTKinectDeviceHands(mmachine m)
678 {
679 #ifdef SCOL_DEBUG
680  MMechostr(MSKDEBUG, "_BLTKinectDeviceHands\n");
681 #endif
682 
683  int bitmap = MMpull(m);
684  int kinect = MMget(m, 0);
685  if (kinect == NIL || bitmap == NIL)
686  {
687  MMset(m, 0, NIL);
688  return 0;
689  }
690 
691  // Get Kinect device
692  KinectDevice* KinectOBJ = MMgetPointer<KinectDevice*>(m, MTOP(kinect));
693  if (KinectOBJ == NULL)
694  {
695  MMset(m, 0, NIL);
696  return 0;
697  }
698 
699  if(!KinectOBJ->IsConnected())
700  {
701  MMset(m, 0, NIL);
702  return 0;
703  }
704 
705  // Create a pointer to ObjBitmap
706  int colorLayer = MMfetch(m, MTOP(bitmap), 0);
707  int alphaLayer = MMfetch(m, MTOP(bitmap), 1);
708 
709  PtrObjVoid OBcolor;
710  PtrObjBitmap Bcolor;
711  OBcolor = (PtrObjVoid) MMstart(m, MTOP(colorLayer));
712  if(OBcolor->Type != OBJ_TYPE_BITMAP << 1)
713  {
714  MMset(m, 0, NIL);
715  return 0;
716  }
717  Bcolor = (PtrObjBitmap) MMstart(m, MTOP(OBcolor->Buffer));
718 
719  PtrObjVoid OBalpha;
720  PtrObjBitmap Balpha;
721  OBalpha = (PtrObjVoid) MMstart(m, MTOP(alphaLayer));
722  if(OBalpha->Type != OBJ_TYPE_BITMAP << 1)
723  {
724  MMset(m, 0, NIL);
725  return 0;
726  }
727  Balpha = (PtrObjBitmap) MMstart(m, MTOP(OBalpha->Buffer));
728 
729  KinectOBJ->GetHandsPixels(Bcolor, Balpha);
730 
731  MMset(m, 0, bitmap);
732 
733 #ifdef SCOL_DEBUG
734  MMechostr(MSKDEBUG, "ok\n");
735 #endif
736  return 0;
737 }
738 
747 int _SETKinectDeviceMirror(mmachine m)
748 {
749 #ifdef SCOL_DEBUG
750  MMechostr(MSKDEBUG, "_SETKinectDeviceMirror\n");
751 #endif
752 
753  int mode = MMpull(m);
754  int kinect = MMget(m, 0);
755  if (kinect == NIL)
756  {
757  MMset(m, 0, NIL);
758  return 0;
759  }
760 
761  // Get Kinect device
762  KinectDevice* KinectOBJ = MMgetPointer<KinectDevice*>(m, MTOP(kinect));
763  if (KinectOBJ == NULL)
764  {
765  MMset(m, 0, NIL);
766  return 0;
767  }
768 
769  bool bMode = false;
770  if (MTOI(mode) == 1)
771  bMode = true;
772 
773  KinectOBJ->SetMirrorMode(bMode);
774 
775  MMset(m, 0, ITOM(1));
776 
777 #ifdef SCOL_DEBUG
778  MMechostr(MSKDEBUG, "ok\n");
779 #endif
780  return 0;
781 }
782 
790 int _GETKinectDeviceMirror(mmachine m)
791 {
792 #ifdef SCOL_DEBUG
793  MMechostr(MSKDEBUG, "_GETKinectDeviceMirror\n");
794 #endif
795 
796  int kinect = MMget(m, 0);
797  if (kinect == NIL)
798  {
799  MMset(m, 0, NIL);
800  return 0;
801  }
802 
803  // Get Kinect device
804  KinectDevice* KinectOBJ = MMgetPointer<KinectDevice*>(m, MTOP(kinect));
805  if (KinectOBJ == NULL)
806  {
807  MMset(m, 0, NIL);
808  return 0;
809  }
810 
811  bool bMode = KinectOBJ->GetMirrorMode();;
812 
813  MMset(m, 0, ITOM(bMode == true ? 1 : 0));
814 
815 #ifdef SCOL_DEBUG
816  MMechostr(MSKDEBUG, "ok\n");
817 #endif
818  return 0;
819 }
820 
832 {
833 #ifdef _SCOL_DEBUG_
834  MMechostr(MSKDEBUG,"_SETKinectDeviceSkeletonSmoothing\n");
835 #endif
836 
837  int ismooth = MMpull(m);
838  int kinect = MMget(m, 0);
839  if (kinect == NIL)
840  {
841  MMset(m, 0, NIL);
842  return 0;
843  }
844 
845  // Get Kinect device
846  KinectDevice* KinectOBJ = MMgetPointer<KinectDevice*>(m, MTOP(kinect));
847  if (KinectOBJ == NULL)
848  {
849  MMset(m, 0, NIL);
850  return 0;
851  }
852 
853  float fsmooth = 0.0f;
854  if ((ismooth != NIL) && (MTOF(ismooth) > 0.0f))
855  fsmooth = MTOF(ismooth);
856 
857  if ((fsmooth) > 1.0f)
858  fsmooth = 1.0f;
859 
860  KinectOBJ->SetSkeletonSmoothing(fsmooth);
861 
862  MMset(m, 0, ITOM(1));
863 
864 #ifdef _SCOL_DEBUG_
865  MMechostr(MSKDEBUG,"ok\n");
866 #endif
867  return 0;
868 }
869 
880 {
881 #ifdef _SCOL_DEBUG_
882  MMechostr(MSKDEBUG,"_GETKinectDeviceSkeletonSmoothing\n");
883 #endif
884 
885  int kinect = MMget(m, 0);
886  if (kinect == NIL)
887  {
888  MMset(m, 0, NIL);
889  return 0;
890  }
891 
892  // Get Kinect device
893  KinectDevice* KinectOBJ = MMgetPointer<KinectDevice*>(m, MTOP(kinect));
894  if (KinectOBJ == NULL)
895  {
896  MMset(m, 0, NIL);
897  return 0;
898  }
899 
900  float smooth = KinectOBJ->GetSkeletonSmoothing();
901 
902  MMset(m, 0, FTOM(smooth));
903 
904 #ifdef _SCOL_DEBUG_
905  MMechostr(MSKDEBUG,"ok\n");
906 #endif
907  return 0;
908 }
909 
921 {
922 #ifdef _SCOL_DEBUG_
923  MMechostr(MSKDEBUG,"_SETKinectDeviceDetectionDistance\n");
924 #endif
925 
926  int idist = MMpull(m);
927  int kinect = MMget(m, 0);
928  if (kinect == NIL)
929  {
930  MMset(m, 0, NIL);
931  return 0;
932  }
933 
934  // Get Kinect device
935  KinectDevice* KinectOBJ = MMgetPointer<KinectDevice*>(m, MTOP(kinect));
936  if (KinectOBJ == NULL)
937  {
938  MMset(m, 0, NIL);
939  return 0;
940  }
941 
942  int dist = 10000;
943  if ((idist != NIL) && (MTOI(idist) > 0))
944  dist = MTOI(idist) * 10;
945 
946  KinectOBJ->SetDistCutoff(dist);
947 
948  MMset(m, 0, ITOM(1));
949 
950 #ifdef _SCOL_DEBUG_
951  MMechostr(MSKDEBUG,"ok\n");
952 #endif
953  return 0;
954 }
955 
966 {
967 #ifdef _SCOL_DEBUG_
968  MMechostr(MSKDEBUG,"_GETKinectDeviceDetectionDistance\n");
969 #endif
970 
971  int kinect = MMget(m, 0);
972  if (kinect == NIL)
973  {
974  MMset(m, 0, NIL);
975  return 0;
976  }
977 
978  // Get Kinect device
979  KinectDevice* KinectOBJ = MMgetPointer<KinectDevice*>(m, MTOP(kinect));
980  if (KinectOBJ == NULL)
981  {
982  MMset(m, 0, NIL);
983  return 0;
984  }
985 
986  int dist = KinectOBJ->GetDistCutoff();
987 
988  MMset(m, 0, ITOM(dist / 10));
989 
990 #ifdef _SCOL_DEBUG_
991  MMechostr(MSKDEBUG,"ok\n");
992 #endif
993  return 0;
994 }
995 
1007 {
1008 #ifdef _SCOL_DEBUG_
1009  MMechostr(MSKDEBUG,"_SETKinectDeviceDetectionAngle\n");
1010 #endif
1011 
1012  int iangle = MMpull(m);
1013  int kinect = MMget(m, 0);
1014  if (kinect == NIL)
1015  {
1016  MMset(m, 0, NIL);
1017  return 0;
1018  }
1019 
1020  // Get Kinect device
1021  KinectDevice* KinectOBJ = MMgetPointer<KinectDevice*>(m, MTOP(kinect));
1022  if (KinectOBJ == NULL)
1023  {
1024  MMset(m, 0, NIL);
1025  return 0;
1026  }
1027 
1028  float fang = 0.0f;
1029  if ((iangle != NIL) && (MTOF(iangle) > 0))
1030  fang = MTOF(iangle);
1031 
1032  KinectOBJ->SetAngCutoff(fang);
1033 
1034  MMset(m, 0, ITOM(1));
1035 
1036 #ifdef _SCOL_DEBUG_
1037  MMechostr(MSKDEBUG,"ok\n");
1038 #endif
1039  return 0;
1040 }
1041 
1052 {
1053 #ifdef _SCOL_DEBUG_
1054  MMechostr(MSKDEBUG,"_GETKinectDeviceDetectionAngle\n");
1055 #endif
1056 
1057  int kinect = MMget(m, 0);
1058  if (kinect == NIL)
1059  {
1060  MMset(m, 0, NIL);
1061  return 0;
1062  }
1063 
1064  // Get Kinect device
1065  KinectDevice* KinectOBJ = MMgetPointer<KinectDevice*>(m, MTOP(kinect));
1066  if (KinectOBJ == NULL)
1067  {
1068  MMset(m, 0, NIL);
1069  return 0;
1070  }
1071 
1072  float fdist = KinectOBJ->GetAngCutoff();
1073 
1074  MMset(m, 0, FTOM(fdist));
1075 
1076 #ifdef _SCOL_DEBUG_
1077  MMechostr(MSKDEBUG,"ok\n");
1078 #endif
1079  return 0;
1080 }
1081 
1093 int _CBKinectConnected(mmachine m)
1094 {
1095  return OBJaddreflex(m, OBJ_KINECT_SCOL, SCOL_KINECT_CONNECTED_CB);
1096 }
1097 
1098 int getKinectConnectedCb(mmachine m, SCOL_PTR_TYPE id, LONG param)
1099 {
1100  int k = 0;
1101  KinectDevice* mKinectObj = (KinectDevice*) id;
1102 
1103  if (OBJbeginreflex(m, OBJ_KINECT_SCOL, SCOL_PTR mKinectObj, SCOL_KINECT_CONNECTED_CB))
1104  return 0;
1105  if ((k=OBJcallreflex(m, 0))) return k;
1106  return k;
1107 }
1108 
1120 int _CBKinectDisconnected(mmachine m)
1121 {
1122  return OBJaddreflex(m, OBJ_KINECT_SCOL, SCOL_KINECT_DISCONNECTED_CB);
1123 }
1124 
1125 int getKinectDisconnectedCb(mmachine m, SCOL_PTR_TYPE id, LONG param)
1126 {
1127  int k = 0;
1128  KinectDevice* mKinectObj = (KinectDevice*) id;
1129 
1130  if (OBJbeginreflex(m, OBJ_KINECT_SCOL, SCOL_PTR mKinectObj, SCOL_KINECT_DISCONNECTED_CB))
1131  return 0;
1132  if ((k=OBJcallreflex(m, 0))) return k;
1133  return k;
1134 }
1135 
1146 int _CRKinectUser(mmachine m)
1147 {
1148  #ifdef _SCOL_DEBUG_
1149  MMechostr(MSKDEBUG,"_CRKinectUser\n");
1150  #endif
1151 
1152  int k = 0;
1153 
1154  int ikindevice = MMpull(m);
1155  if (ikindevice == NIL)
1156  {
1157  MMset(m, 0, NIL); //NIL on the stack
1158  return 0;
1159  }
1160 
1161  // Get the SScene pointer
1162  KinectDevice* kinectDevice = MMgetPointer<KinectDevice*>(m, MTOP(ikindevice));
1163  if(kinectDevice==NULL)
1164  {
1165  MMechostr(MSKDEBUG, "Device NIL\n");
1166  MMset(m, 0, NIL); //NIL on the stack
1167  return 0;
1168  }
1169 
1170  // Create KinectObject instance
1171  KinectUser* newKinectUser = kinectDevice->CreateKinectUser();
1172  if (newKinectUser == 0)
1173  {
1174  MMechostr(MSKDEBUG, "_CRKinectUser ...creation failed\n");
1175  SAFE_DELETE(newKinectUser);
1176  MMset(m, 0, NIL); //NIL on the stack
1177  return 0;
1178  }
1179  MMechostr(MSKDEBUG,"_CRKinectUser ...creation successful\n");
1180 
1181  // Allocate a space in the stack for a table of objects
1182  if ((MMpushPointer(m, newKinectUser) != 0))
1183  {
1184  SAFE_DELETE(newKinectUser);
1185  MMset(m, 0, NIL);
1186  return MERRMEM;
1187  }
1188 
1189  // Create a new scol object
1190  k = OBJcreate(m, OBJ_KINECT_USER_SCOL, SCOL_PTR newKinectUser, OBJ_KINECT_SCOL, (int)kinectDevice);
1191  MMechostr(MSKDEBUG,"_CRKinectUser ...object creation successful\n");
1192 
1193  #ifdef _SCOL_DEBUG_
1194  MMechostr(MSKDEBUG,"ok\n");
1195  #endif
1196  // Return object
1197  return k;
1198 }
1199 
1209 int _DSKinectUser(mmachine m)
1210 {
1211 #ifdef _SCOL_DEBUG_
1212  MMechostr(MSKDEBUG,"_DSKinectUser\n");
1213 #endif
1214 
1215  int objTab = MMget(m, 0);
1216  if ( objTab == NIL)
1217  {
1218  MMset(m,0,NIL);
1219  return 0;
1220  }
1221 
1222  OBJdelTM( m, OBJ_KINECT_USER_SCOL, objTab);
1223  MMset(m, 0, ITOM(1));
1224 
1225 #ifdef _SCOL_DEBUG_
1226  MMechostr(MSKDEBUG,"ok\n");
1227 #endif
1228  return 0;
1229 }
1230 
1242 int _CBKinectUserFound(mmachine m)
1243 {
1244  return OBJaddreflex(m, OBJ_KINECT_USER_SCOL, SCOL_KINECT_NEW_USER_CB);
1245 }
1246 
1247 int getKinectNewUserCb(mmachine m, SCOL_PTR_TYPE id, LONG param)
1248 {
1249  int k = 0;
1250  KinectUser* mKinectUserObj = (KinectUser*) id;
1251 
1252  if (OBJbeginreflex(m, OBJ_KINECT_USER_SCOL, SCOL_PTR mKinectUserObj, SCOL_KINECT_NEW_USER_CB))
1253  return 0;
1254  if ((k=OBJcallreflex(m, 0))) return k;
1255  return k;
1256 }
1257 
1269 int _CBKinectUserLost(mmachine m)
1270 {
1271  return OBJaddreflex(m, OBJ_KINECT_USER_SCOL, SCOL_KINECT_LOST_USER_CB);
1272 }
1273 
1274 int getKinectLostUserCb(mmachine m, SCOL_PTR_TYPE id, LONG param)
1275 {
1276  int k = 0;
1277  KinectUser* mKinectUserObj = (KinectUser*) id;
1278 
1279  if (OBJbeginreflex(m, OBJ_KINECT_USER_SCOL, SCOL_PTR mKinectUserObj, SCOL_KINECT_LOST_USER_CB))
1280  return 0;
1281  if ((k=OBJcallreflex(m, 0))) return k;
1282  return k;
1283 }
1284 
1297 {
1298  return OBJaddreflex(m, OBJ_KINECT_USER_SCOL, SCOL_KINECT_USER_CALIBRATION_START_CB);
1299 }
1300 
1301 int getKinectUserCalibrationStartCb(mmachine m, SCOL_PTR_TYPE id, LONG param)
1302 {
1303  int k = 0;
1304  KinectUser* mKinectUserObj = (KinectUser*) id;
1305 
1306  if (OBJbeginreflex(m, OBJ_KINECT_USER_SCOL, SCOL_PTR mKinectUserObj, SCOL_KINECT_USER_CALIBRATION_START_CB))
1307  return 0;
1308  if ((k=OBJcallreflex(m, 0))) return k;
1309  return k;
1310 }
1311 
1324 {
1325  return OBJaddreflex(m, OBJ_KINECT_USER_SCOL, SCOL_KINECT_USER_CALIBRATION_END_CB);
1326 }
1327 
1328 int getKinectUserCalibrationEndCb(mmachine m, SCOL_PTR_TYPE id, LONG param)
1329 {
1330  int k = 0;
1331  KinectUser* mKinectUserObj = (KinectUser*) id;
1332 
1333  if (OBJbeginreflex(m, OBJ_KINECT_USER_SCOL, SCOL_PTR mKinectUserObj, SCOL_KINECT_USER_CALIBRATION_END_CB))
1334  return 0;
1335  if ((k=OBJcallreflex(m, 0))) return k;
1336  return k;
1337 }
1338 
1351 {
1352  return OBJaddreflex(m, OBJ_KINECT_USER_SCOL, SCOL_KINECT_USER_POSE_DETECTED_CB);
1353 }
1354 
1355 int getKinectUserPoseDetectedCb(mmachine m, SCOL_PTR_TYPE id, LONG param)
1356 {
1357  int k = 0;
1358  KinectUser* mKinectUserObj = (KinectUser*) id;
1359 
1360  if (OBJbeginreflex(m, OBJ_KINECT_USER_SCOL, SCOL_PTR mKinectUserObj, SCOL_KINECT_USER_POSE_DETECTED_CB))
1361  return 0;
1362  if ((k=OBJcallreflex(m, 0))) return k;
1363  return k;
1364 }
1365 
1377 int _CBKinectUserPoseLost(mmachine m)
1378 {
1379  return OBJaddreflex(m, OBJ_KINECT_USER_SCOL, SCOL_KINECT_USER_POSE_LOST_CB);
1380 }
1381 
1382 int getKinectUserPoseLostCb(mmachine m, SCOL_PTR_TYPE id, LONG param)
1383 {
1384  int k = 0;
1385  KinectUser* mKinectUserObj = (KinectUser*) id;
1386 
1387  if (OBJbeginreflex(m, OBJ_KINECT_USER_SCOL, SCOL_PTR mKinectUserObj, SCOL_KINECT_USER_POSE_LOST_CB))
1388  return 0;
1389  if ((k=OBJcallreflex(m, 0))) return k;
1390  return k;
1391 }
1392 
1405 int _CBKinectUserHandFound(mmachine m)
1406 {
1407  return OBJaddreflex(m, OBJ_KINECT_USER_SCOL, SCOL_KINECT_USER_HAND_FOUND_CB);
1408 }
1409 
1410 int getKinectUserHandFoundCb(mmachine m, SCOL_PTR_TYPE id, LONG param)
1411 {
1412  int k = 0;
1413  KinectUser* mKinectUserObj = (KinectUser*) id;
1414 
1415  if (OBJbeginreflex(m, OBJ_KINECT_USER_SCOL, SCOL_PTR mKinectUserObj, SCOL_KINECT_USER_HAND_FOUND_CB))
1416  return 0;
1417 
1418  MMpush(m, ITOM((int)param));
1419 
1420  if ((k=OBJcallreflex(m, 1))) return k;
1421  return k;
1422 }
1423 
1436 int _CBKinectUserHandLost(mmachine m)
1437 {
1438  return OBJaddreflex(m, OBJ_KINECT_USER_SCOL, SCOL_KINECT_USER_HAND_LOST_CB);
1439 }
1440 
1441 int getKinectUserHandLostCb(mmachine m, SCOL_PTR_TYPE id, LONG param)
1442 {
1443  int k = 0;
1444  KinectUser* mKinectUserObj = (KinectUser*) id;
1445 
1446  if (OBJbeginreflex(m, OBJ_KINECT_USER_SCOL, SCOL_PTR mKinectUserObj, SCOL_KINECT_USER_HAND_LOST_CB))
1447  return 0;
1448 
1449  MMpush(m, ITOM((int)param));
1450 
1451  if ((k=OBJcallreflex(m, 1))) return k;
1452  return k;
1453 }
1454 
1468 int _CBKinectUserHandMove(mmachine m)
1469 {
1470  return OBJaddreflex(m, OBJ_KINECT_USER_SCOL, SCOL_KINECT_USER_HAND_MOVE_CB);
1471 }
1472 
1473 int getKinectUserHandMoveCb(mmachine m, SCOL_PTR_TYPE id, LONG param)
1474 {
1475  int k = 0;
1476  KinectUser* mKinectUserObj = (KinectUser*) id;
1477  KinectUserHand* mKinectUserHand = (KinectUserHand*) param;
1478 
1479  if (OBJbeginreflex(m, OBJ_KINECT_USER_SCOL, SCOL_PTR mKinectUserObj, SCOL_KINECT_USER_HAND_MOVE_CB))
1480  return 0;
1481 
1482  nite::Point3f transVec = mKinectUserHand->GetLastTransVec();
1483 
1484  MMpush(m, ITOM((int)mKinectUserHand->GetType()));
1485 
1486  int tuple = MMmalloc(m, 3, TYPETAB);
1487  if(tuple==NIL)
1488  return MERRMEM;
1489 
1490  MMstore(m, tuple, 0, ITOM((int)transVec.x));
1491  MMstore(m, tuple, 1, ITOM((int)transVec.y));
1492  MMstore(m, tuple, 2, ITOM((int)transVec.z));
1493  MMpush(m, PTOM(tuple));
1494 
1495  if ((k=OBJcallreflex(m, 2))) return k;
1496  return k;
1497 }
1498 
1499 
1512 {
1513 #ifdef _SCOL_DEBUG_
1514  MMechostr(MSKDEBUG,"_GETKinectUserJointPixelPosition\n");
1515 #endif
1516 
1517  int iConfidence = MMpull(m);
1518  int bId = MMpull(m);
1519  int objTab = MMget(m, 0);
1520  if ((objTab == NIL) || (bId == NIL))
1521  {
1522  MMset(m, 0, NIL);
1523  return 0;
1524  }
1525  KinectUser* KinectUserOBJ = MMgetPointer<KinectUser*>(m, MTOP(objTab));
1526 
1527  if(!KinectUserOBJ)
1528  {
1529  MMset(m, 0, NIL);
1530  return 0;
1531  }
1532 
1533  float fConfidence = 0.0f;
1534  if ((iConfidence != NIL) || (MTOF(iConfidence) > 0.0f))
1535  fConfidence = MTOF(iConfidence);
1536 
1537  nite::Point3f result;
1538  if(KinectUserOBJ->GetBoneImgCoordinates((nite::JointType)(MTOI(bId)), result, fConfidence))
1539  {
1540  int tuple = MMmalloc(m, 3, TYPETAB);
1541  if(tuple==NIL)
1542  return MERRMEM;
1543 
1544  MMstore(m, tuple, 0, ITOM((int)result.x));
1545  MMstore(m, tuple, 1, ITOM((int)result.y));
1546  MMstore(m, tuple, 2, ITOM((int)result.z));
1547  MMset(m, 0, PTOM(tuple));
1548  }
1549  else
1550  {
1551  MMset(m, 0, NIL);
1552  }
1553 
1554 #ifdef _SCOL_DEBUG_
1555  MMechostr(MSKDEBUG,"ok\n");
1556 #endif
1557  return 0;
1558 }
1559 
1571 {
1572 #ifdef _SCOL_DEBUG_
1573  MMechostr(MSKDEBUG,"_GETKinectUserHandVisible\n");
1574 #endif
1575 
1576  int bId = MMpull(m);
1577  int objTab = MMget(m, 0);
1578  if ((objTab == NIL) || (bId == NIL))
1579  {
1580  MMset(m, 0, NIL);
1581  return 0;
1582  }
1583  KinectUser* KinectUserOBJ = MMgetPointer<KinectUser*>(m, MTOP(objTab));
1584 
1585  if(!KinectUserOBJ)
1586  {
1587  MMset(m, 0, NIL);
1588  return 0;
1589  }
1590 
1591  if (KinectUserOBJ->IsHandVisible((nite::JointType)(MTOI(bId))))
1592  MMset(m, 0, ITOM(1));
1593  else
1594  MMset(m, 0, ITOM(0));
1595 
1596 #ifdef _SCOL_DEBUG_
1597  MMechostr(MSKDEBUG,"ok\n");
1598 #endif
1599  return 0;
1600 }
1601 
1602 
1614 {
1615 #ifdef _SCOL_DEBUG_
1616  MMechostr(MSKDEBUG,"_GETKinectUserFingersPixelPosition\n");
1617 #endif
1618 
1619  int bId = MMpull(m);
1620  int objTab = MMget(m, 0);
1621  if ((objTab == NIL) || (bId == NIL))
1622  {
1623  MMset(m, 0, NIL);
1624  return 0;
1625  }
1626  KinectUser* KinectUserOBJ = MMgetPointer<KinectUser*>(m, MTOP(objTab));
1627 
1628  if(!KinectUserOBJ)
1629  {
1630  MMset(m, 0, NIL);
1631  return 0;
1632  }
1633 
1634  //remove last param
1635  MMpull(m);
1636 
1637  vector<cv::Point> result;
1638  if(KinectUserOBJ->GetFingersPixelPosition((nite::JointType)(MTOI(bId)), result))
1639  {
1640  for (int i=0; i<(int)result.size(); i++)
1641  {
1642  int tuple = MMmalloc(m, 2, TYPETAB);
1643  if(tuple==NIL)
1644  return MERRMEM;
1645 
1646  MMstore(m, tuple, 0, ITOM((int)result[i].x));
1647  MMstore(m, tuple, 1, ITOM((int)result[i].y));
1648  MMpush(m, PTOM(tuple));
1649  }
1650 
1651  if(MMpush(m, NIL))
1652  return MERRMEM;
1653 
1654  for(size_t j=0; j<result.size(); j++)
1655  {
1656  if(MMpush(m, 2*2))
1657  return MERRMEM;
1658 
1659  if(int k=MBdeftab(m))
1660  return k;
1661  }
1662  }
1663  else
1664  {
1665  MMpush(m, NIL);
1666  }
1667 
1668 #ifdef _SCOL_DEBUG_
1669  MMechostr(MSKDEBUG,"ok\n");
1670 #endif
1671  return 0;
1672 }
1673 
1686 {
1687 #ifdef _SCOL_DEBUG_
1688  MMechostr(MSKDEBUG,"_GETKinectUserJointPosition\n");
1689 #endif
1690 
1691  int iConfidence = MMpull(m);
1692  int bId = MMpull(m);
1693  int objTab = MMget(m, 0);
1694  if ((objTab == NIL) || (bId == NIL))
1695  {
1696  MMset(m, 0, NIL);
1697  return 0;
1698  }
1699  KinectUser* KinectUserOBJ = MMgetPointer<KinectUser*>(m, MTOP(objTab));
1700 
1701  if(!KinectUserOBJ)
1702  {
1703  MMset(m, 0, NIL);
1704  return 0;
1705  }
1706 
1707  float fConfidence = 0.0f;
1708  if ((iConfidence != NIL) || (MTOF(iConfidence) > 0.0f))
1709  fConfidence = MTOF(iConfidence);
1710 
1711  nite::Point3f result;
1712  if(KinectUserOBJ->GetBoneCurrentPosition((nite::JointType)(MTOI(bId)), result, fConfidence))
1713  {
1714  int tuple = MMmalloc(m, 3, TYPETAB);
1715  if(tuple==NIL)
1716  {
1717  return MERRMEM;
1718  }
1719  else
1720  {
1721  MMstore(m, tuple, 0, FTOM((result.x * 0.1f)));
1722  MMstore(m, tuple, 1, FTOM((result.y * 0.1f)));
1723  MMstore(m, tuple, 2, FTOM((result.z * 0.1f)));
1724  MMset(m, 0, PTOM(tuple));
1725  }
1726  }
1727  else
1728  {
1729  MMset(m, 0, NIL);
1730  }
1731 
1732 #ifdef _SCOL_DEBUG_
1733  MMechostr(MSKDEBUG,"ok\n");
1734 #endif
1735  return 0;
1736 }
1737 
1750 {
1751 #ifdef _SCOL_DEBUG_
1752  MMechostr(MSKDEBUG,"_GETKinectUserJointOrientation\n");
1753 #endif
1754 
1755  int iConfidence = MMpull(m);
1756  int bId = MMpull(m);
1757  int objTab = MMget(m, 0);
1758  if ((objTab == NIL) || (bId == NIL))
1759  {
1760  MMset(m, 0, NIL);
1761  return 0;
1762  }
1763 
1764  KinectUser* KinectUserOBJ = MMgetPointer<KinectUser*>(m, MTOP(objTab));
1765 
1766  if(!KinectUserOBJ)
1767  {
1768  MMset(m, 0, NIL);
1769  return 0;
1770  }
1771 
1772  float fConfidence = 0.0f;
1773  if ((iConfidence != NIL) || (MTOF(iConfidence) > 0.0f))
1774  fConfidence = MTOF(iConfidence);
1775 
1776  Quaternion result;
1777  if(KinectUserOBJ->GetBoneCurrentOrientation((nite::JointType)(MTOI(bId)), &result, fConfidence))
1778  {
1779  int tuple = MMmalloc(m, 4, TYPETAB);
1780  if(tuple==NIL)
1781  {
1782  return MERRMEM;
1783  }
1784  else
1785  {
1786  MMstore(m, tuple, 0, FTOM(result.x));
1787  MMstore(m, tuple, 1, FTOM(result.y));
1788  MMstore(m, tuple, 2, FTOM(result.z));
1789  MMstore(m, tuple, 3, FTOM(result.w));
1790  MMset(m, 0, PTOM(tuple));
1791  }
1792  }
1793  else
1794  {
1795  MMset(m, 0, NIL);
1796  }
1797 
1798 #ifdef _SCOL_DEBUG_
1799  MMechostr(MSKDEBUG,"ok\n");
1800 #endif
1801  return 0;
1802 }
1803 
1804 
1806 #define NbKinectPKG 63
1807 
1811 char *KinectName[NbKinectPKG] =
1812 {
1813  "ObjKinect",
1814  "ObjKinectUser",
1815  "_CRKinectDevice",
1816  "_DSKinectDevice",
1817  "_GETKinectDeviceById",
1818  "_GETKinectDeviceId",
1819  "_GETKinectDeviceSize",
1820  "_BLTKinectDeviceDepth",
1821  "_BLTKinectDeviceRGB",
1822  "_BLTKinectDeviceGrayscale",
1823  "_BLTKinectDeviceUsers",
1824  "_BLTKinectDeviceUsersRGB",
1825  "_BLTKinectDeviceHands",
1826  "_SETKinectDeviceMirror",
1827  "_GETKinectDeviceMirror",
1828  "_SETKinectDeviceSkeletonSmoothing",
1829  "_GETKinectDeviceSkeletonSmoothing",
1830  "_SETKinectDeviceDetectionDistance",
1831  "_GETKinectDeviceDetectionDistance",
1832  "_SETKinectDeviceDetectionAngle",
1833  "_GETKinectDeviceDetectionAngle",
1834  "_CRKinectUser",
1835  "_DSKinectUser",
1836 
1837  "_CBKinectConnected",
1838  "_CBKinectDisconnected",
1839  "_CBKinectUserFound",
1840  "_CBKinectUserLost",
1841  "_CBKinectUserCalibrationStart",
1842  "_CBKinectUserCalibrationEnd",
1843  "_CBKinectUserPoseDetected",
1844  "_CBKinectUserPoseLost",
1845  "_CBKinectUserHandFound",
1846  "_CBKinectUserHandLost",
1847  "_CBKinectUserHandMove",
1848 
1849  "_GETKinectUserJointPosition",
1850  "_GETKinectUserJointOrientation",
1851  "_GETKinectUserJointPixelPosition",
1852  "_GETKinectUserFingersPixelPosition",
1853  "_GETKinectUserHandVisible",
1854 
1855  "USER_SKEL_HEAD","USER_SKEL_NECK","USER_SKEL_TORSO",
1856  "USER_SKEL_WAIST","USER_SKEL_L_COLLAR","USER_SKEL_L_SHOULDER",
1857  "USER_SKEL_L_ELBOW","USER_SKEL_L_WRIST","USER_SKEL_L_HAND",
1858  "USER_SKEL_L_FINGERTIP","USER_SKEL_R_COLLAR","USER_SKEL_R_SHOULDER",
1859  "USER_SKEL_R_ELBOW","USER_SKEL_R_WRIST","USER_SKEL_R_HAND",
1860  "USER_SKEL_R_FINGERTIP","USER_SKEL_L_HIP","USER_SKEL_L_KNEE",
1861  "USER_SKEL_L_ANKLE","USER_SKEL_L_FOOT","USER_SKEL_R_HIP",
1862  "USER_SKEL_R_KNEE","USER_SKEL_R_ANKLE","USER_SKEL_R_FOOT"
1863 };
1864 
1868 int (*KinectFunc[NbKinectPKG])(mmachine m)=
1869 {
1870  NULL,
1871  NULL,
1891  _CRKinectUser,
1892  _DSKinectUser,
1893 
1905 
1911 
1912  SCOL_TYPTYPE(nite::JOINT_HEAD), SCOL_TYPTYPE(nite::JOINT_NECK), SCOL_TYPTYPE(nite::JOINT_TORSO), //"USER_SKEL_HEAD","USER_SKEL_NECK","USER_SKEL_TORSO",
1913  SCOL_TYPTYPE(0), SCOL_TYPTYPE(0), SCOL_TYPTYPE(nite::JOINT_LEFT_SHOULDER), //USER_SKEL_WAIST,USER_SKEL_L_COLLAR",USER_SKEL_L_SHOULDER,
1914  SCOL_TYPTYPE(nite::JOINT_LEFT_ELBOW), SCOL_TYPTYPE(0), SCOL_TYPTYPE(nite::JOINT_LEFT_HAND), //"USER_SKEL_L_ELBOW","USER_SKEL_L_WRIST","USER_SKEL_L_HAND",
1915  SCOL_TYPTYPE(0), SCOL_TYPTYPE(0), SCOL_TYPTYPE(nite::JOINT_RIGHT_SHOULDER), //"USER_SKEL_L_FINGERTIP","USER_SKEL_R_COLLAR","USER_SKEL_R_SHOULDER",
1916  SCOL_TYPTYPE(nite::JOINT_RIGHT_ELBOW), SCOL_TYPTYPE(0), SCOL_TYPTYPE(nite::JOINT_RIGHT_HAND), //"USER_SKEL_R_ELBOW","USER_SKEL_R_WRIST","USER_SKEL_R_HAND",
1917  SCOL_TYPTYPE(0), SCOL_TYPTYPE(nite::JOINT_LEFT_HIP), SCOL_TYPTYPE(nite::JOINT_LEFT_KNEE), //"USER_SKEL_R_FINGERTIP","USER_SKEL_L_HIP","USER_SKEL_L_KNEE",
1918  SCOL_TYPTYPE(0), SCOL_TYPTYPE(nite::JOINT_LEFT_FOOT), SCOL_TYPTYPE(nite::JOINT_RIGHT_HIP), //"USER_SKEL_L_ANKLE","USER_SKEL_L_FOOT","USER_SKEL_R_HIP",
1919  SCOL_TYPTYPE(nite::JOINT_RIGHT_KNEE), SCOL_TYPTYPE(0), SCOL_TYPTYPE(nite::JOINT_RIGHT_FOOT) //"USER_SKEL_R_KNEE","USER_SKEL_R_ANKLE","USER_SKEL_R_FOOT",
1920 };
1921 
1925 int KinectNArg[NbKinectPKG]=
1926 {
1927  TYPTYPE,
1928  TYPTYPE,
1929  1, // _CRKinectDevice
1930  1, // _DSKinectDevice
1931  1, // _GETKinectDeviceById
1932  1, // _GETKinectDeviceId
1933  1, // _GETKinectDeviceSize
1934  2, // _BLTKinectDeviceDepth
1935  2, // _BLTKinectDeviceRGB
1936  2, // _BLTKinectDeviceGrayscale
1937  2, // _BLTKinectDeviceUsers
1938  2, // _BLTKinectDeviceUsersRGB
1939  2, // _BLTKinectDeviceHands
1940  2, // _SETKinectDeviceMirror
1941  1, // _GETKinectDeviceMirror
1942  2, // _SETKinectDeviceSkeletonSmoothing
1943  1, // _GETKinectDeviceSkeletonSmoothing
1944  2, // _SETKinectDeviceDetectionDistance
1945  1, // _GETKinectDeviceDetectionDistance
1946  2, // _SETKinectDeviceDetectionAngle
1947  1, // _GETKinectDeviceDetectionAngle
1948  2, // _CRKinectUser
1949  1, // _DSKinectUser
1950 
1951  3, // _CBKinectConnected
1952  3, // _CBKinectDisconnected
1953  3, // _CBKinectUserFound
1954  3, // _CBKinectUserLost
1955  3, // _CBKinectUserCalibrationStart
1956  3, // _CBKinectUserCalibrationEnd
1957  3, // _CBKinectUserPoseDetected
1958  3, // _CBKinectUserPoseLost
1959  3, // _CBKinectUserHandFound
1960  3, // _CBKinectUserHandLost
1961  3, // _CBKinectUserHandMove
1962 
1963  3, // _GETKinectUserJointPosition
1964  3, // _GETKinectUserJointOrientation
1965  3, // _GETKinectUserJointPixelPosition
1966  2, // _GETKinectUserFingersPixelPosition
1967  2, // _GETKinectUserHandVisible
1968 
1969  TYPVAR,TYPVAR,TYPVAR, //"USER_SKEL_HEAD","USER_SKEL_NECK","USER_SKEL_TORSO",
1970  TYPVAR,TYPVAR,TYPVAR, //USER_SKEL_WAIST,USER_SKEL_L_COLLAR",USER_SKEL_L_SHOULDER,
1971  TYPVAR,TYPVAR,TYPVAR, //"USER_SKEL_L_ELBOW","USER_SKEL_L_WRIST","USER_SKEL_L_HAND",
1972  TYPVAR,TYPVAR,TYPVAR, //"USER_SKEL_L_FINGERTIP","USER_SKEL_R_COLLAR","USER_SKEL_R_SHOULDER",
1973  TYPVAR,TYPVAR,TYPVAR, //"USER_SKEL_R_ELBOW","USER_SKEL_R_WRIST","USER_SKEL_R_HAND",
1974  TYPVAR,TYPVAR,TYPVAR, //"USER_SKEL_R_FINGERTIP","USER_SKEL_L_HIP","USER_SKEL_L_KNEE",
1975  TYPVAR,TYPVAR,TYPVAR, //"USER_SKEL_L_ANKLE","USER_SKEL_L_FOOT","USER_SKEL_R_HIP",
1976  TYPVAR,TYPVAR,TYPVAR //"USER_SKEL_R_KNEE","USER_SKEL_R_ANKLE","USER_SKEL_R_FOOT",
1977 };
1978 
1982 char* KinectType[NbKinectPKG]=
1983 {
1984  NULL,
1985  NULL,
1986  "fun [Chn] ObjKinect", // _CRKinectDevice
1987  "fun [ObjKinect] I", // _DSKinectDevice
1988  "fun [I] ObjKinect", // _GETKinectDeviceById
1989  "fun [ObjKinect] I", // _GETKinectDeviceId
1990  "fun [ObjKinect] [I I]", // _GETKinectDeviceSize
1991  "fun [ObjKinect ObjBitmap] ObjBitmap", // _BLTKinectDeviceDepth
1992  "fun [ObjKinect ObjBitmap] ObjBitmap", // _BLTKinectDeviceRGB
1993  "fun [ObjKinect ObjBitmap] ObjBitmap", // _BLTKinectDeviceGrayscale
1994  "fun [ObjKinect AlphaBitmap] AlphaBitmap", // _BLTKinectDeviceUsers
1995  "fun [ObjKinect AlphaBitmap] AlphaBitmap", // _BLTKinectDeviceUsersRGB
1996  "fun [ObjKinect AlphaBitmap] AlphaBitmap", // _BLTKinectDeviceHands
1997  "fun [ObjKinect I] I", // _SETKinectDeviceMirror
1998  "fun [ObjKinect] I", // _GETKinectDeviceMirror
1999  "fun [ObjKinect F] I", // _SETKinectDeviceSkeletonSmoothing
2000  "fun [ObjKinect] F", // _GETKinectDeviceSkeletonSmoothing
2001  "fun [ObjKinect I] I", // _SETKinectDeviceDetectionDistance
2002  "fun [ObjKinect] I", // _GETKinectDeviceDetectionDistance
2003  "fun [ObjKinect F] I", // _SETKinectDeviceDetectionAngle
2004  "fun [ObjKinect] F", // _GETKinectDeviceDetectionAngle
2005  "fun [Chn ObjKinect] ObjKinectUser", // _CRKinectUser
2006  "fun [ObjKinectUser] I", // _DSKinectUser
2007 
2008  "fun [ObjKinect fun [ObjKinect u0] u1 u0] ObjKinect", // _CBKinectConnected
2009  "fun [ObjKinect fun [ObjKinect u0] u1 u0] ObjKinect", // _CBKinectDisconnected
2010  "fun [ObjKinectUser fun [ObjKinectUser u0] u1 u0] ObjKinect", // _CBKinectUserFound
2011  "fun [ObjKinectUser fun [ObjKinectUser u0] u1 u0] ObjKinect", // _CBKinectUserLost
2012  "fun [ObjKinectUser fun [ObjKinectUser u0] u1 u0] ObjKinectUser", // _CBKinectUserCalibrationStart
2013  "fun [ObjKinectUser fun [ObjKinectUser u0] u1 u0] ObjKinectUser", // _CBKinectUserCalibrationEnd
2014  "fun [ObjKinectUser fun [ObjKinectUser u0] u1 u0] ObjKinectUser", // _CBKinectUserPoseDetected
2015  "fun [ObjKinectUser fun [ObjKinectUser u0] u1 u0] ObjKinectUser", // _CBKinectUserPoseLost
2016  "fun [ObjKinectUser fun [ObjKinectUser u0 I] u1 u0] ObjKinectUser", // _CBKinectUserHandFound
2017  "fun [ObjKinectUser fun [ObjKinectUser u0 I] u1 u0] ObjKinectUser", // _CBKinectUserHandLost
2018  "fun [ObjKinectUser fun [ObjKinectUser u0 I [I I I]] u1 u0] ObjKinectUser", // _CBKinectUserHandMove
2019 
2020  "fun [ObjKinectUser I F] [F F F]", // _GETKinectUserJointPosition
2021  "fun [ObjKinectUser I F] [F F F F]", // _GETKinectUserJointOrientation
2022  "fun [ObjKinectUser I F] [I I I]", // _GETKinectUserJointPixelPosition
2023  "fun [ObjKinectUser I] [[I I] r1]", // _GETKinectUserFingersPixelPosition
2024  "fun [ObjKinectUser I] I", // _GETKinectUserHandVisible
2025 
2026  "I","I","I", //"USER_SKEL_HEAD","USER_SKEL_NECK","USER_SKEL_TORSO",
2027  "I","I","I", //USER_SKEL_WAIST,USER_SKEL_L_COLLAR",USER_SKEL_L_SHOULDER,
2028  "I","I","I", //"USER_SKEL_L_ELBOW","USER_SKEL_L_WRIST","USER_SKEL_L_HAND",
2029  "I","I","I", //"USER_SKEL_L_FINGERTIP","USER_SKEL_R_COLLAR","USER_SKEL_R_SHOULDER",
2030  "I","I","I", //"USER_SKEL_R_ELBOW","USER_SKEL_R_WRIST","USER_SKEL_R_HAND",
2031  "I","I","I", //"USER_SKEL_R_FINGERTIP","USER_SKEL_L_HIP","USER_SKEL_L_KNEE",
2032  "I","I","I", //"USER_SKEL_L_ANKLE","USER_SKEL_L_FOOT","USER_SKEL_R_HIP",
2033  "I","I","I" //"USER_SKEL_R_KNEE","USER_SKEL_R_ANKLE","USER_SKEL_R_FOOT",
2034 };
2035 
2043 int LoadOpenNiPlugin(mmachine m)
2044 {
2045  int k = 0;
2046 
2047  // Declare a new type of object ("OBJ_KINECT_SCOL")
2048  OBJ_KINECT_SCOL = OBJregister(2 /*nb of callback*/, /* deleted from parent */ 1, destroyKinectObj, "OBJ_KINECT_SCOL");
2049 
2050  //****************************** Callbacks for Kinect Obj *******************************************************
2051  KINECT_CONNECTED_CB = OBJgetUserEvent();
2052  OBJdefEvent( KINECT_CONNECTED_CB, (int (__cdecl*)(struct Mmachine*, SCOL_PTR_TYPE, LONG))getKinectConnectedCb );
2053 
2054  KINECT_DISCONNECTED_CB = OBJgetUserEvent();
2055  OBJdefEvent( KINECT_DISCONNECTED_CB, (int (__cdecl *)(struct Mmachine*, SCOL_PTR_TYPE, LONG))getKinectDisconnectedCb );
2056 
2057  // Declare a new type of object ("OBJ_KINECT_USER_SCOL")
2058  OBJ_KINECT_USER_SCOL = OBJregister(9 /*nb of callback*/, /* deleted from parent */ 1, destroyKinectUserObj, "OBJ_KINECT_USER_SCOL");
2059 
2060  KINECT_NEW_USER_CB = OBJgetUserEvent();
2061  OBJdefEvent( KINECT_NEW_USER_CB, (int (__cdecl *)(struct Mmachine*, SCOL_PTR_TYPE, LONG))getKinectNewUserCb );
2062 
2063  KINECT_LOST_USER_CB = OBJgetUserEvent();
2064  OBJdefEvent( KINECT_LOST_USER_CB, (int (__cdecl *)(struct Mmachine*, SCOL_PTR_TYPE, LONG))getKinectLostUserCb );
2065 
2066  KINECT_USER_CALIBRATION_START_CB = OBJgetUserEvent();
2067  OBJdefEvent( KINECT_USER_CALIBRATION_START_CB, (int (__cdecl *)(struct Mmachine*, SCOL_PTR_TYPE, LONG))getKinectUserCalibrationStartCb );
2068 
2069  KINECT_USER_CALIBRATION_END_CB = OBJgetUserEvent();
2070  OBJdefEvent( KINECT_USER_CALIBRATION_END_CB, (int (__cdecl *)(struct Mmachine*, SCOL_PTR_TYPE, LONG))getKinectUserCalibrationEndCb );
2071 
2072  KINECT_USER_POSE_DETECTED_CB = OBJgetUserEvent();
2073  OBJdefEvent( KINECT_USER_POSE_DETECTED_CB, (int (__cdecl *)(struct Mmachine*, SCOL_PTR_TYPE, LONG))getKinectUserPoseDetectedCb );
2074 
2075  KINECT_USER_POSE_LOST_CB = OBJgetUserEvent();
2076  OBJdefEvent( KINECT_USER_POSE_LOST_CB, (int (__cdecl *)(struct Mmachine*, SCOL_PTR_TYPE, LONG))getKinectUserPoseLostCb );
2077 
2078  KINECT_USER_HAND_FOUND_CB = OBJgetUserEvent();
2079  OBJdefEvent( KINECT_USER_HAND_FOUND_CB, (int (__cdecl *)(struct Mmachine*, SCOL_PTR_TYPE, LONG))getKinectUserHandFoundCb );
2080 
2081  KINECT_USER_HAND_LOST_CB = OBJgetUserEvent();
2082  OBJdefEvent( KINECT_USER_HAND_LOST_CB, (int (__cdecl *)(struct Mmachine*, SCOL_PTR_TYPE, LONG))getKinectUserHandLostCb );
2083 
2084  KINECT_USER_HAND_MOVE_CB = OBJgetUserEvent();
2085  OBJdefEvent( KINECT_USER_HAND_MOVE_CB, (int (__cdecl *)(struct Mmachine*, SCOL_PTR_TYPE, LONG))getKinectUserHandMoveCb );
2086 
2087  // Load package
2088  k = PKhardpak(m, "KinectEngine", NbKinectPKG, KinectName, KinectFunc, KinectNArg, KinectType);
2089 
2090  // Create main Singleton
2091  new DeviceManager();
2092  return k;
2093 }
2094 
2095 // Everything inside _cond and _endcond is ignored by doxygen
2097 
2098 #ifndef SCOL_STATIC
2099 
2102 extern "C" SCOL_EXPORT int ScolLoadPlugin(mmachine m, cbmachine w)
2103 {
2104  SCOLinitplugin(w);
2105 
2106  //init random values
2107  srand((int)time(0));
2108 
2109  LoadOpenNiPlugin(m);
2110  return 0;
2111 }
2112 
2116 extern "C" SCOL_EXPORT int ScolUnloadPlugin()
2117 {
2118  // Free main Singleton
2119  DeviceManager* sManager = DeviceManager::GetSingletonPtr();
2120  SAFE_DELETE(sManager);
2121 
2122  return 0;
2123 }
2124 #else
2125 
2128 extern "C" SCOL_EXPORT int ScolOpenNILoadPlugin(mmachine m, cbmachine w)
2129 {
2130  SCOLinitplugin(w);
2131 
2132  //init random values
2133  srand((int)time(0));
2134 
2135  LoadOpenNiPlugin(m);
2136  return 0;
2137 }
2138 
2142 extern "C" SCOL_EXPORT int ScolOpenNIUnloadPlugin()
2143 {
2144  // Free main Singleton
2145  DeviceManager* sManager = DeviceManager::GetSingletonPtr();
2146  SAFE_DELETE(sManager);
2147 
2148  return 0;
2149 }
2150 #endif //SCOL_STATIC
2151 
int _SETKinectDeviceDetectionDistance(mmachine m)
_SETKinectDeviceDetectionDistance : Set the ObjKinect user detection distance
int _CBKinectUserHandLost(mmachine m)
_CBKinectUserHandLost : This function set the Callback for hand lost from Kinect User ...
int _GETKinectUserJointPixelPosition(mmachine m)
_GETKinectUserJointPixelPosition : Get a objKinectUser hand position in pixel
int _BLTKinectDeviceRGB(mmachine m)
_BLTKinectDeviceRGB : Blit RGB image from Kinect device into a Scol Bitmap object Prototype: fun [Obj...
int _CBKinectConnected(mmachine m)
_CBKinectConnected : This function set the Callback for Connection from kinect device ...
int _GETKinectDeviceDetectionAngle(mmachine m)
_GETKinectDeviceDetectionAngle : Get the ObjKinect user detection angle
int _SETKinectDeviceMirror(mmachine m)
_SETKinectDeviceMirror : Change the mirror mode of th kinect device Prototype: fun [ObjKinect I] I ...
int _CBKinectUserHandMove(mmachine m)
_CBKinectUserHandMove : This function set the Callback for hand move from Kinect User ...
int _CBKinectUserHandFound(mmachine m)
_CBKinectUserHandFound : This function set the Callback for hand found from Kinect User ...
Kinect user handling. .
Definition: KinectUser.h:38
int _GETKinectDeviceDetectionDistance(mmachine m)
_GETKinectDeviceDetectionDistance : Get the ObjKinect user detection distance
int _GETKinectDeviceSkeletonSmoothing(mmachine m)
_GETKinectDeviceSkeletonSmoothing : Get a ObjKinect skeleton smoothing coefficient ...
int _SETKinectDeviceDetectionAngle(mmachine m)
_SETKinectDeviceDetectionAngle : Set the ObjKinect user detection angle
int _BLTKinectDeviceHands(mmachine m)
_BLTKinectDeviceHands : Blit users hands and fingers image from Kinect device into a Scol Bitmap obje...
int _BLTKinectDeviceGrayscale(mmachine m)
_BLTKinectDeviceGrayscale : Blit grayscale image from Kinect device into a Scol Bitmap object Prototy...
int _DSKinectUser(mmachine m)
_DSKinectUser : Destroy objKinectUser object
int _GETKinectUserFingersPixelPosition(mmachine m)
_GETKinectUserFingersPixelPosition : Get a objKinectUser fingers position in pixel ...
int _CBKinectUserFound(mmachine m)
_CBKinectUserFound : This function set the Callback for New User from Kinect
Kinect user hand handling. .
int _CBKinectDisconnected(mmachine m)
_CBKinectDisconnected : This function set the Callback for Disconnection from Kinect ...
int _SETKinectDeviceSkeletonSmoothing(mmachine m)
_SETKinectDeviceSkeletonSmoothing : Set a ObjKinect skeleton smoothing coefficient ...
int _CBKinectUserPoseDetected(mmachine m)
_CBKinectUserPoseDetected : This function set the Callback for detection pose from Kinect User ...
int _GETKinectDeviceById(mmachine m)
_GETKinectDeviceById : retrieve a kinect Device by name
int _GETKinectDeviceSize(mmachine m)
_GETKinectDeviceSize : retrieve a kinect Device picture size
int _CRKinectUser(mmachine m)
_CRKinectUser : Open, initialize objKinectUser
int _GETKinectUserJointPosition(mmachine m)
_GETKinectUserJointPosition : Get a objKinectUser skeleton joint position
int _CBKinectUserLost(mmachine m)
_CBKinectUserLost : This function set the Callback for Lost User from Kinect
Kinect device handling. .
Definition: KinectDevice.h:39
int _BLTKinectDeviceDepth(mmachine m)
_BLTKinectDeviceDepth : Blit the device depth picture into a bitmap Prototype: fun [ObjKinect ObjBitm...
int _DSKinectDevice(mmachine m)
_DSKinectDevice : Destroy objKinectDevice object
int _GETKinectUserJointOrientation(mmachine m)
_GETKinectUserJointOrientation : Get a objKinectUser skeleton joint orientation
Handle DeviceManager type. .
Definition: DeviceManager.h:42
int _CBKinectUserCalibrationStart(mmachine m)
_CBKinectUserCalibrationStart : This function set the Callback for Calibration start from Kinect User...
int _GETKinectUserHandVisible(mmachine m)
_GETKinectUserHandVisible : Get a objKinectUser hand visibility
int _GETKinectDeviceMirror(mmachine m)
_GETKinectDeviceMirror : Get the mirror mode of th kinect device Prototype: fun [ObjKinect] I ...
int _GETKinectDeviceId(mmachine m)
_GETKinectDeviceId : retrieve a kinect Device by name
int _BLTKinectDeviceUsers(mmachine m)
_BLTKinectDeviceUsers : Blit users image from Kinect device into a Scol Bitmap object Prototype: fun ...
int _CBKinectUserPoseLost(mmachine m)
_CBKinectUserPoseLost : This function set the Callback for lost pose from Kinect User ...
int _CBKinectUserCalibrationEnd(mmachine m)
_CBKinectUserCalibrationEnd : This function set the Callback for Calibration end from Kinect User ...
int _CRKinectDevice(mmachine m)
_CRKinectDevice : Open, initialize objKinect
int _BLTKinectDeviceUsersRGB(mmachine m)
_BLTKinectDeviceUsersRGB : Blit users image from RGB camera from Kinect device into a Scol Bitmap obj...