public void Show_PartSearchingDefinitions(IEnumerable <PartSearchingDefinition> partSearchingDefinitions)
        {
            foreach (var ed in partSearchingDefinitions)
            {
                var regionIndicator = new RegionIndicatorViewModel
                {
                    StartPointX     = ed.RoiLine.X1,
                    StartPointY     = ed.RoiLine.Y1,
                    EndPointX       = ed.RoiLine.X2,
                    EndPointY       = ed.RoiLine.Y2,
                    RegionWidth     = ed.RoiHalfWidth,
                    Stroke          = Brushes.Orange,
                    StrokeThickness = 4,
                    IsHidden        = false,
                };
                RegionIndicators.Add(regionIndicator);

                var regionIndicator2 = new RegionIndicatorViewModel
                {
                    StartPointX     = ed.AreaLine.X1,
                    StartPointY     = ed.AreaLine.Y1,
                    EndPointX       = ed.AreaLine.X2,
                    EndPointY       = ed.AreaLine.Y2,
                    RegionWidth     = ed.AreaHalfWidth,
                    Stroke          = Brushes.Orange,
                    StrokeThickness = 4,
                    IsHidden        = false,
                };
                RegionIndicators.Add(regionIndicator2);
            }
        }
        public void Show_RegionTargetResults(IEnumerable <RegionTargetResult> results)
        {
            foreach (var result in results)
            {
                if (result.HasError)
                {
                    continue;
                }

                var rect2   = result.TargetRegion.GetSmallestHRectangle2();
                var roiRect = rect2.GetRoiRectangle();

                if (result.Definition.Rect2Len1Line_DisplayEnabled)
                {
                    var line = roiRect.GetWidthLine();

                    var lineIndicator = new LineIndicatorViewModel
                    {
                        StartPointX     = line.X1,
                        StartPointY     = line.Y1,
                        EndPointX       = line.X2,
                        EndPointY       = line.Y2,
                        Stroke          = Brushes.DeepPink,
                        StrokeThickness = 2,
                    };
                    LineIndicators.Add(lineIndicator);
                }

                if (result.Definition.Rect2Len2Line_DisplayEnabled)
                {
                    var line = roiRect.GetLine();

                    var lineIndicator = new LineIndicatorViewModel
                    {
                        StartPointX     = line.X1,
                        StartPointY     = line.Y1,
                        EndPointX       = line.X2,
                        EndPointY       = line.Y2,
                        Stroke          = Brushes.DeepPink,
                        StrokeThickness = 2,
                    };
                    LineIndicators.Add(lineIndicator);
                }

                var regionIndicator2 = new RegionIndicatorViewModel
                {
                    StartPointX     = roiRect.StartX,
                    StartPointY     = roiRect.StartY,
                    EndPointX       = roiRect.EndX,
                    EndPointY       = roiRect.EndY,
                    RegionWidth     = roiRect.ROIWidth,
                    Stroke          = Brushes.Lime,
                    StrokeThickness = 2,
                    IsHidden        = false,
                };
                RegionIndicators.Add(regionIndicator2);
            }
        }
 public void Show_RegionTargetDefinitions(IEnumerable <RegionTargetDefinition> definitions)
 {
     foreach (var ed in definitions)
     {
         var regionIndicator = new RegionIndicatorViewModel
         {
             StartPointX     = ed.RoiActualLine.X1,
             StartPointY     = ed.RoiActualLine.Y1,
             EndPointX       = ed.RoiActualLine.X2,
             EndPointY       = ed.RoiActualLine.Y2,
             RegionWidth     = ed.RoiHalfWidth,
             Stroke          = Brushes.Orange,
             StrokeThickness = 4,
             IsHidden        = false,
         };
         RegionIndicators.Add(regionIndicator);
     }
 }
 public void Show_EdgeSearchingDefinitions(IEnumerable <EdgeSearchingDefinition> edgeSearchingDefinitions)
 {
     foreach (var ed in edgeSearchingDefinitions)
     {
         var regionIndicator = new RegionIndicatorViewModel
         {
             StartPointX     = ed.StartX,
             StartPointY     = ed.StartY,
             EndPointX       = ed.EndX,
             EndPointY       = ed.EndY,
             RegionWidth     = ed.ROIWidth,
             Stroke          = Brushes.Orange,
             StrokeThickness = 4,
             IsHidden        = false,
         };
         RegionIndicators.Add(regionIndicator);
     }
 }
        public void Show_PartSearchingResults(IEnumerable <PartSearchingResult> partSearchingResults)
        {
            foreach (var edgeSearchingResult in partSearchingResults)
            {
                if (edgeSearchingResult.HasError)
                {
                    continue;
                }

                var regionIndicator2 = new RegionIndicatorViewModel
                {
                    StartPointX     = edgeSearchingResult.PartLine.X1,
                    StartPointY     = edgeSearchingResult.PartLine.Y1,
                    EndPointX       = edgeSearchingResult.PartLine.X2,
                    EndPointY       = edgeSearchingResult.PartLine.Y2,
                    RegionWidth     = edgeSearchingResult.PartHalfWidth,
                    Stroke          = Brushes.Lime,
                    StrokeThickness = 2,
                    IsHidden        = false,
                };
                RegionIndicators.Add(regionIndicator2);
            }
        }
        private void Inspect(InspectionSchema schema)
        {
            //IndicatorViewer.Loaded += (sender, args) => IndicatorViewer.ZoomFit();
            //                        IndicatorViewer.Loaded += (sender, args) => IndicatorViewer.ZoomOut();

            RegionIndicators.Clear();
            LineIndicators.Clear();
            CircleIndicators.Clear();
            DefectIndicators.Clear();
            ObjectIndicators.Clear();

            BitmapSource bs;

            try
            {
                bs = new BitmapImage(new Uri(schema.TestImageFilePath, UriKind.RelativeOrAbsolute));
            }
            catch (FileNotFoundException e)
            {
                throw new HalconInspectorException("Image file not exist", e);
            }

            if (Math.Abs(bs.DpiX - 96) > 0.00001 || Math.Abs(bs.DpiY - 96) > 0.00001)
            {
                var sw1 = new NotifyStopwatch("BitmapSource convert to Dpi96");
                BitmapSourceInfo bsi = bs.ToGray8BppBitmapSourceInfo();
                bsi.DpiX = 96;
                bsi.DpiY = 96;
                var bitmapSourceDpi96 = bsi.GetBitmapSource();
                bs = bitmapSourceDpi96;
                sw1.Stop();
                sw1.Dispose();
            }

            IndicatorViewer.BitmapSource = bs;

            var sw2    = new NotifyStopwatch("BitmapSource.ToHImage()");
            var hImage = bs.ToHImage();

            sw2.Stop();
            sw2.Dispose();


            try
            {
                var sw = new NotifyStopwatch("InspectionController.Inspect()");
                InspectionController
                .SetInspectionSchema()
                .SetImage(hImage)
                .CreateCoordinate()
                .Inspect()
                ;
                sw.Stop();
                sw.Dispose();

                // CoordinateCircles
                Show_CircleSearchingDefinitions(
                    InspectionController.InspectionResult.GetCoordinateCircleSearchingDefinitions());
                Show_CircleSearchingResults(InspectionController.InspectionResult.CoordinateCircles);

                // Circles
                Show_CircleSearchingDefinitions(
                    InspectionController.InspectionResult.GetCircleSearchingDefinitions(), Brushes.Orange);
                Show_CircleSearchingResults(InspectionController.InspectionResult.Circles, Brushes.DodgerBlue);

                // CoordinateEdges
                Show_EdgeSearchingDefinitions(InspectionController.InspectionResult.GetCoordinateEdges());
                Show_EdgeSearchingResults(InspectionController.InspectionResult.CoordinateEdges);

                // Edges
                Show_EdgeSearchingDefinitions(InspectionController.InspectionResult.GetEdgeSearchingDefinitions());
                Show_EdgeSearchingResults(InspectionController.InspectionResult.Edges);

                // DistanceBetweenPoints
                Show_DistanceBetweenPointsResults(InspectionController.InspectionResult.DistanceBetweenPointsResults);

                // Defects
                Show_DefectResults(InspectionController.InspectionResult.RegionDefectResults);

                // Parts
                Show_PartSearchingDefinitions(InspectionController.InspectionResult.GetPartSearchingDefinitions());
                Show_PartSearchingResults(InspectionController.InspectionResult.Parts);

                // RegionTargets
                Show_RegionTargetDefinitions(InspectionController.InspectionResult.GetRegionTargetDefinitions());
                Show_RegionTargetResults(InspectionController.InspectionResult.RegionTargets);
            }
            catch (CreateCoordinateFailedException e)
            {
                Show_CircleSearchingDefinitions(
                    InspectionController.InspectionResult.GetCoordinateCircleSearchingDefinitions());
                Show_CircleSearchingResults(InspectionController.InspectionResult.CoordinateCircles);

                Show_EdgeSearchingDefinitions(InspectionController.InspectionResult.GetCoordinateEdges());
                Show_EdgeSearchingResults(InspectionController.InspectionResult.CoordinateEdges);

                MessageBox.Show(e.Message);
            }
        }