使用VTK
,可以将任意3d对象渲染到图像。例如,以下代码应该完成任务(它是从更大的项目中复制的,未经测试,仅是为了简化讨论):
# prepare everything
source = vtk.vtkSTLReader()
source.SetFileName("fileName.stl")
mapper = vtk.vtkPolyDataMapper()
mapper.SetInputConnection(source.GetOutputPort())
actor = vtk.vtkActor()
actor.SetMapper(mapper)
# optionaly set some actor's, lights, cameras properties ...
# assign actor to the renderer, render and set to numpy array
render.AddActor(actor)
renderWindow.SetOffScreenRendering(1)
vtk_win_im = vtk.vtkWindowToImageFilter()
vtk_win_im.SetInput( renderWindow )
vtk_win_im.Update()
vtk_image = vtk_win_im.GetOutput()
height, width, _ = vtk_image.GetDimensions()
vtk_array = vtk_image.GetPointData().GetScalars()
components = vtk_array.GetNumberOfComponents()
arr = vtk_to_numpy(vtk_array).reshape(height, width, components)
有人知道,天气可能会以某种方式获得存储在最终数组{{1}中的相应渲染像素值的世界坐标(x
,y
,z
坐标) }?
如果我没记错的话,这种事情在arr
中是可能的,所以从理论上讲,OpenGL
也许也有办法。