博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
VTK使用矢量数据弯曲几何体
阅读量:5292 次
发布时间:2019-06-14

本文共 5624 字,大约阅读时间需要 18 分钟。

    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 pythonimport vtkinputPolyData = 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 cellsclean = vtk.vtkCleanPolyData()clean.SetInputData(inputPolyData)# Generate normalsnormals = 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 storedwarp.SetInputArrayToProcess(0, 0, 0,vtk.vtkDataObject.FIELD_ASSOCIATION_POINTS, vtk.vtkDataSetAttributes.NORMALS)# Specify value to scale displacementwarp.SetScaleFactor(1.0) # Visualize the original and warped modelscolors = 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 objectoriginalActor.GetProperty().SetColor(colors.GetColor3d("Flesh"))renderWindow =vtk.vtkRenderWindow()renderWindow.SetSize(640, 480)# Create a camera for all rendererscamera = 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 renderersleftRenderer = 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()
View Code

   膨胀导入的STL模型

#!/usr/bin/env pythonimport vtkinputPolyData = 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 cellsclean = vtk.vtkCleanPolyData()clean.SetInputData(inputPolyData)# Generate normalsnormals = 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 storedwarp.SetInputArrayToProcess(0, 0, 0,vtk.vtkDataObject.FIELD_ASSOCIATION_POINTS, vtk.vtkDataSetAttributes.NORMALS)# Specify value to scale displacementwarp.SetScaleFactor(0.3) # Visualize the original and warped modelscolors = 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 objectoriginalActor.GetProperty().SetColor(colors.GetColor3d("Flesh"))renderWindow =vtk.vtkRenderWindow()renderWindow.SetSize(640, 480)# Create a camera for all rendererscamera = 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 renderersleftRenderer = 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()
View Code

 

 

 

 

参考:

转载于:https://www.cnblogs.com/21207-iHome/p/9130186.html

你可能感兴趣的文章
论文笔记——MobileNets(Efficient Convolutional Neural Networks for Mobile Vision Applications)
查看>>
从今天开始
查看>>
Attribute(特性)与AOP
查看>>
第三次作业
查看>>
Codeforces 962 /2错误 相间位置排列 堆模拟 X轴距离最小值 前向星点双连通分量求只存在在一个简单环中的边...
查看>>
Matrix快速幂 模板
查看>>
laravel command调用方法命令
查看>>
20162302 - 20162319 结对编程项目-四则运算(第一周)
查看>>
用python2和python3伪装浏览器爬取网页
查看>>
MySQL开启远程连接权限
查看>>
tomcat7.0.27的bio,nio.apr高级运行模式
查看>>
SAP HANA 三大特点
查看>>
C#预处理器命令
查看>>
苹果手表:大方向和谷歌一样,硬件分道扬镳
查看>>
ccf 出现次数最多的数
查看>>
单例模式
查看>>
Competing Consumers Pattern (竞争消费者模式)
查看>>
HDUOJ ------1398
查看>>
cf--------(div1)1A. Theatre Square
查看>>
Android面试收集录15 Android Bitmap压缩策略
查看>>