/// <summary>
 /// Creates and initializes a measure object based on information the ROI object
 /// about the ROI.
 /// </summary>
 /// <param name="roi">ROI instance</param>
 /// <param name="mAssist">Reference to controller class</param>
 public Measurement(ROI roi, MeasureAssistant mAssist)
 {
     mMeasAssist    = mAssist;
     mEdgeXLD       = new HXLDCont();
     mMeasureRegion = new HRegion();
     initROI(roi);
 }
 /// <summary>
 /// 建構子
 /// </summary>
 /// <param name="roi"></param>
 /// <param name="mAssist"></param>
 public MeasurementCircle(ROI roi, MeasureAssistant mAssist)
     : base(roi, mAssist)
 {
     mResult    = new CircleResult();
     _cameraOut = new HTuple();
     UpdateMeasure();
 }
 public MeasurementFitLine(ROI roi, MeasureAssistant mAssist)
     : base(roi, mAssist)
 {
     mResult = new FitLineResult();
     _cameraOut = new HTuple();
     UpdateMeasure();
 }
 public MeasurementSymmetryLine(ROI roiOne, ROI roiTwo, MeasureAssistant mAssist)
     : base(null, mAssist)
 {
     var lineF = new MeasurementEdge(roiOne, mAssist);
     var lineS = new MeasurementEdge(roiTwo, mAssist);
     initialize(lineF.GetViewModel(), lineS.GetViewModel(), mAssist);
 }
 /// <summary>
 /// Creates and initializes a measure object based on information the ROI object
 /// about the ROI.
 /// </summary>
 /// <param name="roi">ROI instance</param>
 /// <param name="mAssist">Reference to controller class</param>
 public Measurement(ROI roi, MeasureAssistant mAssist)
 {
     mMeasAssist = mAssist;
     mEdgeXLD = new HXLDCont();
     mMeasureRegion = new HRegion();
     initROI(roi);
 }
 /// <summary>
 /// Creates a measurement object for the provided ROI instance.
 /// </summary>
 /// <param name="roi">ROI instance</param>
 /// <param name="mAssist">Reference to controller class</param>
 public MeasurementEdge(ROI roi, MeasureAssistant mAssist)
     : base(roi, mAssist)
 {
     mResult      = new EdgeResult();
     mResultWorld = new EdgeResult();
     UpdateMeasure();
 }
 /// <summary>
 /// Creates a measurement object for the provided ROI instance.
 /// </summary>
 /// <param name="roi">ROI instance</param>
 /// <param name="mAssist">Reference to controller class</param>
 public MeasurementEdge(ROI roi, MeasureAssistant mAssist)
     : base(roi, mAssist)
 {
     mResult = new EdgeResult();
     mResultWorld = new EdgeResult();
     UpdateMeasure();
 }
        public MeasurementDistanceY(ROI roiOne, ROI roiTwo, MeasureAssistant mAssist)
            : base(null, mAssist)
        {
            var lineF = new MeasurementEdge(roiOne, mAssist);
            var lineS = new MeasurementEdge(roiTwo, mAssist);

            initialize(lineF.GetViewModel(), lineS.GetViewModel(), mAssist);
        }
示例#9
0
 /// <summary>
 /// Factory method to create measure objects
 /// </summary>
 /// <param name="roi">Interactive ROI</param>
 /// <param name="parent">
 /// Reference to measure controller class
 /// </param>
 /// <returns>New measure object</returns>
 public static Measurement CreateMeasure(ROI roi, MeasureAssistant parent)
 {
     if (parent.mSelPair)
     {
         return(new MeasurementPair(roi, parent));
     }
     else
     {
         return(new MeasurementEdge(roi, parent));
     }
 }
示例#10
0
        /// <summary>
        /// Creates and initializes a measure object based on information the ROI object
        /// about the ROI.
        /// </summary>
        /// <param name="roi">ROI instance</param>
        /// <param name="mAssist">Reference to controller class</param>
        public Measurement(ROI roi, MeasureAssistant mAssist)
        {
            mRoi = roi;
            mMeasAssist = mAssist;
            mROICoord = mRoi.getModelData();
            mEdgeXLD = new HXLDCont();
            mMeasureRegion = new HRegion();

            if (mRoi is ROICircularArc)
                mROIType = ROI.ROI_TYPE_CIRCLEARC;
            else
                mROIType = ROI.ROI_TYPE_LINE;
        }
        /// <summary>
        /// Creates and initializes a measure object based on information the ROI object
        /// about the ROI.
        /// </summary>
        /// <param name="roi">ROI instance</param>
        /// <param name="mAssist">Reference to controller class</param>
        public Measurement(ROI roi, MeasureAssistant mAssist)
        {
            mRoi           = roi;
            mMeasAssist    = mAssist;
            mROICoord      = mRoi.getModelData();
            mEdgeXLD       = new HXLDCont();
            mMeasureRegion = new HRegion();

            if (mRoi is ROICircularArc)
            {
                mROIType = ROI.ROI_TYPE_CIRCLEARC;
            }
            else
            {
                mROIType = ROI.ROI_TYPE_LINE;
            }
        }
        /// <summary>
        /// Factory method to create measure objects
        /// </summary>
        /// <param name="roi">Interactive ROI</param>
        /// <param name="parent">
        /// Reference to measure controller class
        /// </param>
        /// <returns>New measure object</returns>
        public static Measurement CreateMeasure(ROI roi, MeasureAssistant parent)
        {
            Measurement mMeasurement = null;

            switch (roi.ROIMeasureType)
            {
            case MeasureType.Circle:
                mMeasurement = new MeasurementCircle(roi, parent);
                break;

            case MeasureType.Line:
                if (_doFitLineAlgo)
                {
                    mMeasurement = new MeasurementFitLine(roi, parent);
                }
                else
                {
                    mMeasurement = new MeasurementEdge(roi, parent);
                }
                break;

            case MeasureType.Point:
                if (roi is ViewROI.SmartROIs.SmartPoint)
                {
                    mMeasurement = new SmartMeasurements.AutoFitPoint(roi, parent);
                }
                else
                {
                    mMeasurement = new MeasurementEdge(roi, parent);
                }
                break;

            default:
                mMeasurement = new MeasurementEdge(roi, parent);
                break;
            }
            //if (parent.mSelPair)
            //	return new MeasurementPair(roi, parent);
            //else if (roi.ROIMeasureType == MeasureType.Circle)
            //{
            //	return new MeasurementCircle(roi, parent);
            //}
            //else
            //	return new MeasurementEdge(roi, parent);
            return(mMeasurement);
        }
