<commit_before>/*
 * OpenNI2Interface.cpp
 *
 *  Created on: 20 May 2013
 *      Author: thomas
 */

#include "OpenNI2Interface.h"

OpenNI2Interface::OpenNI2Interface(int inWidth, int inHeight, int fps)
 : width(inWidth),
   height(inHeight),
   fps(fps),
   initSuccessful(true)
{
    //Setup
    openni::Status rc = openni::STATUS_OK;

    const char * deviceURI = openni::ANY_DEVICE;

    rc = openni::OpenNI::initialize();

    std::string errorString(openni::OpenNI::getExtendedError());

    if(errorString.length() > 0)
    {
        errorText.append(errorString);
        initSuccessful = false;
    }
    else
    {
        rc = device.open(deviceURI);
        if (rc != openni::STATUS_OK)
        {
            errorText.append(openni::OpenNI::getExtendedError());
            openni::OpenNI::shutdown();
            initSuccessful = false;
        }
        else
        {
            device.setProperty(XN_MODULE_PROPERTY_USB_INTERFACE, XN_SENSOR_USB_INTERFACE_ISO_ENDPOINTS);

            rc = depthStream.create(device, openni::SENSOR_DEPTH);
            if (rc == openni::STATUS_OK)
            {
                rc = depthStream.start();
                if (rc != openni::STATUS_OK)
                {
                    errorText.append(openni::OpenNI::getExtendedError());
                    depthStream.destroy();
                    initSuccessful = false;
                }
            }
            else
            {
                errorText.append(openni::OpenNI::getExtendedError());
                initSuccessful = false;
            }

            rc = rgbStream.create(device, openni::SENSOR_COLOR);
            if (rc == openni::STATUS_OK)
            {
                rc = rgbStream.start();
                if (rc != openni::STATUS_OK)
                {
                    errorText.append(openni::OpenNI::getExtendedError());
                    rgbStream.destroy();
                    initSuccessful = false;
                }
            }
            else
            {
                errorText.append(openni::OpenNI::getExtendedError());
                initSuccessful = false;
            }

            if (!depthStream.isValid() || !rgbStream.isValid())
            {
                errorText.append(openni::OpenNI::getExtendedError());
                openni::OpenNI::shutdown();
                initSuccessful = false;
            }

            if(initSuccessful)
            {
                rgbStream.setProperty(XN_STREAM_PROPERTY_INPUT_FORMAT, XN_IO_IMAGE_FORMAT_UNCOMPRESSED_YUV422);

                //For printing out
                formatMap[openni::PIXEL_FORMAT_DEPTH_1_MM] = "1mm";
                formatMap[openni::PIXEL_FORMAT_DEPTH_100_UM] = "100um";
                formatMap[openni::PIXEL_FORMAT_SHIFT_9_2] = "Shift 9 2";
                formatMap[openni::PIXEL_FORMAT_SHIFT_9_3] = "Shift 9 3";<commit_msg>Update OpenNI2Interface.cpp<commit_after>/*
 * OpenNI2Interface.cpp
 *
 *  Created on: 20 May 2013
 *      Author: thomas
 */

#include "OpenNI2Interface.h"

OpenNI2Interface::OpenNI2Interface(int inWidth, int inHeight, int fps)
 : width(inWidth),
   height(inHeight),
   fps(fps),
   initSuccessful(true)
{
    //Setup
    openni::Status rc = openni::STATUS_OK;

    const char * deviceURI = openni::ANY_DEVICE;

    rc = openni::OpenNI::initialize();

    std::string errorString(openni::OpenNI::getExtendedError());

    if(errorString.length() > 0)
    {
        errorText.append(errorString);
        initSuccessful = false;
    }
    else
    {
        rc = device.open(deviceURI);
        if (rc != openni::STATUS_OK)
        {
            errorText.append(openni::OpenNI::getExtendedError());
            openni::OpenNI::shutdown();
            initSuccessful = false;
        }
        else
        {
            rc = depthStream.create(device, openni::SENSOR_DEPTH);
            if (rc == openni::STATUS_OK)
            {
                rc = depthStream.start();
                if (rc != openni::STATUS_OK)
                {
                    errorText.append(openni::OpenNI::getExtendedError());
                    depthStream.destroy();
                    initSuccessful = false;
                }
            }
            else
            {
                errorText.append(openni::OpenNI::getExtendedError());
                initSuccessful = false;
            }

            rc = rgbStream.create(device, openni::SENSOR_COLOR);
            if (rc == openni::STATUS_OK)
            {
                rc = rgbStream.start();
                if (rc != openni::STATUS_OK)
                {
                    errorText.append(openni::OpenNI::getExtendedError());
                    rgbStream.destroy();
                    initSuccessful = false;
                }
            }
            else
            {
                errorText.append(openni::OpenNI::getExtendedError());
                initSuccessful = false;
            }

            if (!depthStream.isValid() || !rgbStream.isValid())
            {
                errorText.append(openni::OpenNI::getExtendedError());
                openni::OpenNI::shutdown();
                initSuccessful = false;
            }

            if(initSuccessful)
            {
                //For printing out
                formatMap[openni::PIXEL_FORMAT_DEPTH_1_MM] = "1mm";
                formatMap[openni::PIXEL_FORMAT_DEPTH_100_UM] = "100um";
                formatMap[openni::PIXEL_FORMAT_SHIFT_9_2] = "Shift 9 2";
                formatMap[openni::PIXEL_FORMAT_SHIFT_9_3] = "Shift 9 3";
{'fraction_non_alphanumeric': 0.1120736329182458, 'fraction_numerical': 0.010467424652589786, 'mean_word_length': 1.6478738652651697, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '797541', 'n_tokens_mistral': 1689, 'n_tokens_neox': 1573, 'n_words': 224}