| 1232 | } |
| 1233 | |
| 1234 | void vtkImageToPolyDataFilter::SmoothEdges(vtkUnsignedCharArray* pointDescr, vtkPolyData* edges) |
| 1235 | { |
| 1236 | |
| 1237 | vtkPoints* points = edges->GetPoints(); |
| 1238 | vtkIdType numPts = points->GetNumberOfPoints(), ptId; |
| 1239 | int i, iterNum; |
| 1240 | int connId; |
| 1241 | double x[3], xconn[3], xave[3], factor; |
| 1242 | vtkIdType ncells; |
| 1243 | vtkIdType* cells; |
| 1244 | const vtkIdType* pts; |
| 1245 | vtkIdType npts; |
| 1246 | |
| 1247 | // For each smoothing operation, loop over points. Points that can be |
| 1248 | // smoothed are moved in the direction of the average of their neighbor |
| 1249 | // points. |
| 1250 | for (iterNum = 0; iterNum < this->NumberOfSmoothingIterations; iterNum++) |
| 1251 | { |
| 1252 | if ((iterNum % 2)) // alternate smoothing direction |
| 1253 | { |
| 1254 | factor = -0.331; |
| 1255 | } |
| 1256 | else |
| 1257 | { |
| 1258 | factor = 0.330; |
| 1259 | } |
| 1260 | |
| 1261 | for (ptId = 0; ptId < numPts; ptId++) |
| 1262 | { |
| 1263 | if (pointDescr->GetValue(ptId) == 0) // can smooth |
| 1264 | { |
| 1265 | points->GetPoint(ptId, x); |
| 1266 | edges->GetPointCells(ptId, ncells, cells); |
| 1267 | xave[0] = xave[1] = xave[2] = 0.0; |
| 1268 | for (i = 0; i < ncells; i++) |
| 1269 | { |
| 1270 | edges->GetCellPoints(cells[i], npts, pts); |
| 1271 | if (pts[0] != ptId) |
| 1272 | { |
| 1273 | connId = pts[0]; |
| 1274 | } |
| 1275 | else if (npts > 1) |
| 1276 | { |
| 1277 | connId = pts[1]; |
| 1278 | } |
| 1279 | else |
| 1280 | { |
| 1281 | vtkErrorMacro("Bad cell in smoothing operation"); |
| 1282 | connId = pts[0]; |
| 1283 | } |
| 1284 | points->GetPoint(connId, xconn); |
| 1285 | xave[0] += xconn[0]; |
| 1286 | xave[1] += xconn[1]; |
| 1287 | xave[2] += xconn[2]; |
| 1288 | } |
| 1289 | if (ncells > 0) |
| 1290 | { |
| 1291 | xave[0] /= ncells; |
no test coverage detected