1 | for (int i = 0; i < lines->GetNumberOfCells(); i++) |
输出结果:1
2
3
4
5
6
7
8
9
10
11
12P1 : 131 111,177,121
P2 : 130 111,177,121
P1 : 130 112,178,120
P2 : 129 112,178,120
P1 : 129 112,178,119
P2 : 128 112,178,119
P1 : 128 112,177,118
P2 : 127 112,177,118
P1 : 127 112,176,117
P2 : 126 112,176,117
P1 : 126 111,175,116
...
发现每次输出P1跟P2坐标相同,好久没发现问题所在。追踪到源码,发现这么一段warning,细想一下,这样设计业很好理解。1
2
3
4
5
6
7
8
9
10
11// Description:
// Return a pointer to a double point x[3] for a specific id.
// WARNING: Just don't use this error-prone method, the returned pointer
// and its values are only valid as long as another method invocation is not
// performed. Prefer GetPoint() with the return value in argument.
double *GetPoint(vtkIdType id) { return this->Data->GetTuple(id); }
// Description:
// Copy point components into user provided array v[3] for specified
// id.
void GetPoint(vtkIdType id, double x[3]) { this->Data->GetTuple(id,x); }
更新程序使用1
2
3
4double p1[3];
double p2[3];
polydata->GetPoints()->GetPoint(pid1, p1);
polydata->GetPoints()->GetPoint(pid2, p2);
目标达成。