On Model Cutting, I want to get the cut part and the cut part when cutting the model

vtkClipPolyData can get two outputs, so at first, I used vtkClipPolyData to cut the model, but the model cut out by vtkClipPolyData was hollow, and the sum of the volumes of the two outputs had a big error with the original model.

So I used vtkClipClosedSurface to cut the model instead, but vtkClipClosedSurface only produced one output. In order to solve the problem of my idea is to use vtkBooleanOperationPolyDataFilter on the original model and the generated model for poor.

But I seem to be stuck in the vtkBooleanOperationPolyDataFilter: : update method.

My code is as follows:

vtkMRMLModelNode* sourceNode = vtkMRMLModelNode::SafeDownCast(mrmlScene->GetNodeByID(charNodeID));
	if (nullptr != sourceNode)
	{
		this->isClipped = true;
		d->appendButton->setEnabled(false);
		d->deleteButton->setEnabled(true);
		d->clipButton->setEnabled(!this->isClipped);

		
		this->appendPlane();
#if 1
		auto result1 = clipHelp(sourceNode);

		vtkSmartPointer<vtkBooleanOperationPolyDataFilter> boolFilter = vtkSmartPointer<vtkBooleanOperationPolyDataFilter>::New();
		boolFilter->SetOperation(vtkBooleanOperationPolyDataFilter::VTK_DIFFERENCE);

		boolFilter->SetInputData(0, sourceNode->GetPolyData());
		boolFilter->SetInputData(1, result1->GetPolyData());
		boolFilter->Update();	//It's stuck here
		auto result2PolyData = boolFilter->GetOutput();

		vtkSmartPointer<vtkMRMLModelNode> result2 = vtkSmartPointer<vtkMRMLModelNode>::New();
		QString resultName = tr("Result Part_");
		resultName.append(QString::number(this->timeOfClip));
		result2->SetName(resultName.toLatin1().data());
		result2->SetAndObservePolyData(result2PolyData);
		result2->SetScene(mrmlScene);

		vtkSmartPointer<vtkMRMLModelDisplayNode> resultDisplay = vtkSmartPointer<vtkMRMLModelDisplayNode>::New();
		vtkSmartPointer<vtkMRMLModelStorageNode> resultStorage = vtkSmartPointer<vtkMRMLModelStorageNode>::New();
		resultDisplay->SetScene(mrmlScene);
		resultStorage->SetScene(mrmlScene);
		resultDisplay->SetInputPolyDataConnection(result2->GetPolyDataConnection());
		resultStorage->SetFileName(resultName.toLatin1().data());
		mrmlScene->AddNode(resultDisplay);
		mrmlScene->AddNode(resultStorage);
		resultDisplay->SetColor(1.0, 0.0, 0.0);
		result2->SetAndObserveDisplayNodeID(resultDisplay->GetID());
		result2->SetAndObserveStorageNodeID(resultStorage->GetID());
		mrmlScene->AddNode(result2);

		this->deleteSurface();

		//设置在同一分组下
		auto shNode = mrmlScene->GetSubjectHierarchyNode();
		if (nullptr != shNode)
		{
			auto groupName = std::string(sourceNode->GetName()) + "_Clip";
			auto parent = shNode->GetItemByName(groupName);
			if (0 == parent)
				parent = mrmlScene->GetSubjectHierarchyNode()->CreateFolderItem(mrmlScene->GetSubjectHierarchyNode()->GetSceneItemID(), groupName);

			if (0 != parent && nullptr != result1)
				mrmlScene->GetSubjectHierarchyNode()->SetItemParent(mrmlScene->GetSubjectHierarchyNode()->GetItemByDataNode(result1), parent);

			if (0 != parent && nullptr != result2)
				mrmlScene->GetSubjectHierarchyNode()->SetItemParent(mrmlScene->GetSubjectHierarchyNode()->GetItemByDataNode(result2), parent);
		}

		auto sourceDisplayNode = sourceNode->GetModelDisplayNode();
		//隐藏被剪切的model
		if (nullptr != sourceDisplayNode)
			sourceDisplayNode->SetVisibility(false);

Can someone help me, or do I have a better way to get two closed cut solid models and cut solid models after cutting models?

vtkBooleanOperationPolyDataFilter does not work: it fails randomly for completely valid inputs, therefore I would not recommend using that.

Instead, you can use the much more robust Combine Models module in Sandbox extension.

Thank you. I’ll try this extension

Sorry to bother you, I didn’t find Combine Models in the extension module, where do I get it

The extension’s name is Sandbox. You will find Combine models module in the module finder after you installed the extension.

All right, thank you very much