alvin.chen
2019-11-29 edf127edc771f715c49f86e91e768633f0a0ed93
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
using System;
using HalconDotNet;
 
 
namespace HalconTools
{
 
    /// <summary>
    /// This class is a base class containing virtual methods for handling
    /// ROIs. Therefore, an inheriting class needs to define/override these
    /// methods to provide the ROIController with the necessary information on
    /// its (= the ROIs) shape and position. The example project provides 
    /// derived ROI shapes for rectangles, lines, circles, and circular arcs.
    /// To use other shapes you must derive a new class from the base class 
    /// ROI and implement its methods.
    /// </summary>    
    public class ROI
    {
 
        // class members of inheriting ROI classes
        protected int   NumHandles;
        protected int    activeHandleIdx;
 
        /// <summary>
        /// Flag to define the ROI to be 'positive' or 'negative'.
        /// </summary>
        protected int     OperatorFlag;
 
        /// <summary>Parameter to define the line style of the ROI.</summary>
        public HTuple     flagLineStyle;
 
        /// <summary>Constant for a positive ROI flag.</summary>
        public const int  POSITIVE_FLAG    = ROIController.MODE_ROI_POS;
 
        /// <summary>Constant for a negative ROI flag.</summary>
        public const int  NEGATIVE_FLAG    = ROIController.MODE_ROI_NEG;
 
        public const int  ROI_TYPE_LINE       = 10;
        public const int  ROI_TYPE_CIRCLE     = 11;
        public const int  ROI_TYPE_CIRCLEARC  = 12;
        public const int  ROI_TYPE_RECTANCLE1 = 13;
        public const int  ROI_TYPE_RECTANGLE2 = 14;
 
 
        protected HTuple  posOperation = new HTuple();
        protected HTuple  negOperation = new HTuple(new int[] { 2, 2 });
 
        /// <summary>Constructor of abstract ROI class.</summary>
        public ROI() { }
 
        /// <summary>Creates a new ROI instance at the mouse position.</summary>
        /// <param name="midX">
        /// x (=column) coordinate for ROI
        /// </param>
        /// <param name="midY">
        /// y (=row) coordinate for ROI
        /// </param>
        public virtual void createROI(double midX, double midY) { }
 
        /// <summary>Paints the ROI into the supplied window.</summary>
        /// <param name="window">HALCON window</param>
        public virtual void draw(HalconDotNet.HWindow window) { }
 
        /// <summary> 
        /// Returns the distance of the ROI handle being
        /// closest to the image point(x,y)
        /// </summary>
        /// <param name="x">x (=column) coordinate</param>
        /// <param name="y">y (=row) coordinate</param>
        /// <returns> 
        /// Distance of the closest ROI handle.
        /// </returns>
        public virtual double distToClosestHandle(double x, double y)
        {
            return 0.0;
        }
 
        /// <summary> 
        /// Paints the active handle of the ROI object into the supplied window. 
        /// </summary>
        /// <param name="window">HALCON window</param>
        public virtual void displayActive(HalconDotNet.HWindow window) { }
 
        /// <summary> 
        /// Recalculates the shape of the ROI. Translation is 
        /// performed at the active handle of the ROI object 
        /// for the image coordinate (x,y).
        /// </summary>
        /// <param name="x">x (=column) coordinate</param>
        /// <param name="y">y (=row) coordinate</param>
        public virtual void moveByHandle(double x, double y) { }
 
        /// <summary>Gets the HALCON region described by the ROI.</summary>
        public virtual HRegion getRegion()
        {
            return null;
        }
 
        public virtual double getDistanceFromStartPoint(double row, double col)
        {
            return 0.0;
        }
        /// <summary>
        /// Gets the model information described by 
        /// the ROI.
        /// </summary> 
        public virtual HTuple getModelData()
        {
            return null;
        }
 
        /// <summary>Number of handles defined for the ROI.</summary>
        /// <returns>Number of handles</returns>
        public int getNumHandles()
        {
            return NumHandles;
        }
 
        /// <summary>Gets the active handle of the ROI.</summary>
        /// <returns>Index of the active handle (from the handle list)</returns>
        public int getActHandleIdx()
        {
            return activeHandleIdx;
        }
 
        /// <summary>
        /// Gets the sign of the ROI object, being either 
        /// 'positive' or 'negative'. This sign is used when creating a model
        /// region for matching applications from a list of ROIs.
        /// </summary>
        public int getOperatorFlag()
        {
            return OperatorFlag;
        }
 
        /// <summary>
        /// Sets the sign of a ROI object to be positive or negative. 
        /// The sign is used when creating a model region for matching
        /// applications by summing up all positive and negative ROI models
        /// created so far.
        /// </summary>
        /// <param name="flag">Sign of ROI object</param>
        public void setOperatorFlag(int flag)
        {
            OperatorFlag = flag;
 
            switch (OperatorFlag)
            {
                case ROI.POSITIVE_FLAG:
                    flagLineStyle = posOperation;
                    break;
                case ROI.NEGATIVE_FLAG:
                    flagLineStyle = negOperation;
                    break;
                default:
                    flagLineStyle = posOperation;
                    break;
            }
        }
    }//end of class
}//end of namespace