bool ListExpr::ExtractNumericElements(vector<double> &output) { bool all_numeric = true; double val = 0.0; output.clear(); std::vector<ListElemExpr*> *elems = GetElems(); for (int i = 0 ; i < elems->size() ; i++) { ExprNode *item = (*elems)[i]->GetItem(); if (item->GetTypeName() == "FloatConst") { ConstExpr *c = dynamic_cast<ConstExpr*>(item); val = (double) dynamic_cast<FloatConstExpr*>(c)->GetValue(); output.push_back(val); } else if (item->GetTypeName() == "IntegerConst") { ConstExpr *c = dynamic_cast<ConstExpr*>(item); val = (double) dynamic_cast<IntegerConstExpr*>(c)->GetValue(); output.push_back(val); } else { all_numeric = false; } } return all_numeric; }
void avtApplyEnumerationExpression::ProcessArguments(ArgsExpr *args, ExprPipelineState *state) { // Check the number of arguments std::vector<ArgExpr*> *arguments = args->GetArgs(); if (arguments->size() != 2) { EXCEPTION2(ExpressionException, outputVariableName, "the enumerate expression accepts only two arguments"); } ArgExpr *listarg = (*arguments)[1]; ExprParseTreeNode *listTree = listarg->GetExpr(); if (listTree->GetTypeName() != "List") { debug1 << "avtApplyEnumerationExpression: second arg is not a list: " << listTree->GetTypeName() << endl; EXCEPTION2(ExpressionException, outputVariableName, "the last argument to enumerate " "must be a list"); } ListExpr *list = dynamic_cast<ListExpr*>(listTree); std::vector<ListElemExpr*> *elems = list->GetElems(); enumeratedValues.resize(elems->size()); for (int i = 0 ; i < elems->size() ; i++) { if ((*elems)[i]->GetEnd()) { EXCEPTION2(ExpressionException, outputVariableName, "the list for the enumerate " "expression cannot contain ranges."); } ExprNode *item = (*elems)[i]->GetItem(); if (item->GetTypeName() == "FloatConst") { ConstExpr *c = dynamic_cast<ConstExpr*>(item); enumeratedValues[i] = dynamic_cast<FloatConstExpr*>(c)->GetValue(); } else if (item->GetTypeName() == "IntegerConst") { ConstExpr *c = dynamic_cast<ConstExpr*>(item); enumeratedValues[i] = dynamic_cast<IntegerConstExpr*>(c)->GetValue(); } else { EXCEPTION2(ExpressionException, outputVariableName, "the list for the enumerate " "expression may contain only numbers."); } } // Let the base class do this processing. We only had to over-ride this // function to determine the number of arguments. avtMultipleInputExpressionFilter::ProcessArguments(args, state); }
bool ListExpr::ExtractStringElements(vector<std::string> &output) { bool all_string = true; output.clear(); std::vector<ListElemExpr*> *elems = GetElems(); for (int i = 0 ; i < elems->size() ; i++) { ExprNode *item = (*elems)[i]->GetItem(); if (item->GetTypeName() == "StringConst") { ConstExpr *c = dynamic_cast<ConstExpr*>(item); output.push_back(dynamic_cast<StringConstExpr*>(c)->GetValue()); } else { all_string = false; } } return all_string; }
void ParallelCoordinatesViewerPluginInfo::InitializePlotAtts( AttributeSubject *atts, ViewerPlot *plot) { // If we had scalar names, we can just copy the default atts // and return. if (defaultAtts->GetScalarAxisNames().size() != 0) { // One helpful thing we can do: make sure the user set the // visual axis names. They really should have, but since // we can blindly copy them from the scalar axis names in // this case, no harm doing it for them. if (defaultAtts->GetVisualAxisNames().size() == 0) defaultAtts->SetVisualAxisNames(defaultAtts->GetScalarAxisNames()); *(ParallelCoordinatesAttributes*)atts = *defaultAtts; return; } // Otherwise, we must be an array variable; try to get // some names for its components.... const avtDatabaseMetaData *md = plot->GetMetaData(); const std::string &var = plot->GetVariableName(); const avtArrayMetaData *array = md->GetArray(var); stringVector subNames; if (array) { subNames = array->compNames; } else { Expression *exp = ParsingExprList::GetExpression(plot->GetVariableName()); if (exp == NULL || exp->GetType() != Expression::ArrayMeshVar) { debug3 << "ParallelCoordinatesAttributes::InitializePlotAtts: " << "variable wasn't an array database variable, an " << "array expression, or a list of scalars. This can " << "happen if the user attempts to create this plot " << "without the use off a wizard, e.g. in the case of " << "the cli. Assuming this is the case and continuing " << "without error.\n"; return; } // If we have any problems walking the expression tree, just return; // the worst case scenario if we don't populate the visual axis // name list is that the GUI window is temporarily blank. ExprNode *root = ParsingExprList::GetExpressionTree(exp); if (root->GetTypeName() != "Function") return; FunctionExpr *fn = dynamic_cast<FunctionExpr*>(root); if (fn->GetName() != "array_compose" && fn->GetName() != "array_compose_with_bins") return; ArgsExpr *argsExpr = fn->GetArgsExpr(); std::vector<ArgExpr*> *args = argsExpr ? argsExpr->GetArgs() : NULL; if (!args) return; for (size_t i=0; i<args->size(); i++) { ExprNode *arg = (ExprNode*)((*args)[i]->GetExpr()); if (arg->GetTypeName() == "List") break; subNames.push_back(arg->GetPos().GetText(exp->GetDefinition())); } } doubleVector extMin(subNames.size(), -1e+37); doubleVector extMax(subNames.size(), +1e+37); // Set up the default attributes to contain these values, so // if the user hits reset, the axis names are retained. defaultAtts->SetVisualAxisNames(subNames); defaultAtts->SetExtentMinima(extMin); defaultAtts->SetExtentMaxima(extMax); *(ParallelCoordinatesAttributes*)atts = *defaultAtts; }
void avtArrayComposeWithBinsExpression::ProcessArguments(ArgsExpr *args, ExprPipelineState *state) { // Check the number of arguments std::vector<ArgExpr*> *arguments = args->GetArgs(); nvars = (int)arguments->size()-1; int idx_of_list = arguments->size()-1; ArgExpr *listarg = (*arguments)[idx_of_list]; ExprParseTreeNode *listTree = listarg->GetExpr(); if (listTree->GetTypeName() != "List") { debug1 << "avtArrayComposeWithBinsExpression: second arg is not a " << "list: " << listTree->GetTypeName() << endl; EXCEPTION2(ExpressionException, outputVariableName, "the last argument to array_compose_" "with_bins must be a list"); } ListExpr *list = dynamic_cast<ListExpr*>(listTree); std::vector<ListElemExpr*> *elems = list->GetElems(); binRanges.resize(elems->size()); if ((int)elems->size() != nvars+1) { EXCEPTION2(ExpressionException, outputVariableName, "the list for array_compose_with_bins" " must have one more number than there are variables. " " For two variables (V1 and V2), there should be a list of" " size 3: [L0, L1, L2]. V1's bin goes from L0 to L1, " "and V2's bin goes from L1 to L2."); } for (size_t i = 0 ; i < elems->size() ; i++) { if ((*elems)[i]->GetEnd()) { EXCEPTION2(ExpressionException, outputVariableName, "the list for array_compose_with" "_bins expression cannot contain ranges."); } ExprNode *item = (*elems)[i]->GetItem(); if (item->GetTypeName() == "FloatConst") { ConstExpr *c = dynamic_cast<ConstExpr*>(item); binRanges[i] = dynamic_cast<FloatConstExpr*>(c)->GetValue(); } else if (item->GetTypeName() == "IntegerConst") { ConstExpr *c = dynamic_cast<ConstExpr*>(item); binRanges[i] = dynamic_cast<IntegerConstExpr*>(c)->GetValue(); } else { EXCEPTION2(ExpressionException, outputVariableName, "the list for the array_compose" "_with_bins expression may contain only numbers."); } } // Let the base class do this processing. We only had to over-ride this // function to determine the number of arguments. avtMultipleInputExpressionFilter::ProcessArguments(args, state); }
// **************************************************************************** // Method: avtMatvfExpression::ProcessArguments // // Purpose: // Tells the first argument to go generate itself. Parses the second // argument into a list of material names. // // Arguments: // inDS The input dataset. // // Returns: The derived variable. The calling class must free this // memory. // // Programmer: Sean Ahern // Creation: Tue Mar 18 23:20:06 America/Los_Angeles 2003 // // Modifications: // Jeremy Meredith, Mon Sep 29 12:13:04 PDT 2003 // Added support for integer material indices. // Added support for integer ranges. // // Hank Childs, Thu Jul 15 14:44:17 PDT 2004 // Make sure the base pointer type for the dynamic cast is in the // inheritance tree of what we are downcasting type. ('5201) // // Jeremy Meredith, Wed Nov 24 12:26:21 PST 2004 // Renamed EngineExprNode to avtExprNode due to a refactoring. // Also renamed Token to ExprToken for the same reason. // Changed the base type for an Arg's expression. // // Jeremy Meredith, Mon Jun 13 11:42:38 PDT 2005 // Changed the way constant expressions work. // // **************************************************************************** void avtMatvfExpression::ProcessArguments(ArgsExpr *args, ExprPipelineState *state) { // Check the number of arguments std::vector<ArgExpr*> *arguments = args->GetArgs(); int nargs = arguments->size(); if (nargs == 0) { EXCEPTION2(ExpressionException, outputVariableName, "avtMatvfExpression: No arguments given."); } // Tell the first argument to create its filters. ArgExpr *firstarg = (*arguments)[0]; avtExprNode *firstTree = dynamic_cast<avtExprNode*>(firstarg->GetExpr()); firstTree->CreateFilters(state); // Check if there's a second argument. if (nargs == 1) { debug5 << "avtMatvfExpression: No second argument." << endl; return; } // See if there are other arguments. if (nargs > 2) { EXCEPTION2(ExpressionException, outputVariableName, "avtMatvfExpression only expects two " "arguments. To specify more than one material, use a " "list (e.g. [1,4,5:9]."); } // Pull off the second argument and see if it's a string or a list. ArgExpr *secondarg = (*arguments)[1]; ExprParseTreeNode *secondTree = secondarg->GetExpr(); std::string type = secondTree->GetTypeName(); if ((type != "IntegerConst") && (type != "StringConst") && (type != "List")) { debug5 << "avtMatvfExpression: Second argument is not a constant or a list: " << type.c_str() << endl; EXCEPTION2(ExpressionException, outputVariableName, "avtMatvfExpression: Second argument is not a constant or a list."); } if (type == "IntegerConst" || type == "StringConst") { // It's a single constant. AddMaterial(dynamic_cast<ConstExpr*>(secondTree)); } else { // It's a list. Process all of them. ListExpr *list = dynamic_cast<ListExpr*>(secondTree); std::vector<ListElemExpr*> *elems = list->GetElems(); for(int i=0;i<elems->size();i++) { if ((*elems)[i]->GetEnd()) { // it's a range ExprNode *begExpr = (*elems)[i]->GetBeg(); ExprNode *endExpr = (*elems)[i]->GetEnd(); ExprNode *skipExpr = (*elems)[i]->GetSkip(); if (begExpr->GetTypeName() != "IntegerConst" || endExpr->GetTypeName() != "IntegerConst" || (skipExpr && skipExpr->GetTypeName() != "IntegerConst")) { EXCEPTION2(ExpressionException, outputVariableName, "avtMatvfExpression: " "Range must contain integers."); } int beg = dynamic_cast<IntegerConstExpr*>(begExpr)->GetValue(); int end = dynamic_cast<IntegerConstExpr*>(endExpr)->GetValue(); int skip = !skipExpr ? 1 : dynamic_cast<IntegerConstExpr*>(skipExpr)->GetValue(); if (skip <= 0 || beg > end) { EXCEPTION2(ExpressionException, outputVariableName, "avtMatvfExpression: " "Range must be of the form beg:end[:skip]."); } for (int m = beg; m <= end ; m += skip) matIndices.push_back(m); } else { ExprNode *item = (*elems)[i]->GetItem(); std::string type = item->GetTypeName(); if (type != "IntegerConst" && type != "StringConst") { debug5 << "avtMatvfExpression: List element is not an " "integer constant, a string constant, " "or a list: " << type.c_str() << endl; EXCEPTION2(ExpressionException, outputVariableName, "avtMatvfExpression: " "List element is not an int/string constant " "or a list."); } AddMaterial(dynamic_cast<ConstExpr*>(item)); } } } }