I’ve been trying to clip a multi-actors mesh with clipPolyData, the expected outcome looks like as following in ParaView.
Anyway, I follow the VTK example named “CapClip” to create the clipping function , it seems that nothing appears in the screen, looks like as following.
My code:
vtkSmartPointer append = vtkSmartPointer::New();
QList<vtkSmartPointer> actorList = partActors.values();
momentCutPlane->SetNormal(dsbMomentOrientationX->value(), dsbMomentOrientationY->value(), dsbMomentOrientationZ->value());
momentCutPlane->SetOrigin(getJointVTKPolyDataOrigin());//vtkPlane
for(int i(0); i < actorList.count(); i++)
{
vtkSmartPointer clipPolyData = vtkSmartPointer::New();
// clipPolyData->SetInputData(actorList.at(i)->GetMapper()->GetInput());
clipPolyData->SetInputData(actorList.at(i)->GetMapper()->GetInputAsDataSet());
// clipPolyData->SetInputConnection(actorList.at(i)->GetMapper()->GetOutputPort());
clipPolyData->SetClipFunction(momentCutPlane);
clipPolyData->GenerateClipScalarsOn();
clipPolyData->GenerateClippedOutputOn();
clipPolyData->InsideOutOn();
clipPolyData->Update();
append->AddInputData(clipPolyData->GetOutput());
if(actorList.at(i)->GetVisibility())
actorList.at(i)->VisibilityOff();
}
append->Update();
vtkSmartPointer</*vtkPolyDataMapper*/vtkDataSetMapper> clipMapper = vtkSmartPointer<vtkDataSetMapper>::New();
clipMapper->SetInputConnection(append->GetOutputPort());
clipMapper->ScalarVisibilityOn();
clipMapper->SetColorModeToDefault();
clipMapper->Update();
if(!clipActor)
{
clipActor = vtkSmartPointer<vtkActor>::New();
}
clipActor->SetMapper(clipMapper);
clipActor->GetProperty()->SetInterpolationToFlat();
clipActor->GetProperty()->EdgeVisibilityOn();
vtkSmartPointer<vtkFeatureEdges> boundaryEdges = vtkSmartPointer<vtkFeatureEdges>::New();
boundaryEdges->SetInputData(append->GetOutput());
boundaryEdges->BoundaryEdgesOn();
boundaryEdges->FeatureEdgesOff();
boundaryEdges->NonManifoldEdgesOff();
boundaryEdges->ManifoldEdgesOff();
vtkSmartPointer<vtkStripper> boundaryStrips = vtkSmartPointer<vtkStripper>::New();
boundaryStrips->SetInputConnection(boundaryEdges->GetOutputPort());
boundaryStrips->Update();
vtkSmartPointer<vtkPolyData> boundaryPoly = vtkSmartPointer<vtkPolyData>::New();
boundaryPoly->SetPoints(boundaryStrips->GetOutput()->GetPoints());
boundaryPoly->SetPolys(boundaryStrips->GetOutput()->GetLines());
vtkSmartPointer<vtkPolyDataMapper> boundaryMapper = vtkSmartPointer<vtkPolyDataMapper>::New();
boundaryMapper->SetInputData(boundaryPoly);
boundaryMapper->ScalarVisibilityOn();
boundaryMapper->SetColorModeToDefault();
if(!boundaryActor)
{
boundaryActor = vtkSmartPointer<vtkActor>::New();
}
boundaryActor->SetMapper(boundaryMapper);
if(momentPostWidget->GetRenderWindow()->GetRenderers()->GetFirstRenderer()->GetActors()->IsItemPresent(clipActor) == 0)
momentPostWidget->GetRenderWindow()->GetRenderers()->GetFirstRenderer()->AddActor(clipActor);
else
clipActor->VisibilityOn();
if(momentPostWidget->GetRenderWindow()->GetRenderers()->GetFirstRenderer()->GetActors()->IsItemPresent(boundaryActor) == 0)
momentPostWidget->GetRenderWindow()->GetRenderers()->GetFirstRenderer()->AddActor(boundaryActor);
else
boundaryActor->VisibilityOn();
momentPostWidget->GetRenderWindow()->Render();
Any suggestion or comment is welcome!