Context: I want to have the union of two walls, the walls may have some offset in both the x and y directions. But the result of my testing is terrible.
The result of testing:
Codes:
int main(int, char* []) {
float thickness = 0.5;
vtkSmartPointer<vtkPoints> points = vtkSmartPointer<vtkPoints>::New();
points->InsertNextPoint(0, 0, 0);
points->InsertNextPoint(2, 0, 0);
points->InsertNextPoint(2, 2, 0);
points->InsertNextPoint(0, 2, 0);
points->InsertNextPoint(0 + 1, 1, thickness);
points->InsertNextPoint(2 + 1, 1, thickness);
points->InsertNextPoint(2 +1, 2 +1, thickness);
points->InsertNextPoint(0 +1, 2 +1, thickness);
vtkSmartPointer<vtkCellArray> cellArray1 = vtkSmartPointer<vtkCellArray>::New();
cellArray1->InsertNextCell(4);
cellArray1->InsertCellPoint(0);
cellArray1->InsertCellPoint(1);
cellArray1->InsertCellPoint(2);
cellArray1->InsertCellPoint(3);
vtkSmartPointer<vtkCellArray> cellArray2 = vtkSmartPointer<vtkCellArray>::New();
cellArray2->InsertNextCell(4);
cellArray2->InsertCellPoint(4);
cellArray2->InsertCellPoint(5);
cellArray2->InsertCellPoint(6);
cellArray2->InsertCellPoint(7);
vtkSmartPointer<vtkPolyData> polyData1 = vtkSmartPointer<vtkPolyData>::New();
polyData1->SetPoints(points);
polyData1->SetPolys(cellArray1);
vtkSmartPointer<vtkPolyData> polyData2 = vtkSmartPointer<vtkPolyData>::New();
polyData2->SetPoints(points);
polyData2->SetPolys(cellArray2);
vtkSmartPointer<vtkLinearExtrusionFilter> extrudeA = vtkSmartPointer<vtkLinearExtrusionFilter>::New();
extrudeA->SetInputData(polyData1);
extrudeA->SetExtrusionTypeToNormalExtrusion();
extrudeA->SetVector(0, 0, 1);
extrudeA->SetScaleFactor(thickness);
extrudeA->Update();
vtkSmartPointer<vtkLinearExtrusionFilter> extrudeB = vtkSmartPointer<vtkLinearExtrusionFilter>::New();
extrudeB->SetInputData(polyData2);
extrudeB->SetExtrusionTypeToNormalExtrusion();
extrudeB->SetVector(0, 0, -1);
extrudeB->SetScaleFactor(thickness);
extrudeB->Update();
vtkNew<vtkTriangleFilter> filter1;
filter1->SetInputData(extrudeA->GetOutput());
filter1->Update();
vtkNew<vtkTriangleFilter> filter2;
filter2->SetInputData(extrudeB->GetOutput());
filter2->Update();
vtkNew<vtkBooleanOperationPolyDataFilter> filter_merge;
filter_merge->SetInputData(0, filter1->GetOutput());
filter_merge->SetInputData(1, filter2->GetOutput());
//filter_merge->SetOperationToDifference();//显示差集
filter_merge->SetOperationToUnion();//显示并集
//filter_merge->SetOperationToIntersection();//显示交集
filter_merge->Update();
vtkSmartPointer<vtkPolyDataMapper> mapper = vtkSmartPointer<vtkPolyDataMapper>::New();
mapper->SetInputConnection(filter_merge->GetOutputPort());
vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New();
actor->SetMapper(mapper);
vtkSmartPointer<vtkRenderer> renderer = vtkSmartPointer<vtkRenderer>::New();
renderer->AddActor(actor);
vtkSmartPointer<vtkRenderWindow> renderWindow = vtkSmartPointer<vtkRenderWindow>::New();
renderWindow->AddRenderer(renderer);
vtkSmartPointer<vtkRenderWindowInteractor> interactor = vtkSmartPointer<vtkRenderWindowInteractor>::New();
interactor->SetRenderWindow(renderWindow);
interactor->Initialize();
interactor->Start();
return EXIT_SUCCESS;
}