MCPcopy Create free account
hub / github.com/Kitware/VTK / GetColorsFromPointData

Method GetColorsFromPointData

Web/WebGLExporter/vtkWebGLPolyData.cxx:695–783  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

693}
694
695void 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 {

Callers 1

Calls 15

GetDataSizeMethod · 0.80
GetArrayAccessModeMethod · 0.80
GetMapperMethod · 0.80
GetArrayIdMethod · 0.80
DeleteMethod · 0.65
sqrtFunction · 0.50
GetScalarsClass · 0.50
GetNormalsMethod · 0.45
GetArrayMethod · 0.45
GetArrayNameMethod · 0.45
GetLookupTableMethod · 0.45
GetNumberOfComponentsMethod · 0.45

Tested by

no test coverage detected