[VTK]设置vtkImplicitPlaneWidget2切割平面的初始化位置

本文介绍如何在VTK中通过代码初始化vtkImplicitPlaneWidget2的切割平面位置,避免手动拖动,提高工作效率。示例代码展示了设置法向量和初始点的方法。
摘要由CSDN通过智能技术生成

在完成任意平面切割后经常需要通过计算机设置切割平面位置,不然就需要一直使用手去拖动比较繁琐。

其实可以通过设置vtkImplicitPlaneWidget2的vtkImplicitPlaneRepresentation的值即可:

    // set up representation for vtkImplicitPlaneWidget2 
    // you could set the normal and origin with the value you want 
    vtkSmartPointer<vtkImplicitPlaneRepresentation> rep = 
    vtkSmartPointer<vtkImplicitPlaneRepresentation>::New();
    rep->SetPlaceFactor(1.25); // This must be set prior to placing the widget
    rep->PlaceWidget(coneSkinActor->GetBounds());
#ifndef SET_VALUE
    rep->SetNormal(measureNormal);
    rep->SetOrigin(point3);
#endif
    vtkSmartPointer<vtkImplicitPlaneWidget2> implicitPlaneWidget = vtkImplicitPlaneWidget2::New();
    implicitPlaneWidget->SetInteractor(iren);
    // this set the representation for the widget thus the normal and origin is transfer to the widget
    implicitPlaneWidget->SetRepresentation(rep);

结果如下图:第一图是没有设置法向量和初始点;第二图是初始化切割平面

完整代码:

// GitPro.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <vtkCommand.h>
#include <vtkRenderer.h>
#include <vtkRenderWindow.h>
#include <vtkSphereSource.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkPolyData.h>
#include <vtkPolyDataMapper.h>
#include <vtkClipPolyData.h>
#include <vtkActor.h>
#include <vtkConeSource.h>
#include <vtkPlane.h>
#include <vtkImageActor.h>
#include <vtkImplicitPlaneWidget2.h>
#include <vtkAngleWidget.h>
#include <vtkPlaneWidget.h>
#include <vtkSmartPointer.h>
#include <vtkImplicitPlaneRepresentation.h>
#include <vtkAngleRepresentation3D.h>
#include <vtkPointHandleRepresentation3D.h>
#include <vtkInteractorStyleTrackballCamera.h>
#include <vtkJPEGReader.h>
#include <vtkContourFilter.h>
#include <vtkImageFlip.h>
#include <vtkSmoothPolyDataFilter.h>
#include <vtkPolyDataNormals.h>
#include <vtkStripper.h>
#include <vtkProperty.h>
#include <vtkOutlineFilter.h>
#include <vtkCamera.h>
#include <vtkTriangle.h>
#include <vtkImageViewer2.h>
#include <vtkImageData.h>


class VTKImplicitPlaneWidget2Callback : public vtkCommand
{
public:
 static VTKImplicitPlaneWidget2Callback *New()
 {
      return new VTKImplicitPlaneWidget2Callback;
 }
public:
 virtual void Execute(vtkObject *caller,
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值