What’s the problem? Somebody help me

  • I made a mistake when using vtkBooleanOperationPolyDataFilter。
    ERROR: In E:\VTKLib\VTK-8.2.0\Common\DataModel\vtkPointLocator.cxx, line 866
    vtkPointLocator (0x15aa4068): No points to subdivide

Generic Warning: In E:\VTKLib\VTK-8.2.0\Filters\General\vtkIntersectionPolyDataFilter.cxx, line 2516
No Intersection between objects

ERROR: In E:\VTKLib\VTK-8.2.0\Filters\General\vtkDistancePolyDataFilter.cxx, line 78
vtkDistancePolyDataFilter (0x159f4600): No points/cells to operate on

ERROR: In E:\VTKLib\VTK-8.2.0\Filters\General\vtkDistancePolyDataFilter.cxx, line 78
vtkDistancePolyDataFilter (0x159f4600): No points/cells to operate on

This is my code。
auto cylinder = vtkSmartPointer::New();
cylinder->SetCenter(0,0,0);
cylinder->SetHeight(5);
cylinder->SetRadius(3);
cylinder->Update();

auto cylinder1 = vtkSmartPointer<vtkCylinderSource>::New();
cylinder1->SetCenter(0,0,0);
cylinder1->SetHeight(10);
cylinder1->SetRadius(2);
cylinder1->Update();

auto booleanOperation = vtkSmartPointer<vtkBooleanOperationPolyDataFilter>::New();
booleanOperation->SetOperationToUnion();
booleanOperation->SetInputData(0,cylinder->GetOutput());
booleanOperation->SetInputData(1,cylinder1->GetOutput());
booleanOperation->Update();

auto appendMapper = vtkSmartPointer::New();
appendMapper->SetInputData(booleanOperation->GetOutput());

auto actor = vtkSmartPointer<vtkActor>::New();
actor->SetMapper(appendMapper);
actor->GetProperty()->SetOpacity(0.4);

auto renderer = vtkSmartPointer<vtkRenderer>::New();
renderer->AddActor(actor);

auto window = vtkSmartPointer<vtkGenericOpenGLRenderWindow>::New();
window->AddRenderer(renderer);
  • I changed the code. Get rid of mistakes. * But there’s no way to change the color

auto cylinder = vtkSmartPointer::New();
cylinder->SetCenter(0,0,0);
cylinder->SetHeight(5);
cylinder->SetRadius(3);
cylinder->SetResolution(100);
cylinder->Update();

auto cylinder1 = vtkSmartPointer<vtkCylinderSource>::New();
cylinder1->SetCenter(0,0,0);
cylinder1->SetHeight(10);
cylinder1->SetRadius(2);
cylinder1->SetResolution(100);
cylinder1->Update();

auto triang1 = vtkSmartPointer<vtkTriangleFilter>::New();
triang1->SetInputData(cylinder->GetOutput());
triang1->Update();
auto triang2 = vtkSmartPointer<vtkTriangleFilter>::New();
triang2->SetInputData(cylinder1->GetOutput());
triang2->Update();


auto booleanOperation = vtkSmartPointer<vtkBooleanOperationPolyDataFilter>::New();
booleanOperation->SetOperationToUnion();
booleanOperation->SetInputData(0,triang1->GetOutput());
booleanOperation->SetInputData(1,triang2->GetOutput());
booleanOperation->Update();


auto appendMapper = vtkSmartPointer<vtkPolyDataMapper>::New();
appendMapper->SetInputData(booleanOperation->GetOutput());

auto actor = vtkSmartPointer<vtkActor>::New();
actor->SetMapper(appendMapper);
actor->GetProperty()->SetOpacity(0.4);

auto renderer = vtkSmartPointer<vtkRenderer>::New();
renderer->AddActor(actor);
renderer->SetBackground(255,255,255);

auto window = vtkSmartPointer<vtkGenericOpenGLRenderWindow>::New();
window->AddRenderer(renderer);

I think you need to add
appendMapper->ScalarVisibilityOff();

Thanks

How to set different colors for cylinder1 and clinder2,After the merger。

you can use
polydata->GetPointData()->SetActiveScalars('PointSource');

i tested it in python and it does the job:

from vtkplotter import show, booleanOperation, Cylinder

s1 = Cylinder(r=1.0, height=1, c="r", alpha=0.5).triangle()
s2 = Cylinder(r=0.5, height=2, c="g", alpha=0.5).triangle()

bol = booleanOperation(s1, "+", s2)
bol.computeNormals().scalars('PointSource')

#bol.polydata().GetPointData().SetActiveScalars('PointSource')

show([(s1,s2), bol], N=2, bg='white')

  • Can I only set different colors through scalar data?I want to use actor.

yes - I would try to set a vtkLookupTable.

Ok, thank you very much