KinectDriver.h
Go to the documentation of this file.00001 #ifndef _KINECT_DRIVER_H_
00002 #define _KINECT_DRIVER_H_
00003
00004
00005
00006
00007
00008
00009 #include <cstdio>
00010
00011 #include <local/DeviceDriver.h>
00012 #include <local/DataSource.h>
00013 #include <DualCoding/Point.h>
00014 #include <Shared/ProjectInterface.h>
00015
00016 #include <XnOS.h>
00017 #include <XnCppWrapper.h>
00018
00019 using namespace std;
00020 using namespace xn;
00021 using namespace DualCoding;
00022
00023 class KinectDriver : public virtual DeviceDriver {
00024 public:
00025 KinectDriver(const string& name);
00026 virtual ~KinectDriver();
00027
00028
00029 virtual string getClassName() const { return autoRegisterKinectDriver; }
00030 virtual void getImageSources(map<string,DataSource*>& sources) {
00031 sources.clear();
00032 sources["Camera"] = &rgbSource;
00033 sources["Depth"] = &depthSource;
00034 }
00035
00036 Context context;
00037 ScriptNode scriptNode;
00038 ImageGenerator image;
00039 DepthGenerator depth;
00040
00041 private:
00042 static const string autoRegisterKinectDriver;
00043
00044 class RGBSource : public DataSource {
00045 public:
00046 RGBSource(KinectDriver *_driver) : DataSource(), driver(_driver), metadata(), cbHandle(NULL), frameNumber(0) { }
00047 RGBSource(const RGBSource&);
00048 ~RGBSource() { deregisterSource(); }
00049
00050 RGBSource& operator= (const RGBSource&);
00051
00052
00053 virtual bool advance();
00054 virtual unsigned int nextTimestamp() { return get_time(); }
00055 virtual const string& nextName() { return instanceName; }
00056 virtual void doFreeze();
00057 virtual void doUnfreeze();
00058
00059 private:
00060 const static string instanceName;
00061 KinectDriver *driver;
00062 ImageMetaData metadata;
00063 XnCallbackHandle cbHandle;
00064 unsigned int frameNumber;
00065
00066 static void imageUpdateReceived(ImageGenerator &image, RGBSource *source);
00067 } rgbSource;
00068
00069 class DepthSource : public DataSource {
00070 public:
00071 DepthSource(KinectDriver * _driver) : DataSource(), driver(_driver), metadata(), cbHandle(NULL), frameNumber(0) { }
00072 DepthSource(const DepthSource&);
00073 ~DepthSource() { deregisterSource(); }
00074
00075 DepthSource& operator= (const DepthSource&);
00076
00077
00078 virtual bool advance();
00079 virtual unsigned int nextTimestamp() { return get_time(); }
00080 virtual const string& nextName() { return instanceName; }
00081 virtual void doFreeze();
00082 virtual void doUnfreeze();
00083
00084 private:
00085 const static string instanceName;
00086 KinectDriver *driver;
00087 DepthMetaData metadata;
00088 XnCallbackHandle cbHandle;
00089 unsigned int frameNumber;
00090
00091 static void depthUpdateReceived(DepthGenerator &depth, DepthSource *source);
00092 } depthSource;
00093 };
00094
00095 #endif