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,一经查实,立即删除!

相关文章

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)可创建的项目种类(主要学习以下四…

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;…

Java并发处理

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

俄罗斯方块的代码实现

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

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

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

【目标检测论文解读复现NO.37】基于改进的 YOLOv8 变电设备红外图像检测

前言 此前出了目标改进算法专栏&#xff0c;但是对于应用于什么场景&#xff0c;需要什么改进方法对应与自己的应用场景有效果&#xff0c;并且多少改进点能发什么水平的文章&#xff0c;为解决大家的困惑&#xff0c;此系列文章旨在给大家解读最新目标检测算法论文&#xff0c…

C语言基础——循环语句

&#x1f33a;​&#x1f64f;&#x1f64f;&#x1f64f;欢迎大家观看&#xff0c;写的好的话希望三连感谢&#x1f64f;&#x1f64f;&#x1f64f;&#x1f33a; 文章目录 一、循环语句的介绍 二、不同循环语句的使用 1.while循环 1.1 while循环的使用方式 1.2 while循环的执…

【免费Java系列】大家好 ,今天是学习面向对象高级的第十二天点赞收藏关注,持续更新作品 !

这是java进阶课面向对象第一天的课程可以坐传送去学习http://t.csdnimg.cn/Lq3io day10-多线程 一、多线程常用方法 下面我们演示一下getName()、setName(String name)、currentThread()、sleep(long time)这些方法的使用效果。 public class MyThread extends Thread{publi…

进入泛型的世界

泛型的理解和好处 泛型的好处 编译时&#xff0c;检查添加元素的类型&#xff0c;提高了安全性减少了类型转换的次数&#xff0c;提高效率 不使用泛型 Dog-加入->Object-取出->Dog&#xff08;向下转型&#xff09; Dog放入到ArrayList 会先转成Object&#xff0c;在转…

SpringBoot自定义初始化sql文件 支持多类型数据库

我在resources目录下有init.sql初始化sql语句 指定sql文件的地址 sql内容如下&#xff1a; /*角色表*/ INSERT INTO #{schema}ccc_base_role (id, create_time, create_user_id, is_delete, role_name, status, update_time, update_user_id) VALUES(b89e30d81acb88448d412…

壹资源知识付费系统源码-小程序端+pc端

最新整理优化&#xff0c;含微信小程序和pc网页。内置几款主题&#xff0c;并且可以自己更改主题样式&#xff0c;各区块颜色&#xff0c;文字按钮等。 适用于知识付费类资源类行业。如&#xff1a;项目类&#xff0c;小吃技术类&#xff0c;图书类&#xff0c;考研资料类&…

漫谈AI时代的手机

以chatGPT 为代表的大语言的横空出世使人们感受到AI 时代的到来&#xff0c;大语言模型技术的最大特点是机器能”懂人话“&#xff0c;”说人话“了。如同历史上任何一个革命性工具的出现一样&#xff0c;它必将对人类生活和工作产生巨大的影响。 在这里。我们不妨畅想一下啊AI…

IM是什么意思?

IM&#xff08;即时通讯&#xff09;作为现代通讯领域的重要且普遍应用&#xff0c;已成为人们日常生活和工作中不可或缺的通信方式。随着科技的不断发展和互联网的普及&#xff0c;IM工具通过实时信息传递&#xff0c;将沟通变得更加迅速、便捷、高效。 IM的诞生极大地改变了…