2
0

PolycodeKinect.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /*
  2. Copyright (C) 2011 by Ivan Safrin
  3. Permission is hereby granted, free of charge, to any person obtaining a copy
  4. of this software and associated documentation files (the "Software"), to deal
  5. in the Software without restriction, including without limitation the rights
  6. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  7. copies of the Software, and to permit persons to whom the Software is
  8. furnished to do so, subject to the following conditions:
  9. The above copyright notice and this permission notice shall be included in
  10. all copies or substantial portions of the Software.
  11. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  12. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  13. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  14. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  15. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  16. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  17. THE SOFTWARE.
  18. */
  19. #pragma once
  20. #include "Polycode.h"
  21. #include "libfreenect.h"
  22. using namespace Polycode;
  23. void depth_cb(freenect_device *dev, void *v_depth, uint32_t timestamp);
  24. void rgb_cb(freenect_device *dev, void *rgb, uint32_t timestamp);
  25. class PolycodeRunner : public Threaded {
  26. public:
  27. PolycodeRunner();
  28. ~PolycodeRunner();
  29. void runThread();
  30. void updateThread() {}
  31. void rgbCallback(freenect_device *dev, void *rgb, uint32_t timestamp);
  32. void depthCallback(freenect_device *dev, void *v_depth, uint32_t timestamp);
  33. // static void depth_cb(freenect_device *dev, void *v_depth, uint32_t timestamp);
  34. // static void rgb_cb(freenect_device *dev, void *rgb, uint32_t timestamp);
  35. int initKinect();
  36. void tiltUp();
  37. void tiltDown();
  38. void Level();
  39. CoreMutex *drawMutex;
  40. uint8_t *depth_mid, *depth_front;
  41. uint8_t *rgb_back, *rgb_mid, *rgb_front;
  42. freenect_context *f_ctx;
  43. freenect_device *f_dev;
  44. int depthMap[640*480];
  45. protected:
  46. uint16_t t_gamma[2048];
  47. int freenect_angle;
  48. freenect_video_format current_format;
  49. freenect_video_format requested_format;
  50. };
  51. class PolycodeKinect : EventHandler {
  52. public:
  53. PolycodeKinect(int frequency, bool calculatePoints, int pointCount, int depthStart, int depthEnd, int pixelSkip);
  54. ~PolycodeKinect();
  55. Texture *getRGBTexture();
  56. Texture *getCloseDepthTexture();
  57. void tiltUp();
  58. void tiltDown();
  59. void Level();
  60. void handleEvent(Event *event);
  61. Mesh *mesh;
  62. Vector3 *points;
  63. Color *colors;
  64. protected:
  65. int pointCount;
  66. int depthStart;
  67. int depthEnd;
  68. int pixelSkip;
  69. Timer *updateTimer;
  70. bool calculatePoints;
  71. bool calculateColors;
  72. uint8_t *rgbPtr;
  73. Texture *rgbTexture;
  74. Texture *closeDepthTexture;
  75. PolycodeRunner *runner;
  76. };