示例#13
0
        /// <summary>
        /// 擬合圓
        /// </summary>
        /// <param name="f_radius">圓 ROI 半徑</param>
        /// <param name="f_ROI_Cur_Row">圓 ROI Row 座標</param>
        /// <param name="f_ROI_Cur_Col">圓 ROI Col 座標</param>
        /// <returns></returns>
        public static MeasureViewModel GetFitCircleModel(HObject ho_image, HTuple f_radius, HTuple f_ROI_Cur_Row, HTuple f_ROI_Cur_Col)
        {
            var cROIController = new ROIController();
            var cAssistant     = new MeasureAssistant(cROIController);

            var hImage = ho_image as HImage;

            cAssistant.setImage(hImage);

            /*參數值*/
            cAssistant.mThresh         = 40.0;
            cAssistant.mSigma          = 1.0;
            cAssistant.mRoiWidth       = 10;
            cAssistant.mInterpolation  = "nearest_neighbor";
            cAssistant.mSelPair        = false;
            cAssistant.mTransition     = "all";
            cAssistant.mPosition       = "all";
            cAssistant.mDispEdgeLength = 30;
            cAssistant.mDispROIWidth   = true;
            cAssistant.setUnit("cm");

            cAssistant.mInitThresh   = 40.0;
            cAssistant.mInitSigma    = 1.0;
            cAssistant.mInitRoiWidth = 10;

            var roiF = new ROICircle()
            {
                ROIMeasureType = MeasureType.Circle
            };

            //roiF.MakeROI(416, 998, 0, 26.5, 71.2);
            roiF.MakeROI(f_ROI_Cur_Row, f_ROI_Cur_Col, f_radius);


            var fitCircle = new MeasurementCircle(roiF, cAssistant);
            var model     = fitCircle.GetViewModel();

            return(model);
        }
        public bool Init(ROIController roicontroller, MeasureAssistant mAssistant
            , double resolution, int roundDigit, string[] inVisibleFields)
        {
            MessageLabel.Text = "";
            var success = true;
            var model = new List<RefCoordinate>() {
                                new RefCoordinate() { ID = "", Name = "Default", Desc = "影像座標" },
                        };
            _dfCoordinateBindingList = new BindingList<RefCoordinate>(model);

            _geoManager = new GeoDataGridViewManager(GeoDataGridView, GeoContextMenuStrip
                                            , _dfCoordinateBindingList, inVisibleFields
                                            , ConfigurationMM.GeoImageDictionary
                                            , resolution, roundDigit, mAssistant);
            _roiController = roicontroller;

            initGeoContextMenu();
            initCoordinateComboBox();
            initLengthUnitComboBox();
            initClearButton();
            initExportButton();
            initGeoTreeView();
            return success;
        }
 /// <summary>
 /// Factory method to create measure objects
 /// </summary>
 /// <param name="roi">Interactive ROI</param>
 /// <param name="parent">
 /// Reference to measure controller class
 /// </param>
 /// <returns>New measure object</returns>
 public static Measurement CreateMeasure(ROI roi, MeasureAssistant parent)
 {
     if (parent.mSelPair)
         return new MeasurementPair(roi, parent);
     else
         return new MeasurementEdge(roi, parent);
 }
 public MeasurementSymmetryLine(IMeasureGeoModel geoModelOne, IMeasureGeoModel geoModelTwo, MeasureAssistant mAssist)
     : base(null, mAssist)
 {
     initialize(geoModelOne, geoModelTwo, mAssist);
 }
        /// <summary>
        /// 建構子
        /// </summary>
        /// <param name="container">DataGrid</param>
        /// <param name="menuStrip">右鍵選單</param>
        /// <param name="refCoordinate">參考座標</param>
        /// <param name="refSkew">參考軸擺正</param>
        /// <param name="invisiableColumnNames">不顯示的欄位名稱們</param>
        /// <param name="iconImageList">圖示s</param>
        /// <param name="resolution">解析度</param>
        /// <param name="roundDigit">進位</param>
        /// <param name="assistant"></param>
        public GeoDataGridViewManager(DataGridView container,
            ContextMenuStrip menuStrip,
            BindingList<RefCoordinate> refCoordinate,
            BindingList<RefSkew> refSkew,
            string[] invisiableColumnNames,
            Dictionary<string, Bitmap> iconImageList,
            double resolution,
            int roundDigit, MeasureAssistant assistant)
        {
            _GridViewContainer = container;
            _geoContextMenuStrip = menuStrip;
            _refCoordinate = refCoordinate;
            _refSkew = refSkew;

            _defaultRefSkew = new RefSkew();
            //初始化 skewID
            if (_refSkew == null)
            {
                _refSkew = new BindingList<RefSkew>();
                _refSkew.Add(_defaultRefSkew);
            }
            _currentSkewID = (_refSkew.Count > 0) ? _refSkew[0].ID : "";

            _DataList = new BindingList<GeoDataGridViewModel>();
            _InvisiableColumnNames = invisiableColumnNames;
            _ImageList = iconImageList;
            _Resolution = resolution;
            _RoundDigit = roundDigit;
            mAssistant = assistant;
            initialize();
        }
 private void initialize(IMeasureGeoModel geoModelOne, IMeasureGeoModel geoModelTwo, MeasureAssistant mAssist)
 {
     _geoModelOne = geoModelOne;
     _geoModelTwo = geoModelTwo;
     ROIMeasureType = MeasureType.SymmetryLine;
     _ResultWorld = new LineResult();
     UpdateResults();
 }
