VMTK学习——02.基本的PYPES教程

写在这里的初衷,一是备忘,二是希望得到高人指点,三是希望能遇到志同道合的朋友。


基本的PYPES教程

最新的稳定版本开发版本
本教程将使您开始使用PypeS。建议的第一步是有效使用vmtk的第一步。
PypeS是vmtk脚本之间的粘合剂。它允许轻松编写新脚本并具有通用接口,但是最重要的是,它允许单个vmtk脚本相互交互,从而使vmtk模块化且灵活。
原始链接http://www.vmtk.org/tutorials/PypesBasic.html
在这里插入图片描述
在这里插入图片描述

让我们键入vmtkmarchingcubes --help(给二进制包用户的注释:您可以在PypePad中键入相同的内容,也可以在命令行前添加vmtk,即在命令行中输入)。 vmtk vmtkmarchingcubes --help。将显示以下文本:

vmtkmarchingcubes --help
Creating vmtkMarchingCubes instance.
Automatic piping vmtkmarchingcubes
Parsing options vmtkmarchingcubes
vmtkmarchingcubes : generate an isosurface of given level from a 3D image
Input arguments:
	-id Id(int,1); default=0: script id
	-handle Self (self,1): handle to self
	-disabled Disabled (bool,1); default=0: disable execution and piping
	-i Image (vtkImageData,1): the input image
	-ifile ImageInputFileName(str,1): filename for the default Image Reader
	-array ArrayName (str,1): name of the array to work with
	-l Level(float,1); default=0.0: graylevel to generate the isosurface at
	-connectivity Connectivity (bool,1); default=0: only output the largest connected region of the isosurface
	-ofile SurfaceOutputFileName (str,1): filename for the default Surface writer
Output arguments:
	-id Id (int,1); default= 0: script id
	-handle Self (self,1): handle to self
	-o Surface (vtkPolyData,1): the output surface

前三行记录了幕后发生的事情:创建了一个PypeS实例,该实例又创建了一个vmtkMarchingCubes实例,并负责将正确的参数传递给它。以下是vmtkmarchingcubes的帮助,以脚本名称,简短描述,输入参数列表和输出参数列表开头。它们依次作为命令行选项,相应的实例变量名称,其必需的类型,默认值和说明进行报告。

在这里插入图片描述
在这里插入图片描述
通过使用内置的I / O功能,我们可以将vmtkmarchingcubes用作独立脚本

vmtkmarchingcubes -ifile foo.vti -ofile foo.vtp

或者我们可以构建一个做同样事情的pype

vmtkimagereader -ifile foo.vti --pipe vmtkmarchingcubes --pipe vmtksurfacewriter -ofile foo.vtp

pype所做的是将每个脚本的自变量与最接近的前一个脚本的匹配自变量进行管道传递。当两个参数具有相同的类型并且其对应的实例变量具有相同的名称时,它们将匹配。阅读上述PypeS生成的日志将有助于澄清发生的情况。

假设我们要在将表面写入磁盘之前先显示该表面。让我们通过管道将查看器放在最后,然后

vmtkimagereader -ifile foo.vti --pipe vmtkmarchingcubes --pipe vmtksurfaceviewer --pipe vmtksurfacewriter -ofile foo.vtp

以及在显示之前对表面进行平滑处理呢?

vmtkimagereader -ifile foo.vti --pipe vmtkmarchingcubes --pipe vmtksurfacesmoothing -passband 0.1 -iterations 30 --pipe vmtksurfaceviewer --pipe vmtksurfacewriter -ofile foo.vtp

另外,请注意,可以通过使用内置I / O功能来简化上述操作

vmtkmarchingcubes -ifile foo.vti --pipe vmtksurfacesmoothing -passband 0.1 -iterations 30 -ofile foo.vtp --pipe vmtksurfaceviewer

除了在此处看到的自动管道连接之外,还可以通过使用@符号显式设置连接,然后使用我们要通过其进行管道传输的脚本名称,并在管道选项上加点。例如,如果我们要显示平滑的表面,但编写不平滑的表面而不更改脚本的顺序,请执行以下操作:

vmtkimagereader -ifile foo.vti --pipe vmtkmarchingcubes --pipe vmtksurfacesmoothing -passband 0.1 -iterations 30 --pipe vmtksurfaceviewer --pipe vmtksurfacewriter -i @vmtkmarchingcubes.o -ofile foo.vtp

当一个引用当前脚本之前的脚本时,可以使用一种简写形式,即省略脚本名称,例如

vmtkimagereader -ifile foo.vti --pipe vmtkmarchingcubes --pipe vmtksurfacesmoothing -passband 0.1 -iterations 30 --pipe vmtksurfacewriter -i @.o -ofile foo.vtp

在这种情况下,vmtksurfacewriter具有从vmtksurfacesmoothing的-o参数显式传递的-ifile参数。(在此示例中,显式管道的输出与自动管道的输出相同)。请谨慎使用此简写形式,因为如果稍后您决定要在vmtksurfacesmoothing和vmtksurfacewriter之间插入脚本,@。o最终将指向新插入的脚本。

另一个功能解决了在同一个管道中具有相同名称的脚本之间进行区分的问题。说我们有两个地面读者和一个作家

vmtksurfacereader -ifile foo1.vtp --pipe vmtksurfacereader -ifile foo2.vtp --pipe vmtksurfacewriter -ofile foo3.vtp

在后一种情况下,编写器将编写来自第二个读取器的表面(自动管道机制将查找向后的第一个匹配参数)。为了手动指定我们要编写来自第一个阅读器的表面,我们可以为每个阅读器分配一个ID,然后使用脚本的ID将第一个阅读器的表面显式地传递给编写器

vmtksurfacereader -ifile foo1.vtp -id 1 --pipe vmtksurfacereader -ifile foo2.vtp -id 2 --pipe vmtksurfacewriter -i @vmtksurfacereader-1.o -ofile foo3.vtp

最后一个功能是可以沿pype推送输入参数。假设我们要读取两个图像,并使用行进立方体提取水平为20的表面。我们可以写

vmtkmarchingcubes -ifile foo1.vti -l 20 --pipe vmtkmarchingcubes -ifile foo2.vti -l 20

或以这种方式将输入参数-l推到第二个vmtkmarchingcubes

vmtkmarchingcubes -ifile foo1.vti -l@ 20 --pipe vmtkmarchingcubes -ifile foo2.vti

在这个例子中,推送实际上并不是很方便,但是当事情变得复杂的时候,您会很高兴地进行推送。
工具箱中的所有脚本都可以通过这种方式进行粘合(无论它们是否属于vmtk,只要它们是从PypeScript基类派生的)。您甚至可以编写自己的PypeScript派生工具,并使它们以相同的方式与vmtk交互(这将在以后的教程中介绍)。
尽管示例中的脚本相互传递了VTK对象,但是PypeS并不了解什么是VTK。类型只是在PypeScript派生类中指定的字符串,因此,如果您想出于不同目的重用PypeS,则非常欢迎这样做。如果您想了解更多,只需看一下脚本,例如vmtk / vmtkScripts / vmtkmarchingcubes.py。这是一个很好的机会,可以欣赏每个脚本使一切正常运行所需的额外代码量很少的事实。如果您认为I / O,选项解析和用法打印会自动处理,那么所需的代码实际上会更少。
现在,您准备好探索vmtk脚本。


以上是自己通过网络查找及自身实践整理所得,大家有更好的建议,可以留言交流!

转载或者引用本文内容请注明来源及原作者

翻译自
http://www.vmtk.org/tutorials/PypesBasic.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值