2017-04-03 13 views
0

vtkOBJReader로 가져온 두 OBJ 메쉬간에 레이 캐스트를 수행하고 싶습니다. 정점에서 두 번째 메쉬를 향한 법선 방향으로 광선 캐스팅을하고 싶습니다.OBJ에서 가져온 VTK의 버텍스 위치, 일반 및 색상을 입력합니다.

그러나 첫 번째 메쉬에서 정점 (및 매개 변수)에 액세스하는 방법을 모르겠습니다. 나는 VCT의 셀과 포인트의 개념과 필터에 대해 다소 혼란 스럽다.

다음

내가 액세스 할 수있는 방법은 ... 내가 지금까지 어떻게 관리 무엇

는 vtkCellCenters 객체를 만들고 내 레이 캐스트를 수행하는 데에서 정상 및 지점을 검색 할 수 있었다 그러나 이것은 내가 원하는 걸 정말 아니다 셀 센터와 일반 내 레이 캐스트 시작 : 나는 같은 일을하지만, 버텍스 POS 및 법선을 할 수 있어야합니다

import vtk 

OBJ_SCALE = 100. 
ColorBackground = [0.0, 0.0, 0.0] 
FirstobjPath = r"...my Path to the first OBJ file..." 

reader = vtk.vtkOBJReader() 
reader.SetFileName(FirstobjPath) 

# I scale up object for better precision 
transform = vtk.vtkTransform() 
transform.Scale(OBJ_SCALE, OBJ_SCALE, OBJ_SCALE) 
transformPData = vtk.vtkTransformPolyDataFilter() 
transformPData.SetTransform(transform) 
transformPData.SetInputConnection(reader.GetOutputPort()) 

# I transform poly to triangle for proper indexing 
triangles = vtk.vtkTriangleFilter() 
triangles.SetInputConnection(transformPData.GetOutputPort()) 

# Here is how I get my cell data 
cellCenterCalc = vtk.vtkCellCenters() 
cellCenterCalc.SetInputConnection(triangles.GetOutputPort()) 
cellCenterCalc.Update() 

# I can get the point center with this 
pointsCellCenters = cellCenterCalc.GetOutput(0) 
# and the normals with this 
normalsCalcScan = vtk.vtkPolyDataNormals() 
normalsCalcScan.SetInputConnection(triangles.GetOutputPort()) 


mapper = vtk.vtkPolyDataMapper() 
mapper.SetInputConnection(triangles.GetOutputPort()) 
actor = vtk.vtkActor() 
actor.SetMapper(mapper) 
ren = vtk.vtkRenderer() 
ren.SetBackground(ColorBackground) 
ren.AddActor(actor) 

을 (나는 또한 마스크로 사용 정점 색상에 액세스 할 수 있도록 좋아 어느 버텍스가 레이크 캐스트를해야하는지 필터링하기) 나는 그런 것 같지만 지금까지는 운이 없다고 생각하고 있습니다. 어떤 도움이 많이 주어집니다. ;)

polyData = triangles.GetOutput() 
polyData.GetCellData().GetScalars("Colors") 

답변

0

나는 그와도 고심했다. 다음은 C++에서 꼭지점과면에 액세스하는 방법입니다. 여기에 그들이 법선의 다른 유형에 액세스 어떻게 example입니다 vtkXXXX>vtkSmartPointer <을 쓸 때, 단지 vtkXXXX

void accessEachVertex(const vtkSmartPointer<vtkPolyData>& mesh) 
{ 
    vtkSmartPointer<vtkPoints> vertices = mesh->GetPoints(); 
    vtkSmartPointer<vtkDataArray> verticesArray = vertices->GetData(); 

    long long numberOfVertices = vertices->GetNumberOfPoints(); 

    // access 3D coordinate [x, y, z] of each vertex 
    for(int i = 0; i < numberOfVertices; i++) 
    { 
     float x = verticesArray->GetComponent(i, 0); 
     float y = verticesArray->GetComponent(i, 1); 
     float z = verticesArray->GetComponent(i, 2); 

     .... 
    } 
} 

void accessEachFace(const vtkSmartPointer<vtkPolyData>& mesh) 
{ 
    int numberOfFaces = mesh->GetNumberOfCells(); 

    // acces each mesh face. A face is defined by the indices 
    // of the participating vertices. 
    // this mesh has triangle faces - therefore three vertices. 
    for(int i = 0; i < numberOfFaces; i++) 
    { 
     vtkSmartPointer<vtkIdList> face = vtkSmartPointer<vtkIdList>::New(); 
     mesh->GetCellPoints(i,face); 
     int v0Idx = face->GetId(0); 
     int v1Idx = face->GetId(1); 
     int v2Idx = face->GetId(2); 

     // see the accessEachVertex function 
     // to read the coordinate of vertex v0Idx, 
     // v1Idx or v2Idx 
    } 
} 

에 초점 - 나는 그것이 유사하다 파이썬 바랍니다. 솔직히, 저는 vtk의 법선에 몇 가지 문제가 있습니다. 어떤 경우에는 그들은 그냥 결석하거나 훨씬 더 가능성이 높습니다, 나는 그들을 찾을 수 없습니다 :) 어쨌든, 나는 그들 자신을 computeVertexNormalsTrivial에서 계산합니다. 이 대답에서 뭔가를 얻을 수 있기를 바랍니다.