Commit 74be8fb5 authored by cyrush's avatar cyrush

added 'map' expression

git-svn-id: http://visit.ilight.com/svn/visit/trunk/src@8131 18c085ea-50e0-402c-830e-de6fd14e8384
parent 414db674
This diff is collapsed.
/*****************************************************************************
*
* Copyright (c) 2000 - 2009, Lawrence Livermore National Security, LLC
* Produced at the Lawrence Livermore National Laboratory
* LLNL-CODE-400124
* All rights reserved.
*
* This file is part of VisIt. For details, see https://visit.llnl.gov/. The
* full copyright notice is contained in the file COPYRIGHT located at the root
* of the VisIt distribution or at http://www.llnl.gov/visit/copyright.html.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the disclaimer below.
* - Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the disclaimer (as noted below) in the
* documentation and/or other materials provided with the distribution.
* - Neither the name of the LLNS/LLNL nor the names of its contributors may
* be used to endorse or promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL LAWRENCE LIVERMORE NATIONAL SECURITY,
* LLC, THE U.S. DEPARTMENT OF ENERGY OR CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
* DAMAGE.
*
*****************************************************************************/
// ************************************************************************* //
// avtApplyMapExpression.h //
// ************************************************************************* //
#ifndef AVT_APPLY_MAP_EXPRESSION_H
#define AVT_APPLY_MAP_EXPRESSION_H
#include <avtMultipleInputExpressionFilter.h>
#include <vector>
#include <map>
class vtkDataArray;
class ArgsExpr;
class ExprPipelineState;
class ExprParseTreeNode;
class ListExpr;
// ****************************************************************************
// Class: avtApplyMapExpression
//
// Purpose:
// Map a set of numeric values to string labels, or another set of
// numeric values.
//
// Programmer: Cyrus Harrison
// Creation: Thursday August 07, 2009
//
// ****************************************************************************
class EXPRESSION_API avtApplyMapExpression
: public avtMultipleInputExpressionFilter
{
public:
avtApplyMapExpression();
virtual ~avtApplyMapExpression();
virtual const char *GetType(void)
{ return "avtApplyMapExpression"; };
virtual const char *GetDescription(void)
{ return "Applying map expression"; };
virtual void ProcessArguments(ArgsExpr*, ExprPipelineState *);
virtual int NumVariableArguments(void) { return 1; };
protected:
virtual vtkDataArray *DeriveVariable(vtkDataSet *);
virtual avtVarType GetVariableType(void) { return AVT_SCALAR_VAR;};
virtual void UpdateDataObjectInfo();
private:
int mapType;
std::map<double,double> numericMap;
double numericDefault;
std::map<double,std::string> stringMap;
std::string stringDefault;
int maxStringLength;
void BuildMap(ListExpr *to_list);
void BuildMap(ListExpr *to_list,
const std::vector<double> &from_values);
void SetMapDefaultValues(ExprParseTreeNode *node);
void ThrowError(const std::string &msg);
};
#endif
......@@ -246,10 +246,13 @@
#
# Brad Whitlock, Tue Jun 2 10:14:37 PDT 2009
# I split up avtExprNode into several files to speed compilation on xlC.
#
#
# Sean Ahern, Wed Jun 24 15:19:46 EDT 2009
# Renamed Diagonal to DiagonalRatio. Added MaxDiagonal and MinDiagonal.
#
# Cyrus Harrison, Tue Aug 11 10:30:49 PDT 2009
# Added the "map" expression (avtApplyMapExpression)
#
##############################################################################
@SET_MAKE@
......@@ -315,6 +318,7 @@ Derivations_src=\
General_src= \
General/avtApplyDDFExpression.C \
General/avtApplyEnumerationExpression.C \
General/avtApplyMapExpression.C \
General/avtArrayComposeExpression.C \
General/avtArrayComposeWithBinsExpression.C \
General/avtArrayDecomposeExpression.C \
......
......@@ -50,6 +50,7 @@
#include <avtApplyDDFExpression.h>
#include <avtApplyEnumerationExpression.h>
#include <avtApplyMapExpression.h>
#include <avtArrayComposeExpression.h>
#include <avtArrayComposeWithBinsExpression.h>
#include <avtArrayDecomposeExpression.h>
......@@ -447,6 +448,9 @@ avtVectorExpr::CreateFilters(ExprPipelineState *state)
// I separated out lots of related functions into methods in another file
// to make this file easier to compile.
//
// Cyrus Harrison, Tue Aug 11 10:34:08 PDT 2009
// Added the "map" expression.
//
// ****************************************************************************
avtExpressionFilter *
......@@ -474,6 +478,8 @@ avtFunctionExpr::CreateFilters(string functionName)
if (functionName == "enumerate")
return new avtApplyEnumerationExpression();
if (functionName == "map")
return new avtApplyMapExpression();
if (functionName == "array_compose")
return new avtArrayComposeExpression();
if (functionName == "array_compose_with_bins")
......
......@@ -283,6 +283,71 @@ ListExpr::AddListElem(ListElemExpr *e)
elems->push_back(e);
}
// Cyrus Harrison, Mon Aug 10 10:14:53 PDT 2009
// Added helpers for use in processing argments.
// These return true if all elements conform to
// the desired type (numeric, or string)
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;
}
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;
}
// Jeremy Meredith, Thu Aug 7 16:21:24 EDT 2008
// Use %ld for longs.
void
......
......@@ -111,6 +111,9 @@ class Pos;
// Jeremy Meredith, Mon Dec 15 12:50:38 EST 2008
// Added GetOp to MathExpr.
//
// Cyrus Harrison, Fri Aug 14 15:22:43 PDT 2009
// Added helpers for processing numeric & string lists.
//
// ****************************************************************************
class EXPR_API ExprNode : public ExprParseTreeNode
{
......@@ -295,6 +298,10 @@ class EXPR_API ListExpr : public ExprParseTreeNode
virtual void PrintNode(ostream &o);
virtual const std::string GetTypeName() { return "List"; }
std::vector<ListElemExpr*> *GetElems(void) { return elems; }
bool ExtractNumericElements(std::vector<double> &output);
bool ExtractStringElements(std::vector<std::string> &output);
virtual std::vector<std::string> GetVarLeaves();
virtual std::set<ExprParseTreeNode *> GetVarLeafNodes();
protected:
......
../../avt/Expressions/General/avtApplyMapExpression.h
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment