VTK Learning Twenty-eight- vtkbool tunnel

Description

利用paraview 生成Box和tube管线,测试vtkbool bool运算。

Code

#include <vtkXMLPolyDataReader.h>
#include<vtkPolyDataMapper.h>
#include<vtkActor.h>
#include<vtkRenderer.h>
#include<vtkRenderWindow.h>
#include<vtkRenderWindowInteractor.h>
#include<vtkAutoInit.h>
#include "vtkPolyDataBooleanFilter.h"

VTK_MODULE_INIT(vtkRenderingOpenGL2);
// VTK was built with vtkRenderingOpenGL2
VTK_MODULE_INIT(vtkInteractionStyle)
int main (int argc, char *argv[]) {
	vtkSmartPointer<vtkXMLPolyDataReader> boxReader = vtkSmartPointer<vtkXMLPolyDataReader>::New();
	//vtkNew<vtkPolyDataReader>boxReader;
	boxReader->SetFileName("box.vtp");
	vtkSmartPointer<vtkXMLPolyDataReader> tunnelReader = vtkSmartPointer<vtkXMLPolyDataReader>::New();
	//vtkNew<vtkPolyDataReader>tunnelReader;
	tunnelReader->SetFileName("tunnel.vtp");
	vtkPolyDataBooleanFilter *bf = vtkPolyDataBooleanFilter::New();
	bf->SetInputConnection(0, boxReader->GetOutputPort());
	bf->SetInputConnection(1, tunnelReader->GetOutputPort());
	
	bf->SetOperModeToDifference();
	//bf->MergeRegsOn();//合并操作
	bf->Update();
	
	vtkSmartPointer<vtkPolyDataMapper> polyDataMapper =
		vtkSmartPointer<vtkPolyDataMapper>::New();
	polyDataMapper->SetInputData(bf->GetOutput(0));

	polyDataMapper->ScalarVisibilityOff();
	vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New();
	actor->SetMapper(polyDataMapper);

	vtkSmartPointer<vtkRenderer> renderer = vtkSmartPointer<vtkRenderer>::New();
	renderer->AddActor(actor);
	renderer->SetBackground(10, 0, 0);

	vtkSmartPointer<vtkRenderWindow> renderWin = vtkSmartPointer<vtkRenderWindow>::New();
	renderWin->AddRenderer(renderer);
	renderWin->SetSize(640, 480);
	renderWin->SetWindowName("PolyData Structure Learing");

	vtkSmartPointer<vtkRenderWindowInteractor>rwi =
		vtkSmartPointer<vtkRenderWindowInteractor>::New();
	rwi->SetRenderWindow(renderWin);
	rwi->Initialize();
	rwi->Start();
    return 0;
}

Result

bool操作前
在这里插入图片描述
bool操作之后
在这里插入图片描述
在这里插入图片描述

测试数据

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值