距離の算出(N点間の積算距離)

Namespace: FVIL.Caliper
Assembly: 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 メンバ内容
51FVIL.ErrorCode.LICENSE_ERROR ライセンスキーが見つからない為、実行できません。 または、 FVIL._SetUp.InitVisionLibrary が実行されていません。
11FVIL.ErrorCode.INVALID_PARAMETERパラメータに誤りがあります。
1FVIL.ErrorCode.FAILED_TO_ALLOCATEメモリが確保できません。

Examples

C# Copy imageCopy
//    $Revision: 1.3 $

using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using fvalgcli;    // FvPluginXXXX attribute requires fvalgcli

namespace User.SampleCode
{
    public partial class Caliper
    {
        /// <summary>
        /// 距離の算出(N点間の積算距離)の測定.
        /// </summary>
        /// <remarks>
        /// FVIL.Caliper.Function.Distance(System.Collections.Generic.IList{FVIL.Data.CFviPoint})
        /// </remarks>
        [FvPluginExecute]
        public void Distance_points()
        {
            // 1) 5つの点が格納された点列の生成.
            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));

            // 2) 計測実行.
            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++)
                    {
                        // 2点を通る線分.
                        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 imageCopy
'    $Revision: 1.1 $

Imports System.Collections.Generic
Imports System.Text
Imports System.Drawing
Imports fvalgcli
' FvPluginXXXX attribute requires fvalgcli
Namespace SampleCode
    Public Partial Class Caliper
        ''' <summary>
        ''' 距離の算出(N点間の積算距離)の測定.
        ''' </summary>
        ''' <remarks>
        ''' FVIL.Caliper.Function.Distance(System.Collections.Generic.IList{FVIL.Data.CFviPoint})
        ''' </remarks>
        <FvPluginExecute> _
        Public Sub Distance_points()
            ' 1) 5つの点が格納された点列の生成.
            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))

            ' 2) 計測実行.
            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
                        ' 2点を通る線分.
                        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

ExceptionCondition
FVIL..::..CFviExceptionこの例外の原因については、上記のエラーコード表をご参照ください。

See Also