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使用矢量数据弯曲几何体的更多相关文章

  1. Three.js开发指南---创建,加载高级网格和几何体(第八章)

    本章的主要内容: 一, 通过Three.js自带的功能来组合和合并已有的几何体,创建出新的几何体 二, 从外部资源中加载网格和几何体 1 前面的章节中,我们学习到,一个几何体创建的网格,想使用多个材质 ...

  2. VTK三维点集轮廓凸包提取

    碰撞检测问题在虚拟现实.计算机辅助设计与制造.游戏及机器人等领域有着广泛的应用,甚至成为关键技术.而包围盒算法是进行碰撞干涉初步检测的重要方法之一.包围盒算法是一种求解离散点集最优包围空间的方法.基本 ...

  3. VTK资料收集

    使用Qt Creator开发VTK 原文链接:http://blog.csdn.net/numit/article/details/10200507 VTK应用系列:非常强大!非常善良 05-VTK在 ...

  4. mfc+vtk

    MFC中view类主要处理显示视图,doc类处理文档,mainframe主要为整个窗口的和工程的设置管理.由此,VTK与MFC联合编程时,需要主要的是数据操作,以及显示要很好的与MFC中的结构结合,做 ...

  5. vtk多线程简单测试

    vtkMultithreader is a class that provides support for multithreaded execution using sproc() on an SG ...

  6. Convert PLY to VTK Using PCL 1.6.0 使用PCL库将PLY格式转为VTK格式

    PLY格式是比较流行的保存点云Point Cloud的格式,可以用MeshLab等软件打开,而VTK是医学图像处理中比较常用的格式,可以使用VTK库和ITK库进行更加复杂的运算处理.我们可以使用Par ...

  7. geotrellis使用(八)矢量数据栅格化

    目录 前言 栅格化处理 总结 参考链接 一.前言        首先前几天学习了一下Markdown,今天将博客园的编辑器改为Markdown,从编写博客到界面美观明显都清爽多了,也能写出各种样式的东 ...

  8. vtk工作流

    要理解VTK的工作原理,首先应明确几个类型: 1.vtkSource(数据源)   这个就好比一个剧本里面的角色,让演员知道要演的是什么人物. 数据源有:vtkConeSource,vtkSphere ...

  9. 认识VTK工作原理

    VTk通过数据流实现变信息为图形数据的. 数据流一般为:source-filter--mapper--actor--render--renderwindow--interactor. 要理解工作原理, ...

随机推荐

  1. Ubuntu 硬盘分区只读,重新挂载为读写分区之后,文件依然创建出错

    原因: 分区只读,可能是windows没有正常关机,或者使用了混合休眠模式. 解决方案: sudo mount -o remount,rw /dev/sdaX 若重新挂载后,创建文件以及文件夹失败: ...

  2. 20165235实验四 Android程序设计

    20165235实验四 Android程序设计 实验课程:JAVA编程设计 实验名称:Android开发 姓名:祁瑛 学号:20165235 实验时间:2018.05.16 指导老师:娄家鹏 Andr ...

  3. 使用 PySide2 开发 Maya 插件系列二:继承 uic 转换出来的 py 文件中的类 Ui_Form

    使用 PySide2 开发 Maya 插件系列二:继承 uic 转换出来的 py 文件中的类 Ui_Form 开发环境: Wing IDE 6.1 步骤1: 打开 Wing IDE,创建一个新的 pr ...

  4. Fire! -两次dfs

    题目描述: Joe works in a maze. Unfortunately, portions of the maze have caught on fire, and the owner of ...

  5. so插件化

    --摘自<android插件化开发指南> 1.local.properties添加配置 ndk.dir=/Users/jianqiang/Library/Android/sdk/ndk-b ...

  6. HDU 3488 Tour (最大权完美匹配)【KM算法】

    <题目链接> 题目大意:给出n个点m条单向边边以及经过每条边的费用,让你求出走过一个哈密顿环(除起点外,每个点只能走一次)的最小费用.题目保证至少存在一个环满足条件. 解题分析: 因为要求 ...

  7. Spring BPP中优雅的创建动态代理Bean

    一.前言 本文章所讲并没有基于Aspectj,而是直接通过Cglib以及ProxyFactoryBean去创建代理Bean.通过下面的例子,可以看出Cglib方式创建的代理Bean和ProxyFact ...

  8. WordPress Social Warfare组件 远程代码漏洞执行详细复现

    0x00前言 今天在知道创宇上发现3月26日提交WordPress XSS和远程代码执行漏洞,于是试着复现了下远程代码执行漏洞 该漏洞源于Social Warfare组件,并且版本<=3.5.2 ...

  9. 关于GitHub中文乱码的问题

    其实跟Git里中文乱码相比,这个问题好解决得多. GitHub中的乱码是由于其使用的编码与Windows记事本的默认编码不同.只要在本地将编码改成UTF-8,再重新push就可以了. 修改编码的方法是 ...

  10. Xamarin SQLite教程Xamarin.iOS项目添加引用

    Xamarin SQLite教程Xamarin.iOS项目添加引用 使用直接方式访问SQLite数据库,需要将System.Data和Mono.Data.SQlite库导入到创建的项目中.下面将分别讲 ...