Clip voronoi2D mesh interiors ?

I have the following mesh that I generated from Spline.
I would like to clip the mesh at the voronoi cells

I used VTKTrimmExtrusion and I get the following output

but it doesn’t include the curved surface…

here is how I do it:


	vtkNew<vtkTriangleFilter> tri1;
	tri1->SetInputData(vornoi_2d->GetOutput());
	tri1->Update();
	

	vtkNew<vtkTriangleFilter> tri2;
	tri2->SetInputData(polydata);
	tri2->Update();

	vtkNew<vtkLinearExtrusionFilter> extrude;
	extrude->SetInputData(tri2->GetOutput());
	extrude->SetExtrusionTypeToNormalExtrusion();
	extrude->SetVector(0, 0, 1);
	extrude->SetScaleFactor(320);
	extrude->Update();


	// Get initial alignment using oriented bounding boxes
	AlignBoundingBoxes(extrude->GetOutput(), vornoi_2d->GetOutput());
	vtkNew<vtkTransform> Transform_voronoi, Transform_Curve;
	Transform_voronoi->Scale(1.7,1.7, 1.7);

	

	vtkNew<vtkTransformFilter> TransformFilter_voronoi, TransformFilter_curve;
	TransformFilter_voronoi->SetTransform(Transform_voronoi);
	TransformFilter_voronoi->SetInputConnection(vornoi_2d->GetOutputPort());
	TransformFilter_voronoi->Update();


	Transform_Curve->Translate(1400, 0, -50);

	TransformFilter_curve->SetTransform(Transform_Curve);
	TransformFilter_curve->SetInputConnection(extrude->GetOutputPort());
	TransformFilter_curve->Update();


	plyWriter->SetFileName("curve1.obj");
	plyWriter->SetInputData(TransformFilter_voronoi->GetOutput());
	plyWriter->Write();

	plyWriter->SetFileName("curve2.obj");
	plyWriter->SetInputData(TransformFilter_curve->GetOutput());
	plyWriter->Write();



	auto bf = vtkSmartPointer<vtkPolyDataBooleanFilter>::New();
	bf->SetInputConnection(0, TransformFilter_voronoi->GetOutputPort());
	bf->SetInputConnection(1, TransformFilter_curve->GetOutputPort());
	bf->SetOperModeToIntersection();
	bf->Update();


	plyWriter->SetFileName("intersection_result.obj");
	plyWriter->SetInputData(bf->GetOutput());
	plyWriter->Write();

	AlignBoundingBoxes(vornoi_2d->GetOutput(), bf->GetOutput());


	vtkNew< vtkTrimmedExtrusionFilter> extrude_trimmed, extrude_trimmed2;
	extrude_trimmed->SetInputData(vornoi_2d->GetOutput());
	extrude_trimmed->SetTrimSurfaceConnection(bf->GetOutputPort());
	extrude_trimmed->SetExtrusionDirection(0, 0, 1);
	extrude_trimmed->SetCapping(false);
	extrude_trimmed->Update();
	 
	  
	plyWriter->SetFileName("final_.obj");
	plyWriter->SetInputData(extrude_trimmed->GetOutput());
	plyWriter->Write();

@will.schroeder @lassoan

Boolean mesh operation filters built into VTK often fail for valid input. If you want to use Boolean operations on meshes then I would recommend vtkbool library.

Or you can clip polydata robustly using vtkClipPolyData or vtkThreshold.

@lassoan
I’m already using vtkbool library. But I just want to get the curved mesh + voronoi cells<-- clipped.

You can use vtkClipPolyData or vtkThreshold for clipping. Check out the VTK examples website or Github for examples.

@lassoan
Tried the example of VTKThreshold in github, the intersection always fail… however the two shapes(voronoi and the curve grid mesh ) are interesecting.

So I’m gonna try vtkClipPolyData, but confused about which one to choose as clip function ? I have 2D Voronoi mesh, and a 2D curved grid. and I want to get the cells of the voronoi mesh to be clipped with the curvgrid.

@lassoan
Hello, hope you’re doing fine.
I tried now VTKClipPolyData, but the results are ok, but I want to preserve the curve grid mesh while clipping the cells of the voronoi mesh.

for example here is the original curve grid mesh, and the top cells are voronoi

however with the current polydata cut, it removes the curve grid, and just keeps the voronoi cells clipped only


vtkNew<vtkTriangleFilter> tri1;
	tri1->SetInputData(vornoi_2d->GetOutput());
	tri1->Update();


	vtkNew<vtkTriangleFilter> tri2;
	tri2->SetInputData(polydata); // curve grid
	tri2->Update();

	vtkNew<vtkLinearExtrusionFilter> extrude;
	extrude->SetInputData(tri2->GetOutput());
	extrude->SetExtrusionTypeToNormalExtrusion();
	extrude->SetVector(0, 0, 1);
	extrude->SetScaleFactor(320);
	extrude->Update(); 

	vtkNew<vtkLinearExtrusionFilter> extrude_voronoi;
	extrude_voronoi->SetInputData(tri1->GetOutput());
	extrude_voronoi->SetExtrusionTypeToNormalExtrusion();
	extrude_voronoi->SetVector(0, 0, 1);
	extrude_voronoi->SetScaleFactor(320);
	extrude_voronoi->Update();

	// Get initial alignment using oriented bounding boxes
	AlignBoundingBoxes(extrude_voronoi->GetOutput(), extrude->GetOutput());
	 


	plyWriter->SetFileName("curve1.obj");
	plyWriter->SetInputData(extrude_voronoi->GetOutput());
	plyWriter->Write();

	plyWriter->SetFileName("curve2.obj");
	plyWriter->SetInputData(extrude->GetOutput());
	plyWriter->Write();
	vtkNew<vtkImplicitPolyDataDistance> implicit_distance_2;
	implicit_distance_2->SetInput(extrude->GetOutput());

	vtkSmartPointer<vtkClipPolyData> clipper =
		vtkSmartPointer<vtkClipPolyData>::New();
	clipper->SetInputData(extrude_voronoi->GetOutput());
	clipper->SetClipFunction(implicit_distance_2);
	clipper->GenerateClippedOutputOn();
	clipper->Update();