传输优化

This commit is contained in:
liu.wenjie
2021-03-17 16:08:13 +08:00
parent 1451352125
commit 0af0e8b01a
348 changed files with 12192 additions and 863190 deletions

View File

@@ -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)
{
}
}

View File

@@ -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()

View File

@@ -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

View File

@@ -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;

View File

@@ -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;
}

View File

@@ -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;

View 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

View File

@@ -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

View File

@@ -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();