一个使用VTK执行光线投射的Python包
项目描述
背景
pycaster是一个简单的单模块包(模块也称为pycaster),它包含一个rayCaster类。这个类允许对任何由‘vtkPolyData’对象表示的网格执行光线投射操作。
rayCaster类是vtkOBBTree类的包装器,并使用它执行光线投射。它可以计算光线与表面之间入口/出口点的坐标。此外,它可以计算光线在表面封闭部分(即实心部分)内行进的距离。
该类具有一个静态方法fromSTL,允许直接从STL文件初始化它,该文件加载并从初始化的光线投射器中提取polydata。
文档
由于pycaster简单,因此没有编写详细的文档。
示例:IPython笔记本
编写了两个IPython笔记本,展示了在STL模型上使用pycaster的方法
使用示例
总之,使用pycaster大致如下
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 nose >= 1.3.3
Python 3.x支持
在撰写本文时,pycaster 由于 VTK Python 绑定尚未移植到 Python 3.x,无法在 Python 3.x 中运行。然而,pycaster 已与不同的 Python 2.7.x 版本进行了广泛的测试。
安装
该软件包已在 PyPI 上托管,地址为 这里,可以通过 pip 容易地安装,如下所示
pip install pycaster
或者直接从源代码使用 setuptools,如下所示
python setup.py install
但是,鉴于 pycaster 对 vtk 的需求,并不总是容易通过 pip 构建,我强烈建议以下方法
使用 Anaconda Python 发行版。我已撰写了一篇关于其提供的优点的博客文章,链接为 此处。
使用 conda 安装依赖项(见上述文章)
使用 pip 安装 pycaster,同时跳过依赖项,如下所示
pip install pycaster --no-deps
测试 & CI
pycaster 包含使用 unittest 编写的测试,并使用 nose 批量执行。此外,该分发还包含用于测试该软件包不同方面的几个 .stl 文件。安装后,您可以使用以下代码在 Python 会话中轻松运行这些测试
from pycaster.test import test_all test_all.runTests()
pycaster 的每个提交都在 Wercker CI 系统上构建和测试。应用程序是公开的,可以通过点击本页顶部的 Wercker 徽标或通过 此链接 访问。
项目详情
pycaster-0.1.1.tar.gz 的散列
算法 | 散列摘要 | |
---|---|---|
SHA256 | b742c1f0a2eff36dc62dfdf57377ce3c05a909254bb21b682f82fe69d9cb9103 |
|
MD5 | 65aa3c08665d7df1d5d42ea3e64c5688 |
|
BLAKE2b-256 | c2a3b8162d52f7f0244f73bb73a30199fd4bd4cb4b70629a5f4c61a3222fef76 |