/* * ***************************************************************** * * * * * 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 実寸ワーク幅計測(エッジ検出)      SCALE_E.C */ /*[作成者]H.Yagi */ /* 目的: 関数: 履歴: Ver 1.0 97/09/01 注記:m_menu.hをインクルードして下さい。 m_menu.c及びm_note.cをリンクして下さい。 */ /* * Include compiler runtime library */ #include #include /* * Include CSC90X library */ #include "f_stdlib.h" #include "f_time.h" #include "f_gui.h" #include "f_stdio.h" #include "f_graph.h" #include "f_image.h" #include "f_pinf.h" #include "f_video.h" #include "f_system.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 set( void ); void pdm_set_line( int, int, PARADIGM * ); void pdm_calc_josu( int, int, PARADIGM * ); void line_set( int *, int *, int *, int * ); int area_chk( int, int, int, int ); void exec( int, int, int, int ); void em_exec( int, int, int, int, double * ); extern int message_note( void ); /* * メニュー項目 */ #define LANG_N 2 #define MAIN_MENU_N 4 static const char *str_main_menu[MAIN_MENU_N][LANG_N] = { { " SET ", " 設 定 " }, { " EXEC ", " 実 行 " }, { " PROC3 ", " 処理3 " }, { " PROC4 ", " 処理4 " } }; #define INIT_CUR_POS_X 255 #define INIT_CUR_POS_Y 239 #define FACTOR 256 typedef enum { POINT2_MODE, POINT4_MODE } dummy1; int pad_level; PVAL value[10]; static char ss[70]; int exs, eys, exe, eye; /* エッジ検出ライン位置 */ int line_reg_flg; /* ライン設定完了フラグ */ int calc_josu_flg; /* 乗数算出完了フラグ */ double scale_josu; /* スケール変換乗数 */ int real_kijun_distance; /* 基準距離(実寸) 単位:ミクロン */ int edge_mode; /* 計測モード 0=2点モード、 1=4点モード */ /* * メイン */ 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; edge_mode = POINT2_MODE; real_kijun_distance = 1000; /*1mm*/ line_reg_flg = OFF; /* 入力ビデオ制御 */ 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(); /*設定*/ 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 ); exec( exs, eys, exe, eye ); /*実行*/ 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; /* 終了 */ } } } } /* * メインメニュー表示 */ static 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 ); } /* * ヘルプ表示 */ static void disp_help( void ) { Lib_chrdisp( 10, 8, "【機能\概要】 SCALE_E" ); Lib_chrdisp( 11, 10, "任意の2点または4点の位置をエッジ検出により" ); Lib_chrdisp( 11, 12, "求め、その距離とパラメータの基準実寸からスケ" ); Lib_chrdisp( 11, 14, "ール変換乗数を算出し、[実行]でワークの実寸" ); Lib_chrdisp( 11, 16, "距離を計測します。" ); Lib_chrdisp( 11, 18, "4点モードの場合、左側2点の中心と右側2点の" ); Lib_chrdisp( 11, 20, "中心との距離で処理します。" ); } /***********************************************************************/ /* 設定          */ /***********************************************************************/ static char *select_mode[2] = { "2点モード", "4点モード" }; void set() { int rtn; int i; int width, height; Lib_get_standard_key_size( &width, &height ); pad_level = Lib_view_open(); Lib_view_set_title( pad_level, "設定" ); value[0].select_type = edge_mode; value[2].value_type = (long)real_kijun_distance; /* メニュー登録 */ i = 0; Lib_view_set_select ( pad_level, 5, 5, "計測モード", value[i].select_type, 2, select_mode, i ); i++; Lib_view_set_null ( pad_level, 5, 35, "ライン設定", i ); i++; Lib_view_set_uniq_numeral( pad_level, 5, 65, "基準実寸" , value[i].value_type, 1, 100000, i ); i++; Lib_view_set_comment ( pad_level, width*2+30, 65, "μm", i ); i++; Lib_view_set_null ( pad_level, 5, 95, "乗数算出" , i ); i++; Lib_set_paradigm( pad_level, 1, START_TIMING, pdm_set_line ); Lib_set_paradigm( pad_level, 4, START_TIMING, pdm_calc_josu ); Lib_view_set_size( pad_level, 50, 80, 5, 5 ); Lib_draw_menu( pad_level ); if( ERROR_RETURN != ( rtn = Lib_process_menu( pad_level, value ) ) ) { if ( PAD_EXECUTE == rtn ) { edge_mode = value[0].select_type; real_kijun_distance = (int)value[2].value_type; } } else { Lib_printf( "pad_level err\r\n" ); } Lib_erase_menu( pad_level ); Lib_view_close( pad_level ); } /***********************************************************************/ /* ライン設定制御           */ /***********************************************************************/ void pdm_set_line( Timing, Numb, val ) int Timing; int Numb; PARADIGM val[]; { line_set( &exs, &eys, &exe, &eye ); /* ライン設定 */ Lib_drawline( exs, eys, exe, eye ); line_reg_flg = ON; } /***********************************************************************/ /* 計測ラインの設定          */ /***********************************************************************/ void line_set( xs, ys, xe, ye ) int *xs; /* 出力:始点x */ int *ys; /* 出力:始点y */ int *xe; /* 出力:終点x */ int *ye; /* 出力:終点y */ { /*注釈: 始点から水平or垂直方向にライン設定します*/ int sts, area; int xpos, ypos; int s_xpos, s_ypos; *xs = *ys = *xe = *ye = 0; xpos = s_xpos = 255; ypos = s_ypos = 240; Lib_draw_cursor( xpos, ypos ); Lib_chrdisp( 1, 30, "始点の指定" ); for (;;) { sts = 0; sts = Lib_see_current_position( &xpos, &ypos ); /* マウス位置読みとり */ if ( CURSOR_EXECUTE == sts ) { *xs = xpos; *ys = ypos; break; } if ( xpos != s_xpos || ypos != s_ypos ) { s_xpos = xpos; s_ypos = ypos; Lib_move_cursor( xpos, ypos ); } } xpos = s_xpos = *xs; ypos = s_ypos = *ys; Lib_draw_cursor( xpos, ypos ); Lib_chrdisp( 1, 30, "終点の指定" ); for (;;) { sts = 0; sts = Lib_see_current_position( &xpos, &ypos ); /* マウス位置読みとり */ if ( xpos != s_xpos || ypos != s_ypos ) { area = area_chk( *xs, *ys, xpos, ypos ); if ( area == 2 || area == 4 ) { Lib_erasline( *xs, *ys, *xe, *ye ); Lib_drawline( *xs, *ys, xpos, *ys ); Lib_move_cursor( xpos, *ys ); *xe = xpos; *ye = *ys; s_xpos = xpos; s_ypos = ypos; } else if ( area == 1 || area == 3 ) { Lib_erasline( *xs, *ys, *xe, *ye ); Lib_drawline( *xs, *ys, *xs, ypos ); Lib_move_cursor( *xs, ypos ); *xe = *xs; *ye = ypos; s_xpos = xpos; s_ypos = ypos; } } if ( CURSOR_EXECUTE == sts ) { Lib_chrdisp( 1, 30, " " ); break; } } } /***********************************************************************/ /* 4方向エリア判別          */ /***********************************************************************/ /* 基点 :kx, ky */ /* ワーク点:wx, wy */ /*(戻り値) 0 : 基点とワーク点は同位置 */ /* 1 : 基点から見て上方向にワーク点がある */ /* 2 : 基点から見て左方向にワーク点がある */ /* 3 : 基点から見て下方向にワーク点がある */ /* 4 : 基点から見て右方向にワーク点がある */ int area_chk( kx, ky, wx, wy ) int kx, ky; /* 入力:基点座標 */ int wx, wy; /* 入力:ワーク座標 */ { if ( wx == kx && wy == ky ) return( 0 ); if ( wx > kx ) /* 右半分側にある */ { if ( wy < ky ) /* 右上側にある */ { if ( ( wx - kx ) > ( ky - wy ) ) return( 4 ); else return( 1 ); } else /* 右下側にある */ { if ( ( wx - kx ) > ( wy - ky ) ) return( 4 ); else return( 3 ); } } else /* 左半分側にある */ { if ( wy < ky ) /* 左上側にある */ { if ( ( kx - wx ) > ( ky - wy ) ) return( 2 ); else return( 1 ); } else /* 左下側にある */ { if ( ( kx - wx ) > ( wy - ky ) ) return( 2 ); else return( 3 ); } } } /***********************************************************************/ /* 乗数算出       */ /***********************************************************************/ void pdm_calc_josu( Timing, Numb, val ) int Timing; int Numb; PARADIGM val[]; { double distance; Lib_erase_menu( pad_level ); if ( ON == line_reg_flg ) { Lib_memory_clear( LINE_PLANE | CHAR_PLANE ); Lib_freeze( TRANSMIT ); /* エッジ検出( 2箇所分 ) */ em_exec( exs, eys, exe, eye, &distance ); /* 乗数算出 */ scale_josu = (double)value[2].value_type / distance; /* 結果表示 */ Lib_sprintf( ss,"距離(画素) : %.2lf", distance ); Lib_chrdisp( 1, 26, ss ); Lib_sprintf( ss,"スケール乗数 : %.3lf", scale_josu ); Lib_chrdisp( 1, 28, ss ); Lib_display_keyinput( 430, 0, " 確認 " ); Lib_memory_clear( LINE_PLANE | CHAR_PLANE ); calc_josu_flg = ON; } else { Lib_display_message( 70, 200, "エラー", "ライン設定がされてません" ); } Lib_draw_menu( pad_level ); Lib_freerun(); } /************************************************************************/ /* 2点間のエッジ幅計測 */ /************************************************************************/ void em_exec( xs, ys, xe, ye, dist ) int xs, ys, xe, ye; double *dist; { static EM_INSPECTION inspection; /* エッジ測定結果を格納する構造体 */ static EM_EDGE_INFO edge_info; static double da, db; int edge_mode; edge_mode = value[0].select_type; Lib_drawline( xs, ys, xe, ye ); if ( NORMAL_RETURN == Lib_em_inspection_open() ) /* エッジ検査の開始 */ { Lib_em_inspection( xs, ys, xe, ye, 50, 50, 1, 1000, 1000, FACTOR, &inspection ); /* エッジ測定 */ Lib_em_edge_pos( xs, ys, xe, ye, 50, 50, &edge_info ); /* エッジ位置の計測 */ Lib_em_edge_disp(); /* エッジ位置を表示する */ if ( POINT2_MODE == edge_mode ) { if ( 2 == edge_info.num * 2 ) /*検出エッジは2点か?*/ *dist = ( double )inspection.width[0] / 16.0; else Lib_display_message( 70, 200, "エラー", "エッジ数が2点でない" ); } else { if ( 4 == edge_info.num * 2 ) /*検出エッジは4点か?*/ { if ( ys == ye ) /* 水平方向 */ { da = ( (double)edge_info.upx[0]/16.0 + (double)edge_info.downx[0]/16.0 ) / 2.0; db = ( (double)edge_info.upx[1]/16.0 + (double)edge_info.downx[1]/16.0 ) / 2.0; } else /* 垂直方向 */ { da = ( (double)edge_info.upy[0]/16.0 + (double)edge_info.downy[0]/16.0 ) / 2.0; db = ( (double)edge_info.upy[1]/16.0 + (double)edge_info.downy[1]/16.0 ) / 2.0; } if ( da < db ) *dist = db - da; else *dist = da - db; } else Lib_display_message( 70, 200, "エラー", "エッジ数が4点でない" ); } Lib_em_inspection_close(); /* エッジ検査の終了 */ } } /************************************************************************/ /* 実行 */ /************************************************************************/ void exec( xs, ys, xe, ye ) int xs, ys, xe, ye; { double distance; double real_distance; if ( ON == calc_josu_flg ) { Lib_memory_clear( LINE_PLANE | CHAR_PLANE ); Lib_freeze( TRANSMIT ); /* エッジ検出( 2箇所分 ) */ em_exec( exs, eys, exe, eye, &distance ); /* スケール変換 */ real_distance = distance * scale_josu; /* 結果表示 */ Lib_sprintf( ss,"距離(画素): %.2lf", distance ); Lib_chrdisp( 1, 26, ss ); Lib_sprintf( ss,"距離(実寸): %.1lfμm", real_distance ); Lib_chrdisp( 1, 28, ss ); Lib_display_keyinput( 460, 0, "確認" ); Lib_cls( ( LINE_PLANE | CHAR_PLANE ), BLACK_COLOR ); } else { Lib_display_message( 70, 200, "エラー", "乗数算出がされてません" ); } Lib_freerun(); }