1+ #include < string>
12#include " DepthStream.hpp"
23
34using namespace FreenectDriver ;
45
56
6- DepthStream::DepthStream (Freenect::FreenectDevice* pDevice) : VideoStream(pDevice) {
7+ DepthStream::DepthStream (Freenect::FreenectDevice* pDevice) : VideoStream(pDevice)
8+ {
79 video_mode = makeOniVideoMode (ONI_PIXEL_FORMAT_DEPTH_1_MM, 640 , 480 , 30 );
810 image_registration_mode = ONI_IMAGE_REGISTRATION_OFF;
911 setVideoMode (video_mode);
@@ -12,7 +14,8 @@ DepthStream::DepthStream(Freenect::FreenectDevice* pDevice) : VideoStream(pDevic
1214// Add video modes here as you implement them
1315// Note: if image_registration_mode == ONI_IMAGE_REGISTRATION_DEPTH_TO_COLOR,
1416// setVideoFormat() will try FREENECT_DEPTH_REGISTERED first then fall back on what is set here.
15- DepthStream::FreenectDepthModeMap DepthStream::getSupportedVideoModes () {
17+ DepthStream::FreenectDepthModeMap DepthStream::getSupportedVideoModes ()
18+ {
1619 FreenectDepthModeMap modes;
1720 // pixelFormat, resolutionX, resolutionY, fps
1821 modes[makeOniVideoMode (ONI_PIXEL_FORMAT_DEPTH_1_MM, 640 , 480 , 30 )] = std::pair<freenect_depth_format, freenect_resolution>(FREENECT_DEPTH_MM, FREENECT_RESOLUTION_MEDIUM);
@@ -21,7 +24,8 @@ DepthStream::FreenectDepthModeMap DepthStream::getSupportedVideoModes() {
2124 return modes;
2225}
2326
24- OniStatus DepthStream::setVideoMode (OniVideoMode requested_mode) {
27+ OniStatus DepthStream::setVideoMode (OniVideoMode requested_mode)
28+ {
2529 FreenectDepthModeMap supported_video_modes = getSupportedVideoModes ();
2630 FreenectDepthModeMap::const_iterator matched_mode_iter = supported_video_modes.find (requested_mode);
2731 if (matched_mode_iter == supported_video_modes.end ())
@@ -33,10 +37,12 @@ OniStatus DepthStream::setVideoMode(OniVideoMode requested_mode) {
3337 format = FREENECT_DEPTH_REGISTERED;
3438
3539 try { device->setDepthFormat (format, resolution); }
36- catch (std::runtime_error e) {
37- printf (" format-resolution combination not supported by libfreenect: %d-%d\n " , format, resolution);
38- if (image_registration_mode == ONI_IMAGE_REGISTRATION_DEPTH_TO_COLOR) {
39- printf (" could not use image registration format; disabling registration and falling back to format defined in getSupportedVideoModes()\n " );
40+ catch (std::runtime_error e)
41+ {
42+ LogError (" Format " + format + std::string (" and resolution " + resolution) + " combination not supported by libfreenect" );
43+ if (image_registration_mode == ONI_IMAGE_REGISTRATION_DEPTH_TO_COLOR)
44+ {
45+ LogError (" Could not enable image registration format; falling back to format defined in getSupportedVideoModes()" );
4046 image_registration_mode = ONI_IMAGE_REGISTRATION_OFF;
4147 return setVideoMode (requested_mode);
4248 }
@@ -46,7 +52,8 @@ OniStatus DepthStream::setVideoMode(OniVideoMode requested_mode) {
4652 return ONI_STATUS_OK;
4753}
4854
49- void DepthStream::populateFrame (void * data, OniFrame* frame) const {
55+ void DepthStream::populateFrame (void * data, OniFrame* frame) const
56+ {
5057 frame->sensorType = sensor_type;
5158 frame->stride = video_mode.resolutionX * sizeof (uint16_t );
5259
@@ -69,11 +76,14 @@ void DepthStream::populateFrame(void* data, OniFrame* frame) const {
6976 unsigned short * target = static_cast <unsigned short *>(frame->data );
7077 const unsigned int skipWidth = video_mode.resolutionX - frame->width ;
7178
72- if (mirroring) {
79+ if (mirroring)
80+ {
7381 target += frame->width ;
7482
75- for (int y = 0 ; y < frame->height ; y++) {
76- for (int x = 0 ; x < frame->width ; x++) {
83+ for (int y = 0 ; y < frame->height ; y++)
84+ {
85+ for (int x = 0 ; x < frame->width ; x++)
86+ {
7787 unsigned short value = *(source++);
7888 *(target--) = value < DepthStream::MAX_VALUE ? value : 0 ;
7989 }
@@ -82,9 +92,12 @@ void DepthStream::populateFrame(void* data, OniFrame* frame) const {
8292 target += 2 * frame->width ;
8393 }
8494 }
85- else {
86- for (int y = 0 ; y < frame->height ; y++) {
87- for (int x = 0 ; x < frame->width ; x++) {
95+ else
96+ {
97+ for (int y = 0 ; y < frame->height ; y++)
98+ {
99+ for (int x = 0 ; x < frame->width ; x++)
100+ {
88101 unsigned short value = *(source++);
89102 *(target++) = value < DepthStream::MAX_VALUE ? value : 0 ;
90103 }
0 commit comments