• 使用python vtk 生成立体网格


    效果:

     points = vtk.vtkPoints()
        cells = vtk.vtkCellArray()
        polydata = vtk.vtkPolyData()
        mapper = vtk.vtkPolyDataMapper()
    
        rangeX = [-10,10]
        rangeY = [-10,10]
        rangeZ = [-10,10]
    
        intervalX = 2
        intervalY = 2
        intervalZ = 2
    
        for gridZ in range(rangeZ[0],rangeZ[1] + intervalZ,intervalZ):
            for gridX in range(rangeX[0],rangeX[1] + intervalX,intervalX):
                lineStart = [gridX, rangeY[0],gridZ]
                lineEnd = [gridX,rangeY[1],gridZ]
    
                pointIdStart = points.InsertNextPoint(lineStart)
                pointIdEnd = points.InsertNextPoint(lineEnd)
    
                singleLineCell = [pointIdStart,pointIdEnd]
                cells.InsertNextCell(2,singleLineCell)
    
            for gridY in range(rangeY[0],rangeY[1] +intervalY,intervalY):
                lineStart = [gridY, rangeX[0],gridZ]
                lineEnd = [gridY,rangeX[1],gridZ]
    
                pointIdStart = points.InsertNextPoint(lineStart)
                pointIdEnd = points.InsertNextPoint(lineEnd)
    
                singleLineCell = [pointIdStart,pointIdEnd]
                cells.InsertNextCell(2,singleLineCell)
    
        for gridY in range(rangeY[0], rangeY[1] + intervalY , intervalY):
            for gridZ in range(rangeZ[0], rangeZ[1] + intervalZ, intervalZ):
                lineStart = [rangeX[0], gridY, gridZ]
                lineEnd = [rangeX[1], gridY, gridZ]
    
                pointIdStart = points.InsertNextPoint(lineStart)
                pointIdEnd = points.InsertNextPoint(lineEnd)
    
                singleLineCell = [pointIdStart, pointIdEnd]
                cells.InsertNextCell(2, singleLineCell)
    
            for gridX in range(rangeX[0], rangeX[1] +intervalX, intervalX):
                lineStart = [gridX, gridY, rangeZ[0]]
                lineEnd = [gridX, gridY, rangeZ[1]]
    
                pointIdStart = points.InsertNextPoint(lineStart)
                pointIdEnd = points.InsertNextPoint(lineEnd)
    
                singleLineCell = [pointIdStart, pointIdEnd]
                cells.InsertNextCell(2, singleLineCell)
    
        polydata.SetLines(cells)
        polydata.SetPoints(points)
        mapper.SetInputData(polydata)
    
        actor = vtk.vtkActor()
        actor.SetMapper(mapper)
    
        ren1 = vtk.vtkRenderer()
        ren1.AddActor(actor)
        ren1.SetBackground(0.1,0.2,0.4)
    
        renWin = vtk.vtkRenderWindow()
        renWin.AddRenderer(ren1);
        renWin.SetSize(300, 300);
    
        #enderWindowInteractor
        iren = vtk.vtkRenderWindowInteractor();
        iren.SetRenderWindow(renWin);
        style = vtk.vtkInteractorStyleTrackballCamera();
        iren.SetInteractorStyle(style);
    
        renWin.SetSize(600, 600);
        renWin.Render();
        iren.Initialize()
        iren.Start()
    

      

     代码:

  • 相关阅读:
    Centos7更改网卡名为eth0
    Centos7部署Open-Falcon监控
    centos6.x一键15项系统优化(转自努力哥)
    运维题目(十三)
    运维题目(十二)
    Mongodb的学习整理(下)
    Centos7下yum安装mongodb
    浏览器缓存
    控制反转
    js setTimeOut()
  • 原文地址:https://www.cnblogs.com/0523jy/p/16088673.html
Copyright © 2020-2023  润新知