avtColorTables::avtColorTables() { ctAtts = new ColorTableAttributes(); // Set up some pointers. const float *predef_ct_colors[17]; predef_ct_colors[0] = ct_bluehot; predef_ct_colors[1] = ct_caleblack; predef_ct_colors[2] = ct_calewhite; predef_ct_colors[3] = ct_contoured; predef_ct_colors[4] = ct_difference; predef_ct_colors[5] = ct_gray; predef_ct_colors[6] = ct_hot; predef_ct_colors[7] = ct_hot_and_cold; predef_ct_colors[8] = ct_hot_desaturated; predef_ct_colors[9] = ct_levels; predef_ct_colors[10] = ct_orangehot; predef_ct_colors[11] = ct_rainbow; predef_ct_colors[12] = ct_xray; predef_ct_colors[13] = ct_jmol_colors; predef_ct_colors[14] = ct_rasmol_colors; predef_ct_colors[15] = ct_amino_colors; predef_ct_colors[16] = ct_shapely_colors; // Add each colortable. for(int i = 0; i < 17; ++i) { ColorControlPointList ccpl; const float *fptr = predef_ct_colors[i]; for(int j = 0; j < predef_ct_ncolors[i]; ++j) { ColorControlPoint p(fptr[0], (unsigned char)(fptr[1]*255), (unsigned char)(fptr[2]*255), (unsigned char)(fptr[3]*255), 255); ccpl.AddControlPoints(p); fptr += 4; } ccpl.SetSmoothingFlag(predef_ct_smooth[i] == 1); ccpl.SetEqualSpacingFlag(predef_ct_equal[i] == 1); ccpl.SetDiscreteFlag(predef_ct_discrete[i] == 1); ctAtts->AddColorTable(predef_ct_names[i], ccpl); } // Set the active continuous color table to "hot". ctAtts->SetActiveContinuous("hot"); // Set the active discrete color table to "levels". ctAtts->SetActiveDiscrete("levels"); }
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()); }