示例#19
0
        public MeasureResult Action()
        {
            #region 輸出結果
            DistanceResult mResult = null;
            #endregion

            HTuple hv_STD_Row;
            HTuple hv_STD_Col, hv_Img_Row, hv_Img_Col, hv_Img_Rotate_Angle;
            HTuple hv_OffsetRow, hv_OffsetCol;
            HOperatorSet.SetSystem("border_shape_models", "false");

            //STD 中心點
            hv_STD_Row = 839.5;
            hv_STD_Col = 1046.5;

            //目前圖形 中心點
            hv_Img_Row = hv_AllModelRow.Clone();
            hv_Img_Col = hv_AllModelColumn.Clone();

            //目前圖形 Rotate Angle
            hv_Img_Rotate_Angle = hv_AllModelAngle.Clone();

            //目前圖形偏移量
            hv_OffsetRow = hv_Img_Row - hv_STD_Row;
            hv_OffsetCol = hv_Img_Col - hv_STD_Col;

            //第一個 線段 ROI
            HTuple f_ROI_Row = 341.21875;
            HTuple f_ROI_Col = 803.078431372549;
            HTuple f_angle = 1.5707963267949;
            HTuple f_ROI_Length1 = 77.5390625;
            HTuple f_ROI_Length2 = 148.705882352941;

            HTuple f_angleOffset = f_angle - hv_Img_Rotate_Angle;
            HTuple f_ROI_Cur_Row, f_ROI_Cur_Col;
            PositionLocater.ReLocater(hv_STD_Row, hv_STD_Col, hv_AllModelAngle, hv_OffsetRow, hv_OffsetCol, f_ROI_Row, f_ROI_Col, out f_ROI_Cur_Row, out f_ROI_Cur_Col);

            //

            //第二個 線段 ROI

            HTuple s_ROI_Row = 774.4765625;
            HTuple s_ROI_Col = 709.622549019608;
            HTuple s_angle = 0;
            HTuple s_ROI_Length1 = 45.2843137254902;
            HTuple s_ROI_Length2 = 30.15234375;

            HTuple s_angleOffset = s_angle - hv_Img_Rotate_Angle;
            HTuple s_ROI_Cur_Row, s_ROI_Cur_Col;
            PositionLocater.ReLocater(hv_STD_Row, hv_STD_Col, hv_AllModelAngle, hv_OffsetRow, hv_OffsetCol
                    , s_ROI_Row, s_ROI_Col, out s_ROI_Cur_Row, out s_ROI_Cur_Col);

            #region Measure
            var cROIController = new ROIController();
            var cAssistant = new MeasureAssistant(cROIController);

            var hImage = ho_Image as HImage;
            cAssistant.setImage(hImage);

            /*參數值*/
            cAssistant.mThresh = 40.0;
            cAssistant.mSigma = 1.0;
            cAssistant.mRoiWidth = 10;
            cAssistant.mInterpolation = "nearest_neighbor";
            cAssistant.mSelPair = false;
            cAssistant.mTransition = "all";
            cAssistant.mPosition = "all";
            cAssistant.mDispEdgeLength = 30;
            cAssistant.mDispROIWidth = true;
            cAssistant.setUnit("cm");

            cAssistant.mInitThresh = 40.0;
            cAssistant.mInitSigma = 1.0;
            cAssistant.mInitRoiWidth = 10;

            var roiF = new ROIRectangle2() { ROIMeasureType = MeasureType.Line };
            roiF.MakeROI(f_ROI_Cur_Row, f_ROI_Cur_Col, f_angleOffset, f_ROI_Length1, f_ROI_Length2);

            var roiS = new ROIRectangle2() { ROIMeasureType = MeasureType.Point };
            roiS.MakeROI(s_ROI_Cur_Row, s_ROI_Cur_Col, s_angleOffset, s_ROI_Length1, s_ROI_Length2);

            var lineF = new MeasurementEdge(roiF, cAssistant);
            var pointS = new MeasurementEdge(roiS, cAssistant);
            mResult = DistanceHelper.PointToLine(lineF, pointS, this.hv_AllModelAngle);

            #endregion

            return mResult;
        }
示例#20
0
        public void Initialize(HImage image, HTuple modelRow, HTuple modelColumn, HTuple modelAngle)
        {
            ho_Image = image;
            hv_AllModelRow = new HTuple(modelRow);
            hv_AllModelColumn = new HTuple(modelColumn);
            hv_AllModelAngle = new HTuple(modelAngle);

            cAssistant = new MeasureAssistant(new ROIController());
        }
 private void initialize(IMeasureGeoModel geoModelOne, IMeasureGeoModel geoModelTwo, MeasureAssistant mAssist)
 {
     _geoModelOne = geoModelOne;
     _geoModelTwo = geoModelTwo;
     ROIMeasureType = MeasureType.Angle;
     //_Result = new AngleResult();
     _ResultWorld = new AngleResult();
     UpdateResults();
 }
示例#22
0
        /// <summary>
        /// Loads MeasureForm and initializes view functions
        /// to include in the MeasureAssistant.
        /// </summary>
        private void MeasureForm_Load(object sender, System.EventArgs e)
        {
            mView = new HWndCtrl(viewPort);
            roiController = new ROIController();
            mView.useROIController(roiController);
            mAssistant = new MeasureAssistant(roiController);
            mShadow = new HXLDCont();

            mView.setViewState(HWndCtrl.MODE_VIEW_NONE);
            mView.changeGraphicSettings(GraphicsContext.GC_LINEWIDTH, 1);

            roiController.NotifyRCObserver = new IconicDelegate(UpdateROIData);
            mAssistant.NotifyMeasureObserver = new MeasureDelegate(UpdateMeasureResults);

            plotGraphWindow = new FunctionPlot(panelAxis, true);

              openImageFileDialog.InitialDirectory =
            (string)(HSystem.GetSystem("image_dir").TupleSplit(";"));
            Init();

            mView.setDispLevel(HWndCtrl.MODE_EXCLUDE_ROI);
        }
