00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00035 #include "ScolPlugin.h"
00036
00037 #include "core/Exception.h"
00038 #include "core/DataSkeleton.h"
00039 #include "DeviceManager.h"
00040 #include "objects/KinectDevice.h"
00041 #include "generator/User.h"
00042
00044
00045 using namespace NIDevice;
00046 using namespace NIDevice::Objects;
00047
00049 cbmachine ww;
00050
00051 HWND HScol = 0;
00052
00054 int OBJ_KINECT_SCOL;
00055
00056
00057 int SCOL_KINECT_CONNECTED_CB = 0;
00058 int KINECT_CONNECTED_CB;
00059
00060
00061 int SCOL_KINECT_DISCONNECTED_CB = 1;
00062 int KINECT_DISCONNECTED_CB;
00063
00064
00066 int OBJ_KINECT_USER_SCOL;
00067
00068
00069 int SCOL_KINECT_USER_CALIBRATION_START_CB = 0;
00070 int KINECT_USER_CALIBRATION_START_CB;
00071
00072
00073 int SCOL_KINECT_USER_CALIBRATION_END_CB = 1;
00074 int KINECT_USER_CALIBRATION_END_CB;
00075
00076
00077 int SCOL_KINECT_USER_POSE_DETECTED_CB = 2;
00078 int KINECT_USER_POSE_DETECTED_CB;
00079
00080
00081 int SCOL_KINECT_USER_POSE_LOST_CB = 3;
00082 int KINECT_USER_POSE_LOST_CB;
00083
00084
00085 int SCOL_KINECT_NEW_USER_CB = 4;
00086 int KINECT_NEW_USER_CB;
00087
00088
00089 int SCOL_KINECT_LOST_USER_CB = 5;
00090 int KINECT_LOST_USER_CB;
00091
00093 NIDevice::DeviceManager* deviceManager;
00094
00095
00118 int destroyKinectUserObj(mmachine m, int handsys, int objTab)
00119 {
00120
00121 KinectUser* kinectUserObject = (KinectUser*) MMfetch(m, MTOP(objTab), 0);
00122
00123 if (kinectUserObject != 0)
00124 {
00125 try
00126 {
00127 kinectUserObject->GetParentDevice()->DestroyKinectUser(kinectUserObject);
00128 }
00129 catch (NIDevice::Core::ExceptionKinect& e)
00130 {
00131 MMechostr(MSKDEBUG,"%s",e.GetFullDescription().c_str());
00132 }
00133 }
00134
00135
00136 MMstore(m, MTOP(objTab), 0, 0);
00137
00138
00139 MMechostr(MSKDEBUG,"ObjKinectUser destroyed.\n");
00140 return 0;
00141 }
00142
00143
00153 int destroyKinectObj(mmachine m, int handsys, int objTab)
00154 {
00155
00156 KinectDevice* kinectObject = (KinectDevice*) MMfetch(m, MTOP(objTab), 0);
00157
00158 if (kinectObject != 0)
00159 {
00160 try
00161 {
00162 NIDevice::DeviceManager::GetSingletonPtr()->DestroyKinectDevice(kinectObject);
00163 }
00164 catch (NIDevice::Core::ExceptionKinect& e)
00165 {
00166 MMechostr(MSKDEBUG,"%s",e.GetFullDescription().c_str());
00167 }
00168 }
00169
00170
00171 MMstore(m, MTOP(objTab), 0, 0);
00172
00173
00174 MMechostr(MSKDEBUG,"ObjKinect destroyed.\n");
00175 return 0;
00176 }
00177
00178
00188 int _CRKinectDevice(mmachine m)
00189 {
00190 #ifdef _SCOL_DEBUG_
00191 MMechostr(MSKDEBUG,"_CRKinectDevice\n");
00192 #endif
00193
00194
00195 int k = 0;
00196
00197
00198 KinectDevice* newKinectDevice = 0;
00199 if ((NIDevice::DeviceManager::GetSingletonPtr()) == 0)
00200 {
00201 MMset(m, 0, NIL);
00202 return 0;
00203 }
00204
00205 try
00206 {
00207 newKinectDevice = NIDevice::DeviceManager::GetSingletonPtr()->CreateKinectDevice();
00208 }
00209 catch (NIDevice::Core::ExceptionKinect& e)
00210 {
00211 MMechostr(MSKDEBUG,"%s",e.GetFullDescription().c_str());
00212 MMset(m, 0, NIL);
00213 return 0;
00214 }
00215
00216 if (newKinectDevice == 0)
00217 {
00218 MMechostr(MSKDEBUG, "_CRobjKinect ...creation failed\n");
00219 SAFE_DELETE(newKinectDevice);
00220 MMset(m, 0, NIL);
00221 return 0;
00222 }
00223 MMechostr(MSKDEBUG,"_CRobjKinect ...creation successful\n");
00224
00225 int objTab = MMmalloc(m, 1, TYPETAB);
00226 if (objTab == NIL)
00227 {
00228 MMechostr(MSKDEBUG,"_CRobjKinect ...MMmalloc failed\n");
00229 SAFE_DELETE(newKinectDevice);
00230 MMset(m, 0, NIL);
00231 return 0;
00232 }
00233 MMechostr(MSKDEBUG,"_CRobjKinect ...MMmalloc successful\n");
00234
00235
00236 MMstore(m, objTab, 0, (int)newKinectDevice);
00237 MMpush(m, PTOM(objTab));
00238
00239
00240 k = OBJcreate(m, OBJ_KINECT_SCOL, (int)newKinectDevice, 0, 0);
00241 MMechostr(MSKDEBUG,"_CRobjKinectDevice ...object creation successful\n");
00242
00243 #ifdef _SCOL_DEBUG_
00244 MMechostr(MSKDEBUG,"ok\n");
00245 #endif
00246
00247 return k;
00248 }
00249
00259 int _DSKinectDevice(mmachine m)
00260 {
00261 #ifdef _SCOL_DEBUG_
00262 MMechostr(MSKDEBUG,"_DSKinectDevice\n");
00263 #endif
00264
00265 int objTab = MMget(m, 0);
00266 if ( objTab == NIL )
00267 {
00268 MMset(m, 0, NIL);
00269 return 0;
00270 }
00271
00272 OBJdelTM( m, OBJ_KINECT_SCOL, objTab);
00273 MMset(m, 0, ITOM(1));
00274
00275 #ifdef _SCOL_DEBUG_
00276 MMechostr(MSKDEBUG,"ok\n");
00277 #endif
00278 return 0;
00279 }
00280
00290 int _GETKinectDeviceById(mmachine m)
00291 {
00292 #ifdef _SCOL_DEBUG_
00293 MMechostr(MSKDEBUG,"_GETKinectDeviceById\n");
00294 #endif
00295
00296
00297 int kId = MMget(m, 0);
00298
00299 if (kId == NIL)
00300 kId = 0;
00301 else
00302 kId = MTOI(kId);
00303
00304 KinectDevice* newKinectDevice=0;
00305 try
00306 {
00307 newKinectDevice = NIDevice::DeviceManager::GetSingletonPtr()->GetKinectDevice(kId);
00308 }
00309 catch (NIDevice::Core::ExceptionKinect& e)
00310 {
00311 MMechostr(MSKDEBUG,"%s",e.GetFullDescription().c_str());
00312 MMset(m, 0, NIL);
00313 return 0;
00314 }
00315
00316 if (newKinectDevice == 0)
00317 {
00318 MMechostr(MSKDEBUG, "_GETKinectDeviceById ... not found\n");
00319 MMset(m, 0, NIL);
00320 return 0;
00321 }
00322
00323 int kin = OBJfindTH(m, OBJ_KINECT_SCOL, (int)(newKinectDevice));
00324 if(kin!=NIL)
00325 kin = MMfetch(m, kin, OFFOBJMAG);
00326
00327 MMset(m, 0, kin);
00328
00329 #ifdef _SCOL_DEBUG_
00330 MMechostr(MSKDEBUG,"ok\n");
00331 #endif
00332
00333 return 0;
00334 }
00335
00343 int _GETKinectDeviceId(mmachine m)
00344 {
00345 #ifdef _SCOL_DEBUG_
00346 MMechostr(MSKDEBUG,"_GETKinectDeviceId\n");
00347 #endif
00348
00349 int objTab = MMget(m, 0);
00350 if (objTab == NIL)
00351 {
00352 MMset(m, 0, NIL);
00353 return 0;
00354 }
00355
00356 KinectDevice* kinectObject = (KinectDevice*) MMfetch(m, MTOP(objTab), 0);
00357 if(kinectObject==NULL)
00358 {
00359 MMset(m, 0, NIL);
00360 return 0;
00361 }
00362
00363 MMset(m, 0, ITOM(kinectObject->GetId()));
00364
00365 #ifdef _SCOL_DEBUG_
00366 MMechostr(MSKDEBUG,"ok\n");
00367 #endif
00368
00369 return 0;
00370 }
00371
00380 int _BLTKinectDeviceDepth(mmachine m)
00381 {
00382 #ifdef SCOL_DEBUG
00383 MMechostr(MSKDEBUG, "_BLTKinectDeviceDepth\n");
00384 #endif
00385
00386 int bitmap = MMpull(m);
00387 int kinect = MMget(m, 0);
00388 if (kinect == NIL || bitmap == NIL)
00389 {
00390 MMset(m, 0, NIL);
00391 return 0;
00392 }
00393
00394 NIDevice::Objects::KinectDevice* KinectOBJ = (NIDevice::Objects::KinectDevice*) MMfetch(m, MTOP(kinect), 0);
00395
00396 if (KinectOBJ == NULL)
00397 {
00398 MMset(m, 0, NIL);
00399 return 0;
00400 }
00401
00402 if(!KinectOBJ->IsGenerating())
00403 {
00404 MMset(m, 0, NIL);
00405 return 0;
00406 }
00407
00408 const unsigned short* depthMap;
00409 int depthW, depthH;
00410 float* history;
00411 try
00412 {
00413
00414 depthMap = KinectOBJ->GetDepthGenerator()->GetDepthBuffer(true);
00415 KinectOBJ->GetDepthGenerator()->GetDepthSize(depthW, depthH);
00416 history = KinectOBJ->GetDepthGenerator()->GetHistory();
00417 }
00418 catch (NIDevice::Core::ExceptionKinect& e)
00419 {
00420 MMechostr(MSKDEBUG, "%s", e.GetFullDescription().c_str());
00421 MMset(m, 0, bitmap);
00422 return 0;
00423 }
00424
00425
00426 PtrObjVoid OB = (PtrObjVoid) MMstart(m, MTOP(bitmap));
00427 PtrObjBitmap B = (PtrObjBitmap) MMstart(m, MTOP(OB->Buffer));
00428
00429
00430 if ((B->TailleW != depthW) || (B->TailleH != depthH))
00431 {
00432 MMset(m, 0, NIL);
00433 return 0;
00434 }
00435
00436
00437
00438
00439 long x = 0, y = 0;
00440 unsigned long srcByte = 0, destByte = 0;
00441 unsigned int mask = 0;
00442 unsigned int color = 0;
00443 for (y=0; y<depthH; y++)
00444 {
00445 for (x=0; x<depthW; x++)
00446 {
00447
00448
00449
00450
00451
00452
00453 srcByte = x + y*depthW;
00454 destByte = srcByte * 3;
00455 color = history[depthMap[srcByte]] *255;;
00456
00457 B->bits[destByte] = color;
00458 B->bits[destByte+1] = color;
00459 B->bits[destByte+2] = color;
00460 }
00461 }
00462
00463
00464 MMset(m, 0, bitmap);
00465
00466 #ifdef SCOL_DEBUG
00467 MMechostr(MSKDEBUG, "ok\n");
00468 #endif
00469 return 0;
00470 }
00471
00480 int _BLTKinectDeviceRGB(mmachine m)
00481 {
00482 #ifdef SCOL_DEBUG
00483 MMechostr(MSKDEBUG, "_BLTKinectDeviceRGB\n");
00484 #endif
00485
00486 int bitmap = MMpull(m);
00487 int kinect = MMget(m, 0);
00488 if (kinect == NIL || bitmap == NIL)
00489 {
00490 MMset(m, 0, NIL);
00491 return 0;
00492 }
00493
00494
00495 NIDevice::Objects::KinectDevice* KinectOBJ = (NIDevice::Objects::KinectDevice*) MMfetch(m, MTOP(kinect), 0);
00496 if (KinectOBJ == NULL)
00497 {
00498 MMset(m, 0, NIL);
00499 return 0;
00500 }
00501
00502 if(!KinectOBJ->IsGenerating())
00503 {
00504 MMset(m, 0, NIL);
00505 return 0;
00506 }
00507
00508
00509 const unsigned char* rgbMap;
00510 int rgbW, rgbH;
00511 try
00512 {
00513 rgbMap = KinectOBJ->GetImageGenerator()->GetImageBuffer();
00514 KinectOBJ->GetImageGenerator()->GetImageSize(rgbW, rgbH);
00515 }
00516 catch (NIDevice::Core::ExceptionKinect& e)
00517 {
00518 MMechostr(MSKDEBUG, "%s", e.GetFullDescription().c_str());
00519 MMset(m, 0, bitmap);
00520 return 0;
00521 }
00522
00523
00524 PtrObjVoid OB = (PtrObjVoid) MMstart(m, MTOP(bitmap));
00525 PtrObjBitmap B = (PtrObjBitmap) MMstart(m, MTOP(OB->Buffer));
00526
00527 if ((B->TailleW != rgbW) || (B->TailleH != rgbH))
00528 {
00529 MMset(m, 0, NIL);
00530 return 0;
00531 }
00532
00533
00534
00535
00536 long x = 0, y = 0;
00537 unsigned long srcByte = 0, destByte = 0;
00538 for (y = 0; y < rgbH; y++)
00539 {
00540 for (x = 0; x < rgbW; x++)
00541 {
00542
00543
00544
00545
00546
00547
00548 srcByte = x*3 + y*rgbW*3;
00549 destByte = x*3 + y*rgbW*3;
00550
00551 B->bits[destByte] = rgbMap[srcByte+2];
00552 B->bits[destByte+1] = rgbMap[srcByte+1];
00553 B->bits[destByte+2] = rgbMap[srcByte];
00554 }
00555 }
00556 MMset(m, 0, bitmap);
00557
00558 #ifdef SCOL_DEBUG
00559 MMechostr(MSKDEBUG, "ok\n");
00560 #endif
00561 return 0;
00562 }
00563
00572 int _BLTKinectDeviceGrayscale(mmachine m)
00573 {
00574 #ifdef SCOL_DEBUG
00575 MMechostr(MSKDEBUG, "_BLTKinectDeviceGrayscale\n");
00576 #endif
00577
00578 int bitmap = MTOP(MMpull(m));
00579 int kinect = MTOP(MMget(m, 0));
00580 if (kinect == NIL || bitmap == NIL)
00581 {
00582 MMset(m, 0, NIL);
00583 return 0;
00584 }
00585
00586
00587 NIDevice::Objects::KinectDevice* KinectOBJ = (NIDevice::Objects::KinectDevice*) MMfetch(m, kinect, 0);
00588 if (KinectOBJ == NULL)
00589 {
00590 MMset(m, 0, NIL);
00591 return 0;
00592 }
00593
00594
00595 const unsigned char* grayscaleMap;
00596 int grayscaleW, grayscaleH;
00597 try
00598 {
00599 grayscaleMap = KinectOBJ->GetImageGenerator()->GetImageBuffer();
00600 KinectOBJ->GetImageGenerator()->GetImageSize(grayscaleW, grayscaleH);
00601 }
00602 catch (NIDevice::Core::ExceptionKinect& e)
00603 {
00604 MMechostr(MSKDEBUG, "%s", e.GetFullDescription().c_str());
00605 MMset(m, 0, bitmap);
00606 return 0;
00607 }
00608
00609
00610 PtrObjVoid OB = (PtrObjVoid) MMstart(m, bitmap);
00611 PtrObjBitmap B = (PtrObjBitmap) MMstart(m, MTOP(OB->Buffer));
00612
00613 if ((B->TailleW != grayscaleW) || (B->TailleH != grayscaleH))
00614 {
00615 MMset(m, 0, NIL);
00616 return 0;
00617 }
00618
00619
00620
00621
00622 long x = 0, y = 0;
00623 unsigned long srcByte = 0, destByte = 0;
00624 for (y = 0; y < grayscaleH; y++)
00625 {
00626 for (x = 0; x < grayscaleW; x++)
00627 {
00628
00629
00630
00631
00632
00633
00634 srcByte = x*3 + y*grayscaleW*3;
00635 destByte = x*3 + y*grayscaleW*3;
00636
00637
00638
00639 B->bits[destByte] = grayscaleMap[srcByte];
00640 B->bits[destByte+1] = grayscaleMap[srcByte];
00641 B->bits[destByte+2] = grayscaleMap[srcByte];
00642 }
00643 }
00644 MMset(m, 0, PTOM(bitmap));
00645
00646 #ifdef SCOL_DEBUG
00647 MMechostr(MSKDEBUG, "ok\n");
00648 #endif
00649 return 0;
00650 }
00651
00660 int _BLTKinectDeviceUsers(mmachine m)
00661 {
00662 #ifdef SCOL_DEBUG
00663 MMechostr(MSKDEBUG, "_BLTKinectDeviceRGB\n");
00664 #endif
00665
00666 int bitmap = MMpull(m);
00667 int kinect = MMget(m, 0);
00668 if (kinect == NIL || bitmap == NIL)
00669 {
00670 MMset(m, 0, NIL);
00671 return 0;
00672 }
00673
00674
00675 NIDevice::Objects::KinectDevice* KinectOBJ = (NIDevice::Objects::KinectDevice*) MMfetch(m, MTOP(kinect), 0);
00676 if (KinectOBJ == NULL)
00677 {
00678 MMset(m, 0, NIL);
00679 return 0;
00680 }
00681
00682 if(!KinectOBJ->IsGenerating())
00683 {
00684 MMset(m, 0, NIL);
00685 return 0;
00686 }
00687
00688
00689 const unsigned short* rgbMap;
00690 int rgbW, rgbH;
00691 try
00692 {
00693 rgbMap = KinectOBJ->GetUserGenerator()->GetUserPixels();
00694 KinectOBJ->GetUserGenerator()->GetImageSize(rgbW, rgbH);
00695 }
00696 catch (NIDevice::Core::ExceptionKinect& e)
00697 {
00698 MMechostr(MSKDEBUG, "%s", e.GetFullDescription().c_str());
00699 MMset(m, 0, bitmap);
00700 return 0;
00701 }
00702
00703
00704 int colorLayer = MMfetch(m, MTOP(bitmap), 0);
00705 int alphaLayer = MMfetch(m, MTOP(bitmap), 1);
00706
00707 PtrObjVoid OBcolor;
00708 PtrObjBitmap Bcolor;
00709 OBcolor = (PtrObjVoid) MMstart(m, MTOP(colorLayer));
00710 if(OBcolor->Type != OBJ_TYPE_BITMAP << 1)
00711 {
00712 MMset(m, 0, NIL);
00713 return 0;
00714 }
00715 Bcolor = (PtrObjBitmap) MMstart(m, MTOP(OBcolor->Buffer));
00716
00717 PtrObjVoid OBalpha;
00718 PtrObjBitmap Balpha;
00719 OBalpha = (PtrObjVoid) MMstart(m, MTOP(alphaLayer));
00720 if(OBalpha->Type != OBJ_TYPE_BITMAP << 1)
00721 {
00722 MMset(m, 0, NIL);
00723 return 0;
00724 }
00725 Balpha = (PtrObjBitmap) MMstart(m,MTOP(OBalpha->Buffer));
00726
00727 if ((Bcolor->TailleW != rgbW) || (Bcolor->TailleH != rgbH))
00728 {
00729 MMset(m, 0, NIL);
00730 return 0;
00731 }
00732
00733 if ((Balpha->TailleW != rgbW) || (Balpha->TailleH != rgbH))
00734 {
00735 MMset(m, 0, NIL);
00736 return 0;
00737 }
00738
00739 bool isMirror = KinectOBJ->GetMirrorMode();
00740
00741
00742 NIDevice::Objects::KinectUser* tUsers[16];
00743 memset(tUsers, 0, 16);
00744 KinectOBJ->GetValidUsersMap(tUsers);
00745
00746
00747 long x = 0, y = 0;
00748 unsigned long srcByte = 0, destByte = 0;
00749 for (y = 0; y < rgbH; y++)
00750 {
00751 for (x = 0; x < rgbW; x++)
00752 {
00753 unsigned int fixed_x = x;
00754 if(!isMirror)
00755 {
00756 fixed_x = (rgbW - 1) - x;
00757 }
00758
00759 srcByte = y*rgbW + fixed_x;
00760 destByte = x*3 + y*rgbW*3;
00761
00762 int id = rgbMap[srcByte];
00763
00764 int color = 0;
00765
00766 KinectUser* user = tUsers[id];
00767 if (user != 0)
00768 color = user->GetColor();
00769
00770 Bcolor->bits[destByte] = color &0xFF;
00771 Bcolor->bits[destByte+1] = color>>8 &0xFF;
00772 Bcolor->bits[destByte+2] = color>>16 &0xFF;
00773 Balpha->bits[(x + y*rgbW)] = (user == 0) || (id == 0) ? 0 : 0xFF;
00774 }
00775 }
00776 MMset(m, 0, bitmap);
00777
00778 #ifdef SCOL_DEBUG
00779 MMechostr(MSKDEBUG, "ok\n");
00780 #endif
00781 return 0;
00782 }
00783
00792 int _SETKinectDeviceMirror(mmachine m)
00793 {
00794 #ifdef SCOL_DEBUG
00795 MMechostr(MSKDEBUG, "_SETKinectDeviceMirror\n");
00796 #endif
00797
00798 int mode = MMpull(m);
00799 int kinect = MMget(m, 0);
00800 if (kinect == NIL)
00801 {
00802 MMset(m, 0, NIL);
00803 return 0;
00804 }
00805
00806
00807 NIDevice::Objects::KinectDevice* KinectOBJ = (NIDevice::Objects::KinectDevice*) MMfetch(m, MTOP(kinect), 0);
00808 if (KinectOBJ == NULL)
00809 {
00810 MMset(m, 0, NIL);
00811 return 0;
00812 }
00813
00814 bool bMode = false;
00815 if (MTOI(mode) == 1)
00816 bMode = true;
00817
00818 KinectOBJ->SetMirrorMode(bMode);
00819
00820 MMset(m, 0, ITOM(1));
00821
00822 #ifdef SCOL_DEBUG
00823 MMechostr(MSKDEBUG, "ok\n");
00824 #endif
00825 return 0;
00826 }
00827
00835 int _GETKinectDeviceMirror(mmachine m)
00836 {
00837 #ifdef SCOL_DEBUG
00838 MMechostr(MSKDEBUG, "_GETKinectDeviceMirror\n");
00839 #endif
00840
00841 int kinect = MMget(m, 0);
00842 if (kinect == NIL)
00843 {
00844 MMset(m, 0, NIL);
00845 return 0;
00846 }
00847
00848
00849 NIDevice::Objects::KinectDevice* KinectOBJ = (NIDevice::Objects::KinectDevice*) MMfetch(m, MTOP(kinect), 0);
00850 if (KinectOBJ == NULL)
00851 {
00852 MMset(m, 0, NIL);
00853 return 0;
00854 }
00855
00856 bool bMode = KinectOBJ->GetMirrorMode();;
00857
00858 MMset(m, 0, ITOM(bMode == true ? 1 : 0));
00859
00860 #ifdef SCOL_DEBUG
00861 MMechostr(MSKDEBUG, "ok\n");
00862 #endif
00863 return 0;
00864 }
00865
00876 int _SETKinectDeviceSkeletonSmoothing(mmachine m)
00877 {
00878 #ifdef _SCOL_DEBUG_
00879 MMechostr(MSKDEBUG,"_SETKinectDeviceSkeletonSmoothing\n");
00880 #endif
00881
00882 int ismooth = MMpull(m);
00883 int kinect = MMget(m, 0);
00884 if (kinect == NIL)
00885 {
00886 MMset(m, 0, NIL);
00887 return 0;
00888 }
00889
00890
00891 NIDevice::Objects::KinectDevice* KinectOBJ = (NIDevice::Objects::KinectDevice*) MMfetch(m, MTOP(kinect), 0);
00892 if (KinectOBJ == NULL)
00893 {
00894 MMset(m, 0, NIL);
00895 return 0;
00896 }
00897
00898 float fsmooth = 0.0f;
00899 if ((ismooth != NIL) && (MTOF(ismooth) > 0.0f))
00900 fsmooth = MTOF(ismooth);
00901
00902 if ((fsmooth) > 1.0f)
00903 fsmooth = 1.0f;
00904
00905 KinectOBJ->SetSkeletonSmoothing(fsmooth);
00906
00907 MMset(m, 0, ITOM(1));
00908
00909 #ifdef _SCOL_DEBUG_
00910 MMechostr(MSKDEBUG,"ok\n");
00911 #endif
00912 return 0;
00913 }
00914
00924 int _GETKinectDeviceSkeletonSmoothing(mmachine m)
00925 {
00926 #ifdef _SCOL_DEBUG_
00927 MMechostr(MSKDEBUG,"_GETKinectDeviceSkeletonSmoothing\n");
00928 #endif
00929
00930 int kinect = MMget(m, 0);
00931 if (kinect == NIL)
00932 {
00933 MMset(m, 0, NIL);
00934 return 0;
00935 }
00936
00937
00938 NIDevice::Objects::KinectDevice* KinectOBJ = (NIDevice::Objects::KinectDevice*) MMfetch(m, MTOP(kinect), 0);
00939 if (KinectOBJ == NULL)
00940 {
00941 MMset(m, 0, NIL);
00942 return 0;
00943 }
00944
00945 float smooth = KinectOBJ->GetSkeletonSmoothing();
00946
00947 MMset(m, 0, FTOM(smooth));
00948
00949 #ifdef _SCOL_DEBUG_
00950 MMechostr(MSKDEBUG,"ok\n");
00951 #endif
00952 return 0;
00953 }
00954
00965 int _SETKinectDeviceDetectionDistance(mmachine m)
00966 {
00967 #ifdef _SCOL_DEBUG_
00968 MMechostr(MSKDEBUG,"_SETKinectDeviceDetectionDistance\n");
00969 #endif
00970
00971 int idist = MMpull(m);
00972 int kinect = MMget(m, 0);
00973 if (kinect == NIL)
00974 {
00975 MMset(m, 0, NIL);
00976 return 0;
00977 }
00978
00979
00980 NIDevice::Objects::KinectDevice* KinectOBJ = (NIDevice::Objects::KinectDevice*) MMfetch(m, MTOP(kinect), 0);
00981 if (KinectOBJ == NULL)
00982 {
00983 MMset(m, 0, NIL);
00984 return 0;
00985 }
00986
00987 int dist = 10000;
00988 if ((idist != NIL) && (MTOI(idist) > 0))
00989 dist = MTOI(idist) * 10;
00990
00991 KinectOBJ->SetDistCutoff(dist);
00992
00993 MMset(m, 0, ITOM(1));
00994
00995 #ifdef _SCOL_DEBUG_
00996 MMechostr(MSKDEBUG,"ok\n");
00997 #endif
00998 return 0;
00999 }
01000
01010 int _GETKinectDeviceDetectionDistance(mmachine m)
01011 {
01012 #ifdef _SCOL_DEBUG_
01013 MMechostr(MSKDEBUG,"_GETKinectDeviceDetectionDistance\n");
01014 #endif
01015
01016 int kinect = MMget(m, 0);
01017 if (kinect == NIL)
01018 {
01019 MMset(m, 0, NIL);
01020 return 0;
01021 }
01022
01023
01024 NIDevice::Objects::KinectDevice* KinectOBJ = (NIDevice::Objects::KinectDevice*) MMfetch(m, MTOP(kinect), 0);
01025 if (KinectOBJ == NULL)
01026 {
01027 MMset(m, 0, NIL);
01028 return 0;
01029 }
01030
01031 int dist = KinectOBJ->GetDistCutoff();
01032
01033 MMset(m, 0, ITOM(dist / 10));
01034
01035 #ifdef _SCOL_DEBUG_
01036 MMechostr(MSKDEBUG,"ok\n");
01037 #endif
01038 return 0;
01039 }
01040
01051 int _SETKinectDeviceDetectionAngle(mmachine m)
01052 {
01053 #ifdef _SCOL_DEBUG_
01054 MMechostr(MSKDEBUG,"_SETKinectDeviceDetectionAngle\n");
01055 #endif
01056
01057 int iangle = MMpull(m);
01058 int kinect = MMget(m, 0);
01059 if (kinect == NIL)
01060 {
01061 MMset(m, 0, NIL);
01062 return 0;
01063 }
01064
01065
01066 NIDevice::Objects::KinectDevice* KinectOBJ = (NIDevice::Objects::KinectDevice*) MMfetch(m, MTOP(kinect), 0);
01067 if (KinectOBJ == NULL)
01068 {
01069 MMset(m, 0, NIL);
01070 return 0;
01071 }
01072
01073 float fang = 0.0f;
01074 if ((iangle != NIL) && (MTOF(iangle) > 0))
01075 fang = MTOF(iangle);
01076
01077 KinectOBJ->SetAngCutoff(fang);
01078
01079 MMset(m, 0, ITOM(1));
01080
01081 #ifdef _SCOL_DEBUG_
01082 MMechostr(MSKDEBUG,"ok\n");
01083 #endif
01084 return 0;
01085 }
01086
01096 int _GETKinectDeviceDetectionAngle(mmachine m)
01097 {
01098 #ifdef _SCOL_DEBUG_
01099 MMechostr(MSKDEBUG,"_GETKinectDeviceDetectionAngle\n");
01100 #endif
01101
01102 int kinect = MMget(m, 0);
01103 if (kinect == NIL)
01104 {
01105 MMset(m, 0, NIL);
01106 return 0;
01107 }
01108
01109
01110 NIDevice::Objects::KinectDevice* KinectOBJ = (NIDevice::Objects::KinectDevice*) MMfetch(m, MTOP(kinect), 0);
01111 if (KinectOBJ == NULL)
01112 {
01113 MMset(m, 0, NIL);
01114 return 0;
01115 }
01116
01117 float fdist = KinectOBJ->GetAngCutoff();
01118
01119 MMset(m, 0, FTOM(fdist));
01120
01121 #ifdef _SCOL_DEBUG_
01122 MMechostr(MSKDEBUG,"ok\n");
01123 #endif
01124 return 0;
01125 }
01126
01138 int _CBKinectConnected(mmachine m)
01139 {
01140 return OBJaddreflex(m, OBJ_KINECT_SCOL, SCOL_KINECT_CONNECTED_CB);
01141 }
01142
01143 int getKinectConnectedCb(mmachine m,HWND h,unsigned msg,UINT id,LONG param,int *ret)
01144 {
01145 int k = 0;
01146 NIDevice::Objects::KinectDevice* mKinectObj = (NIDevice::Objects::KinectDevice*) id;
01147
01148 if (OBJbeginreflex(m, OBJ_KINECT_SCOL, (int)mKinectObj, SCOL_KINECT_CONNECTED_CB))
01149 return 0;
01150 if ((k=OBJcallreflex(m, 0))) return k;
01151 return k;
01152 }
01153
01165 int _CBKinectDisconnected(mmachine m)
01166 {
01167 return OBJaddreflex(m, OBJ_KINECT_SCOL, SCOL_KINECT_DISCONNECTED_CB);
01168 }
01169
01170 int getKinectDisconnectedCb(mmachine m,HWND h,unsigned msg,UINT id,LONG param,int *ret)
01171 {
01172 int k = 0;
01173 NIDevice::Objects::KinectDevice* mKinectObj = (NIDevice::Objects::KinectDevice*) id;
01174
01175 if (OBJbeginreflex(m, OBJ_KINECT_SCOL, (int)mKinectObj, SCOL_KINECT_DISCONNECTED_CB))
01176 return 0;
01177 if ((k=OBJcallreflex(m, 0))) return k;
01178 return k;
01179 }
01180
01191 int _CRKinectUser(mmachine m)
01192 {
01193 #ifdef _SCOL_DEBUG_
01194 MMechostr(MSKDEBUG,"_CRKinectUser\n");
01195 #endif
01196
01197 int k = 0;
01198
01199 int ikindevice = MMpull(m);
01200 if (ikindevice == NIL)
01201 {
01202 MMset(m, 0, NIL);
01203 return 0;
01204 }
01205
01206
01207 KinectDevice* kinectDevice = (KinectDevice*) MMfetch(m, MTOP(ikindevice), 0);
01208 if(kinectDevice==NULL)
01209 {
01210 MMechostr(MSKDEBUG, "Device NIL\n");
01211 MMset(m, 0, NIL);
01212 return 0;
01213 }
01214
01215
01216 KinectUser* newKinectUser=0;
01217 try
01218 {
01219 newKinectUser = kinectDevice->CreateKinectUser();
01220 }
01221 catch (NIDevice::Core::ExceptionKinect& e)
01222 {
01223 MMechostr(MSKDEBUG,"%s",e.GetFullDescription().c_str());
01224 MMset(m, 0, NIL);
01225 return 0;
01226 }
01227
01228 if (newKinectUser == 0)
01229 {
01230 MMechostr(MSKDEBUG, "_CRKinectUser ...creation failed\n");
01231 SAFE_DELETE(newKinectUser);
01232 MMset(m, 0, NIL);
01233 return 0;
01234 }
01235 MMechostr(MSKDEBUG,"_CRKinectUser ...creation successful\n");
01236
01237
01238 int objTab = MMmalloc(m, 1, TYPETAB);
01239 if (objTab == NIL)
01240 {
01241 MMechostr(MSKDEBUG,"_CRKinectUser ...MMmalloc failed\n");
01242 SAFE_DELETE(newKinectUser);
01243 MMset(m, 0, NIL);
01244 return 0;
01245 }
01246 MMechostr(MSKDEBUG,"_CRKinectUser ...MMmalloc successful\n");
01247
01248
01249 MMstore(m, objTab, 0, (int)newKinectUser);
01250 MMpush(m, PTOM(objTab));
01251
01252
01253 k = OBJcreate(m, OBJ_KINECT_USER_SCOL, (int)newKinectUser, OBJ_KINECT_SCOL, (int)kinectDevice);
01254 MMechostr(MSKDEBUG,"_CRKinectUser ...object creation successful\n");
01255
01256 #ifdef _SCOL_DEBUG_
01257 MMechostr(MSKDEBUG,"ok\n");
01258 #endif
01259
01260 return k;
01261 }
01262
01272 int _DSKinectUser(mmachine m)
01273 {
01274 #ifdef _SCOL_DEBUG_
01275 MMechostr(MSKDEBUG,"_DSKinectUser\n");
01276 #endif
01277
01278 int objTab = MMget(m, 0);
01279 if ( objTab == NIL)
01280 {
01281 MMset(m,0,NIL);
01282 return 0;
01283 }
01284
01285 OBJdelTM( m, OBJ_KINECT_USER_SCOL, objTab);
01286 MMset(m, 0, ITOM(1));
01287
01288 #ifdef _SCOL_DEBUG_
01289 MMechostr(MSKDEBUG,"ok\n");
01290 #endif
01291 return 0;
01292 }
01293
01305 int _CBKinectUserFound(mmachine m)
01306 {
01307 return OBJaddreflex(m, OBJ_KINECT_USER_SCOL, SCOL_KINECT_NEW_USER_CB);
01308 }
01309
01310 int getKinectNewUserCb(mmachine m,HWND h,unsigned msg,UINT id,LONG param,int *ret)
01311 {
01312 int k = 0;
01313 NIDevice::Objects::KinectUser* mKinectUserObj = (NIDevice::Objects::KinectUser*) id;
01314
01315 if (OBJbeginreflex(m, OBJ_KINECT_USER_SCOL, (int)mKinectUserObj, SCOL_KINECT_NEW_USER_CB))
01316 return 0;
01317 if ((k=OBJcallreflex(m, 0))) return k;
01318 return k;
01319 }
01320
01332 int _CBKinectUserLost(mmachine m)
01333 {
01334 return OBJaddreflex(m, OBJ_KINECT_USER_SCOL, SCOL_KINECT_LOST_USER_CB);
01335 }
01336
01337 int getKinectLostUserCb(mmachine m,HWND h,unsigned msg,UINT id,LONG param,int *ret)
01338 {
01339 int k = 0;
01340 NIDevice::Objects::KinectUser* mKinectUserObj = (NIDevice::Objects::KinectUser*) id;
01341
01342 if (OBJbeginreflex(m, OBJ_KINECT_USER_SCOL, (int)mKinectUserObj, SCOL_KINECT_LOST_USER_CB))
01343 return 0;
01344 if ((k=OBJcallreflex(m, 0))) return k;
01345 return k;
01346 }
01347
01359 int _CBKinectUserCalibrationStart(mmachine m)
01360 {
01361 return OBJaddreflex(m, OBJ_KINECT_USER_SCOL, SCOL_KINECT_USER_CALIBRATION_START_CB);
01362 }
01363
01364 int getKinectUserCalibrationStartCb(mmachine m,HWND h,unsigned msg,UINT id,LONG param,int *ret)
01365 {
01366 int k = 0;
01367 NIDevice::Objects::KinectUser* mKinectUserObj = (NIDevice::Objects::KinectUser*) id;
01368
01369 if (OBJbeginreflex(m, OBJ_KINECT_USER_SCOL, (int)mKinectUserObj, SCOL_KINECT_USER_CALIBRATION_START_CB))
01370 return 0;
01371 if ((k=OBJcallreflex(m, 0))) return k;
01372 return k;
01373 }
01374
01386 int _CBKinectUserCalibrationEnd(mmachine m)
01387 {
01388 return OBJaddreflex(m, OBJ_KINECT_USER_SCOL, SCOL_KINECT_USER_CALIBRATION_END_CB);
01389 }
01390
01391 int getKinectUserCalibrationEndCb(mmachine m,HWND h,unsigned msg,UINT id,LONG param,int *ret)
01392 {
01393 int k = 0;
01394 NIDevice::Objects::KinectUser* mKinectUserObj = (NIDevice::Objects::KinectUser*) id;
01395
01396 if (OBJbeginreflex(m, OBJ_KINECT_USER_SCOL, (int)mKinectUserObj, SCOL_KINECT_USER_CALIBRATION_END_CB))
01397 return 0;
01398 if ((k=OBJcallreflex(m, 0))) return k;
01399 return k;
01400 }
01401
01413 int _CBKinectUserPoseDetected(mmachine m)
01414 {
01415 return OBJaddreflex(m, OBJ_KINECT_USER_SCOL, SCOL_KINECT_USER_POSE_DETECTED_CB);
01416 }
01417
01418 int getKinectUserPoseDetectedCb(mmachine m,HWND h,unsigned msg,UINT id,LONG param,int *ret)
01419 {
01420 int k = 0;
01421 NIDevice::Objects::KinectUser* mKinectUserObj = (NIDevice::Objects::KinectUser*) id;
01422
01423 if (OBJbeginreflex(m, OBJ_KINECT_USER_SCOL, (int)mKinectUserObj, SCOL_KINECT_USER_POSE_DETECTED_CB))
01424 return 0;
01425 if ((k=OBJcallreflex(m, 0))) return k;
01426 return k;
01427 }
01428
01440 int _CBKinectUserPoseLost(mmachine m)
01441 {
01442 return OBJaddreflex(m, OBJ_KINECT_USER_SCOL, SCOL_KINECT_USER_POSE_LOST_CB);
01443 }
01444
01445 int getKinectUserPoseLostCb(mmachine m,HWND h,unsigned msg,UINT id,LONG param,int *ret)
01446 {
01447 int k = 0;
01448 NIDevice::Objects::KinectUser* mKinectUserObj = (NIDevice::Objects::KinectUser*) id;
01449
01450 if (OBJbeginreflex(m, OBJ_KINECT_USER_SCOL, (int)mKinectUserObj, SCOL_KINECT_USER_POSE_LOST_CB))
01451 return 0;
01452 if ((k=OBJcallreflex(m, 0))) return k;
01453 return k;
01454 }
01455
01467 int _GETKinectUserJointPosition(mmachine m)
01468 {
01469 #ifdef _SCOL_DEBUG_
01470 MMechostr(MSKDEBUG,"_GETKinectUserJointPosition\n");
01471 #endif
01472
01473 int iConfidence = MMpull(m);
01474 int bId = MMpull(m);
01475 int objTab = MMget(m, 0);
01476 if ((objTab == NIL) || (bId == NIL))
01477 {
01478 MMset(m, 0, NIL);
01479 return 0;
01480 }
01481 NIDevice::Objects::KinectUser* KinectUserOBJ = (NIDevice::Objects::KinectUser*) MMfetch(m, MTOP(objTab), 0);
01482
01483 if(!KinectUserOBJ)
01484 {
01485 MMset(m, 0, NIL);
01486 return 0;
01487 }
01488
01489 float fConfidence = 0.0f;
01490 if ((iConfidence != NIL) || (MTOF(iConfidence) > 0.0f))
01491 fConfidence = MTOF(iConfidence);
01492
01493 XnPoint3D result;
01494 if(KinectUserOBJ->GetSkeletonData()->GetBoneCurrentPosition((XnSkeletonJoint)(MTOI(bId)), result, fConfidence))
01495 {
01496 int tuple = MMmalloc(m, 3, TYPETAB);
01497 if(tuple==NIL)
01498 {
01499 MMset(m, 0, NIL);
01500 }
01501 else
01502 {
01503 MMstore(m, tuple, 0, FTOM((result.X * 0.1f)));
01504 MMstore(m, tuple, 1, FTOM((result.Y * 0.1f)));
01505 MMstore(m, tuple, 2, FTOM((result.Z * 0.1f)));
01506 MMset(m, 0, PTOM(tuple));
01507 }
01508 }
01509 else
01510 {
01511 MMset(m, 0, NIL);
01512 }
01513
01514 #ifdef _SCOL_DEBUG_
01515 MMechostr(MSKDEBUG,"ok\n");
01516 #endif
01517 return 0;
01518 }
01519
01531 int _GETKinectUserJointOrientation(mmachine m)
01532 {
01533 #ifdef _SCOL_DEBUG_
01534 MMechostr(MSKDEBUG,"_GETKinectUserJointOrientation\n");
01535 #endif
01536
01537 int iConfidence = MMpull(m);
01538 int bId = MMpull(m);
01539 int objTab = MMget(m, 0);
01540 if ((objTab == NIL) || (bId == NIL))
01541 {
01542 MMset(m, 0, NIL);
01543 return 0;
01544 }
01545
01546 NIDevice::Objects::KinectUser* KinectUserOBJ = (NIDevice::Objects::KinectUser*) MMfetch(m, MTOP(objTab), 0);
01547
01548 if(!KinectUserOBJ)
01549 {
01550 MMset(m, 0, NIL);
01551 return 0;
01552 }
01553
01554 float fConfidence = 0.0f;
01555 if ((iConfidence != NIL) || (MTOF(iConfidence) > 0.0f))
01556 fConfidence = MTOF(iConfidence);
01557
01558 Quaternion result;
01559 if(KinectUserOBJ->GetSkeletonData()->GetBoneCurrentOrientation((XnSkeletonJoint)(MTOI(bId)), &result, fConfidence))
01560 {
01561 int tuple = MMmalloc(m, 4, TYPETAB);
01562 if(tuple==NIL)
01563 {
01564 MMset(m, 0, NIL);
01565 }
01566 else
01567 {
01568 MMstore(m, tuple, 0, FTOM(result.x));
01569 MMstore(m, tuple, 1, FTOM(result.y));
01570 MMstore(m, tuple, 2, FTOM(result.z));
01571 MMstore(m, tuple, 3, FTOM(result.w));
01572 MMset(m, 0, PTOM(tuple));
01573 }
01574 }
01575 else
01576 {
01577 MMset(m, 0, NIL);
01578 }
01579
01580 #ifdef _SCOL_DEBUG_
01581 MMechostr(MSKDEBUG,"ok\n");
01582 #endif
01583 return 0;
01584 }
01585
01586
01588 #define NbKinectPKG 54
01589
01593 char *KinectName[NbKinectPKG] =
01594 {
01595 "ObjKinect",
01596 "ObjKinectUser",
01597 "_CRKinectDevice",
01598 "_DSKinectDevice",
01599 "_GETKinectDeviceById",
01600 "_GETKinectDeviceId",
01601 "_BLTKinectDeviceDepth",
01602 "_BLTKinectDeviceRGB",
01603 "_BLTKinectDeviceGrayscale",
01604 "_BLTKinectDeviceUsers",
01605 "_SETKinectDeviceMirror",
01606 "_GETKinectDeviceMirror",
01607 "_SETKinectDeviceSkeletonSmoothing",
01608 "_GETKinectDeviceSkeletonSmoothing",
01609 "_SETKinectDeviceDetectionDistance",
01610 "_GETKinectDeviceDetectionDistance",
01611 "_SETKinectDeviceDetectionAngle",
01612 "_GETKinectDeviceDetectionAngle",
01613 "_CBKinectConnected",
01614 "_CBKinectDisconnected",
01615 "_CBKinectUserFound",
01616 "_CBKinectUserLost",
01617 "_CRKinectUser",
01618 "_DSKinectUser",
01619 "_CBKinectUserCalibrationStart",
01620 "_CBKinectUserCalibrationEnd",
01621 "_CBKinectUserPoseDetected",
01622 "_CBKinectUserPoseLost",
01623 "_GETKinectUserJointPosition",
01624 "_GETKinectUserJointOrientation",
01625 "USER_SKEL_HEAD","USER_SKEL_NECK","USER_SKEL_TORSO",
01626 "USER_SKEL_WAIST","USER_SKEL_L_COLLAR","USER_SKEL_L_SHOULDER",
01627 "USER_SKEL_L_ELBOW","USER_SKEL_L_WRIST","USER_SKEL_L_HAND",
01628 "USER_SKEL_L_FINGERTIP","USER_SKEL_R_COLLAR","USER_SKEL_R_SHOULDER",
01629 "USER_SKEL_R_ELBOW","USER_SKEL_R_WRIST","USER_SKEL_R_HAND",
01630 "USER_SKEL_R_FINGERTIP","USER_SKEL_L_HIP","USER_SKEL_L_KNEE",
01631 "USER_SKEL_L_ANKLE","USER_SKEL_L_FOOT","USER_SKEL_R_HIP",
01632 "USER_SKEL_R_KNEE","USER_SKEL_R_ANKLE","USER_SKEL_R_FOOT"
01633 };
01634
01638 int (*KinectFunc[NbKinectPKG])(mmachine m)=
01639 {
01640 NULL,
01641 NULL,
01642 _CRKinectDevice,
01643 _DSKinectDevice,
01644 _GETKinectDeviceById,
01645 _GETKinectDeviceId,
01646 _BLTKinectDeviceDepth,
01647 _BLTKinectDeviceRGB,
01648 _BLTKinectDeviceGrayscale,
01649 _BLTKinectDeviceUsers,
01650 _SETKinectDeviceMirror,
01651 _GETKinectDeviceMirror,
01652 _SETKinectDeviceSkeletonSmoothing,
01653 _GETKinectDeviceSkeletonSmoothing,
01654 _SETKinectDeviceDetectionDistance,
01655 _GETKinectDeviceDetectionDistance,
01656 _SETKinectDeviceDetectionAngle,
01657 _GETKinectDeviceDetectionAngle,
01658 _CBKinectConnected,
01659 _CBKinectDisconnected,
01660 _CBKinectUserFound,
01661 _CBKinectUserLost,
01662 _CRKinectUser,
01663 _DSKinectUser,
01664 _CBKinectUserCalibrationStart,
01665 _CBKinectUserCalibrationEnd,
01666 _CBKinectUserPoseDetected,
01667 _CBKinectUserPoseLost,
01668 _GETKinectUserJointPosition,
01669 _GETKinectUserJointOrientation,
01670 SCOL_TYPTYPE(1), SCOL_TYPTYPE(2), SCOL_TYPTYPE(3),
01671 SCOL_TYPTYPE(4), SCOL_TYPTYPE(5), SCOL_TYPTYPE(6),
01672 SCOL_TYPTYPE(7), SCOL_TYPTYPE(8), SCOL_TYPTYPE(9),
01673 SCOL_TYPTYPE(10), SCOL_TYPTYPE(11), SCOL_TYPTYPE(12),
01674 SCOL_TYPTYPE(13), SCOL_TYPTYPE(14), SCOL_TYPTYPE(15),
01675 SCOL_TYPTYPE(16), SCOL_TYPTYPE(17), SCOL_TYPTYPE(18),
01676 SCOL_TYPTYPE(19), SCOL_TYPTYPE(20), SCOL_TYPTYPE(21),
01677 SCOL_TYPTYPE(22), SCOL_TYPTYPE(23), SCOL_TYPTYPE(24)
01678 };
01679
01683 int KinectNArg[NbKinectPKG]=
01684 {
01685 TYPTYPE,
01686 TYPTYPE,
01687 1,
01688 1,
01689 1,
01690 1,
01691 2,
01692 2,
01693 2,
01694 2,
01695 2,
01696 1,
01697 2,
01698 1,
01699 2,
01700 1,
01701 2,
01702 1,
01703 3,
01704 3,
01705 3,
01706 3,
01707 2,
01708 1,
01709 3,
01710 3,
01711 3,
01712 3,
01713 3,
01714 3,
01715 TYPVAR,TYPVAR,TYPVAR,
01716 TYPVAR,TYPVAR,TYPVAR,
01717 TYPVAR,TYPVAR,TYPVAR,
01718 TYPVAR,TYPVAR,TYPVAR,
01719 TYPVAR,TYPVAR,TYPVAR,
01720 TYPVAR,TYPVAR,TYPVAR,
01721 TYPVAR,TYPVAR,TYPVAR,
01722 TYPVAR,TYPVAR,TYPVAR
01723 };
01724
01728 char* TplType[NbKinectPKG]=
01729 {
01730 NULL,
01731 NULL,
01732 "fun [Chn] ObjKinect",
01733 "fun [ObjKinect] I",
01734 "fun [I] ObjKinect",
01735 "fun [ObjKinect] I",
01736 "fun [ObjKinect ObjBitmap] ObjBitmap",
01737 "fun [ObjKinect ObjBitmap] ObjBitmap",
01738 "fun [ObjKinect ObjBitmap] ObjBitmap",
01739 "fun [ObjKinect AlphaBitmap] AlphaBitmap",
01740 "fun [ObjKinect I] I",
01741 "fun [ObjKinect] I",
01742 "fun [ObjKinect F] I",
01743 "fun [ObjKinect] F",
01744 "fun [ObjKinect I] I",
01745 "fun [ObjKinect] I",
01746 "fun [ObjKinect F] I",
01747 "fun [ObjKinect] F",
01748 "fun [ObjKinect fun [ObjKinect u0] u1 u0] ObjKinect",
01749 "fun [ObjKinect fun [ObjKinect u0] u1 u0] ObjKinect",
01750 "fun [ObjKinectUser fun [ObjKinectUser u0] u1 u0] ObjKinect",
01751 "fun [ObjKinectUser fun [ObjKinectUser u0] u1 u0] ObjKinect",
01752 "fun [Chn ObjKinect] ObjKinectUser",
01753 "fun [ObjKinectUser] I",
01754 "fun [ObjKinectUser fun [ObjKinectUser u0] u1 u0] ObjKinectUser",
01755 "fun [ObjKinectUser fun [ObjKinectUser u0] u1 u0] ObjKinectUser",
01756 "fun [ObjKinectUser fun [ObjKinectUser u0] u1 u0] ObjKinectUser",
01757 "fun [ObjKinectUser fun [ObjKinectUser u0] u1 u0] ObjKinectUser",
01758 "fun [ObjKinectUser I F] [F F F]",
01759 "fun [ObjKinectUser I F] [F F F F]",
01760 "I","I","I",
01761 "I","I","I",
01762 "I","I","I",
01763 "I","I","I",
01764 "I","I","I",
01765 "I","I","I",
01766 "I","I","I",
01767 "I","I","I"
01768 };
01769
01777 int LoadPlugin(mmachine m)
01778 {
01779 int k = 0;
01780
01781
01782 OBJ_KINECT_SCOL = OBJregister(2 , 1, destroyKinectObj, "OBJ_KINECT_SCOL");
01783
01784
01785 KINECT_CONNECTED_CB = OBJgetUserEvent();
01786 OBJdefEvent( KINECT_CONNECTED_CB, (int (__cdecl *)(struct Mmachine *,int,unsigned int,int,int,int *))getKinectConnectedCb );
01787
01788 KINECT_DISCONNECTED_CB = OBJgetUserEvent();
01789 OBJdefEvent( KINECT_DISCONNECTED_CB, (int (__cdecl *)(struct Mmachine *,int,unsigned int,int,int,int *))getKinectDisconnectedCb );
01790
01791
01792
01793 OBJ_KINECT_USER_SCOL = OBJregister(6 , 1, destroyKinectUserObj, "OBJ_KINECT_USER_SCOL");
01794
01795 KINECT_NEW_USER_CB = OBJgetUserEvent();
01796 OBJdefEvent( KINECT_NEW_USER_CB, (int (__cdecl *)(struct Mmachine *,int,unsigned int,int,int,int *))getKinectNewUserCb );
01797
01798 KINECT_LOST_USER_CB = OBJgetUserEvent();
01799 OBJdefEvent( KINECT_LOST_USER_CB, (int (__cdecl *)(struct Mmachine *,int,unsigned int,int,int,int *))getKinectLostUserCb );
01800
01801 KINECT_USER_CALIBRATION_START_CB = OBJgetUserEvent();
01802 OBJdefEvent( KINECT_USER_CALIBRATION_START_CB, (int (__cdecl *)(struct Mmachine *,int,unsigned int,int,int,int *))getKinectUserCalibrationStartCb );
01803
01804 KINECT_USER_CALIBRATION_END_CB = OBJgetUserEvent();
01805 OBJdefEvent( KINECT_USER_CALIBRATION_END_CB, (int (__cdecl *)(struct Mmachine *,int,unsigned int,int,int,int *))getKinectUserCalibrationEndCb );
01806
01807 KINECT_USER_POSE_DETECTED_CB = OBJgetUserEvent();
01808 OBJdefEvent( KINECT_USER_POSE_DETECTED_CB, (int (__cdecl *)(struct Mmachine *,int,unsigned int,int,int,int *))getKinectUserPoseDetectedCb );
01809
01810 KINECT_USER_POSE_LOST_CB = OBJgetUserEvent();
01811 OBJdefEvent( KINECT_USER_POSE_LOST_CB, (int (__cdecl *)(struct Mmachine *,int,unsigned int,int,int,int *))getKinectUserPoseLostCb );
01812
01813
01814 k = PKhardpak(m, "KinectEngine", NbKinectPKG, KinectName, KinectFunc, KinectNArg, TplType);
01815
01816
01817 try
01818 {
01819 deviceManager = new NIDevice::DeviceManager();
01820 }
01821 catch (NIDevice::Core::ExceptionKinect& e)
01822 {
01823 MMechostr(MSKDEBUG, "%s", e.GetFullDescription().c_str());
01824 return 0;
01825 }
01826 return k;
01827 }
01828
01829
01830
01832
01835 extern "C" __declspec (dllexport) int ScolLoadPlugin(mmachine m, cbmachine w)
01836 {
01837 SCOLinitplugin(w);
01838
01839
01840 HScol = (HWND)SCgetExtra("hscol");
01841 srand((int)time(0));
01842 LoadPlugin(m);
01843 return 0;
01844 }
01845
01849 extern "C" __declspec (dllexport) int ScolUnloadPlugin()
01850 {
01851
01852 SAFE_DELETE(deviceManager);
01853 return 0;
01854 }
01855