【vtk实例】平面切割
2015-05-06 10:26
706 查看
用到的主要类为 vtkImplicitPlaneWidget2
参考实例:http://www.vtk.org/Wiki/VTK/Examples/Cxx/Widgets/ImplicitPlaneWidget2
界面效果:
参考实例:http://www.vtk.org/Wiki/VTK/Examples/Cxx/Widgets/ImplicitPlaneWidget2
界面效果:
#include <vtkSmartPointer.h> #include <vtkXMLPolyDataReader.h> #include <vtkSphereSource.h> #include <vtkClipPolyData.h> #include <vtkPlane.h> #include <vtkCommand.h> #include <vtkImplicitPlaneWidget2.h> #include <vtkImplicitPlaneRepresentation.h> #include <vtkPolyDataMapper.h> #include <vtkProperty.h> #include <vtkActor.h> #include <vtkRenderWindow.h> #include <vtkRenderer.h> #include <vtkRenderWindowInteractor.h> // Callback for the interaction // This does the actual work: updates the vtkPlane implicit function. // This in turn causes the pipeline to update and clip the object. class vtkIPWCallback : public vtkCommand { public: static vtkIPWCallback *New() { return new vtkIPWCallback; } virtual void Execute(vtkObject *caller, unsigned long, void*) { vtkImplicitPlaneWidget2 *planeWidget = reinterpret_cast<vtkImplicitPlaneWidget2*>(caller); vtkImplicitPlaneRepresentation *rep = reinterpret_cast<vtkImplicitPlaneRepresentation*>(planeWidget->GetRepresentation()); rep->GetPlane(this->Plane); } vtkIPWCallback():Plane(0),Actor(0) {} vtkPlane *Plane; vtkActor *Actor; }; int main(int argc, char *argv[]) { vtkSmartPointer<vtkSphereSource> sphereSource = vtkSmartPointer<vtkSphereSource>::New(); sphereSource->SetRadius(10.0); vtkSmartPointer<vtkXMLPolyDataReader> reader = vtkSmartPointer<vtkXMLPolyDataReader>::New(); // Setup a visualization pipeline vtkSmartPointer<vtkPlane> plane = vtkSmartPointer<vtkPlane>::New(); vtkSmartPointer<vtkClipPolyData> clipper = vtkSmartPointer<vtkClipPolyData>::New(); clipper->SetClipFunction(plane); clipper->InsideOutOn(); if (argc < 2) { clipper->SetInputConnection(sphereSource->GetOutputPort()); } else { reader->SetFileName(argv[1]); clipper->SetInputConnection(reader->GetOutputPort()); } // Create a mapper and actor vtkSmartPointer<vtkPolyDataMapper> mapper = vtkSmartPointer<vtkPolyDataMapper>::New(); mapper->SetInputConnection(clipper->GetOutputPort()); vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New(); actor->SetMapper(mapper); vtkSmartPointer<vtkProperty> backFaces = vtkSmartPointer<vtkProperty>::New(); backFaces->SetDiffuseColor(.8, .8, .4); actor->SetBackfaceProperty(backFaces); // A renderer and render window vtkSmartPointer<vtkRenderer> renderer = vtkSmartPointer<vtkRenderer>::New(); vtkSmartPointer<vtkRenderWindow> renderWindow = vtkSmartPointer<vtkRenderWindow>::New(); renderWindow->AddRenderer(renderer); renderer->AddActor(actor); // An interactor vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor = vtkSmartPointer<vtkRenderWindowInteractor>::New(); renderWindowInteractor->SetRenderWindow(renderWindow); renderWindow->Render(); // The callback will do the work vtkSmartPointer<vtkIPWCallback> myCallback = vtkSmartPointer<vtkIPWCallback>::New(); myCallback->Plane = plane; myCallback->Actor = actor; vtkSmartPointer<vtkImplicitPlaneRepresentation> rep = vtkSmartPointer<vtkImplicitPlaneRepresentation>::New(); rep->SetPlaceFactor(1.25); // This must be set prior to placing the widget rep->PlaceWidget(actor->GetBounds()); rep->SetNormal(plane->GetNormal()); rep->SetOrigin(0,0,50); //this doesn't seem to work? vtkSmartPointer<vtkImplicitPlaneWidget2> planeWidget = vtkSmartPointer<vtkImplicitPlaneWidget2>::New(); planeWidget->SetInteractor(renderWindowInteractor); planeWidget->SetRepresentation(rep); planeWidget->AddObserver(vtkCommand::InteractionEvent,myCallback); // Render renderWindowInteractor->Initialize(); renderWindow->Render(); planeWidget->On(); // Begin mouse interaction renderWindowInteractor->Start(); return EXIT_SUCCESS; }
相关文章推荐
- 基于VTK的任意平面切割
- QT+VTK+PCL实现交互式点云平面切割
- 基于VTK的任意平面切割
- VTK面绘制实例
- Linux(Fedora 16) + elcipse + qt + vtk 结合开发实例
- JCrop+ajaxUpload 图像切割上传的实例代码
- 关于直线,折线切割平面的问题
- vtk类之vtkPlaneSource:创建一个平面的poly data
- VTK实现面模型切割
- c++使用动态规划dp(自底向上)重构解决钢条切割输出最大收益和切割方案及运行实例结果
- VTK经验分享 4. VTK数据集实例
- VTK实现面模型切割
- vtk基本数据结构与模型构建实例讲解
- VTK在MFC中实现的小实例
- 关于直线,折线切割平面的问题
- javascript实现的图片切割多块效果实例
- c++使用动态规划dp(自底向上)重构解决钢条切割输出最大收益和切割方案及运行实例结果
- 人工智能 tensorflow框架-->生成三维数据,然后用一个平面拟合它,伴随训练次数的增加,拟合结果越接近预期值 实例04
- 平面的切割
- nginx常用配置实例(虚拟主机,防盗链,日志切割)