示例#23
0
        public MeasureViewModel GetMidLine()
        {
            #region 輸出結果
            DistanceResult mResult = null;
            MeasureViewModel midLineModel = null;
            #endregion

            HTuple hv_STD_Row;
            HTuple hv_STD_Col, hv_Img_Row, hv_Img_Col, hv_Img_Rotate_Angle;
            HTuple hv_OffsetRow, hv_OffsetCol;
            HOperatorSet.SetSystem("border_shape_models", "false");

            //STD 中心點
            hv_STD_Row = 839.5;
            hv_STD_Col = 1046.5;

            //目前圖形 中心點
            hv_Img_Row = hv_AllModelRow.Clone();
            hv_Img_Col = hv_AllModelColumn.Clone();

            //目前圖形 Rotate Angle
            hv_Img_Rotate_Angle = hv_AllModelAngle.Clone();

            //目前圖形偏移量
            hv_OffsetRow = hv_Img_Row - hv_STD_Row;
            hv_OffsetCol = hv_Img_Col - hv_STD_Col;

            //第一個 線段 ROI
            //HTuple f_ROI_Row = 528.01953125;
            //HTuple f_ROI_Col = 821.555555555556;
            //HTuple f_angle = 0;
            //HTuple f_ROI_Length1 = 20;
            //HTuple f_ROI_Length2 = 93;
            HTuple f_ROI_Row = 528.01953125;
            HTuple f_ROI_Col = 1067.82352941176;
            HTuple f_angle = 0;
            HTuple f_ROI_Length1 = 20.9019607843137;
            HTuple f_ROI_Length2 = 90.669921875;

            HTuple f_angle_offset = f_angle - hv_Img_Rotate_Angle;
            HTuple f_ROI_Cur_Row, f_ROI_Cur_Col;
            PositionLocater.ReLocater(hv_STD_Row, hv_STD_Col, hv_AllModelAngle, hv_OffsetRow, hv_OffsetCol, f_ROI_Row, f_ROI_Col, out f_ROI_Cur_Row, out f_ROI_Cur_Col);

            //第二個 線段 ROI
            //HTuple s_ROI_Row = 528.03515625;
            //HTuple s_ROI_Col = 858.300653594771;
            //HTuple s_angle = 3.14159265358979;
            //HTuple s_ROI_Length1 = 20;
            //HTuple s_ROI_Length2 = 93;
            HTuple s_ROI_Row = 528.03515625;
            HTuple s_ROI_Col = 1102.59477124183;
            HTuple s_angle = 3.14159265358979;
            HTuple s_ROI_Length1 = 17.3856209150328;
            HTuple s_ROI_Length2 = 91.6015625;

            HTuple s_angle_offset = s_angle - hv_Img_Rotate_Angle;
            HTuple s_ROI_Cur_Row, s_ROI_Cur_Col;
            PositionLocater.ReLocater(hv_STD_Row, hv_STD_Col, hv_AllModelAngle, hv_OffsetRow, hv_OffsetCol
                    , s_ROI_Row, s_ROI_Col, out s_ROI_Cur_Row, out s_ROI_Cur_Col);

            #region Measure
            var cROIController = new ROIController();
            var cAssistant = new MeasureAssistant(cROIController);

            var hImage = ho_Image as HImage;
            cAssistant.setImage(hImage);

            /*參數值*/
            cAssistant.mThresh = 40.0;
            cAssistant.mSigma = 1.0;
            cAssistant.mRoiWidth = 10;
            cAssistant.mInterpolation = "nearest_neighbor";
            cAssistant.mSelPair = false;
            cAssistant.mTransition = "all";
            cAssistant.mPosition = "all";
            cAssistant.mDispEdgeLength = 30;
            cAssistant.mDispROIWidth = true;
            cAssistant.setUnit("cm");

            cAssistant.mInitThresh = 40.0;
            cAssistant.mInitSigma = 1.0;
            cAssistant.mInitRoiWidth = 10;

            var roiF = new ROIRectangle2() { ROIMeasureType = MeasureType.Line };
            //roiF.MakeROI(416, 998, 0, 26.5, 71.2);
            roiF.MakeROI(f_ROI_Cur_Row, f_ROI_Cur_Col, f_angle_offset, f_ROI_Length1, f_ROI_Length2);

            var roiS = new ROIRectangle2() { ROIMeasureType = MeasureType.Line };
            //roiS.MakeROI(400, 1041, 0, 13.3, 75.7);
            roiS.MakeROI(s_ROI_Cur_Row, s_ROI_Cur_Col, s_angle_offset, s_ROI_Length1, s_ROI_Length2);

            var lineF = new MeasurementEdge(roiF, cAssistant);
            var lineS = new MeasurementEdge(roiS, cAssistant);
            mResult = DistanceHelper.LineToLine(lineF, lineS, this.hv_AllModelAngle, LineDirection.Horizontal);

            var firstModel = lineF.GetViewModel();
            var secondModel = lineS.GetViewModel();
            if (firstModel != null && secondModel != null && firstModel.Distance != null && secondModel.Distance != null
                && firstModel.Distance.TupleLength() > 0 && secondModel.Distance.TupleLength() > 0)
            {
                //作線段
                var centerRow = (f_ROI_Cur_Row + s_ROI_Cur_Row) / 2.0;
                var centerCol = (f_ROI_Cur_Col + s_ROI_Cur_Col) / 2.0;

                midLineModel = DistanceHelper.MakeLine(centerRow, centerCol, hv_AllModelAngle, mResult.Distance / 2.0);
            }

            return midLineModel;
            #endregion
        }
        public GeoDataGridViewManager(DataGridView container,
            BindingList<GeoDataGridViewModel> bindingList,
            string[] invisiableColumnNames,
            Dictionary<string, Bitmap> iconImageList,
            double resolution,
            int roundDigit, MeasureAssistant assistant)
        {
            _GridViewContainer = container;
            _DataList = bindingList;
            _InvisiableColumnNames = invisiableColumnNames;
            _ImageList = iconImageList;
            _Resolution = resolution;
            _RoundDigit = roundDigit;
            mAssistant = assistant;

            var dfCoordinateModel = new List<RefCoordinate>() { new RefCoordinate(), };
            _refCoordinate = new BindingList<RefCoordinate>(dfCoordinateModel);

            //初始化 軸擺正
            _defaultRefSkew = new RefSkew();
            _currentSkewID = _defaultRefSkew.ID;
            var dfSkewModel = new List<RefSkew>() { _defaultRefSkew };
            _refSkew = new BindingList<RefSkew>(dfSkewModel);

            initialize();
        }
 public MeasurementDistanceY(IMeasureGeoModel geoModelOne, IMeasureGeoModel geoModelTwo, MeasureAssistant mAssist)
     : base(null, mAssist)
 {
     initialize(geoModelOne, geoModelTwo, mAssist);
 }
