Skip to content

Commit

Permalink
BUG: Attempt to make Scissors effect more robust
Browse files Browse the repository at this point in the history
Scissors effect sometimes crashes on macOS. These code reorganizations might make it a bit more robust.

see #6705
  • Loading branch information
lassoan committed Nov 26, 2022
1 parent f9dcc53 commit a5af820
Showing 1 changed file with 12 additions and 11 deletions.
Expand Up @@ -491,14 +491,11 @@ bool qSlicerSegmentEditorScissorsEffectPrivate::updateBrushModel(qMRMLWidget* vi
return false;
}

vtkNew<vtkPoints> closedSurfacePoints; // p0Top, p0Bottom, p1Top, p1Bottom, ...
vtkNew<vtkCellArray> closedSurfaceStrips;
vtkNew<vtkCellArray> closedSurfacePolys;

vtkPoints* pointsXY = pipeline->PolyData->GetPoints();
int numberOfPoints = pointsXY ? pointsXY->GetNumberOfPoints() : 0;
if (numberOfPoints <= 1)
if (numberOfPoints < 3)
{
// at least a triangle is needed
return false;
}

Expand All @@ -525,6 +522,8 @@ bool qSlicerSegmentEditorScissorsEffectPrivate::updateBrushModel(qMRMLWidget* vi
// TODO: show a meaningful error message to the user if attempted
vtkMRMLTransformNode::GetMatrixTransformBetweenNodes(segmentationNode->GetParentTransformNode(), nullptr, segmentationToWorldMatrix.GetPointer());

vtkNew<vtkPoints> closedSurfacePoints; // p0Top, p0Bottom, p1Top, p1Bottom, ...

// Used for excluding one side of the slice plane from being modified when
// filling or erasing outside in slice cut mode.
vtkSmartPointer<vtkPolyData> additionalBrushRegion;
Expand Down Expand Up @@ -793,13 +792,9 @@ bool qSlicerSegmentEditorScissorsEffectPrivate::updateBrushModel(qMRMLWidget* vi
return false;
}

// Construct polydata
vtkNew<vtkPolyData> closedSurfacePolyData;
closedSurfacePolyData->SetPoints(closedSurfacePoints.GetPointer());
closedSurfacePolyData->SetStrips(closedSurfaceStrips.GetPointer());
closedSurfacePolyData->SetPolys(closedSurfacePolys.GetPointer());

// Skirt
vtkNew<vtkCellArray> closedSurfacePolys;
vtkNew<vtkCellArray> closedSurfaceStrips;
closedSurfaceStrips->InsertNextCell(numberOfPoints * 2 + 2);
for (int i = 0; i < numberOfPoints * 2; i++)
{
Expand All @@ -820,6 +815,12 @@ bool qSlicerSegmentEditorScissorsEffectPrivate::updateBrushModel(qMRMLWidget* vi
closedSurfacePolys->InsertCellPoint(i * 2 + 1);
}

// Construct polydata
vtkNew<vtkPolyData> closedSurfacePolyData;
closedSurfacePolyData->SetPoints(closedSurfacePoints.GetPointer());
closedSurfacePolyData->SetStrips(closedSurfaceStrips.GetPointer());
closedSurfacePolyData->SetPolys(closedSurfacePolys.GetPointer());

if (additionalBrushRegion)
{
vtkNew<vtkAppendPolyData> append;
Expand Down

0 comments on commit a5af820

Please sign in to comment.