using System;
using HalconDotNet;
namespace ViewWindow.Model
{
///
/// 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.
///
[Serializable]
public class ROI
{
private string color = "yellow";
public string Color
{
get { return this.color; }
set { this.color = value; }
}
private string _type;
public string Type
{
get
{
return this._type ;
}
set
{
this._type = value;
}
}
// class members of inheriting ROI classes
protected int NumHandles;
protected int activeHandleIdx;
///
/// Flag to define the ROI to be 'positive' or 'negative'.
///
protected int OperatorFlag;
/// Parameter to define the line style of the ROI.
public HTuple flagLineStyle;
/// Constant for a positive ROI flag.
public const int POSITIVE_FLAG = ROIController.MODE_ROI_POS;
/// Constant for a negative ROI flag.
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 });
/// Constructor of abstract ROI class.
public ROI() { }
public virtual void createRectangle1(double row1, double col1, double row2, double col2) { }
public virtual void createRectangle2(double row, double col, double phi, double length1, double length2) { }
public virtual void createCircle(double row,double col,double radius) { }
public virtual void createLine(double beginRow, double beginCol, double endRow, double endCol) { }
/// Creates a new ROI instance at the mouse position.
///
/// x (=column) coordinate for ROI
///
///
/// y (=row) coordinate for ROI
///
public virtual void createROI(double midX, double midY) { }
/// Paints the ROI into the supplied window.
/// HALCON window
public virtual void draw(HalconDotNet.HWindow window) { }
///
/// Returns the distance of the ROI handle being
/// closest to the image point(x,y)
///
/// x (=column) coordinate
/// y (=row) coordinate
///
/// Distance of the closest ROI handle.
///
public virtual double distToClosestHandle(double x, double y)
{
return 0.0;
}
///
/// Paints the active handle of the ROI object into the supplied window.
///
/// HALCON window
public virtual void displayActive(HalconDotNet.HWindow window) { }
///
/// Recalculates the shape of the ROI. Translation is
/// performed at the active handle of the ROI object
/// for the image coordinate (x,y).
///
/// x (=column) coordinate
/// y (=row) coordinate
public virtual void moveByHandle(double x, double y) { }
/// Gets the HALCON region described by the ROI.
public virtual HRegion getRegion()
{
return null;
}
public virtual double getDistanceFromStartPoint(double row, double col)
{
return 0.0;
}
///
/// Gets the model information described by
/// the ROI.
///
public virtual HTuple getModelData()
{
return null;
}
/// Number of handles defined for the ROI.
/// Number of handles
public int getNumHandles()
{
return NumHandles;
}
/// Gets the active handle of the ROI.
/// Index of the active handle (from the handle list)
public int getActHandleIdx()
{
return activeHandleIdx;
}
///
/// 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.
///
public int getOperatorFlag()
{
return OperatorFlag;
}
///
/// 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.
///
/// Sign of ROI object
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