示例#26
0
 public MeasurementSymmetryLine(IMeasureGeoModel geoModelOne, IMeasureGeoModel geoModelTwo, MeasureAssistant mAssist)
     : base(null, mAssist)
 {
     initialize(geoModelOne, geoModelTwo, mAssist);
 }
 public MeasurementTwoLineCrossPoint(IMeasureGeoModel geoModelOne, IMeasureGeoModel geoModelTwo, MeasureAssistant mAssist)
     : base(null, mAssist)
 {
     initialize(geoModelOne, geoModelTwo, mAssist);
 }
        /// <summary>
        /// 初始化
        /// </summary>
        /// <param name="message"></param>
        /// <returns></returns>
        public bool Init(out string message)
        {
            _isReady = true;
            message = "";
            try
            {
                _roiController = new ROIController();
                mView = new HWndCtrl(this.ViewPort);
                mView.useROIController(_roiController);
                _roiController.NotifyRCObserver = new IconicDelegate(On_ROIUpdated);// ROI 操作通知

                mAssistant = new MeasureAssistant(_roiController);
                mAssistant.NotifyMeasureObserver = new MeasureDelegate(UpdateMeasureResults);

                initFileDialog();
                initializeGrabImage();
            }
            catch (Exception ex)
            {
                _isReady = false;
                message = ex.Message;
            }
            return _isReady;
        }
        /// <summary>
        /// 擬合圓
        /// </summary>
        /// <param name="f_radius">圓 ROI 半徑</param>
        /// <param name="f_ROI_Cur_Row">圓 ROI Row 座標</param>
        /// <param name="f_ROI_Cur_Col">圓 ROI Col 座標</param>
        /// <returns></returns>
        public static MeasureViewModel GetFitCircleModel(HObject ho_image, HTuple f_radius, HTuple f_ROI_Cur_Row, HTuple f_ROI_Cur_Col)
        {
            var cROIController = new ROIController();
            var cAssistant = new MeasureAssistant(cROIController);

            var hImage = ho_image as HImage;
            cAssistant.setImage(hImage);

            /*參數值*/
            cAssistant.mThresh = 40.0;
            cAssistant.mSigma = 1.0;
            cAssistant.mRoiWidth = 10;
            cAssistant.mInterpolation = "nearest_neighbor";
            cAssistant.mSelPair = false;
            cAssistant.mTransition = "all";
            cAssistant.mPosition = "all";
            cAssistant.mDispEdgeLength = 30;
            cAssistant.mDispROIWidth = true;
            cAssistant.setUnit("cm");

            cAssistant.mInitThresh = 40.0;
            cAssistant.mInitSigma = 1.0;
            cAssistant.mInitRoiWidth = 10;

            var roiF = new ROICircle() { ROIMeasureType = MeasureType.Circle };
            //roiF.MakeROI(416, 998, 0, 26.5, 71.2);
            roiF.MakeROI(f_ROI_Cur_Row, f_ROI_Cur_Col, f_radius);

            var fitCircle = new MeasurementCircle(roiF, cAssistant);
            var model = fitCircle.GetViewModel();
            return model;
        }
示例#30
0
 public MeasurementTwoLineCrossPoint(IMeasureGeoModel geoModelOne, IMeasureGeoModel geoModelTwo, MeasureAssistant mAssist)
     : base(null, mAssist)
 {
     initialize(geoModelOne, geoModelTwo, mAssist);
 }
