栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

Slicer学习笔记(二十一)slicer的python接口说明

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Slicer学习笔记(二十一)slicer的python接口说明

Slicer学习笔记(二十一)slicer的python接口说明
  • 1、python接口

1、python接口

slicer package
Submodules
slicer.scriptedLoadableModule module
slicer.cli module
此模块是一个占位符,用于实现方便的功能,允许与CLI交互。

slicer.cli.cancel(node)
slicer.cli.createNode(cliModule, parameters=None)

使用可选参数为特定模块创建新的vtkMRMLCommandLineModuleNode

slicer.cli.run(module, node=None, parameters=None, wait_for_completion=False, delete_temporary_files=True, update_display=True)¶

Runs a CLI, optionally given a node with optional parameters, returning back the node (or the new one if created) node: existing parameter node (None by default) parameters: dictionary of parameters for cli (None by default) wait_for_completion: block if True (False by default) delete_temporary_files: remove temp files created during execution (True by default) update_display: show output nodes after completion
运行CLI,可选地指定具有可选参数的节点,返回节点(或新节点,如果已创建)节点:现有参数节点(默认情况下无)参数:CLI参数字典(默认情况下无)等待u完成:如果为True,则阻止(默认情况下为False)删除临时u文件:删除执行期间创建的临时文件(默认为True)更新显示:完成后显示输出节点

slicer.cli.runSync(module, node=None, parameters=None, delete_temporary_files=True, update_display=True)

Run a CLI synchronously, optionally given a node with optional parameters, returning the node (or the new one if created) node: existing parameter node (None by default) parameters: dictionary of parameters for cli (None by default) delete_temporary_files: remove temp files created during execution (True by default) update_display: show output nodes after completion
同步运行CLI(可选)给定一个具有可选参数的节点,返回该节点(或新节点,如果已创建)节点:现有参数节点(默认为无)参数:CLI参数字典(默认为无)删除临时文件:删除执行期间创建的临时文件(默认为真)更新显示:完成后显示输出节点

slicer.cli.setNodeParameters(node, parameters)

Sets parameters for a vtkMRMLCommandLineModuleNode given a dictionary of (parameterName, parameterValue) pairs For vectors: provide a list, tuple or comma-separated string For enumerations, provide the single enumeration value For files and directories, provide a string For images, geometry, points and regions, provide a vtkMRMLNode
设置VTKMRLCommandLineModuleNode的参数,给定向量的(parameterName,parameterValue)对字典:为枚举提供列表、元组或逗号分隔字符串,为文件和目录提供单个枚举值,为图像、几何体、点和区域提供字符串,提供vtkMRMLNode.

slicer.logic module
slicer.testing module

slicer.testing.exitFailure(message='')
slicer.testing.exitSuccess()
slicer.testing.runUnitTest(path, testname)

slicer.util module

slicer.util.DATA_STORE_URL= 'https://github.com/Slicer/SlicerDataStore/releases/download/'

base URL for downloading data from Slicer Data Store. Data store contains atlases, registration case library images, and various sample data sets.

Datasets can be downloaded using URL of the form DATA_STORE_URL + “SHA256/” + sha256ofDataSet

exceptionslicer.util.MRMLNodeNotFoundException

bases: Exception

Exception raised when a requested MRML node was not found.
未找到请求的MRML节点时引发异常。

classslicer.util.NodeModify(node)

bases: object

Context manager to conveniently compress mrml node modified event.
上下文管理器,方便地压缩mrml节点修改事件。

classslicer.util.RenderBlocker

bases: object
Context manager to conveniently pause and resume view rendering. This makes sure that we are not displaying incomplete states to the user. Pausing the views can be useful to improve performance and ensure consistency by skiping all rendering calls until the current code block has completed.
上下文管理器,方便地暂停和恢复视图渲染。这确保我们不会向用户显示不完整的状态。暂停视图有助于提高性能并确保一致性,方法是跳过所有渲染调用,直到当前代码块完成。
Code blocks such as:
代码块,例如:

try:
  slicer.app.pauseRender()
  # Do things
finally:
  slicer.app.resumeRender()

可以写为:

with slicer.util.RenderBlocker():
  # Do things
