void ColorControlPointList::SetFromNode(DataNode* parentNode) { if (parentNode == 0) return; DataNode* searchNode = parentNode->GetNode("ColorControlPointList"); if (searchNode == 0) return; DataNode* node; DataNode** children; // Clear all the ColorControlPoints. ClearControlPoints(); // // Try setting the colors from the compact color and position vectors. // bool colorsAreSet = false; DataNode* compactColorNode = searchNode->GetNode("compactColors"); DataNode* compactPositionNode = searchNode->GetNode("compactPositions"); if (compactColorNode != 0 && compactPositionNode != 0) { const unsignedCharVector& colors = compactColorNode->AsUnsignedCharVector(); const floatVector& positions = compactPositionNode->AsFloatVector(); unsigned int npts = static_cast<unsigned int>(colors.size() / 4); if (npts > static_cast<unsigned int>(positions.size())) npts = static_cast<unsigned int>(positions.size()); if (npts > 0) { for (unsigned int i = 0; i < npts; ++i) { int index = i << 2; AddControlPoints(ColorControlPoint( positions[i], colors[index], colors[index + 1], colors[index + 2], colors[index + 3])); } colorsAreSet = true; } } if (!colorsAreSet) { // Go through all of the children and construct a new // ColorControlPoint for each one of them. children = searchNode->GetChildren(); for (int i = 0; i < searchNode->GetNumChildren(); ++i) { if (children[i]->GetKey() == std::string("ColorControlPoint")) { ColorControlPoint temp; temp.SetFromNode(children[i]); AddControlPoints(temp); } } } if ((node = searchNode->GetNode("smoothingFlag")) != 0) SetSmoothingFlag(node->AsBool()); if ((node = searchNode->GetNode("equalSpacingFlag")) != 0) SetEqualSpacingFlag(node->AsBool()); if ((node = searchNode->GetNode("discreteFlag")) != 0) SetDiscreteFlag(node->AsBool()); if ((node = searchNode->GetNode("externalFlag")) != 0) SetExternalFlag(node->AsBool()); }
void ColorTableAttributes::SetFromNode(DataNode *parentNode) { if(parentNode == 0) return; DataNode *searchNode = parentNode->GetNode("ColorTableAttributes"); if(searchNode == 0) return; // Look for the number of color tables. DataNode *node = 0; if((node = searchNode->GetNode("Ntables")) != 0) { char tmp[100]; int ntables = node->AsInt(); // Look for ntables color table nodes. for(int i = 0; i < ntables; ++i) { SNPRINTF(tmp, 100, "table%02d", i); if((node = searchNode->GetNode(tmp)) != 0) { DataNode *nameNode = node->GetNode("ctName"); DataNode *pointNode = node->GetNode("controlPts"); // If we have the name node and the pointNode, we can add a // color table. if(nameNode && pointNode) { ColorControlPointList ccpl; // Try and set the equal flag. DataNode *tmpNode; if((tmpNode = node->GetNode("equal")) != 0) ccpl.SetEqualSpacingFlag(tmpNode->AsBool()); // Try and set the smooth flag. if((tmpNode = node->GetNode("smooth")) != 0) ccpl.SetSmoothingFlag(tmpNode->AsBool()); if((tmpNode = node->GetNode("discrete")) != 0) ccpl.SetDiscreteFlag(tmpNode->AsBool()); // Set the color control points. floatVector fvec = pointNode->AsFloatVector(); for(size_t j = 0; j < fvec.size() / 4; ++j) { // Create a control point based on the values // in the float vector. int index = j * 4; ColorControlPoint cpt(fvec[index], (unsigned char)(fvec[index+1]), (unsigned char)(fvec[index+2]), (unsigned char)(fvec[index+3]), 255); ccpl.AddControlPoints(cpt); } // If the color table is already in the list, remove it. // Then add the new color table to the list. RemoveColorTable(nameNode->AsString()); AddColorTable(nameNode->AsString(), ccpl); } } } // end for i } if((node = searchNode->GetNode("activeContinuous")) != 0) SetActiveContinuous(node->AsString()); if((node = searchNode->GetNode("activeDiscrete")) != 0) SetActiveDiscrete(node->AsString()); // For older version compatibility... if((node = searchNode->GetNode("activeColorTable")) != 0) SetActiveContinuous(node->AsString()); }
void ColorTableAttributes::SetFromNode(DataNode *parentNode) { if(parentNode == 0) return; DataNode *searchNode = parentNode->GetNode("ColorTableAttributes"); if(searchNode == 0) return; // Look for the number of color tables. DataNode *node = 0; if((node = searchNode->GetNode("Ntables")) != 0) { char tmp[100]; int ntables = node->AsInt(); // Look for ntables color table nodes. for(int i = 0; i < ntables; ++i) { SNPRINTF(tmp, 100, "table%02d", i); if((node = searchNode->GetNode(tmp)) != 0) { DataNode *nameNode = node->GetNode("ctName"); DataNode *pointNode = node->GetNode("controlPts"); DataNode *colorsHaveOpacity = node->GetNode("colorsHaveOpacity"); bool readAlpha = false; if (colorsHaveOpacity != NULL) readAlpha = true; // If we have the name node and the pointNode, we can add a // color table. if(nameNode && pointNode) { ColorControlPointList ccpl; // Try and set the equal flag. DataNode *tmpNode; if((tmpNode = node->GetNode("equal")) != 0) ccpl.SetEqualSpacingFlag(tmpNode->AsBool()); // Try and set the smooth flag. (old way) if((tmpNode = node->GetNode("smooth")) != 0) ccpl.SetSmoothing(tmpNode->AsBool()?ColorControlPointList::Linear:ColorControlPointList::None); // (new way) if((tmpNode = node->GetNode("smoothing")) != 0) ccpl.SetSmoothing(static_cast<ColorControlPointList::SmoothingMethod>(tmpNode->AsInt())); if((tmpNode = node->GetNode("discrete")) != 0) ccpl.SetDiscreteFlag(tmpNode->AsBool()); if((tmpNode = node->GetNode("category")) != 0) ccpl.SetCategoryName(tmpNode->AsString()); else ccpl.SetCategoryName("Standard"); // Set the color control points. floatVector fvec = pointNode->AsFloatVector(); int nvalsPerColor = 4; if (readAlpha) nvalsPerColor = 5; for(size_t j = 0; j < fvec.size() / nvalsPerColor; ++j) { // Create a control point based on the values // in the float vector. int index = j * nvalsPerColor; ColorControlPoint cpt(fvec[index], (unsigned char)(fvec[index+1]), (unsigned char)(fvec[index+2]), (unsigned char)(fvec[index+3]), (readAlpha ? (unsigned char)(fvec[index+4]) : 255)); ccpl.AddControlPoints(cpt); } // If the color table is already in the list, remove it. // Then add the new color table to the list. RemoveColorTable(nameNode->AsString()); AddColorTable(nameNode->AsString(), ccpl); } } } // end for i } if((node = searchNode->GetNode("activeContinuous")) != 0) SetActiveContinuous(node->AsString()); if((node = searchNode->GetNode("activeDiscrete")) != 0) SetActiveDiscrete(node->AsString()); if((node = searchNode->GetNode("groupingFlag")) != 0) SetGroupingFlag(node->AsBool()); // For older version compatibility... if((node = searchNode->GetNode("activeColorTable")) != 0) SetActiveContinuous(node->AsString()); }