----------------------------------------------------------------------------
| 941 | |
| 942 | //---------------------------------------------------------------------------- |
| 943 | bool vtkSMTransferFunctionProxy::SaveColorMap(vtkPVXMLElement* xml) |
| 944 | { |
| 945 | if (!xml) |
| 946 | { |
| 947 | vtkWarningMacro("'xml' cannot be nullptr"); |
| 948 | return false; |
| 949 | } |
| 950 | |
| 951 | xml->SetName("ColorMap"); |
| 952 | |
| 953 | bool indexedLookup = vtkSMPropertyHelper(this, "IndexedLookup").GetAsInt() != 0; |
| 954 | xml->AddAttribute("indexedLookup", indexedLookup ? "1" : "0"); |
| 955 | |
| 956 | if (!indexedLookup) |
| 957 | { |
| 958 | std::string space = vtkSMPropertyHelper(this, "ColorSpace").GetAsString(); |
| 959 | if (space == "HSV" && vtkSMPropertyHelper(this, "HSVWrap").GetAsInt() == 1) |
| 960 | { |
| 961 | xml->AddAttribute("space", "Wrapped"); |
| 962 | } |
| 963 | else |
| 964 | { |
| 965 | xml->AddAttribute("space", space.c_str()); |
| 966 | } |
| 967 | } |
| 968 | |
| 969 | // Add the control points. |
| 970 | vtkSMProperty* controlPointsProperty = |
| 971 | indexedLookup ? this->GetProperty("IndexedColors") : GetControlPointsProperty(this); |
| 972 | if (!controlPointsProperty) |
| 973 | { |
| 974 | return false; |
| 975 | } |
| 976 | |
| 977 | vtkSMPropertyHelper cntrlPoints(controlPointsProperty); |
| 978 | unsigned int num_elements = cntrlPoints.GetNumberOfElements(); |
| 979 | if (num_elements > 0) |
| 980 | { |
| 981 | if (indexedLookup) |
| 982 | { |
| 983 | // Save (r,g,b) tuples for categorical colors. |
| 984 | std::vector<vtkTuple<double, 3>> points; |
| 985 | points.resize(num_elements / 3); |
| 986 | cntrlPoints.Get(points[0].GetData(), num_elements); |
| 987 | |
| 988 | for (size_t cc = 0; cc < points.size(); cc++) |
| 989 | { |
| 990 | vtkNew<vtkPVXMLElement> child; |
| 991 | child->SetName("Point"); |
| 992 | child->AddAttribute("r", points[cc].GetData()[1]); |
| 993 | child->AddAttribute("g", points[cc].GetData()[2]); |
| 994 | child->AddAttribute("b", points[cc].GetData()[3]); |
| 995 | child->AddAttribute("o", 1.0); |
| 996 | xml->AddNestedElement(child); |
| 997 | } |
| 998 | } |
| 999 | else |
| 1000 | { |
no test coverage detected