示例#1
0
/*!
	@brief 描画プロシージャ
*/
void mine_tile::paint(Graphics* g){
	switch(state){
	case init:
	case init_lock:
		draw_frame(g);
		break;
	case opened:
		draw_grid(g);
		draw_number(g);
		break;
	case marked:
	case mark_lock:
		draw_frame(g);
		draw_flag(g);
		break;
	case bomb:
		draw_grid(g);
		draw_bomb(g);
		break;
	case exploded:
		draw_grid(g);
		draw_bomb(g);
		draw_cross(g);
		break;
	case missmark:
		draw_frame(g);
		draw_flag(g);
		draw_cross(g);
		break;
	default:
		break;
	}
}
示例#2
0
static void add_clock_to_frame( mlt_producer producer, mlt_frame frame, time_info* info )
{
	mlt_profile profile = mlt_service_profile( MLT_PRODUCER_SERVICE( producer ) );
	mlt_properties producer_properties = MLT_PRODUCER_PROPERTIES( producer );
	uint8_t* image = NULL;
	mlt_image_format format = mlt_image_rgb24a;
	int size = 0;
	int width = profile->width;
	int height = profile->height;
	int line_width = LINE_WIDTH_RATIO * (width > height ? height : width) / 100;
	int radius = (width > height ? height : width) / 2;
	char* direction = mlt_properties_get( producer_properties, "direction" );
	int clock_angle = 0;

	mlt_frame_get_image( frame, &image, &format, &width, &height, 1 );

	// Calculate the angle for the clock.
	int frames = info->frames;
	if( !strcmp( direction, "down" ) )
	{
		frames = info->fps - info->frames - 1;
	}
	clock_angle = (frames + 1) * 360 / info->fps;

	draw_clock( image, profile, clock_angle, line_width );
	draw_cross( image, profile, line_width );
	draw_ring( image, profile, ( radius * OUTER_RING_RATIO ) / 100, line_width );
	draw_ring( image, profile, ( radius * INNER_RING_RATIO ) / 100, line_width );

	size = mlt_image_format_size( format, width, height, NULL );
	mlt_frame_set_image( frame, image, size, mlt_pool_release );
}
示例#3
0
void simulation_render_lagrange_points(simulation_t* sim,celestial_body_t* secondary)
{
vector_t lagrange_points[5];
vector_t rel_position=vector_subtract(secondary->base.position,secondary->orbit.primary->base.position);
vector_t direction=vector_normalize(rel_position);
float a=secondary->base.mass/(secondary->base.mass+secondary->orbit.primary->base.mass);

float offset=powf(a*0.3333333,0.333333);
lagrange_points[0]=vector_multiply(secondary->orbit.semi_major_axis*(1+offset),direction);
lagrange_points[1]=vector_multiply(secondary->orbit.semi_major_axis*(1-offset),direction);
lagrange_points[2]=vector_multiply(-secondary->orbit.semi_major_axis*(1+(5.0/12.0)*a),direction);

lagrange_points[3].x=rel_position.x*cos(M_PI/3)+rel_position.y*sin(M_PI/3);
lagrange_points[3].y=rel_position.x*-sin(M_PI/3)+rel_position.y*cos(M_PI/3);

lagrange_points[4].x=rel_position.x*cos(-M_PI/3)+rel_position.y*sin(-M_PI/3);
lagrange_points[4].y=rel_position.x*-sin(-M_PI/3)+rel_position.y*cos(-M_PI/3);

int i;
    for(i=0;i<5;i++)
    {
    char str[128];
    sprintf(str,"%s-%s L%d point",secondary->orbit.primary->name,secondary->name,i+1);
    vector_t screen_pos=vector_transform(vector_add(secondary->orbit.primary->base.position,lagrange_points[i]),sim->camera);
    draw_cross(screen_pos,get_color(0,0,255));
    draw_text(screen_pos.x+10,screen_pos.y,str);
    }

}
示例#4
0
void	exe_key(int *src, t_ray *ray)
{
  if (src[4] == 1)
    do_disco_key(ray, 1);
  if (src[4] == 0)
    do_disco_key(ray, 0);
  if (src[5] == 1)
    draw_cross(ray);

}
示例#5
0
/**
 * \brief Selects a random, unoccupied square
 */
static void opponent_turn(void)
{
	uint8_t square_num;

	do {
		square_num = rand() % 9;
	} while (occupied_squares[square_num / 3][square_num % 3]);

	occupied_squares[square_num / 3][square_num % 3] = COMPUTER;
	draw_cross(square_num);
}
示例#6
0
static void test_calibration(void)
{
    int sample[3][2] = {
	{ 200, 200 },
	{ 100, 400 },
	{ 600, 330 },
    };
    int tx[3];
    int ty[3];
    int i, x, y;

    for (i = 0; i < 3; i ++) {
	draw_cross(sample[i][0], sample[i][1], 0);
	get_input(&tx[i], &ty[i]);
	x = (cal_val[0] * tx[i]) +
		(cal_val[1] * ty[i]) +
		cal_val[2];
	y = (cal_val[3] * tx[i]) +
		(cal_val[4] * ty[i]) +
		cal_val[5];
	log_write("get event: %d,%d\n", x/cal_val[6], y/cal_val[6]);
	draw_cross(sample[i][0], sample[i][1], 1);
    }
}
示例#7
0
文件: quad.c 项目: PSC-SR/libkoki
/**
 * @brief draws a little cross on each corner of a quad
 *
 * @param frame  the \c IplImage to draw on to
 * @param quad   the quad that should be drawn
 */
