/// <summary>
 /// 更新量測結果.
 /// 量測演算法放這裡
 /// </summary>
 public override void UpdateResults()
 {
     try
     {
         _Result = DistanceHelper.DistanceY(_geoModelOne, _geoModelTwo);
         if (_Result != null)
         {
             if (mMeasAssist.mIsCalibValid && mMeasAssist.mTransWorldCoord)
             {
                 Rectify(_Result.Row1, _Result.Col1, out _ResultWorld.Row1, out _ResultWorld.Col1);
             }
             else
             {
                 _ResultWorld = new LineResult(_Result);
             }
         }
     }
     catch (HOperatorException ex)
     {
         mMeasAssist.exceptionText = ex.Message;
         _ResultWorld = new LineResult();
         _Result      = new LineResult();
     }
     UpdateXLD();
 }
        private CircleResult fitCircle(HObject ho_Border, double areaPixels)
        {
            var result = new CircleResult();

            try
            {
                // Local control variables
                HTuple hv_Row, hv_Column, hv_Radius, hv_StartPhi;
                HTuple hv_EndPhi, hv_PointOrder;

                //******* Choice Candidate Objects
                HObject ho_SelectedContours;
                HOperatorSet.GenEmptyObj(out ho_SelectedContours);
                ho_SelectedContours.Dispose();
                HOperatorSet.SelectContoursXld(ho_Border, out ho_SelectedContours, "contour_length",
                                               10, Int16.MaxValue, -0.5, 0.5);

                //******* Fit Circle ************
                HTuple  hv_Number, hv_Index;
                HObject ho_ObjectSelected;
                HOperatorSet.GenEmptyObj(out ho_ObjectSelected);
                HOperatorSet.CountObj(ho_SelectedContours, out hv_Number);
                var resultRadius = 0.0;
                for (hv_Index = 1; hv_Index.Continue(hv_Number, 1); hv_Index = hv_Index.TupleAdd(1))
                {
                    ho_ObjectSelected.Dispose();
                    HOperatorSet.SelectObj(ho_SelectedContours, out ho_ObjectSelected, hv_Index);
                    HOperatorSet.FitCircleContourXld(ho_SelectedContours
                                                     , _Algorithm, _MaxNumPoints, _MaxClosureDist, _ClippingEndPoints, _Iterations, _ClippingFactor
                                                     , out hv_Row, out hv_Column, out hv_Radius, out hv_StartPhi, out hv_EndPhi, out hv_PointOrder);

                    //Answer
                    var radiusIndex = -1;
                    if (hv_Radius.TupleLength() > 0)
                    {
                        radiusIndex = DistanceHelper.GetApproximateRadiusIndex(hv_Radius.DArr, areaPixels);
                        if (radiusIndex > -1)
                        {
                            //取最大的 Circle
                            if (resultRadius < hv_Radius.DArr[radiusIndex])
                            {
                                result = new CircleResult(new HTuple(hv_Row.DArr[radiusIndex])
                                                          , new HTuple(hv_Column.DArr[radiusIndex])
                                                          , new HTuple(hv_Radius.DArr[radiusIndex])
                                                          , hv_StartPhi
                                                          , hv_EndPhi
                                                          , hv_PointOrder)
                                {
                                };
                                resultRadius = hv_Radius.DArr[radiusIndex];
                            }
                        }
                    }
                }
            }
            catch (HOperatorException ex)
            {
                Hanbo.Log.LogManager.Error(ex);
            }
            return(result);
        }