博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
VTK Users Guide 中C++例程之ImplicitPlaneWidget
阅读量:7122 次
发布时间:2019-06-28

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

本人将《The VTK User’s Guide 11th Edition 》中的TCL编写的例程进行了C++的转换,使用的平台是VS2015,VTK版本是8.0.1。之所以贴出来,以求方便大家使用C++来进行VTK的研究。

VTK/Examples/GUI/Tcl/ImplicitPlaneWidget.tcl 之转成C++

1 #include "vtkAutoInit.h"  2 #include "vtkRenderer.h"  3 #include "vtkRenderWindow.h"  4 #include "vtkRenderWindowInteractor.h"  5 #include "vtkSmartPointer.h"  6 #include "vtkSphereSource.h"  7 #include "vtkConeSource.h"  8 #include "vtkGlyph3D.h"  9 #include "vtkAppendPolyData.h" 10 #include "vtkPolyDataMapper.h" 11 #include "vtkLODActor.h" 12 #include "vtkPlane.h" 13 #include "vtkClipPolyData.h" 14 #include "vtkProperty.h" 15 #include "vtkImplicitPlaneWidget.h" 16 #include "vtkCommand.h" 17 #include "vtkCallbackCommand.h" 18  19 static vtkSmartPointer
planeWidget; 20 static vtkSmartPointer
selectActor; 21 static vtkSmartPointer
plane; 22 23 void myCallbackFunction(vtkObject* caller, long unsigned int eventId, void* clientData, void* callData) 24 { 25 planeWidget->GetPlane(plane); 26 selectActor->VisibilityOn(); 27 } 28 29 int main() 30 { 31 VTK_MODULE_INIT(vtkRenderingOpenGL2); 32 VTK_MODULE_INIT(vtkRenderingFreeType); 33 VTK_MODULE_INIT(vtkInteractionStyle); 34 35 //# This example demonstrates how to use the vtkPlaneWidget to probe 36 //# a dataset and then generate contours on the probed data. 37 38 //# Create a mace out of filters. 39 vtkSmartPointer
sphere = vtkSmartPointer
::New(); 40 vtkSmartPointer
cone = vtkSmartPointer
::New(); 41 vtkSmartPointer
glyph = vtkSmartPointer
::New(); 42 glyph->SetInputConnection(sphere->GetOutputPort()); 43 glyph->SetSourceConnection(cone->GetOutputPort()); 44 glyph->SetVectorModeToUseNormal(); 45 glyph->SetScaleModeToScaleByVector(); 46 glyph->SetScaleFactor(0.25); 47 48 //# The sphere and spikes are appended into a single polydata. 49 //# This just makes things simpler to manage. 50 vtkSmartPointer
apd = vtkSmartPointer
::New(); 51 apd->AddInputConnection(glyph->GetOutputPort()); 52 apd->AddInputConnection(sphere->GetOutputPort()); 53 vtkSmartPointer
maceMapper = vtkSmartPointer
::New(); 54 maceMapper->SetInputConnection(apd->GetOutputPort()); 55 vtkSmartPointer
maceActor = vtkSmartPointer
::New(); 56 maceActor->SetMapper(maceMapper); 57 maceActor->VisibilityOn(); 58 59 //# This portion of the code clips the mace with the vtkPlanes 60 //# implicit function.The clipped region is colored green. 61 plane = vtkSmartPointer
::New(); 62 vtkSmartPointer
clipper = vtkSmartPointer
::New(); 63 clipper->SetInputConnection(apd->GetOutputPort()); 64 clipper->SetClipFunction(plane); 65 clipper->InsideOutOn(); 66 vtkSmartPointer
selectMapper = vtkSmartPointer
::New(); 67 selectMapper->SetInputConnection(clipper->GetOutputPort()); 68 selectActor = vtkSmartPointer
::New(); 69 selectActor->SetMapper(selectMapper); 70 selectActor->GetProperty()->SetColor(0, 1, 0); 71 selectActor->VisibilityOff(); 72 selectActor->SetScale(1.01, 1.01, 1.01); 73 74 //Create the Renderer, RenderWindow, RenderWindowInteractor 75 vtkSmartPointer
ren1 = vtkSmartPointer
::New(); 76 vtkSmartPointer
renWin = vtkSmartPointer
::New(); 77 renWin->AddRenderer(ren1); 78 vtkSmartPointer
iren = vtkSmartPointer
::New(); 79 iren->SetRenderWindow(renWin); 80 81 //# Associate the line widget with the interactor 82 planeWidget = vtkSmartPointer
::New(); 83 planeWidget->SetInteractor(iren); 84 planeWidget->SetPlaceFactor(1.25); 85 planeWidget->SetInputConnection(glyph->GetOutputPort()); 86 planeWidget->PlaceWidget(); 87 vtkSmartPointer
myCallback = vtkSmartPointer
::New(); 88 myCallback->SetCallback(myCallbackFunction); 89 planeWidget->AddObserver(vtkCommand::InteractionEvent,myCallback); 90 91 ren1->AddActor(maceActor); 92 ren1->AddActor(selectActor); 93 94 //Add the actors to the renderer; set the background and size; zoom in; 95 //and render. 96 ren1->SetBackground(1, 1, 1); 97 renWin->SetSize(300, 300); 98 ren1->SetBackground(0.1, 0.2, 0.4); 99 100 //ren1->ResetCamera();101 102 renWin->Render();103 iren->Start();104 105 return 0;106 }

 

转载于:https://www.cnblogs.com/liangliu/p/7911023.html

你可能感兴趣的文章
Thread初探
查看>>
磁盘的读写原理
查看>>
配置防盗链、访问控制Directory针对目录、访问控制FilesMatch针对链接
查看>>
Tomcat 仅用ip和端口 不用项目名就能访问项目
查看>>
LNMP平台部署及应用
查看>>
appium python 实例链接
查看>>
redis 关于string数据类型的学习
查看>>
上一个项目的开发中需要实现从word中读取表格数据的功能,在JAVA社区搜索了很多资料,终于找到了两...
查看>>
IP SLA冗余切换
查看>>
关于安全运维中,网络及安全设备基线设置的方法和必要性。
查看>>
nodejs渐入佳境[24]-用户权限-express+mongoDB+authtoken
查看>>
关于GITLAB若干权限问题
查看>>
强大的PDF创建和管理控件ActivePDF Toolkit
查看>>
linux下DNS的配置
查看>>
Android中带分割线的九宫格
查看>>
修改progressbar的样式
查看>>
Python3.x和Python2.x的区别
查看>>
原子变量类Atomic详解(java.util.Concurrent)
查看>>
Nginx 外的另一选择,轻量级开源 Web 服务器 Tengine 发布新版本
查看>>
常见的分布式文件系统介绍
查看>>