/* * ***************************************************************** * * * * * Copyright (c) Fast Corporation, 1997 * * * * * * All Rights Reserved. Unpublished rights reserved under * * * the copyright laws of the Japan. * * * * * * The software contained on this media is proprietary to * * * and embodies the confidential technology of Fast * * * Corporation. Possession, use, duplication or * * * dissemination of the software and media is authorized only * * * pursuant to a valid written license from Fast Corporation. * * * * * ***************************************************************** */ /* CSC90X エッジ計測サンプル 90xboxe.c */ /*[作成者]A.Sekimori */ /* 目的: 関数: 履歴: Ver 1.0 97/09/18 注記:m_menu.hをインクルードして下さい。 m_menu.c及びm_note.cをリンクして下さい。 */ /* Include compiler runtime library */ #include #include /* Include CSC90X library */ #include "f_stdio.h" /* 標準入出力 */ #include "f_stdlib.h" /* メモリ領域割当 */ #include "f_gui.h" /* GUI */ #include "f_graph.h" /* モニタ表示 */ #include "f_pinf.h" /* システムパラメータ */ #include "f_video.h" /* ビデオ入力制御 */ #include "f_image.h" /* フレームバッファ */ #include "f_time.h" /* 時刻サービス */ #include "f_system.h" /* システム制御 */ #include "f_math.h" /* 数学演算 */ #include "f_em.h" /* 濃淡エッジ計測 */ /* Include CSC90X common local */ #include "m_menu.h" /* プロトタイプ宣言 */ void main( void ); void main_menu_disp( void ); void disp_help( void ); void data_init( void ); void set_menu( void ); void set_window( void ); void set_pit_menu( void ); void set_pos( void ); void set_parameter( void ); void em( void ); void set_cursor( void ); void calc_win_center( void ); void draw_window( int ); void set_pit( int, int, int, PARADIGM * ); void cross_mark( int, int, int ); extern int message_note( void ); /* メニュー項目 */ #define LANG_N 2 #define MAIN_MENU_N 2 static const char *str_main_menu[MAIN_MENU_N][LANG_N] = { { " SET ", " 設 定 " }, { " EXECUTE ", " 実 行 " } }; #define INIT_CUR_POS_X 255 #define INIT_CUR_POS_Y 239 /* 設定・メニュー */ #define S_KEY1_XS 1 /* キー「ウィンドウ」の表示位置(X) */ #define S_KEY_YS 1 /* キーの表示位置(Y) */ #define S_KEY_SIZE_Y 25 /* キーのサイズ(縦) */ #define S_STR 10 /* キーの表示文字数 */ #define DIFF_MIN 1 #define DIFF_MAX 99 #define LEVEL_MIN 1 #define LEVEL_MAX 99 #define PIT_MIN 1 #define PIT_MAX 50 static const char *set_menu_key[5] = { "ウィンドウ", " ピッチ ", " 計測位置 ", "パラメータ", " 終 了 " }; /* 設定・メニュー・キー・タイトルの定義 */ typedef struct { int diff_p; int level_p; } PARAM; typedef struct { int box_sx; int box_sy; int box_ex; int box_ey; int size_x; int size_y; int pit_t; int pit_y; int cx; int cy; } WINDOW; static PARAM pm; static WINDOW win; static int pad_level_e; /* メイン */ void main( void ) { int sts; int xpos; int ypos; int s_xpos; int s_ypos; /* 初期メッセージ表示 */ if( NORMAL_RETURN != message_note() ) return; /* パラメタ初期化 */ xpos = INIT_CUR_POS_X; ypos = INIT_CUR_POS_Y; s_xpos = INIT_CUR_POS_X; s_ypos = INIT_CUR_POS_Y; data_init(); /* 入力ビデオ制御 */ Lib_input_video_control( GRAY_PLANE ); /* ビデオ出力表示項目制御 */ Lib_display_control( GRAY_PLANE | LINE_PLANE | CHAR_PLANE ); /* ビデオ表示項目クリア */ Lib_memory_clear( LINE_PLANE | CHAR_PLANE ); /* カーソル初期化 */ Lib_init_cursor(); /* メインメニューの表示 */ main_menu_disp(); /* マウスカーソルの表示 */ Lib_draw_cursor( INIT_CUR_POS_X, INIT_CUR_POS_Y ); /* メニュー制御 */ for (;;) { sts = 0; /* マウス位置読みとり */ sts = Lib_see_current_position( &xpos, &ypos ); if ( s_xpos != xpos || s_ypos != ypos ) { /* マウス表示位置移動 */ Lib_move_cursor( xpos, ypos ); s_xpos = xpos; s_ypos = ypos; } /* 処理振り分け */ if( CURSOR_EXECUTE == sts ) { if ( xpos > MENU_1_XS && xpos < MENU_1_XE && ypos > MENU_1_YS && ypos < MENU_1_YE ) { Lib_memory_clear( LINE_PLANE | CHAR_PLANE ); /* 「設定」が選択された */ set_menu(); Lib_memory_clear( LINE_PLANE | CHAR_PLANE ); main_menu_disp(); } else if ( xpos > MENU_2_XS && xpos < MENU_2_XE && ypos > MENU_2_YS && ypos < MENU_2_YE ) { Lib_memory_clear( LINE_PLANE | CHAR_PLANE ); /* 「計測」が選択された */ em(); Lib_memory_clear( LINE_PLANE | CHAR_PLANE ); main_menu_disp(); } else if ( xpos > MENU_H_XS && xpos < MENU_H_XE && ypos > MENU_H_YS && ypos < MENU_H_YE ) { Lib_memory_clear( LINE_PLANE | CHAR_PLANE ); disp_help(); /* ヘルプ */ main_menu_disp(); } else if ( xpos > MENU_E_XS && xpos < MENU_E_XE && ypos > MENU_E_YS && ypos < MENU_E_YE ) { break; /* 終了 */ } } } } /* メインメニュー表示 */ void main_menu_disp( void ) { int iLanguage; /* 日本語/英語表示文字列切替情報取得 */ iLanguage = Lib_get_disp_language(); /* 整列キー表示 -> ( m_menu.c ) */ SUB_menu_disp4he( (char *)str_main_menu[0][iLanguage], (char *)str_main_menu[1][iLanguage], (char *)NULL, (char *)NULL ); } /* ヘルプ表示 */ void disp_help( void ) { Lib_chrdisp( 6, 8, "【機能\概要】 90XBOXE" ); Lib_chrdisp( 7, 10, "このサンプルは四角形の4辺のエッジを" ); Lib_chrdisp( 7, 11, "検出するソ\フトです。" ); Lib_chrdisp( 7, 13, "【設定】 各種設定を行います。" ); Lib_chrdisp( 7, 15, " 【ウィンドウ】 対象物を囲います。" ); Lib_chrdisp( 7, 17, " 【ピッチ】 計測ラインのピッチを設定します。" ); Lib_chrdisp( 7, 19, " 【計測位置】計測ラインの位置を設定します。" ); Lib_chrdisp( 7, 21, " 【パラメータ】 計測パラメータを設定します。" ); Lib_chrdisp( 7, 23, "【実行】 計測を実行します。" ); } /***** データ初期化 *****/ void data_init( void ) { win.box_sx = 100; win.box_sy = 100; win.size_x = 311; win.size_y = 279; win.box_ex = 411; win.box_ey = 379; win.pit_t = 10; win.pit_y = 10; win.cx = 255; win.cy = 239; pm.diff_p = 50; pm.level_p = 50; } /***** 設定メニュー *****/ void set_menu( void ) { int width,height; int cpx,cpy; int s_key2_xs,s_key3_xs,s_key4_xs,s_key5_xs; int s_key1_xe,s_key2_xe,s_key3_xe,s_key4_xe,s_key5_xe; Lib_cls( ( LINE_PLANE | CHAR_PLANE ), BLACK_COLOR ); Lib_look_current_position( &cpx, &cpy ); Lib_move_cursor( cpx, cpy ); /* カーソル初期表示 */ for ( ; ; ) { /* メニュー・キー初期表示 */ Lib_display_key( S_KEY1_XS, S_KEY_YS, ( char * )set_menu_key[0], 1 ); Lib_get_key_size( S_STR, &width, &height ); s_key1_xe = S_KEY1_XS + width - 1; s_key2_xs = S_KEY1_XS + width + 1; Lib_display_key( s_key2_xs, S_KEY_YS, ( char * )set_menu_key[1], 1 ); Lib_get_key_size( S_STR, &width, &height ); s_key2_xe = s_key2_xs + width - 1; s_key3_xs = s_key2_xs + width + 1; Lib_display_key( s_key3_xs, S_KEY_YS, ( char * )set_menu_key[2], 1 ); Lib_get_key_size( S_STR, &width, &height ); s_key3_xe = s_key3_xs + width - 1; s_key4_xs = s_key3_xs + width + 1; Lib_display_key( s_key4_xs, S_KEY_YS, ( char * )set_menu_key[3], 1 ); Lib_get_key_size( S_STR, &width, &height ); s_key4_xe = s_key4_xs + width - 1; s_key5_xs = s_key4_xs + width + 1; Lib_display_key( s_key5_xs, S_KEY_YS, ( char * )set_menu_key[4], 1 ); Lib_get_key_size( S_STR, &width, &height ); s_key5_xe = s_key5_xs + width - 1; /* トラック・ボールの左ボタンクリック? */ if ( CURSOR_EXECUTE == Lib_get_current_position( &cpx, &cpy ) ) { if ( S_KEY1_XS <= cpx && cpx <= s_key1_xe && cpy < S_KEY_SIZE_Y ) { /* 「ウィンドウ」が選択された */ Lib_display_key( S_KEY1_XS, S_KEY_YS, ( char * )set_menu_key[0], 2 ); set_window(); } else if ( s_key2_xs <= cpx && cpx <= s_key2_xe && cpy < S_KEY_SIZE_Y ) { /* 「ピッチ」が選択された */ Lib_display_key( s_key2_xs, S_KEY_YS, ( char * )set_menu_key[1], 2 ); set_pit_menu(); } else if ( s_key3_xs <= cpx && cpx <= s_key3_xe && cpy < S_KEY_SIZE_Y ) { /* 「計測位置」が選択された */ Lib_display_key( s_key3_xs, S_KEY_YS, ( char * )set_menu_key[2], 2 ); set_pos(); } else if ( s_key4_xs <= cpx && cpx <= s_key4_xe && cpy < S_KEY_SIZE_Y ) { /* 「パラメータ」が選択された */ Lib_display_key( s_key4_xs, S_KEY_YS, ( char * )set_menu_key[3], 2 ); set_parameter(); } else if ( s_key5_xs <= cpx && cpx <= s_key5_xe && cpy < S_KEY_SIZE_Y ) { /* 「終了」が選択された */ Lib_display_key( s_key5_xs, S_KEY_YS, ( char * )set_menu_key[4], 2 ); break; } } } Lib_cls( ( LINE_PLANE | CHAR_PLANE ), BLACK_COLOR ); } /***** 計測パラメータ設定 *****/ void set_parameter( void ) { PVAL value[2]; int pad_level_p; int no; Lib_cls( ( LINE_PLANE | CHAR_PLANE ), BLACK_COLOR ); pad_level_p = Lib_view_open(); /* パッドのオープン */ Lib_view_set_title( pad_level_p, "しきい値" ); /* パッドタイトルの登録 */ /* 各属性メニューの登録 */ Lib_view_set_uniq_numeral( pad_level_p, 5, 5, "微分シキイ値", pm.diff_p , DIFF_MIN , DIFF_MAX , 0 ); Lib_view_set_uniq_numeral( pad_level_p, 5, 35, "濃度シキイ値", pm.level_p, LEVEL_MIN, LEVEL_MAX, 1 ); /* パッドの表示位置の登録 */ Lib_view_set_size( pad_level_p, 100, 130, 15, 5 ); Lib_draw_menu( pad_level_p ); /* メニューパッドの表示 */ if ( ERROR_RETURN != ( no = Lib_process_menu( pad_level_p, value ) ) ) /* メニュー値の取得 */ { switch( no ) { case 101: /*「実行」が選択された */ pm.diff_p = value[0].value_type; pm.level_p = value[1].value_type; break; case 102: /*「取り消し」が選択された */ break; } } Lib_erase_menu( pad_level_p ); /* メニューパッドの消去 */ Lib_view_close( pad_level_p ); /* パッドのクローズ */ } /***** ウィンドウ設定 *****/ void set_window( void ) { PVAL value_w[2]; int no; int pad_level_w; Lib_cls( ( LINE_PLANE | CHAR_PLANE ), BLACK_COLOR ); pad_level_w = Lib_view_open(); /* パッドのオープン */ Lib_view_set_title( pad_level_w, "ウィンドウ" ); /* パッドタイトルの登録 */ /* 各属性メニューの登録 */ Lib_view_set_box( pad_level_w, 5, 5, "始点" , win.box_sx, win.box_sy, 3, 1, 0 ); Lib_view_set_box( pad_level_w, 5, 35, "サイズ", win.size_x, win.size_y, 3, 0, 1 ); /* パッドの表示位置の登録 */ Lib_view_set_size( pad_level_w, 10, 400, 15, 5 ); Lib_draw_menu( pad_level_w ); /* メニューパッドの表示 */ if ( ERROR_RETURN != ( no = Lib_process_menu( pad_level_w, value_w ) ) ) /* メニュー値の取得 */ { switch( no ) { case 101: /*「実行」が選択された */ win.box_sx = value_w[0].box_type.x; win.box_sy = value_w[0].box_type.y; win.size_x = value_w[1].box_type.x; win.size_y = value_w[1].box_type.y; break; case 102: /*「取り消し」が選択された */ break; } } Lib_erase_menu( pad_level_w ); /* メニューパッドの消去 */ Lib_view_close( pad_level_w ); /* パッドのクローズ */ /* すべてのラインをウィンドウ内に調整 */ if ( win.size_y < win.pit_y * 8 ) win.pit_y = win.size_y / 8; calc_win_center(); } /***** ウィンドウの中心を求める *****/ void calc_win_center( void ) { int w_xs,w_ys; w_xs = win.box_sx; w_ys = win.box_sy; win.box_ex = win.box_sx + win.size_x - 1; win.box_ey = win.box_sy + win.size_y - 1; win.cx = ( w_xs + win.box_ex ) / 2; win.cy = ( w_ys + win.box_ey ) / 2; } /***** ピッチ設定 *****/ void set_pit_menu( void ) { PVAL value_e[2]; int no; int pit_max_t,pit_max_y; int len_r,len_l,len_u,len_d; Lib_cls( ( LINE_PLANE | CHAR_PLANE ), BLACK_COLOR ); len_r = win.cx - win.box_sx; len_l = win.box_ex - win.cx; len_u = win.cy - win.box_sy; len_d = win.box_ey - win.cy; if ( len_r <= len_l ) pit_max_t = len_r / 4; else pit_max_t = len_l / 4; if ( len_u <= len_d ) pit_max_y = len_u / 4; else pit_max_y = len_d / 4; pad_level_e = Lib_view_open(); /* パッドのオープン */ Lib_view_set_title( pad_level_e, "ピッチ" ); /* パッドタイトルの登録 */ /* 各属性メニューの登録 */ Lib_view_set_uniq_numeral( pad_level_e, 5, 5, "縦ラインピッチ", win.pit_t, PIT_MIN, pit_max_t, 0 ); Lib_view_set_uniq_numeral( pad_level_e, 5, 35, "横ラインピッチ", win.pit_y, PIT_MIN, pit_max_y, 1 ); Lib_set_xparadigm( pad_level_e, 0, WHOLE_TIMING, set_pit ); Lib_set_xparadigm( pad_level_e, 1, WHOLE_TIMING, set_pit ); /* パッドの表示位置の登録 */ Lib_view_set_size( pad_level_e, 100, 130, 15, 5 ); Lib_draw_menu( pad_level_e ); /* メニューパッドの表示 */ if ( ERROR_RETURN != ( no = Lib_process_menu( pad_level_e, value_e ) ) ) /* メニュー値の取得 */ { switch( no ) { case 101: /*「実行」が選択された */ win.pit_t = value_e[0].value_type; win.pit_y = value_e[1].value_type; break; case 102: /*「取り消し」が選択された */ break; } } Lib_erase_menu( pad_level_e ); /* メニューパッドの消去 */ Lib_view_close( pad_level_e ); /* パッドのクローズ */ Lib_cls( ( LINE_PLANE | CHAR_PLANE ), BLACK_COLOR ); } /***** 設定されたウィンドウを描く *****/ void draw_window( menu_no ) int menu_no; { int ct; int xs,xe,ys,ye; Lib_box( win.box_sx, win.box_sy, win.box_ex, win.box_ey, SOLID_LINE ); if ( 0 == menu_no ) { xs = win.cx; ys = win.box_sy; xe = win.cx; ye = win.box_ey; } else if ( 1 == menu_no ) { xs = win.box_sx; ys = win.cy; xe = win.box_ex; ye = win.cy; } Lib_drawline( xs, ys, xe, ye ); for ( ct = 0; ct < 4; ct++ ) { if ( 0 == menu_no ) { xs += win.pit_t; xe += win.pit_t; } else if ( 1 == menu_no ) { ys += win.pit_y; ye += win.pit_y; } Lib_drawline( xs, ys, xe, ye ); } if ( 0 == menu_no ) { xs = win.cx; ys = win.box_sy; xe = win.cx; ye = win.box_ey; } else if ( 1 == menu_no ) { xs = win.box_sx; ys = win.cy; xe = win.box_ex; ye = win.cy; } for ( ct = 0; ct < 4; ct++ ) { if ( 0 == menu_no ) { xs -= win.pit_t; xe -= win.pit_t; } else if ( 1 == menu_no ) { ys -= win.pit_y; ye -= win.pit_y; } Lib_drawline( xs, ys, xe, ye ); } } /***** ピッチ設定(パラダイム) *****/ void set_pit( menu_no, Timing, Numb, val ) int menu_no; int Timing; int Numb; PARADIGM val[]; { int ct; int xs,xe,ys,ye; if ( Timing == START_TIMING ) { Lib_erase_menu( pad_level_e ); Lib_cls( ( LINE_PLANE | CHAR_PLANE ), BLACK_COLOR ); draw_window( menu_no ); } else if ( Timing == END_TIMING ) { Lib_cls( ( LINE_PLANE | CHAR_PLANE ), BLACK_COLOR ); Lib_draw_menu( pad_level_e ); } else if ( Timing == PROCESS_TIMING ) { Lib_cls( LINE_PLANE, BLACK_COLOR ); Lib_box( win.box_sx, win.box_sy, win.box_ex, win.box_ey, SOLID_LINE ); if ( 0 == menu_no ) { xs = win.cx; ys = win.box_sy; xe = win.cx; ye = win.box_ey; } else if ( 1 == menu_no ) { xs = win.box_sx; ys = win.cy; xe = win.box_ex; ye = win.cy; } Lib_drawline( xs, ys, xe, ye ); for ( ct = 0; ct < 4; ct++ ) { if ( 0 == menu_no ) { xs += (int)val[0].long_type; xe += (int)val[0].long_type; } else if ( 1 == menu_no ) { ys += (int)val[0].long_type; ye += (int)val[0].long_type; } Lib_drawline( xs, ys, xe, ye ); } if ( 0 == menu_no ) { xs = win.cx; ys = win.box_sy; xe = win.cx; ye = win.box_ey; } else if ( 1 == menu_no ) { xs = win.box_sx; ys = win.cy; xe = win.box_ex; ye = win.cy; } for ( ct = 0; ct < 4; ct++ ) { if ( 0 == menu_no ) { xs -= (int)val[0].long_type; xe -= (int)val[0].long_type; } else if ( 1 == menu_no ) { ys -= (int)val[0].long_type; ye -= (int)val[0].long_type; } Lib_drawline( xs, ys, xe, ye ); } } } /***** 位置設定 *****/ void set_pos( void ) { int status; int ct,ct2; int xs,xe,ys,ye; int a_x,a_y,b_x,b_y; int lrx,llx,luy,ldy; Lib_cls( ( LINE_PLANE | CHAR_PLANE ), BLACK_COLOR ); a_x = win.cx; a_y = win.cy; b_x = 0; b_y = 0; lrx = win.box_sx + win.pit_t * 4; llx = win.box_ex - win.pit_t * 4; luy = win.box_sy + win.pit_y * 4; ldy = win.box_ey - win.pit_y * 4; for ( ; ; ) { Lib_box( win.box_sx, win.box_sy, win.box_ex, win.box_ey, SOLID_LINE ); status = Lib_see_current_position( &a_x, &a_y ); if ( a_x <= lrx ) a_x = lrx; else if ( llx <= a_x ) a_x = llx; if ( a_y <= luy ) a_y = luy; else if ( ldy <= a_y ) a_y = ldy; if ( b_x != a_x || b_y != a_y ) /* カーソルは移動したか? */ { Lib_cls( LINE_PLANE, BLACK_COLOR ); Lib_move_cursor( a_x, a_y ); b_x = a_x; /* カーソルの位置情報の更新(X座標)*/ b_y = a_y; /* カーソルの位置情報の更新(Y座標)*/ } else { b_x = a_x; /* カーソルの位置情報の更新(X座標)*/ b_y = a_y; /* カーソルの位置情報の更新(Y座標)*/ } if ( CURSOR_EXECUTE == status ) { win.cx = a_x; win.cy = a_y; break; } for ( ct = 1; ct <= 2; ct++ ) { if ( 1 == ct ) { xs = a_x; ys = win.box_sy; xe = a_x; ye = win.box_ey; } else if ( 2 == ct ) { xs = win.box_sx; ys = a_y; xe = win.box_ex; ye = a_y; } Lib_drawline( xs, ys, xe, ye ); for ( ct2 = 0; ct2 < 4; ct2++ ) { if ( 1 == ct ) { xs += win.pit_t; xe += win.pit_t; } else if ( 2 == ct ) { ys += win.pit_y; ye += win.pit_y; } Lib_drawline( xs, ys, xe, ye ); } if ( 1 == ct ) { xs = a_x; ys = win.box_sy; xe = a_x; ye = win.box_ey; } else if ( 2 == ct ) { xs = win.box_sx; ys = a_y; xe = win.box_ex; ye = a_y; } for ( ct2 = 0; ct2 < 4; ct2++ ) { if ( 1 == ct ) { xs -= win.pit_t; xe -= win.pit_t; } else if ( 2 == ct ) { ys -= win.pit_y; ye -= win.pit_y; } Lib_drawline( xs, ys, xe, ye ); } } } Lib_cls( ( LINE_PLANE | CHAR_PLANE ), BLACK_COLOR ); } /***** エッジ計測 *****/ void em( void ) { EM_EDGE_INFO er; int ct,ct2,i; int status; int xs,xe,ys,ye; double edge_x,edge_y; Lib_em_inspection_open(); Lib_cls( ( LINE_PLANE | CHAR_PLANE ), BLACK_COLOR ); Lib_strtclk_count(); Lib_freeze( TRANSMIT ); for ( ct = 1; ct <= 2; ct++ ) { if ( 1 == ct ) { xs = win.cx - win.pit_t * 4; ys = win.box_sy; xe = win.cx - win.pit_t * 4; ye = win.box_ey; } else if ( 2 == ct ) { xs = win.box_sx; ys = win.cy - win.pit_y * 4; xe = win.box_ex; ye = win.cy - win.pit_y * 4; } for ( ct2 = 0; ct2 < 9; ct2++ ) { if ( NORMAL_RETURN == ( status = Lib_em_edge_pos( xs, ys, xe, ye, pm.diff_p, pm.level_p, &er ) ) ) { for ( i = 0; i < er.num; i++ ) { edge_x = (double)er.upx[i] / 16.0; edge_y = (double)er.upy[i] / 16.0; cross_mark( (int)edge_x, (int)edge_y, 3 ); edge_x = (double)er.downx[i] / 16.0; edge_y = (double)er.downy[i] / 16.0; cross_mark( (int)edge_x, (int)edge_y, 3 ); } } else if( OUT_OF_SPACE == status ) Lib_display_comment( 0, 479, "エラー:最大計測数を越えました" ); if ( 1 == ct ) { xs += win.pit_t; xe += win.pit_t; } else if ( 2 == ct ) { ys += win.pit_y; ye += win.pit_y; } } } Lib_time_disp( 0, 0 ); Lib_display_keyinput( 460, 0, "確認" ); Lib_freerun(); Lib_cls( ( LINE_PLANE | CHAR_PLANE ), BLACK_COLOR ); Lib_em_inspection_close(); } /***** 十字マーク *****/ void cross_mark( x, y, length ) int x; int y; int length; { Lib_drawline( x - length, y, x + length, y ); Lib_drawline( x, y - length, x, y + length ); }