/* * ***************************************************************** * * * * * 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 円周エッジの角度計測 CEDANGLE.C */ /*[作成者]H.Yagi */ /* 目的: 関数: 履歴: Ver 1.0 97/08/14 Ver 1.1 99/03/25 Lib_calclineの第2引数coodの型がPOINTでなく POINT_Tになっていた。 Ver 1.2 99/10/28 Lib_arc_boxの終点半径を0→10へ変更。 注記:m_menu.h、xx.hをインクルードして下さい。 m_menu.c、m_note.c、xxcomm.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_gray.h" #include "f_calip.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 param_set( void ); void pdm_set_center( int, int, PARADIGM * ); void pdm_set_circle_edge( int, int, PARADIGM * ); void pdm_set_circle( int, int, PARADIGM * ); void pdm_enhance( int, int, PARADIGM * ); void exec( void ); void disp_abc_line( double, double, double ); void draw_calc_line( double, double ); void disp_cnt( void ); void pdm_enhance_ab( int, int, int, PARADIGM * ); void pdm_disp_enhance( int, int, PARADIGM * ); 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 ", " 実 行 " }, { " DISP ", " 表\ 示 " }, { " PROC4 ", " 処理4 " } }; #define INIT_CUR_POS_X 255 #define INIT_CUR_POS_Y 239 #define MAX_EDGE_NO 100 static CPNT_T tCent; static CPNT_T cir_edge[MAX_EDGE_NO]; int pad_level; int pad_level_enhance; int pad_level_circle_edge; static PVAL value[5]; static PVAL value_enhance[5]; static PVAL value_circle_edge[5]; static char ss[70]; int sts; int time; int no; int gray_mem_no; static struct Gray_conv gconv; int cx, cy; /*メーター中心 */ int edge_r; /*半径 */ int edge_sta_angle; /*円弧始点角度 */ int edge_end_angle; /*円弧終点角度 */ int edge_shikii; /*エッジしきい値*/ int enhance_sw; int enhance_a; int enhance_b; int disp_sw_ciredg; /*円周エッジ位置表示スイッチ*/ int disp_sw_calcline; /*近似直線 表示スイッチ*/ int disp_sw_data; /*角度データ 表示スイッチ*/ /* * メイン */ 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; cx = 255; /*メーター中心x*/ cy = 240; /*メーター中心y*/ edge_r = 50; /*半径 */ edge_sta_angle = 0; /*円弧始点角度 */ edge_end_angle = 3600; /*円弧終点角度 */ edge_shikii = 50; /*エッジしきい値*/ disp_sw_ciredg = ON; /*円周エッジ位置表示スイッチ*/ disp_sw_calcline = OFF; /*近似直線 表示スイッチ*/ disp_sw_data = ON; /*角度データ 表示スイッチ*/ enhance_sw = OFF; /*エンハンス要否*/ enhance_a = 0; enhance_b = 100; gconv.Shape = SLOPE_TYPE; gconv.Aparam = 40; gconv.Bparam = 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 ); Lib_clp_open( ); /*キャリパオープン*/ /* グレイメモリのアロケーション */ 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(); /*設定*/ 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 ); exec(); /*実行*/ 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 ); disp_cnt(); /*表示*/ 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 ); Lib_clp_close( ); /*キャリパクローズ*/ } /* * メインメニュー表示 */ 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, "【機能\概要】 CEDANGLE" ); Lib_chrdisp( 11, 10, "円周エッジの角度計測サンプル" ); Lib_chrdisp( 11, 14, " ○角度は3時方向を0度とした時計まわりの" ); Lib_chrdisp( 11, 16, "  角度です。" ); Lib_chrdisp( 11, 18, " ○任意にエンハンスがかけられます。" ); } /*********************************************************************/ /*  設定                         */ /*********************************************************************/ void param_set() { int i; pad_level = Lib_view_open(); Lib_view_set_title( pad_level, "設定" ); value[0].point_type.x = cx; value[0].point_type.y = cy; value[2].on_off_type = enhance_sw; i = 0; Lib_view_set_point ( pad_level, 5, 5, "円中心", value[i].point_type.x, value[i].point_type.y, 3, i ); i++; Lib_view_set_null ( pad_level, 5, 35, "円周エッジ", i ); i++; Lib_view_set_uniq_alter ( pad_level, 5, 65, "エンハンス", value[i].on_off_type, i ); i++; Lib_set_paradigm( pad_level, 0, WHOLE_TIMING, pdm_set_center ); Lib_set_paradigm( pad_level, 1, START_TIMING, pdm_set_circle_edge ); Lib_set_paradigm( pad_level, 2, END_TIMING, pdm_enhance ); Lib_view_set_size( pad_level, 50, 50, 5, 5 ); Lib_draw_menu( pad_level ); if( PAD_EXECUTE == Lib_process_menu( pad_level, value ) ) { cx = value[0].point_type.x; cy = value[0].point_type.y; enhance_sw = value[2].on_off_type; } Lib_erase_menu( pad_level ); Lib_view_close( pad_level ); } /*********************************************************************/ /*  エンハンス                         */ /*********************************************************************/ void pdm_enhance( Timing, Numb, val ) int Timing; int Numb; PARADIGM val[]; { int i; if ( ON == value[2].on_off_type ) { Lib_erase_menu( pad_level ); pad_level_enhance = Lib_view_open(); Lib_view_set_title( pad_level_enhance, "エンハンス" ); value_enhance[0].value_type = (long)enhance_a; value_enhance[1].value_type = (long)enhance_b; i = 0; Lib_view_set_uniq_numeral( pad_level_enhance, 5, 5, "エンハンス A", value_enhance[i].value_type, 0, 255, i ); i++; Lib_view_set_uniq_numeral( pad_level_enhance, 5, 35, "エンハンス B", value_enhance[i].value_type, 0, 255, i ); i++; Lib_view_set_null ( pad_level_enhance, 5, 65, "エンハンス画像", i ); i++; Lib_set_xparadigm( pad_level_enhance, 0, WHOLE_TIMING, pdm_enhance_ab ); Lib_set_xparadigm( pad_level_enhance, 1, WHOLE_TIMING, pdm_enhance_ab ); Lib_set_paradigm ( pad_level_enhance, 2, START_TIMING, pdm_disp_enhance ); Lib_view_set_size( pad_level_enhance, 80, 80, 30, 5 ); Lib_draw_menu( pad_level_enhance ); if( PAD_EXECUTE == Lib_process_menu( pad_level_enhance, value_enhance ) ) { enhance_a = (int)value_enhance[0].value_type; enhance_b = (int)value_enhance[1].value_type; } Lib_erase_menu( pad_level_enhance ); Lib_view_close( pad_level_enhance ); Lib_draw_menu( pad_level ); } } /*********************************************************************/ /* メーター中心マーク表示             */ /*********************************************************************/ void pdm_set_center( Timing, Numb, val ) int Timing; int Numb; PARADIGM val[]; { Lib_cls( LINE_PLANE, 0 ); XXdraw_cross( val[0].int_type, val[1].int_type, 8, GRAPH_DRAW ); } /************************************************************************/ /* エンハンスパラメータ設定 */ /************************************************************************/ void pdm_enhance_ab( menu_no, timing, numb, val ) int menu_no; int timing; int numb; PARADIGM val[]; { if ( timing == START_TIMING ) { Lib_erase_menu( pad_level_enhance ); Lib_freeze( NOT_TRANSMIT ); } if ( timing == END_TIMING ) { Lib_freerun(); Lib_memory_clear( LINE_PLANE | CHAR_PLANE ); Lib_draw_menu( pad_level_enhance ); } if ( 0 == menu_no ) gconv.Aparam = (int)val[0].long_type; else gconv.Bparam = (int)val[0].long_type; Lib_make_grayconv_table( &gconv, OFF ); Lib_gray_convert( 0, gray_mem_no ); /*エンハンス*/ Lib_xvideo_transmit( gray_mem_no, GRAY_PLANE ); } /************************************************************************/ /* エンハンス画像の表示   */ /************************************************************************/ void pdm_disp_enhance( timing, numb, val ) int timing; int numb; PARADIGM val[]; { Lib_erase_menu( pad_level_enhance ); Lib_freeze( NOT_TRANSMIT ); Lib_gray_convert( 0, gray_mem_no ); /*エンハンス*/ Lib_xvideo_transmit( gray_mem_no, GRAY_PLANE ); Lib_display_keyinput( 400, 30, " 確認 " ); Lib_freerun(); Lib_draw_menu( pad_level_enhance ); } /*********************************************************************/ /* 円周エッジ計測関連設定             */ /*********************************************************************/ void pdm_set_circle_edge( Timing, Numb, val ) int Timing; int Numb; PARADIGM val[]; { int i; Lib_erase_menu( pad_level ); pad_level_circle_edge = Lib_view_open(); Lib_view_set_title( pad_level_circle_edge, "円周エッジ" ); value_circle_edge[1].value_type = edge_sta_angle; value_circle_edge[2].value_type = edge_end_angle; value_circle_edge[3].value_type = edge_shikii; i = 0; Lib_view_set_null ( pad_level_circle_edge, 5, 5, "計測円設定", i ); i++; Lib_view_set_uniq_numeral( pad_level_circle_edge, 5, 35, "円弧始点角度", value_circle_edge[i].value_type, 0, 3600, i ); i++; Lib_view_set_uniq_numeral( pad_level_circle_edge, 5, 65, "円弧終点角度", value_circle_edge[i].value_type, 0, 3600, i ); i++; Lib_view_set_uniq_numeral( pad_level_circle_edge, 5, 95, "最小しきい値", value_circle_edge[i].value_type, 0, 255, i ); i++; Lib_set_paradigm( pad_level_circle_edge, 0, START_TIMING, pdm_set_circle ); Lib_view_set_size( pad_level_circle_edge, 80, 80, 30, 5 ); Lib_draw_menu( pad_level_circle_edge ); if( PAD_EXECUTE == Lib_process_menu( pad_level_circle_edge, value_circle_edge ) ) { edge_sta_angle = value_circle_edge[1].value_type; edge_end_angle = value_circle_edge[2].value_type; edge_shikii = value_circle_edge[3].value_type; } Lib_erase_menu( pad_level_circle_edge ); Lib_view_close( pad_level_circle_edge ); Lib_memory_clear( LINE_PLANE | CHAR_PLANE ); Lib_draw_menu( pad_level ); } /*********************************************************************/ /* エッジ検出円設定              */ /*********************************************************************/ void pdm_set_circle( Timing, Numb, val ) int Timing; int Numb; PARADIGM val[]; { static int r; int sts; int xpos; int ypos; int s_xpos; int s_ypos; int cx, cy; Lib_erase_menu( pad_level_circle_edge ); r = 100; Lib_chrdisp( 1, 30, "エッジ検出円を指定してください" ); cx = value[0].point_type.x; cy = value[0].point_type.y; s_xpos = xpos = cx + r; s_ypos = ypos = cy; Lib_move_cursor( xpos, ypos ); Lib_drawcircle( cx, cy, r ); for (;;) { sts = 0; sts = Lib_see_current_position( &xpos, &ypos ); /* マウス位置読みとり */ ypos = cy; if ( s_xpos != xpos || s_ypos != ypos ) { Lib_move_cursor( xpos, ypos ); Lib_erascircle( cx, cy, XXu_abs( s_xpos - cx ) ); Lib_drawcircle( cx, cy, XXu_abs( xpos - cx ) ); s_xpos = xpos; s_ypos = ypos; } if ( CURSOR_EXECUTE == sts ) { edge_r = XXu_abs( xpos - cx ); break; } } Lib_memory_clear( LINE_PLANE | CHAR_PLANE ); Lib_draw_menu( pad_level_circle_edge ); } /*********************************************************************/ /* 実行                 */ /*********************************************************************/ void exec() { int status; int i; int edge_cnt; double da, db, dc; static POINT_T cir_point[MAX_EDGE_NO]; POINT point[30]; LINE coeff; int dist_x, dist_y; int angle; /**/Lib_strtclk_count(); /*タイマーカウントモードのスタート*/ Lib_erase_cursor(); status = ERROR_RETURN; Lib_freeze( TRANSMIT ); if ( ON == enhance_sw ) { Lib_gray_convert( 0, gray_mem_no ); /*エンハンス*/ Lib_xvideo_transmit( gray_mem_no, GRAY_PLANE ); Lib_change_gray_memory( gray_mem_no ); } if ( ON == disp_sw_ciredg ) { Lib_arc_box( cx, cy, edge_r+50, (double)edge_sta_angle/10.0, 10, (double)edge_end_angle/10.0, DASHED_LINE ); } /*円周エッジ検出*/ XXdraw_cross( cx, cy, 5, GRAPH_DRAW ); Lib_drawcircle( cx, cy, edge_r ); point[0].x = cx; point[0].y = cy; tCent.x = cx; tCent.y = cy; tCent.wScale = 1; edge_cnt = Lib_clp_arc_edge_set_threshold( CURRENT_MEMORY, tCent, edge_r, edge_sta_angle, edge_end_angle, edge_shikii, MAX_EDGE_NO, cir_edge ); if( 0 < ( edge_cnt ) ) { for( i=0; i