VTK使用矢量数据弯曲几何体
vtkWarpVector is a filter that modifies point coordinates by moving points along vector times the scale factor. Useful for showing flow profiles or mechanical deformation. The filter passes both its point data and cell data to its output.
沿法向膨胀
#!/usr/bin/env python
import vtk inputPolyData = vtk.vtkPolyData() sphereSource = vtk.vtkSphereSource()
sphereSource.SetPhiResolution(15)
sphereSource.SetThetaResolution(15)
sphereSource.Update()
inputPolyData = sphereSource.GetOutput() # merge duplicate points, and/or remove unused points and/or remove degenerate cells
clean = vtk.vtkCleanPolyData()
clean.SetInputData(inputPolyData) # Generate normals
normals = vtk.vtkPolyDataNormals()
normals.SetInputConnection(clean.GetOutputPort())
normals.SplittingOff() # vtkWarpVector is a filter that modifies point coordinates by moving points along vector times the scale factor
# Warp using the normals (deform geometry with vector data)
warp = vtk.vtkWarpVector()
warp.SetInputConnection(normals.GetOutputPort()) # Set the input data arrays that this algorithm will process
# The fieldAssociation refers to which field in the data object the array is stored
warp.SetInputArrayToProcess(0, 0, 0,vtk.vtkDataObject.FIELD_ASSOCIATION_POINTS, vtk.vtkDataSetAttributes.NORMALS) # Specify value to scale displacement
warp.SetScaleFactor(1.0) # Visualize the original and warped models
colors = vtk.vtkNamedColors() mapper = vtk.vtkPolyDataMapper()
mapper.SetInputConnection(warp.GetOutputPort()) warpedActor = vtk.vtkActor()
warpedActor.SetMapper(mapper)
warpedActor.GetProperty().SetColor(colors.GetColor3d("Flesh")) originalMapper = vtk.vtkPolyDataMapper()
originalMapper.SetInputConnection(normals.GetOutputPort()) originalActor = vtk.vtkActor()
originalActor.SetMapper(originalMapper)
originalActor.GetProperty().SetInterpolationToFlat() # Set the shading interpolation method for an object
originalActor.GetProperty().SetColor(colors.GetColor3d("Flesh")) renderWindow =vtk.vtkRenderWindow()
renderWindow.SetSize(640, 480) # Create a camera for all renderers
camera = vtk.vtkCamera() # Define viewport ranges: (xmin, ymin, xmax, ymax)
leftViewport = [0.0, 0.0, 0.5, 1.0]
rightViewport =[0.5, 0.0, 1.0, 1.0] # Setup both renderers
leftRenderer = vtk.vtkRenderer()
leftRenderer.SetViewport(leftViewport)
leftRenderer.SetBackground(colors.GetColor3d("Burlywood"))
leftRenderer.SetActiveCamera(camera) rightRenderer = vtk.vtkRenderer()
rightRenderer.SetViewport(rightViewport)
rightRenderer.SetBackground(colors.GetColor3d("CornFlower"))
rightRenderer.SetActiveCamera(camera) leftRenderer.AddActor(originalActor)
rightRenderer.AddActor(warpedActor) rightRenderer.ResetCamera() renderWindow.AddRenderer(rightRenderer)
renderWindow.AddRenderer(leftRenderer) style = vtk.vtkInteractorStyleTrackballCamera() interactor = vtk.vtkRenderWindowInteractor()
interactor.SetRenderWindow(renderWindow)
interactor.SetInteractorStyle(style) renderWindow.Render()
interactor.Start()