void koki_quad_draw(IplImage *frame, koki_quad_t *quad)
{

	koki_point2Di_t p;

	assert(frame != NULL);
	assert(quad != NULL);

	for (uint8_t i=0; i<4; i++){

		p.x = quad->vertices[i].x;
		p.y = quad->vertices[i].y;

		if (p.x < 0 || p.x > frame->width ||
		    p.y < 0 || p.y > frame->height)
			continue;

		draw_cross(frame, p);

	}

}
示例#8
0
Var* ff_drawshape(vfuncptr func, Var* arg)
{
	Var *obj = NULL, *ovar = NULL;
	size_t x, y, z;
	char* out;
	float ignore = FLT_MAX;

	const char* options[] = {"cross", "box", "circle", NULL};
	const char* shape     = options[0];

	Alist alist[9];
	alist[0]      = make_alist("object", ID_VAL, NULL, &obj);
	alist[1]      = make_alist("shape", ID_ENUM, options, &shape);
	alist[2]      = make_alist("ignore", DV_FLOAT, NULL, &ignore);
	alist[3].name = NULL;

	if (parse_args(func, arg, alist) == 0) return (NULL);

	if (obj == NULL) {
		parse_error("%s: No object specified\n", func->name);
		return (NULL);
	}

	x    = GetX(obj);
	y    = GetY(obj);
	z    = GetZ(obj);
	out  = calloc(x * y, sizeof(char));
	ovar = newVal(BSQ, x, y, 1, DV_UINT8, out);

	if (!strcmp(shape, "cross")) {
		draw_cross(obj, x, y, ignore, out);
	} else if (!strcmp(shape, "box")) {
		draw_box(obj, x, y, ignore, out);
	} else if (!strcmp(shape, "circle")) {
		draw_circle(obj, x, y, ignore, out);
	}
	return (ovar);
}
示例#9
0
int main(int argc, char** argv)
{
    if(argc != 6) {
        std::cerr << "Usage: " << argv[0]
                  << " in.png out.png match.txt left|right H.txt" <<std::endl;
        return 1;
    }

    // Read image
    size_t nx, ny;
    LWImage<unsigned char> in(0,0,0);
    in.data = read_png_u8_rgb(argv[1], &nx, &ny);
    in.w = static_cast<int>(nx); in.h = static_cast<int>(ny); in.comps=3;
    if(! in.data) {
        std::cerr << "Error reading image " << argv[1] << std::endl;
        return 1;
    }

    // Read correspondences
    std::vector<Match> match;
    if(! loadMatch(argv[3],match)) {
        std::cerr << "Failed reading " << argv[3] << std::endl;
        return 1;
    }

    // Read left/right image
    bool bLeft = (strcmp(argv[4],"left")==0);
    if(!bLeft && strcmp(argv[4], "right")!=0) {
        std::cerr << "Error: arg 4 must be 'left' or 'right'" << std::endl;
        return 1;
    }

    // Read homography
    libNumerics::Homography H;
    std::ifstream f(argv[5]);
    if((f >> H.mat()).fail()) {
        std::cerr << "Error reading homography file " << argv[2] << std::endl;
        return 1;
    }

    // Drawing lines
    int delta = in.h/(NUM_LINES+1);
    if(delta==0) delta=1;
    for(int i=delta; i < in.h; i+=delta)
        draw_horizontal_dashed_line(in.data, in.w, in.h, i,
                                    LENGTH_ON, LENGTH_OFF, CYAN);

    // Drawing SIFT
    std::vector<Match>::const_iterator it=match.begin();
    for(; it != match.end(); ++it) {
        double x=it->x1, y=it->y1;
        if(! bLeft) {
            x = it->x2; y=it->y2;
        }
        H(x,y);
        int ix = static_cast<int>(std::floor(x+0.5));
        int iy = static_cast<int>(std::floor(y+0.5));
        if(0<=ix && ix<in.w && 0<=iy && iy<in.h)
            draw_cross(in.data, in.w, in.h, ix, iy, CROSS_HALF_LENGTH, RED);
    }

    // Write image
    if(write_png_u8(argv[2], in.data, in.w, in.h, in.comps) != 0) {
        std::cerr << "Error writing file " << argv[3] << std::endl;
        return 1;
    }
    return 0;
}
示例#10
0
文件: kalman.cpp 项目: lblsa/roombara
int main(int argc, char** argv)
{
    /* A matrix data */
    const float A[] = { 1, 1, 0, 1 };

    IplImage* img = cvCreateImage( cvSize(500,500), 8, 3 );
    CvKalman* kalman = cvCreateKalman( 2, 1, 0 );
    /* state is (phi, delta_phi) - angle and angle increment */
    CvMat* state = cvCreateMat( 2, 1, CV_32FC1 );
    CvMat* process_noise = cvCreateMat( 2, 1, CV_32FC1 );
    /* only phi (angle) is measured */
    CvMat* measurement = cvCreateMat( 1, 1, CV_32FC1 );
    CvRandState rng;
    int code = -1;

    cvRandInit( &rng, 0, 1, -1, CV_RAND_UNI );

    cvZero( measurement );
    cvNamedWindow( "Kalman", 1 );

    for(;;)
    {
        cvRandSetRange( &rng, 0, 0.1, 0 );
        rng.disttype = CV_RAND_NORMAL;

        cvRand( &rng, state );

        memcpy( kalman->transition_matrix->data.fl, A, sizeof(A));
        cvSetIdentity( kalman->measurement_matrix, cvRealScalar(1) );
        cvSetIdentity( kalman->process_noise_cov, cvRealScalar(1e-5) );
        cvSetIdentity( kalman->measurement_noise_cov, cvRealScalar(1e-1) );
        cvSetIdentity( kalman->error_cov_post, cvRealScalar(1));
        /* choose random initial state */
        cvRand( &rng, kalman->state_post );

        rng.disttype = CV_RAND_NORMAL;

        for(;;)
        {
            #define calc_point(angle)                                      \
                cvPoint( cvRound(img->width/2 + img->width/3*cos(angle)),  \
                         cvRound(img->height/2 - img->width/3*sin(angle)))

            float state_angle = state->data.fl[0];
            CvPoint state_pt = calc_point(state_angle);

            /* predict point position */
            const CvMat* prediction = cvKalmanPredict( kalman, 0 );
            float predict_angle = prediction->data.fl[0];
            CvPoint predict_pt = calc_point(predict_angle);
            float measurement_angle;
            CvPoint measurement_pt;

            cvRandSetRange( &rng,
                            0,
                            sqrt(kalman->measurement_noise_cov->data.fl[0]),
                            0 );
            cvRand( &rng, measurement );

            /* generate measurement */
            cvMatMulAdd( kalman->measurement_matrix, state, measurement, measurement );

            measurement_angle = measurement->data.fl[0];
            measurement_pt = calc_point(measurement_angle);

            /* plot points */
            #define draw_cross( center, color, d )                        \
                cvLine( img, cvPoint( center.x - d, center.y - d ),       \
                             cvPoint( center.x + d, center.y + d ),       \
                             color, 1, 0 );                               \
                cvLine( img, cvPoint( center.x + d, center.y - d ),       \
                             cvPoint( center.x - d, center.y + d ),       \
                             color, 1, 0 )

            cvZero( img );
            draw_cross( state_pt, CV_RGB(255,255,255), 3 );
            draw_cross( measurement_pt, CV_RGB(255,0,0), 3 );
            draw_cross( predict_pt, CV_RGB(0,255,0), 3 );
            cvLine( img, state_pt, predict_pt, CV_RGB(255,255,0), 3, 0 );

            /* adjust Kalman filter state */
            cvKalmanCorrect( kalman, measurement );

            cvRandSetRange( &rng,
                            0,
                            sqrt(kalman->process_noise_cov->data.fl[0]),
                            0 );
            cvRand( &rng, process_noise );
            cvMatMulAdd( kalman->transition_matrix,
                         state,
                         process_noise,
                         state );

            cvShowImage( "Kalman", img );
            code = cvWaitKey( 100 );

            if( code > 0 ) /* break current simulation by pressing a key */
                break;
        }
        if( code == 27 ) /* exit by ESCAPE */
            break;
    }

    return 0;
}
示例#11
0
static int  do_calibration_uc6811(void)
{
	/* calculate the expected point */
    int i, x, y;
    int dx[4], dy[4];
    int tx[4], ty[4];
	int tmp_x, tmp_y;
	x = info.xres;
	y = info.yres;
	int get_width, get_height;
	dx[0] = x / 2;
	dy[0] = y / 10;
	dx[1] = x / 10;
	dy[1] = y / 2;
	dx[2] = x  - x / 10;
	dy[2] = y / 2;
	dx[3] = x / 2;
	dy[3] = y - y / 10;
	
	log_write("enter in do_calibration_uc6811\n");
	log_write("x: %d---y:%d", x, y);
retry:

	for (i = 0; i < 4; i ++) {
		draw_cross(dx[i], dy[i], 0);
		get_input(&tx[i], &ty[i]);
		log_write("get event: %d,%d -> %d,%d\n", tx[i], ty[i], dx[i], dy[i]);
		draw_cross(dx[i], dy[i], 1);
	}
	
	for(i = 0; i < 4; i++) {
		log_write("tx[%d] = %d, ty[%d] = %d\n\r", i, tx[i], i, ty[i]);

	}
	for (i = 0; i < 4; i ++) {
		tx[i] = tx[i] * 800 / MAX_12BIT;
		ty[i] = ty[i] * 480 / MAX_12BIT;
	}
	
	for(i = 0; i < 4; i++) {
		log_write("tx[%d] = %d, ty[%d] = %d\n\r", i, tx[i], i, ty[i]);

	}
	if ( ((tx[0] > ((int)(x/2 + x/10))) || (tx[0] < ((int)(x/2 - x/10))) || (ty[0] > ((int)(y*1/4)))) ||
		  	((ty[1] > ((int)(y/2 + y/10))) || (ty[1] < ((int)(y/2 - y/10))) || (tx[1] > ((int)(x*1/4)))) ||
			((ty[2] > ((int)(y/2 + y/10))) || (ty[2] < ((int)(y/2) - y/10)) || (tx[2] < ((int)(x-x*1/4)))) ||
			((tx[3] > ((int)(x/2 + x/10))) || (tx[3] < ((int)(x/2 - x/10))) || (ty[3] < ((int)(y-y*1/4))))) {
		log_write("Not pass calibration\n");
		return 1;
	}

	get_width = tx[2] - tx[1];
	get_height = ty[3] - ty[0];
	tx[1] -= (int)(get_width/8);
	if (tx[1] < 0){
		tx[1] = 0;
	}	
	tx[2] += (int)(get_width/8);
	if (tx[2] > (x-1)){
		tx[2] = (x-1);
	}
	ty[0] -= (int)(get_height/8);
	if (ty[0] < 0){
		ty[0] = 0;
	}
	ty[3] += (int)(get_height/8);
	if (ty[3] > (y-1)){
		ty[3] = (y-1);
	}
	for(i = 0; i < 4; i++) {
		log_write("tx[%d] = %d, ty[%d] = %d\n\r", i, tx[i], i, ty[i]);

	}
	//modify the max, min data, end 
//	for(i = 0; i < 4; i++) {
//		tmp_x=y-ty[i]; 
//		tmp_y=x-tx[i];
//		tx[i]=tmp_x;
//		ty[i]=tmp_y;
//	}
	//file established when calibration ok 
	

	
	save_conf_uc6811(&(tx[0]), &(ty[0]));
    //write_conf(cal_val);	
	return 0;
// write parameter data into file	

}
示例#12
0
void LineChart::draw_highlight(QPainter& painter, const QPoint& mouse_position) const
{
    draw_point_highlight(painter, mouse_position);
    draw_cross(painter, mouse_position);
}
示例#13
0
static int  do_calibration(void)
{
    int i, x, y;
    int dx[6], dy[6];
    int tx[6], ty[6];
    int delta, delta_x[6], delta_y[6];
	int status=0;
    
    /* calculate the expected point */
    x = info.xres / 4;
    y = info.yres / 4;
    dx[0] = x;
    dy[0] = info.yres / 2;
    dx[1] = info.xres / 2;
    dy[1] = y;
    dx[2] = info.xres - x;
    dy[2] = info.yres - y;
    dx[3] = 400;
    dy[3] = 360;
    dx[4] = 200;
    dy[4] = 360;
    dx[5] = 600;
    dy[5] = 240;

retry:

    for (i = 0; i < 3; i ++) {
		draw_cross(dx[i], dy[i], 0);
		get_input(&tx[i], &ty[i]);
		log_write("get event: %d,%d -> %d,%d\n", tx[i], ty[i], dx[i], dy[i]);
		draw_cross(dx[i], dy[i], 1);
    }

    if( (dx[0] == 0) || (dx[1] == 0) || (dx[2] == 0) || (dy[0] == 0) || (dy[1] == 0) || (dy[2] == 0)){
    		log_write("Calibration Got ZERO Value\n");
		goto retry;
    }

    if( (dy[0] < dy[1]) && (dy[1] - dy[0] < 10)){
		log_write("Point 0 and Point 1 Get too Closed\n");
		goto retry;
    }else if( dy[0] > dx[1]){
		goto retry;
    }

    if( (dy[1] < dy[2]) && (dy[2] - dy[1] < 10))
		goto retry;
    else if( dy[1] > dy[2])
		goto retry;

    /* check ok, calulate the result */
    delta = (tx[0] - tx[2]) * (ty[1] - ty[2])
                - (tx[1] - tx[2]) * (ty[0] - ty[2]);
    delta_x[0] = (dx[0] - dx[2]) * (ty[1] - ty[2])
                - (dx[1] - dx[2]) * (ty[0] - ty[2]);
    delta_x[1] = (tx[0] - tx[2]) * (dx[1] - dx[2])
                - (tx[1] - tx[2]) * (dx[0] - dx[2]);
    delta_x[2] = dx[0] * (tx[1] * ty[2] - tx[2] * ty[1]) -
                dx[1] * (tx[0] * ty[2] - tx[2] * ty[0]) +
                dx[2] * (tx[0] * ty[1] - tx[1] * ty[0]);
    delta_y[0] = (dy[0] - dy[2]) * (ty[1] - ty[2])
                - (dy[1] - dy[2]) * (ty[0] - ty[2]);
    delta_y[1] = (tx[0] - tx[2]) * (dy[1] - dy[2])
                - (tx[1] - tx[2]) * (dy[0] - dy[2]);
    delta_y[2] = dy[0] * (tx[1] * ty[2] - tx[2] * ty[1]) -
                dy[1] * (tx[0] * ty[2] - tx[2] * ty[0]) +
                dy[2] * (tx[0] * ty[1] - tx[1] * ty[0]);

    cal_val[0] = delta_x[0];
    cal_val[1] = delta_x[1];
    cal_val[2] = delta_x[2];
    cal_val[3] = delta_y[0];
    cal_val[4] = delta_y[1];
    cal_val[5] = delta_y[2];
    cal_val[6] = delta;
    
    for (i = 3; i < 6; i ++) {
	draw_cross(dx[i], dy[i], 0);
	get_input(&tx[i], &ty[i]);
	get_calibration_value(&tx[i],&ty[i]);
	if(tx[i] >= dx[i] )
		status = (tx[i] - dx[i] > status) ? tx[i] - dx[i]: status;
	else if(dx[i] > tx[i] ){
		status = (dx[i] - tx[i] > status) ? dx[i] - tx[i]: status;
	}

	if(ty[i] >= dy[i] )
		status = (ty[i] - dy[i] > status) ? ty[i] - dy[i]: status;
	else if(dy[i] > ty[i] ){
		status = (dy[i] - ty[i] > status) ? dy[i] - ty[i]: status;
	}
	log_write("get event: %d,%d -> %d,%d  status=%d\n", tx[i], ty[i], dx[i], dy[i],status);
	draw_cross(dx[i], dy[i], 1);
    }

	if(status > DIFF_VALUE){
		return status;
	}
	save_conf(cal_val);
    write_conf(cal_val);	
	return 0;
}
int main(int argc, char** argv)
{
    const float A[] = { 1, 1, 0, 1 };//状态转移矩阵
    
    IplImage* img = cvCreateImage( cvSize(500,500), 8, 3 );//创建显示所用的图像
    CvKalman* kalman = cvCreateKalman( 2, 1, 0 );//创建cvKalman数据结构,状态向量为2维,观测向量为1维,无激励输入维
    CvMat* state = cvCreateMat( 2, 1, CV_32FC1 ); //(phi, delta_phi) 定义了状态变量
    CvMat* process_noise = cvCreateMat( 2, 1, CV_32FC1 );// 创建两行一列CV_32FC1的单通道浮点型矩阵
    CvMat* measurement = cvCreateMat( 1, 1, CV_32FC1 ); //定义观测变量
    CvRNG rng = cvRNG(-1);//初始化一个随机序列函数
    char code = -1;

    cvZero( measurement );//观测变量矩阵置零
    cvNamedWindow( "Kalman", 1 );

    for(;;)
    {		//用均匀分布或者正态分布的随机数填充输出数组state
        cvRandArr( &rng, state, CV_RAND_NORMAL, cvRealScalar(0), cvRealScalar(0.1) );//状态state
        memcpy( kalman->transition_matrix->data.fl, A, sizeof(A));//初始化状态转移F矩阵
        
        //cvSetIdentity()用法:把数组中除了行数与列数相等以外的所有元素的值都设置为0;行数与列数相等的元素的值都设置为1
        //我们将(第一个前假象阶段的)后验状态初始化为一个随机值
        cvSetIdentity( kalman->measurement_matrix, cvRealScalar(1) );//观测矩阵H
        cvSetIdentity( kalman->process_noise_cov, cvRealScalar(1e-5) );//过程噪声Q
        cvSetIdentity( kalman->measurement_noise_cov, cvRealScalar(1e-1) );//观测噪声R 
        cvSetIdentity( kalman->error_cov_post, cvRealScalar(1));//后验误差协方差
        cvRandArr( &rng, kalman->state_post, CV_RAND_NORMAL, cvRealScalar(0), cvRealScalar(0.1) );//校正状态
        
        //在时机动态系统上开始预测
        
        for(;;)
        {
            #define calc_point(angle)                                      \
                cvPoint( cvRound(img->width/2 + img->width/3*cos(angle)),  \
                         cvRound(img->height/2 - img->width/3*sin(angle))) 

            float state_angle = state->data.fl[0];
            CvPoint state_pt = calc_point(state_angle);
            
            const CvMat* prediction = cvKalmanPredict( kalman, 0 );//计算下一个时间点的预期值,激励项输入为0
            float predict_angle = prediction->data.fl[0];
            CvPoint predict_pt = calc_point(predict_angle);
            
            float measurement_angle;
            CvPoint measurement_pt;

            cvRandArr( &rng, measurement, CV_RAND_NORMAL, cvRealScalar(0),
                       cvRealScalar(sqrt(kalman->measurement_noise_cov->data.fl[0])) );

            /* generate measurement */
            cvMatMulAdd( kalman->measurement_matrix, state, measurement, measurement );
            //cvMatMulAdd(src1,src2,src3,dst)就是实现dist=src1*src2+src3; 

            measurement_angle = measurement->data.fl[0];
            measurement_pt = calc_point(measurement_angle);
            
            //调用Kalman滤波器并赋予其最新的测量值,接下来就是产生过程噪声,然后对状态乘以传递矩阵F完成一次迭代并加上我们产生的过程噪声
            /* plot points */
            #define draw_cross( center, color, d )                                 \
                cvLine( img, cvPoint( center.x - d, center.y - d ),                \
                             cvPoint( center.x + d, center.y + d ), color, 1, CV_AA, 0); \
                cvLine( img, cvPoint( center.x + d, center.y - d ),                \
                             cvPoint( center.x - d, center.y + d ), color, 1, CV_AA, 0 )

            cvZero( img );
            //使用上面宏定义的函数
            draw_cross( state_pt, CV_RGB(255,255,255), 3 );//白色,状态点
            draw_cross( measurement_pt, CV_RGB(255,0,0), 3 );//红色,测量点
            draw_cross( predict_pt, CV_RGB(0,255,0), 3 );//绿色,估计点
            cvLine( img, state_pt, measurement_pt, CV_RGB(255,0,0), 3, CV_AA, 0 );
            cvLine( img, state_pt, predict_pt, CV_RGB(255,255,0), 3, CV_AA, 0 );
            
            cvKalmanCorrect( kalman, measurement );//校正新的测量值

            cvRandArr( &rng, process_noise, CV_RAND_NORMAL, cvRealScalar(0),
                       cvRealScalar(sqrt(kalman->process_noise_cov->data.fl[0])));//设置正态分布过程噪声
            cvMatMulAdd( kalman->transition_matrix, state, process_noise, state );

            cvShowImage( "Kalman", img );
			//当按键按下时,开始新的循环,初始矩阵可能会改变,所以移动速率会改变
            code = (char) cvWaitKey( 100 );
            if( code > 0 )
                break;
        }
        if( code == 27 || code == 'q' || code == 'Q' )
            break;
    }
    
    cvDestroyWindow("Kalman");

    return 0;
}
示例#15
0
static void do_calibration_da9052(int do_calib)
{
    int i, x, y;
    int dx[3], dy[3];
    int tx[3], ty[3];
    int delta, delta_x[3], delta_y[3];
    struct input_absinfo absX, absY;
    
    if (do_calib) {
        /* calculate the expected point */
        x = info.xres / 4;
        y = info.yres / 4;

        dx[0] = x;
        dy[0] = info.yres / 2;
        dx[1] = info.xres / 2;
        dy[1] = y;
        dx[2] = info.xres - x;
        dy[2] = info.yres - y;

        for (i = 0; i < 3; i ++) {
        draw_cross(dx[i], dy[i], 0);
        get_input(&tx[i], &ty[i]);
	        log_write("Received x,y -> Expected x,y\n");
	        log_write("%d,%d -> %d,%d\n",
		        tx[i], ty[i], dx[i], dy[i]);
        draw_cross(dx[i], dy[i], 1);
        }


        /* check ok, calulate the result */
        delta = (tx[0] - tx[2]) * (ty[1] - ty[2])
                    - (tx[1] - tx[2]) * (ty[0] - ty[2]);
        delta_x[0] = (dx[0] - dx[2]) * (ty[1] - ty[2])
                    - (dx[1] - dx[2]) * (ty[0] - ty[2]);
        delta_x[1] = (tx[0] - tx[2]) * (dx[1] - dx[2])
                    - (tx[1] - tx[2]) * (dx[0] - dx[2]);
        delta_x[2] = dx[0] * (tx[1] * ty[2] - tx[2] * ty[1]) -
                    dx[1] * (tx[0] * ty[2] - tx[2] * ty[0]) +
                    dx[2] * (tx[0] * ty[1] - tx[1] * ty[0]);
        delta_y[0] = (dy[0] - dy[2]) * (ty[1] - ty[2])
                    - (dy[1] - dy[2]) * (ty[0] - ty[2]);
        delta_y[1] = (tx[0] - tx[2]) * (dy[1] - dy[2])
                    - (tx[1] - tx[2]) * (dy[0] - dy[2]);
        delta_y[2] = dy[0] * (tx[1] * ty[2] - tx[2] * ty[1]) -
                    dy[1] * (tx[0] * ty[2] - tx[2] * ty[0]) +
                    dy[2] * (tx[0] * ty[1] - tx[1] * ty[0]);

        cal_val[0] = delta_x[0];
        cal_val[1] = delta_x[1];
        cal_val[2] = delta_x[2];
        cal_val[3] = delta_y[0];
        cal_val[4] = delta_y[1];
        cal_val[5] = delta_y[2];
        cal_val[6] = delta;
		

        save_conf(cal_val);
        write_conf(cal_val);
    }

    /* Android input framework expects values based on the absmax.
	 Now that the touchscreen is calibrated set the input maximum
	 according to screen resolution, not the touch sensor resolution */
	if (ioctl(ts_fd, EVIOCGABS(ABS_X), &absX) == -1) {
		log_write("EVIOCGABS( failed\n");
	} else {
		log_write("Modifying x.max:%i -> %i\n", absX.maximum, info.xres);
		absX.maximum = info.xres;
		if (ioctl(ts_fd, EVIOCSABS(ABS_X), &absX) == -1)
			log_write("EVIOCSABS( failed\n");
	}

	if (ioctl(ts_fd, EVIOCGABS(ABS_Y), &absY) == -1) {
		log_write("EVIOCGABS( failed\n");
	} else {
		log_write("Modifying y.max:%i -> %i\n", absY.maximum, info.yres);
		absY.maximum = info.yres;
		if (ioctl(ts_fd, EVIOCSABS(ABS_Y), &absY) == -1)
			log_write("EVIOCSABS( failed\n");
	}
}
示例#16
0
void simulation_render(simulation_t* sim)
{
const color_t red=get_color(255,0,0);
const color_t white=get_color(255,255,255);

orbit_t* current_orbit=&sim->current_spacecraft->orbit;


//Calculate camera position and orientation
sim->camera.position=sim->current_spacecraft->base.position;
//vector_t primary_to_cam=vector_subtract(sim->camera.position,current_orbit->primary->base.position);
sim->camera.rotation=0;//atan2(primary_to_cam.y,primary_to_cam.x)+M_PI_2;



//Plot apoapsis and periapsis
vector_t apoapsis=vector_transform(orbit_get_position(current_orbit,current_orbit->longitude_of_periapsis+M_PI),sim->camera);
vector_t periapsis=vector_transform(orbit_get_position(current_orbit,current_orbit->longitude_of_periapsis),sim->camera);
draw_cross(apoapsis,red);
draw_cross(periapsis,red);
draw_text(apoapsis.x-20,apoapsis.y-20,"Apoapsis");
draw_text(periapsis.x-20,periapsis.y-20,"Periapsis");
//Render arrow on spacecraft
draw_arrow(vector_transform(sim->current_spacecraft->base.position,sim->camera),sim->current_spacecraft->base.rotation+sim->camera.rotation,get_color(0,255,255));
//Show orbit
orbit_show(current_orbit,sim->camera,get_color(0,255,0));

char str[64];
//Show speedup
	if(sim->speedup==1)draw_text(20,650,"Real time");
	else
	{
	sprintf(str,"Fast forward: %dx",sim->speedup);

	draw_text(20,650,str);
	}


int i;
	for(i=0;i<sim->num_celestial_bodies;i++)
	{
	//Show orbit
		if(sim->celestial_bodies[i].orbit.primary!=NULL)
        {
        orbit_show(&sim->celestial_bodies[i].orbit,sim->camera,get_color(255,255,0));
        simulation_render_lagrange_points(sim,&sim->celestial_bodies[i]);
        }
	//Draw planet
	object_render((object_t*)(&sim->celestial_bodies[i]),sim->camera);
	//Show name
	vector_t position=vector_transform(sim->celestial_bodies[i].base.position,sim->camera);
	draw_text(position.x,position.y,sim->celestial_bodies[i].name);
	//Draw sphere of influence
	int j;
	double theta=0;
		for(j=0;j<32;j++)
		{
		vector_t line_start=sim->celestial_bodies[i].base.position;
		line_start.x+=sim->celestial_bodies[i].sphere_of_influence*sin(theta);
		line_start.y+=sim->celestial_bodies[i].sphere_of_influence*cos(theta);
		line_start=vector_transform(line_start,sim->camera);
		theta+=M_PI/32;
		vector_t line_end=sim->celestial_bodies[i].base.position;
		line_end.x+=sim->celestial_bodies[i].sphere_of_influence*sin(theta);
		line_end.y+=sim->celestial_bodies[i].sphere_of_influence*cos(theta);
		line_end=vector_transform(line_end,sim->camera);
		theta+=M_PI/32;
		draw_line(line_start.x,line_start.y,line_end.x,line_end.y,white);
		}
	}
	for(i=0;i<sim->num_spacecraft;i++)
	{
	object_render((object_t*)(&sim->spacecraft[i]),sim->camera);
	}
render_spacecraft_info(sim->current_spacecraft,50,50);
//render_celestial_body_info(sim->current_spacecraft->orbit.primary,500,50);
//render_celestial_body_info(&sim->celestial_bodies[5],950,50);
}
示例#17
0
文件: sdlgui.c 项目: Yamakuzure/PUAE
/**SDLGui_DoDialog
 * Show and process a dialog. Returns the button number that has been
 * pressed or SDLGUI_UNKNOWNEVENT if an unsupported event occured (will be
 * stored in parameter pEventOut).
 */