示例#31
0
        public MeasureResult Action()
        {
            #region 輸出結果
            LineResult mResult = null;
            #endregion

            HTuple hv_STD_Row;
            HTuple hv_STD_Col, hv_Img_Row, hv_Img_Col, hv_Img_Rotate_Angle;
            HTuple hv_OffsetRow, hv_OffsetCol;
            HOperatorSet.SetSystem("border_shape_models", "false");

            //STD 中心點
            hv_STD_Row = 839.5;
            hv_STD_Col = 1046.5;

            //目前圖形 中心點
            hv_Img_Row = hv_AllModelRow.Clone();
            hv_Img_Col = hv_AllModelColumn.Clone();

            //目前圖形 Rotate Angle
            hv_Img_Rotate_Angle = hv_AllModelAngle.Clone();

            //目前圖形偏移量
            hv_OffsetRow = hv_Img_Row - hv_STD_Row;
            hv_OffsetCol = hv_Img_Col - hv_STD_Col;

            //第一個 線段 ROI
            //HTuple f_ROI_Row = 341.21875;
            //HTuple f_ROI_Col = 803.078431372549;
            //HTuple f_angle = 1.5707963267949;
            //HTuple f_ROI_Length1 = 77.5390625;
            //HTuple f_ROI_Length2 = 148.705882352941;
            HTuple f_ROI_Row = 357.08984375;
            HTuple f_ROI_Col = 816.555555555556;
            HTuple f_angle = 1.5707963267949;
            HTuple f_ROI_Length1 = 69.8359375;
            HTuple f_ROI_Length2 = 122.277777777778;

            HTuple f_angleOffset = f_angle - hv_Img_Rotate_Angle;
            HTuple f_ROI_Cur_Row, f_ROI_Cur_Col;
            PositionLocater.ReLocater(hv_STD_Row, hv_STD_Col, hv_AllModelAngle, hv_OffsetRow, hv_OffsetCol, f_ROI_Row, f_ROI_Col, out f_ROI_Cur_Row, out f_ROI_Cur_Col);

            //兩線段交點
            HTuple p1_ROI_Row = 715.40234375;
            HTuple p1_ROI_Col = 744.222222222222;
            HTuple p1_angle = 0.764250656215704;
            HTuple p1_ROI_Length1 = 68.0072446324003;
            HTuple p1_ROI_Length2 = 105.756749157524;

            HTuple p1_angleOffset = p1_angle - hv_Img_Rotate_Angle;
            HTuple p1_ROI_Cur_Row, p1_ROI_Cur_Col;
            PositionLocater.ReLocater(hv_STD_Row, hv_STD_Col, hv_AllModelAngle, hv_OffsetRow, hv_OffsetCol
                    , p1_ROI_Row, p1_ROI_Col, out p1_ROI_Cur_Row, out p1_ROI_Cur_Col);

            HTuple p2_ROI_Row = 794.64453125;
            HTuple p2_ROI_Col = 702.888888888889;
            HTuple p2_angle = 0;
            HTuple p2_ROI_Length1 = 100;
            HTuple p2_ROI_Length2 = 50;
            HTuple p2_angleOffset = p2_angle - hv_Img_Rotate_Angle;
            HTuple p2_ROI_Cur_Row, p2_ROI_Cur_Col;
            PositionLocater.ReLocater(hv_STD_Row, hv_STD_Col, hv_AllModelAngle, hv_OffsetRow, hv_OffsetCol
                    , p2_ROI_Row, p2_ROI_Col, out p2_ROI_Cur_Row, out p2_ROI_Cur_Col);

            #region Measure
            var cROIController = new ROIController();
            var cAssistant = new MeasureAssistant(cROIController);

            var hImage = ho_Image as HImage;
            cAssistant.setImage(hImage);

            /*參數值*/
            cAssistant.mThresh = 40.0;
            cAssistant.mSigma = 1.0;
            cAssistant.mRoiWidth = 10;
            cAssistant.mInterpolation = "nearest_neighbor";
            cAssistant.mSelPair = false;
            cAssistant.mTransition = "all";
            cAssistant.mPosition = "all";
            cAssistant.mDispEdgeLength = 30;
            cAssistant.mDispROIWidth = true;
            cAssistant.setUnit("cm");

            cAssistant.mInitThresh = 40.0;
            cAssistant.mInitSigma = 1.0;
            cAssistant.mInitRoiWidth = 10;

            var p1Line = new ROIRectangle2() { ROIMeasureType = MeasureType.Line };
            //roiF.MakeROI(416, 998, 0, 26.5, 71.2);
            p1Line.MakeROI(p1_ROI_Cur_Row, p1_ROI_Cur_Col, p1_angleOffset, p1_ROI_Length1, p1_ROI_Length2);

            var p2Line = new ROIRectangle2() { ROIMeasureType = MeasureType.Line };
            //roiS.MakeROI(400, 1041, 0, 13.3, 75.7);
            p2Line.MakeROI(p2_ROI_Cur_Row, p2_ROI_Cur_Col, p2_angleOffset, p2_ROI_Length1, p2_ROI_Length2);

            var p1F = new MeasurementEdge(p1Line, cAssistant);
            var p2S = new MeasurementEdge(p2Line, cAssistant);
            var angleResult = DistanceHelper.AngleLineToLine(p1F, p2S);

            var roiF = new ROIRectangle2() { ROIMeasureType = MeasureType.Line };
            roiF.MakeROI(f_ROI_Cur_Row, f_ROI_Cur_Col, f_angleOffset, f_ROI_Length1, f_ROI_Length2);
            var lineF = new MeasurementEdge(roiF, cAssistant);

            if (angleResult != null && lineF != null)
            {
                var pointViewModel = new MeasureViewModel()
                {
                    Row1 = angleResult.Row,
                    Col1 = angleResult.Col,
                };
                var lineViewModel = lineF.GetViewModel();
                var distance = DistanceHelper.PointToLine(lineViewModel, pointViewModel);
                mResult = new LineResult()
                {
                    Row1 = lineViewModel.Row2,
                    Col1 = lineViewModel.Col2,
                    Row2 = pointViewModel.Row1,
                    Col2 = pointViewModel.Col1,
                    Distance = distance,
                };
            }

            #endregion

            return mResult;
        }