膨胀导入的STL模型
#!/usr/bin/env python
import vtk inputPolyData = vtk.vtkPolyData() readerSTL = vtk.vtkSTLReader()
readerSTL.SetFileName("Suzanne.stl")
readerSTL.Update()
inputPolyData = readerSTL.GetOutput() # merge duplicate points, and/or remove unused points and/or remove degenerate cells
clean = vtk.vtkCleanPolyData()
clean.SetInputData(inputPolyData) # Generate normals
normals = vtk.vtkPolyDataNormals()
normals.SetInputConnection(clean.GetOutputPort())
normals.SplittingOff() # Turn off the splitting of sharp edges # vtkWarpVector is a filter that modifies point coordinates by moving points along vector times the scale factor
# Warp using the normals (deform geometry with vector data)
warp = vtk.vtkWarpVector()
warp.SetInputConnection(normals.GetOutputPort()) # Set the input data arrays that this algorithm will process
# The fieldAssociation refers to which field in the data object the array is stored
warp.SetInputArrayToProcess(0, 0, 0,vtk.vtkDataObject.FIELD_ASSOCIATION_POINTS, vtk.vtkDataSetAttributes.NORMALS) # Specify value to scale displacement
warp.SetScaleFactor(0.3) # Visualize the original and warped models
colors = vtk.vtkNamedColors() mapper = vtk.vtkPolyDataMapper()
mapper.SetInputConnection(warp.GetOutputPort()) warpedActor = vtk.vtkActor()
warpedActor.SetMapper(mapper)
warpedActor.GetProperty().SetColor(colors.GetColor3d("Flesh")) originalMapper = vtk.vtkPolyDataMapper()
originalMapper.SetInputConnection(normals.GetOutputPort()) originalActor = vtk.vtkActor()
originalActor.SetMapper(originalMapper)
originalActor.GetProperty().SetInterpolationToFlat() # Set the shading interpolation method for an object
originalActor.GetProperty().SetColor(colors.GetColor3d("Flesh")) renderWindow =vtk.vtkRenderWindow()
renderWindow.SetSize(640, 480) # Create a camera for all renderers
camera = vtk.vtkCamera() # Define viewport ranges: (xmin, ymin, xmax, ymax)
leftViewport = [0.0, 0.0, 0.5, 1.0]
rightViewport =[0.5, 0.0, 1.0, 1.0] # Setup both renderers
leftRenderer = vtk.vtkRenderer()
leftRenderer.SetViewport(leftViewport)
leftRenderer.SetBackground(colors.GetColor3d("Burlywood"))
leftRenderer.SetActiveCamera(camera) rightRenderer = vtk.vtkRenderer()
rightRenderer.SetViewport(rightViewport)
rightRenderer.SetBackground(colors.GetColor3d("CornFlower"))
rightRenderer.SetActiveCamera(camera) leftRenderer.AddActor(originalActor)
rightRenderer.AddActor(warpedActor) rightRenderer.ResetCamera() renderWindow.AddRenderer(rightRenderer)
renderWindow.AddRenderer(leftRenderer) style = vtk.vtkInteractorStyleTrackballCamera() interactor = vtk.vtkRenderWindowInteractor()
interactor.SetRenderWindow(renderWindow)
interactor.SetInteractorStyle(style) renderWindow.Render()
interactor.Start()