int32_t SDLGui_DoDialog(SGOBJ *dlg, int/*SDL_Event */*pEventOut)
{
	int32_t obj=0;
	int32_t oldbutton=0;
	int32_t retbutton=0;
	int32_t i, j, b;
	int32_t /*SDL_Event*/ sdlEvent;//SDL_Event sdlEvent;
	SDL_Rect rct;
	Uint32 grey;

	SDL_Rect dlgrect, bgrect;

        grey = 0xC0C0C0FF;

	dlgrect.x = dlg[0].x * sdlgui_fontwidth;
	dlgrect.y = dlg[0].y * sdlgui_fontheight;
	dlgrect.w = dlg[0].w * sdlgui_fontwidth;
	dlgrect.h = dlg[0].h * sdlgui_fontheight;

	bgrect.x = bgrect.y = 0;
	bgrect.w = dlgrect.w;
	bgrect.h = dlgrect.h;



	/* (Re-)draw the dialog */
	SDLGui_DrawDialog(dlg);

	input_gui();

        if(touch!=-1){b=1;boutc=1;}
	else {b=0;boutc=0;}

	i=gmx;j=gmy;

	/* If current object is the scrollbar, and mouse is still down, we can scroll it */
	/* also if the mouse pointer has left the scrollbar */
	if (dlg[current_object].type == SGSCROLLBAR) {
		if (b == 1/*& SDL_BUTTON(1))*/) {
			obj = current_object;
			dlg[obj].state |= SG_MOUSEDOWN;
			oldbutton = obj;
			retbutton = obj;

		}
		else {
			obj = current_object;
			current_object = 0;
			dlg[obj].state &= SG_MOUSEUP;
			//retbutton = obj;
			//oldbutton = obj;
			okold=1;

		}
	}
	else {
		obj = SDLGui_FindObj(dlg, i, j);
		current_object = obj;
		if (obj > 0 && (dlg[obj].flags&SG_TOUCHEXIT) )
		{
			oldbutton = obj;
			if (b ==1/*2*/ /*& SDL_BUTTON(1)*/)
			{
				dlg[obj].state |= SG_SELECTED;
				retbutton = obj;
			}else{
                                dlg[obj].state &= ~SG_SELECTED;
			}
		}
	}

        /* The main loop */
	while (retbutton == 0 && !bQuitProgram)
	{

		input_gui();

		draw_cross(gmx,gmy);

                if(touch!=-1 && okold==0 ){

			okold=1;

			obj = SDLGui_FindObj(dlg, gmx, gmy);
				if (obj>0)
				{
					if (dlg[obj].type==SGBUTTON)
					{
						dlg[obj].state |= SG_SELECTED;
						SDLGui_DrawButton(dlg, obj);


						oldbutton=obj;//dbgoldobj=obj;
					}
                                        if (dlg[obj].type==SGSCROLLBAR)
					{
						dlg[obj].state |= SG_MOUSEDOWN;
						oldbutton=obj;

					}
					if ( dlg[obj].flags&SG_TOUCHEXIT )
					{
						dlg[obj].state |= SG_SELECTED;
						retbutton = obj;
					}
				}

		}
		else if(touch==-1 && okold==1){
			okold=0;

				// It was the left button: Find the object under the mouse cursor /
				obj = SDLGui_FindObj(dlg, gmx, gmy);
				if (obj>0)
				{
					switch (dlg[obj].type)
					{
					 case SGBUTTON:
						if (oldbutton==obj){
							retbutton=obj;}
						break;

					 case SGSCROLLBAR:
 						dlg[obj].state &= SG_MOUSEUP;

						if (oldbutton==obj)
							retbutton=obj;
						break;
					 case SGEDITFIELD:
						SDLGui_EditField(dlg, obj);
						break;
					 case SGRADIOBUT:
						for (i = obj-1; i > 0 && dlg[i].type == SGRADIOBUT; i--)
						{
							dlg[i].state &= ~SG_SELECTED;  // Deselect all radio buttons in this group /

							DrawBoxF((dlg[0].x+dlg[i].x)*fontwidth,(dlg[0].y+dlg[i].y)*fontheight,0,fontwidth ,fontheight,grey);
							SDLGui_DrawRadioButton(dlg, i);

						}
						for (i = obj+1; dlg[i].type == SGRADIOBUT; i++)
						{
							dlg[i].state &= ~SG_SELECTED;  // Deselect all radio buttons in this group /

                                                        DrawBoxF((dlg[0].x+dlg[i].x)*fontwidth,(dlg[0].y+dlg[i].y)*fontheight,0,fontwidth ,fontheight,grey);
							SDLGui_DrawRadioButton(dlg, i);

						}
						dlg[obj].state |= SG_SELECTED;  // Select this radio button

                                                DrawBoxF((dlg[0].x+dlg[obj].x)*fontwidth,(dlg[0].y+dlg[obj].y)*fontheight,0,fontwidth ,fontheight,grey);
						SDLGui_DrawRadioButton(dlg, obj);

						break;
					 case SGCHECKBOX:
						dlg[obj].state ^= SG_SELECTED;

                                                DrawBoxF((dlg[0].x+dlg[obj].x)*fontwidth,(dlg[0].y+dlg[obj].y)*fontheight,0,fontwidth ,fontheight,grey);
						SDLGui_DrawCheckBox(dlg, obj);

						break;
					 case SGPOPUP:
						dlg[obj].state |= SG_SELECTED;
						SDLGui_DrawPopupButton(dlg, obj);

						retbutton=obj;
						break;
					}
				}
				if (oldbutton > 0)
				{
					dlg[oldbutton].state &= ~SG_SELECTED;
					SDLGui_DrawButton(dlg, oldbutton);
					oldbutton = 0;//dbgoldobj=0;
				}
				if (obj >= 0 && (dlg[obj].flags&SG_EXIT))
				{
					if(dlg[obj].type==SGBUTTON)dlg[obj].state &= ~SG_SELECTED;
					retbutton = obj;
				}


		}

		if(retbutton ==0)retbutton = 1;//SG_TOUCHEXIT  ;

	}


	if (retbutton == SDLGUI_QUIT)
		bQuitProgram = true;

	return retbutton;
}
static void
draw_action_volume (GsdMediaKeysWindow *window,
                    cairo_t            *cr)
{
        int window_width;
        int window_height;
        double icon_box_width;
        double icon_box_height;
        double icon_box_x0;
        double icon_box_y0;
        double volume_box_x0;
        double volume_box_y0;
        double volume_box_width;
        double volume_box_height;
        gboolean res;

        gtk_window_get_size (GTK_WINDOW (window), &window_width, &window_height);

        icon_box_width = round (window_width * ICON_SCALE);
        icon_box_height = round (window_height * ICON_SCALE);
        volume_box_width = icon_box_width;
        volume_box_height = round (window_height * 0.05);

        icon_box_x0 = round ((window_width - icon_box_width) / 2);
        icon_box_y0 = round ((window_height - icon_box_height - volume_box_height) / 2 - volume_box_height);
        volume_box_x0 = round (icon_box_x0);
        volume_box_y0 = round (icon_box_height + icon_box_y0) + volume_box_height;

#if 0
        g_message ("icon box: w=%f h=%f _x0=%f _y0=%f",
                   icon_box_width,
                   icon_box_height,
                   icon_box_x0,
                   icon_box_y0);
        g_message ("volume box: w=%f h=%f _x0=%f _y0=%f",
                   volume_box_width,
                   volume_box_height,
                   volume_box_x0,
                   volume_box_y0);
#endif

        res = render_speaker (window,
                              cr,
                              icon_box_x0, icon_box_y0,
                              icon_box_width, icon_box_height);
        if (! res) {
                double speaker_width;
                double speaker_height;
                double speaker_cx;
                double speaker_cy;

                speaker_width = icon_box_width * 0.5;
                speaker_height = icon_box_height * 0.75;
                speaker_cx = icon_box_x0 + speaker_width / 2;
                speaker_cy = icon_box_y0 + speaker_height / 2;

#if 0
                g_message ("speaker box: w=%f h=%f cx=%f cy=%f",
                           speaker_width,
                           speaker_height,
                           speaker_cx,
                           speaker_cy);
#endif

                /* draw speaker symbol */
                draw_speaker (cr, speaker_cx, speaker_cy, speaker_width, speaker_height);

                if (! window->priv->volume_muted) {
                        /* draw sound waves */
                        double wave_x0;
                        double wave_y0;
                        double wave_radius;

                        wave_x0 = window_width / 2;
                        wave_y0 = speaker_cy;
                        wave_radius = icon_box_width / 2;

                        draw_waves (cr, wave_x0, wave_y0, wave_radius, window->priv->volume_level);
                } else {
                        /* draw 'mute' cross */
                        double cross_x0;
                        double cross_y0;
                        double cross_size;

                        cross_size = speaker_width * 3 / 4;
                        cross_x0 = icon_box_x0 + icon_box_width - cross_size;
                        cross_y0 = speaker_cy;

                        draw_cross (cr, cross_x0, cross_y0, cross_size);
                }
        }

        /* draw volume meter */
        draw_volume_boxes (window,
                           cr,
                           (double)window->priv->volume_level / 100.0,
                           volume_box_x0,
                           volume_box_y0,
                           volume_box_width,
                           volume_box_height);
}
int main(int argc, char **argv) {
    if (argc > 2 || (argc == 2 && strcmp(argv[1], "print"))) {
        printf("I expect no command line argument or \"print\" as unique command line argument.\n");
        return EXIT_FAILURE;
    }
    if (!get_input()) {
        printf("Incorrect input.\n");
        return EXIT_FAILURE;
    }
    if (argc == 2) {
        printf("\\documentclass[10pt]{article}\n");
        printf("\\usepackage{tikz}\n");
        printf("\\usetikzlibrary{shapes.misc}\n");
        printf("\\usepackage[margin=0cm]{geometry}\n");
        printf("\\pagestyle{empty}\n");
        printf("\\tikzstyle{every node}=[cross out, draw, red]\n\n");
        printf("\\begin{document}\n\n");
        printf("\\vspace*{\\fill}\n");
        printf("\\begin{center}\n");
        printf("\\begin{tikzpicture}[x=0.5cm, y=-0.5cm, ultra thick, blue]\n");
        rebuild_grid();
        printf("%% Walls\n");
        draw_horizontal_lines();
        draw_vertical_lines();
        rebuild_grid();
        draw_pillars();
        rebuild_grid();
        trans_grid();
        looking_for_access_areas();
        looking_for_inner_points();
        looking_for_dead_ends();
        printf("%% Inner points in accessible cul-de-sacs\n");
        draw_cross();
        looking_for_one_way_paths();
        adjust_grid();
        printf("%% Entry-exit paths without intersections\n");
        draw_horizontal_dash();
        draw_vertical_dash();
        printf("\\end{tikzpicture}\n");
        printf("\\end{center}\n");
        printf("\\vspace*{\\fill}\n\n");
        printf("\\end{document}\n");
        return EXIT_SUCCESS;
    }
    rebuild_grid();
    int num_of_gates = looking_for_gates();
    if (num_of_gates == 0)
        printf("The maze has no gate.\n");
    if (num_of_gates == 1)
        printf("The maze has a single gate.\n");
    if (num_of_gates > 1)
        printf("The maze has %d gates.\n", num_of_gates);
    rebuild_grid();
    int num_of_walls = looking_for_walls();
    if (num_of_walls == 0)
        printf("The maze has no wall.\n");
    if (num_of_walls == 1)
        printf("The maze has walls that are all connected.\n");
    if (num_of_walls > 1)
        printf("The maze has %d sets of walls that are all connected.\n", num_of_walls);
    rebuild_grid();
    trans_grid();
    int num_of_accessible_areas = looking_for_access_areas();
    int num_of_inner_points = looking_for_inner_points();
    if (num_of_inner_points == 0)
        printf("The maze has no inaccessible inner point.\n");
    if (num_of_inner_points == 1)
        printf("The maze has a unique inaccessible inner point.\n");
    if (num_of_inner_points > 1)
        printf("The maze has %d inaccessible inner points.\n", num_of_inner_points);
    if (num_of_accessible_areas == 0)
        printf("The maze has no accessible area.\n");
    if (num_of_accessible_areas == 1)
        printf("The maze has a unique accessible area.\n");
    if (num_of_accessible_areas > 1)
        printf("The maze has %d accessible areas.\n", num_of_accessible_areas);
    int num_of_dead_ends = looking_for_dead_ends();
    if (num_of_dead_ends == 0)
        printf("The maze has no accessible cul-de-sac.\n");
    if (num_of_dead_ends == 1)
        printf("The maze has accessible cul-de-sacs that are all connected.\n");
    if (num_of_dead_ends > 1)
        printf("The maze has %d sets of accessible cul-de-sacs that are all connected.\n", num_of_dead_ends);
    int num_of_paths = looking_for_one_way_paths();
    if (num_of_paths == 0)
        printf("The maze has no entry-exit path with no intersection not to cul-de-sacs.\n");
    if (num_of_paths == 1)
        printf("The maze has a unique entry-exit path with no intersection not to cul-de-sacs.\n");
    if (num_of_paths > 1)
        printf("The maze has %d entry-exit paths with no intersections not to cul-de-sacs.\n", num_of_paths);    
}