VTK官方例子

VTK官方例子

vtkMutableDirectedGraph

#!/usr/bin/env python# noinspection PyUnresolvedReferences
import vtkmodules.vtkInteractionStyle
# noinspection PyUnresolvedReferences
import vtkmodules.vtkRenderingOpenGL2
from vtkmodules.vtkCommonColor import vtkNamedColors
from vtkmodules.vtkCommonCore import (vtkIntArray,vtkLookupTable
)
from vtkmodules.vtkCommonDataModel import vtkMutableDirectedGraph
from vtkmodules.vtkViewsCore import vtkViewTheme
from vtkmodules.vtkViewsInfovis import vtkGraphLayoutViewdef main():colors = vtkNamedColors()graph = vtkMutableDirectedGraph()# Create a graphv1 = graph.AddVertex()v2 = graph.AddVertex()v3 = graph.AddVertex()graph.AddGraphEdge(v1, v2)graph.AddGraphEdge(v2, v3)# Create the color arrayedgeColors = vtkIntArray()edgeColors.SetNumberOfComponents(1)edgeColors.SetName('Color')lookupTable = vtkLookupTable()lookupTable.SetNumberOfTableValues(2)lookupTable.SetTableValue(0, colors.GetColor4d('Red'))lookupTable.SetTableValue(1, colors.GetColor4d('Lime'))lookupTable.Build()edgeColors.InsertNextValue(0)edgeColors.InsertNextValue(1)# Add the color array to the graphgraph.GetEdgeData().AddArray(edgeColors)graphLayoutView = vtkGraphLayoutView()graphLayoutView.AddRepresentationFromInput(graph)graphLayoutView.SetLayoutStrategy('Simple 2D')graphLayoutView.GetLayoutStrategy().SetEdgeWeightField('Graphs')graphLayoutView.GetLayoutStrategy().SetWeightEdges(1)graphLayoutView.SetEdgeColorArrayName('Color')graphLayoutView.SetEdgeLabelVisibility(1)graphLayoutView.ColorEdgesOn()theme = vtkViewTheme()theme.SetCellLookupTable(lookupTable)graphLayoutView.ApplyViewTheme(theme)graphLayoutView.ResetCamera()graphLayoutView.GetRenderer().GetActiveCamera().Zoom(0.8)graphLayoutView.Render()graphLayoutView.GetLayoutStrategy().SetRandomSeed(0)graphLayoutView.GetInteractor().Initialize()graphLayoutView.GetInteractor().Start()if __name__ == '__main__':main()

请添加图片描述

vtkGraphLayoutView

#!/usr/bin/env python# noinspection PyUnresolvedReferences
import vtkmodules.vtkInteractionStyle
# noinspection PyUnresolvedReferences
import vtkmodules.vtkRenderingOpenGL2
from vtkmodules.vtkCommonColor import vtkNamedColors
from vtkmodules.vtkCommonCore import vtkIntArray
from vtkmodules.vtkCommonDataModel import vtkMutableDirectedGraph
from vtkmodules.vtkViewsInfovis import (vtkGraphLayoutView,vtkRenderedGraphRepresentation
)def main():colors = vtkNamedColors()# Create a graphgraph = vtkMutableDirectedGraph()v1 = graph.AddVertex()v2 = graph.AddVertex()graph.AddEdge(v1, v2)# Create an array for the vertex labelsvertexIDs = vtkIntArray()vertexIDs.SetNumberOfComponents(1)vertexIDs.SetName('VertexIDs')# Set the vertex labelsvertexIDs.InsertNextValue(0)vertexIDs.InsertNextValue(1)# Add the array to the graphgraph.GetVertexData().AddArray(vertexIDs)graphLayoutView = vtkGraphLayoutView()graphLayoutView.AddRepresentationFromInput(graph)graphLayoutView.SetVertexLabelVisibility(1)rGraph = vtkRenderedGraphRepresentation()rGraph.SafeDownCast(graphLayoutView.GetRepresentation()).GetVertexLabelTextProperty().SetColor(colors.GetColor3d('Red'))graphLayoutView.SetLayoutStrategyToSimple2D()graphLayoutView.SetVertexLabelArrayName('VertexIDs')graphLayoutView.SetVertexLabelVisibility(True)graphLayoutView.ResetCamera()graphLayoutView.GetRenderer().GetActiveCamera().Zoom(0.8)graphLayoutView.Render()graphLayoutView.GetInteractor().Start()if __name__ == '__main__':main()

