| 693 | } |
| 694 | |
| 695 | void vtkWebGLPolyData::GetColorsFromPointData( |
| 696 | unsigned char* color, vtkPointData* pointdata, vtkPolyData* polydata, vtkActor* actor) |
| 697 | { |
| 698 | vtkDataSetAttributes* attr = (vtkDataSetAttributes*)pointdata; |
| 699 | |
| 700 | int colorSize = attr->GetNormals()->GetDataSize() * 4 / 3; |
| 701 | |
| 702 | vtkDataArray* array; |
| 703 | if (actor->GetMapper()->GetArrayAccessMode() == VTK_GET_ARRAY_BY_ID) |
| 704 | array = pointdata->GetArray(actor->GetMapper()->GetArrayId()); |
| 705 | else |
| 706 | array = pointdata->GetArray(actor->GetMapper()->GetArrayName()); |
| 707 | |
| 708 | if (array && actor->GetMapper()->GetScalarVisibility() && |
| 709 | actor->GetMapper()->GetArrayName() != nullptr && actor->GetMapper()->GetArrayName()[0] != '\0') |
| 710 | { |
| 711 | vtkScalarsToColors* table = actor->GetMapper()->GetLookupTable(); |
| 712 | int colorComponent = table->GetVectorComponent(), |
| 713 | numberOfComponents = array->GetNumberOfComponents(); |
| 714 | int mode = table->GetVectorMode(); |
| 715 | double mag = 0, rgb[3]; |
| 716 | double alpha = 1.0; |
| 717 | |
| 718 | if (numberOfComponents == 1 && mode == vtkScalarsToColors::MAGNITUDE) |
| 719 | { |
| 720 | mode = vtkScalarsToColors::COMPONENT; |
| 721 | colorComponent = 0; |
| 722 | } |
| 723 | for (int i = 0; i < colorSize / 4; i++) |
| 724 | { |
| 725 | switch (mode) |
| 726 | { |
| 727 | case vtkScalarsToColors::MAGNITUDE: |
| 728 | mag = 0; |
| 729 | for (int w = 0; w < numberOfComponents; w++) |
| 730 | mag += array->GetComponent(i, w) * array->GetComponent(i, w); |
| 731 | mag = sqrt(mag); |
| 732 | table->GetColor(mag, &rgb[0]); |
| 733 | alpha = table->GetOpacity(mag); |
| 734 | break; |
| 735 | case vtkScalarsToColors::COMPONENT: |
| 736 | mag = array->GetComponent(i, colorComponent); |
| 737 | table->GetColor(mag, &rgb[0]); |
| 738 | alpha = table->GetOpacity(mag); |
| 739 | break; |
| 740 | case vtkScalarsToColors::RGBCOLORS: |
| 741 | array->GetTuple(i, &rgb[0]); |
| 742 | alpha = actor->GetProperty()->GetOpacity(); |
| 743 | break; |
| 744 | } |
| 745 | color[i * 4 + 0] = (unsigned char)((int)(rgb[0] * 255)); |
| 746 | color[i * 4 + 1] = (unsigned char)((int)(rgb[1] * 255)); |
| 747 | color[i * 4 + 2] = (unsigned char)((int)(rgb[2] * 255)); |
| 748 | color[i * 4 + 3] = (unsigned char)((int)(alpha * 255)); |
| 749 | } |
| 750 | } |
| 751 | else |
| 752 | { |
no test coverage detected