1. 程式人生 > >HALCON setsystem 運算元中引數的含義之 flush_graphic

HALCON setsystem 運算元中引數的含義之 flush_graphic

首先是halcon上的文件解釋:

 

'flush_graphic':

After each HALCON operation which creates a graphic output, a flush operation will be executed in order to display the data immediately on screen. This is not necessary for all programs, e.g., if everything is done with the help of the mouse. In this case'flush_graphic'

 can be set to 'false' to improve the runtime. Note that this parameter has no effect on Unix-like systems because there, the window managers flush the display buffer automatically.

Value: 'true' or 'false'

Default: 'true'

理解的大概意思是 halcon運算元建立一個圖形輸出後,會執行一個flush操作來更新螢幕上顯示的資料。可以將值設為false來停止這個操作來提升runtime.

實際遇到的一個相關例子是,在影象視窗上繪製region,當flush_graphic的值是true時,不斷的flush導致的結果就是螢幕上的

region在不停的閃爍,看起來很不友好;而當flush_graphic的值是false時,由於停止不斷的flush,所以region不停閃爍的問題也就沒有了。只在region更新的時候設定flush_graphic為true,是比較好的選擇。


附一段halcon-c++開發使用到flush_graphic的功能函式:

/*********************採用圓形筆刷畫出模板區*********************************
輸入引數:
WindowHandle:視窗影象控制代碼
       Image:模板影象
      radius:筆刷半

輸出引數:
ModelRegion:模板區域

返回值:
成功返回0,失敗返回-1
/***************************************************************************/
int CreateModeRegion

(const HTuple &WindowHandle,const HObject &Image,const Hlong &radius,HObject *ModleRegion)
{
    try
    {

        HTuple hvRow,hvColumn,hvButton,hvRowPos,hvColPos;
        HObject hoCircle;

        hvRowPos = 10;
        hvColPos = 10;
        SetColor(WindowHandle,"red");
        SetDraw(WindowHandle,"margin");

        SetTposition(WindowHandle,hvRowPos-10,hvRowPos);
        WriteString(WindowHandle,"用下面大小的小圓去塗抹模板區,按下左鍵移動塗抹,右鍵結束");
        DispCircle(WindowHandle,hvRowPos+radius+60,hvColPos+radius,radius);

        GenEmptyObj(ModleRegion);
        GetMbutton(WindowHandle,&hvRow, &hvColumn, &hvButton);

        //未畫模板點右鍵退出則不建立模板
        int value = hvButton.I();
        if(4 == value)
        {
            SetSystem("flush_graphic","true");
            return -1;
        }
        //按下滑鼠右鍵結束
        while(4 != value)
        {
            GetMposition(WindowHandle,&hvRow,&hvColumn,&hvButton);        
            value = hvButton.I();
            SetSystem("flush_graphic","false");
            DispObj(Image,WindowHandle);        
            if(hvRow>0 && hvColumn>0)
            {                
                if(0 == value)
                {                
                    GenCircle(&hoCircle, hvRow, hvColumn, radius);
                    DispObj(hoCircle,WindowHandle);
                    DispObj(*ModleRegion,WindowHandle);
                    SetSystem("flush_graphic","true");
                }
                //按下滑鼠左鍵
                else if (1 == value)
                {
                    GenCircle(&hoCircle, hvRow, hvColumn, radius);                
                    SetSystem("flush_graphic","false");
                    Union2(*ModleRegion,hoCircle,ModleRegion);
                    DispObj(*ModleRegion,WindowHandle);
                }
            }
            else
            {
                break;
            }
        }    
        SetSystem("flush_graphic","true");
    }
    catch (HOperatorException &e)
    {
        CString csError(e.ErrorMessage());
        AfxMessageBox(csError);

    }
    catch(HTupleAccessException &ex)
    {
        CString csError(ex.ErrorMessage());
        AfxMessageBox(csError);
    }
    return 0;
}