示例#32
0
        public MeasureResult Action()
        {
            #region 輸出結果
            DistanceResult mResult = null;
            #endregion

            HTuple hv_STD_Row;
            HTuple hv_STD_Col, hv_Img_Row, hv_Img_Col, hv_Img_Rotate_Angle;
            HTuple hv_OffsetRow, hv_OffsetCol;
            HOperatorSet.SetSystem("border_shape_models", "false");

            //STD 中心點
            hv_STD_Row = 839.5;
            hv_STD_Col = 1046.5;

            //目前圖形 中心點
            hv_Img_Row = hv_AllModelRow.Clone();
            hv_Img_Col = hv_AllModelColumn.Clone();

            //目前圖形 Rotate Angle
            hv_Img_Rotate_Angle = hv_AllModelAngle.Clone();

            //目前圖形偏移量
            hv_OffsetRow = hv_Img_Row - hv_STD_Row;
            hv_OffsetCol = hv_Img_Col - hv_STD_Col;

            //第一個 線段 ROI
            HTuple f_ROI_Row = 416.40625;
            HTuple f_ROI_Col = 752;
            HTuple f_angle = 0;
            HTuple f_ROI_Length1 = 56;
            HTuple f_ROI_Length2 = 256.25;

            HTuple f_angle_offset = f_angle - hv_Img_Rotate_Angle;
            HTuple f_ROI_Cur_Row, f_ROI_Cur_Col;
            PositionLocater.ReLocater(hv_STD_Row, hv_STD_Col, hv_AllModelAngle, hv_OffsetRow, hv_OffsetCol, f_ROI_Row, f_ROI_Col, out f_ROI_Cur_Row, out f_ROI_Cur_Col);

            //第二個 線段 ROI
            HTuple s_ROI_Row = 435.638671875;
            HTuple s_ROI_Col = 1429.16339869281;
            HTuple s_angle = 0;
            HTuple s_ROI_Length1 = 49.8594771241831;
            HTuple s_ROI_Length2 = 241.6796875;

            HTuple s_angle_offset = s_angle - hv_Img_Rotate_Angle;
            HTuple s_ROI_Cur_Row, s_ROI_Cur_Col;
            PositionLocater.ReLocater(hv_STD_Row, hv_STD_Col, hv_AllModelAngle, hv_OffsetRow, hv_OffsetCol
                    , s_ROI_Row, s_ROI_Col, out s_ROI_Cur_Row, out s_ROI_Cur_Col);

            #region Measure
            var cROIController = new ROIController();
            var cAssistant = new MeasureAssistant(cROIController);

            var hImage = ho_Image as HImage;
            cAssistant.setImage(hImage);

            /*參數值*/
            cAssistant.mThresh = 40.0;
            cAssistant.mSigma = 1.0;
            cAssistant.mRoiWidth = 10;
            cAssistant.mInterpolation = "nearest_neighbor";
            cAssistant.mSelPair = false;
            cAssistant.mTransition = "all";
            cAssistant.mPosition = "all";
            cAssistant.mDispEdgeLength = 30;
            cAssistant.mDispROIWidth = true;
            cAssistant.setUnit("cm");

            cAssistant.mInitThresh = 40.0;
            cAssistant.mInitSigma = 1.0;
            cAssistant.mInitRoiWidth = 10;

            var roiF = new ROIRectangle2() { ROIMeasureType = MeasureType.Line };
            //roiF.MakeROI(416, 998, 0, 26.5, 71.2);
            roiF.MakeROI(f_ROI_Cur_Row, f_ROI_Cur_Col, f_angle_offset, f_ROI_Length1, f_ROI_Length2);

            var roiS = new ROIRectangle2() { ROIMeasureType = MeasureType.Line };
            //roiS.MakeROI(400, 1041, 0, 13.3, 75.7);
            roiS.MakeROI(s_ROI_Cur_Row, s_ROI_Cur_Col, s_angle_offset, s_ROI_Length1, s_ROI_Length2);

            var lineF = new MeasurementEdge(roiF, cAssistant);
            var lineS = new MeasurementEdge(roiS, cAssistant);
            mResult = DistanceHelper.LineToLine(lineF, lineS, this.hv_AllModelAngle, LineDirection.Horizontal);

            #endregion

            return mResult;
        }
        public void SaveMacroPlanTest(string imagepath)
        {
            //assign
            var shapemodelpath = "filepath";
            var note = "note";
            var exportUnit = "mm";
            var image = new HImage(imagepath);

            var imageBinData = new Binary(ImageConventer.ConvertHalconImageToByteArray(image, false));

            var matchingParam = new MatchingParam();

            var matchingParamByteArray = ModelSerializer.DoSerialize(matchingParam);

            var matchingParamBinData = new Binary(matchingParamByteArray);

            BindingList<GeoDataGridViewModel> a = new BindingList<GeoDataGridViewModel>();
            a.Add(new GeoDataGridViewModel() { RecordID = "aaa" });

            var measureBinData = ModelSerializer.DoSerialize(a);
            //BindingList a;

            var ma = new MeasureAssistant();
            var maParam = ma.GetMeasureAssistantParam();
            var maParamBin = ModelSerializer.DoSerialize(maParam);

            LightChannel upper = new LightChannel() { Channel = "00", Intensity = 100, OnOff = LightSwitch.On };

            LightChannel bottom = new LightChannel() { Channel = "01", Intensity = 200, OnOff = LightSwitch.OFF };
            //act
            var success = SDMSRepo.SaveMacroPlan("Test", Guid.NewGuid().ToString(), shapemodelpath, note, imageBinData, exportUnit, matchingParamBinData, measureBinData, maParamBin, upper, bottom, new ShapeViewModel() { }, "system", "");

            //assert
            Assert.True(success);
        }
        public MeasureViewModel GetMidLine()
        {
            #region 輸出結果
            LineResult mResult = null;
            MeasureViewModel midLineModel = null;
            #endregion

            HTuple hv_STD_Row;
            HTuple hv_STD_Col, hv_Img_Row, hv_Img_Col, hv_Img_Rotate_Angle;
            HTuple hv_OffsetRow, hv_OffsetCol;
            HOperatorSet.SetSystem("border_shape_models", "false");

            //STD 中心點
            hv_STD_Row = 839.5;
            hv_STD_Col = 1046.5;

            //目前圖形 中心點
            hv_Img_Row = hv_AllModelRow.Clone();
            hv_Img_Col = hv_AllModelColumn.Clone();

            //目前圖形 Rotate Angle
            hv_Img_Rotate_Angle = hv_AllModelAngle.Clone();

            //目前圖形偏移量
            hv_OffsetRow = hv_Img_Row - hv_STD_Row;
            hv_OffsetCol = hv_Img_Col - hv_STD_Col;

            //第一個 線段 ROI
            HTuple f_ROI_Row = 528.064453125;
            HTuple f_ROI_Col = 802.751633986928;
            HTuple f_angle = 0;
            HTuple f_ROI_Length1 = 38.2679738562091;
            HTuple f_ROI_Length2 = 99.6328125;

            HTuple f_angle_offset = f_angle - hv_Img_Rotate_Angle;
            HTuple f_ROI_Cur_Row, f_ROI_Cur_Col;
            PositionLocater.ReLocater(hv_STD_Row, hv_STD_Col, hv_AllModelAngle, hv_OffsetRow, hv_OffsetCol, f_ROI_Row, f_ROI_Col, out f_ROI_Cur_Row, out f_ROI_Cur_Col);

            //第二個 線段 ROI
            HTuple s_ROI_Row = 523.408203125;
            HTuple s_ROI_Col = 853.542483660131;
            HTuple s_angle = 3.14159265358979;
            HTuple s_ROI_Length1 = 27.4509803921568;
            HTuple s_ROI_Length2 = 105.341796875;

            HTuple s_angle_offset = s_angle - hv_Img_Rotate_Angle;
            HTuple s_ROI_Cur_Row, s_ROI_Cur_Col;
            PositionLocater.ReLocater(hv_STD_Row, hv_STD_Col, hv_AllModelAngle, hv_OffsetRow, hv_OffsetCol
                    , s_ROI_Row, s_ROI_Col, out s_ROI_Cur_Row, out s_ROI_Cur_Col);

            #region Measure
            var cROIController = new ROIController();
            var cAssistant = new MeasureAssistant(cROIController);

            var hImage = ho_Image as HImage;
            cAssistant.setImage(hImage);

            /*參數值*/
            cAssistant.mThresh = 40.0;
            cAssistant.mSigma = 1.0;
            cAssistant.mRoiWidth = 10;
            cAssistant.mInterpolation = "bilinear";
            cAssistant.mSelPair = false;
            cAssistant.mTransition = "all";
            cAssistant.mPosition = "last";
            cAssistant.mDispEdgeLength = 30;
            cAssistant.mDispROIWidth = true;
            cAssistant.setUnit("cm");

            cAssistant.mInitThresh = 40.0;
            cAssistant.mInitSigma = 1.0;
            cAssistant.mInitRoiWidth = 10;

            var roiF = new ROIRectangle2() { ROIMeasureType = MeasureType.Line };
            //roiF.MakeROI(416, 998, 0, 26.5, 71.2);
            roiF.MakeROI(f_ROI_Cur_Row, f_ROI_Cur_Col, f_angle_offset, f_ROI_Length1, f_ROI_Length2);

            var roiS = new ROIRectangle2() { ROIMeasureType = MeasureType.Line };
            //roiS.MakeROI(400, 1041, 0, 13.3, 75.7);
            roiS.MakeROI(s_ROI_Cur_Row, s_ROI_Cur_Col, s_angle_offset, s_ROI_Length1, s_ROI_Length2);

            var lineF = new MeasurementEdge(roiF, cAssistant);
            var lineS = new MeasurementEdge(roiS, cAssistant);
            mResult = DistanceHelper.CalculateSymmetryLine(lineF.GetViewModel(), lineS.GetViewModel());
            //mResult = DistanceHelper.LineToLine(lineF, lineS, this.hv_AllModelAngle, LineDirection.Horizontal);

            midLineModel = new MeasureViewModel()
            {
                Row1 = mResult.Row1,
                Row2 = mResult.Row2,
                Col1 = mResult.Col1,
                Col2 = mResult.Col2,
                Distance = mResult.Distance,
            };

            //var firstModel = lineF.GetViewModel();
            //var secondModel = lineS.GetViewModel();
            //if (firstModel != null && secondModel != null && firstModel.Distance != null && secondModel.Distance != null
            //	&& firstModel.Distance.TupleLength() > 0 && secondModel.Distance.TupleLength() > 0)
            //{
            //	//作線段
            //	var centerRow = (f_ROI_Cur_Row + s_ROI_Cur_Row) / 2.0;
            //	var centerCol = (f_ROI_Cur_Col + s_ROI_Cur_Col) / 2.0;

            //	midLineModel = DistanceHelper.MakeLine(centerRow, centerCol, hv_AllModelAngle, mResult.Distance / 2.0);
            //}

            return midLineModel;
            #endregion
        }
 public MeasurementDistanceY(IMeasureGeoModel geoModelOne, IMeasureGeoModel geoModelTwo, MeasureAssistant mAssist)
     : base(null, mAssist)
 {
     initialize(geoModelOne, geoModelTwo, mAssist);
 }
 private void initialize(IMeasureGeoModel geoModelOne, IMeasureGeoModel geoModelTwo, MeasureAssistant mAssist)
 {
     _geoModelOne   = geoModelOne;
     _geoModelTwo   = geoModelTwo;
     ROIMeasureType = MeasureType.DistanceY;
     _ResultWorld   = new LineResult();
     UpdateResults();
 }
 /// <summary>
 /// Factory method to create measure objects
 /// </summary>
 /// <param name="roi">Interactive ROI</param>
 /// <param name="parent">
 /// Reference to measure controller class
 /// </param>
 /// <returns>New measure object</returns>
 public static Measurement CreateMeasure(ROI roi, MeasureAssistant parent)
 {
     Measurement mMeasurement = null;
     switch (roi.ROIMeasureType)
     {
         case MeasureType.Circle:
             mMeasurement = new MeasurementCircle(roi, parent);
             break;
         case MeasureType.Line:
             if (_doFitLineAlgo)
                 mMeasurement = new MeasurementFitLine(roi, parent);
             else
                 mMeasurement = new MeasurementEdge(roi, parent);
             break;
         case MeasureType.Point:
             if (roi is ViewROI.SmartROIs.SmartPoint)
             {
                 mMeasurement = new SmartMeasurements.AutoFitPoint(roi, parent);
             }
             else
             {
                 mMeasurement = new MeasurementEdge(roi, parent);
             }
             break;
         default:
             mMeasurement = new MeasurementEdge(roi, parent);
             break;
     }
     //if (parent.mSelPair)
     //	return new MeasurementPair(roi, parent);
     //else if (roi.ROIMeasureType == MeasureType.Circle)
     //{
     //	return new MeasurementCircle(roi, parent);
     //}
     //else
     //	return new MeasurementEdge(roi, parent);
     return mMeasurement;
 }