使用vtk执行光线投射的python包
pycaster的Python项目详细描述
背景
pycaster是一个简单的单模块包(模块也称为 pycaster)包含一个rayCaster类。这个类允许 对于要在由 “vtkpolydata”对象。
rayCaster类充当vtkOBBTree类的包装器 并使用执行光线投射。它可以计算 射线和表面之间的出入点。它还可以 计算光线在 表面,即固体内部。
该类具有一个静态方法“fromstl”,它允许 直接从加载并提取 来自初始化光线投射器的polydata。
文档
由于其 简单。
用法示例
简而言之,使用pycaster的shell将如下所示:
from pycaster import pycaster # Create a new rayCaster object through the 'fromSTL' static-method thus loading # the STL file 'sphereHollow.stl' and creating a new rayCaster under 'caster' caster = pycaster.rayCaster.fromSTL("sphereHollow.stl", scale=1.0) # Set the source and target coordinate of the ray pSource = [-50.0, 0.0, 0.0] pTarget = [50.0, 0.0, 0.0] # Use the 'castRay' method of the 'rayCaster' class to intersect a ray/line with # the surface and return a list of coordinates, i.e., the intersection points pointsIntersection = caster.castRay(pSource, pTarget) # Use the calcDistanceInSolid to calculate the distance the ray 'travels' within # the surface caster.calcDistanceInSolid(pSource, pTarget)
要求
vtk>;=5.10.1鼻子>;=1.3.3
python 3.x支持
在编写^{tt1}时,$无法使用python 3.x作为 VTK Python绑定尚未移植到Python3.x。 pycaster已经用不同的python 2.7.x进行了广泛的测试 版本。
安装
此包已托管在pypi上 here而且很容易 通过PIP安装:
pip install pycaster
或者直接使用setuptools作为源代码:
python setup.py install
但是,给定vtk的pycaster需求,而不是 始终使用PIP轻松构建我强烈建议如下:
- 使用anaconda python发行版。我写了一篇关于 它提供的优势 here。
- 使用conda安装依赖项(请参阅前面的文章)
- 使用pip安装pycaster,同时跳过依赖项 例如:
pip install pycaster --no-deps
测试&ci
pycaster附带用unittest和 使用nose执行批处理。发行版还附带了几个 .stl文件,用于测试包的不同方面。之后 安装您可以在python会话中轻松运行这些测试 使用以下代码:
from pycaster.test import test_all test_all.runTests()