python绘制直线的方法

作者:genispan 时间:2022-10-08 20:01:52 

本文实例为大家分享了python绘制直线的具体代码,供大家参考,具体内容如下


#!/usr/bin/env python

import vtk

# 绘制通用方法
def myshow(linepolydata):
# Now we'll look at it.
lineMapper = vtk.vtkPolyDataMapper()
if vtk.VTK_MAJOR_VERSION <= 5:
 lineMapper.SetInput(linepolydata)
else:
 lineMapper.SetInputData(linepolydata)
 lineMapper.SetScalarRange(0, 2)
lineActor = vtk.vtkActor()
lineActor.SetMapper(lineMapper)

# The usual rendering stuff.
camera = vtk.vtkCamera()
camera.SetPosition(1, 1, 1)
camera.SetFocalPoint(0, 0, 0)

renderer = vtk.vtkRenderer()
renWin = vtk.vtkRenderWindow()
renWin.AddRenderer(renderer)

iren = vtk.vtkRenderWindowInteractor()
iren.SetRenderWindow(renWin)

renderer.AddActor(lineActor)
renderer.SetActiveCamera(camera)
renderer.ResetCamera()
renderer.SetBackground(0, 0, 0)

renWin.SetSize(300, 300)

# interact with data
renWin.Render()
iren.Start()
del lineMapper
del lineActor
del camera
del renderer
del renWin
del iren

def main():
# 直线在三维坐标系中的2个顶点
x = [(0.0, 0.0, 0.0),(1.0, 0.0, 0.0), (0.0, 1.0, 0.0)]

# We'll create the building blocks of polydata including data attributes.
linepoly = vtk.vtkPolyData()
points = vtk.vtkPoints()
lines = vtk.vtkCellArray()
scalars = vtk.vtkFloatArray()

for i in range(3):
 points.InsertNextPoint(x[i])
linepoly.SetPoints(points)

line0 = vtk.vtkLine()
line0.GetPointIds().SetId(0, 0); # 第二个0表示pts中的origin点
line0.GetPointIds().SetId(1, 1); # 第二个1表示pts中的p0点

line1 = vtk.vtkLine()
line1.GetPointIds().SetId(0, 0);
line1.GetPointIds().SetId(1, 2);

lines.InsertNextCell(line0)
lines.InsertNextCell(line1)
linepoly.SetLines(lines);

colors = vtk.vtkUnsignedCharArray()
colors.SetNumberOfComponents(3);
red = [255, 0, 0]
colors.InsertNextTypedTuple(red);
green = [0, 255, 0]
colors.InsertNextTypedTuple(green);
linepoly.GetCellData().SetScalars(colors);

del points
del lines
del scalars
del colors
myshow(linepoly)
# Clean up
del linepoly

main()

python绘制直线的方法

来源:https://blog.csdn.net/genispan/article/details/79584494

标签:python,绘制直线
0
投稿

猜你喜欢

  • python连接数据库的方法

    2024-01-25 18:21:06
  • 10点优化sql数据库技巧

    2008-06-09 15:00:00
  • Python运算符重载用法实例

    2022-11-02 11:33:20
  • 段正淳的css笔记(4)css代码的简写

    2007-11-01 22:03:00
  • jQuery ajaxSubmit 实现ajax提交表单局部刷新

    2024-05-02 17:05:35
  • MySql安装与卸载的详细教程

    2024-01-14 09:47:53
  • MySQL动态字符串处理DYNAMIC_STRING

    2024-01-26 01:20:19
  • vue组件间传值的方法你知道几种

    2024-04-28 09:31:32
  • 菜鸟课堂:详述如何提高MySQL中数据装载效率

    2009-10-23 14:29:00
  • Idea 2019.3 本应该搜索到的插件却搜索不到的解决方法

    2022-03-18 14:42:22
  • 收集的几个Python小技巧分享

    2023-06-14 01:54:01
  • 页面中 CSS 加载方式的优化

    2008-03-26 12:36:00
  • 详解python中index()、find()方法

    2021-02-25 02:38:59
  • pyqt远程批量执行Linux命令程序的方法

    2023-05-08 15:59:06
  • Python机器学习之实现模型持久化与加载

    2022-06-06 14:24:13
  • php session安全问题分析

    2023-11-15 06:45:29
  • python sqlalchemy动态修改tablename两种实现方式

    2023-12-05 06:43:15
  • 详解SQL Server分布式查询

    2010-09-19 09:07:00
  • python Opencv实现停车位识别思路详解

    2023-10-20 21:54:25
  • MySQL优化之InnoDB优化

    2024-01-14 07:06:20
  • asp之家 网络编程 m.aspxhome.com