在这里插入图片描述

ImageWeightedSum

#!/usr/bin/env python# noinspection PyUnresolvedReferences
import vtkmodules.vtkInteractionStyle
# noinspection PyUnresolvedReferences
import vtkmodules.vtkRenderingOpenGL2
from vtkmodules.vtkCommonColor import vtkNamedColors
from vtkmodules.vtkImagingCore import vtkImageCast
from vtkmodules.vtkImagingMath import vtkImageWeightedSum
from vtkmodules.vtkImagingSources import (vtkImageMandelbrotSource,vtkImageSinusoidSource
)
from vtkmodules.vtkRenderingCore import (vtkImageActor,vtkRenderWindow,vtkRenderWindowInteractor,vtkRenderer
)def main():colors = vtkNamedColors()# Create image 1source1 = vtkImageMandelbrotSource()source1.SetWholeExtent(0, 255, 0, 255, 0, 0)source1.Update()source1Double = vtkImageCast()source1Double.SetInputConnection(0, source1.GetOutputPort())source1Double.SetOutputScalarTypeToDouble()# Create image 2source2 = vtkImageSinusoidSource()source2.SetWholeExtent(0, 255, 0, 255, 0, 0)source2.Update()# Do the sumsumFilter = vtkImageWeightedSum()sumFilter.SetWeight(0, 0.8)sumFilter.SetWeight(1, 0.2)sumFilter.AddInputConnection(source1Double.GetOutputPort())sumFilter.AddInputConnection(source2.GetOutputPort())sumFilter.Update()# Display the imagessource1CastFilter = vtkImageCast()source1CastFilter.SetInputConnection(source1.GetOutputPort())source1CastFilter.SetOutputScalarTypeToUnsignedChar()source1CastFilter.Update()source2CastFilter = vtkImageCast()source2CastFilter.SetInputConnection(source2.GetOutputPort())source2CastFilter.SetOutputScalarTypeToUnsignedChar()source2CastFilter.Update()summedCastFilter = vtkImageCast()summedCastFilter.SetInputConnection(sumFilter.GetOutputPort())summedCastFilter.SetOutputScalarTypeToUnsignedChar()summedCastFilter.Update()# Create actorssource1Actor = vtkImageActor()source1Actor.GetMapper().SetInputConnection(source1CastFilter.GetOutputPort())source2Actor = vtkImageActor()source2Actor.GetMapper().SetInputConnection(source2CastFilter.GetOutputPort())summedActor = vtkImageActor()summedActor.GetMapper().SetInputConnection(summedCastFilter.GetOutputPort())# There will be one render windowrenderWindow = vtkRenderWindow()renderWindow.SetSize(600, 300)# And one interactorinteractor = vtkRenderWindowInteractor()interactor.SetRenderWindow(renderWindow)# Define viewport ranges# (xmin, ymin, xmax, ymax)leftViewport = [0.0, 0.0, 0.33, 1.0]centerViewport = [0.33, 0.0, .66, 1.0]rightViewport = [0.66, 0.0, 1.0, 1.0]# Setup renderersleftRenderer = vtkRenderer()renderWindow.AddRenderer(leftRenderer)leftRenderer.SetViewport(leftViewport)leftRenderer.SetBackground(colors.GetColor3d('Peru'))centerRenderer = vtkRenderer()renderWindow.AddRenderer(centerRenderer)centerRenderer.SetViewport(centerViewport)centerRenderer.SetBackground(colors.GetColor3d('DarkTurquoise'))rightRenderer = vtkRenderer()renderWindow.AddRenderer(rightRenderer)rightRenderer.SetViewport(rightViewport)rightRenderer.SetBackground(colors.GetColor3d('SteelBlue'))leftRenderer.AddActor(source1Actor)centerRenderer.AddActor(source2Actor)rightRenderer.AddActor(summedActor)leftRenderer.ResetCamera()centerRenderer.ResetCamera()rightRenderer.ResetCamera()renderWindow.SetWindowName('ImageWeightedSum')renderWindow.Render()interactor.Start()if __name__ == '__main__':main()