参考:
VTK: vtkWarpVector Class Reference
VTK/Examples/Cxx/PolyData/WarpSurface
VTK/Examples/Python/PolyData/WarpVector.py
An algorithm for inflating/deflating (offsetting, buffering) polygons
VTK使用矢量数据弯曲几何体的更多相关文章
- Three.js开发指南---创建,加载高级网格和几何体(第八章)
本章的主要内容: 一, 通过Three.js自带的功能来组合和合并已有的几何体,创建出新的几何体 二, 从外部资源中加载网格和几何体 1 前面的章节中,我们学习到,一个几何体创建的网格,想使用多个材质 ...
- VTK三维点集轮廓凸包提取
碰撞检测问题在虚拟现实.计算机辅助设计与制造.游戏及机器人等领域有着广泛的应用,甚至成为关键技术.而包围盒算法是进行碰撞干涉初步检测的重要方法之一.包围盒算法是一种求解离散点集最优包围空间的方法.基本 ...
- VTK资料收集
使用Qt Creator开发VTK 原文链接:http://blog.csdn.net/numit/article/details/10200507 VTK应用系列:非常强大!非常善良 05-VTK在 ...
- mfc+vtk
MFC中view类主要处理显示视图,doc类处理文档,mainframe主要为整个窗口的和工程的设置管理.由此,VTK与MFC联合编程时,需要主要的是数据操作,以及显示要很好的与MFC中的结构结合,做 ...
- vtk多线程简单测试
vtkMultithreader is a class that provides support for multithreaded execution using sproc() on an SG ...
- Convert PLY to VTK Using PCL 1.6.0 使用PCL库将PLY格式转为VTK格式
PLY格式是比较流行的保存点云Point Cloud的格式,可以用MeshLab等软件打开,而VTK是医学图像处理中比较常用的格式,可以使用VTK库和ITK库进行更加复杂的运算处理.我们可以使用Par ...
- geotrellis使用(八)矢量数据栅格化
目录 前言 栅格化处理 总结 参考链接 一.前言 首先前几天学习了一下Markdown,今天将博客园的编辑器改为Markdown,从编写博客到界面美观明显都清爽多了,也能写出各种样式的东 ...
- vtk工作流
要理解VTK的工作原理,首先应明确几个类型: 1.vtkSource(数据源) 这个就好比一个剧本里面的角色,让演员知道要演的是什么人物. 数据源有:vtkConeSource,vtkSphere ...
- 认识VTK工作原理
VTk通过数据流实现变信息为图形数据的. 数据流一般为:source-filter--mapper--actor--render--renderwindow--interactor. 要理解工作原理, ...
随机推荐
- day64 django django零碎知识点整理
本文转载自紫金葫芦,哪吒,liwenzhou.cnblog博客地址 简单了解mvc框架和MTV框架, mvc是一种简单的软件架构模式: m----model,模型 v---view,视图 c---co ...
- Could not find result map XXX 解决办法
错误定位在xml文件中 resultmap类型不匹配
- TF:Tensorflow定义变量+常量,实现输出计数功能—Jason niu
#TF:Tensorflow定义变量+常量,实现输出计数功能 import tensorflow as tf state = tf.Variable(0, name='Parameter_name_c ...
- web服务-1、http协议的三次握手四次挥手
知识点:http协议:它是基于tcp协议的,浏览器访问服务器,服务器把资源回给浏览器,这个过程都是遵循http协议的,否则无法完成,http早些年是1.0版本,现在基本上都是1.1版本了,俩个版本的区 ...
- hibernate.properties not found
在配置hibernate的主键生成策略的时候突然报出如下错误,寻找了很长时间,虽然不是什么严重的错误,但是希望可以警醒自己 问题: 11:26:21,611 INFO Version:37 - HHH ...
- 使用SpringSecurity
前几天写了一个SpringBoot对拦截器的使用,在实际项目中,对一些情况需要做一些安全验证,比如在没有登录的情况下访问特定的页面应该解释的拦截处理.这一篇介绍使用SpringSecurity来做简单 ...
- Java基础(十三) 文件高级技术
文件高级技术 一.常见文件类型处理 一)属性文件 属性文件很简单,一行表示一个属性,属性就是键值对,键和值用(=)或者(:)分隔. #ready to work name = tang age = p ...
- c++中static变量有什么用
主要有两点用途. 1.让一个变量长期有效,而不管其是在什么地方被申明.比如: int fun1() { static int s_value = 0; .... } 那么fun1不管在什么地方被调用, ...
- python网络编程(四)
TFTP客户端 1. TFTP协议介绍 TFTP(Trivial File Transfer Protocol,简单文件传输协议) 是TCP/IP协议族中的一个用来在客户端与服务器之间进行简单文件传输 ...
- GetLastError
GetLastError返回错误表[0]-操作成功完成. [1]-功能错误. [2]-系统找不到指定的文件. [3]-系统找不到指定的路径. [4]-系统无法打开文件. [5]-拒绝访问. [6]-句 ...