Monotone Chain法による二次凸包作成

Namespace: fvalgcli
Assembly: fvalgcli (in fvalgcli.dll) Version: 3.1.0.0 (3.1.0.11)

Syntax

C#
public static int fnFIE_convex2d_monochain(
	DPNT_T_PTR pnts,
	int iPntsNum,
	ref DPNT_T_PTR ppHull,
	ref int ipVerNum
)
Visual Basic
Public Shared Function fnFIE_convex2d_monochain ( 
	pnts As DPNT_T_PTR,
	iPntsNum As Integer,
	ByRef ppHull As DPNT_T_PTR,
	ByRef ipVerNum As Integer
) As Integer

Parameters

pnts
Type: fvalgcli..::..DPNT_T_PTR
入力点集合配列
iPntsNum
Type: System..::..Int32
入力点の数(3点以上)
ppHull
Type: fvalgcli..::..DPNT_T_PTR%
出力される凸包の頂点列。(IntPtr.Zero で初期化してください。)
ipVerNum
Type: System..::..Int32%
出力される凸包の頂点の個数

Return Value

Type: Int32
以下のエラーコードを返します。

エラーコード:
f_err内容
F_ERR_NONE正常終了
F_ERR_NOMEMORY メモリ不足で確保に失敗した
F_ERR_INVALID_PARAM パラメータ不正
F_ERR_CALC_IMPOSSIBLE 入力点列が一直線上にある、或いはすべて同一点だった
F_ERR_NO_LICENCEライセンスエラー、または未初期化エラー

Remarks

Examples

C# Copy imageCopy
//    $Revision: 1.1 $

using System;
using System.Collections.Generic;
using System.Text;

using fvalgcli;

namespace TC
{
    public partial class FIE
    {
        [FvPluginExecute]
        public void fnFIE_convex2d_monochain()
        {
            int status = (int)f_err.F_ERR_NONE;

            DPNT_T_PTR pnts = IntPtr.Zero;        // 入力点集合配列.
            int iPntsNum = 0;                    // 入力点の数(3点以上).
            DPNT_T_PTR ppHull = IntPtr.Zero;    // 出力される凸包の頂点列.
            int ipVerNum = 0;                    // 出力される凸包の頂点の個数.

            try
            {
                // 入力点集合配列を確保、設定する.
                const int ans_ipVerNum = 5;
                const int InnerPntsNum = 7;
                const int Min = 5;
                const int Max = 23;

                iPntsNum = ans_ipVerNum + InnerPntsNum;
                pnts = DPNT_T_PTR.alloc(iPntsNum);

                // (外側の点).
                pnts[InnerPntsNum + 0] = DPNT_T.init(Min, Min);
                pnts[InnerPntsNum + 1] = DPNT_T.init(Max, Min);
                pnts[InnerPntsNum + 2] = DPNT_T.init(Max, Max);
                pnts[InnerPntsNum + 3] = DPNT_T.init(Min, Max);
                pnts[InnerPntsNum + 4] = DPNT_T.init(pnts[InnerPntsNum + 0].x, pnts[InnerPntsNum + 0].y);

                // (内側の点).
                Random rand = new Random();
                for (int i = 0; i < InnerPntsNum; i++)
                {
                    pnts[i] = DPNT_T.init(rand.Next(Min + 1, Max - 1), rand.Next(Min + 1, Max - 1));
                }

                // Monotone Chain法による二次凸包作成.
                status = api.fnFIE_convex2d_monochain(pnts, iPntsNum, ref ppHull, ref ipVerNum);

                Assert.IsTrue(status == (int)f_err.F_ERR_NONE, "エラーが発生しました。({0})", (f_err)status);

                // 結果を出力する.
                ConsoleOut.WriteFunctionName(":\t");
                // (compare)
                bool check = true;
                {
                    if (ipVerNum != ans_ipVerNum) check = false;
                    Console.Write("ipVerNum = {0}\n", ipVerNum);

                    Console.Write("\tppHull =");
                    for (int i = 0; i < ipVerNum; i++)
                    {
                        DPNT_T pnt = ppHull[i];
                        if (pnt.x != pnts[InnerPntsNum + i].x || pnt.y != pnts[InnerPntsNum + i].y)
                            check = false;
                        Console.Write("({0}, {1})  ", pnt.x, pnt.y);
                    }
                }
                Console.Write(" ...");
                ConsoleOut.IsTrue(check);
            }
            catch (System.Exception ex)
            {
                throw ex;
            }
            finally
            {
                pnts.Dispose();
                ppHull.Dispose();
            }
        }
    }
}


