/* * ***************************************************************** * * * * * 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 エッジ検出(2点以上)FS0入力版 EMFS0.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_file.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_line_set( int, int, PARADIGM * ); void line_set( int *, int *, int *, int * ); int area_chk( int, int, int, int ); void exec( void ); void em_exec( int, int, int, int ); double u_dabs( double ); void set_file( void ); int xxx_freeze( int ); void cut_space( char *, char * ); 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 #define FACTOR 256 #define FILENAME_SAIZE 12 char grayfile[FILENAME_SAIZE+1]; static char ss[70]; int xs, ys, xe, ye; int diff_p; int level_p; int precise; /* * メイン */ 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" ); diff_p = 50; level_p = 50; precise = 0; /* 入力ビデオ制御 */ 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( ); /*実行*/ 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, "【機能\概要】 EMFS0" ); Lib_chrdisp( 11, 10, "FS0よりロードした濃淡画像ファイルに対して" ); Lib_chrdisp( 11, 12, "Lib_em_edge_posにて濃淡エッジ計測を行うサンプルです。" ); Lib_chrdisp( 11, 14, "ラインの開始点を背景色として白または黒エリアの" ); Lib_chrdisp( 11, 16, "複数個のエッジを計測し座標を表\示します。" ); Lib_chrdisp( 11, 18, "(注)最低2点以上エッジがあるところにライン設定" ); Lib_chrdisp( 11, 20, " してください。" ); } /***********************************************************************/ /* 設定          */ /***********************************************************************/ void set( ) { PVAL value[3]; int pad_level; int no; Lib_set_pad_maxstring( 12 ); /*パッド表示文字数変更*/ pad_level = Lib_view_open(); Lib_view_set_title( pad_level, "設定" ); Lib_view_set_null ( pad_level, 5, 5, "ライン設定" , 0 ); Lib_view_set_uniq_numeral( pad_level, 5, 35, "微分しきい値", diff_p , 1, 99, 1 ); Lib_view_set_uniq_numeral( pad_level, 5, 65, "濃度しきい値", level_p, 1, 99, 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: /*「実行」が選択された */ diff_p = value[1].value_type; level_p = value[2].value_type; break; case 102: /*「取り消し」が選択された */ break; } } Lib_erase_menu( pad_level ); Lib_view_close( pad_level ); Lib_set_pad_maxstring( 10 ); /*パッド表示文字数初期化*/ } /************************************************************************/ /* 計測ラインの設定制御 */ /************************************************************************/ 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 ); if ( NORMAL_RETURN == xxx_freeze( TRANSMIT ) ) { line_set( &xs, &ys, &xe, &ye ); Lib_drawline( xs, ys, xe, ye ); Lib_display_keyinput( 460, 0, "確認" ); Lib_cls( LINE_PLANE, BLACK_COLOR ); Lib_freerun(); } 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( ) { char wwstr[15]; if ( NORMAL_RETURN == xxx_freeze( TRANSMIT ) ) { /*処理ファイル名表示*/ cut_space( grayfile, wwstr ); Lib_chrdisp( 1, 1, wwstr ); em_exec( xs, ys, xe, ye ); /* エッジ メジャー試行 */ } } /************************************************************************/ /* エッジ メジャー試行 */ /************************************************************************/ void em_exec( xs, ys, xe, ye ) int xs, ys, xe, ye; { EM_EDGE_INFO edge_info; double da, db; int error; int i; int time; double xxx,yyy; Lib_drawline( xs, ys, xe, ye ); Lib_strtclk_count(); /*タイマーカウントモードのスタート*/ if ( NORMAL_RETURN == Lib_em_inspection_open() ) /* エッジ検査の開始 */ { if ( NORMAL_RETURN == ( error = Lib_em_edge_pos( xs, ys, xe, ye, diff_p, level_p, &edge_info ) ) ) { time = Lib_readclk_count(); /* 計測結果の表示 */ Lib_sprintf( ss, "エッジ数 : %d", edge_info.num * 2 ); Lib_chrdisp( 1, 1, ss ); if ( ys == ye ) /* 水平方向 */ { da = (double)xs - (double)edge_info.upx[0] /16.0; db = (double)xs - (double)edge_info.downx[0] /16.0; } else /* 垂直方向 */ { da = (double)ys - (double)edge_info.upy[0] /16.0; db = (double)ys - (double)edge_info.downy[0] /16.0; } if ( u_dabs(da) < u_dabs(db) ) { for ( i = 0; i < edge_info.num; i++ ) { xxx = (double)edge_info.upx[i] /16.0; yyy = (double)edge_info.upy[i] /16.0; Lib_sprintf( ss, "( %5.1f, %5.1f )", xxx, yyy ); Lib_chrdisp( 1, 2+i*2, ss ); xxx = (double)edge_info.downx[i] /16.0; yyy = (double)edge_info.downy[i] /16.0; Lib_sprintf( ss, "( %5.1f, %5.1f )", xxx, yyy ); Lib_chrdisp( 1, 2+i*2+1, ss ); } } else { for ( i = 0; i < edge_info.num; i++ ) { xxx = (double)edge_info.downx[i] /16.0; yyy = (double)edge_info.downy[i] /16.0; Lib_sprintf( ss, "( %5.1f, %5.1f )", xxx, yyy ); Lib_chrdisp( 1, 2+i*2, ss ); xxx = (double)edge_info.upx[i] /16.0; yyy = (double)edge_info.upy[i] /16.0; Lib_sprintf( ss, "( %5.1f, %5.1f )", xxx, yyy ); Lib_chrdisp( 1, 2+i*2+1, ss ); } } Lib_em_edge_disp(); /* エッジ位置を表示する */ time = ( time * 8138 ) / 10000; Lib_sprintf( ss, "エッジ計測 %4d(ms)", time ); Lib_chrdisp( 1, 30, ss ); Lib_display_keyinput( 460, 0, "確認" ); } else if ( OUT_OF_SPACE == error ) Lib_display_message( 120, 200, "エラー", "最大計測数を越えました。" ); Lib_em_inspection_close(); /* エッジ検査の終了 */ } else Lib_display_message( 120, 200, "エラー", "エッジ計測のワークメモリが確保できません。" ); Lib_cls( ( LINE_PLANE | CHAR_PLANE ), BLACK_COLOR ); Lib_freerun(); } /************************************************************************/ /* 絶対値取得(double型)                    */ /************************************************************************/ double u_dabs( in ) double in; /* 入力:符号付き数値 */ { double out; if ( in < 0.0 ) out = -in; else out = in; return( out ); } /************************************************************************/ /* ファイル名設定 */ /************************************************************************/ void set_file( void ) { int no; int pad_level; PVAL value[1]; pad_level = Lib_view_open(); Lib_view_set_title( pad_level, "ファイル設定" ); Lib_view_set_uniq_string ( pad_level, 5, 5, "GRAY FILE", grayfile, 12, 0 ); 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 ) ) ) { switch( no ) { case 101: /*「実行」が選択された */ strcpy( grayfile, value[0].string_type ); break; case 102: /*「取り消し」が選択された */ break; } } 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++; } }