python 切割立方体,python绘制立方体的方法
本文实例为大家分享了python绘制立方体的具体代码,供大家参考,具体内容如下
#!/usr/bin/env python
# This is (almost) a direct C++ to Python transliteration of
# /Examples/DataManipulation/Cxx/Cube.cxx from the VTK
# source distribution, which "shows how to manually create vtkPolyData"
#
# A convenience function, mkVtkIdList(), has been added and one if/else
# so the example also works in version 6 or later.
#
# Lines like `obj->Delete()` have been transliterated as `del obj` to,
# preserve the resemblance to the original C++ example, although I
# doubt this achieves anything beyond what Python's garbage collection
# would do anyway.
import vtk
# Makes a vtkIdList from a Python iterable. I'm kinda surprised that
# this is necessary, since I assumed that this kind of thing would
# have been built into the wrapper and happen transparently, but it
# seems not.
def mkVtkIdList(it):
vil = vtk.vtkIdList()
for i in it:
vil.InsertNextId(int(i))
return vil
# 绘制通用方法
def myShow(cube):
# Now we'll look at it.
cubeMapper = vtk.vtkPolyDataMapper()
if vtk.VTK_MAJOR_VERSION <= 5:
cubeMapper.SetInput(cube)
else:
cubeMapper.SetInputData(cube)
cubeMapper.SetScalarRange(0, 7)
cubeActor = vtk.vtkActor()
cubeActor.SetMapper(cubeMapper)
# 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(cubeActor)
renderer.SetActiveCamera(camera)
renderer.ResetCamera()
renderer.SetBackground(0, 0, 0)
renWin.SetSize(300, 300)
# interact with data
renWin.Render()
iren.Start()
del cubeMapper
del cubeActor
del camera
del renderer
del renWin
del iren
def main():
# x = array of 8 3-tuples of float representing the vertices of a cube:
# 8个三维值代表长方体的8个顶点
x = [(0.0, 0.0, 0.0), (1.0, 0.0, 0.0), (1.0, 1.0, 0.0), (0.0, 1.0, 0.0),
(0.0, 0.0, 1.0), (1.0, 0.0, 1.0), (1.0, 1.0, 1.0), (0.0, 1.0, 1.0)]
# pts = array of 6 4-tuples of vtkIdType (int) representing the faces
# of the cube in terms of the above vertices
# 点的编号0-7,每个面由4个点组成
pts = [(0, 1, 2, 3), (4, 5, 6, 7), (0, 1, 5, 4),
(1, 2, 6, 5), (2, 3, 7, 6), (3, 0, 4, 7)]
# We'll create the building blocks of polydata including data attributes.
cube = vtk.vtkPolyData()
points = vtk.vtkPoints()
polys = vtk.vtkCellArray()
scalars = vtk.vtkFloatArray()
# Load the point, cell, and data attributes.
for i in range(8):
points.InsertPoint(i, x[i])
for i in range(6):
polys.InsertNextCell(mkVtkIdList(pts[i]))
for i in range(8):
scalars.InsertTuple1(i, i)
# We now assign the pieces to the vtkPolyData.
cube.SetPoints(points)
del points
cube.SetPolys(polys)
del polys
cube.GetPointData().SetScalars(scalars)
del scalars
myShow(cube)
# Clean up
del cube
main()
效果图:
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持找一找教程网。
python 切割立方体,python绘制立方体的方法相关推荐
- python画正方体_python绘制立方体的方法
本文实例为大家分享了python绘制立方体的具体代码,供大家参考,具体内容如下 #!/usr/bin/env python # This is (almost) a direct C++ to Pyt ...
- python画圆柱体_python绘制圆柱体的方法
本文实例为大家分享了python绘制圆柱体示的具体代码,供大家参考,具体内容如下 #!/usr/bin/env python import vtk # 参考的C++版本源码及解释 感谢原作者 # ht ...
- python画正切函数_python的pygal模块绘制反正切函数图像方法
python的pygal模块绘制反正切函数图像方法 python是一个很有趣的语言,可以在命令行窗口运行.python中有很多功能强大的模块,这篇经验告诉你,如何使用python的pygal模块绘制反 ...
- 用python画四叶草-python turtle工具绘制四叶草的实例分享
本篇文章介绍了python使用turtle库绘制四叶草的方法,代码很简单,希望对学习python的朋友有帮助. import turtle import time turtle.setup(650., ...
- Panda3D绘制立方体
看一下Panda3D的Tut-Procedural-Cube示例: 一个旋转的立方体: 可以在六个面上添加纹理: 单独看一下绘制立方体这部分代码: from direct.showbase.ShowB ...
- python turtle画滑稽_使用python的turtle函数绘制一个滑稽表情的方法
Turtle库是Python语言中一个很流行的绘制图像的函数库,想象一个小乌龟,在一个横轴为x.纵轴为y的坐标系原点,(0,0)位置开始,它根据一组函数指令的控制,在这个平面坐标系中移动,从而在它爬行 ...
- python键盘输入数组_python 二维数组切割Python读取键盘输入的2种方法
Python提供了两个内置函数从标准输入读入一行文本,默认的标准输入是键盘.如下: 1.raw_input 2.input raw_input函数raw_input() 函数从标准输入读取一个行,并返 ...
- python绘制动画示例_Python使用matplotlib绘制动画的方法
本文实例讲述了Python使用matplotlib绘制动画的方法.分享给大家供大家参考.具体分析如下: matplotlib从1.1.0版本以后就开始支持绘制动画 下面是几个的示例: 第一个例子使用g ...
- python利用matplotlib做饼图_python利用matplotlib库绘制饼图的方法示例
介绍 matplotlib 是python最著名的绘图库,它提供了一整套和matlab相似的命令API,十分适合交互式地进行制图.而且也可以方便地将它作为绘图控件,嵌入GUI应用程序中. 它的文档相当 ...
- 学以致用——Java源码——使用Graphics2D类draw方法绘制立方体(Drawing Cubes)
程序功能: 使用Graphics2D类draw方法绘制立方体 运行示例: 源码: 1. 实体类 import java.awt.Graphics2D; import java.awt.Polygon; ...
最新文章
- 小波阈值图像去噪的实现步骤
- Maven高级之archetype(原型/骨架)开发
- KVM 通过virsh console连入虚拟机
- Ubuntu下使用UFW配置防火墙(简化iptables的操作)
- java 获取季度第一天_Java获取当天、本周、本月、本季度、本年等 开始及结束时间...
- 源码安装natcat
- shell 参数,shell与Java 交互参数
- 设置窗体的可见性无效
- 参加香港亚洲秋季电子展经验点滴拾遗
- 未知高度的非表格垂直对齐
- 基于FPGA的CameraLink视频开发案例
- 如何用SolidWorks软件绘制三维模型?
- HTML期末大学生网页设计作业--官网仿qq音乐(1页)
- 组件化-创建私有组件库库
- 计算机图书管理系统测试用例,图书管理系统测试用例设计.doc
- 膜态沸腾UDF【转载】
- PS工作记录——图片元素复制,智能抠图
- 阿里云天池大数据长期赛:金融风控-贷款违约预测(含代码)
- 考研计算机专业的优点和缺点,领航考研:跨专业考研优缺点分析
- DirectX游戏开发之3D角色动起(下)