2013-06-28 3 views
2

저는 Python 3.3에서 xyz 좌표의 텍스트 파일을 읽고 중간에 등가 삼각형을 출력하는 간단한 명령 행 프로그램을 작성하고 있습니다. 내보내기 형식은 Wavefront obj-files (https://en.wikipedia.org/wiki/Wavefront_.obj_file)입니다. algorthm은 지구의 고해상도 인공위성 스캔으로부터 일정한 간격을 둔 지점으로 작업하기위한 것입니다. 실제로 저는 약 340000 점의 집합을 사용하고 정점 quadrupel 사이에 2 개의 삼각형을 만듭니다. 외부 반복은 x 방향으로 진행하고 내부 반복은 y 방향으로 진행합니다. 따라서 삼각형면 쌍은 x 방향으로 이동하고 과정을 반복 할 때까지 y 방향의 모든 정점에 대해 생성됩니다. 이 코드는 블렌더 또는 MeshLab에서 파일을 가져 오기로 방식으로 작동하는 것 같다 Python 3.3 - 일정한 간격의 정점에서 Wavefront obj 파일로 3D 메쉬 만들기

한 가지를 제외하고, 합리적인 결과를 제공

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

: 모든 줄무늬의 나는 당신에게 원칙 패턴 (라인 얼굴 가장자리이다)를 표시합니다 얼굴 쌍은 x 축을 따라 이웃 사람과 연결되어 있지 않은 것처럼 보입니다. 문제를 나타내는 렌더링 된 그림 : unconnected stripes.

일반적으로 서로 다른면 - 줄무늬가 내부 경계선 (- 선)을 따라 동일한 정점을 공유하기 때문에 서로 다른면 - 줄무늬 사이에 수직 간격 띄우기가 없어야합니다. 정점이 적고 일반적으로 낮은 좌표 값을 가진 테스트가 성공했습니다. 이 방법은 완벽하게 작동했습니다. 어쩌면 문제는 내 메시 생성기가 아닌 Blender, MeshLab 등의 좌표 제한 내에서 찾을 수 있습니다. 유사한

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) 

함수에 입력된다 버텍스 변수는 2 차원에서의 형태를 가진다 : 여기서

는 복귀 문자열 함께 모든 게면 스티치를 생성하는 함수 받는 사람 :

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

저는 여러분 중 일부가 불행에서 벗어날 수 있기를 바랍니다. 더 자세한 설명이 필요한 경우 알려 주시면 첫 번째 게시물에 추가하겠습니다.

답변

1

마침내 문제가 해결되었습니다. 문제는 메쉬 생성 프로그램에 없습니다. Blender와 MeshLab (그리고 다른 3D 프로그램들도 마찬가지 임)은 꼭지점의 좌표가 너무 크면 이상한 일을합니다. 현실 세계를 축소 좌표계로 설정하면 상대적 좌표를 작게 유지하면 모든 것이 잘 작동합니다 (https://dl.dropboxusercontent.com/u/13547611/meshGenWorking001.png).

제 추측 : Wavefront obj 형식의 숫자에 대한 바이트 크기가 너무 작습니다. 또는 더 정확한 것 : 일반적인 3D 프로그램은 숫자가 실제 것 같이 아주 클 것으로 기대하지 않습니다. 이렇게하면 혼란스러운 방식으로 해석합니다.

나는이 솔루션이 앞으로 누군가에게 도움이되기를 바랍니다.