2

xyz座標のテキストファイルを読み取り、その間にある同等の三角形の面を出力するPython 3.3で簡単なコマンドラインプログラムを作成しています。エクスポート形式は Wavefront obj ファイル ( https://en.wikipedia.org/wiki/Wavefront_.obj_file ) です。このアルゴリズムは、地球の高解像度衛星スキャンからの規則的な間隔のポイントで動作することのみを目的としています。実際、私は約 340000 ポイントのセットを使用して、頂点四重極の間に 2 つの三角形を作成しています。外側の反復は x 方向に進み、内側の反復は y 方向に進みます。したがって、x 方向に移動してプロセスが繰り返されるまで、y 方向のすべての頂点に対して三角形の面のペアが作成されます。原則的なパターンを示します (線は面のエッジです)。

v1--v5--v9
| \ | / |
v2--v6--v10
| / | \ |
v3--v7--v11
| \ | / |
v4--v8--v12

Blender または MeshLab でファイルをインポートすると妥当な結果が得られるため、コードは適切に機能しているように見えますが、1 つのことを除いて、面のペアのすべてのストライプが x 軸に沿って隣接するストライプと接続されていないように見えます。問題を示すレンダリング画像: 接続されていないストライプ.

通常、異なるフェース ストライプ間に垂直方向のオフセットがあってはなりません。これは、それらが内側の境界線 (ライン) に沿って同じ頂点を共有しているためです。より少ない頂点とより一般的な低い座標値を使用したテストは成功しました。メソッドは完全にうまく機能していました。問題は私のメッシュ ジェネレーター内ではなく、Blender、MeshLab などの座標制限内にあるのかもしれません。

以下は、フェースを生成し、return-string ですべてをつなぎ合わせる関数です。

def simpleTriangMesh(verts):
    printAll("--creating simple triangulated mesh", "\n")
    maxCoords = [max(verts[0]), max(verts[1]), max(verts[2])]
    minCoords = [min(verts[0]), min(verts[1]), min(verts[2])]
    printAll("max. coordinates (xyz): \n", maxCoords, "\n")
    printAll("min. coordinates (xyz): \n", minCoords, "\n")

    xVerts = 0 # amount of vertices in x-direction
    yVerts = 0 # amount of vertices in y-direction
    faceAmount = 0 # amount of required faces to skin grid
    i = 0
    temp = verts[0][0]
    while(i < len(verts[0])):
        if(temp < verts[0][i]):
            yVerts = int(i)
            break
        temp = verts[0][i]
        i += 1
    xVerts = int(len(verts[0]) / float(yVerts))
    faceAmount = ((xVerts - 1) * (yVerts - 1)) * 2
    printAll("vertices in x direction: ", xVerts, "\n")
    printAll("vertices in y direction: ", yVerts, "\n")
    printAll("estimated amount of triangle faces: ", 
             faceAmount, "\n")

    printAll("----generating vertex triangles representing the faces", "\n")
    # list of vertex-index quadrupels representing the faces
    faceList = [[0 for line in range(0, 3)] for face in range(0, int(faceAmount))]
    f = 0
    v = 0
    # rather to draw hypotenuse of the triangles from topleft to bottomright 
    # or perpendicular to that (topright to bottomleft)
    tl = True # the one that changes in y-direction
    tl_rem = False # to remember the hypotenuse direction of the last topmost faces
    while(f < len(faceList)):
        # prevent creation of faces at the bottom line
        # + guarantees that v = 1 when creating the first face
        if(( v % yVerts ) == 0):
            v += 1
            tl = not tl_rem
            tl_rem = tl

        if(tl):
            faceList[f][0] = v
            faceList[f][1] = v + yVerts
            faceList[f][2] = v + yVerts + 1
            f += 1
            faceList[f][0] = v
            faceList[f][1] = v + yVerts + 1
            faceList[f][2] = v + 1
        else:
            faceList[f][0] = v
            faceList[f][1] = v + yVerts
            faceList[f][2] = v + 1
            f += 1
            faceList[f][0] = v + 1
            faceList[f][1] = v + yVerts
            faceList[f][2] = v + yVerts + 1

        f += 1
        v += 1
        tl = not tl

    printAll("----preparing obj-file-content for export", "\n")
    rectMesh_Obj = "" # string containing the mesh in obj-format (ascii)
    tempVerts = ""
    tempFaces = ""
    row = 0
    while(row < len(verts[0])):
#         temp = ("v" + " " + str(verts[0][row]) + " " + str(verts[1][row])
#                 + " " + str(verts[2][row]) + "\n")
        temp = ("v" + " " + str(verts[0][row]) + " " + str(verts[2][row])
                + " " + str(verts[1][row]) + "\n")
        tempVerts += temp
        row += 1
    row = 0
    while(row < len(faceList)):
        temp = ("f" 
                + " " + str(int(faceList[row][0]))
                + " " + str(int(faceList[row][1]))
                + " " + str(int(faceList[row][2]))
#                 + " " + str(int(faceList[row][3]))
                + "\n")
        tempFaces += temp
        row += 1
    rectMesh_Obj += tempVerts + tempFaces
    return(rectMesh_Obj)

関数に入力される verts-variable は、次のような 2 次元リストの形式をとります。

#                       x                   y                   z
vertsExample = [[3334, 3333, 3332], [2555, 2554, 2553], [10.2, 5.2, 6.7]]

あなたの何人かが私を悲惨な状態から救ってくれることを願っています。さらに説明が必要な場合はお知らせください。最初の投稿に追加します。

4

1 に答える 1