Visual Basic Copy imageCopy
'    $Revision: 1.1 $

Imports System.Collections.Generic
Imports System.Text

Imports fvalgcli

Public Partial Class FIE
    <FvPluginExecute> _
    Public Sub fnFIE_convex2d_monochain()
        Dim status As Integer = CInt(f_err.F_ERR_NONE)

        Dim pnts As DPNT_T_PTR = IntPtr.Zero
        ' 入力点集合配列.
        Dim iPntsNum As Integer = 0
        ' 入力点の数(3点以上).
        Dim ppHull As DPNT_T_PTR = IntPtr.Zero
        ' 出力される凸包の頂点列.
        Dim ipVerNum As Integer = 0
        ' 出力される凸包の頂点の個数.
        Try
            ' 入力点集合配列を確保、設定する.
            Const  ans_ipVerNum As Integer = 5
            Const  InnerPntsNum As Integer = 7
            Const  Min As Integer = 5
            Const  Max As Integer = 23

            iPntsNum = ans_ipVerNum + InnerPntsNum
            pnts = DPNT_T_PTR.alloc(iPntsNum)

            ' (外側の点).
            pnts(InnerPntsNum + 0) = DPNT_T.init(Min, Min)
            pnts(InnerPntsNum + 1) = DPNT_T.init(Max, Min)
            pnts(InnerPntsNum + 2) = DPNT_T.init(Max, Max)
            pnts(InnerPntsNum + 3) = DPNT_T.init(Min, Max)
            pnts(InnerPntsNum + 4) = DPNT_T.init(pnts(InnerPntsNum + 0).x, pnts(InnerPntsNum + 0).y)

            ' (内側の点).
            Dim rand As New Random()
            For i As Integer = 0 To InnerPntsNum - 1
                pnts(i) = DPNT_T.init(rand.[Next](Min + 1, Max - 1), rand.[Next](Min + 1, Max - 1))
            Next

            ' Monotone Chain法による二次凸包作成.
            status = api.fnFIE_convex2d_monochain(pnts, iPntsNum, ppHull, ipVerNum)

            Assert.IsTrue(status = CInt(f_err.F_ERR_NONE), "エラーが発生しました。({0})", CType(status, f_err))

            ' 結果を出力する.
            ConsoleOut.WriteFunctionName(":" & vbTab)
            ' (compare)
            Dim check As Boolean = True
            If True Then
                If ipVerNum <> ans_ipVerNum Then
                    check = False
                End If
                Console.Write("ipVerNum = {0}" & vbLf, ipVerNum)

                Console.Write(vbTab & "ppHull =")
                For i As Integer = 0 To ipVerNum - 1
                    Dim pnt As DPNT_T = ppHull(i)
                    If pnt.x <> pnts(InnerPntsNum + i).x OrElse pnt.y <> pnts(InnerPntsNum + i).y Then
                        check = False
                    End If
                    Console.Write("({0}, {1})  ", pnt.x, pnt.y)
                Next
            End If
            Console.Write(" ...")
            ConsoleOut.IsTrue(check)
        Catch ex As System.Exception
            Throw ex
        Finally
            pnts.Dispose()
            ppHull.Dispose()
        End Try
    End Sub
End Class

See Also