| 365 | } |
| 366 | |
| 367 | void vtkApplyColors::ProcessColorArray(vtkUnsignedCharArray* colorArr, vtkScalarsToColors* lut, |
| 368 | vtkAbstractArray* arr, unsigned char color[4], bool scaleToArray) |
| 369 | { |
| 370 | if (lut && arr) |
| 371 | { |
| 372 | // If scaling is on, use data min/max. |
| 373 | // Otherwise, use the lookup table range. |
| 374 | const double* rng = lut->GetRange(); |
| 375 | double minVal = rng[0]; |
| 376 | double maxVal = rng[1]; |
| 377 | if (scaleToArray) |
| 378 | { |
| 379 | minVal = VTK_DOUBLE_MAX; |
| 380 | maxVal = VTK_DOUBLE_MIN; |
| 381 | for (vtkIdType i = 0; i < colorArr->GetNumberOfTuples(); ++i) |
| 382 | { |
| 383 | double val = arr->GetVariantValue(i).ToDouble(); |
| 384 | maxVal = std::max(val, maxVal); |
| 385 | minVal = std::min(val, minVal); |
| 386 | } |
| 387 | } |
| 388 | |
| 389 | // Map the data values through the lookup table. |
| 390 | double scale = 1.0; |
| 391 | if (minVal != maxVal) |
| 392 | { |
| 393 | scale = (rng[1] - rng[0]) / (maxVal - minVal); |
| 394 | } |
| 395 | unsigned char myColor[4] = { 0, 0, 0, 0 }; |
| 396 | for (vtkIdType i = 0; i < colorArr->GetNumberOfTuples(); ++i) |
| 397 | { |
| 398 | double val = arr->GetVariantValue(i).ToDouble(); |
| 399 | const unsigned char* mappedColor = lut->MapValue(rng[0] + scale * (val - minVal)); |
| 400 | myColor[0] = mappedColor[0]; |
| 401 | myColor[1] = mappedColor[1]; |
| 402 | myColor[2] = mappedColor[2]; |
| 403 | // Combine the opacity of the lookup table with the |
| 404 | // default color opacity. |
| 405 | myColor[3] = static_cast<unsigned char>((color[3] / 255.0) * mappedColor[3]); |
| 406 | colorArr->SetTypedTuple(i, myColor); |
| 407 | } |
| 408 | } |
| 409 | else |
| 410 | { |
| 411 | // If no lookup table, use default color. |
| 412 | for (vtkIdType i = 0; i < colorArr->GetNumberOfTuples(); ++i) |
| 413 | { |
| 414 | colorArr->SetTypedTuple(i, color); |
| 415 | } |
| 416 | } |
| 417 | } |
| 418 | |
| 419 | vtkMTimeType vtkApplyColors::GetMTime() |
| 420 | { |
no test coverage detected