The following are private helper functions----------------------------------
| 434 | // The following are private helper functions---------------------------------- |
| 435 | // |
| 436 | vtkUnsignedCharArray* vtkImageToPolyDataFilter::QuantizeImage( |
| 437 | vtkDataArray* inScalars, int numComp, int type, int dims[3], int extent[4]) |
| 438 | { |
| 439 | int numPixels, i, j, idx, id; |
| 440 | vtkUnsignedCharArray* pixels; |
| 441 | unsigned char *ptr, *ptr2, *outPixels; |
| 442 | unsigned char* inPixels; |
| 443 | |
| 444 | // doing a portion of the image |
| 445 | numPixels = (extent[1] - extent[0] + 1) * (extent[3] - extent[2] + 1); |
| 446 | pixels = vtkUnsignedCharArray::New(); |
| 447 | pixels->SetNumberOfValues(3 * numPixels); |
| 448 | outPixels = pixels->GetPointer(0); |
| 449 | |
| 450 | // Figure out how to quantize |
| 451 | // |
| 452 | if (this->ColorMode == VTK_COLOR_MODE_LINEAR_256) |
| 453 | { |
| 454 | // Check scalar type |
| 455 | if (type != VTK_UNSIGNED_CHAR || numComp != 3) |
| 456 | { |
| 457 | vtkErrorMacro(<< "Wrong input scalar type"); |
| 458 | return nullptr; |
| 459 | } |
| 460 | else |
| 461 | { |
| 462 | inPixels = static_cast<vtkUnsignedCharArray*>(inScalars)->GetPointer(0); |
| 463 | } |
| 464 | |
| 465 | // Generate a color table used to quantize the points |
| 466 | // |
| 467 | if (this->GetMTime() > this->TableMTime) |
| 468 | { |
| 469 | this->BuildTable(inPixels); |
| 470 | } |
| 471 | |
| 472 | for (id = 0, j = extent[2]; j <= extent[3]; j++) |
| 473 | { |
| 474 | for (i = extent[0]; i <= extent[1]; i++) |
| 475 | { |
| 476 | idx = i + j * dims[0]; |
| 477 | ptr = inPixels + 3 * idx; |
| 478 | ptr2 = outPixels + 3 * id; |
| 479 | const unsigned char* color = this->GetColor(ptr); |
| 480 | ptr2[0] = color[0]; |
| 481 | ptr2[1] = color[1]; |
| 482 | ptr2[2] = color[2]; |
| 483 | id++; |
| 484 | } |
| 485 | } |
| 486 | } // using build in table |
| 487 | |
| 488 | else // using provided lookup table |
| 489 | { |
| 490 | if (numComp != 1 || this->LookupTable == nullptr) |
| 491 | { |
| 492 | vtkErrorMacro(<< "LUT mode requires single component scalar and LUT"); |
| 493 | return nullptr; |
no test coverage detected