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

原文地址:https://www.cnblogs.com/21207-iHome/p/9130186.html

时间: 2024-10-09 18:10:55

VTK使用矢量数据弯曲几何体的相关文章

创建、加载高级网格和几何体

1.对象合并 使用THREE.Group对象作为组合对象,调用它的add函数附加其他几何体.如下面的代码,创建了两个几何体sphere.cube,然后调用group的add函数,把两个几何体组合在一起.代码中的redraw函数在最后调用了position.BoundingBox()函数,用来定位组合体对象的位置.在positionBoundingBox函数中调用了setFromeObject并且返回了一个THREE.Box3对象.这里先不介绍这个对象,直接看后面的代码,通过box.max和box

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

本章的主要内容: 一, 通过Three.js自带的功能来组合和合并已有的几何体,创建出新的几何体 二, 从外部资源中加载网格和几何体 1 前面的章节中,我们学习到,一个几何体创建的网格,想使用多个材质的方法: var mesh=THREE.SceneUtils.createMultiMaterialObject(geometry,[material1,,material2]); 看似一个网格中有一个几何体,多个材质,其实该网格拥有与材质数量相对应的几何体,每个几何体都对应一种材质,形成一个网格,

基于矢量数据的逆地理编码功能实现

地理编码和逆地理编码概述 地理编码,是指将大家熟悉的地址文字描述,转换为经纬度,如输入某某省.某某市.某某路,在地图上根据经纬度定位到输入的地图上的某个点,直观的显示所在位置.逆地理编码是指将经纬度转化为大家都能看懂文字描述.一般人对经纬度数字没什么概念,转化为文字描述后,更容易让人理解.在现在大量的人员定位,车辆监控中,除了在地图上直观的展示人员或者车辆的地图位置外,很多的系统也提供了人员或者车辆所在位置的文字描述功能. 目前大部分系统和项目开发中,逆地理编码功能的实现,都是调用主流厂商提供的

动态时间归整/规整/弯曲(Dynamic time warping,DTW)

动态时间规整DTW 在日常的生活中我们最经常使用的距离毫无疑问应该是欧式距离,但是对于一些特殊情况,欧氏距离存在着其很明显的缺陷,比如说时间序列,举个比较简单的例子,序列A:1,1,1,10,2,3,序列B:1,1,1,2,10,3,如果用欧氏距离,也就是distance[i][j]=(b[j]-a[i])*(b[j]-a[i])来计算的话,总的距离和应该是128,应该说这个距离是非常大的,而实际上这个序列的图像是十分相似的,这种情况下就有人开始考虑寻找新的时间序列距离的计算方法,然后提出了DT

VTK 6.1 安装配置

安装可以参考http://blog.csdn.net/jasonleesjtu/article/details/8211692 过程大致一样. VTK 6.1 相对于VTK 5 在目录结构方面有很大的改动,很多lib文件的名字都换掉了.所以配置部分按上文无法成功.此时可以借助CMake配置文件. cmake_minimum_required(VERSION 2.8.5 FATAL_ERROR) project(Cylinder) find_package(VTK REQUIRED) includ

第04章-VTK基础(7)

[译者:这个系列教程是以Kitware公司出版的<VTK User's Guide -11th edition>一书作的中文翻译(出版时间2010年,ISBN: 978-1-930934-23-8),由于时间关系,我们不能保证每周都能更新本书内容,但尽量做到一周更新一篇到两篇内容.敬请期待^_^.欢迎转载,另请转载时注明本文出处,谢谢合作!同时,由于译者水平有限,出错之处在所难免,欢迎指出订正!] [本小节内容对应原书的第83页至第87页] 4.16 动画 动画是可视化等系统的重要模块: 通过

第04章-VTK基础(5)

[译者:这个系列教程是以Kitware公司出版的<VTK User's Guide -11th edition>一书作的中文翻译(出版时间2010年,ISBN: 978-1-930934-23-8),由于时间关系,我们不能保证每周都能更新本书内容,但尽量做到一周更新一篇到两篇内容.敬请期待^_^.欢迎转载,另请转载时注明本文出处,谢谢合作!同时,由于译者水平有限,出错之处在所难免,欢迎指出订正!] [本小节内容对应原书的第63页至第70页] 4.11 文本标注 VTK提供了两种方法用于标注图像

第02章-VTK安装(2)

[译者:这个系列教程是以Kitware公司出版的<VTK User's Guide -11th edition>一书作的中文翻译(出版时间2010年,ISBN: 978-1-930934-23-8),由于时间关系,我们不能保证每周都能更新本书内容,但尽量做到一周更新一篇到两篇内容.敬请期待^_^.欢迎转载,另请转载时注明本文出处,谢谢合作!同时,由于译者水平有限,出错之处在所难免,欢迎指出订正!] 2.3Windows XP, Vista及以上版本平台下安装VTK Windows平台下有两种安

关于Unity中的几何体

一.创建几何体的类型 1: 创建平面 Plane;2: 创建立方体 Cube;3: 创建球体 Sphere;4: 创建胶囊体 Capsule;5: 创建圆柱体 Cylinder;6: 3D文字 3D text; 创建出来的几何体,自带这些组件: 1.transform 2.Mesh Filter:网格 3.Collider:碰撞体 4.Mesh Renderer:网格绘制,把材质拖进Material属性中就可以绘制出几何体的图案 二.材质 在resources文件夹下面创建一个metarial文