slicer.util.TESTING_DATA_URL= 'https://github.com/Slicer/SlicerTestingData/releases/download/'

base URL for downloading testing data.
用于下载测试数据的基本URL.
Datasets can be downloaded using URL of the form TESTING_DATA_URL + “SHA256/” + sha256ofDataSet

classslicer.util.VTKObservationMixin

bases: object

addObserver(object, event, method, group='none', priority=0.0)
hasObserver(object, event, method)
observer(event, method)
removeObserver(object, event, method)
removeObservers(method=None)
slicer.util.addParameterEditWidgetConnections(parameterEditWidgets, updateParameterNodeFromGUI)

Add connections to get notification of a widget change.
The function is useful for calling updateParameterNodeFromGUI method in scripted module widgets.
添加连接以获取小部件更改通知。
该函数用于在脚本化模块小部件中调用updateParameterNodeFromGUI方法。

Note
Not all widget classes are supported yet. Report any missing classes at https://discourse.slicer.org.
并非所有小部件类都受支持。请在以下位置报告任何缺失的类:https://discourse.slicer.org.

Example:
例子:

class SurfaceToolboxWidget(scriptedLoadableModuleWidget, VTKObservationMixin):
  ...
  def setup(self):
    ...
    self.parameterEditWidgets = [
      (self.ui.inputModelSelector, "inputModel"),
      (self.ui.outputModelSelector, "outputModel"),
      (self.ui.decimationButton, "decimation"),
      ...]
    slicer.util.addParameterEditWidgetConnections(self.parameterEditWidgets, self.updateParameterNodeFromGUI)

  def updateGUIFromParameterNode(self, caller=None, event=None):
    if self._parameterNode is None or self._updatingGUIFromParameterNode:
      return
    self._updatingGUIFromParameterNode = True
    slicer.util.updateParameterEditWidgetsFromNode(self.parameterEditWidgets, self._parameterNode)
    self._updatingGUIFromParameterNode = False

  def updateParameterNodeFromGUI(self, caller=None, event=None):
    if self._parameterNode is None or self._updatingGUIFromParameterNode:
      return
    wasModified = self._parameterNode.StartModify()  # Modify all properties in a single batch
    slicer.util.updateNodeFromParameterEditWidgets(self.parameterEditWidgets, self._parameterNode)
    self._parameterNode.EndModify(wasModified)
slicer.util.addVolumeFromArray(narray, ijkToRAS=None, name=None, nodeClassName=None)

Create a new volume node from content of a numpy array and add it to the scene.
Voxels values are deep-copied, therefore if the numpy array is modified after calling this method, voxel values in the volume node will not change.
从numpy数组的内容创建新的卷节点,并将其添加到场景中。
体素值是深度复制的,因此,如果在调用此方法后修改numpy数组,则体积节点中的体素值不会更改。

Parameters:

  • narray – numpy array containing volume voxels.
  • ijkToRAS – 4x4 numpy array or vtk.vtkMatrix4x4 that defines mapping from IJK to RAS coordinate system (specifying origin, spacing, directions)
  • name – volume node name
  • nodeClassName – type of created volume, default: vtkMRMLScalarVolumeNode. Use vtkMRMLLabelMapVolumeNode for labelmap volume, vtkMRMLVectorVolumeNode for vector volume.

Returns: created new volume node

Example:

# create zero-filled volume
import numpy as np
volumeNode = slicer.util.addVolumeFromArray(np.zeros((30, 40, 50)))

Example:

# create labelmap volume filled with voxel value of 120
import numpy as np
volumeNode = slicer.util.addVolumeFromArray(np.ones((30, 40, 50), 'int8') * 120,
  np.diag([0.2, 0.2, 0.5, 1.0]), nodeClassName="vtkMRMLLabelMapVolumeNode")
slicer.util.array(pattern='', index=0)

Return the array you are “most likely to want” from the indexth
从索引中返回“最可能需要”的数组.
MRML node that matches the pattern.
与模式匹配的MRML节点。
Raises RuntimeError – if the node cannot be accessed as an array.

Warning
Meant to be used in the python console for quick debugging/testing.
用于python控制台中的快速调试/测试。

参考: Developer Guide » Slicer API » slicer package

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/313429.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号