| 257 | } |
| 258 | |
| 259 | void vtkImageToPolyDataFilter::RunLengthImage(vtkUnsignedCharArray* pixels, int dims[3], |
| 260 | double origin[3], double spacing[3], vtkPolyData* output) |
| 261 | { |
| 262 | int i, j; |
| 263 | vtkIdType pts[4], id; |
| 264 | vtkPoints* newPts; |
| 265 | vtkCellArray* newPolys; |
| 266 | double x[3], minX, maxX, minY, maxY; |
| 267 | vtkUnsignedCharArray* polyColors; |
| 268 | unsigned char *colors = pixels->GetPointer(0), *color; |
| 269 | |
| 270 | // Setup data |
| 271 | newPts = vtkPoints::New(); |
| 272 | newPolys = vtkCellArray::New(); |
| 273 | newPolys->AllocateEstimate(dims[0] * dims[1] / 10, 4); |
| 274 | |
| 275 | polyColors = vtkUnsignedCharArray::New(); |
| 276 | polyColors->Allocate(3 * dims[0] * dims[1] / 10); // for rgb |
| 277 | polyColors->SetNumberOfComponents(3); |
| 278 | |
| 279 | // Loop over row-by-row generating quad polygons |
| 280 | x[2] = 0.0; |
| 281 | for (j = 0; j < dims[1]; j++) |
| 282 | { |
| 283 | if (j == 0) |
| 284 | { |
| 285 | minY = origin[1]; |
| 286 | maxY = origin[1] + 0.5 * spacing[1]; |
| 287 | } |
| 288 | else if (j == (dims[1] - 1)) |
| 289 | { |
| 290 | minY = origin[1] + j * spacing[1] - 0.5 * spacing[1]; |
| 291 | maxY = origin[1] + j * spacing[1]; |
| 292 | } |
| 293 | else |
| 294 | { |
| 295 | minY = origin[1] + j * spacing[1] - 0.5 * spacing[1]; |
| 296 | maxY = origin[1] + j * spacing[1] + 0.5 * spacing[1]; |
| 297 | } |
| 298 | |
| 299 | for (i = 0; i < dims[0];) |
| 300 | { |
| 301 | if (i == 0) |
| 302 | { |
| 303 | minX = origin[0]; |
| 304 | } |
| 305 | else |
| 306 | { |
| 307 | minX = origin[0] + i * spacing[0] - 0.5 * spacing[0]; |
| 308 | } |
| 309 | color = colors + 3 * (i + j * dims[0]); |
| 310 | while (i < dims[0]) |
| 311 | { |
| 312 | unsigned char* ptr = colors + 3 * (i + j * dims[0]); |
| 313 | if (!this->IsSameColor(color, ptr)) |
| 314 | { |
| 315 | break; |
| 316 | } |
no test coverage detected