mirror of
https://github.com/eggplantlwj/VisionEdit.git
synced 2026-03-28 19:26:35 +08:00
传输优化
This commit is contained in:
@@ -33,7 +33,7 @@ namespace ViewWindow.Config
|
||||
set { this._radius = value; }
|
||||
}
|
||||
|
||||
private string color = "yellow";
|
||||
private string color = "blue";
|
||||
[XmlElement(ElementName = "Color")]
|
||||
public string Color
|
||||
{
|
||||
|
||||
@@ -47,7 +47,7 @@ namespace ViewROI.Config
|
||||
set { this._extentPhi = value; }
|
||||
}
|
||||
|
||||
private string color = "yellow";
|
||||
private string color = "blue";
|
||||
[XmlElement(ElementName = "Color")]
|
||||
public string Color
|
||||
{
|
||||
|
||||
@@ -40,7 +40,7 @@ namespace ViewWindow.Config
|
||||
get { return this._columnEnd; }
|
||||
set { this._columnEnd = value; }
|
||||
}
|
||||
private string color = "yellow";
|
||||
private string color = "blue";
|
||||
[XmlElement(ElementName = "Color")]
|
||||
public string Color
|
||||
{
|
||||
|
||||
@@ -41,7 +41,7 @@ namespace ViewWindow.Config
|
||||
get { return this._column2; }
|
||||
set { this._column2 = value; }
|
||||
}
|
||||
private string color = "yellow";
|
||||
private string color = "blue";
|
||||
[XmlElement(ElementName = "Color")]
|
||||
public string Color
|
||||
{
|
||||
|
||||
@@ -48,7 +48,7 @@ namespace ViewWindow.Config
|
||||
get { return this._lenth2; }
|
||||
set { this._lenth2 = value; }
|
||||
}
|
||||
private string color = "yellow";
|
||||
private string color = "blue";
|
||||
|
||||
[XmlElement(ElementName = "Color")]
|
||||
public string Color
|
||||
|
||||
96
ImageWindow/HWindowTool_Smart.Designer.cs
generated
Normal file
96
ImageWindow/HWindowTool_Smart.Designer.cs
generated
Normal file
@@ -0,0 +1,96 @@
|
||||
namespace ViewROI
|
||||
{
|
||||
partial class HWindowTool_Smart
|
||||
{
|
||||
/// <summary>
|
||||
/// 必需的设计器变量。
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// 清理所有正在使用的资源。
|
||||
/// </summary>
|
||||
/// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region 组件设计器生成的代码
|
||||
|
||||
/// <summary>
|
||||
/// 设计器支持所需的方法 - 不要修改
|
||||
/// 使用代码编辑器修改此方法的内容。
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
this.SmartWindow = new HalconDotNet.HSmartWindowControl();
|
||||
this.statusStrip = new System.Windows.Forms.StatusStrip();
|
||||
this.lb_Status = new System.Windows.Forms.ToolStripStatusLabel();
|
||||
this.statusStrip.SuspendLayout();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// SmartWindow
|
||||
//
|
||||
this.SmartWindow.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
|
||||
this.SmartWindow.AutoValidate = System.Windows.Forms.AutoValidate.EnableAllowFocusChange;
|
||||
this.SmartWindow.Dock = System.Windows.Forms.DockStyle.Fill;
|
||||
this.SmartWindow.HDoubleClickToFitContent = true;
|
||||
this.SmartWindow.HDrawingObjectsModifier = HalconDotNet.HSmartWindowControl.DrawingObjectsModifier.None;
|
||||
this.SmartWindow.HImagePart = new System.Drawing.Rectangle(0, 0, 640, 480);
|
||||
this.SmartWindow.HKeepAspectRatio = true;
|
||||
this.SmartWindow.HMoveContent = true;
|
||||
this.SmartWindow.HZoomContent = HalconDotNet.HSmartWindowControl.ZoomContent.WheelForwardZoomsIn;
|
||||
this.SmartWindow.Location = new System.Drawing.Point(0, 0);
|
||||
this.SmartWindow.Margin = new System.Windows.Forms.Padding(0);
|
||||
this.SmartWindow.Name = "SmartWindow";
|
||||
this.SmartWindow.Size = new System.Drawing.Size(576, 457);
|
||||
this.SmartWindow.TabIndex = 0;
|
||||
this.SmartWindow.WindowSize = new System.Drawing.Size(576, 457);
|
||||
this.SmartWindow.HMouseMove += new HalconDotNet.HMouseEventHandler(this.SmartWindow_HMouseMove);
|
||||
//
|
||||
// statusStrip
|
||||
//
|
||||
this.statusStrip.BackColor = System.Drawing.Color.White;
|
||||
this.statusStrip.Font = new System.Drawing.Font("微软雅黑", 10.5F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
|
||||
this.statusStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
|
||||
this.lb_Status});
|
||||
this.statusStrip.Location = new System.Drawing.Point(0, 435);
|
||||
this.statusStrip.Name = "statusStrip";
|
||||
this.statusStrip.Size = new System.Drawing.Size(576, 22);
|
||||
this.statusStrip.TabIndex = 1;
|
||||
this.statusStrip.Text = "statusStrip1";
|
||||
//
|
||||
// lb_Status
|
||||
//
|
||||
this.lb_Status.Font = new System.Drawing.Font("微软雅黑", 10.5F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
|
||||
this.lb_Status.Name = "lb_Status";
|
||||
this.lb_Status.Size = new System.Drawing.Size(0, 17);
|
||||
//
|
||||
// HWindowTool_Smart
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.Controls.Add(this.statusStrip);
|
||||
this.Controls.Add(this.SmartWindow);
|
||||
this.Name = "HWindowTool_Smart";
|
||||
this.Size = new System.Drawing.Size(576, 457);
|
||||
this.Load += new System.EventHandler(this.HWindowTool_Smart_Load);
|
||||
this.SizeChanged += new System.EventHandler(this.HWindowTool_Smart_SizeChanged);
|
||||
this.statusStrip.ResumeLayout(false);
|
||||
this.statusStrip.PerformLayout();
|
||||
this.ResumeLayout(false);
|
||||
this.PerformLayout();
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
private System.Windows.Forms.StatusStrip statusStrip;
|
||||
private System.Windows.Forms.ToolStripStatusLabel lb_Status;
|
||||
public HalconDotNet.HSmartWindowControl SmartWindow;
|
||||
}
|
||||
}
|
||||
60
ImageWindow/HWindowTool_Smart.cs
Normal file
60
ImageWindow/HWindowTool_Smart.cs
Normal file
@@ -0,0 +1,60 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Drawing;
|
||||
using System.Data;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Windows.Forms;
|
||||
using HalconDotNet;
|
||||
|
||||
namespace ViewROI
|
||||
{
|
||||
public partial class HWindowTool_Smart : UserControl
|
||||
{
|
||||
public bool DispStatus { get; set; }
|
||||
public HImage hv_Image { get; set; }
|
||||
public HWindowTool_Smart()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
public void DispImage(HObject inputImage)
|
||||
{
|
||||
statusStrip.BackColor = Color.White;
|
||||
if (inputImage == null || !inputImage.IsInitialized())
|
||||
{
|
||||
this.lb_Status.Text = "输入图像为空,请检查!";
|
||||
statusStrip.BackColor = Color.Red;
|
||||
return;
|
||||
}
|
||||
this.SmartWindow.HalconWindow.DispImage(new HImage(inputImage));
|
||||
}
|
||||
|
||||
private void SmartWindow_HMouseMove(object sender, HalconDotNet.HMouseEventArgs e)
|
||||
{
|
||||
if(DispStatus)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private void HWindowTool_Smart_Load(object sender, EventArgs e)
|
||||
{
|
||||
this.MouseWheel += HWindowTool_Smart_MouseWheel;
|
||||
}
|
||||
|
||||
private void HWindowTool_Smart_MouseWheel(object sender, MouseEventArgs e)
|
||||
{
|
||||
Point pt = SmartWindow.Location;
|
||||
MouseEventArgs newe = new MouseEventArgs(e.Button, e.Clicks, e.X - pt.X, e.Y - pt.Y, e.Delta);
|
||||
SmartWindow.HSmartWindowControl_MouseWheel(sender, newe);
|
||||
}
|
||||
|
||||
private void HWindowTool_Smart_SizeChanged(object sender, EventArgs e)
|
||||
{
|
||||
//Point pt = SmartWindow.Location;
|
||||
//Point pt2 = SmartWindow.PointToScreen(pt);
|
||||
//this.SmartWindow.HalconWindow.SendMouseDoubleClickEvent(pt2.X+20, pt2.Y+30,(int)MouseButtons.Left);
|
||||
}
|
||||
}
|
||||
}
|
||||
123
ImageWindow/HWindowTool_Smart.resx
Normal file
123
ImageWindow/HWindowTool_Smart.resx
Normal file
@@ -0,0 +1,123 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
associated with the data types.
|
||||
|
||||
Example:
|
||||
|
||||
... ado.net/XML headers & schema ...
|
||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||
<resheader name="version">2.0</resheader>
|
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||
</data>
|
||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||
<comment>This is a comment</comment>
|
||||
</data>
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
name/value pairs.
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
mimetype set.
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
extensible. For a given mimetype the value must be set accordingly:
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
read any of the formats listed below.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||
value : The object must be serialized into a byte array
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<metadata name="statusStrip.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>17, 17</value>
|
||||
</metadata>
|
||||
</root>
|
||||
@@ -14,10 +14,12 @@ using System.Text;
|
||||
using System.Windows.Forms;
|
||||
|
||||
using HalconDotNet;
|
||||
using System.Threading;
|
||||
|
||||
|
||||
namespace ChoiceTech.Halcon.Control
|
||||
{
|
||||
public delegate void DoubleClick();
|
||||
/// <summary>
|
||||
/// halcon鼠标缩放控件
|
||||
///
|
||||
@@ -31,9 +33,7 @@ namespace ChoiceTech.Halcon.Control
|
||||
#region 私有变量定义.
|
||||
|
||||
private HWindow /**/ hv_window; //halcon窗体控件的句柄 this.mCtrl_HWindow.HalconWindow;
|
||||
private ContextMenuStrip /**/ hv_MenuStrip; //右键菜单控件
|
||||
// 窗体控件右键菜单内容
|
||||
ToolStripMenuItem fit_strip;
|
||||
ToolStripMenuItem saveImg_strip;
|
||||
ToolStripMenuItem saveWindow_strip;
|
||||
ToolStripMenuItem barVisible_strip;
|
||||
@@ -42,7 +42,6 @@ namespace ChoiceTech.Halcon.Control
|
||||
private HImage /**/ hv_image; //缩放时操作的图片 此处千万不要使用hv_image = new HImage(),不然在生成控件dll的时候,会导致无法序列化,去你妈隔壁,还好老子有版本控制,不然都找不到这种恶心问题
|
||||
private int /**/ hv_imageWidth, hv_imageHeight; //图片宽,高
|
||||
private string /**/ str_imgSize; //图片尺寸大小 5120X3840
|
||||
private HTuple str_channel; //通道数
|
||||
private bool /**/ drawModel = false; //绘制模式下,不允许缩放和鼠标右键菜单
|
||||
|
||||
public ViewWindow.ViewWindow viewWindow; /**/ //ViewWindow
|
||||
@@ -68,9 +67,6 @@ namespace ChoiceTech.Halcon.Control
|
||||
//
|
||||
// hv_window.SetMshape("Hourglass");
|
||||
|
||||
fit_strip = new ToolStripMenuItem("适应窗口");
|
||||
fit_strip.Click += new EventHandler((s, e) => DispImageFit(mCtrl_HWindow));
|
||||
|
||||
barVisible_strip = new ToolStripMenuItem("显示StatusBar");
|
||||
barVisible_strip.CheckOnClick = true;
|
||||
barVisible_strip.CheckedChanged += new EventHandler(barVisible_strip_CheckedChanged);
|
||||
@@ -87,21 +83,14 @@ namespace ChoiceTech.Halcon.Control
|
||||
histogram_strip.CheckOnClick = true;
|
||||
histogram_strip.Checked = false;
|
||||
|
||||
hv_MenuStrip = new ContextMenuStrip();
|
||||
hv_MenuStrip.Items.Add(fit_strip);
|
||||
hv_MenuStrip.Items.Add(barVisible_strip);
|
||||
hv_MenuStrip.Items.Add(new ToolStripSeparator());
|
||||
hv_MenuStrip.Items.Add(saveImg_strip);
|
||||
hv_MenuStrip.Items.Add(saveWindow_strip);
|
||||
|
||||
|
||||
barVisible_strip.Enabled = true;
|
||||
fit_strip.Enabled = false;
|
||||
histogram_strip.Enabled = false;
|
||||
saveImg_strip.Enabled = false;
|
||||
saveWindow_strip.Enabled = false;
|
||||
|
||||
mCtrl_HWindow.ContextMenuStrip = hv_MenuStrip;
|
||||
mCtrl_HWindow.SizeChanged += new EventHandler((s, e) => DispImageFit(mCtrl_HWindow));
|
||||
mCtrl_HWindow.SizeChanged += new EventHandler((s, e) => DispImageFit());
|
||||
|
||||
}
|
||||
|
||||
@@ -116,17 +105,6 @@ namespace ChoiceTech.Halcon.Control
|
||||
{
|
||||
//缩放控制
|
||||
viewWindow.setDrawModel(value);
|
||||
//绘制模式 不现实右键
|
||||
if (value == true)
|
||||
{
|
||||
|
||||
mCtrl_HWindow.ContextMenuStrip = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
//恢复
|
||||
mCtrl_HWindow.ContextMenuStrip = hv_MenuStrip;
|
||||
}
|
||||
drawModel = value;
|
||||
}
|
||||
}
|
||||
@@ -149,7 +127,8 @@ namespace ChoiceTech.Halcon.Control
|
||||
/// </summary>
|
||||
public HImage Image
|
||||
{
|
||||
get {
|
||||
get
|
||||
{
|
||||
return this.hv_image;
|
||||
}
|
||||
set
|
||||
@@ -158,20 +137,17 @@ namespace ChoiceTech.Halcon.Control
|
||||
{
|
||||
if (this.hv_image != null)
|
||||
{
|
||||
this.hv_image.Dispose();
|
||||
this.hv_image.Dispose();
|
||||
}
|
||||
|
||||
this.hv_image = value;
|
||||
hv_image.GetImageSize(out hv_imageWidth, out hv_imageHeight);
|
||||
HOperatorSet.CountChannels(hv_image ,out str_channel );
|
||||
str_imgSize = String.Format("{0}X{1}", hv_imageWidth, hv_imageHeight);
|
||||
str_channel = string.Format("C{0}",str_channel );
|
||||
|
||||
//DispImageFit(mCtrl_HWindow);
|
||||
try
|
||||
{
|
||||
barVisible_strip.Enabled = true;
|
||||
fit_strip.Enabled = true;
|
||||
histogram_strip.Enabled = true;
|
||||
saveImg_strip.Enabled = true;
|
||||
saveWindow_strip.Enabled = true;
|
||||
@@ -180,6 +156,34 @@ namespace ChoiceTech.Halcon.Control
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
|
||||
int W, H, w, h;
|
||||
W = this.Width;
|
||||
H = this.Height;
|
||||
w = hv_imageWidth;
|
||||
h = hv_imageHeight;
|
||||
|
||||
|
||||
|
||||
//if (w * 1.0 / W < h * 1.0 / H)
|
||||
//{
|
||||
// HOperatorSet.SetPart(this.HWindowHalconID, 0, -(h * W / H - w) / 2, h, w + (h * W / H - w) / 2);
|
||||
//}
|
||||
//else if (w * 1.0 / W > h * 1.0 / H)
|
||||
//{
|
||||
// HOperatorSet.SetPart(this.HWindowHalconID, (h - w * H / H) / 2, 0, h - (h - w * H / H) / 2, w);
|
||||
//}
|
||||
//else
|
||||
//{
|
||||
// HOperatorSet.SetPart(this.HWindowHalconID, 0, 0, H, W);
|
||||
//}
|
||||
|
||||
|
||||
|
||||
// HOperatorSet.SetPart(this.HWindowHalconID, 0, 0, 3844, 4000);
|
||||
|
||||
|
||||
viewWindow.displayImage(hv_image);
|
||||
}
|
||||
}
|
||||
@@ -203,7 +207,7 @@ namespace ChoiceTech.Halcon.Control
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
void barVisible_strip_CheckedChanged(object sender, EventArgs e)
|
||||
public void barVisible_strip_CheckedChanged(object sender, EventArgs e)
|
||||
{
|
||||
ToolStripMenuItem strip = sender as ToolStripMenuItem;
|
||||
|
||||
@@ -218,7 +222,7 @@ namespace ChoiceTech.Halcon.Control
|
||||
else
|
||||
{
|
||||
m_CtrlHStatusLabelCtrl.Visible = false;
|
||||
//mCtrl_HWindow.Height = this.Height;
|
||||
// mCtrl_HWindow.Height = this.Height;
|
||||
mCtrl_HWindow.HMouseMove -= HWindowControl_HMouseMove;
|
||||
}
|
||||
|
||||
@@ -274,7 +278,7 @@ namespace ChoiceTech.Halcon.Control
|
||||
/// 图片适应大小显示在窗体
|
||||
/// </summary>
|
||||
/// <param name="hw_Ctrl">halcon窗体控件</param>
|
||||
private void DispImageFit(HWindowControl hw_Ctrl)
|
||||
public void DispImageFit()
|
||||
{
|
||||
|
||||
try
|
||||
@@ -310,7 +314,7 @@ namespace ChoiceTech.Halcon.Control
|
||||
HOperatorSet.CountChannels(hv_image, out channel_count);
|
||||
|
||||
hv_window.GetMpositionSubPix(out positionY, out positionX, out button_state);
|
||||
str_position = String.Format("R: {0:0000.0}, C: {1:0000.0}", positionY, positionX);
|
||||
str_position = String.Format("RC: {0:0000},{1:0000}", positionY, positionX);
|
||||
|
||||
_isXOut = (positionX < 0 || positionX >= hv_imageWidth);
|
||||
_isYOut = (positionY < 0 || positionY >= hv_imageHeight);
|
||||
@@ -319,9 +323,9 @@ namespace ChoiceTech.Halcon.Control
|
||||
{
|
||||
if ((int)channel_count == 1)
|
||||
{
|
||||
int grayVal;
|
||||
double grayVal;
|
||||
grayVal = hv_image.GetGrayval((int)positionY, (int)positionX);
|
||||
str_value = String.Format("V: {0:000}", grayVal);
|
||||
str_value = String.Format("Val: {0:000}", grayVal);
|
||||
}
|
||||
else if ((int)channel_count == 3)
|
||||
{
|
||||
@@ -341,13 +345,13 @@ namespace ChoiceTech.Halcon.Control
|
||||
_GreenChannel.Dispose();
|
||||
_BlueChannel.Dispose();
|
||||
|
||||
str_value = String.Format("V: ({0:000.0}, {1:000.0}, {2:000.0})", grayValRed, grayValGreen, grayValBlue);
|
||||
str_value = String.Format("Gray: ({0:000}, {1:000}, {2:000})", grayValRed, grayValGreen, grayValBlue);
|
||||
}
|
||||
else
|
||||
{
|
||||
str_value = "";
|
||||
}
|
||||
m_CtrlHStatusLabelCtrl.Text = str_channel +" "+str_imgSize + " " + str_position + " " + str_value;
|
||||
m_CtrlHStatusLabelCtrl.Text = string.Format("Ch:{0} ", channel_count.ToDArr()) + str_imgSize + " " + str_position + " " + str_value;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
@@ -367,7 +371,6 @@ namespace ChoiceTech.Halcon.Control
|
||||
//this.hv_image = null;
|
||||
m_CtrlHStatusLabelCtrl.Visible = false;
|
||||
barVisible_strip.Enabled = false;
|
||||
fit_strip.Enabled = false;
|
||||
histogram_strip.Enabled = false;
|
||||
saveImg_strip.Enabled = false;
|
||||
saveWindow_strip.Enabled = false;
|
||||
@@ -413,10 +416,10 @@ namespace ChoiceTech.Halcon.Control
|
||||
public void DispObj(HObject hObj)
|
||||
{
|
||||
|
||||
lock (this)
|
||||
{
|
||||
viewWindow.displayHobject(hObj, null);
|
||||
}
|
||||
lock (this)
|
||||
{
|
||||
viewWindow.displayHobject(hObj, null);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -452,6 +455,45 @@ namespace ChoiceTech.Halcon.Control
|
||||
}
|
||||
|
||||
|
||||
|
||||
public event DoubleClick doubleClick;
|
||||
|
||||
private void mCtrl_HWindow_Click(object sender, EventArgs e)
|
||||
{
|
||||
|
||||
}
|
||||
int i = 0;
|
||||
private void mCtrl_HWindow_HMouseDown(object sender, HMouseEventArgs e)
|
||||
{
|
||||
i += 1;
|
||||
|
||||
System.Windows.Forms.Timer timer = new System.Windows.Forms.Timer();
|
||||
|
||||
timer.Interval = 300;
|
||||
|
||||
timer.Tick += (s, e1) => { timer.Enabled = false; i = 0; };
|
||||
|
||||
timer.Enabled = true;
|
||||
|
||||
if (i % 2 == 0)
|
||||
{
|
||||
|
||||
timer.Enabled = false;
|
||||
|
||||
i = 0;
|
||||
|
||||
if (doubleClick != null)
|
||||
doubleClick();
|
||||
|
||||
Application.DoEvents();
|
||||
Thread.Sleep(5);
|
||||
DispImageFit();
|
||||
//this.WindowState = (this.WindowState == FormWindowState.Maximized ? FormWindowState.Normal : FormWindowState.Maximized);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
15
ImageWindow/HWindow_Final.designer.cs
generated
15
ImageWindow/HWindow_Final.designer.cs
generated
@@ -16,7 +16,6 @@
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
hv_MenuStrip.Dispose();
|
||||
|
||||
mCtrl_HWindow.HMouseMove -= HWindowControl_HMouseMove;
|
||||
}
|
||||
@@ -48,11 +47,11 @@
|
||||
//
|
||||
// m_CtrlHStatusLabelCtrl
|
||||
//
|
||||
this.m_CtrlHStatusLabelCtrl.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
|
||||
this.m_CtrlHStatusLabelCtrl.AutoSize = true;
|
||||
this.m_CtrlHStatusLabelCtrl.Dock = System.Windows.Forms.DockStyle.Bottom;
|
||||
this.m_CtrlHStatusLabelCtrl.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
|
||||
this.m_CtrlHStatusLabelCtrl.ForeColor = System.Drawing.SystemColors.WindowText;
|
||||
this.m_CtrlHStatusLabelCtrl.Location = new System.Drawing.Point(3, 498);
|
||||
this.m_CtrlHStatusLabelCtrl.Location = new System.Drawing.Point(0, 385);
|
||||
this.m_CtrlHStatusLabelCtrl.Margin = new System.Windows.Forms.Padding(3);
|
||||
this.m_CtrlHStatusLabelCtrl.Name = "m_CtrlHStatusLabelCtrl";
|
||||
this.m_CtrlHStatusLabelCtrl.Size = new System.Drawing.Size(0, 17);
|
||||
@@ -75,10 +74,12 @@
|
||||
this.mCtrl_HWindow.Location = new System.Drawing.Point(0, 0);
|
||||
this.mCtrl_HWindow.Margin = new System.Windows.Forms.Padding(0);
|
||||
this.mCtrl_HWindow.Name = "mCtrl_HWindow";
|
||||
this.mCtrl_HWindow.Size = new System.Drawing.Size(562, 518);
|
||||
this.mCtrl_HWindow.Size = new System.Drawing.Size(536, 402);
|
||||
this.mCtrl_HWindow.TabIndex = 0;
|
||||
this.mCtrl_HWindow.WindowSize = new System.Drawing.Size(562, 518);
|
||||
this.mCtrl_HWindow.WindowSize = new System.Drawing.Size(536, 402);
|
||||
this.mCtrl_HWindow.HMouseMove += new HalconDotNet.HMouseEventHandler(this.HWindowControl_HMouseMove);
|
||||
this.mCtrl_HWindow.HMouseDown += new HalconDotNet.HMouseEventHandler(this.mCtrl_HWindow_HMouseDown);
|
||||
this.mCtrl_HWindow.Click += new System.EventHandler(this.mCtrl_HWindow_Click);
|
||||
this.mCtrl_HWindow.MouseLeave += new System.EventHandler(this.mCtrl_HWindow_MouseLeave);
|
||||
//
|
||||
// HWindow_Final
|
||||
@@ -90,7 +91,7 @@
|
||||
this.Controls.Add(this.m_CtrlHStatusLabelCtrl);
|
||||
this.Controls.Add(this.mCtrl_HWindow);
|
||||
this.Name = "HWindow_Final";
|
||||
this.Size = new System.Drawing.Size(562, 518);
|
||||
this.Size = new System.Drawing.Size(536, 402);
|
||||
this.ResumeLayout(false);
|
||||
this.PerformLayout();
|
||||
|
||||
@@ -98,8 +99,8 @@
|
||||
|
||||
#endregion
|
||||
|
||||
private System.Windows.Forms.Label m_CtrlHStatusLabelCtrl;
|
||||
private System.Windows.Forms.ImageList m_CtrlImageList;
|
||||
private HalconDotNet.HWindowControl mCtrl_HWindow;
|
||||
public System.Windows.Forms.Label m_CtrlHStatusLabelCtrl;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -125,7 +125,7 @@
|
||||
AAEAAAD/////AQAAAAAAAAAMAgAAAFdTeXN0ZW0uV2luZG93cy5Gb3JtcywgVmVyc2lvbj0yLjAuMC4w
|
||||
LCBDdWx0dXJlPW5ldXRyYWwsIFB1YmxpY0tleVRva2VuPWI3N2E1YzU2MTkzNGUwODkFAQAAACZTeXN0
|
||||
ZW0uV2luZG93cy5Gb3Jtcy5JbWFnZUxpc3RTdHJlYW1lcgEAAAAERGF0YQcCAgAAAAkDAAAADwMAAADk
|
||||
CAAAAk1TRnQBSQFMAgEBAgEAAbABAAGwAQABEAEAARABAAT/AQkBAAj/AUIBTQE2AQQGAAE2AQQCAAEo
|
||||
CAAAAk1TRnQBSQFMAgEBAgEAAQgBAQEIAQEBEAEAARABAAT/AQkBAAj/AUIBTQE2AQQGAAE2AQQCAAEo
|
||||
AwABQAMAARADAAEBAQABCAYAAQQYAAGAAgABgAMAAoABAAGAAwABgAEAAYABAAKAAgADwAEAAcAB3AHA
|
||||
AQAB8AHKAaYBAAEzBQABMwEAATMBAAEzAQACMwIAAxYBAAMcAQADIgEAAykBAANVAQADTQEAA0IBAAM5
|
||||
AQABgAF8Af8BAAJQAf8BAAGTAQAB1gEAAf8B7AHMAQABxgHWAe8BAAHWAucBAAGQAakBrQIAAf8BMwMA
|
||||
|
||||
168
ImageWindow/HWindow_Tool.csproj
Normal file
168
ImageWindow/HWindow_Tool.csproj
Normal file
@@ -0,0 +1,168 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">x86</Platform>
|
||||
<ProductVersion>9.0.30729</ProductVersion>
|
||||
<SchemaVersion>2.0</SchemaVersion>
|
||||
<ProjectGuid>{9BAA53FD-89B5-43E2-AC59-A27B006DEBB6}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>ViewROI</RootNamespace>
|
||||
<AssemblyName>HWindow_Tool</AssemblyName>
|
||||
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
|
||||
<TargetFrameworkProfile>
|
||||
</TargetFrameworkProfile>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<SccProjectName>
|
||||
</SccProjectName>
|
||||
<SccLocalPath>
|
||||
</SccLocalPath>
|
||||
<SccAuxPath>
|
||||
</SccAuxPath>
|
||||
<SccProvider>
|
||||
</SccProvider>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<Prefer32Bit>false</Prefer32Bit>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
|
||||
<PlatformTarget>x86</PlatformTarget>
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<Prefer32Bit>false</Prefer32Bit>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<StartupObject>
|
||||
</StartupObject>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<OutputPath>bin\x64\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<DebugType>full</DebugType>
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
|
||||
<Prefer32Bit>false</Prefer32Bit>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
|
||||
<OutputPath>bin\x64\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<Optimize>true</Optimize>
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<PlatformTarget>x64</PlatformTarget>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
|
||||
<Prefer32Bit>false</Prefer32Bit>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|AnyCPU'">
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>TRACE;DEBUG</DefineConstants>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|AnyCPU'">
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="halcondotnet, Version=19.5.0.0, Culture=neutral, PublicKeyToken=4973bed59ddbf2b8, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>C:\Program Files\MVTec\HALCON-19.05-Progress\bin\dotnet20\halcondotnet.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Runtime.Serialization.Formatters.Soap" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="System.Data.DataSetExtensions" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Deployment" />
|
||||
<Reference Include="System.Drawing" />
|
||||
<Reference Include="System.Windows.Forms" />
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Config\Circle.cs" />
|
||||
<Compile Include="Config\CircularArc.cs" />
|
||||
<Compile Include="Config\HObjectWithColor.cs" />
|
||||
<Compile Include="Config\Line.cs" />
|
||||
<Compile Include="Config\Rectangle1.cs" />
|
||||
<Compile Include="Config\Rectangle2.cs" />
|
||||
<Compile Include="Config\SerializeHelper.cs" />
|
||||
<Compile Include="HWindowTool_Smart.cs">
|
||||
<SubType>UserControl</SubType>
|
||||
</Compile>
|
||||
<Compile Include="HWindowTool_Smart.Designer.cs">
|
||||
<DependentUpon>HWindowTool_Smart.cs</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="HWindow_Final.cs">
|
||||
<SubType>UserControl</SubType>
|
||||
</Compile>
|
||||
<Compile Include="HWindow_Final.designer.cs">
|
||||
<DependentUpon>HWindow_Final.cs</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Model\GraphicsContext.cs" />
|
||||
<Compile Include="Model\HObjectEntry.cs" />
|
||||
<Compile Include="Model\HWndCtrl.cs" />
|
||||
<Compile Include="Model\IViewWindow.cs" />
|
||||
<Compile Include="Model\ROI.cs" />
|
||||
<Compile Include="Model\ROICircle.cs" />
|
||||
<Compile Include="Model\ROICircularArc.cs" />
|
||||
<Compile Include="Model\ROIController.cs" />
|
||||
<Compile Include="Model\RoiData.cs" />
|
||||
<Compile Include="Model\ROILine.cs" />
|
||||
<Compile Include="Model\ROINurbs.cs" />
|
||||
<Compile Include="Model\ROIRectangle1.cs" />
|
||||
<Compile Include="Model\ROIRectangle2.cs" />
|
||||
<Compile Include="Program.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="ViewWindow.cs" />
|
||||
<EmbeddedResource Include="HWindowTool_Smart.resx">
|
||||
<DependentUpon>HWindowTool_Smart.cs</DependentUpon>
|
||||
</EmbeddedResource>
|
||||
<EmbeddedResource Include="HWindow_Final.resx">
|
||||
<DependentUpon>HWindow_Final.cs</DependentUpon>
|
||||
<SubType>Designer</SubType>
|
||||
</EmbeddedResource>
|
||||
<EmbeddedResource Include="Properties\Resources.resx">
|
||||
<Generator>ResXFileCodeGenerator</Generator>
|
||||
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
|
||||
<SubType>Designer</SubType>
|
||||
</EmbeddedResource>
|
||||
<Compile Include="Properties\Resources.Designer.cs">
|
||||
<AutoGen>True</AutoGen>
|
||||
<DependentUpon>Resources.resx</DependentUpon>
|
||||
<DesignTime>True</DesignTime>
|
||||
</Compile>
|
||||
<None Include="app.config" />
|
||||
<None Include="Properties\Settings.settings">
|
||||
<Generator>SettingsSingleFileGenerator</Generator>
|
||||
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
|
||||
</None>
|
||||
<Compile Include="Properties\Settings.Designer.cs">
|
||||
<AutoGen>True</AutoGen>
|
||||
<DependentUpon>Settings.settings</DependentUpon>
|
||||
<DesignTimeSharedInput>True</DesignTimeSharedInput>
|
||||
</Compile>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
<Target Name="BeforeBuild">
|
||||
</Target>
|
||||
<Target Name="AfterBuild">
|
||||
</Target>
|
||||
-->
|
||||
</Project>
|
||||
@@ -4,6 +4,7 @@ using System.Collections;
|
||||
using HalconDotNet;
|
||||
using ViewROI.Config;
|
||||
using System.Collections.Generic;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace ViewWindow.Model
|
||||
{
|
||||
@@ -91,8 +92,8 @@ namespace ViewWindow.Model
|
||||
/* Basic parameters, like dimension of window and displayed image part */
|
||||
private int windowWidth;
|
||||
private int windowHeight;
|
||||
private int imageWidth;
|
||||
private int imageHeight;
|
||||
internal int imageWidth;
|
||||
internal int imageHeight;
|
||||
|
||||
private int[] CompRangeX;
|
||||
private int[] CompRangeY;
|
||||
@@ -104,7 +105,7 @@ namespace ViewWindow.Model
|
||||
|
||||
/* Image coordinates, which describe the image part that is displayed
|
||||
in the HALCON window */
|
||||
private double ImgRow1, ImgCol1, ImgRow2, ImgCol2;
|
||||
public double ImgRow1, ImgCol1, ImgRow2, ImgCol2;
|
||||
|
||||
/// <summary>Error message when an exception is thrown</summary>
|
||||
public string exceptionText = "";
|
||||
@@ -567,6 +568,7 @@ namespace ViewWindow.Model
|
||||
/*******************************************************************/
|
||||
private void mouseMoved(object sender, HalconDotNet.HMouseEventArgs e)
|
||||
{
|
||||
|
||||
//关闭缩放事件
|
||||
if (drawModel)
|
||||
{
|
||||
@@ -583,10 +585,11 @@ namespace ViewWindow.Model
|
||||
|
||||
if (roiManager != null && (roiManager.activeROIidx != -1) && (dispROI == MODE_INCLUDE_ROI))
|
||||
{
|
||||
roiManager.mouseMoveAction(e.X, e.Y);
|
||||
roiManager.mouseMoveAction(e.X, e.Y,viewPort );
|
||||
}
|
||||
else if (stateView == MODE_VIEW_MOVE)
|
||||
{
|
||||
viewPort.Cursor = System.Windows.Forms.Cursors.Hand;
|
||||
motionX = ((e.X - startX));
|
||||
motionY = ((e.Y - startY));
|
||||
|
||||
@@ -725,10 +728,6 @@ namespace ViewWindow.Model
|
||||
{
|
||||
repaint(viewPort.HalconWindow);
|
||||
}
|
||||
public void repaint(string color)
|
||||
{
|
||||
repaint(viewPort.HalconWindow ,color );
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Repaints the HALCON window 'window'
|
||||
@@ -762,7 +761,7 @@ namespace ViewWindow.Model
|
||||
addInfoDelegate();
|
||||
|
||||
if (roiManager != null && (dispROI == MODE_INCLUDE_ROI))
|
||||
roiManager.paintData(window);
|
||||
roiManager.paintData(window,viewPort );
|
||||
|
||||
|
||||
HSystem.SetSystem("flush_graphic", "true");
|
||||
@@ -777,50 +776,6 @@ namespace ViewWindow.Model
|
||||
|
||||
}
|
||||
}
|
||||
public void repaint(HalconDotNet.HWindow window,string color)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
||||
|
||||
int count = HObjImageList.Count;
|
||||
HObjectEntry entry;
|
||||
|
||||
HSystem.SetSystem("flush_graphic", "false");
|
||||
window.ClearWindow();
|
||||
mGC.stateOfSettings.Clear();
|
||||
|
||||
//显示图片
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
entry = ((HObjectEntry)HObjImageList[i]);
|
||||
mGC.applyContext(window, entry.gContext);
|
||||
window.DispObj(entry.HObj);
|
||||
|
||||
}
|
||||
|
||||
//显示region
|
||||
showHObjectList();
|
||||
|
||||
|
||||
addInfoDelegate();
|
||||
|
||||
if (roiManager != null && (dispROI == MODE_INCLUDE_ROI))
|
||||
roiManager.paintData(window,color );
|
||||
|
||||
|
||||
HSystem.SetSystem("flush_graphic", "true");
|
||||
|
||||
//注释了下面语句,会导致窗口无法实现缩放和拖动
|
||||
window.SetColor("black");
|
||||
window.DispLine(-100.0, -100.0, -101.0, -101.0);
|
||||
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using HalconDotNet;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace ViewWindow.Model
|
||||
{
|
||||
@@ -67,9 +68,12 @@ namespace ViewWindow.Model
|
||||
|
||||
/// <summary>Constructor of abstract ROI class.</summary>
|
||||
public ROI() { }
|
||||
|
||||
public virtual void createROINurbs(HTuple rows, HTuple cols) { }
|
||||
public virtual void createROINurbs(double imageHeight) { }
|
||||
public virtual void createRectangle1(double row1, double col1, double row2, double col2) { }
|
||||
public virtual void createInitRectangle1(double imageHeight) { }
|
||||
public virtual void createRectangle2(double row, double col, double phi, double length1, double length2) { }
|
||||
public virtual void createInitRectangle2(double imageHeight) { }
|
||||
public virtual void createCircle(double row,double col,double radius) { }
|
||||
public virtual void createCircularArc(double row, double col, double radius, double startPhi, double extentPhi, string direct) { }
|
||||
public virtual void createLine(double beginRow, double beginCol, double endRow, double endCol) { }
|
||||
@@ -85,7 +89,7 @@ namespace ViewWindow.Model
|
||||
|
||||
/// <summary>Paints the ROI into the supplied window.</summary>
|
||||
/// <param name="window">HALCON window</param>
|
||||
public virtual void draw(HalconDotNet.HWindow window) { }
|
||||
public virtual void draw(HalconDotNet.HWindow window,int imageWidth,int imageHeight) { }
|
||||
|
||||
/// <summary>
|
||||
/// Returns the distance of the ROI handle being
|
||||
@@ -105,7 +109,7 @@ namespace ViewWindow.Model
|
||||
/// 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) { }
|
||||
public virtual void displayActive(HalconDotNet.HWindow window, int imageWidth, int imageHeight) { }
|
||||
|
||||
/// <summary>
|
||||
/// Recalculates the shape of the ROI. Translation is
|
||||
@@ -114,7 +118,7 @@ namespace ViewWindow.Model
|
||||
/// </summary>
|
||||
/// <param name="x">x (=column) coordinate</param>
|
||||
/// <param name="y">y (=row) coordinate</param>
|
||||
public virtual void moveByHandle(double x, double y) { }
|
||||
public virtual void moveByHandle(double x, double y, HWindowControl window) { }
|
||||
|
||||
/// <summary>Gets the HALCON region described by the ROI.</summary>
|
||||
public virtual HRegion getRegion()
|
||||
@@ -134,7 +138,19 @@ namespace ViewWindow.Model
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public virtual HTuple getRowsData()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
public virtual HTuple getColsData()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
public virtual void getModelData(out HTuple t1,out HTuple t2)
|
||||
{
|
||||
t1 = new HTuple();
|
||||
t2 = new HTuple();
|
||||
}
|
||||
/// <summary>Number of handles defined for the ROI.</summary>
|
||||
/// <returns>Number of handles</returns>
|
||||
public int getNumHandles()
|
||||
|
||||
@@ -4,15 +4,15 @@ using System.Xml.Serialization;
|
||||
|
||||
namespace ViewWindow.Model
|
||||
{
|
||||
/// <summary>
|
||||
/// This class demonstrates one of the possible implementations for a
|
||||
/// circular ROI. ROICircle inherits from the base class ROI and
|
||||
/// implements (besides other auxiliary methods) all virtual methods
|
||||
/// defined in ROI.cs.
|
||||
/// </summary>
|
||||
/// <summary>
|
||||
/// This class demonstrates one of the possible implementations for a
|
||||
/// circular ROI. ROICircle inherits from the base class ROI and
|
||||
/// implements (besides other auxiliary methods) all virtual methods
|
||||
/// defined in ROI.cs.
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
public class ROICircle : ROI
|
||||
{
|
||||
public class ROICircle : ROI
|
||||
{
|
||||
|
||||
[XmlElement(ElementName = "Row")]
|
||||
public double Row
|
||||
@@ -35,22 +35,23 @@ namespace ViewWindow.Model
|
||||
}
|
||||
|
||||
|
||||
private double radius;
|
||||
private double row1, col1; // first handle
|
||||
private double midR, midC; // second handle
|
||||
private double radius;
|
||||
private double row1, col1; // first handle
|
||||
private double midR, midC; // second handle
|
||||
|
||||
|
||||
public ROICircle()
|
||||
{
|
||||
NumHandles = 2; // one at corner of circle + midpoint
|
||||
activeHandleIdx = 1;
|
||||
}
|
||||
public ROICircle()
|
||||
{
|
||||
NumHandles = 2; // one at corner of circle + midpoint
|
||||
activeHandleIdx = 1;
|
||||
}
|
||||
|
||||
public ROICircle(double row, double col, double radius)
|
||||
{
|
||||
createCircle(row, col, radius);
|
||||
}
|
||||
|
||||
|
||||
public override void createCircle(double row, double col, double radius)
|
||||
{
|
||||
base.createCircle(row, col, radius);
|
||||
@@ -63,131 +64,193 @@ namespace ViewWindow.Model
|
||||
col1 = midC + radius;
|
||||
}
|
||||
|
||||
/// <summary>Creates a new ROI instance at the mouse position</summary>
|
||||
public override void createROI(double midX, double midY)
|
||||
{
|
||||
midR = midY;
|
||||
midC = midX;
|
||||
/// <summary>Creates a new ROI instance at the mouse position</summary>
|
||||
public override void createROI(double midX, double midY)
|
||||
{
|
||||
midR = midY;
|
||||
midC = midX;
|
||||
|
||||
radius = 100;
|
||||
radius = 100;
|
||||
|
||||
row1 = midR;
|
||||
col1 = midC + radius;
|
||||
}
|
||||
row1 = midR;
|
||||
col1 = midC + radius;
|
||||
}
|
||||
|
||||
/// <summary>Paints the ROI into the supplied window</summary>
|
||||
/// <param name="window">HALCON window</param>
|
||||
public override void draw(HalconDotNet.HWindow window)
|
||||
{
|
||||
window.DispCircle(midR, midC, radius);
|
||||
window.DispRectangle2(row1, col1, 0, 8, 8);
|
||||
window.DispRectangle2(midR, midC, 0, 8, 8);
|
||||
}
|
||||
/// <summary>Paints the ROI into the supplied window</summary>
|
||||
/// <param name="window">HALCON window</param>
|
||||
public override void draw(HalconDotNet.HWindow window, int imageWidth, int imageHeight)
|
||||
{
|
||||
HOperatorSet.SetDraw(window, "margin");
|
||||
window.DispCircle(midR, midC, radius);
|
||||
|
||||
/// <summary>
|
||||
/// Returns the distance of the ROI handle being
|
||||
/// closest to the image point(x,y)
|
||||
/// </summary>
|
||||
public override double distToClosestHandle(double x, double y)
|
||||
{
|
||||
double max = 10000;
|
||||
double [] val = new double[NumHandles];
|
||||
double littleRecSize = 0;
|
||||
if (imageHeight < 300) littleRecSize = 1;
|
||||
else if (imageHeight < 600) littleRecSize = 2;
|
||||
else if (imageHeight < 900) littleRecSize = 3;
|
||||
else if (imageHeight < 1200) littleRecSize = 4;
|
||||
else if (imageHeight < 1500) littleRecSize = 5;
|
||||
else if (imageHeight < 1800) littleRecSize = 6;
|
||||
else if (imageHeight < 2100) littleRecSize = 7;
|
||||
else if (imageHeight < 2400) littleRecSize = 8;
|
||||
else if (imageHeight < 2700) littleRecSize = 9;
|
||||
else if (imageHeight < 3000) littleRecSize = 10;
|
||||
else if (imageHeight < 3300) littleRecSize = 11;
|
||||
else if (imageHeight < 3600) littleRecSize = 12;
|
||||
else if (imageHeight < 3900) littleRecSize = 13;
|
||||
else if (imageHeight < 4200) littleRecSize = 14;
|
||||
else if (imageHeight < 4500) littleRecSize = 15;
|
||||
else if (imageHeight < 4800) littleRecSize = 16;
|
||||
else if (imageHeight < 5100) littleRecSize = 17;
|
||||
else littleRecSize = 18;
|
||||
|
||||
val[0] = HMisc.DistancePp(y, x, row1, col1); // border handle
|
||||
val[1] = HMisc.DistancePp(y, x, midR, midC); // midpoint
|
||||
if (littleRecSize % 2 != 0)
|
||||
littleRecSize++;
|
||||
|
||||
for (int i=0; i < NumHandles; i++)
|
||||
{
|
||||
if (val[i] < max)
|
||||
{
|
||||
max = val[i];
|
||||
activeHandleIdx = i;
|
||||
}
|
||||
}// end of for
|
||||
return val[activeHandleIdx];
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Paints the active handle of the ROI object into the supplied window
|
||||
/// </summary>
|
||||
public override void displayActive(HalconDotNet.HWindow window)
|
||||
{
|
||||
|
||||
switch (activeHandleIdx)
|
||||
{
|
||||
case 0:
|
||||
window.DispRectangle2(row1, col1, 0, 8, 8);
|
||||
break;
|
||||
case 1:
|
||||
window.DispRectangle2(midR, midC, 0, 8, 8);
|
||||
break;
|
||||
}
|
||||
}
|
||||
HOperatorSet.SetDraw(window, "fill");
|
||||
|
||||
/// <summary>Gets the HALCON region described by the ROI</summary>
|
||||
public override HRegion getRegion()
|
||||
{
|
||||
HRegion region = new HRegion();
|
||||
region.GenCircle(midR, midC, radius);
|
||||
return region;
|
||||
}
|
||||
window.DispRectangle2(row1, col1, 0, littleRecSize, littleRecSize);
|
||||
window.DispRectangle2(midR, midC, 0, littleRecSize, littleRecSize);
|
||||
}
|
||||
|
||||
public override double getDistanceFromStartPoint(double row, double col)
|
||||
{
|
||||
double sRow = midR; // assumption: we have an angle starting at 0.0
|
||||
double sCol = midC + 1 * radius;
|
||||
/// <summary>
|
||||
/// Returns the distance of the ROI handle being
|
||||
/// closest to the image point(x,y)
|
||||
/// </summary>
|
||||
public override double distToClosestHandle(double x, double y)
|
||||
{
|
||||
double max = 10000;
|
||||
double[] val = new double[NumHandles];
|
||||
|
||||
double angle = HMisc.AngleLl(midR, midC, sRow, sCol, midR, midC, row, col);
|
||||
val[0] = HMisc.DistancePp(y, x, row1, col1); // border handle
|
||||
val[1] = HMisc.DistancePp(y, x, midR, midC); // midpoint
|
||||
|
||||
if (angle < 0)
|
||||
angle += 2 * Math.PI;
|
||||
for (int i = 0; i < NumHandles; i++)
|
||||
{
|
||||
if (val[i] < max)
|
||||
{
|
||||
max = val[i];
|
||||
activeHandleIdx = i;
|
||||
}
|
||||
}// end of for
|
||||
return val[activeHandleIdx];
|
||||
}
|
||||
|
||||
return (radius * angle);
|
||||
}
|
||||
/// <summary>
|
||||
/// Paints the active handle of the ROI object into the supplied window
|
||||
/// </summary>
|
||||
public override void displayActive(HalconDotNet.HWindow window, int imageWidth, int imageHeight)
|
||||
{
|
||||
double littleRecSize = 0;
|
||||
if (imageHeight < 300) littleRecSize = 1;
|
||||
else if (imageHeight < 600) littleRecSize = 2;
|
||||
else if (imageHeight < 900) littleRecSize = 3;
|
||||
else if (imageHeight < 1200) littleRecSize = 4;
|
||||
else if (imageHeight < 1500) littleRecSize = 5;
|
||||
else if (imageHeight < 1800) littleRecSize = 6;
|
||||
else if (imageHeight < 2100) littleRecSize = 7;
|
||||
else if (imageHeight < 2400) littleRecSize = 8;
|
||||
else if (imageHeight < 2700) littleRecSize = 9;
|
||||
else if (imageHeight < 3000) littleRecSize = 10;
|
||||
else if (imageHeight < 3300) littleRecSize = 11;
|
||||
else if (imageHeight < 3600) littleRecSize = 12;
|
||||
else if (imageHeight < 3900) littleRecSize = 13;
|
||||
else if (imageHeight < 4200) littleRecSize = 14;
|
||||
else if (imageHeight < 4500) littleRecSize = 15;
|
||||
else if (imageHeight < 4800) littleRecSize = 16;
|
||||
else if (imageHeight < 5100) littleRecSize = 17;
|
||||
else littleRecSize = 18;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the model information described by
|
||||
/// the ROI
|
||||
/// </summary>
|
||||
public override HTuple getModelData()
|
||||
{
|
||||
return new HTuple(new double[] { midR, midC, radius });
|
||||
}
|
||||
if (littleRecSize % 2 != 0)
|
||||
littleRecSize++;
|
||||
|
||||
/// <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>
|
||||
public override void moveByHandle(double newX, double newY)
|
||||
{
|
||||
HTuple distance;
|
||||
double shiftX,shiftY;
|
||||
//HOperatorSet.SetDraw(window, "margin");
|
||||
|
||||
|
||||
switch (activeHandleIdx)
|
||||
{
|
||||
case 0: // handle at circle border
|
||||
HOperatorSet.SetDraw(window, "fill");
|
||||
|
||||
row1 = newY;
|
||||
col1 = newX;
|
||||
HOperatorSet.DistancePp(new HTuple(row1), new HTuple(col1),
|
||||
new HTuple(midR), new HTuple(midC),
|
||||
out distance);
|
||||
|
||||
radius = distance[0].D;
|
||||
break;
|
||||
case 1: // midpoint
|
||||
|
||||
shiftY = midR - newY;
|
||||
shiftX = midC - newX;
|
||||
|
||||
midR = newY;
|
||||
midC = newX;
|
||||
switch (activeHandleIdx)
|
||||
{
|
||||
case 0:
|
||||
window.DispRectangle2(row1, col1, 0, littleRecSize, littleRecSize);
|
||||
break;
|
||||
case 1:
|
||||
window.DispRectangle2(midR, midC, 0, littleRecSize, littleRecSize);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
row1 -= shiftY;
|
||||
col1 -= shiftX;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}//end of class
|
||||
/// <summary>Gets the HALCON region described by the ROI</summary>
|
||||
public override HRegion getRegion()
|
||||
{
|
||||
HRegion region = new HRegion();
|
||||
region.GenCircle(midR, midC, radius);
|
||||
return region;
|
||||
}
|
||||
|
||||
public override double getDistanceFromStartPoint(double row, double col)
|
||||
{
|
||||
double sRow = midR; // assumption: we have an angle starting at 0.0
|
||||
double sCol = midC + 1 * radius;
|
||||
|
||||
double angle = HMisc.AngleLl(midR, midC, sRow, sCol, midR, midC, row, col);
|
||||
|
||||
if (angle < 0)
|
||||
angle += 2 * Math.PI;
|
||||
|
||||
return (radius * angle);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the model information described by
|
||||
/// the ROI
|
||||
/// </summary>
|
||||
public override HTuple getModelData()
|
||||
{
|
||||
return new HTuple(new double[] { midR, midC, radius });
|
||||
}
|
||||
|
||||
/// <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>
|
||||
public override void moveByHandle(double newX, double newY, HWindowControl window)
|
||||
{
|
||||
HTuple distance;
|
||||
double shiftX, shiftY;
|
||||
|
||||
switch (activeHandleIdx)
|
||||
{
|
||||
case 0: // handle at circle border
|
||||
|
||||
row1 = newY;
|
||||
col1 = newX;
|
||||
HOperatorSet.DistancePp(new HTuple(row1), new HTuple(col1),
|
||||
new HTuple(midR), new HTuple(midC),
|
||||
out distance);
|
||||
|
||||
radius = distance[0].D;
|
||||
window.Cursor = System.Windows.Forms.Cursors.Hand ;
|
||||
break;
|
||||
case 1: // midpoint
|
||||
|
||||
shiftY = midR - newY;
|
||||
shiftX = midC - newX;
|
||||
|
||||
midR = newY;
|
||||
midC = newX;
|
||||
|
||||
row1 -= shiftY;
|
||||
col1 -= shiftX;
|
||||
window.Cursor = System.Windows.Forms.Cursors.SizeAll ;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}//end of class
|
||||
}//end of namespace
|
||||
|
||||
@@ -126,16 +126,38 @@ namespace ViewWindow.Model
|
||||
|
||||
/// <summary>Paints the ROI into the supplied window</summary>
|
||||
/// <param name="window">HALCON window</param>
|
||||
public override void draw(HalconDotNet.HWindow window)
|
||||
public override void draw(HalconDotNet.HWindow window, int imageWidth, int imageHeight)
|
||||
{
|
||||
contour.Dispose();
|
||||
contour.GenCircleContourXld(midR, midC, radius, startPhi,
|
||||
(startPhi + extentPhi), circDir, 1.0);
|
||||
double littleRecSize = 0;
|
||||
if (imageHeight < 300) littleRecSize = 1;
|
||||
else if (imageHeight < 600) littleRecSize = 2;
|
||||
else if (imageHeight < 900) littleRecSize = 3;
|
||||
else if (imageHeight < 1200) littleRecSize = 4;
|
||||
else if (imageHeight < 1500) littleRecSize = 5;
|
||||
else if (imageHeight < 1800) littleRecSize = 6;
|
||||
else if (imageHeight < 2100) littleRecSize = 7;
|
||||
else if (imageHeight < 2400) littleRecSize = 8;
|
||||
else if (imageHeight < 2700) littleRecSize = 9;
|
||||
else if (imageHeight < 3000) littleRecSize = 10;
|
||||
else if (imageHeight < 3300) littleRecSize = 11;
|
||||
else if (imageHeight < 3600) littleRecSize = 12;
|
||||
else if (imageHeight < 3900) littleRecSize = 13;
|
||||
else if (imageHeight < 4200) littleRecSize = 14;
|
||||
else if (imageHeight < 4500) littleRecSize = 15;
|
||||
else if (imageHeight < 4800) littleRecSize = 16;
|
||||
else if (imageHeight < 5100) littleRecSize = 17;
|
||||
else littleRecSize = 18;
|
||||
|
||||
window.DispObj(contour);
|
||||
window.DispRectangle2(sizeR, sizeC, 0, 5, 5);
|
||||
window.DispRectangle2(midR, midC, 0, 5, 5);
|
||||
window.DispRectangle2(startR, startC, startPhi, 10, 2);
|
||||
window.DispObj(arrowHandleXLD);
|
||||
window.DispRectangle2(sizeR, sizeC, 0, littleRecSize, littleRecSize);
|
||||
window.DispRectangle2(midR, midC, 0, littleRecSize, littleRecSize);
|
||||
window.DispRectangle2(startR, startC, startPhi, littleRecSize, littleRecSize);
|
||||
window.DispRectangle2(extentR , extentC , 0, littleRecSize, littleRecSize);
|
||||
window.DispLine(startR, startC, midR, midC);
|
||||
window.DispLine(extentR , extentC , midR, midC);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -166,21 +188,41 @@ namespace ViewWindow.Model
|
||||
/// <summary>
|
||||
/// Paints the active handle of the ROI object into the supplied window
|
||||
/// </summary>
|
||||
public override void displayActive(HalconDotNet.HWindow window)
|
||||
public override void displayActive(HalconDotNet.HWindow window, int imageWidth, int imageHeight)
|
||||
{
|
||||
double littleRecSize = 0;
|
||||
if (imageHeight < 300) littleRecSize = 1;
|
||||
else if (imageHeight < 600) littleRecSize = 2;
|
||||
else if (imageHeight < 900) littleRecSize = 3;
|
||||
else if (imageHeight < 1200) littleRecSize = 4;
|
||||
else if (imageHeight < 1500) littleRecSize = 5;
|
||||
else if (imageHeight < 1800) littleRecSize = 6;
|
||||
else if (imageHeight < 2100) littleRecSize = 7;
|
||||
else if (imageHeight < 2400) littleRecSize = 8;
|
||||
else if (imageHeight < 2700) littleRecSize = 9;
|
||||
else if (imageHeight < 3000) littleRecSize = 10;
|
||||
else if (imageHeight < 3300) littleRecSize = 11;
|
||||
else if (imageHeight < 3600) littleRecSize = 12;
|
||||
else if (imageHeight < 3900) littleRecSize = 13;
|
||||
else if (imageHeight < 4200) littleRecSize = 14;
|
||||
else if (imageHeight < 4500) littleRecSize = 15;
|
||||
else if (imageHeight < 4800) littleRecSize = 16;
|
||||
else if (imageHeight < 5100) littleRecSize = 17;
|
||||
else littleRecSize = 18;
|
||||
|
||||
switch (activeHandleIdx)
|
||||
{
|
||||
case 0:
|
||||
window.DispRectangle2(midR, midC, 0, 5, 5);
|
||||
window.DispRectangle2(midR, midC, 0, littleRecSize, littleRecSize);
|
||||
break;
|
||||
case 1:
|
||||
window.DispRectangle2(sizeR, sizeC, 0, 5, 5);
|
||||
window.DispRectangle2(sizeR, sizeC, 0, littleRecSize, littleRecSize);
|
||||
break;
|
||||
case 2:
|
||||
window.DispRectangle2(startR, startC, startPhi, 10, 2);
|
||||
window.DispRectangle2(startR, startC, startPhi, littleRecSize, littleRecSize);
|
||||
break;
|
||||
case 3:
|
||||
window.DispObj(arrowHandleXLD);
|
||||
window.DispRectangle2(extentR , extentC , 0, littleRecSize, littleRecSize);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -190,7 +232,7 @@ namespace ViewWindow.Model
|
||||
/// performed at the active handle of the ROI object
|
||||
/// for the image coordinate (x,y)
|
||||
/// </summary>
|
||||
public override void moveByHandle(double newX, double newY)
|
||||
public override void moveByHandle(double newX, double newY, HWindowControl window)
|
||||
{
|
||||
HTuple distance;
|
||||
double dirX, dirY, prior, next, valMax, valMin;
|
||||
|
||||
@@ -2,6 +2,7 @@ using System;
|
||||
using HalconDotNet;
|
||||
using ViewWindow;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace ViewWindow.Model
|
||||
{
|
||||
@@ -79,8 +80,8 @@ namespace ViewWindow.Model
|
||||
/// </summary>
|
||||
public HRegion ModelROI;
|
||||
|
||||
private string activeCol = "green";
|
||||
private string activeHdlCol = "red";
|
||||
private string activeCol = "blue";
|
||||
private string activeHdlCol = "green";
|
||||
private string inactiveCol = "blue";
|
||||
|
||||
/// <summary>
|
||||
@@ -301,58 +302,36 @@ namespace ViewWindow.Model
|
||||
/// Paints all objects from the ROIList into the HALCON window
|
||||
/// </summary>
|
||||
/// <param name="window">HALCON window</param>
|
||||
internal void paintData(HalconDotNet.HWindow window)
|
||||
{
|
||||
window.SetDraw("margin");
|
||||
window.SetLineWidth(1);
|
||||
if (ROIList.Count > 0)
|
||||
{
|
||||
window.SetColor(inactiveCol);
|
||||
window.SetDraw("margin");
|
||||
for (int i = 0; i < ROIList.Count; i++)
|
||||
{
|
||||
window.SetLineStyle(((ROI)ROIList[i]).flagLineStyle);
|
||||
((ROI)ROIList[i]).draw(window);
|
||||
}
|
||||
if (activeROIidx != -1)
|
||||
{
|
||||
window.SetColor(activeCol);
|
||||
window.SetLineStyle(((ROI)ROIList[activeROIidx]).flagLineStyle);
|
||||
((ROI)ROIList[activeROIidx]).draw(window);
|
||||
public void paintData(HalconDotNet.HWindow window,HWindowControl windowCtrl)
|
||||
{
|
||||
window.SetDraw("margin");
|
||||
window.SetLineWidth(1);
|
||||
|
||||
window.SetColor(activeHdlCol);
|
||||
((ROI)ROIList[activeROIidx]).displayActive(window);
|
||||
}
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 以指定颜色显示ROI
|
||||
/// </summary>
|
||||
/// <param name="window"></param>
|
||||
internal void paintData(HalconDotNet.HWindow window,string color)
|
||||
{
|
||||
window.SetDraw("margin");
|
||||
window.SetLineWidth(1);
|
||||
if (ROIList.Count > 0)
|
||||
{
|
||||
window.SetColor(color);
|
||||
window.SetDraw("margin");
|
||||
for (int i = 0; i < ROIList.Count; i++)
|
||||
{
|
||||
window.SetLineStyle(((ROI)ROIList[i]).flagLineStyle);
|
||||
((ROI)ROIList[i]).draw(window);
|
||||
}
|
||||
if (activeROIidx != -1)
|
||||
{
|
||||
window.SetColor(color);
|
||||
window.SetLineStyle(((ROI)ROIList[activeROIidx]).flagLineStyle);
|
||||
((ROI)ROIList[activeROIidx]).draw(window);
|
||||
if (ROIList.Count > 0)
|
||||
{
|
||||
//
|
||||
//window.SetColor(inactiveCol);
|
||||
|
||||
window.SetDraw("margin");
|
||||
|
||||
window.SetColor(color);
|
||||
((ROI)ROIList[activeROIidx]).displayActive(window);
|
||||
}
|
||||
}
|
||||
}
|
||||
for (int i=0; i < ROIList.Count; i++)
|
||||
{
|
||||
window.SetColor(((ROI)ROIList[i]).Color);
|
||||
window.SetLineStyle(((ROI)ROIList[i]).flagLineStyle);
|
||||
((ROI)ROIList[i]).draw(window,Convert .ToInt32 ( viewController .ImgCol2 -viewController .ImgCol1) ,Convert .ToInt32 (viewController .ImgRow2 -viewController .ImgRow1 ) );
|
||||
}
|
||||
|
||||
if (activeROIidx != -1)
|
||||
{
|
||||
window.SetColor(activeCol);
|
||||
window.SetLineStyle(((ROI)ROIList[activeROIidx]).flagLineStyle);
|
||||
((ROI)ROIList[activeROIidx]).draw(window, Convert.ToInt32(viewController.ImgCol2 - viewController.ImgCol1), Convert.ToInt32(viewController.ImgRow2 - viewController.ImgRow1));
|
||||
|
||||
window.SetColor(activeHdlCol);
|
||||
((ROI)ROIList[activeROIidx]).displayActive(window, Convert.ToInt32(viewController.ImgCol2 - viewController.ImgCol1), Convert.ToInt32(viewController.ImgRow2 - viewController.ImgRow1));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reaction of ROI objects to the 'mouse button down' event: changing
|
||||
@@ -410,7 +389,7 @@ namespace ViewWindow.Model
|
||||
/// </summary>
|
||||
/// <param name="newX">x coordinate of mouse event</param>
|
||||
/// <param name="newY">y coordinate of mouse event</param>
|
||||
public void mouseMoveAction(double newX, double newY)
|
||||
public void mouseMoveAction(double newX, double newY, HWindowControl window)
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -418,7 +397,7 @@ namespace ViewWindow.Model
|
||||
if ((newX == currX) && (newY == currY))
|
||||
return;
|
||||
|
||||
((ROI)ROIList[activeROIidx]).moveByHandle(newX, newY);
|
||||
((ROI)ROIList[activeROIidx]).moveByHandle(newX, newY,window );
|
||||
viewController.repaint();
|
||||
currX = newX;
|
||||
currY = newY;
|
||||
@@ -458,7 +437,24 @@ namespace ViewWindow.Model
|
||||
ROIList.Add(roiMode);
|
||||
roiMode = null;
|
||||
activeROIidx = ROIList.Count - 1;
|
||||
viewController.repaint("blue");
|
||||
viewController.repaint();
|
||||
|
||||
NotifyRCObserver(ROIController.EVENT_CREATED_ROI);
|
||||
}
|
||||
}
|
||||
public void displayNurbs(string color,HTuple rows,HTuple cols)
|
||||
{
|
||||
setROIShape(new ROINurbs ());
|
||||
|
||||
if (roiMode != null) //either a new ROI object is created
|
||||
{
|
||||
roiMode.createROINurbs (rows, cols);
|
||||
roiMode.Type = roiMode.GetType().Name;
|
||||
roiMode.Color = color;
|
||||
ROIList.Add(roiMode);
|
||||
roiMode = null;
|
||||
activeROIidx = ROIList.Count - 1;
|
||||
viewController.repaint();
|
||||
|
||||
NotifyRCObserver(ROIController.EVENT_CREATED_ROI);
|
||||
}
|
||||
@@ -565,7 +561,37 @@ namespace ViewWindow.Model
|
||||
/// <param name="row2"></param>
|
||||
/// <param name="col2"></param>
|
||||
/// <param name="rois"></param>
|
||||
public void genRect1(double row1, double col1, double row2, double col2, ref System.Collections.Generic.List<ROI> rois)
|
||||
protected internal void genNurbs(HTuple rows, HTuple cols, ref System.Collections.Generic.List<ROI> rois)
|
||||
{
|
||||
setROIShape(new ROINurbs() );
|
||||
|
||||
if (rois == null)
|
||||
{
|
||||
rois = new System.Collections.Generic.List<ROI>();
|
||||
}
|
||||
|
||||
if (roiMode != null) //either a new ROI object is created
|
||||
{
|
||||
roiMode.createROINurbs (rows ,cols );
|
||||
roiMode.Type = roiMode.GetType().Name;
|
||||
rois.Add(roiMode);
|
||||
ROIList.Add(roiMode);
|
||||
roiMode = null;
|
||||
activeROIidx = ROIList.Count - 1;
|
||||
viewController.repaint();
|
||||
|
||||
NotifyRCObserver(ROIController.EVENT_CREATED_ROI);
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 在指定位置生成ROI--Rectangle1
|
||||
/// </summary>
|
||||
/// <param name="row1"></param>
|
||||
/// <param name="col1"></param>
|
||||
/// <param name="row2"></param>
|
||||
/// <param name="col2"></param>
|
||||
/// <param name="rois"></param>
|
||||
protected internal void genRect1(double row1, double col1, double row2, double col2, ref System.Collections.Generic.List<ROI> rois)
|
||||
{
|
||||
setROIShape(new ROIRectangle1());
|
||||
|
||||
@@ -588,6 +614,36 @@ namespace ViewWindow.Model
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 在指定位置生成ROI--Rectangle1
|
||||
/// </summary>
|
||||
/// <param name="row1"></param>
|
||||
/// <param name="col1"></param>
|
||||
/// <param name="row2"></param>
|
||||
/// <param name="col2"></param>
|
||||
/// <param name="rois"></param>
|
||||
protected internal void genInitRect1(int imageHeight, ref System.Collections.Generic.List<ROI> rois)
|
||||
{
|
||||
setROIShape(new ROIRectangle1());
|
||||
|
||||
if (rois == null)
|
||||
{
|
||||
rois = new System.Collections.Generic.List<ROI>();
|
||||
}
|
||||
|
||||
if (roiMode != null) //either a new ROI object is created
|
||||
{
|
||||
roiMode.createInitRectangle1(imageHeight );
|
||||
roiMode.Type = roiMode.GetType().Name;
|
||||
rois.Add(roiMode);
|
||||
ROIList.Add(roiMode);
|
||||
roiMode = null;
|
||||
activeROIidx = ROIList.Count - 1;
|
||||
viewController.repaint();
|
||||
|
||||
NotifyRCObserver(ROIController.EVENT_CREATED_ROI);
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 在指定位置生成ROI--Rectangle2
|
||||
/// </summary>
|
||||
/// <param name="row"></param>
|
||||
@@ -596,7 +652,7 @@ namespace ViewWindow.Model
|
||||
/// <param name="length1"></param>
|
||||
/// <param name="length2"></param>
|
||||
/// <param name="rois"></param>
|
||||
public void genRect2(double row, double col, double phi, double length1, double length2, ref System.Collections.Generic.List<ROI> rois)
|
||||
protected internal void genRect2(double row, double col, double phi, double length1, double length2, ref System.Collections.Generic.List<ROI> rois)
|
||||
{
|
||||
setROIShape(new ROIRectangle2());
|
||||
|
||||
@@ -619,13 +675,44 @@ namespace ViewWindow.Model
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 在指定位置生成ROI--Rectangle2
|
||||
/// </summary>
|
||||
/// <param name="row"></param>
|
||||
/// <param name="col"></param>
|
||||
/// <param name="phi"></param>
|
||||
/// <param name="length1"></param>
|
||||
/// <param name="length2"></param>
|
||||
/// <param name="rois"></param>
|
||||
protected internal void genInitRect2(double imageHeight, ref System.Collections.Generic.List<ROI> rois)
|
||||
{
|
||||
setROIShape(new ROIRectangle2());
|
||||
|
||||
if (rois == null)
|
||||
{
|
||||
rois = new System.Collections.Generic.List<ROI>();
|
||||
}
|
||||
|
||||
if (roiMode != null) //either a new ROI object is created
|
||||
{
|
||||
roiMode.createInitRectangle2(imageHeight );
|
||||
roiMode.Type = roiMode.GetType().Name;
|
||||
rois.Add(roiMode);
|
||||
ROIList.Add(roiMode);
|
||||
roiMode = null;
|
||||
activeROIidx = ROIList.Count - 1;
|
||||
viewController.repaint();
|
||||
|
||||
NotifyRCObserver(ROIController.EVENT_CREATED_ROI);
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 在指定位置生成ROI--Circle
|
||||
/// </summary>
|
||||
/// <param name="row"></param>
|
||||
/// <param name="col"></param>
|
||||
/// <param name="radius"></param>
|
||||
/// <param name="rois"></param>
|
||||
public void genCircle(double row, double col, double radius, ref System.Collections.Generic.List<ROI> rois)
|
||||
protected internal void genCircle(double row, double col, double radius, ref System.Collections.Generic.List<ROI> rois)
|
||||
{
|
||||
setROIShape(new ROICircle());
|
||||
|
||||
@@ -648,7 +735,7 @@ namespace ViewWindow.Model
|
||||
}
|
||||
}
|
||||
|
||||
public void genCircularArc(double row, double col, double radius, double startPhi, double extentPhi, string direct, ref System.Collections.Generic.List<ROI> rois)
|
||||
protected internal void genCircularArc(double row, double col, double radius,double startPhi, double extentPhi,string direct, ref System.Collections.Generic.List<ROI> rois)
|
||||
{
|
||||
setROIShape(new ROICircularArc());
|
||||
|
||||
@@ -742,13 +829,12 @@ namespace ViewWindow.Model
|
||||
{
|
||||
ROI region = this.getActiveROI();
|
||||
Type type = region.GetType();
|
||||
|
||||
HTuple smallest = region.getModelData();
|
||||
|
||||
for (int i = 0; i < smallest.Length; i++)
|
||||
{
|
||||
data.Add(smallest[i].D);
|
||||
}
|
||||
//////for (int i = 0; i < smallest.Length; i++)
|
||||
//////{
|
||||
////// data.Add(smallest[i].D);
|
||||
//////}
|
||||
|
||||
return region;
|
||||
}
|
||||
|
||||
@@ -89,7 +89,7 @@ namespace ViewWindow.Model
|
||||
updateArrowHandle();
|
||||
}
|
||||
/// <summary>Paints the ROI into the supplied window.</summary>
|
||||
public override void draw(HalconDotNet.HWindow window)
|
||||
public override void draw(HalconDotNet.HWindow window, int imageWidth, int imageHeight)
|
||||
{
|
||||
|
||||
window.DispLine(row1, col1, row2, col2);
|
||||
@@ -128,7 +128,7 @@ namespace ViewWindow.Model
|
||||
/// <summary>
|
||||
/// Paints the active handle of the ROI object into the supplied window.
|
||||
/// </summary>
|
||||
public override void displayActive(HalconDotNet.HWindow window)
|
||||
public override void displayActive(HalconDotNet.HWindow window, int imageWidth, int imageHeight)
|
||||
{
|
||||
|
||||
switch (activeHandleIdx)
|
||||
@@ -172,7 +172,7 @@ namespace ViewWindow.Model
|
||||
/// performed at the active handle of the ROI object
|
||||
/// for the image coordinate (x,y).
|
||||
/// </summary>
|
||||
public override void moveByHandle(double newX, double newY)
|
||||
public override void moveByHandle(double newX, double newY, HWindowControl window)
|
||||
{
|
||||
double lenR, lenC;
|
||||
|
||||
|
||||
346
ImageWindow/Model/ROINurbs.cs
Normal file
346
ImageWindow/Model/ROINurbs.cs
Normal file
@@ -0,0 +1,346 @@
|
||||
using System;
|
||||
using HalconDotNet;
|
||||
using System.Xml.Serialization;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace ViewWindow.Model
|
||||
{
|
||||
/// <summary>
|
||||
/// This class demonstrates one of the possible implementations for a
|
||||
/// (simple) rectangularly shaped ROI. ROIRectangle1 inherits
|
||||
/// from the base class ROI and implements (besides other auxiliary
|
||||
/// methods) all virtual methods defined in ROI.cs.
|
||||
/// Since a simple rectangle is defined by two data points, by the upper
|
||||
/// left corner and the lower right corner, we use four values (row1/col1)
|
||||
/// and (row2/col2) as class members to hold these positions at
|
||||
/// any time of the program. The four corners of the rectangle can be taken
|
||||
/// as handles, which the user can use to manipulate the size of the ROI.
|
||||
/// Furthermore, we define a midpoint as an additional handle, with which
|
||||
/// the user can grab and drag the ROI. Therefore, we declare NumHandles
|
||||
/// to be 5 and set the activeHandle to be 0, which will be the upper left
|
||||
/// corner of our ROI.
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
public class ROINurbs : ROI
|
||||
{
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
private string color = "blue";
|
||||
|
||||
|
||||
private HTuple rows = new HTuple();
|
||||
private HTuple cols = new HTuple();
|
||||
|
||||
/// <summary>Constructor</summary>
|
||||
public ROINurbs()
|
||||
{
|
||||
NumHandles = rows.Length ; // 4 corner points + midpoint
|
||||
activeHandleIdx = 0;
|
||||
}
|
||||
|
||||
public ROINurbs(HTuple rows, HTuple cols)
|
||||
{
|
||||
createROINurbs(rows, cols);
|
||||
}
|
||||
|
||||
public override void createROINurbs(HTuple rows, HTuple cols)
|
||||
{
|
||||
base.createROINurbs(rows, cols);
|
||||
this.rows = rows;
|
||||
this.cols = cols;
|
||||
}
|
||||
public override void createROINurbs(double imageHeight)
|
||||
{
|
||||
double size = 0;
|
||||
if (imageHeight < 300) size = 10;
|
||||
else if (imageHeight < 600) size = 20;
|
||||
else if (imageHeight < 900) size = 30;
|
||||
else if (imageHeight < 1200) size = 40;
|
||||
else if (imageHeight < 1500) size = 50;
|
||||
else if (imageHeight < 1800) size = 60;
|
||||
else if (imageHeight < 2100) size = 70;
|
||||
else if (imageHeight < 2400) size = 80;
|
||||
else if (imageHeight < 2700) size = 90;
|
||||
else if (imageHeight < 3000) size = 100;
|
||||
else if (imageHeight < 3300) size = 110;
|
||||
else if (imageHeight < 3600) size = 120;
|
||||
else if (imageHeight < 3900) size = 130;
|
||||
else if (imageHeight < 4200) size = 140;
|
||||
else if (imageHeight < 4500) size = 150;
|
||||
else if (imageHeight < 4800) size = 160;
|
||||
else if (imageHeight < 5100) size = 170;
|
||||
else size = 180;
|
||||
|
||||
double length1 = size * 3;
|
||||
double length2 = size * 4;
|
||||
|
||||
|
||||
base.createROINurbs(rows, cols);
|
||||
this.rows = rows;
|
||||
this.cols = cols;
|
||||
}
|
||||
/// <summary>Creates a new ROI instance at the mouse position</summary>
|
||||
/// <param name="midX">
|
||||
/// x (=column) coordinate for interactive ROI
|
||||
/// </param>
|
||||
/// <param name="midY">
|
||||
/// y (=row) coordinate for interactive ROI
|
||||
/// </param>
|
||||
////public override void createROI(List<double> rows, List<double> cols)
|
||||
////{
|
||||
//// //////midR = midY;
|
||||
//// //////midC = midX;
|
||||
|
||||
//// //////row1 = midR - 25;
|
||||
//// //////col1 = midC - 25;
|
||||
//// //////row2 = midR + 25;
|
||||
//// //////col2 = midC + 25;
|
||||
////}
|
||||
|
||||
/// <summary>Paints the ROI into the supplied window</summary>
|
||||
/// <param name="window">HALCON window</param>
|
||||
public override void draw(HalconDotNet.HWindow window, int imageWidth, int imageHeight)
|
||||
{
|
||||
double littleRecSize = 0;
|
||||
if (imageHeight < 300) littleRecSize = 1;
|
||||
else if (imageHeight < 600) littleRecSize = 2;
|
||||
else if (imageHeight < 900) littleRecSize = 3;
|
||||
else if (imageHeight < 1200) littleRecSize = 4;
|
||||
else if (imageHeight < 1500) littleRecSize = 5;
|
||||
else if (imageHeight < 1800) littleRecSize = 6;
|
||||
else if (imageHeight < 2100) littleRecSize = 7;
|
||||
else if (imageHeight < 2400) littleRecSize = 8;
|
||||
else if (imageHeight < 2700) littleRecSize = 9;
|
||||
else if (imageHeight < 3000) littleRecSize = 10;
|
||||
else if (imageHeight < 3300) littleRecSize = 11;
|
||||
else if (imageHeight < 3600) littleRecSize = 12;
|
||||
else if (imageHeight < 3900) littleRecSize = 13;
|
||||
else if (imageHeight < 4200) littleRecSize = 14;
|
||||
else if (imageHeight < 4500) littleRecSize = 15;
|
||||
else if (imageHeight < 4800) littleRecSize = 16;
|
||||
else if (imageHeight < 5100) littleRecSize = 17;
|
||||
else littleRecSize = 18;
|
||||
|
||||
////// window.DispObj (row1, col1, row2, col2);
|
||||
|
||||
if (littleRecSize % 2 != 0)
|
||||
littleRecSize++;
|
||||
|
||||
HOperatorSet.SetDraw(window, "fill");
|
||||
|
||||
for (int i = 0; i < rows.Length ; i++)
|
||||
{
|
||||
window.DispRectangle2(rows[i], cols[i], 0, littleRecSize, littleRecSize);
|
||||
if (i < rows.Length - 1)
|
||||
window.DispLine((HTuple)rows[i], (HTuple)cols[i], (HTuple)rows[i + 1], (HTuple)cols[i + 1]);
|
||||
else
|
||||
window.DispLine((HTuple)rows[i], (HTuple)cols[i], (HTuple)rows[0], (HTuple)cols[0]);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/// <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 override double distToClosestHandle(double x, double y)
|
||||
{
|
||||
|
||||
double max = 10000;
|
||||
double[] val = new double[rows.Length ];
|
||||
|
||||
//midR = ((row2 - row1) / 2) + row1;
|
||||
//midC = ((col2 - col1) / 2) + col1;
|
||||
|
||||
for (int i = 0; i < rows.Length ; i++)
|
||||
{
|
||||
val[i] = HMisc.DistancePp(y, x, rows[i], cols[i]); // upper left
|
||||
}
|
||||
//////val[0] = HMisc.DistancePp(y, x, row1, col1); // upper left
|
||||
//////val[1] = HMisc.DistancePp(y, x, row1, col2); // upper right
|
||||
//////val[2] = HMisc.DistancePp(y, x, row2, col2); // lower right
|
||||
//////val[3] = HMisc.DistancePp(y, x, row2, col1); // lower left
|
||||
//////val[4] = HMisc.DistancePp(y, x, midR, midC); // midpoint
|
||||
//////val[5] = HMisc.DistancePp(y, x, (row1 + row2) / 2, col1);
|
||||
//////val[6] = HMisc.DistancePp(y, x, (row1 + row2) / 2, col2);
|
||||
//////val[7] = HMisc.DistancePp(y, x, row1, (col1 + col2) / 2);
|
||||
//////val[8] = HMisc.DistancePp(y, x, row2, (col1 + col2) / 2);
|
||||
|
||||
for (int i = 0; i < rows.Length ; i++)
|
||||
{
|
||||
if (val[i] < max)
|
||||
{
|
||||
max = val[i];
|
||||
activeHandleIdx = i;
|
||||
}
|
||||
}// end of for
|
||||
|
||||
return val[activeHandleIdx];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Paints the active handle of the ROI object into the supplied window
|
||||
/// </summary>
|
||||
/// <param name="window">HALCON window</param>
|
||||
public override void displayActive(HalconDotNet.HWindow window, int imageWidth, int imageHeight)
|
||||
{
|
||||
double littleRecSize = 0;
|
||||
if (imageHeight < 300) littleRecSize = 1;
|
||||
else if (imageHeight < 600) littleRecSize = 2;
|
||||
else if (imageHeight < 900) littleRecSize = 3;
|
||||
else if (imageHeight < 1200) littleRecSize = 4;
|
||||
else if (imageHeight < 1500) littleRecSize = 5;
|
||||
else if (imageHeight < 1800) littleRecSize = 6;
|
||||
else if (imageHeight < 2100) littleRecSize = 7;
|
||||
else if (imageHeight < 2400) littleRecSize = 8;
|
||||
else if (imageHeight < 2700) littleRecSize = 9;
|
||||
else if (imageHeight < 3000) littleRecSize = 10;
|
||||
else if (imageHeight < 3300) littleRecSize = 11;
|
||||
else if (imageHeight < 3600) littleRecSize = 12;
|
||||
else if (imageHeight < 3900) littleRecSize = 13;
|
||||
else if (imageHeight < 4200) littleRecSize = 14;
|
||||
else if (imageHeight < 4500) littleRecSize = 15;
|
||||
else if (imageHeight < 4800) littleRecSize = 16;
|
||||
else if (imageHeight < 5100) littleRecSize = 17;
|
||||
else littleRecSize = 18;
|
||||
|
||||
if (littleRecSize % 2 != 0)
|
||||
littleRecSize++;
|
||||
|
||||
window.DispRectangle2(rows[activeHandleIdx], cols[activeHandleIdx], 0, littleRecSize, littleRecSize);
|
||||
////switch (activeHandleIdx)
|
||||
////{
|
||||
//// case 0:
|
||||
//// window.DispRectangle2(row1, col1, 0, littleRecSize, littleRecSize);
|
||||
//// break;
|
||||
//// case 1:
|
||||
//// window.DispRectangle2(row1, col2, 0, littleRecSize, littleRecSize);
|
||||
//// break;
|
||||
//// case 2:
|
||||
//// window.DispRectangle2(row2, col2, 0, littleRecSize, littleRecSize);
|
||||
//// break;
|
||||
//// case 3:
|
||||
//// window.DispRectangle2(row2, col1, 0, littleRecSize, littleRecSize);
|
||||
//// break;
|
||||
//// case 4:
|
||||
//// window.DispRectangle2(midR, midC, 0, littleRecSize, littleRecSize);
|
||||
//// break;
|
||||
//// case 5:
|
||||
//// window.DispRectangle2((row1 + row2) / 2, col1, 0, littleRecSize, littleRecSize);
|
||||
//// break;
|
||||
//// case 6:
|
||||
//// window.DispRectangle2((row1 + row2) / 2, col2, 0, littleRecSize, littleRecSize);
|
||||
//// break;
|
||||
//// case 7:
|
||||
//// window.DispRectangle2(row1, (col1 + col2) / 2, 0, littleRecSize, littleRecSize);
|
||||
//// break;
|
||||
//// case 8:
|
||||
//// window.DispRectangle2(row2, (col1 + col2) / 2, 0, littleRecSize, littleRecSize);
|
||||
//// break;
|
||||
////}
|
||||
}
|
||||
|
||||
/// <summary>Gets the HALCON region described by the ROI</summary>
|
||||
public override HRegion getRegion()
|
||||
{
|
||||
HRegion region = new HRegion();
|
||||
region.GenRegionPolygonFilled(new HTuple (rows ) , new HTuple (cols ) );
|
||||
return (HRegion )region;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the model information described by
|
||||
/// the interactive ROI
|
||||
/// </summary>
|
||||
public override void getModelData(out HTuple t1,out HTuple t2)
|
||||
{
|
||||
//return new HTuple();
|
||||
t1 = rows;
|
||||
t2 = cols;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Recalculates the shape of the ROI instance. Translation is
|
||||
/// performed at the active handle of the ROI object
|
||||
/// for the image coordinate (x,y)
|
||||
/// </summary>
|
||||
/// <param name="newX">x mouse coordinate</param>
|
||||
/// <param name="newY">y mouse coordinate</param>
|
||||
public override void moveByHandle(double newX, double newY, HWindowControl window)
|
||||
{
|
||||
double len1, len2;
|
||||
double tmp;
|
||||
|
||||
//switch (activeHandleIdx)
|
||||
//{
|
||||
// case 0: // upper left
|
||||
rows[activeHandleIdx] = newY;
|
||||
cols[activeHandleIdx] = newX;
|
||||
window.Cursor = System.Windows.Forms.Cursors.Hand ;
|
||||
// break;
|
||||
// case 1: // upper right
|
||||
// row1 = newY;
|
||||
// col2 = newX;
|
||||
// break;
|
||||
// case 2: // lower right
|
||||
// row2 = newY;
|
||||
// col2 = newX;
|
||||
// break;
|
||||
// case 3: // lower left
|
||||
// row2 = newY;
|
||||
// col1 = newX;
|
||||
// break;
|
||||
// case 4: // midpoint
|
||||
// len1 = ((row2 - row1) / 2);
|
||||
// len2 = ((col2 - col1) / 2);
|
||||
|
||||
// row1 = newY - len1;
|
||||
// row2 = newY + len1;
|
||||
|
||||
// col1 = newX - len2;
|
||||
// col2 = newX + len2;
|
||||
|
||||
// break;
|
||||
// case 5: // upper right
|
||||
// col1 = newX;
|
||||
// break;
|
||||
// case 6: // lower right
|
||||
// col2 = newX;
|
||||
// break;
|
||||
// case 7: // lower left
|
||||
// row1 = newY;
|
||||
// break;
|
||||
// case 8: // midpoint
|
||||
// row2 = newY;
|
||||
// break;
|
||||
//}
|
||||
|
||||
//if (row2 <= row1)
|
||||
//{
|
||||
// tmp = row1;
|
||||
// row1 = row2;
|
||||
// row2 = tmp;
|
||||
//}
|
||||
|
||||
//if (col2 <= col1)
|
||||
//{
|
||||
// tmp = col1;
|
||||
// col1 = col2;
|
||||
// col2 = tmp;
|
||||
//}
|
||||
|
||||
//midR = ((row2 - row1) / 2) + row1;
|
||||
//midC = ((col2 - col1) / 2) + col1;
|
||||
|
||||
}//end of method
|
||||
}//end of class
|
||||
}//end of namespace
|
||||
@@ -4,24 +4,24 @@ using System.Xml.Serialization;
|
||||
|
||||
namespace ViewWindow.Model
|
||||
{
|
||||
/// <summary>
|
||||
/// This class demonstrates one of the possible implementations for a
|
||||
/// (simple) rectangularly shaped ROI. ROIRectangle1 inherits
|
||||
/// from the base class ROI and implements (besides other auxiliary
|
||||
/// methods) all virtual methods defined in ROI.cs.
|
||||
/// Since a simple rectangle is defined by two data points, by the upper
|
||||
/// left corner and the lower right corner, we use four values (row1/col1)
|
||||
/// and (row2/col2) as class members to hold these positions at
|
||||
/// any time of the program. The four corners of the rectangle can be taken
|
||||
/// as handles, which the user can use to manipulate the size of the ROI.
|
||||
/// Furthermore, we define a midpoint as an additional handle, with which
|
||||
/// the user can grab and drag the ROI. Therefore, we declare NumHandles
|
||||
/// to be 5 and set the activeHandle to be 0, which will be the upper left
|
||||
/// corner of our ROI.
|
||||
/// </summary>
|
||||
/// <summary>
|
||||
/// This class demonstrates one of the possible implementations for a
|
||||
/// (simple) rectangularly shaped ROI. ROIRectangle1 inherits
|
||||
/// from the base class ROI and implements (besides other auxiliary
|
||||
/// methods) all virtual methods defined in ROI.cs.
|
||||
/// Since a simple rectangle is defined by two data points, by the upper
|
||||
/// left corner and the lower right corner, we use four values (row1/col1)
|
||||
/// and (row2/col2) as class members to hold these positions at
|
||||
/// any time of the program. The four corners of the rectangle can be taken
|
||||
/// as handles, which the user can use to manipulate the size of the ROI.
|
||||
/// Furthermore, we define a midpoint as an additional handle, with which
|
||||
/// the user can grab and drag the ROI. Therefore, we declare NumHandles
|
||||
/// to be 5 and set the activeHandle to be 0, which will be the upper left
|
||||
/// corner of our ROI.
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
public class ROIRectangle1 : ROI
|
||||
{
|
||||
{
|
||||
[XmlElement(ElementName = "Row1")]
|
||||
public double Row1
|
||||
{
|
||||
@@ -49,20 +49,20 @@ namespace ViewWindow.Model
|
||||
get { return this.col2; }
|
||||
set { this.col2 = value; }
|
||||
}
|
||||
private string color = "yellow";
|
||||
private string color = "blue";
|
||||
|
||||
|
||||
private double row1, col1; // upper left
|
||||
private double row2, col2; // lower right
|
||||
private double midR, midC; // midpoint
|
||||
private double row1, col1; // upper left
|
||||
private double row2, col2; // lower right
|
||||
private double midR, midC; // midpoint
|
||||
|
||||
|
||||
/// <summary>Constructor</summary>
|
||||
public ROIRectangle1()
|
||||
{
|
||||
NumHandles = 5; // 4 corner points + midpoint
|
||||
activeHandleIdx = 4;
|
||||
}
|
||||
/// <summary>Constructor</summary>
|
||||
public ROIRectangle1()
|
||||
{
|
||||
NumHandles = 9; // 4 corner points + midpoint
|
||||
activeHandleIdx = 4;
|
||||
}
|
||||
|
||||
public ROIRectangle1(double row1, double col1, double row2, double col2)
|
||||
{
|
||||
@@ -79,177 +79,299 @@ namespace ViewWindow.Model
|
||||
midR = (this.row1 + this.row2) / 2.0;
|
||||
midC = (this.col1 + this.col2) / 2.0;
|
||||
}
|
||||
/// <summary>Creates a new ROI instance at the mouse position</summary>
|
||||
/// <param name="midX">
|
||||
/// x (=column) coordinate for interactive ROI
|
||||
/// </param>
|
||||
/// <param name="midY">
|
||||
/// y (=row) coordinate for interactive ROI
|
||||
/// </param>
|
||||
public override void createROI(double midX, double midY)
|
||||
{
|
||||
midR = midY;
|
||||
midC = midX;
|
||||
public override void createInitRectangle1(double imageHeight)
|
||||
{
|
||||
double size = 0;
|
||||
if (imageHeight < 300) size = 10;
|
||||
else if (imageHeight < 600) size = 20;
|
||||
else if (imageHeight < 900) size = 30;
|
||||
else if (imageHeight < 1200) size = 40;
|
||||
else if (imageHeight < 1500) size = 50;
|
||||
else if (imageHeight < 1800) size = 60;
|
||||
else if (imageHeight < 2100) size = 70;
|
||||
else if (imageHeight < 2400) size = 80;
|
||||
else if (imageHeight < 2700) size = 90;
|
||||
else if (imageHeight < 3000) size = 100;
|
||||
else if (imageHeight < 3300) size = 110;
|
||||
else if (imageHeight < 3600) size = 120;
|
||||
else if (imageHeight < 3900) size = 130;
|
||||
else if (imageHeight < 4200) size = 140;
|
||||
else if (imageHeight < 4500) size = 150;
|
||||
else if (imageHeight < 4800) size = 160;
|
||||
else if (imageHeight < 5100) size = 170;
|
||||
else size = 180;
|
||||
|
||||
row1 = midR - 25;
|
||||
col1 = midC - 25;
|
||||
row2 = midR + 25;
|
||||
col2 = midC + 25;
|
||||
}
|
||||
|
||||
/// <summary>Paints the ROI into the supplied window</summary>
|
||||
/// <param name="window">HALCON window</param>
|
||||
public override void draw(HalconDotNet.HWindow window)
|
||||
{
|
||||
window.DispRectangle1(row1, col1, row2, col2);
|
||||
|
||||
window.DispRectangle2(row1, col1, 0, 8,8);
|
||||
window.DispRectangle2(row1, col2, 0, 8,8);
|
||||
window.DispRectangle2(row2, col2, 0, 8,8);
|
||||
window.DispRectangle2(row2, col1, 0, 8,8);
|
||||
window.DispRectangle2(midR, midC, 0, 8,8);
|
||||
}
|
||||
|
||||
/// <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 override double distToClosestHandle(double x, double y)
|
||||
{
|
||||
|
||||
double max = 10000;
|
||||
double [] val = new double[NumHandles];
|
||||
|
||||
midR = ((row2 - row1) / 2) + row1;
|
||||
midC = ((col2 - col1) / 2) + col1;
|
||||
|
||||
val[0] = HMisc.DistancePp(y, x, row1, col1); // upper left
|
||||
val[1] = HMisc.DistancePp(y, x, row1, col2); // upper right
|
||||
val[2] = HMisc.DistancePp(y, x, row2, col2); // lower right
|
||||
val[3] = HMisc.DistancePp(y, x, row2, col1); // lower left
|
||||
val[4] = HMisc.DistancePp(y, x, midR, midC); // midpoint
|
||||
|
||||
for (int i=0; i < NumHandles; i++)
|
||||
{
|
||||
if (val[i] < max)
|
||||
{
|
||||
max = val[i];
|
||||
activeHandleIdx = i;
|
||||
}
|
||||
}// end of for
|
||||
|
||||
return val[activeHandleIdx];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Paints the active handle of the ROI object into the supplied window
|
||||
/// </summary>
|
||||
/// <param name="window">HALCON window</param>
|
||||
public override void displayActive(HalconDotNet.HWindow window)
|
||||
{
|
||||
switch (activeHandleIdx)
|
||||
{
|
||||
case 0:
|
||||
window.DispRectangle2(row1, col1, 0, 8,8);
|
||||
break;
|
||||
case 1:
|
||||
window.DispRectangle2(row1, col2, 0, 8,8);
|
||||
break;
|
||||
case 2:
|
||||
window.DispRectangle2(row2, col2, 0, 8,8);
|
||||
break;
|
||||
case 3:
|
||||
window.DispRectangle2(row2, col1, 0, 8,8);
|
||||
break;
|
||||
case 4:
|
||||
window.DispRectangle2(midR, midC, 0, 8,8);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Gets the HALCON region described by the ROI</summary>
|
||||
public override HRegion getRegion()
|
||||
{
|
||||
HRegion region = new HRegion();
|
||||
region.GenRectangle1(row1, col1, row2, col2);
|
||||
return region;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the model information described by
|
||||
/// the interactive ROI
|
||||
/// </summary>
|
||||
public override HTuple getModelData()
|
||||
{
|
||||
return new HTuple(new double[] { row1, col1, row2, col2 });
|
||||
}
|
||||
double length1 = size * 3;
|
||||
double length2 = size * 4;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Recalculates the shape of the ROI instance. Translation is
|
||||
/// performed at the active handle of the ROI object
|
||||
/// for the image coordinate (x,y)
|
||||
/// </summary>
|
||||
/// <param name="newX">x mouse coordinate</param>
|
||||
/// <param name="newY">y mouse coordinate</param>
|
||||
public override void moveByHandle(double newX, double newY)
|
||||
{
|
||||
double len1, len2;
|
||||
double tmp;
|
||||
base.createRectangle1(row1, col1, row1 + length1, col1+ length2);
|
||||
this.row1 = row1;
|
||||
this.col1 = col1;
|
||||
this.row2 = row1 + length1;
|
||||
this.col2 = col1 + length2;
|
||||
midR = (this.row1 + this.row2) / 2.0;
|
||||
midC = (this.col1 + this.col2) / 2.0;
|
||||
}
|
||||
/// <summary>Creates a new ROI instance at the mouse position</summary>
|
||||
/// <param name="midX">
|
||||
/// x (=column) coordinate for interactive ROI
|
||||
/// </param>
|
||||
/// <param name="midY">
|
||||
/// y (=row) coordinate for interactive ROI
|
||||
/// </param>
|
||||
public override void createROI(double midX, double midY)
|
||||
{
|
||||
midR = midY;
|
||||
midC = midX;
|
||||
|
||||
switch (activeHandleIdx)
|
||||
{
|
||||
case 0: // upper left
|
||||
row1 = newY;
|
||||
col1 = newX;
|
||||
break;
|
||||
case 1: // upper right
|
||||
row1 = newY;
|
||||
col2 = newX;
|
||||
break;
|
||||
case 2: // lower right
|
||||
row2 = newY;
|
||||
col2 = newX;
|
||||
break;
|
||||
case 3: // lower left
|
||||
row2 = newY;
|
||||
col1 = newX;
|
||||
break;
|
||||
case 4: // midpoint
|
||||
len1 = ((row2 - row1) / 2);
|
||||
len2 = ((col2 - col1) / 2);
|
||||
row1 = midR - 25;
|
||||
col1 = midC - 25;
|
||||
row2 = midR + 25;
|
||||
col2 = midC + 25;
|
||||
}
|
||||
|
||||
row1 = newY - len1;
|
||||
row2 = newY + len1;
|
||||
/// <summary>Paints the ROI into the supplied window</summary>
|
||||
/// <param name="window">HALCON window</param>
|
||||
public override void draw(HalconDotNet.HWindow window, int imageWidth, int imageHeight)
|
||||
{
|
||||
double littleRecSize = 0;
|
||||
if (imageHeight < 300) littleRecSize = 1;
|
||||
else if (imageHeight < 600) littleRecSize = 2;
|
||||
else if (imageHeight < 900) littleRecSize = 3;
|
||||
else if (imageHeight < 1200) littleRecSize = 4;
|
||||
else if (imageHeight < 1500) littleRecSize = 5;
|
||||
else if (imageHeight < 1800) littleRecSize = 6;
|
||||
else if (imageHeight < 2100) littleRecSize = 7;
|
||||
else if (imageHeight < 2400) littleRecSize = 8;
|
||||
else if (imageHeight < 2700) littleRecSize = 9;
|
||||
else if (imageHeight < 3000) littleRecSize = 10;
|
||||
else if (imageHeight < 3300) littleRecSize = 11;
|
||||
else if (imageHeight < 3600) littleRecSize = 12;
|
||||
else if (imageHeight < 3900) littleRecSize = 13;
|
||||
else if (imageHeight < 4200) littleRecSize = 14;
|
||||
else if (imageHeight < 4500) littleRecSize = 15;
|
||||
else if (imageHeight < 4800) littleRecSize = 16;
|
||||
else if (imageHeight < 5100) littleRecSize = 17;
|
||||
else littleRecSize = 18;
|
||||
|
||||
col1 = newX - len2;
|
||||
col2 = newX + len2;
|
||||
if (littleRecSize % 2 != 0)
|
||||
littleRecSize++;
|
||||
|
||||
break;
|
||||
}
|
||||
HOperatorSet.SetDraw(window,"margin");
|
||||
window.DispRectangle1(row1, col1, row2, col2);
|
||||
|
||||
if (row2 <= row1)
|
||||
{
|
||||
tmp = row1;
|
||||
row1 = row2;
|
||||
row2 = tmp;
|
||||
}
|
||||
HOperatorSet.SetDraw(window, "fill");
|
||||
window.DispRectangle2(row1, col1, 0, littleRecSize, littleRecSize);
|
||||
window.DispRectangle2(row1, col2, 0, littleRecSize, littleRecSize);
|
||||
window.DispRectangle2(row2, col2, 0, littleRecSize, littleRecSize);
|
||||
window.DispRectangle2(row2, col1, 0, littleRecSize, littleRecSize);
|
||||
window.DispRectangle2(midR, midC, 0, littleRecSize, littleRecSize);
|
||||
window.DispRectangle2((row1 + row2) / 2, col1, 0, littleRecSize, littleRecSize);
|
||||
window.DispRectangle2((row1 + row2) / 2, col2, 0, littleRecSize, littleRecSize);
|
||||
window.DispRectangle2(row1, (col1 + col2) / 2, 0, littleRecSize, littleRecSize);
|
||||
window.DispRectangle2(row2, (col1 + col2) / 2, 0, littleRecSize, littleRecSize);
|
||||
}
|
||||
|
||||
if (col2 <= col1)
|
||||
{
|
||||
tmp = col1;
|
||||
col1 = col2;
|
||||
col2 = tmp;
|
||||
}
|
||||
/// <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 override double distToClosestHandle(double x, double y)
|
||||
{
|
||||
|
||||
midR = ((row2 - row1) / 2) + row1;
|
||||
midC = ((col2 - col1) / 2) + col1;
|
||||
double max = 10000;
|
||||
double[] val = new double[NumHandles];
|
||||
|
||||
}//end of method
|
||||
}//end of class
|
||||
midR = ((row2 - row1) / 2) + row1;
|
||||
midC = ((col2 - col1) / 2) + col1;
|
||||
|
||||
val[0] = HMisc.DistancePp(y, x, row1, col1); // upper left
|
||||
val[1] = HMisc.DistancePp(y, x, row1, col2); // upper right
|
||||
val[2] = HMisc.DistancePp(y, x, row2, col2); // lower right
|
||||
val[3] = HMisc.DistancePp(y, x, row2, col1); // lower left
|
||||
val[4] = HMisc.DistancePp(y, x, midR, midC); // midpoint
|
||||
val[5] = HMisc.DistancePp(y, x, (row1 + row2) / 2, col1);
|
||||
val[6] = HMisc.DistancePp(y, x, (row1 + row2) / 2, col2);
|
||||
val[7] = HMisc.DistancePp(y, x, row1, (col1 + col2) / 2);
|
||||
val[8] = HMisc.DistancePp(y, x, row2, (col1 + col2) / 2);
|
||||
|
||||
for (int i = 0; i < NumHandles; i++)
|
||||
{
|
||||
if (val[i] < max)
|
||||
{
|
||||
max = val[i];
|
||||
activeHandleIdx = i;
|
||||
}
|
||||
}// end of for
|
||||
|
||||
return val[activeHandleIdx];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Paints the active handle of the ROI object into the supplied window
|
||||
/// </summary>
|
||||
/// <param name="window">HALCON window</param>
|
||||
public override void displayActive(HalconDotNet.HWindow window, int imageWidth, int imageHeight)
|
||||
{
|
||||
double littleRecSize = 0;
|
||||
if (imageHeight < 300) littleRecSize = 1;
|
||||
else if (imageHeight < 600) littleRecSize = 2;
|
||||
else if (imageHeight < 900) littleRecSize = 3;
|
||||
else if (imageHeight < 1200) littleRecSize = 4;
|
||||
else if (imageHeight < 1500) littleRecSize = 5;
|
||||
else if (imageHeight < 1800) littleRecSize = 6;
|
||||
else if (imageHeight < 2100) littleRecSize = 7;
|
||||
else if (imageHeight < 2400) littleRecSize = 8;
|
||||
else if (imageHeight < 2700) littleRecSize = 9;
|
||||
else if (imageHeight < 3000) littleRecSize = 10;
|
||||
else if (imageHeight < 3300) littleRecSize = 11;
|
||||
else if (imageHeight < 3600) littleRecSize = 12;
|
||||
else if (imageHeight < 3900) littleRecSize = 13;
|
||||
else if (imageHeight < 4200) littleRecSize = 14;
|
||||
else if (imageHeight < 4500) littleRecSize = 15;
|
||||
else if (imageHeight < 4800) littleRecSize = 16;
|
||||
else if (imageHeight < 5100) littleRecSize = 17;
|
||||
else littleRecSize = 18;
|
||||
|
||||
if (littleRecSize % 2 != 0)
|
||||
littleRecSize++;
|
||||
|
||||
switch (activeHandleIdx)
|
||||
{
|
||||
case 0:
|
||||
window.DispRectangle2(row1, col1, 0, littleRecSize, littleRecSize);
|
||||
break;
|
||||
case 1:
|
||||
window.DispRectangle2(row1, col2, 0, littleRecSize, littleRecSize);
|
||||
break;
|
||||
case 2:
|
||||
window.DispRectangle2(row2, col2, 0, littleRecSize, littleRecSize);
|
||||
break;
|
||||
case 3:
|
||||
window.DispRectangle2(row2, col1, 0, littleRecSize, littleRecSize);
|
||||
break;
|
||||
case 4:
|
||||
window.DispRectangle2(midR, midC, 0, littleRecSize, littleRecSize);
|
||||
break;
|
||||
case 5:
|
||||
window.DispRectangle2((row1 + row2) / 2, col1, 0, littleRecSize, littleRecSize);
|
||||
break;
|
||||
case 6:
|
||||
window.DispRectangle2((row1 + row2) / 2, col2, 0, littleRecSize, littleRecSize);
|
||||
break;
|
||||
case 7:
|
||||
window.DispRectangle2(row1, (col1 + col2) / 2, 0, littleRecSize, littleRecSize);
|
||||
break;
|
||||
case 8:
|
||||
window.DispRectangle2(row2, (col1 + col2) / 2, 0, littleRecSize, littleRecSize);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Gets the HALCON region described by the ROI</summary>
|
||||
public override HRegion getRegion()
|
||||
{
|
||||
HRegion region = new HRegion();
|
||||
region.GenRectangle1(row1, col1, row2, col2);
|
||||
return region;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the model information described by
|
||||
/// the interactive ROI
|
||||
/// </summary>
|
||||
public override HTuple getModelData()
|
||||
{
|
||||
return new HTuple(new double[] { row1, col1, row2, col2 });
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Recalculates the shape of the ROI instance. Translation is
|
||||
/// performed at the active handle of the ROI object
|
||||
/// for the image coordinate (x,y)
|
||||
/// </summary>
|
||||
/// <param name="newX">x mouse coordinate</param>
|
||||
/// <param name="newY">y mouse coordinate</param>
|
||||
public override void moveByHandle(double newX, double newY,HWindowControl window)
|
||||
{
|
||||
double len1, len2;
|
||||
double tmp;
|
||||
|
||||
switch (activeHandleIdx)
|
||||
{
|
||||
case 0: // upper left
|
||||
row1 = newY;
|
||||
col1 = newX;
|
||||
window.Cursor = System.Windows.Forms.Cursors.SizeNWSE ;
|
||||
break;
|
||||
case 1: // upper right
|
||||
row1 = newY;
|
||||
col2 = newX;
|
||||
window.Cursor = System.Windows.Forms.Cursors.SizeNESW ;
|
||||
break;
|
||||
case 2: // lower right
|
||||
row2 = newY;
|
||||
col2 = newX;
|
||||
window.Cursor = System.Windows.Forms.Cursors.SizeNWSE ;
|
||||
break;
|
||||
case 3: // lower left
|
||||
row2 = newY;
|
||||
col1 = newX;
|
||||
window.Cursor = System.Windows.Forms.Cursors.SizeNESW;
|
||||
break;
|
||||
case 4: // midpoint
|
||||
len1 = ((row2 - row1) / 2);
|
||||
len2 = ((col2 - col1) / 2);
|
||||
|
||||
row1 = newY - len1;
|
||||
row2 = newY + len1;
|
||||
|
||||
col1 = newX - len2;
|
||||
col2 = newX + len2;
|
||||
window.Cursor = System.Windows.Forms.Cursors.SizeAll ;
|
||||
break;
|
||||
case 5: // upper right
|
||||
col1 = newX;
|
||||
window.Cursor = System.Windows.Forms.Cursors.SizeWE ;
|
||||
break;
|
||||
case 6: // lower right
|
||||
col2 = newX;
|
||||
window.Cursor = System.Windows.Forms.Cursors.SizeWE ;
|
||||
break;
|
||||
case 7: // lower left
|
||||
row1 = newY;
|
||||
window.Cursor = System.Windows.Forms.Cursors.SizeNS ;
|
||||
break;
|
||||
case 8: // midpoint
|
||||
row2 = newY;
|
||||
window.Cursor = System.Windows.Forms.Cursors.SizeNS ;
|
||||
break;
|
||||
}
|
||||
|
||||
if (row2 <= row1)
|
||||
{
|
||||
tmp = row1;
|
||||
row1 = row2;
|
||||
row2 = tmp;
|
||||
}
|
||||
|
||||
if (col2 <= col1)
|
||||
{
|
||||
tmp = col1;
|
||||
col1 = col2;
|
||||
col2 = tmp;
|
||||
}
|
||||
|
||||
midR = ((row2 - row1) / 2) + row1;
|
||||
midC = ((col2 - col1) / 2) + col1;
|
||||
|
||||
}//end of method
|
||||
}//end of class
|
||||
}//end of namespace
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using HalconDotNet;
|
||||
using System.Xml.Serialization;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace ViewWindow.Model
|
||||
{
|
||||
@@ -71,15 +72,15 @@ namespace ViewWindow.Model
|
||||
//auxiliary variables
|
||||
HTuple rowsInit;
|
||||
HTuple colsInit;
|
||||
HTuple rows;
|
||||
HTuple cols;
|
||||
public HTuple rows;
|
||||
public HTuple cols;
|
||||
|
||||
HHomMat2D hom2D, tmp;
|
||||
|
||||
/// <summary>Constructor</summary>
|
||||
public ROIRectangle2()
|
||||
{
|
||||
NumHandles = 6; // 4 corners + 1 midpoint + 1 rotationpoint
|
||||
NumHandles = 10; // 4 corners + 1 midpoint + 1 rotationpoint
|
||||
activeHandleIdx = 4;
|
||||
}
|
||||
|
||||
@@ -98,9 +99,50 @@ namespace ViewWindow.Model
|
||||
this.phi = phi;
|
||||
|
||||
rowsInit = new HTuple(new double[] {-1.0, -1.0, 1.0,
|
||||
1.0, 0.0, 0.0 });
|
||||
1.0, 0.0, 0.0 ,0,-1,0,1});
|
||||
colsInit = new HTuple(new double[] {-1.0, 1.0, 1.0,
|
||||
-1.0, 0.0, 0.6 });
|
||||
-1.0, 0.0, 1.8 ,-1,0,1,0});
|
||||
//order ul , ur, lr, ll, mp, arrowMidpoint
|
||||
hom2D = new HHomMat2D();
|
||||
tmp = new HHomMat2D();
|
||||
|
||||
updateHandlePos();
|
||||
}
|
||||
public override void createInitRectangle2(double imageHeight)
|
||||
{
|
||||
double size = 0;
|
||||
if (imageHeight < 300) size = 10;
|
||||
else if (imageHeight < 600) size = 20;
|
||||
else if (imageHeight < 900) size = 30;
|
||||
else if (imageHeight < 1200) size = 40;
|
||||
else if (imageHeight < 1500) size = 50;
|
||||
else if (imageHeight < 1800) size = 60;
|
||||
else if (imageHeight < 2100) size = 70;
|
||||
else if (imageHeight < 2400) size = 80;
|
||||
else if (imageHeight < 2700) size = 90;
|
||||
else if (imageHeight < 3000) size = 100;
|
||||
else if (imageHeight < 3300) size = 110;
|
||||
else if (imageHeight < 3600) size = 120;
|
||||
else if (imageHeight < 3900) size = 130;
|
||||
else if (imageHeight < 4200) size = 140;
|
||||
else if (imageHeight < 4500) size = 150;
|
||||
else if (imageHeight < 4800) size = 160;
|
||||
else if (imageHeight < 5100) size = 170;
|
||||
else size = 180;
|
||||
double length1 = size * 3;
|
||||
double length2 = size * 4;
|
||||
|
||||
base.createRectangle2(midR , midC , phi, length1, length2);
|
||||
this.midR = midR ;
|
||||
this.midC = midC ;
|
||||
this.length1 = length1;
|
||||
this.length2 = length2;
|
||||
this.phi = phi;
|
||||
|
||||
rowsInit = new HTuple(new double[] {-1.0, -1.0, 1.0,
|
||||
1.0, 0.0, 0.0 ,0,-1,0,1});
|
||||
colsInit = new HTuple(new double[] {-1.0, 1.0, 1.0,
|
||||
-1.0, 0.0, 1.8 ,-1,0,1,0});
|
||||
//order ul , ur, lr, ll, mp, arrowMidpoint
|
||||
hom2D = new HHomMat2D();
|
||||
tmp = new HHomMat2D();
|
||||
@@ -128,7 +170,7 @@ namespace ViewWindow.Model
|
||||
rowsInit = new HTuple(new double[] {-1.0, -1.0, 1.0,
|
||||
1.0, 0.0, 0.0 });
|
||||
colsInit = new HTuple(new double[] {-1.0, 1.0, 1.0,
|
||||
-1.0, 0.0, 0.6 });
|
||||
-1.0, 0.0, 1.8 });
|
||||
//order ul , ur, lr, ll, mp, arrowMidpoint
|
||||
hom2D = new HHomMat2D();
|
||||
tmp = new HHomMat2D();
|
||||
@@ -138,14 +180,44 @@ namespace ViewWindow.Model
|
||||
|
||||
/// <summary>Paints the ROI into the supplied window</summary>
|
||||
/// <param name="window">HALCON window</param>
|
||||
public override void draw(HalconDotNet.HWindow window)
|
||||
public override void draw(HalconDotNet.HWindow window, int imageWidth, int imageHeight)
|
||||
{
|
||||
window.DispRectangle2(midR, midC, -phi, length1, length2);
|
||||
for (int i =0; i < NumHandles; i++)
|
||||
window.DispRectangle2(rows[i].D, cols[i].D, -phi, 8,8);
|
||||
double littleRecSize = 0;
|
||||
if (imageHeight < 300) littleRecSize = 1;
|
||||
else if (imageHeight < 600) littleRecSize = 2;
|
||||
else if (imageHeight < 900) littleRecSize = 3;
|
||||
else if (imageHeight < 1200) littleRecSize = 4;
|
||||
else if (imageHeight < 1500) littleRecSize = 5;
|
||||
else if (imageHeight < 1800) littleRecSize = 6;
|
||||
else if (imageHeight < 2100) littleRecSize = 7;
|
||||
else if (imageHeight < 2400) littleRecSize = 8;
|
||||
else if (imageHeight < 2700) littleRecSize = 9;
|
||||
else if (imageHeight < 3000) littleRecSize = 10;
|
||||
else if (imageHeight < 3300) littleRecSize = 11;
|
||||
else if (imageHeight < 3600) littleRecSize = 12;
|
||||
else if (imageHeight < 3900) littleRecSize = 13;
|
||||
else if (imageHeight < 4200) littleRecSize = 14;
|
||||
else if (imageHeight < 4500) littleRecSize = 15;
|
||||
else if (imageHeight < 4800) littleRecSize = 16;
|
||||
else if (imageHeight < 5100) littleRecSize = 17;
|
||||
else littleRecSize = 18;
|
||||
|
||||
window.DispArrow(midR, midC, midR + (Math.Sin(phi) * length1 * 1.2),
|
||||
midC + (Math.Cos(phi) * length1 * 1.2), 5.0);
|
||||
if (littleRecSize % 2 != 0)
|
||||
littleRecSize++;
|
||||
|
||||
HOperatorSet.SetDraw(window, "margin");
|
||||
|
||||
window.DispRectangle2(midR, midC, -phi, length1, length2);
|
||||
HOperatorSet.SetDraw(window, "fill");
|
||||
|
||||
for (int i = 0; i < NumHandles; i++)
|
||||
{
|
||||
window.DispRectangle2(rows[i].D, cols[i].D, -phi, littleRecSize, littleRecSize);
|
||||
Application.DoEvents();
|
||||
}
|
||||
|
||||
window.DispArrow(midR, midC, midR + (Math.Sin(phi) * length1 * 1.8),
|
||||
midC + (Math.Cos(phi) * length1 * 1.8), littleRecSize);
|
||||
|
||||
}
|
||||
|
||||
@@ -182,17 +254,41 @@ namespace ViewWindow.Model
|
||||
/// Paints the active handle of the ROI object into the supplied window
|
||||
/// </summary>
|
||||
/// <param name="window">HALCON window</param>
|
||||
public override void displayActive(HalconDotNet.HWindow window)
|
||||
public override void displayActive(HalconDotNet.HWindow window, int imageWidth, int imageHeight)
|
||||
{
|
||||
double littleRecSize = 0;
|
||||
if (imageHeight < 300) littleRecSize = 1;
|
||||
else if (imageHeight < 600) littleRecSize = 2;
|
||||
else if (imageHeight < 900) littleRecSize = 3;
|
||||
else if (imageHeight < 1200) littleRecSize = 4;
|
||||
else if (imageHeight < 1500) littleRecSize = 5;
|
||||
else if (imageHeight < 1800) littleRecSize = 6;
|
||||
else if (imageHeight < 2100) littleRecSize = 7;
|
||||
else if (imageHeight < 2400) littleRecSize = 8;
|
||||
else if (imageHeight < 2700) littleRecSize = 9;
|
||||
else if (imageHeight < 3000) littleRecSize = 10;
|
||||
else if (imageHeight < 3300) littleRecSize = 11;
|
||||
else if (imageHeight < 3600) littleRecSize = 12;
|
||||
else if (imageHeight < 3900) littleRecSize = 13;
|
||||
else if (imageHeight < 4200) littleRecSize = 14;
|
||||
else if (imageHeight < 4500) littleRecSize = 15;
|
||||
else if (imageHeight < 4800) littleRecSize = 16;
|
||||
else if (imageHeight < 5100) littleRecSize = 17;
|
||||
else littleRecSize = 18;
|
||||
|
||||
if (littleRecSize % 2 != 0)
|
||||
littleRecSize++;
|
||||
|
||||
|
||||
window.DispRectangle2(rows[activeHandleIdx].D,
|
||||
cols[activeHandleIdx].D,
|
||||
-phi, 8,8);
|
||||
-phi, littleRecSize, littleRecSize);
|
||||
|
||||
if (activeHandleIdx == 5)
|
||||
window.DispArrow(midR, midC,
|
||||
midR + (Math.Sin(phi) * length1 * 1.2),
|
||||
midC + (Math.Cos(phi) * length1 * 1.2),
|
||||
5.0);
|
||||
midR + (Math.Sin(phi) * length1 * 1.8),
|
||||
midC + (Math.Cos(phi) * length1 * 1.8),
|
||||
littleRecSize);
|
||||
}
|
||||
|
||||
|
||||
@@ -212,6 +308,14 @@ namespace ViewWindow.Model
|
||||
{
|
||||
return new HTuple(new double[] { midR, midC, phi, length1, length2 });
|
||||
}
|
||||
public override HTuple getRowsData()
|
||||
{
|
||||
return new HTuple(rows);
|
||||
}
|
||||
public override HTuple getColsData()
|
||||
{
|
||||
return new HTuple(cols );
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Recalculates the shape of the ROI instance. Translation is
|
||||
@@ -220,7 +324,7 @@ namespace ViewWindow.Model
|
||||
/// </summary>
|
||||
/// <param name="newX">x mouse coordinate</param>
|
||||
/// <param name="newY">y mouse coordinate</param>
|
||||
public override void moveByHandle(double newX, double newY)
|
||||
public override void moveByHandle(double newX, double newY, HWindowControl window)
|
||||
{
|
||||
double vX, vY, x=0, y=0;
|
||||
|
||||
@@ -230,6 +334,7 @@ namespace ViewWindow.Model
|
||||
case 1:
|
||||
case 2:
|
||||
case 3:
|
||||
|
||||
tmp = hom2D.HomMat2dInvert();
|
||||
x = tmp.AffineTransPoint2d(newX, newY, out y);
|
||||
|
||||
@@ -237,15 +342,40 @@ namespace ViewWindow.Model
|
||||
length1 = Math.Abs(x);
|
||||
|
||||
checkForRange(x, y);
|
||||
window.Cursor = System.Windows.Forms.Cursors.Hand ;
|
||||
break;
|
||||
case 4:
|
||||
midC = newX;
|
||||
midR = newY;
|
||||
window.Cursor = System.Windows.Forms.Cursors.SizeAll ;
|
||||
break;
|
||||
case 5:
|
||||
vY = newY - rows[4].D;
|
||||
vX = newX - cols[4].D;
|
||||
phi = Math.Atan2(vY, vX);
|
||||
window.Cursor = System.Windows.Forms.Cursors.Hand;
|
||||
break;
|
||||
case 7:
|
||||
case 9:
|
||||
tmp = hom2D.HomMat2dInvert();
|
||||
x = tmp.AffineTransPoint2d(newX, newY, out y);
|
||||
|
||||
|
||||
|
||||
length2 = Math.Abs(y);
|
||||
|
||||
checkForRange(x, y);
|
||||
window.Cursor = System.Windows.Forms.Cursors.Hand;
|
||||
break;
|
||||
case 6:
|
||||
case 8:
|
||||
tmp = hom2D.HomMat2dInvert();
|
||||
x = tmp.AffineTransPoint2d(newX, newY, out y);
|
||||
|
||||
|
||||
length1 = Math.Abs(x);
|
||||
checkForRange(x, y);
|
||||
window.Cursor = System.Windows.Forms.Cursors.Hand;
|
||||
break;
|
||||
}
|
||||
updateHandlePos();
|
||||
|
||||
@@ -8,7 +8,7 @@ namespace ViewWindow
|
||||
{
|
||||
public class ViewWindow : Model.IViewWindow
|
||||
{
|
||||
public Model.HWndCtrl _hWndControl;
|
||||
public Model.HWndCtrl _hWndControl;
|
||||
|
||||
private Model.ROIController _roiController;
|
||||
|
||||
@@ -97,12 +97,23 @@ namespace ViewWindow
|
||||
{
|
||||
this._roiController.genRect1(row1, col1, row2, col2, ref rois);
|
||||
}
|
||||
public void genNurbs(HTuple rows, HTuple cols, ref List<Model.ROI> rois)
|
||||
{
|
||||
this._roiController.genNurbs( rows,cols,ref rois);
|
||||
}
|
||||
public void genInitRect1( ref List<Model.ROI> rois)
|
||||
{
|
||||
this._roiController.genInitRect1(_roiController.viewController .imageHeight , ref rois);
|
||||
}
|
||||
|
||||
public void genRect2(double row, double col, double phi, double length1, double length2, ref List<Model.ROI> rois)
|
||||
{
|
||||
this._roiController.genRect2(row, col, phi, length1, length2, ref rois);
|
||||
}
|
||||
|
||||
public void genInitRect2(ref List<Model.ROI> rois)
|
||||
{
|
||||
this._roiController.genInitRect2(_roiController.viewController.imageHeight, ref rois);
|
||||
}
|
||||
public void genCircle(double row, double col, double radius, ref List<Model.ROI> rois)
|
||||
{
|
||||
this._roiController.genCircle(row, col, radius, ref rois);
|
||||
@@ -198,20 +209,21 @@ namespace ViewWindow
|
||||
|
||||
foreach (var roi in rois)
|
||||
{
|
||||
HTuple m_roiData = null;
|
||||
m_roiData = roi.getModelData();
|
||||
|
||||
|
||||
switch (roi.Type)
|
||||
{
|
||||
case "ROIRectangle1":
|
||||
|
||||
HTuple m_roiData = null;
|
||||
m_roiData = roi.getModelData();
|
||||
if (m_roiData != null)
|
||||
{
|
||||
this._roiController.displayRect1(roi.Color, m_roiData[0].D, m_roiData[1].D, m_roiData[2].D, m_roiData[3].D);
|
||||
}
|
||||
break;
|
||||
case "ROIRectangle2":
|
||||
|
||||
m_roiData = null;
|
||||
m_roiData = roi.getModelData();
|
||||
if (m_roiData != null)
|
||||
{
|
||||
this._roiController.displayRect2(roi.Color, m_roiData[0].D, m_roiData[1].D, m_roiData[2].D, m_roiData[3].D, m_roiData[4].D);
|
||||
@@ -219,19 +231,27 @@ namespace ViewWindow
|
||||
}
|
||||
break;
|
||||
case "ROICircle":
|
||||
|
||||
m_roiData = roi.getModelData();
|
||||
if (m_roiData != null)
|
||||
{
|
||||
this._roiController.displayCircle(roi.Color, m_roiData[0].D, m_roiData[1].D, m_roiData[2].D);
|
||||
}
|
||||
break;
|
||||
case "ROILine":
|
||||
|
||||
m_roiData = roi.getModelData();
|
||||
if (m_roiData != null)
|
||||
{
|
||||
this._roiController.displayLine(roi.Color, m_roiData[0].D, m_roiData[1].D, m_roiData[2].D, m_roiData[3].D);
|
||||
}
|
||||
break;
|
||||
case "ROINurbs":
|
||||
HTuple rows, cols;
|
||||
roi.getModelData(out rows ,out cols );
|
||||
if (rows != null)
|
||||
{
|
||||
this._roiController.displayNurbs(roi.Color, rows, cols);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
Binary file not shown.
BIN
ImageWindow/bin/Debug/HWindow_Final.designer.cs
generated
BIN
ImageWindow/bin/Debug/HWindow_Final.designer.cs
generated
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user