Exemple #1
0
/**
* @param fileName 要发送的文件路径.
* @return 结果代码.
*
* 将模型文件发送至服务器.
* 接收服务器返回的结果.
* 当中任何一个步骤出现错误则直接返回对应的结果代码,
* 全部成功返回OK.
*/
RC Client::SendModelFile(LPCWSTR fileName)
{
    RC rc;

    CHECK_RC(m_Socket.SendCommand(CC::SEND_MODEL_FILE_COMMAND));
    RC _rc = m_Socket.SendFile(fileName);

    if (OK == _rc)
    {
        CHECK_RC(m_Socket.RecvRC(_rc));
        if (OK == _rc)
        {
            wstring datFileName = fileName;
            datFileName += TEXT(".dat");
            CHECK_RC(m_Socket.RecvFile(datFileName.c_str()));
        }
    }

    return _rc;
}
Exemple #2
0
int configKinect(){
		
	XnStatus rc = XN_STATUS_OK;
	xn::EnumerationErrors errors;

	// Initialize OpenNI
	rc = g_Context.InitFromXmlFile(SAMPLE_XML_PATH, g_ScriptNode, &errors);
	CHECK_ERRORS(rc, errors, "InitFromXmlFile");
	CHECK_RC(rc, "InitFromXmlFile");

	rc = g_Context.FindExistingNode(XN_NODE_TYPE_DEPTH, g_DepthGenerator);
	CHECK_RC(rc, "Find depth generator");
	rc = g_Context.FindExistingNode(XN_NODE_TYPE_GESTURE, g_GestureGenerator);
	CHECK_RC(rc, "Find gesture generator");

	XnCallbackHandle hGestureIntermediateStageCompleted, hGestureProgress, hGestureReadyForNextIntermediateStage;
	g_GestureGenerator.RegisterToGestureIntermediateStageCompleted(GestureIntermediateStageCompletedHandler, NULL, hGestureIntermediateStageCompleted);
	g_GestureGenerator.RegisterToGestureReadyForNextIntermediateStage(GestureReadyForNextIntermediateStageHandler, NULL, hGestureReadyForNextIntermediateStage);
	g_GestureGenerator.RegisterGestureCallbacks(NULL, GestureProgressHandler, NULL, hGestureProgress);

	// Create NITE objects
	g_pSessionManager = new XnVSessionManager;
	rc = g_pSessionManager->Initialize(&g_Context, "Click,Wave", "RaiseHand");
	CHECK_RC(rc, "SessionManager::Initialize");

	g_pSessionManager->RegisterSession(NULL, SessionStarting, SessionEnding, FocusProgress);

	pointHandler = new PointHandler(20, g_DepthGenerator); 
	g_pFlowRouter = new XnVFlowRouter;
	g_pFlowRouter->SetActive(pointHandler);

	g_pSessionManager->AddListener(g_pFlowRouter);

	pointHandler->RegisterNoPoints(NULL, NoHands);

	// Initialization done. Start generating
	rc = g_Context.StartGeneratingAll();
	CHECK_RC(rc, "StartGenerating");

	return rc;
}
int init_mc(struct ctx *p_ctx, res_hndl_t *res_hndl)
{
    int rc;
    __u64 chunks=16;
    __u64 actual_size=0;

    rc = mc_init();
    CHECK_RC(rc, "mc_init failed");
    debug("mc_init success :%d\n",rc);

    rc = ctx_init(p_ctx);
    CHECK_RC(rc, "Context init failed");

    rc = create_res(p_ctx);
    CHECK_RC(rc, "opening res_hndl");

    rc = mc_size1(p_ctx,chunks, &actual_size);
    CHECK_RC(rc, "mc_size");

    *res_hndl = p_ctx->res_hndl;

    rc = create_res(p_ctx);
    CHECK_RC(rc, "opening res_hndl");

    rc = mc_size1(p_ctx, chunks, &actual_size);
    CHECK_RC(rc, "mc_size");
    return 0;
}
int create_ctx_process(char *dev, dev64_t devno, __u64 chunk)
{
    int rc;
    struct ctx my_ctx;
    struct ctx *p_ctx = &my_ctx;
    g_error=0;
    pid = getpid();
    pthread_t threads[MAX_RES_HANDLE];
    pthread_t intr_thread;
    //__u64 flags;
    int i;

    rc = ctx_init2(p_ctx, dev, DK_AF_ASSIGN_AFU, devno);
    CHECK_RC(rc, "Context init failed");
    // interrupt handler per context
    rc = pthread_create(&intr_thread, NULL, ctx_rrq_rx, p_ctx);

    p_ctx ->lun_size = chunk * p_ctx->chunk_size;
    for (i = 0; i <MAX_RES_HANDLE; i++)
    {
        if ( MAX_RES_HANDLE == i+1 && imLastContext == 1 )
        { // this is last resource of last context
            debug("%d:create_ctx_process: last res ==> %d of last contxt \n", pid,i+1);
            p_ctx ->lun_size = ( chunk + chunkRemain )*p_ctx->chunk_size;
        }
        rc = pthread_create(&threads[i], NULL, res_thread, p_ctx);
        CHECK_RC(rc, "pthread_create failed");
    }
    //wait all threads to get complete
    for (i = 0; i <MAX_RES_HANDLE; i++)
    {
        pthread_join(threads[i], NULL);
    }

    pthread_cancel(intr_thread);

    rc = g_error;
    g_error = 0;
    return rc;
}
/*private*/ inline void UserManager::broadcastJointPositions(XnUserID currentUserId, XnSkeletonJoint jointEnum, int jointId) {
	XnSkeletonJointPosition jointPosition;

	// TODO strange, this is how it should be ... :-/
//	this->skeletonCapability.GetSkeletonJointPosition(currentUserId, jointEnum, jointPosition);
	CHECK_RC(this->skeletonCapability.GetSkeletonJointPosition(currentUserId, jointEnum, jointPosition), "Get joint position failed");

	if(jointPosition.fConfidence < 0.5) { return; }

	for(int i=0, n = this->listeners.size(); i < n; i++) {
		this->listeners.at(i)->onJointPositionChanged(currentUserId, jointId, jointPosition);
	}
}
bool get_peerProfileById(const char *uid, char **nick_name, char **group_name, int *sex, int *age, char **introduction, char **head_image_path, int *server_id, char **server_uid, char **last_ip, int *tcp_port, int *udp_port)
{
	int nrows,ncols; //nrows:记录返回数据库表的行数,ncols:记录返回表的列数
	char *errmsg=0;//记录返回的错误信息。
	char **results;//记录返回的查询结果
	sqlite3 *db=0; //记录返回的数据库句柄

	if(!open_db(&db, PEERSINFO_DBFILE_NAME))
		return false;

	//下述函数进行查询数据库操作
	char *szBaseSql = "select * from peers_profile where uid='";
	char *szSql = v6strcat(3, szBaseSql, uid, "';");
	int rc=sqlite3_get_table(db,szSql,&results,&nrows,&ncols,&errmsg);
	release_db_data((void **)&szSql);
	CHECK_RC(rc,errmsg,db);

	bool success = true;
	if(nrows > 0)
	{
		int buf_size = strlen(results[PEERSINFO_DB_ROWS+1])+1;
		*nick_name  = (char*)malloc(buf_size);
		memcpy(*nick_name, results[PEERSINFO_DB_ROWS+1], buf_size);
		buf_size = strlen(results[PEERSINFO_DB_ROWS+2])+1;
		*group_name  = (char*)malloc(buf_size);
		memcpy(*group_name, results[PEERSINFO_DB_ROWS+2], buf_size);
	    *sex = atoi(results[PEERSINFO_DB_ROWS+3]);
		*age = atoi(results[PEERSINFO_DB_ROWS+4]);
		buf_size = strlen(results[PEERSINFO_DB_ROWS+5])+1;
		*introduction = (char*)malloc(buf_size);
		memcpy(*introduction, results[PEERSINFO_DB_ROWS+5], buf_size);
		buf_size = strlen(results[PEERSINFO_DB_ROWS+6])+1;
		*head_image_path = (char*)malloc(buf_size);
		memcpy(*head_image_path, results[PEERSINFO_DB_ROWS+6], buf_size);
		*server_id = atoi(results[PEERSINFO_DB_ROWS+7]);
		buf_size = strlen(results[PEERSINFO_DB_ROWS+8])+1;
		*server_uid = (char*)malloc(buf_size);
		memcpy(*server_uid, results[PEERSINFO_DB_ROWS+8], buf_size);
		buf_size = strlen(results[PEERSINFO_DB_ROWS+9])+1;
		*last_ip = (char*)malloc(buf_size);
		memcpy(*last_ip, results[PEERSINFO_DB_ROWS+9], buf_size);
		*tcp_port = atoi(results[PEERSINFO_DB_ROWS+10]);
		*udp_port = atoi(results[PEERSINFO_DB_ROWS+11]);
	}
	else
		success = false;

	sqlite3_free_table(results);
	sqlite3_close(db);
	return success;
}
/*public*/ void UserManager::update() throw(OpenNiException) {
	const XnUInt16 constUserCount = this->userGenerator.GetNumberOfUsers();
	XnUserID userIds[constUserCount];
	XnUInt16 userCount = constUserCount;
	CHECK_RC(this->userGenerator.GetUsers(userIds, userCount), "Getting users failed!");
	for (int i = 0; i < userCount; ++i) {
		XnUserID currentUserId = userIds[i];
		if (!this->skeletonCapability.IsTracking(currentUserId)) {
			// user is detected (new), but not yet calibrated; skip. // still, could have checked with IsTracking(), but because of performance reasons...
			continue;
		}

		this->broadcastJointPositions(currentUserId, XN_SKEL_HEAD, 0);
		this->broadcastJointPositions(currentUserId, XN_SKEL_NECK, 1);
		this->broadcastJointPositions(currentUserId, XN_SKEL_TORSO, 2);
//		this->broadcastJointPositions(currentUserId, XN_SKEL_WAIST, 3);
//		this->broadcastJointPositions(currentUserId, XN_SKEL_LEFT_COLLAR, 4);
		this->broadcastJointPositions(currentUserId, XN_SKEL_LEFT_SHOULDER, 5);
		this->broadcastJointPositions(currentUserId, XN_SKEL_LEFT_ELBOW, 6);
//		this->broadcastJointPositions(currentUserId, XN_SKEL_LEFT_WRIST, 7);
		this->broadcastJointPositions(currentUserId, XN_SKEL_LEFT_HAND, 8);
//		this->broadcastJointPositions(currentUserId, XN_SKEL_LEFT_FINGERTIP, 9);
//		this->broadcastJointPositions(currentUserId, XN_SKEL_RIGHT_COLLAR, 10);
		this->broadcastJointPositions(currentUserId, XN_SKEL_RIGHT_SHOULDER, 11);
		this->broadcastJointPositions(currentUserId, XN_SKEL_RIGHT_ELBOW, 12);
//		this->broadcastJointPositions(currentUserId, XN_SKEL_RIGHT_WRIST, 13);
		this->broadcastJointPositions(currentUserId, XN_SKEL_RIGHT_HAND, 14);
//		this->broadcastJointPositions(currentUserId, XN_SKEL_RIGHT_FINGERTIP, 15);
		this->broadcastJointPositions(currentUserId, XN_SKEL_LEFT_HIP, 16);
		this->broadcastJointPositions(currentUserId, XN_SKEL_LEFT_KNEE, 17);
//		this->broadcastJointPositions(currentUserId, XN_SKEL_LEFT_ANKLE, 18);
		this->broadcastJointPositions(currentUserId, XN_SKEL_LEFT_FOOT, 19);
		this->broadcastJointPositions(currentUserId, XN_SKEL_RIGHT_HIP, 20);
		this->broadcastJointPositions(currentUserId, XN_SKEL_RIGHT_KNEE, 21);
//		this->broadcastJointPositions(currentUserId, XN_SKEL_RIGHT_ANKLE, 22);
		this->broadcastJointPositions(currentUserId, XN_SKEL_RIGHT_FOOT, 23);

//		XnSkeletonJointOrientation jointOrientation; NO => if interested in position AND orientation ==> use GetSkeletonJoint() instead!!
//		CHECK_RC(this->skeletonCapability.GetSkeletonJointOrientation(currentUserId, XN_SKEL_HEAD, jointOrientation), "Get joint orientation failed!");
//		if(jointOrientation.fConfidence < 0.5) { continue; }
//		jointOrientation.orientation.elements[0], jointOrientation.orientation.elements[1], jointOrientation.orientation.elements[2],
//		jointOrientation.orientation.elements[3], jointOrientation.orientation.elements[4], jointOrientation.orientation.elements[5],
//		jointOrientation.orientation.elements[6], jointOrientation.orientation.elements[7], jointOrientation.orientation.elements[8],
//		printf("joint update:\n\tposition: %.2f x %.2f x %.2f (confidence: %.2f)\n\torientation: [ (%.2f, %.2f, %.2f) - (%.2f, %.2f, %.2f) - (%.2f, %.2f, %.2f)] (confidence: %.2f)\n",
//				jointPosition.position.X, jointPosition.position.Y, jointPosition.position.Z, jointPosition.fConfidence,
//				jointOrientation.orientation.elements[0], jointOrientation.orientation.elements[1], jointOrientation.orientation.elements[2],
//				jointOrientation.orientation.elements[3], jointOrientation.orientation.elements[4], jointOrientation.orientation.elements[5],
//				jointOrientation.orientation.elements[6], jointOrientation.orientation.elements[7], jointOrientation.orientation.elements[8],
//				jointOrientation.fConfidence);
	}
}
int test_spio_direct_virtual()
{
    int rc=0;
    int j;
    int cfdisk = 0;
    struct flash_disk fldisks[MAX_FDISK];
    //__u64 chunk;
    int count = 1;
    int procces=10;
    int index = 0; //to switch flash disks for VLUN & PLUN IO

    char *str = getenv("LONG_RUN");
    if (str != NULL)
    {
        printf("LONG_RUN enabled...\n");
        count = 10;
    }
    cfdisk = get_flash_disks(fldisks, FDISKS_ALL);
    if (cfdisk < 2)
    {
        fprintf(stderr,"Must have 2 flash disks..\n");
        return -1;
    }

    while (count-- >0)
    {
        if (0 == fork())
        {
            rc = test_spio_lun(fldisks[index].dev,
                               fldisks[index].devno[0],LUN_DIRECT,0);
            exit(rc);
        }
        //create atleast 10 chunks on each on PLUN
        index = (index+1)%2;
        for (j=0; j < procces; j++)
        {
            if (0 == fork()) //child process
            {
                //here you can change the path ids later
                rc = test_spio_lun(fldisks[index].dev, fldisks[index].devno[0],
                                   LUN_VIRTUAL,chunks[j]);
                exit(rc);
            }
        }
        rc = wait4all();
        CHECK_RC(rc, "wait4all failed");
        printf("%d loop remain................\n",count);
    }
    return rc;
}
// 7.1.217 : create two context for same flash disks shared between 2 adapters
int test_cfdisk_ctxs_diff_devno()
{
    int nDisk;
    int rc=0;
    struct flash_disk cfDisk[2];
    struct ctx myctx1, myctx2;
    struct ctx *p_ctx1 = &myctx1;
    struct ctx *p_ctx2 = &myctx2;

    pid = getpid();

    nDisk = get_flash_disks(cfDisk, FDISKS_DIFF_ADPTR);
    if (nDisk < 2)
    {
        fprintf(stderr,"Failed to find 2 flash disks from diff adapter..\n");
        return -1;
    }
    // On AIX both dev will have same name
    // On Linux both dev will have diff name

    rc = ctx_init2(p_ctx1, cfDisk[0].dev, DK_AF_ASSIGN_AFU, cfDisk[0].devno[0]);
    CHECK_RC(rc, "p_ctx1 Context init failed");

    rc = ctx_init2(p_ctx2, cfDisk[1].dev, DK_AF_ASSIGN_AFU, cfDisk[1].devno[0]);
    CHECK_RC(rc, "p_ctx2 Context init failed");

    rc = create_resource(p_ctx1, 0, DK_UDF_ASSIGN_PATH, LUN_DIRECT);
    CHECK_RC(rc, "create LUN_DIRECT for p_ctx1 failed");

    rc = create_resource(p_ctx2, 0, DK_UDF_ASSIGN_PATH, LUN_DIRECT);
    CHECK_RC(rc, "create LUN_DIRECT for p_ctx2 failed");

    cleanup(p_ctx1, -1);
    cleanup(p_ctx2, -1);

    return 0;
}
bool ofxOpenNIContext::unregisterViewport() {
	
	// get refs to depth generator
	xn::DepthGenerator depth_generator;
	getDepthGenerator(&depth_generator);
	
	// Unregister view point from (image) any map	
	if (depth_generator.IsCapabilitySupported(XN_CAPABILITY_ALTERNATIVE_VIEW_POINT)) {
		XnStatus result = depth_generator.GetAlternativeViewPointCap().ResetViewPoint();
		CHECK_RC(result, "Unregister viewport");
		
	} else return false;
	
	return true;
}
// Barebones setup
bool CinderOpenNISkeleton::setup()
{
	XnStatus nRetVal = XN_STATUS_OK;
	xn::EnumerationErrors errors;

	// Init
	nRetVal = mContext.Init();
	CHECK_RC(nRetVal, "Init", true);

	nRetVal = xnFPSInit(&xnFPS, 180);
	CHECK_RC(nRetVal, "FPS Init", true);

    worldOffset.x = -160;
    worldOffset.y = -200;
    worldOffset.z = -2784;

	// Output device production nodes (user, depth, etc)
	debugOutputNodeTypes();

	_allUsers.clear();
	for(int i = 0; i < maxUsers; i++) {
		UserSkeleton emptySkeleton;
		emptySkeleton.isValid = false;
		emptySkeleton.id = currentUsers[i];

		// Create a bunch of spots to contain our vectors
		emptySkeleton.projectedPositions.clear();
		for( int j = 0; j <= XN_SKEL_RIGHT_FOOT+1; ++j) {
			emptySkeleton.projectedPositions.push_back( ci::Vec3f::zero() );
		}

		_allUsers.push_back( emptySkeleton );
	}

	return true;
}
int max_vlun_on_a_ctx()
{
    int i;
    int rc;
    struct ctx myctx;
    struct ctx *p_ctx=&myctx;
    pid = getpid();
    rc=ctx_init(p_ctx);
    __u64 vluns[MAX_VLUNS];
    for (i=0;i<MAX_VLUNS;i++)
    {
        rc = create_resource(p_ctx,p_ctx->chunk_size,0,LUN_VIRTUAL);
        CHECK_RC(rc, "create_resource Failed\n");
        vluns[i]=p_ctx->rsrc_handle;
    }
    for (i=0;i<MAX_VLUNS;i++)
    {
        p_ctx->rsrc_handle=vluns[i];
        rc=close_res(p_ctx);
        CHECK_RC(rc, "close_res failed\n");
    }
    rc = ctx_close(p_ctx);
    return rc;
}
RC AlgorithmDataFile::RemoveAlgorithm(wstring name)
{
    RC rc;

    if (m_Lines.find(name) == m_Lines.end())
    {
        return RC::ALGORITHM_REMOVE_ERROR;
    }

    m_Lines.erase(name);

    CHECK_RC(Save());

    return rc;
}
Exemple #14
0
bool clear_peersProfile()
{
	char *errmsg=0;//记录返回的错误信息。
	sqlite3 *db=0; //记录返回的数据库句柄

	if(!open_db(&db, PEERSINFO_DBFILE_NAME))
		return false;

	//下述函数进行数据库添加操作
	char *szSql = "delete from peers_profile";
	int rc=sqlite3_exec(db,szSql,0,0,&errmsg);
	CHECK_RC(rc,errmsg,db);

	sqlite3_close(db);
	return true;
}
Exemple #15
0
bool delete_peerProfile(const char *uid)
{
	char *errmsg=0;//记录返回的错误信息。
	sqlite3 *db=0; //记录返回的数据库句柄

	if(!open_db(&db, PEERSINFO_DBFILE_NAME))
		return false;

	//下述函数进行数据库添加操作
	char *szSql = v6strcat(2, "delete from peers_profile where uid = ", uid);
	int rc=sqlite3_exec(db,szSql,0,0,&errmsg);
	CHECK_RC(rc,errmsg,db);

	sqlite3_close(db);
	return true;
}
Exemple #16
0
bool clear_serversInformation()
{
	char *errmsg=0;//记录返回的错误信息。
	sqlite3 *db=0; //记录返回的数据库句柄

	if(!open_db(&db, SERVERSINFO_DBFILE_NAME))
		return false;

	//下述函数进行数据库添加操作
	char *szSql = "delete * from server_information";
	int rc=sqlite3_exec(db,szSql,0,0,&errmsg);
	CHECK_RC(rc,errmsg,db);

	sqlite3_close(db);
	return true;
}
void OpenNiManager::startAll() {
	LOG->info("startAll()");

	for(int i = 0, n = this->cams.size(); i < n; i++) {
		Cam* currentCam = cams.at(i);
		std::cout << (i+1) << ". " << currentCam->toString() << std::endl;

		if(this->initDescriptor->isImageGeneratorRequired()) {
			xn::ImageGenerator generator = currentCam->getImageGenerator();
			CHECK_RC(generator.StartGenerating(), "generator.StartGenerating()");
		}

		if(this->initDescriptor->isUserGeneratorRequired()) {
			this->userManager->start();
		}
	}
}
bool ofxDepthGenerator::setup(ofxOpenNIContext* pContext) {

	XnStatus result = XN_STATUS_OK;	
	XnMapOutputMode map_mode; 
	
	// Try to fetch depth generator before creating one
	if(pContext->getDepthGenerator(&depth_generator)) {
		// found the depth generator so set map_mode from it
		depth_generator.GetMapOutputMode(map_mode);
	} else {
		result = depth_generator.Create(pContext->getXnContext());
		CHECK_RC(result, "Creating depth generator");
		
		if (result != XN_STATUS_OK) return false;
		
		// make new map mode -> default to 640 x 480 @ 30fps
		map_mode.nXRes = XN_VGA_X_RES;
		map_mode.nYRes = XN_VGA_Y_RES;
		map_mode.nFPS  = 30;
		
		depth_generator.SetMapOutputMode(map_mode);
	}	

	// Default max depth is on GlobalDefaults.ini: MaxDepthValue=10000
	max_depth	= depth_generator.GetDeviceMaxDepth();		
	width		= map_mode.nXRes;
	height		= map_mode.nYRes;
	
	// TODO: add capability for b+w depth maps (more efficient for draw)
	depth_texture.allocate(map_mode.nXRes, map_mode.nYRes, GL_RGBA);		
	depth_pixels = new unsigned char[map_mode.nXRes * map_mode.nYRes * 4];
	memset(depth_pixels, 0, map_mode.nXRes * map_mode.nYRes * 4 * sizeof(unsigned char));
	
	// setup mask pixelskk
	for (int i = 0; i < MAX_NUMBER_DEPTHS; i++) {
		maskPixels[i] = new unsigned char[width * height];
		depth_thresholds[i].nearThreshold = 0;
		depth_thresholds[i].farThreshold = 10000;
	}
	
	depth_generator.StartGenerating();	
	
	printf("Depth camera inited\n");
	
	return true;
}
Exemple #19
0
std::vector<std::vector<XnPoint3D> > KinectControl::getSkeleton()
{
    SkeletonCapability skeleton = user_generator.GetSkeletonCap();

    XnUserID user_id[15];
    XnUInt16 user_count = sizeof(user_id) / sizeof(user_id[0]);

    XnStatus nRetVal = user_generator.GetUsers(user_id, user_count);
    CHECK_RC(nRetVal, "Get Users");

    // 全ユーザ
    std::vector<std::vector<XnPoint3D> > skeletons;

    for(int i = 0; i < user_count; ++i)
    {
        // i番目のユーザがトラッキングされていたら
        if(skeleton.IsTracking(user_id[i]))
        {
            // 個別ユーザ
            std::vector<XnPoint3D> user_skeleton;

            // 関節は全てで24個
            XnSkeletonJointPosition joint[24];

            // [0]はCenter of Mass
            XnPoint3D pt[25];

            for(int j = 1; j < 25; ++j)
            {
                skeleton.GetSkeletonJointPosition(user_id[i], (XnSkeletonJoint)(j), joint[j - 1]);
                pt[j] = joint[j - 1].position;
            }

            user_generator.GetCoM(user_id[i], pt[0]);
            depth_generator.ConvertRealWorldToProjective(25, pt, pt);

            for(int j = 0; j < 25; ++j)
                user_skeleton.push_back(pt[j]);

            skeletons.push_back(user_skeleton);
        }
    }

    return skeletons;
}
//--------------------------------------------------------------
bool ofxHandGenerator::setup(ofxOpenNIContext* pContext) {
	
	context = pContext;
	context->getDepthGenerator(&depth_generator);
	
	XnStatus result = XN_STATUS_OK;	
	
	// setup a gesture generator using our ofxGestureGenerator wrapper
	gesture_generator.setup(context);
	ofAddListener(gesture_generator.gestureRecognized, this, &ofxHandGenerator::gestureRecognized); 
	
	// Try to fetch hands generator before creating one
	if(pContext->getHandsGenerator(&hands_generator)) {
		// found the hands generator - for do nothing		
	} else {
		result = hands_generator.Create(context->getXnContext());
		CHECK_RC(result, "Creating hand generator");
		hands_generator.StartGenerating();
	}
	
	XnCallbackHandle hand_cb_handle;
	hands_generator.RegisterHandCallbacks(HandCreate, HandUpdate, HandDestroy, this, hand_cb_handle);
	
	printf("Hands generator inited\n");
	
	// pre-generate the tracked users.
	tracked_hands.reserve(max_hands);
	for(int i = 0; i < max_hands; ++i) {
		printf("Creating hand: %d", i);
		ofxTrackedHand* hand = new ofxTrackedHand(context);
		tracked_hands.push_back(hand);
	}
	
	found_hands = 0;
	
	isFiltering = false;

	// Start looking for gestures
	this->addGestures();

	return true;
}
Exemple #21
0
bool get_peersProfile(char ***peers_table, int *rows, int *cols)
{
	char *errmsg=0;//记录返回的错误信息。
	sqlite3 *db=0; //记录返回的数据库句柄

	if(!open_db(&db, PEERSINFO_DBFILE_NAME))
		return false;

	//下述函数进行查询数据库操作
	char *szSql = "select * from peers_profile";
	int rc=sqlite3_get_table(db,szSql,peers_table,rows,cols,&errmsg);
	CHECK_RC(rc,errmsg,db);

	bool success = true;
	if(SQLITE_OK != errmsg)
		success = false;

	sqlite3_close(db);
	return success;
}
Exemple #22
0
bool get_serversInformation(char ***servers_table, int *rows, int *cols)
{
	char *errmsg=0;//记录返回的错误信息。
	sqlite3 *db=0; //记录返回的数据库句柄

	if(!open_db(&db, SERVERSINFO_DBFILE_NAME))
		return false;

	//下述函数进行查询数据库操作
	char *szSql = "select * from server_information";
	int rc=sqlite3_get_table(db,szSql,servers_table,rows,cols,&errmsg);
	CHECK_RC(rc,errmsg,db);

	bool success = true;
	if(SQLITE_OK != errmsg)
		success = false;

	sqlite3_close(db);
	return success;
}
void UserTracker::update()
{
    
    //XnStatus rc = m_Context.WaitAnyUpdateAll();
     XnStatus rc = m_Context.WaitOneUpdateAll(m_UserGenerator);
    
    CHECK_RC(rc, "Wait and Update");
    
    m_DepthGenerator.GetMetaData(depthMD);
    m_UserGenerator.GetUserPixels(0, sceneMD);
    
    //m_UserGenerator.GetUsers(aUsers[1], 1);
    
    XnUInt16 nUsers = 1; 
    m_UserGenerator.GetUsers(aUsers, nUsers); 
    for (int i = 0; i < nUsers; ++i) 
    { 
        XnPoint3D com; 
        m_UserGenerator.GetCoM(aUsers[i], com); 
        
        if (com.Z == 0) //this could be your check for useful data 
        { 
            
        } 
    } 
    
    if(m_UserGenerator.GetSkeletonCap().IsTracking(1))
    {
        XnSkeletonJointPosition Torso;
        m_UserGenerator.GetSkeletonCap().GetSkeletonJointPosition(1, XN_SKEL_TORSO, Torso);
        printf("%d: (%f,%f,%f) [%f]\n", 1,Torso.position.X+ APP_RES_X/2.0f, -(-Torso.position.Y+ APP_RES_Y/2.0f), Torso.position.Z,Torso.fConfidence);
        //printf("this is called\n");
        if(userPoints.size()>0)
        {
            userPoints.at(0).prevPosition = userPoints.at(0).position;
            //userPoints.at(0).position = ci::Vec3f( Torso.position.X + APP_RES_X/2.0f, -(-Torso.position.Y + APP_RES_Y/2.0f), Torso.position.Z );
            userPoints.at(0).position = ci::Vec3f( Torso.position.X + APP_RES_X/3.0f, -(-Torso.position.Y + APP_RES_Y/2.0f), Torso.position.Z );
        }
        
    }
}
Exemple #24
0
bool get_myProfileById(const char *id, char **name, unsigned short *sex, unsigned int *age, char **introduction,char **head_image_path, int *v4_port, int *v6_port)
{
	int nrows,ncols; //nrows:记录返回数据库表的行数,ncols:记录返回表的列数
	char *errmsg=0;//记录返回的错误信息。
	char **results;//记录返回的查询结果
	sqlite3 *db=0; //记录返回的数据库句柄

	if(!open_db(&db, MYINFO_DBFILE_NAME))
		return false;

	//下述函数进行查询数据库操作
	char *szBaseSql = "select * from my_profile where id='";
	char *szSql = v6strcat(3, szBaseSql, id, "';");
	int rc=sqlite3_get_table(db,szSql,&results,&nrows,&ncols,&errmsg);
	release_db_data((void **)&szSql);
	CHECK_RC(rc,errmsg,db);

	bool success = true;
	if(nrows > 0)
	{
		int buf_size = strlen(results[MYINFO_DB_ROWS+1])+1;
		*name  = (char*)malloc(buf_size);
		memcpy(*name, results[MYINFO_DB_ROWS+1], buf_size);
	    *sex = atoi(results[MYINFO_DB_ROWS+2]);
		*age = atoi(results[MYINFO_DB_ROWS+3]);
		buf_size = strlen(results[MYINFO_DB_ROWS+4])+1;
		*introduction = (char*)malloc(buf_size);
		memcpy(*introduction, results[MYINFO_DB_ROWS+4], buf_size);
		buf_size = strlen(results[MYINFO_DB_ROWS+5])+1;
		*head_image_path = (char*)malloc(buf_size);
		memcpy(*head_image_path, results[MYINFO_DB_ROWS+5], buf_size);
		*v4_port = atoi(results[MYINFO_DB_ROWS+6]);
		*v6_port = atoi(results[MYINFO_DB_ROWS+7]);
	}
	else
		success = false;

	sqlite3_free_table(results);
	sqlite3_close(db);
	return success;
}
Exemple #25
0
int insert_serverInformation(const char *name, const char *ip, const char *port, const char *description, const char *uid, const char *upassword)
{
	char *errmsg=0;//记录返回的错误信息。
	sqlite3 *db=0; //记录返回的数据库句柄

	if(!open_db(&db, SERVERSINFO_DBFILE_NAME))
		return false;

	//下述函数进行数据库添加操作
	char *szBaseSql = "insert into server_information(name,ip,port,description,uid,upassword) values('";
	char *szSql = v6strcat(13, szBaseSql, name, "','", ip, "','", port, "','",description, "','",uid, "','",upassword,"')");
	int rc=sqlite3_exec(db,szSql,0,0,&errmsg);
	release_db_data((void **)&szSql);
	CHECK_RC(rc,errmsg,db);

	//下述函数获取数据库插入的数据的ID
	int id = (int) sqlite3_last_insert_rowid(db);

	sqlite3_close(db);
	return id;
}
Exemple #26
0
int insert_myProfile(const char *name,const char *sex,const char *age,const char *introduction,const char *head_image_path, const char *v4_port, const char *v6_port)
{
	char *errmsg=0;//记录返回的错误信息。
	sqlite3 *db=0; //记录返回的数据库句柄

	if(!open_db(&db, MYINFO_DBFILE_NAME))
		return false;

	//下述函数进行数据库添加操作
	char *szBaseSql = "insert into my_profile(nick_name,sex,age,introduction,head_image_path,v4_port,v6_port) values('";
	char *szSql = v6strcat(15, szBaseSql, name, "','", sex, "','", age, "','",introduction,"','",head_image_path,"','",v4_port,"','",v6_port,"')");
	int rc=sqlite3_exec(db,szSql,0,0,&errmsg);
	release_db_data((void **)&szSql);
	CHECK_RC(rc,errmsg,db);

	//下述函数获取数据库插入的数据的ID
	int id = (int) sqlite3_last_insert_rowid(db);

	sqlite3_close(db);
	return id;
}
Exemple #27
0
int insert_peerProfile(const char *nick_name, const char *group_name, const char *sex, const char *age, const char *introduction, const char *head_image_path, const char *server_id, const char *server_uid, const char *last_ip, const char *tcp_port, const char *udp_port)
{
	char *errmsg=0;//记录返回的错误信息。
	sqlite3 *db=0; //记录返回的数据库句柄

	if(!open_db(&db, PEERSINFO_DBFILE_NAME))
		return false;

	// 下述函数进行数据库添加操作
	char *szBaseSql = "insert into peers_profile(nick_name,group_name,sex,age,introduction,head_image_path,server_id,server_uid,last_ip,last_tcp_port,last_udp_port) values('";
	char *szSql = v6strcat(23, szBaseSql, nick_name, "','", group_name, "','", sex, "','",age, "','",introduction, "','",head_image_path, "','",server_id, "','",server_uid, "','",last_ip, "','",tcp_port, "','",udp_port,"')");
	int rc=sqlite3_exec(db,szSql,0,0,&errmsg);
	release_db_data((void **)&szSql);
	CHECK_RC(rc,errmsg,db);

	// 下述函数获取数据库插入的数据的ID
	int id = (int) sqlite3_last_insert_rowid(db);

	sqlite3_close(db);
	return id;
}
Exemple #28
0
bool Kinect::Init(){
	m_hPoseCallbacks = NULL;
	m_hUserCallbacks = NULL;
	m_hCalibrationCallbacks = NULL;
	m_hHandCallbacks = NULL;
	m_hGestureCallbacks = NULL;

	// Init OpenNI from XML
	rc = m_Context.InitFromXmlFile(".\\Data\\openni.xml");
	CHECK_RC(rc, "InitFromXml");

	// Make sure we have all OpenNI nodes we need
	VALIDATE_GENERATOR(XN_NODE_TYPE_DEPTH, "Depth", m_DepthGenerator);
	VALIDATE_GENERATOR(XN_NODE_TYPE_HANDS, "Image", m_ImageGenerator);
	VALIDATE_GENERATOR(XN_NODE_TYPE_USER, "User", m_UserGenerator);
	VALIDATE_GENERATOR(XN_NODE_TYPE_GESTURE, "Gesture", m_GestureGenerator);
	VALIDATE_GENERATOR(XN_NODE_TYPE_HANDS, "Hands", m_HandsGenerator);

	m_DepthGenerator.GetAlternativeViewPointCap().SetViewPoint( m_ImageGenerator);
	return true;
};
Exemple #29
0
bool ofxImageGenerator::setup(ofxOpenNIContext* pContext) {
	
	XnStatus result = XN_STATUS_OK;	
	XnMapOutputMode map_mode;
	
	// check we don't already have an IR generator -> can only have an image OR an ir gen
	xn::IRGenerator ir_generator;
	if(pContext->getIRGenerator(&ir_generator)) {
		printf("Can't init image generator: can only have image OR IR gen, not both!!!");
		return false;
	}
	
	// Try to fetch image generator before creating one
	if(pContext->getImageGenerator(&image_generator)) {
		// found the image generator so set map_mode from it
		image_generator.GetMapOutputMode(map_mode);
	} else {
		result = image_generator.Create(pContext->getXnContext());
		CHECK_RC(result, "Creating image generator");
		
		// make new map mode -> default to 640 x 480 @ 30fps
		map_mode.nXRes = XN_VGA_X_RES;
		map_mode.nYRes = XN_VGA_Y_RES;
		map_mode.nFPS  = 30;
		
		image_generator.SetMapOutputMode(map_mode);
	}

	// TODO: add capability for b+w depth maps (more efficient for draw)
	image_texture.allocate(map_mode.nXRes, map_mode.nYRes, GL_RGBA);		
	image_pixels = new unsigned char[map_mode.nXRes * map_mode.nYRes * 3];
	memset(image_pixels, 0, map_mode.nXRes * map_mode.nYRes * 3 * sizeof(unsigned char));
	
	image_generator.StartGenerating();	
	
	printf("Image camera inited\n");
	
	return true;
	
}
bool ofxOpenNIContext::registerViewport() {
	
	// get refs to depth and image generators TODO: make work with IR generator
	xn::DepthGenerator depth_generator;
	getDepthGenerator(&depth_generator);
	
	xn::ImageGenerator image_generator;
	if (!getImageGenerator(&image_generator)) {
		printf("No Image generator found: cannot register viewport");
		return false;
	}
	
	// Register view point to image map
	if (depth_generator.IsCapabilitySupported(XN_CAPABILITY_ALTERNATIVE_VIEW_POINT)) {
		
		XnStatus result = depth_generator.GetAlternativeViewPointCap().SetViewPoint(image_generator);
		CHECK_RC(result, "Register viewport");
		
	} else return false;
	
	return true;
}