Why the boolean operation is failed, saying there isn't an overlap

I want to subtract a cylinder from the cone to form a frustrum, it always shows “ERR| vtkDistancePolyDataFilter (0000019EC3064A90): No points/cells to operate on” but they’re indeed overlapped
Code below:

Create the upper cone (pointing upwards)

cone1 = vtk.vtkConeSource()
cone1.SetRadius(neck_diameter / 2)
cone1.SetHeight(upper_height)
cone1.SetResolution(resolution)
cone1.SetDirection(0, 1, 0) # Pointing upwards
cone1.SetCenter(0, upper_height / 2, 0) # Adjust position to be centered at height / 2
cone1.Update()

Create the middle cone (pointing downwards)

cone2 = vtk.vtkConeSource()
cone2.SetRadius(neck_diameter / 2)
cone2.SetHeight(mid_height)
cone2.SetResolution(resolution)
cone2.SetDirection(0, -1, 0) # Pointing downwards
cone2.SetCenter(0, -mid_height / 2, 0) # Adjust position to be centered at -upper_height / 2
cone2.Update()

Create the bottom cone (pointing downwards)

cone3 = vtk.vtkConeSource()
cone3.SetRadius(body_diameter / 2)
cone3.SetHeight(lower_height)
cone3.SetResolution(resolution)
cone3.SetDirection(0, -1, 0) # Pointing downwards
cone3.SetCenter(0, -neck_height - (lower_height / 2), 0) # Adjust position to be centered at -upper_height / 2
cone3.Update()

Create the top excluded cylinder

cylinder1 = vtk.vtkCylinderSource()
cylinder1.SetRadius(platform_diameter / 2)
cylinder1.SetHeight(upper_height - upper_neck_height)
cylinder1.SetResolution(resolution)
cylinder1.SetCenter(0, upper_neck_height + (upper_height - upper_neck_height) / 2, 0) # Adjust position to be centered
cylinder1.Update()

Create the middle excluded cylinder

cylinder2 = vtk.vtkCylinderSource()
cylinder2.SetRadius(body_diameter / 2)
cylinder2.SetHeight(mid_height - neck_height)
cylinder2.SetResolution(resolution)
cylinder2.SetCenter(0, -neck_height - (mid_height - neck_height) / 2, 0) # Adjust position to be centered
cylinder2.Update()

Create the bottom excluded cylinder

cylinder3 = vtk.vtkCylinderSource()
cylinder3.SetRadius(tip_diameter / 2)
cylinder3.SetHeight(lower_height - body_height)
cylinder3.SetResolution(resolution)
cylinder3.SetCenter(0, -neck_height - body_height - (lower_height - body_height) / 2, 0) # Adjust position to be centered
cylinder3.Update()

Subtract cylinder1 from cone1

boolean1 = vtkBooleanOperationPolyDataFilter()
boolean1.SetOperationToDifference()
boolean1.SetInputConnection(0, cone1.GetOutputPort())
boolean1.SetInputConnection(1, cylinder1.GetOutputPort())
boolean1.Update()

Subtract cylinder2 from cone2

boolean2 = vtkBooleanOperationPolyDataFilter()
boolean2.SetOperationToDifference()
boolean2.SetInputConnection(0, cone2.GetOutputPort())
boolean2.SetInputConnection(1, cylinder2.GetOutputPort())
boolean2.Update()

Subtract cylinder3 from cone3

boolean3 = vtkBooleanOperationPolyDataFilter()
boolean3.SetOperationToDifference()
boolean3.SetInputConnection(0, cone3.GetOutputPort())
boolean3.SetInputConnection(1, cylinder3.GetOutputPort())
boolean3.Update()

Append the results together

appendFilter = vtk.vtkAppendPolyData()
appendFilter.AddInputConnection(boolean1.GetOutputPort())
appendFilter.AddInputConnection(boolean2.GetOutputPort())
appendFilter.AddInputConnection(boolean3.GetOutputPort())

