/* * ***************************************************************** * * * * * 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 エッジ検出(1点のみ)FS0入力版 EPOSFS0.C */ /*[作成者]H.Yagi */ /* 目的: 関数: 履歴: Ver 1.0 97/08/15 注記: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_gray.h" #include "f_file.h" #include "xx.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_line_set( int, int, PARADIGM * ); void line_set( int *, int *, int *, int * ); int area_chk( int, int, int, int ); void exec( int, int, int, int ); void draw_cros( int, int ); void set_file( void ); int xxx_freeze( int ); void cut_space( char *, char * ); int d4i5_d( 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 ", " 設 定 " }, { " SET FILE ", "ファイル名選択" }, { " EXEC ", " 実 行 " }, { " PROC4 ", " 処理4 " } }; #define INIT_CUR_POS_X 255 #define INIT_CUR_POS_Y 239 static char *select_mode[2] = { "平均データ", "生データ " }; static char ss[70]; int xs, ys, xe, ye; int edge_mode; int edge_minmaxdiff; #define FILENAME_SAIZE 12 char grayfile[FILENAME_SAIZE+1]; /* * メイン */ 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; strcpy( grayfile, "GRAYMEM1.DAT" ); edge_mode = 1; edge_minmaxdiff = 10; /* 入力ビデオ制御 */ 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 ); set_file( ); /*ファイル名設定*/ main_menu_disp(); } else if ( xpos > MENU_3_XS && xpos < MENU_3_XE && ypos > MENU_3_YS && ypos < MENU_3_YE ) { Lib_memory_clear( LINE_PLANE | CHAR_PLANE ); exec( xs, ys, xe, ye ); /*実行*/ 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 *)str_main_menu[2][iLanguage], (char *)NULL ); } /* * ヘルプ表示 */ static void disp_help( void ) { Lib_chrdisp( 10, 8, "【機能\概要】 EPOSFS0" ); Lib_chrdisp( 11, 10, "FS0よりロードした濃淡画像ファイルに対して" ); Lib_chrdisp( 11, 12, "Lib_edge_pos_xyにてエッジを1点検出する" ); Lib_chrdisp( 11, 14, "サンプルです。" ); } /***********************************************************************/ /* 設定           */ /***********************************************************************/ void set( ) { PVAL value[3]; int pad_level; int no; if ( NORMAL_RETURN == xxx_freeze( TRANSMIT ) ) { pad_level = Lib_view_open(); Lib_view_set_title( pad_level, "設定" ); Lib_view_set_null ( pad_level, 5, 5, "ライン設定", 0 ); Lib_view_set_select ( pad_level, 5, 35, "モード" , edge_mode, 2, select_mode, 1 ); Lib_view_set_uniq_numeral( pad_level, 5, 65, "しきい値" , edge_minmaxdiff, 0, 255, 2 ); Lib_set_paradigm( pad_level, 0, START_TIMING, pdm_line_set ); Lib_view_set_size( pad_level, 80, 80, 5, 5 ); Lib_draw_menu( pad_level ); if( ERROR_RETURN != ( no = Lib_process_menu( pad_level, value ) ) ) { switch( no ) { case 101: /*「実行」が選択された */ edge_mode = value[1].select_type; edge_minmaxdiff = value[2].value_type; break; case 102: /*「取り消し」が選択された */ break; } } Lib_erase_menu( pad_level ); Lib_view_close( pad_level ); } Lib_freerun(); } /************************************************************************/ /* 計測ラインの設定制御 */ /************************************************************************/ void pdm_line_set( timing, numb, val ) int timing; int numb; PARADIGM val[]; { int idc; idc = Lib_shelter_plane( 0, 0, (Lib_get_dx_size() - 1), (Lib_get_dy_size() - 1), CHAR_PLANE ); line_set( &xs, &ys, &xe, &ye ); Lib_drawline( xs, ys, xe, ye ); Lib_display_keyinput( 460, 0, "確認" ); Lib_cls( LINE_PLANE, BLACK_COLOR ); Lib_recover_plane( idc ); } /***********************************************************************/ /* 計測ラインの設定          */ /***********************************************************************/ 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 exec( xs, ys, xe, ye ) int xs, ys, xe, ye; { int xx, yy; int time; double dx, dy; if ( NORMAL_RETURN == xxx_freeze( TRANSMIT ) ) { Lib_drawline( xs, ys, xe, ye ); Lib_strtclk_count(); /*タイマーカウントモードのスタート*/ if( NORMAL_RETURN == Lib_edge_pos_xy( xs, ys, xe, ye, edge_mode, edge_minmaxdiff, CURRENT_MEMORY, &xx, &yy )) { time = Lib_readclk_count(); dx = (double)xx / 16.0; dy = (double)yy / 16.0; draw_cros( d4i5_d( dx ), d4i5_d( dy ) ); Lib_sprintf( ss, "エッジ座標:X=%.1lf, Y=%.1lf", dx, dy ); Lib_chrdisp( 1, 29, ss ); time = ( time * 8138 ) / 10000; Lib_sprintf( ss, "エッジ計測 %4d(ms)", time ); Lib_chrdisp( 1, 30, ss ); Lib_display_keyinput( 460, 0, "確認" ); } else Lib_display_message( 400, 450, "エラー", "エッジ検出エラー!"); } Lib_cls( ( LINE_PLANE | CHAR_PLANE ), BLACK_COLOR ); Lib_freerun(); } /************************************************************************/ /* クロスマーク表示 */ /************************************************************************/ void draw_cros( x, y ) int x, y; { Lib_drawline( x-5, y, x+5, y ); Lib_drawline( x, y-5, x, y+5 ); } /************************************************************************/ /* ファイル名設定 */ /************************************************************************/ void set_file( ) { int i; int no; int pad_level; PVAL value[2]; pad_level = Lib_view_open(); Lib_view_set_title( pad_level, "ファイル設定" ); strcpy( value[0].string_type, grayfile ); i = 0; Lib_view_set_uniq_string ( pad_level, 5, 5, "GRAY FILE", value[i].string_type, 12, i ); i++; Lib_view_set_size( pad_level, 50, 80, 5, 5 ); Lib_draw_menu( pad_level ); if( ERROR_RETURN != ( no = Lib_process_menu( pad_level, value ) ) ) { strcpy( grayfile, value[0].string_type ); } else { Lib_chrdisp( 1, 28, "pad err" ); } Lib_erase_menu( pad_level ); Lib_view_close( pad_level ); } /************************************************************************/ /* フリーズ */ /************************************************************************/ int xxx_freeze( flag ) int flag; /* バッファ転送フラグ */ { char wwstr[13]; char infile[20]; int status; Lib_freeze( NOT_TRANSMIT ); Lib_chrdisp( 1, 30, "画像ロード中..." ); cut_space( grayfile, wwstr ); Lib_sprintf( infile, "\\FS0\\%s", wwstr ); if ( NORMAL_RETURN == Lib_load_gray_memory( CURRENT_MEMORY, infile ) ) { Lib_chrdisp( 1, 30, " " ); if ( ON == flag ) Lib_xvideo_transmit( 0, GRAY_PLANE ); /* モニタ表示 */ status = NORMAL_RETURN; } else { Lib_chrdisp( 1, 30, " " ); Lib_display_message( 70, 200, "fload_err", infile ); status = ERROR_RETURN; } return( status ); } /*********************************************************************/ /* スペース除去                        */ /*********************************************************************/ void cut_space( instr, otstr ) char *instr; char *otstr; { for(;;) { if ( ' ' != *instr ) *otstr++ = *instr; if ( 0x00 == *instr ) break; instr++; } } /***********************************************************************/ /* 入力数値(double)の4捨5入した数値(int)を返す */ /***********************************************************************/ int d4i5_d( double in ) { int out; if ( in >= 0.0 ) out = (int)( in + 0.5 ); else out = (int)( in - 0.5 ); return( out ); }