请添加图片描述

writeImageData

#!/usr/bin/env python# noinspection PyUnresolvedReferences
import vtkmodules.vtkInteractionStyle
# noinspection PyUnresolvedReferences
import vtkmodules.vtkRenderingOpenGL2
from vtkmodules.vtkCommonColor import vtkNamedColors
from vtkmodules.vtkCommonCore import VTK_DOUBLE
from vtkmodules.vtkCommonDataModel import vtkImageData
from vtkmodules.vtkFiltersGeometry import vtkImageDataGeometryFilter
from vtkmodules.vtkIOXML import (vtkXMLImageDataReader,vtkXMLImageDataWriter
)
from vtkmodules.vtkRenderingCore import (vtkActor,vtkPolyDataMapper,vtkRenderWindow,vtkRenderWindowInteractor,vtkRenderer
)def get_program_parameters():import argparsedescription = 'Generate image data, edit data points, store and reload it.'epilogue = ''''''parser = argparse.ArgumentParser(description=description, epilog=epilogue)parser.add_argument('filename', help='A required vtk filename, e.g. writeImageData.vti.', nargs='?',const='writeImageData.vti',type=str, default='writeImageData.vti')args = parser.parse_args()return args.filenamedef main():colors = vtkNamedColors()filename = get_program_parameters()imageData = vtkImageData()imageData.SetDimensions(3, 4, 5)imageData.AllocateScalars(VTK_DOUBLE, 1)dims = imageData.GetDimensions()# Fill every entry of the image data with '2.0'for z in range(dims[2]):for y in range(dims[1]):for x in range(dims[0]):imageData.SetScalarComponentFromDouble(x, y, z, 0, 2.0)writer = vtkXMLImageDataWriter()writer.SetFileName(filename)writer.SetInputData(imageData)writer.Write()# Read the file (to test that it was written correctly)reader = vtkXMLImageDataReader()reader.SetFileName(filename)reader.Update()# Convert the image to a polydataimageDataGeometryFilter = vtkImageDataGeometryFilter()imageDataGeometryFilter.SetInputConnection(reader.GetOutputPort())imageDataGeometryFilter.Update()mapper = vtkPolyDataMapper()mapper.SetInputConnection(imageDataGeometryFilter.GetOutputPort())actor = vtkActor()actor.SetMapper(mapper)actor.GetProperty().SetPointSize(3)# Setup renderingrenderer = vtkRenderer()renderer.AddActor(actor)renderer.SetBackground(colors.GetColor3d('White'))renderer.ResetCamera()renderWindow = vtkRenderWindow()renderWindow.AddRenderer(renderer)renderWindowInteractor = vtkRenderWindowInteractor()renderWindowInteractor.SetRenderWindow(renderWindow)renderWindowInteractor.Initialize()renderWindowInteractor.Start()if __name__ == '__main__':main()

EnhanceEdges

