void knt_Init(kinect_t *k, int tipo){ XnStatus nRetVal = XN_STATUS_OK; nRetVal = xnInit(&(k->pContext)); k->Node_Deep = knt_create_node_deep( k->pContext); k->Node_Image = knt_create_node_image( k->pContext, tipo); nRetVal = xnStartGeneratingAll(k->pContext); if(nRetVal != XN_STATUS_OK){ printf("Error ejecutando nodo: %s\n",xnGetStatusString(nRetVal)); } }
XnStatus xnConfigureCreateNodes(XnContext* pContext, const TiXmlElement* pRootElem, XnEnumerationErrors* pErrors) { XnStatus nRetVal = XN_STATUS_OK; const TiXmlElement* pProudctionNodes = pRootElem->FirstChildElement("ProductionNodes"); if (pProudctionNodes == NULL) { printf("XnXMLConfig::xnConfigureCreateNodes(): firstChildElement == ProductionNodes == NULL\n"); return (XN_STATUS_OK); } // global mirror printf("XnXMLConfig::xnConfigureCreateNodes(): Check GlobalMirror\n"); const TiXmlElement* pGlobalMirror = pProudctionNodes->FirstChildElement("GlobalMirror"); if (pGlobalMirror != NULL) { XnBool bOn; nRetVal = xnXmlReadBoolAttribute(pGlobalMirror, "on", &bOn); XN_IS_STATUS_OK(nRetVal); nRetVal = xnSetGlobalMirror(pContext, bOn); XN_IS_STATUS_OK(nRetVal); } // file recordings const TiXmlElement* pRecording = pProudctionNodes->FirstChildElement("Recording"); if (pRecording != NULL) { const XnChar* strFileName; nRetVal = xnXmlReadStringAttribute(pRecording, "file", &strFileName); XN_IS_STATUS_OK(nRetVal); xnLogVerbose(XN_MASK_OPEN_NI, "Opening file recording '%s'...", strFileName); nRetVal = xnContextOpenFileRecording(pContext, strFileName); XN_IS_STATUS_OK(nRetVal); } const XnChar* strNodeTagName = "Node"; const XnChar* strStartGeneratingAttr = "startGenerating"; XnBool bStartGeneratingAll = TRUE; if (NULL != pProudctionNodes->Attribute(strStartGeneratingAttr)) { nRetVal = xnXmlReadBoolAttribute(pProudctionNodes, strStartGeneratingAttr, &bStartGeneratingAll); XN_IS_STATUS_OK(nRetVal); } // new nodes printf("XnXMLConfig::xnConfigureCreateNodes(): Start iterating over production nodes.\n"); const TiXmlElement* pNode = pProudctionNodes->FirstChildElement(strNodeTagName); while (pNode != NULL) { // get type const XnChar* strType; nRetVal = xnXmlReadStringAttribute(pNode, "type", &strType); XN_IS_STATUS_OK(nRetVal); xnLogVerbose(XN_MASK_OPEN_NI, "Requested to create a node of type %s...", strType); XnProductionNodeType Type; printf("XnXMLConfig::xnConfigureCreateNodes(): call to xnProductionNodeTypeFromString()\n"); nRetVal = xnProductionNodeTypeFromString(strType, &Type); printf("ProductoniNodeType (see Include/XnTypes.h): %d\n", Type); XN_IS_STATUS_OK(nRetVal); // check if there is a query XnNodeQuery* pQuery = NULL; const TiXmlElement* pQueryElem = pNode->FirstChildElement("Query"); if (pQueryElem != NULL) { nRetVal = xnNodeQueryAllocate(&pQuery); XN_IS_STATUS_OK(nRetVal); nRetVal = xnXmlReadQuery(pQueryElem, pQuery); XN_IS_STATUS_OK(nRetVal); } // enumerate XnNodeInfoList* pTrees; printf("XnXMLConfig::xnConfigureCreateNodes(): call to xnEnumerateProductionTrees\n"); nRetVal = xnEnumerateProductionTrees(pContext, Type, pQuery, &pTrees, pErrors); // @todo Porting to Mac - this is where it goes wrong. XN_IS_STATUS_OK(nRetVal); if (pQuery != NULL) { xnNodeQueryFree(pQuery); pQuery = NULL; } // choose first one XnNodeInfoListIterator itChosen = xnNodeInfoListGetFirst(pTrees); XnNodeInfo* pChosenInfo = xnNodeInfoListGetCurrent(itChosen); // check if a name was requested if (NULL != pNode->Attribute("name")) { const XnChar* strName = NULL; nRetVal = xnXmlReadStringAttribute(pNode, "name", &strName); if (nRetVal != XN_STATUS_OK) { xnNodeInfoListFree(pTrees); return (nRetVal); } nRetVal = xnNodeInfoSetInstanceName(pChosenInfo, strName); if (nRetVal != XN_STATUS_OK) { xnNodeInfoListFree(pTrees); return (nRetVal); } } // create it printf("XnXMLConfig::xnConfigureCreateNodes(): call to xnCreateProductionTree()"); XnNodeHandle hNode; nRetVal = xnCreateProductionTree(pContext, pChosenInfo, &hNode); if (nRetVal != XN_STATUS_OK) { xnNodeInfoListFree(pTrees); return (nRetVal); } // free the list xnNodeInfoListFree(pTrees); // config it nRetVal = xnConfigureNodeFromXml(hNode, pNode); XN_IS_STATUS_OK(nRetVal); // check if we need to start it (if start generating all is on, it will be started at the end) XnBool bStart = FALSE; if (!bStartGeneratingAll) { if (NULL != pNode->Attribute(strStartGeneratingAttr)) { nRetVal = xnXmlReadBoolAttribute(pNode, strStartGeneratingAttr, &bStart); XN_IS_STATUS_OK(nRetVal); } if (bStart) { nRetVal = xnStartGenerating(hNode); XN_IS_STATUS_OK(nRetVal); } } pNode = pNode->NextSiblingElement(strNodeTagName); } // start generating all if (bStartGeneratingAll) { nRetVal = xnStartGeneratingAll(pContext); XN_IS_STATUS_OK(nRetVal); } return (XN_STATUS_OK); }
XnStatus xnConfigureCreateNodes(XnContext* pContext, const TiXmlElement* pRootElem, XnEnumerationErrors* pErrors) { XnStatus nRetVal = XN_STATUS_OK; const TiXmlElement* pProudctionNodes = pRootElem->FirstChildElement("ProductionNodes"); if (pProudctionNodes == NULL) { return (XN_STATUS_OK); } // global mirror const TiXmlElement* pGlobalMirror = pProudctionNodes->FirstChildElement("GlobalMirror"); if (pGlobalMirror != NULL) { XnBool bOn; nRetVal = xnXmlReadBoolAttribute(pGlobalMirror, "on", &bOn); XN_IS_STATUS_OK(nRetVal); nRetVal = xnSetGlobalMirror(pContext, bOn); XN_IS_STATUS_OK(nRetVal); } // file recordings const TiXmlElement* pRecording = pProudctionNodes->FirstChildElement("Recording"); if (pRecording != NULL) { const XnChar* strFileName; nRetVal = xnXmlReadStringAttribute(pRecording, "file", &strFileName); XN_IS_STATUS_OK(nRetVal); xnLogVerbose(XN_MASK_OPEN_NI, "Opening file recording '%s'...", strFileName); nRetVal = xnContextOpenFileRecording(pContext, strFileName); XN_IS_STATUS_OK(nRetVal); XnDouble dSpeed = 1.0; if (NULL != pRecording->Attribute("playbackSpeed", &dSpeed)) { XnNodeHandle hPlayer; nRetVal = xnFindExistingNodeByType(pContext, XN_NODE_TYPE_PLAYER, &hPlayer); XN_IS_STATUS_OK(nRetVal); nRetVal = xnSetPlaybackSpeed(hPlayer, dSpeed); XN_IS_STATUS_OK(nRetVal); } } const XnChar* strNodeTagName = "Node"; const XnChar* strStartGeneratingAttr = "startGenerating"; XnBool bStartGeneratingAll = TRUE; if (NULL != pProudctionNodes->Attribute(strStartGeneratingAttr)) { nRetVal = xnXmlReadBoolAttribute(pProudctionNodes, strStartGeneratingAttr, &bStartGeneratingAll); XN_IS_STATUS_OK(nRetVal); } // new nodes const TiXmlElement* pNode = pProudctionNodes->FirstChildElement(strNodeTagName); while (pNode != NULL) { // get type const XnChar* strType; nRetVal = xnXmlReadStringAttribute(pNode, "type", &strType); XN_IS_STATUS_OK(nRetVal); xnLogVerbose(XN_MASK_OPEN_NI, "Requested to create a node of type %s...", strType); XnProductionNodeType Type; nRetVal = xnProductionNodeTypeFromString(strType, &Type); XN_IS_STATUS_OK(nRetVal); // check if there is a query XnNodeQuery* pQuery = NULL; const TiXmlElement* pQueryElem = pNode->FirstChildElement("Query"); if (pQueryElem != NULL) { nRetVal = xnNodeQueryAllocate(&pQuery); XN_IS_STATUS_OK(nRetVal); nRetVal = xnXmlReadQuery(pQueryElem, pQuery); XN_IS_STATUS_OK(nRetVal); } // enumerate XnNodeInfoList* pTrees; nRetVal = xnEnumerateProductionTrees(pContext, Type, pQuery, &pTrees, pErrors); XN_IS_STATUS_OK(nRetVal); if (pQuery != NULL) { xnNodeQueryFree(pQuery); pQuery = NULL; } // choose first one XnNodeInfoListIterator itChosen = xnNodeInfoListGetFirst(pTrees); XnNodeInfo* pChosenInfo = xnNodeInfoListGetCurrent(itChosen); // check if a name was requested if (NULL != pNode->Attribute("name")) { const XnChar* strName = NULL; nRetVal = xnXmlReadStringAttribute(pNode, "name", &strName); if (nRetVal != XN_STATUS_OK) { xnNodeInfoListFree(pTrees); return (nRetVal); } nRetVal = xnNodeInfoSetInstanceName(pChosenInfo, strName); if (nRetVal != XN_STATUS_OK) { xnNodeInfoListFree(pTrees); return (nRetVal); } } // create it XnNodeHandle hNode; nRetVal = xnCreateProductionTree(pContext, pChosenInfo, &hNode); if (nRetVal != XN_STATUS_OK) { xnNodeInfoListFree(pTrees); return (nRetVal); } // free the list xnNodeInfoListFree(pTrees); // config it nRetVal = xnConfigureNodeFromXml(hNode, pNode); XN_IS_STATUS_OK(nRetVal); // check if we need to start it (if start generating all is on, it will be started at the end) XnBool bStart = FALSE; if (!bStartGeneratingAll) { if (NULL != pNode->Attribute(strStartGeneratingAttr)) { nRetVal = xnXmlReadBoolAttribute(pNode, strStartGeneratingAttr, &bStart); XN_IS_STATUS_OK(nRetVal); } if (bStart) { nRetVal = xnStartGenerating(hNode); XN_IS_STATUS_OK(nRetVal); } } pNode = pNode->NextSiblingElement(strNodeTagName); } // start generating all if (bStartGeneratingAll) { nRetVal = xnStartGeneratingAll(pContext); XN_IS_STATUS_OK(nRetVal); } return (XN_STATUS_OK); }