48 m_code(_state->tilt_status), m_state(_state)
68 if(
freenect_open_device(_ctx, &m_dev, _index) < 0)
throw std::runtime_error(
"Cannot open Kinect");
94 if(
freenect_set_led(m_dev, _option) < 0)
throw std::runtime_error(
"Cannot set led");
106 if (!mode.
is_valid)
throw std::runtime_error(
"Cannot set video format: invalid mode");
115 return m_video_format;
118 return m_video_resolution;
124 if (!mode.
is_valid)
throw std::runtime_error(
"Cannot set depth format: invalid mode");
133 return m_depth_format;
136 return m_depth_resolution;
151 switch(m_video_format) {
188 if(
freenect_init(&m_ctx, NULL) < 0)
throw std::runtime_error(
"Cannot initialize freenect library");
192 if(pthread_create(&m_thread, NULL, pthread_callback, (
void*)
this) != 0)
throw std::runtime_error(
"Cannot initialize freenect thread");
196 for(DeviceMap::iterator it = m_devices.begin() ; it != m_devices.end() ; ++it) {
199 pthread_join(m_thread, NULL);
202 template <
typename ConcreteDevice>
204 DeviceMap::iterator it = m_devices.find(_index);
205 if (it != m_devices.end())
delete it->second;
206 ConcreteDevice *
device =
new ConcreteDevice(m_ctx, _index);
207 m_devices[_index] =
device;
211 DeviceMap::iterator it = m_devices.find(_index);
212 if (it == m_devices.end())
return;
222 static timeval timeout = { 1, 0 };
233 std::stringstream ss;
234 ss <<
"Cannot process freenect events (libusb error code: " << res <<
")";
235 throw std::runtime_error(ss.str());
void freenect_set_video_callback(freenect_device *dev, freenect_video_cb cb)
freenect_flag
Enumeration of flags to toggle features with freenect_set_flag()
void freenect_select_subdevices(freenect_context *ctx, freenect_device_flags subdevs)
const freenect_device * getDevice()
void freenect_get_mks_accel(freenect_raw_tilt_state *state, double *x, double *y, double *z)
void setTiltDegrees(double _angle)
int freenect_stop_video(freenect_device *dev)
freenect_resolution getVideoResolution()
int setFlag(freenect_flag flag, bool value)
ConcreteDevice & createDevice(int _index)
virtual ~FreenectDevice()
int freenect_num_devices(freenect_context *ctx)
void setLed(freenect_led_options _option)
void deleteDevice(int _index)
static void freenect_depth_callback(freenect_device *dev, void *depth, uint32_t timestamp)
int freenect_start_depth(freenect_device *dev)
int freenect_set_led(freenect_device *dev, freenect_led_options option)
freenect_video_format m_video_format
freenect_tilt_status_code m_code
FreenectTiltState(freenect_raw_tilt_state *_state)
int freenect_shutdown(freenect_context *ctx)
Freenect::Freenect freenect
virtual void DepthCallback(void *depth, uint32_t timestamp)
freenect_depth_format getDepthFormat()
FREENECTAPI int freenect_set_flag(freenect_device *dev, freenect_flag flag, freenect_flag_value value)
int freenect_set_video_mode(freenect_device *dev, const freenect_frame_mode mode)
int freenect_set_tilt_degs(freenect_device *dev, double angle)
int freenect_process_events_timeout(freenect_context *ctx, struct timeval *timeout)
freenect_raw_tilt_state * m_state
void freenect_set_depth_callback(freenect_device *dev, freenect_depth_cb cb)
freenect_depth_format m_depth_format
int freenect_start_video(freenect_device *dev)
freenect_resolution m_depth_resolution
const Noncopyable & operator=(const Noncopyable &)
double freenect_get_tilt_degs(freenect_raw_tilt_state *state)
freenect_frame_mode freenect_find_video_mode(freenect_resolution res, freenect_video_format fmt)
freenect_frame_mode freenect_get_current_depth_mode(freenect_device *dev)
freenect_resolution m_video_resolution
void setVideoFormat(freenect_video_format requested_format, freenect_resolution requested_resolution=FREENECT_RESOLUTION_MEDIUM)
void * freenect_get_user(freenect_device *dev)
freenect_frame_mode freenect_find_depth_mode(freenect_resolution res, freenect_depth_format fmt)
MyFreenectDevice * device
freenect_resolution getDepthResolution()
static void * pthread_callback(void *user_data)
static void freenect_video_callback(freenect_device *dev, void *video, uint32_t timestamp)
freenect_raw_tilt_state * freenect_get_tilt_state(freenect_device *dev)
int freenect_update_tilt_state(freenect_device *dev)
int freenect_close_device(freenect_device *dev)
int freenect_set_depth_mode(freenect_device *dev, const freenect_frame_mode mode)
int freenect_open_device(freenect_context *ctx, freenect_device **dev, int index)
Data from the tilt motor and accelerometer.
FreenectTiltState getState() const
virtual void VideoCallback(void *video, uint32_t timestamp)
freenect_video_format requested_format
void getAccelerometers(double *x, double *y, double *z)
std::map< int, FreenectDevice * > DeviceMap
int freenect_stop_depth(freenect_device *dev)
freenect_resolution requested_resolution
freenect_video_format getVideoFormat()
freenect_tilt_status_code
Enumeration of tilt motor status.
FreenectDevice(freenect_context *_ctx, int _index)
void freenect_set_user(freenect_device *dev, void *user)
void setDepthFormat(freenect_depth_format requested_format, freenect_resolution requested_resolution=FREENECT_RESOLUTION_MEDIUM)
int freenect_init(freenect_context **ctx, freenect_usb_context *usb_ctx)