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操作之后