#!/usr/bin/env python# noinspection PyUnresolvedReferences
import vtkmodules.vtkRenderingOpenGL2
from vtkmodules.vtkIOImage import vtkImageReader2Factory
from vtkmodules.vtkImagingColor import vtkImageMapToWindowLevelColors
from vtkmodules.vtkImagingCore import vtkImageCast
from vtkmodules.vtkImagingGeneral import vtkImageLaplacian
from vtkmodules.vtkImagingMath import vtkImageMathematics
from vtkmodules.vtkInteractionStyle import vtkInteractorStyleImage
from vtkmodules.vtkRenderingCore import (vtkImageActor,vtkRenderWindow,vtkRenderWindowInteractor,vtkRenderer
)def main():# colors = vtkNamedColors()fileName = "D:/vtk/vtk-examples-master/src/Testing/Data/FullHead.mhd"# Read the image.readerFactory = vtkImageReader2Factory()reader = readerFactory.CreateImageReader2(fileName)reader.SetFileName(fileName)reader.Update()scalarRange = [0] * 2scalarRange[0] = reader.GetOutput().GetPointData().GetScalars().GetRange()[0]scalarRange[1] = reader.GetOutput().GetPointData().GetScalars().GetRange()[1]print("Range:", scalarRange)middleSlice = 22# Work with triple images.cast = vtkImageCast()cast.SetInputConnection(reader.GetOutputPort())cast.SetOutputScalarTypeToDouble()cast.Update()laplacian = vtkImageLaplacian()laplacian.SetInputConnection(cast.GetOutputPort())laplacian.SetDimensionality(3)enhance = vtkImageMathematics()enhance.SetInputConnection(0, cast.GetOutputPort())enhance.SetInputConnection(1, laplacian.GetOutputPort())enhance.SetOperationToSubtract()colorWindow = (scalarRange[1] - scalarRange[0])colorLevel = colorWindow / 2# Map the image through the lookup table.originalColor = vtkImageMapToWindowLevelColors()originalColor.SetWindow(colorWindow)originalColor.SetLevel(colorLevel)originalColor.SetInputConnection(reader.GetOutputPort())originalActor = vtkImageActor()originalActor.GetMapper().SetInputConnection(originalColor.GetOutputPort())originalActor.GetProperty().SetInterpolationTypeToNearest()originalActor.SetDisplayExtent(reader.GetDataExtent()[0], reader.GetDataExtent()[1],reader.GetDataExtent()[2], reader.GetDataExtent()[3],middleSlice, middleSlice)laplacianColor = vtkImageMapToWindowLevelColors()laplacianColor.SetWindow(1000)laplacianColor.SetLevel(0)laplacianColor.SetInputConnection(laplacian.GetOutputPort())laplacianActor = vtkImageActor()laplacianActor.GetMapper().SetInputConnection(laplacianColor.GetOutputPort())laplacianActor.GetProperty().SetInterpolationTypeToNearest()laplacianActor.SetDisplayExtent(originalActor.GetDisplayExtent())enhancedColor = vtkImageMapToWindowLevelColors()enhancedColor.SetWindow(colorWindow)enhancedColor.SetLevel(colorLevel)enhancedColor.SetInputConnection(enhance.GetOutputPort())enhancedActor = vtkImageActor()enhancedActor.GetMapper().SetInputConnection(enhancedColor.GetOutputPort())enhancedActor.GetProperty().SetInterpolationTypeToNearest()enhancedActor.SetDisplayExtent(originalActor.GetDisplayExtent())# Setup the renderers.originalRenderer = vtkRenderer()originalRenderer.AddActor(originalActor)laplacianRenderer = vtkRenderer()laplacianRenderer.AddActor(laplacianActor)enhancedRenderer = vtkRenderer()enhancedRenderer.AddActor(enhancedActor)renderers = list()renderers.append(originalRenderer)renderers.append(laplacianRenderer)renderers.append(enhancedRenderer)# Setup viewports for the renderers.rendererSize = 400xGridDimensions = 3yGridDimensions = 1renderWindow = vtkRenderWindow()renderWindow.SetSize(rendererSize * xGridDimensions, rendererSize * yGridDimensions)for row in range(0, yGridDimensions):for col in range(xGridDimensions):index = row * xGridDimensions + col# (xmin, ymin, xmax, ymax)viewport = [float(col) / xGridDimensions, float(yGridDimensions - (row + 1)) / yGridDimensions,float(col + 1) / xGridDimensions, float(yGridDimensions - row) / yGridDimensions]renderers[index].SetViewport(viewport)renderWindow.AddRenderer(renderers[index])renderWindow.SetWindowName('EnhanceEdges')renderWindowInteractor = vtkRenderWindowInteractor()style = vtkInteractorStyleImage()renderWindowInteractor.SetInteractorStyle(style)renderWindowInteractor.SetRenderWindow(renderWindow)# Renderers share one camera.renderWindow.Render()renderers[0].GetActiveCamera().Dolly(1.5)renderers[0].ResetCameraClippingRange()for r in range(1, len(renderers)):renderers[r].SetActiveCamera(renderers[0].GetActiveCamera())renderWindowInteractor.Initialize()renderWindowInteractor.Start()def get_program_parameters():import argparsedescription = 'High-pass filters can extract and enhance edges in an image.'epilogue = '''Subtraction of the Laplacian (middle) from the original image (left) resultsin edge enhancement or a sharpening operation (right).'''parser = argparse.ArgumentParser(description=description, epilog=epilogue,formatter_class=argparse.RawDescriptionHelpFormatter)parser.add_argument('filename', help='FullHead.mhd.')args = parser.parse_args()return args.filenameif __name__ == '__main__':main()

