# GetCellEdgeNeighbors gives all 0s

**URL:** https://discourse.vtk.org/t/getcelledgeneighbors-gives-all-0s/9346
**Category:** Support
**Created:** [September 14, 2022, 12:53pm UTC](https://discourse.vtk.org/t/getcelledgeneighbors-gives-all-0s/9346 "2022-09-14T12:53:52Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![AlexLuya](https://discourse.vtk.org/user_avatar/discourse.vtk.org/alexluya/32/4036_2.png) [@AlexLuya](https://discourse.vtk.org/u/AlexLuya)
#### Post date: [September 14, 2022, 12:53pm UTC](https://discourse.vtk.org/t/getcelledgeneighbors-gives-all-0s/9346/1 "2022-09-14T12:53:52Z")

</div>

Hello,I have a cude ,and want to get the neighbors of each cell iterating edge like this:

GetCellEdgeNeighbors( cellId , edgeStart , edgeEnd , xxx)

In expectation,each edge should have one neighbor,but all got 0,and if set cellId to -1,I got one neighbor for each edge, runnable code like this:

```auto
#include <iostream>
#include <string>
#include <vector>
#include <vtkOBJReader.h>

struct Edge {
		long long from;
		long long to;
};

//if face is [0 1 2 3],it's edges will be {[0,1],[1,2],[2,3],[3,0]}
//caution last point will connect back to first point as last edge
std::vector<Edge> faceToEdges(std::vector<long long> face) {
	std::vector<Edge> edges;

	int size = face.size();
	for (int i = 1; i <= size; i++) {
		if (i == size) { //link last point to first point
			edges.emplace_back(Edge { face.at(i - 1), face.at(0) });
		} else { //link previous point to current point
			edges.emplace_back(Edge { face.at(i - 1), face.at(i) });
		}
	}

	return edges;
}

//extract point(indexes) of each cell,then push these cells into a vector,similar to EBO
std::vector<std::vector<long long>> faceTable(vtkPolyData *pd) {
	std::vector<std::vector<long long>> cs;

	vtkCellArray *polys = pd->GetPolys();

	vtkIdType npts;
	const vtkIdType *indx;

	for (polys->InitTraversal(); polys->GetNextCell(npts, indx);) {
		std::vector<long long> cell;
		for (int i = 0; i < npts; i++) {
			cell.emplace_back(indx[i]);
		}
		cs.emplace_back(cell);
	}

	return cs;
}

int main(int, char*[]) {

	auto fileName = "/home/alex/workspace/Geometry-Python/files/Cube-With-Reversed-Normal.obj";
//	auto fileName = "/path/to/cube.obj";

	vtkNew<vtkOBJReader> reader;
	reader->SetFileName(fileName);
	reader->Update();
	auto pd = reader->GetOutput();

	std::cout << "Point number: " << pd->GetNumberOfPoints() << std::endl<< std::endl;

	pd->BuildLinks();

	auto cells = faceTable(pd);

	for (long long i = 0; i < cells.size(); i++) {
		auto edges = faceToEdges(cells.at(i));
		for (auto &edge : edges) {
			vtkNew<vtkIdList> neighbors;
			pd->GetCellEdgeNeighbors(i, edge.from, edge.to, neighbors);
			std::cout << "Cell " << i << " Edge " << edge.from << "-" << edge.to << " neighbors: " << neighbors->GetNumberOfIds() << std::endl;
		}
	}

	return 1;
}

```

And the output like this:

```auto
Point number: 24

Cell 0 Edge 0-1 neighbors: 0
Cell 0 Edge 1-2 neighbors: 0
Cell 0 Edge 2-3 neighbors: 0
Cell 0 Edge 3-0 neighbors: 0
Cell 1 Edge 4-5 neighbors: 0
Cell 1 Edge 5-6 neighbors: 0
....

```

As you can,all 0s, the questions are:

1,Why does “cellId= -1” give wanted result,but all real cellId gives 0?

2,Each cude has 8 points,why does “pd-\>GetNumberOfPoints()” give 24?

---

<div class="post-metadata">

### Author: ![will.schroeder](https://discourse.vtk.org/user_avatar/discourse.vtk.org/will.schroeder/32/233_2.png) [@will.schroeder](https://discourse.vtk.org/u/will.schroeder)
#### Post date: [September 14, 2022, 1:32pm UTC](https://discourse.vtk.org/t/getcelledgeneighbors-gives-all-0s/9346/2 "2022-09-14T13:32:25Z")

</div>

My suspicion is that you have coincident points, so that the cells are not topologically joined. Use something like vtkCleanPolyData or vtkStaticCleanPolyData to merge the coincident points.

---

<div class="post-metadata">

### Author: ![AlexLuya](https://discourse.vtk.org/user_avatar/discourse.vtk.org/alexluya/32/4036_2.png) [@AlexLuya](https://discourse.vtk.org/u/AlexLuya)
#### Post date: [September 14, 2022, 2:33pm UTC](https://discourse.vtk.org/t/getcelledgeneighbors-gives-all-0s/9346/3 "2022-09-14T14:33:19Z")

</div>

You are right,thanks!!
