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. 要理解工作原理, ...
随机推荐
- Python中元类
元类(metaclass) 简单地说,元类就是一个能创建类的类,而类class 是由type创建的,class可以创建对象 type与object的关系详见:python中type和object 1. ...
- tesorflow - create neural network+结果可视化+加速神经网络训练+Optimizer+TensorFlow
以下仅为了自己方便查看,绝大部分参考来源:莫烦Python,建议去看原博客 一.添加层 def add_layer() 定义 add_layer()函数 在 Tensorflow 里定义一个添加层的函 ...
- HDU 1796 How many integers can you find 【容斥】
<题目链接> 题目大意: 给你m个数,其中可能含有0,问有多少小于n的正数能整除这个m个数中的某一个. 解题分析: 容斥水题,直接对这m个数(除0以外)及其组合的倍数在[1,n)中的个数即 ...
- POJ 2912 Rochambeau(暴力)+【带权并查集】
<题目链接> 题目大意: n个人进行m轮剪刀石头布游戏(0<n<=500,0<=m<=2000),接下来m行形如x, y, ch的输入,ch='='表示x, y平局 ...
- B. Divisiblity of Differences
B. Divisiblity of Differencestime limit per test1 secondmemory limit per test512 megabytesinputstand ...
- linux 学习笔记三
用户管理篇章 useradd 建立用户 一般用法 #useradd mysql 含义 创建 mysql用户 特殊用户 > #useradd -d /usr/cjh -m cjh 含义 创建 cj ...
- BZOJ.1492.[NOI2007]货币兑换(DP 斜率优化 CDQ分治/Splay)
BZOJ 洛谷 如果某天能够赚钱,那么一定会在这天把手上的金券全卖掉.同样如果某天要买,一定会把所有钱花光. 那么令\(f_i\)表示到第\(i\)天所拥有的最多钱数(此时手上没有任何金券),可以选择 ...
- Linux基础操作整理
1,目录操作 1.1创建目录 1.1.1使用 mkdir 命令创建目录:mkdir $HOME/testFolder 1.2切换目录 1.2.1使用 cd 命令切换目录:cd $HOME/testFo ...
- MySql中drop、truncate、delete的区别
1.drop:能对table和view 用法: drop table [is exists] 表1,表2,表3....: ①drop是DDL中删除表的操作,会删除表结构和所有数据,并释放空间. ②并 ...
- BZOJ3499 : PA2009 Quasi-template
建立后缀树,用线段树合并求出每个节点子树内部最靠前和最靠后的后缀位置以及相邻后缀距离的最大值,同时求出每个子串能完整匹配的最长后缀的长度. 对于一个子串,如果其长度不小于相邻后缀距离的最大值,且最靠后 ...