Beispiel #1
0
static XnBool xnIsNodeMatch(XnContext* pContext, const XnNodeQuery* pQuery, XnNodeInfo* pNodeInfo)
{
	// check existing node
	XnNodeHandle hNode = xnNodeInfoGetRefHandle(pNodeInfo);
	if (pQuery->bExistingNodeOnly && (hNode == NULL))
	{
		return (FALSE);
	}

	if (pQuery->bNonExistingNodeOnly && (hNode != NULL))
	{
		return (FALSE);
	}

	if (!xnIsInfoQueryMatch(pQuery, pNodeInfo))
	{
		if (hNode != NULL)
		{
			xnProductionNodeRelease(hNode);
		}

		return (FALSE);
	}

	// check if we need to create an instance, to check capabilities
	if (pQuery->nSupportedCapabilities > 0 ||
		pQuery->nSupportedMapOutputModes > 0 ||
		pQuery->nMinUserPositions > 0)
	{
		if (hNode == NULL)
		{
			const XnProductionNodeDescription* pDescription = xnNodeInfoGetDescription(pNodeInfo);
			xnLogVerbose(XN_MASK_OPEN_NI, "Creating node '%s' of type '%s' for querying...", pDescription->strName, xnProductionNodeTypeToString(pDescription->Type));
			XnStatus nRetVal = xnCreateProductionTree(pContext, pNodeInfo, &hNode);
			if (nRetVal != XN_STATUS_OK)
			{
				xnLogWarning(XN_MASK_OPEN_NI, "Failed to create node of type '%s' for querying: %s", xnProductionNodeTypeToString(pDescription->Type), xnGetStatusString(nRetVal));
				return (FALSE);
			}
		}
	}

	XnBool bResult = xnIsNodeInstanceMatch(pQuery, hNode);

	// in any case, we need to release the node. if we created it, this will cause it to be destroyed. If we just took
	// a reference to it, we need to release it.
	if (hNode != NULL)
	{
		xnProductionNodeRelease(hNode);
	}

	return (bResult);
}
Beispiel #2
0
static XnBool xnIsInfoQueryMatch(const XnNodeQuery* pQuery, XnNodeInfo* pNodeInfo)
{
	const XnProductionNodeDescription* pDescription = xnNodeInfoGetDescription(pNodeInfo);
	
	// vendor
	if (pQuery->strVendor[0] != '\0' && strcmp(pQuery->strVendor, pDescription->strVendor) != 0)
	{
		return (FALSE);
	}

	// name
	if (pQuery->strName[0] != '\0' && strcmp(pQuery->strName, pDescription->strName) != 0)
	{
		return (FALSE);
	}

	// min version
	if (xnVersionCompare(&pQuery->MinVersion, &pDescription->Version) > 0)
	{
		return (FALSE);
	}

	// max version
	if (xnVersionCompare(&pQuery->MaxVersion, &pDescription->Version) < 0)
	{
		return (FALSE);
	}

	// check needed nodes
	for (XnUInt i = 0; i < pQuery->nNeededNodes; ++i)
	{
		if (!xnIsInstanceInTree(pNodeInfo, pQuery->astrNeededNodes[i]))
		{
			return (FALSE);
		}
	}

	// Creation info
	if (pQuery->strCreationInfo[0] != '\0' && strcmp(pQuery->strCreationInfo, xnNodeInfoGetCreationInfo(pNodeInfo)) != 0)
	{
		return (FALSE);
	}

	return (TRUE);
}
Beispiel #3
0
// One of the core methods of PyOpenNI:
// It tries to find the exposed class that best matches the given node.
BP::object wrapNode(XnNodeHandle node) {
    if (node == NULL) {
        return BP::object();
    }

    XnNodeInfo* info = xnGetNodeInfo(node);
    const XnProductionNodeDescription* desc = xnNodeInfoGetDescription(info);
    XnProductionNodeType original = desc->Type;

    if (isInstanceOf(original, XN_NODE_TYPE_PRODUCTION_NODE)) {
        if (isInstanceOf(original, XN_NODE_TYPE_GENERATOR)) {
            if (isInstanceOf(original, XN_NODE_TYPE_MAP_GENERATOR)) {
                if (isInstanceOf(original, XN_NODE_TYPE_DEPTH)) {
                    return BP::object(xn::DepthGenerator(node));
                }
                if (isInstanceOf(original, XN_NODE_TYPE_IMAGE)) {
                    return BP::object(xn::ImageGenerator(node));
                }
                if (isInstanceOf(original, XN_NODE_TYPE_SCENE)) {
                    return BP::object(xn::SceneAnalyzer(node));
                }
                return BP::object(xn::MapGenerator(node));
            }
            if (isInstanceOf(original, XN_NODE_TYPE_GESTURE)) {
                return BP::object(xn::GestureGenerator(node));
            }
            if (isInstanceOf(original, XN_NODE_TYPE_USER)) {
                return BP::object(xn::UserGenerator(node));
            }
            if (isInstanceOf(original, XN_NODE_TYPE_AUDIO)) {
                return BP::object(xn::AudioGenerator(node));
            }
            return BP::object(xn::Generator(node));
        }
        return BP::object(xn::ProductionNode(node));
    }

    //This should never happen
    PyErr_SetString(PyExc_TypeError, "Couldn't find appropiate type to wrap node.");
    throw BP::error_already_set();
}