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. 要理解工作原理, ...
随机推荐
- Git submodule 仓库中包含另外的仓库(子仓库)
Git submodule 仓库中包含另外的仓库(子仓库) 添加 submodule 在父仓库 git 目录下: git submodule add ssh://ip/[path]/xxx.git 注 ...
- Django 学习第六天——Django模型基础第一节
一.Django 的 ORM 简介: Django的ORM系统的分析: 1.ORM 概念:对象关系映射(Object Relational Mapping,简称ORM) 2.ORM的优势:不用直接编写 ...
- XamarinSQLite教程Xamarin.Android项目添加引用
XamarinSQLite教程Xamarin.Android项目添加引用 在Xamarin.Android项目中,导入System.Data和Mono.Data.SQLite库的操作步骤如下: (1) ...
- XamarinAndroid组件教程RecylerView适配器使用动画
XamarinAndroid组件教程RecylerView适配器使用动画 为RecylerView使用RecylerViewAnimators组件中提供的适配器动画,需要使用RecyclerView类 ...
- Django单表操作
一.数据库相关设置 配置ORM的loggers日志: # 配置ORM的loggers日志 LOGGING = { 'version': 1, 'disable_existing_loggers': F ...
- Touch事件详解及区别,触屏滑动距离计算
移动端有四个关于触摸的事件,分别是touchstart.touchmove.touchend.touchcancel(比较少用), 它们的触发顺序是touchstart-->touchmove- ...
- 一次ARP病毒排查
XX公司网络卡断问题 1. 问题现象 2017年XX公司机关网络出现几次异常情况,并寻求内外部专家对异常情况进行诊断分析,均未找到原因,具体情况如下: 1.XX分公司机关网络IP地址为10.0.0. ...
- 在UnrealEngine中用Custom节点实现毛玻璃的效果
本人在论坛上找到了一篇实现毛玻璃效果的文章:https://forums.unrealengine.com/showthread.php?70143-So-Blurred-glass-material ...
- 2006 ACM 求奇数的和
题目:http://acm.hdu.edu.cn/showproblem.php?pid=2006 注意 sum=1,写在while 不然每次结果会累积 #include <stdio.h> ...
- Linux之Redis安装
一.下载解压 1 2 3 4 ## 下载Redis wget http://download.redis.io/releases/redis-2.8.17.tar.gz ## 解压 tar zxvf ...