距離の算出(N点間の積算距離)
Namespace: FVIL.CaliperAssembly: FVILbasic (in FVILbasic.dll) Version: 3.1.0.0 (3.1.0.17)
Syntax
C# |
---|
public static double Distance(
IEnumerable<CFviPoint> points
) |
Visual Basic |
---|
Public Shared Function Distance (
points As IEnumerable(Of CFviPoint)
) As Double |
Parameters
- points
- Type: System.Collections.Generic..::..IEnumerable<(Of <(<'CFviPoint>)>)>
座標点群
Return Value
Type:
Double
N点間の積算距離を算出します。
引数(
points)に格納している順番に前後の点の距離の積算を求めます。
正常に実行できなかった場合は例外を発行します。
例外の原因と発生位置を特定するには、発行された例外クラスの ErrorCode メンバと Function メンバを参照してください。
エラーコード:
値 | ErrorCode メンバ | 内容 |
---|
51 | FVIL.ErrorCode.LICENSE_ERROR |
ライセンスキーが見つからない為、実行できません。
または、 FVIL._SetUp.InitVisionLibrary が実行されていません。
|
11 | FVIL.ErrorCode.INVALID_PARAMETER | パラメータに誤りがあります。 |
1 | FVIL.ErrorCode.FAILED_TO_ALLOCATE | メモリが確保できません。 |
Examples
C# | Copy |
---|
using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using fvalgcli;
namespace User.SampleCode
{
public partial class Caliper
{
[FvPluginExecute]
public void Distance_points()
{
System.Collections.Generic.List<FVIL.Data.CFviPoint> points = new List<FVIL.Data.CFviPoint>();
points.Add(new FVIL.Data.CFviPoint(50, 140));
points.Add(new FVIL.Data.CFviPoint(100, 160));
points.Add(new FVIL.Data.CFviPoint(150, 80));
points.Add(new FVIL.Data.CFviPoint(180, 160));
points.Add(new FVIL.Data.CFviPoint(220, 140));
double dist = FVIL.Caliper.Function.Distance(points);
{
FVIL.Data.CFviImage image = new FVIL.Data.CFviImage(320, 240, FVIL.ImageType.UC8, 1);
FVIL.GDI.CFviDisplay display = new FVIL.GDI.CFviDisplay();
FVIL.GDI.CFviOverlay overlay = new FVIL.GDI.CFviOverlay();
{
System.Collections.Generic.List<FVIL.GDI.CFviGdiLineSegment> glines = new List<FVIL.GDI.CFviGdiLineSegment>();
for (int index = 0; index + 1 < points.Count; index++)
{
FVIL.Data.CFviLineSegment lineseg = new FVIL.Data.CFviLineSegment(points[index], points[index + 1]);
glines.Add(new FVIL.GDI.CFviGdiLineSegment(lineseg));
glines[index].Pen.Color = Color.Green;
glines[index].Pen.Width = 1;
glines[index].Pen.Style = FVIL.GDI.PenStyle.Dot;
}
System.Collections.Generic.List<FVIL.GDI.CFviGdiPoint> gpoints = new List<FVIL.GDI.CFviGdiPoint>();
for (int index = 0; index < points.Count; index++)
{
gpoints.Add(new FVIL.GDI.CFviGdiPoint(points[index]));
gpoints[index].Pen.Color = Color.Green;
gpoints[index].Pen.Width = 4;
}
foreach (FVIL.GDI.CFviGdiLineSegment gline in glines)
{
overlay.Figures.Add(gline);
}
foreach (FVIL.GDI.CFviGdiPoint gpoint in gpoints)
{
overlay.Figures.Add(gpoint);
}
overlay.Enable = true;
}
display.Overlays.Add(overlay);
display.Image = image;
display.DisplayRect = image.Window;
FVIL.Data.CFviImage dstimage = new FVIL.Data.CFviImage();
display.SaveImage(dstimage);
FVIL.File.Function.SaveImageFile(Defs.ResultDir + "/Caliper.Distance_points.png", dstimage);
}
}
}
} |
Visual Basic | Copy |
---|
Imports System.Collections.Generic
Imports System.Text
Imports System.Drawing
Imports fvalgcli
Namespace SampleCode
Public Partial Class Caliper
<FvPluginExecute> _
Public Sub Distance_points()
Dim points As System.Collections.Generic.List(Of FVIL.Data.CFviPoint) = New List(Of FVIL.Data.CFviPoint)()
points.Add(New FVIL.Data.CFviPoint(50, 140))
points.Add(New FVIL.Data.CFviPoint(100, 160))
points.Add(New FVIL.Data.CFviPoint(150, 80))
points.Add(New FVIL.Data.CFviPoint(180, 160))
points.Add(New FVIL.Data.CFviPoint(220, 140))
Dim dist As Double = FVIL.Caliper.[Function].Distance(points)
If True Then
Dim image As New FVIL.Data.CFviImage(320, 240, FVIL.ImageType.UC8, 1)
Dim display As New FVIL.GDI.CFviDisplay()
Dim overlay As New FVIL.GDI.CFviOverlay()
If True Then
Dim glines As System.Collections.Generic.List(Of FVIL.GDI.CFviGdiLineSegment) = New List(Of FVIL.GDI.CFviGdiLineSegment)()
Dim index As Integer = 0
While index + 1 < points.Count
Dim lineseg As New FVIL.Data.CFviLineSegment(points(index), points(index + 1))
glines.Add(New FVIL.GDI.CFviGdiLineSegment(lineseg))
glines(index).Pen.Color = Color.Green
glines(index).Pen.Width = 1
glines(index).Pen.Style = FVIL.GDI.PenStyle.Dot
index += 1
End While
Dim gpoints As System.Collections.Generic.List(Of FVIL.GDI.CFviGdiPoint) = New List(Of FVIL.GDI.CFviGdiPoint)()
For index = 0 To points.Count - 1
gpoints.Add(New FVIL.GDI.CFviGdiPoint(points(index)))
gpoints(index).Pen.Color = Color.Green
gpoints(index).Pen.Width = 4
Next
For Each gline As FVIL.GDI.CFviGdiLineSegment In glines
overlay.Figures.Add(gline)
Next
For Each gpoint As FVIL.GDI.CFviGdiPoint In gpoints
overlay.Figures.Add(gpoint)
Next
overlay.Enable = True
End If
display.Overlays.Add(overlay)
display.Image = image
display.DisplayRect = image.Window
Dim dstimage As New FVIL.Data.CFviImage()
display.SaveImage(dstimage)
FVIL.File.[Function].SaveImageFile(Defs.ResultDir & "/Caliper.Distance_points.png", dstimage)
End If
End Sub
End Class
End Namespace |
Exceptions
See Also