/* * ***************************************************************** * * * * * 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 手動センサボールによる平均濃度検査 GRAYBALL.C */ /*[作成者]H.Yagi */ /* 目的: 関数: 履歴: Ver 1.0 98/04/07 Ver 1.1 99/04/07 グレイメモリを解放していないバグを修正 S.Masuda Ver 1.2 99/11/09 前処理フィルタが反映されていないバグを修正 Y.Hori Ver 1.3 99/11/16 実行時に検査円を画面の端に設定されるとハングアップする不具合を修正。 注記: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_math.h" #include "f_file.h" #include "f_filter.h" #include "f_gray.h" /* * Include CSC90X common local */ #include "m_menu.h" /* * プロトタイプ宣言 */ void main( void ); void main_menu_disp( void ); void disp_help( void ); void param_set( void ); void exec_kijun( int, int, PARADIGM * ); void exec( void ); int d4i5_d( double ); void draw_batu( int, int, int ); void average( int, int, int, int, int * ); void set_file( int, int, PARADIGM * ); void 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 ", " 設 定 " }, { " EXEC ", " 実 行 " }, { " PROC3 ", " 処理3 " }, { " PROC4 ", " 処理4 " } }; #define INIT_CUR_POS_X 255 #define INIT_CUR_POS_Y 239 #define FILENAME_SAIZE 12 char grayfile[FILENAME_SAIZE+1]; int pad_level; int pad_level_ptn; PVAL value[10]; static char ss[70]; int sts; int xs, ys, xe, ye; int time; int no; int cx, cy; static int master_ave; int gray_mem_no; int kensa_r; /*検査半径 */ int kensa_pitch; /*検査角ピッチ */ int shikii; /*許容値レベル±*/ int fs0_image_sw; /*FS0画像入力スイッチ*/ int pre_code; /*前処理 */ /* * メイン */ 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; kensa_r = 5; /*検査半径 */ shikii = 15; /*許容値レベル±*/ fs0_image_sw = OFF; strcpy( grayfile, "GRAYMEM1.DAT" ); /*FS0画像ファイル名*/ pre_code = 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 ); gray_mem_no = Lib_alloc_gray_memory(); /* グレイメモリの確保 */ if ( -1 == gray_mem_no ) { Lib_display_message( 70, 200, "グレイメモリ アロケーションエラー", "処理打ち切り" ); return; } else Lib_gray_memory_cls( gray_mem_no ); /* メニュー制御 */ 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 ); param_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(); /*実行*/ 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; /* 終了 */ } } } Lib_free_gray_memory(gray_mem_no); /* グレイメモリの解放 */ } /* * メインメニュー表示 */ 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, "【機能\概要】 GRAYBALL" ); Lib_chrdisp( 11, 10, "手動でセンサボールを操作し平均濃度を検査します。" ); Lib_chrdisp( 11, 12, "○任意に下記の前処理がかけられます" ); Lib_chrdisp( 11, 14, " 最大値/最小値/鮮鋭化/ソ\ーベル微分" ); Lib_chrdisp( 11, 16, "○FS0画像入力も可です。" ); Lib_chrdisp( 11, 18, "まず基準設定してください。" ); } /*********************************************************************/ /*  設定                         */ /*********************************************************************/ static char *select_pre_code[7] = { "なし     ", "最大値    ", "ソ\ーベル X ", "最小値    ", "ソ\ーベル Y ", "鮮鋭化    ", "ソ\ーベル XY" }; void param_set() { int i; Lib_freerun(); Lib_set_pad_maxstring( 14 ); pad_level = Lib_view_open(); Lib_view_set_title( pad_level, "設定" ); value[0].value_type = kensa_r; value[2].value_type = shikii; value[3].on_off_type = fs0_image_sw; value[4].select_type = pre_code; i = 0; Lib_view_set_uniq_numeral( pad_level, 5, 5, "検査半径" , value[i].value_type, 1, 50, 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, 0, 100, i ); i++; Lib_view_set_uniq_alter ( pad_level, 5, 95, "FS0画像", value[i].on_off_type, i ); i++; Lib_view_set_select ( pad_level, 5,125, "前処理" , value[i].select_type, 7, select_pre_code, i ); i++; Lib_set_paradigm( pad_level, 1, START_TIMING, exec_kijun ); Lib_set_paradigm( pad_level, 3, END_TIMING, set_file ); Lib_view_set_size( pad_level, 50, 80, 5, 5 ); Lib_draw_menu( pad_level ); if( PAD_EXECUTE == Lib_process_menu( pad_level, value ) ) { kensa_r = value[0].value_type; shikii = value[2].value_type; fs0_image_sw = value[3].on_off_type; pre_code = value[4].select_type; } Lib_erase_menu( pad_level ); Lib_view_close( pad_level ); Lib_set_pad_maxstring( 10 ); } /*********************************************************************/ /* 基準レベル計測                 */ /*********************************************************************/ void exec_kijun( Timing, Numb, val ) int Timing; int Numb; PARADIGM val[]; { int mem_no; int sts; int xpos; int ypos; int s_xpos; int s_ypos; int r; Lib_erase_menu( pad_level ); r = value[0].value_type; if ( OFF == value[3].on_off_type ) Lib_freeze( NOT_TRANSMIT ); else xxx_freeze( TRANSMIT ); if ( 0 == value[4].select_type ) /*なし*/ Lib_gray_memory_move( 0, gray_mem_no, 0xff ); else if ( 1 == value[4].select_type ) Lib_max_filter( 0, gray_mem_no ); /*最大値*/ else if ( 2 == value[4].select_type ) Lib_sobel( 0, gray_mem_no, X_DIRECTION ); /*ソーベル X*/ else if ( 3 == value[4].select_type ) Lib_min_filter( 0, gray_mem_no ); /*最小値*/ else if ( 4 == value[4].select_type ) Lib_sobel( 0, gray_mem_no, Y_DIRECTION ); /*ソーベル Y*/ else if ( 5 == value[4].select_type ) Lib_sharp( 0, gray_mem_no ); /*鮮鋭化*/ else if ( 6 == value[4].select_type ) Lib_sobel( 0, gray_mem_no, XY_DIRECTION ); /*ソーベル XY*/ Lib_xvideo_transmit( gray_mem_no, GRAY_PLANE ); xpos = INIT_CUR_POS_X; ypos = 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 ); Lib_erascircle( s_xpos, s_ypos, r ); Lib_drawcircle( xpos, ypos, r ); /* 位置表示 */ s_xpos = xpos; s_ypos = ypos; } /* 処理振り分け */ if ( CURSOR_EXECUTE == sts ) { mem_no = gray_mem_no; average( mem_no, xpos, ypos, r, &master_ave ); Lib_sprintf( ss, "基準濃度 = %d", master_ave ); Lib_chrdisp( 1, 30, ss ); break; } } Lib_display_keyinput( 430, 0, " 確認 " ); Lib_memory_clear( LINE_PLANE | CHAR_PLANE ); if ( OFF == value[3].on_off_type /*&& 0 == value[4].select_type*/ ) Lib_freerun(); Lib_draw_menu( pad_level ); } /*********************************************************************/ /* 実行                 */ /*********************************************************************/ void exec() { int mem_no; int ave; int sts; int xpos; int ypos; int s_xpos; int s_ypos; int fx_size,fy_size; Lib_memory_clear( LINE_PLANE | CHAR_PLANE ); fx_size = Lib_get_fx_size(); fy_size = Lib_get_fy_size(); if ( OFF == fs0_image_sw ) Lib_freeze( NOT_TRANSMIT ); else xxx_freeze( TRANSMIT ); if ( 0 == pre_code ) /*なし*/ Lib_gray_memory_move( 0, gray_mem_no, 0xff ); else if ( 1 == pre_code ) Lib_max_filter( 0, gray_mem_no ); /*最大値*/ else if ( 2 == pre_code ) Lib_sobel( 0, gray_mem_no, X_DIRECTION ); /*ソーベル X*/ else if ( 3 == pre_code ) Lib_min_filter( 0, gray_mem_no ); /*最小値*/ else if ( 4 == pre_code ) Lib_sobel( 0, gray_mem_no, Y_DIRECTION ); /*ソーベル Y*/ else if ( 5 == pre_code ) Lib_sharp( 0, gray_mem_no ); /*鮮鋭化*/ else if ( 6 == pre_code ) Lib_sobel( 0, gray_mem_no, XY_DIRECTION ); /*ソーベル XY*/ Lib_xvideo_transmit( gray_mem_no, GRAY_PLANE ); xpos = INIT_CUR_POS_X; ypos = INIT_CUR_POS_Y; for (;;) { sts = 0; /* マウス位置読みとり */ sts = Lib_see_current_position( &xpos, &ypos ); if ( s_xpos != xpos || s_ypos != ypos ) { /* カーソル移動範囲の制限 */ if ( xpos < kensa_r ) xpos = kensa_r; else if ( ( fx_size - 1 - kensa_r ) < xpos ) xpos = fx_size - 1 - kensa_r; if ( ypos < kensa_r ) ypos = kensa_r; else if ( ( fy_size - 1 - kensa_r ) < ypos ) ypos = fy_size - 1 - kensa_r; /* マウス表示位置移動 */ Lib_memory_clear( LINE_PLANE | CHAR_PLANE ); Lib_move_cursor( xpos, ypos ); Lib_erascircle( s_xpos, s_ypos, kensa_r ); Lib_drawcircle( xpos, ypos, kensa_r ); /* 位置表示 */ mem_no = gray_mem_no; average( mem_no, xpos, ypos, kensa_r, &ave ); Lib_sprintf( ss, "測定濃度 = %d", ave ); Lib_chrdisp( 1, 28, ss ); Lib_sprintf( ss, "正常範囲 = %d±%d ( %d〜%d )", master_ave, shikii, master_ave - shikii, master_ave + shikii ); Lib_chrdisp( 1, 30, ss ); /* しきい値チェック */ if ( (ave < master_ave - shikii) || (master_ave + shikii < ave) ) { draw_batu( xpos, ypos, kensa_r-2 ); Lib_kanjishift( REVERSE_FONT, DOUBLE_FONT, 0, 450, 450, "×" ); } else Lib_kanjishift( REVERSE_FONT, DOUBLE_FONT, 0, 450, 450, "○" ); s_xpos = xpos; s_ypos = ypos; } if ( CURSOR_CANCEL == sts ) { break; } } Lib_memory_clear( LINE_PLANE | CHAR_PLANE ); if ( OFF == fs0_image_sw/* && 0 == pre_code*/ ) Lib_freerun(); } /***********************************************************************/ /* 入力数値(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 ); } /************************************************************************/ /* ×マーク表示 */ /************************************************************************/ void draw_batu( x, y, size ) int x, y; /* 入力:表示位置 */ int size; { Lib_drawline( x-size, y-size, x+size, y+size ); Lib_drawline( x-size, y+size, x+size, y-size ); } /************************************************************************/ /* 平均濃度算出 */ /************************************************************************/ void average( mem_no, ix, iy, kensa_r, ave ) int mem_no, ix, iy, kensa_r; int *ave; { register int i, a; char *base; char *wbase; char *wb2; int xs, ys, xe, ye; int s_xs; int windx; int windy; int sum; int cnt; xs = ix - kensa_r; ys = iy - kensa_r; xe = ix + kensa_r; ye = iy + kensa_r; s_xs = xs; windx = xe - xs + 1; /* ウィンド枠x画素数 */ windy = ye - ys + 1; /* ウィンド枠y画素数 */ base = Lib_adrs_gray_memory( mem_no ); wbase = base + 512*ys + xs; sum = cnt = 0; for ( i=0; i