Might make it easier to read if you enclose your program in triple backticks (i.e. markdown for program text). Three of these: ` on the top and three on the bottom.

So that it looks like this:

# Create the upper cone (pointing upwards)
cone1 = vtk.vtkConeSource()
cone1.SetRadius(neck_diameter / 2)
cone1.SetHeight(upper_height)
cone1.SetResolution(resolution)
cone1.SetDirection(0, 1, 0) # Pointing upwards
cone1.SetCenter(0, upper_height / 2, 0) # Adjust position to be centered at height / 2
cone1.Update()

# Create the middle cone (pointing downwards)
cone2 = vtk.vtkConeSource()
cone2.SetRadius(neck_diameter / 2)
cone2.SetHeight(mid_height)
cone2.SetResolution(resolution)
cone2.SetDirection(0, -1, 0) # Pointing downwards
cone2.SetCenter(0, -mid_height / 2, 0) # Adjust position to be centered at -upper_height / 2
cone2.Update()

# Create the bottom cone (pointing downwards)
cone3 = vtk.vtkConeSource()
cone3.SetRadius(body_diameter / 2)
cone3.SetHeight(lower_height)
cone3.SetResolution(resolution)
cone3.SetDirection(0, -1, 0) # Pointing downwards
cone3.SetCenter(0, -neck_height - (lower_height / 2), 0) # Adjust position to be centered at -upper_height / 2
cone3.Update()

# Create the top excluded cylinder
cylinder1 = vtk.vtkCylinderSource()
cylinder1.SetRadius(platform_diameter / 2)
cylinder1.SetHeight(upper_height - upper_neck_height)
cylinder1.SetResolution(resolution)
cylinder1.SetCenter(0, upper_neck_height + (upper_height - upper_neck_height) / 2, 0) # Adjust position to be centered
cylinder1.Update()

# Create the middle excluded cylinder
cylinder2 = vtk.vtkCylinderSource()
cylinder2.SetRadius(body_diameter / 2)
cylinder2.SetHeight(mid_height - neck_height)
cylinder2.SetResolution(resolution)
cylinder2.SetCenter(0, -neck_height - (mid_height - neck_height) / 2, 0) # Adjust position to be centered
cylinder2.Update()

# Create the bottom excluded cylinder
cylinder3 = vtk.vtkCylinderSource()
cylinder3.SetRadius(tip_diameter / 2)
cylinder3.SetHeight(lower_height - body_height)
cylinder3.SetResolution(resolution)
cylinder3.SetCenter(0, -neck_height - body_height - (lower_height - body_height) / 2, 0) # Adjust position to be centered
cylinder3.Update()

# Subtract cylinder1 from cone1
boolean1 = vtkBooleanOperationPolyDataFilter()
boolean1.SetOperationToDifference()
boolean1.SetInputConnection(0, cone1.GetOutputPort())
boolean1.SetInputConnection(1, cylinder1.GetOutputPort())
boolean1.Update()

# Subtract cylinder2 from cone2
boolean2 = vtkBooleanOperationPolyDataFilter()
boolean2.SetOperationToDifference()
boolean2.SetInputConnection(0, cone2.GetOutputPort())
boolean2.SetInputConnection(1, cylinder2.GetOutputPort())
boolean2.Update()

# Subtract cylinder3 from cone3
boolean3 = vtkBooleanOperationPolyDataFilter()
boolean3.SetOperationToDifference()
boolean3.SetInputConnection(0, cone3.GetOutputPort())
boolean3.SetInputConnection(1, cylinder3.GetOutputPort())
boolean3.Update()

# Append the results together
appendFilter = vtk.vtkAppendPolyData()
appendFilter.AddInputConnection(boolean1.GetOutputPort())
appendFilter.AddInputConnection(boolean2.GetOutputPort())
appendFilter.AddInputConnection(boolean3.GetOutputPort())
1 Like