在这里插入图片描述

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/diannao/10572.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

EasyExcel自定义数据格式化

自定格式常量类 public class ExcelFormatConstants {public static final String DATE_FORMAT "yyyy-MM-dd";public static final String NUMBER_FORMAT_DEFAULT "#,##0.00";public static final String NUMBER_FORMAT_FOUR_DECIMAL "#,##0.0000…

Apache Flume事务

Apache Flume 中的事务处理是指 Flume Agent 在处理事件流时的一种机制,用于确保数据的可靠传输和处理。 1. 事务概述: Flume 中的事务是指一组事件的传输和处理,这些事件在传输过程中要么全部成功完成,要么全部失败&#xff0…

Jsp+Servlet实现图片上传和点击放大预览功能(提供Gitee源码)

前言:在最近老项目的开发中,需要做一个图片上传和点击放大的功能,在Vue和SpringBoot框架都有现成封装好的组件和工具类,对于一些上世纪的项目就没这么方便了,所以需要自己用原生的代码去编写,这里分享一下我…

01.Net基础知识

.Net的用途 Web、移动、云、桌面、游戏开发、物联网 (IDE:集成开发环境) .Net学习资源 Microsoft Learn、GitHub、G码云(Gitee) Visual Studio初步使用 1)可创建的项目种类(主要学习以下四…

JSON.parse()反序列化数据丢失

序列化:将数据转换为字符串的过程称为序列化。在序列化过程中,数据结构(比如对象、数组等)被转换成一个字符串形式,这个字符串通常以特定的格式表示,比如 JSON 或 XML。 反序列化:反序列化是序…

React Native跨平台开发实战:从零到一

最近在学习React Native跨平台开发,从零开始如何开发第一个基础应用并打包发布: 1. 环境准备 安装Node.js安装React Native CLI设置Android或iOS开发环境(取决于你想要支持的平台) 2. 创建新项目 使用React Native CLI创建一个…

Maven 的仓库、周期和插件

优质博文:IT-BLOG-CN 一、Maven 仓库 在Maven的世界中,任何一个依赖、插件或者项目构建的输出,都可以称为构建。Maven在某个统一的位置存储所有项目的共享的构建,这个统一的位置,我们就称之为仓库。任何的构建都有唯一…

经典权限五张表功能实现

文章目录 用户模块(未使用框架)查询功能实现步骤代码 新增功能实现步骤代码 修改功能实现步骤代码实现 删除功能实现步骤代码实现 用户模块会了,其他两个模块与其类似 用户模块(未使用框架) 查询功能 这里将模糊查询和分页查询写在一起 实现步骤 前端&#xff1…

翻译/润色找哪里比较专业,机构怎么选?

英文专业术语多,润色是很有必要的,大家可以选择专业的文章翻译润色服务,一定要挑选好正规的机构,这样的机构在出版过程中会为作者提供多项支持,对顺利发表是有帮助的。 科研领域英文论文专业润色包含这些内容&#xff…

基于Huffman编码的字符串统计及WPL计算

一、问题描述 问题概括: 给定一个字符串或文件,基于Huffman编码方法,实现以下功能: 1.统计每个字符的频率。 2.输出每个字符的Huffman编码。 3.计算并输出WPL(加权路径长度)。 这个问题要求对Huffman编码算…

德国Dürr杜尔机器人维修技巧分析

在工业生产中,杜尔工业机器人因其高效、精准和稳定性而备受青睐。然而,即便是最精良的设备,也难免会出现Drr机械手故障。 一、传感器故障 1. 视觉传感器故障:可能导致机器人无法正确识别目标物,影响工作效率。解决方法…

【页面】3D六边形

<!DOCTYPE html> <html> <head><title>3D正六边形</title><style>body {display: flex;justify-content: center;align-items: center;height: 100vh;margin: 0;}.container {perspective: 1000px;}.hexagon {width: 200px;height: 200px;…

ShellCode详解二

终于到了期待已久的编写代码环节了&#xff0c;哈哈哈哈~ 开始 首先&#xff0c;从上一章中我们了解到&#xff0c;shellcode代码是不可以包含任何的导入表的&#xff0c;所以我们写的所有shellcode代码都不可以调用系统库&#xff0c;这里说的不能调用是指不可以静态包含这些…

Server refused our key 【Navicat Premium 15 】

解决 Navicat Premium 15 SSH 连接报错 Server refused our key 1.1 问题描述 在使用 Navicat Premium 15 连接阿里云RDS数据库 Postgress 时&#xff0c;通过SSH隧道私钥连接报错 “Server refused our key”。 前提&#xff1a;目标服务器已经配置了本地生成的公钥 1.2 环…

Java并发处理

Java并发处理 问题描述:项目中业务编号出现重复编号 生成编号规则&#xff1a;获取数据库表最大值&#xff0c;然后再做1处理&#xff0c;即为新编号&#xff08;因为起始值是不固定的&#xff0c;还存在‘字符数据’格式&#xff0c;做了字典项可配置&#xff0c;所以不能直…

俄罗斯方块的代码实现

文章目录 首先是头文件的引入部分接下来是一些预处理指令接下来定义了两个结构体&#xff1a;接下来是全局变量g_hConsoleOutput&#xff0c;用于存储控制台输出句柄。之后是一系列函数的声明最后是main函数源码 首先是头文件的引入部分 包括stdio.h、string.h、stdlib.h、tim…

知识付费app系统开发案例,在线课程制作系统怎么搭建?你知道吗?

如果教育机构想要自主搭建在线教学习系统&#xff0c;需要专业的开发团队&#xff0c;进行功能板块设计和编程&#xff0c;成本较高&#xff0c;且有很多技术上的难点。那么在线课程制作系统怎么搭建?你知道吗? 其实&#xff0c;并不需要大费周章自主搭建平台&#xff0c;借助…

pypi国内源

pypi国内源 在中国使用Python包索引(PyPI)时&#xff0c;由于网络问题&#xff0c;下载速度可能较慢。为了提高下载速度&#xff0c;可以使用国内的镜像源。以下是一些国内的PyPI镜像源&#xff1a; 阿里云&#xff1a;Simple Index 中国科技大学&#xff1a;Simple Index 豆…

相机标定详解

在使用相机的视觉任务中&#xff0c;我们总是听到相机标定这个词&#xff0c; 那么相机标定到底是干什么&#xff0c; 为什么要进行相机标定呢? 常用的相机标定方法又有哪些呢&#xff1f; 本文试图从这几个方面来详细解释相机标定。 与其他的文章不同&#xff0c; 本文抛开繁…

企业破产重整:从“至暗时刻”到“涅槃重生”

今天我们不谈星辰大海&#xff0c;而是要潜入商业世界的深海区&#xff0c;探索那些濒临绝境的企业是如何借助“破产重整”的神秘力量&#xff0c;实现惊天大逆转的&#xff01; 一、破产重整&#xff0c;到底是个啥&#xff1f; 想象一下&#xff0c;企业像是一位远航的船长…