# using vtkIntersectionPolyDataFilter

**URL:** https://discourse.vtk.org/t/using-vtkintersectionpolydatafilter/9960
**Category:** Support
**Created:** [November 25, 2022, 9:59pm UTC](https://discourse.vtk.org/t/using-vtkintersectionpolydatafilter/9960 "2022-11-25T21:59:07Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![AndreAhmed](https://discourse.vtk.org/user_avatar/discourse.vtk.org/andreahmed/32/6061_2.png) [@AndreAhmed](https://discourse.vtk.org/u/AndreAhmed)
#### Post date: [November 25, 2022, 9:59pm UTC](https://discourse.vtk.org/t/using-vtkintersectionpolydatafilter/9960/1 "2022-11-25T21:59:07Z")

</div>

hello,  
I’m having a polyline and I’m trying to convert it to polydata, and then use vtkIntersectionPolyDataFilter  
to compute intersection and cutting another mesh.

But I see that polydata doesn’t have GetOutPort.

```auto
vtkSmartPointer<vtkPoints> vertices = vtkPoints::New();
	vtkSmartPointer<vtkCellArray> faces = vtkCellArray::New();

	int nVer = pnt.size();// ver.size();
	vertices->SetNumberOfPoints(nVer);

	int nFaces = fac.size();

	vtkIdType* cells_array = new vtkIdType[nFaces * 4];

		for (int i = 0; i < nVer; i+=3)
		{
			
			vertices->SetPoint(i, pnt[i], pnt[i+1], pnt[i+2]);
		}

		for (int i = 0; i < nFaces; i+=3)
		{
			 
			cells_array[i * 4 + 0] = 3; // 3 is the number of points in this cell (face)
			cells_array[i * 4 + 1] = fac[i];
			cells_array[i * 4 + 2] = fac[i+1];
			cells_array[i * 4 + 3] = fac[i+2];
		}

	vtkSmartPointer<vtkPolyData> pPolyData = vtkSmartPointer<vtkPolyData>::New();

	// construct vtk id type array from raw cells array
	vtkSmartPointer<vtkIdTypeArray> facesArray = vtkSmartPointer<vtkIdTypeArray>::New();
	facesArray->SetArray(cells_array, nFaces * 4, 0, vtkAbstractArray::DeleteMethod::VTK_DATA_ARRAY_DELETE);

	// pass this id type array to the cell array object to initialize it with the manually created cells
	faces->SetCells(nFaces, facesArray);

	pPolyData = vtkSmartPointer<vtkPolyData>::New();
	pPolyData->SetPoints(vertices);
	pPolyData->SetPolys(faces);

	pPolyData->Squeeze();

	vtkNew<vtkIntersectionPolyDataFilter> intersectionPolyDataFilter;
	intersectionPolyDataFilter->SetInputConnection(
		0, pPolyData->GetOutPort()));
	intersectionPolyDataFilter->SetInputConnection(
		1, sphereSource2->GetOutputPort());
	intersectionPolyDataFilter->Update();

```

---

<div class="post-metadata">

### Author: ![AndreAhmed](https://discourse.vtk.org/user_avatar/discourse.vtk.org/andreahmed/32/6061_2.png) [@AndreAhmed](https://discourse.vtk.org/u/AndreAhmed)
#### Post date: [November 25, 2022, 10:08pm UTC](https://discourse.vtk.org/t/using-vtkintersectionpolydatafilter/9960/2 "2022-11-25T22:08:27Z")

</div>

I also have another question, how can I use vtkImprintFilter to write to obj file.

---

<div class="post-metadata">

### Author: ![zhang-qiang-github](https://discourse.vtk.org/user_avatar/discourse.vtk.org/zhang-qiang-github/32/2519_2.png) [@zhang-qiang-github](https://discourse.vtk.org/u/zhang-qiang-github)
#### Post date: [November 26, 2022, 2:41am UTC](https://discourse.vtk.org/t/using-vtkintersectionpolydatafilter/9960/3 "2022-11-26T02:41:34Z")

</div>

> [@AndreAhmed](#):
>
> ```auto
> intersectionPolyDataFilter->SetInputConnection(
> 0, pPolyData->GetOutPort()));
> 
> ```

You can try:

```auto
intersectionPolyDataFilter->SetInputData(0, pPolyData);

```
