Commit 0c20fa6f authored by js9's avatar js9
Browse files

Adding ability for operators to create new variables.

Adding new "constant" expression function.



git-svn-id: http://visit.ilight.com/svn/visit/trunk/src@3266 18c085ea-50e0-402c-830e-de6fd14e8384
parent 054059a8
/*****************************************************************************
*
* Copyright (c) 2000 - 2008, Lawrence Livermore National Security, LLC
* Produced at the Lawrence Livermore National Laboratory
* LLNL-CODE-400142
* 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.
*
*****************************************************************************/
// ************************************************************************* //
// avtConstantFunctionExpression.C //
// ************************************************************************* //
#include <avtConstantFunctionExpression.h>
#include <vtkDataSet.h>
#include <vtkFloatArray.h>
#include <ExpressionException.h>
#include <avtExprNode.h>
// ****************************************************************************
// Method: avtConstantFunctionExpression constructor
//
// Purpose:
// Defines the constructor. Note: this should not be inlined in the
// header because it causes problems for certain compilers.
//
// Programmer: Jeremy Meredith
// Creation: February 19, 2008
//
// ****************************************************************************
avtConstantFunctionExpression::avtConstantFunctionExpression()
{
value = 0;
}
// ****************************************************************************
// Method: avtConstantFunctionExpression destructor
//
// Purpose:
// Defines the destructor. Note: this should not be inlined in the header
// because it causes problems for certain compilers.
//
// Programmer: Jeremy Meredith
// Creation: February 19, 2008
//
// ****************************************************************************
avtConstantFunctionExpression::~avtConstantFunctionExpression()
{
}
// ****************************************************************************
// Method: avtConstantFunctionExpression::DeriveVariable
//
// Purpose:
// Assigns a constant value to the variable.
//
// Arguments:
// inDS The input dataset.
//
// Returns: The derived variable. The calling class must free this
// memory.
//
// Programmer: Jeremy Meredith
// Creation: February 19, 2008
//
// ****************************************************************************
vtkDataArray *
avtConstantFunctionExpression::DeriveVariable(vtkDataSet *in_ds)
{
int npts = in_ds->GetNumberOfPoints();
vtkFloatArray *rv = vtkFloatArray::New();
rv->SetNumberOfTuples(npts);
for (int i = 0 ; i < npts ; i++)
{
rv->SetTuple1(i, value);
}
return rv;
}
void
avtConstantFunctionExpression::ProcessArguments(ArgsExpr *args,
ExprPipelineState *state)
{
if (!args || args->GetArgs()->size() != 2)
{
EXCEPTION2(ExpressionException, outputVariableName,
"the function expected two arguments");
}
std::vector<ArgExpr*> *arguments = args->GetArgs();
ArgExpr *arg0 = (*arguments)[0];
ArgExpr *arg1 = (*arguments)[1];
ExprParseTreeNode *node0 = arg0->GetExpr();
ExprParseTreeNode *node1 = arg1->GetExpr();
avtExprNode *expr0 = dynamic_cast<avtExprNode*>(node0);
avtExprNode *expr1 = dynamic_cast<avtExprNode*>(node1);
if (!expr0)
{
EXCEPTION2(ExpressionException, outputVariableName,
"the first argument was not an expression");
}
if (!expr1 ||
(expr1->GetTypeName() != "IntegerConst" &&
expr1->GetTypeName() != "FloatConst"))
{
EXCEPTION2(ExpressionException, outputVariableName,
"the second argument was not an int or float constant");
}
expr0->CreateFilters(state);
if (expr1->GetTypeName() == "IntegerConst")
value = dynamic_cast<avtIntegerConstExpr*>(expr1)->GetValue();
else
value = dynamic_cast<avtFloatConstExpr*>(expr1)->GetValue();
}
/*****************************************************************************
*
* Copyright (c) 2000 - 2008, Lawrence Livermore National Security, LLC
* Produced at the Lawrence Livermore National Laboratory
* LLNL-CODE-400142
* 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.
*
*****************************************************************************/
// ************************************************************************* //
// avtConstantFunctionExpression.h //
// ************************************************************************* //
#ifndef AVT_CONSTANT_FUNCTION_EXPRESSION_H
#define AVT_CONSTANT_FUNCTION_EXPRESSION_H
#include <avtMultipleInputExpressionFilter.h>
class vtkDataArray;
// ****************************************************************************
// Class: avtConstantFunctionExpression
//
// Purpose:
// Create a constant-valued nodal variable on a mesh. Useful if you
// want to create a constant on a mesh using only a single function.
//
// Programmer: Jeremy Meredith
// Creation: February 19, 2008
//
// Modifications:
//
// ****************************************************************************
class EXPRESSION_API avtConstantFunctionExpression
: public avtMultipleInputExpressionFilter
{
public:
avtConstantFunctionExpression();
virtual ~avtConstantFunctionExpression();
virtual const char *GetType() { return "avtConstantFunctionExpression"; }
virtual const char *GetDescription() { return "Assigning constant."; }
virtual void ProcessArguments(ArgsExpr*, ExprPipelineState *);
protected:
virtual vtkDataArray *DeriveVariable(vtkDataSet *);
virtual bool IsPointVariable() { return true; }
virtual int GetVariableDimension() { return 1; }
virtual int NumVariableArguments(void) { return 1; }
private:
float value;
};
#endif
......@@ -202,6 +202,9 @@
# Jeremy Meredith, Wed Feb 13 12:11:56 EST 2008
# Add avtApplyEnumerationExpression.
#
# Jeremy Meredith, Tue Feb 19 14:18:03 EST 2008
# Added constant creation function.
#
##############################################################################
@SET_MAKE@
......@@ -271,6 +274,7 @@ General_src= \
General/avtArrayDecomposeExpression.C \
General/avtColorComposeExpression.C \
General/avtConnComponentsExpression.C \
General/avtConstantFunctionExpression.C \
General/avtCurlExpression.C \
General/avtDataIdExpression.C \
General/avtDegreeExpression.C \
......
......@@ -156,6 +156,7 @@
#include <avtPerformColorTableLookupExpression.h>
#include <avtPerMaterialValueExpression.h>
#include <avtApplyEnumerationExpression.h>
#include <avtConstantFunctionExpression.h>
#include <stdio.h>
#include <ExpressionException.h>
......@@ -474,6 +475,9 @@ avtVectorExpr::CreateFilters(ExprPipelineState *state)
// Hank Childs, Wed Feb 13 11:21:40 PST 2008
// Make module an alias for mod.
//
// Jeremy Meredith, Tue Feb 19 14:19:18 EST 2008
// Added "constant".
//
// ****************************************************************************
avtExpressionFilter *
......@@ -879,6 +883,8 @@ avtFunctionExpr::CreateFilters(string functionName)
return new avtHSVColorComposeExpression;
if (functionName == "colorlookup")
return new avtPerformColorTableLookupExpression;
if (functionName == "constant")
return new avtConstantFunctionExpression;
return NULL;
}
......
......@@ -55,6 +55,9 @@ class QWidget;
class avtPluginFilter;
class ViewerPlot;
#include <vector>
#include <string>
// ****************************************************************************
// Class: *OperatorPluginInfo
//
......@@ -101,6 +104,9 @@ class ViewerPlot;
// Added new methods to the operator plugin that allow it to control
// the types of variables that the GUI puts in the variable list.
//
// Jeremy Meredith, Mon Feb 18 17:44:40 EST 2008
// Added way for operators to create new variable names.
//
// ****************************************************************************
class PLUGIN_API GeneralOperatorPluginInfo
......@@ -153,6 +159,10 @@ class PLUGIN_API ViewerOperatorPluginInfo : public virtual CommonOperatorPluginI
virtual bool Removeable() const { return true; }
virtual bool Moveable() const { return true; }
virtual bool AllowsSubsequentOperators() const { return true; }
virtual std::vector<std::string> GetCreatedVariableNames()
{
return std::vector<std::string>();
}
};
class PLUGIN_API EngineOperatorPluginInfo : public virtual CommonOperatorPluginInfo
......
......@@ -80,7 +80,7 @@ Expression::ExprType_FromString(const std::string &s, Expression::ExprType &val)
}
// Type map format string
const char *Expression::TypeMapFormatString = "ssbibsb";
const char *Expression::TypeMapFormatString = "ssbibbsb";
// ****************************************************************************
// Method: Expression::Expression
......@@ -91,7 +91,7 @@ const char *Expression::TypeMapFormatString = "ssbibsb";
// Note: Autogenerated by xml2atts.
//
// Programmer: xml2atts
// Creation: Thu Dec 20 09:40:36 PDT 2007
// Creation: Tue Feb 19 10:29:09 PDT 2008
//
// Modifications:
//
......@@ -105,6 +105,7 @@ Expression::Expression() :
hidden = false;
type = ScalarMeshVar;
fromDB = false;
fromOperator = false;
dbName = "__none__";
autoExpression = false;
}
......@@ -118,7 +119,7 @@ Expression::Expression() :
// Note: Autogenerated by xml2atts.
//
// Programmer: xml2atts
// Creation: Thu Dec 20 09:40:36 PDT 2007
// Creation: Tue Feb 19 10:29:09 PDT 2008
//
// Modifications:
//
......@@ -132,6 +133,7 @@ Expression::Expression(const Expression &obj) :
hidden = obj.hidden;
type = obj.type;
fromDB = obj.fromDB;
fromOperator = obj.fromOperator;
dbName = obj.dbName;
autoExpression = obj.autoExpression;
......@@ -147,7 +149,7 @@ Expression::Expression(const Expression &obj) :
// Note: Autogenerated by xml2atts.
//
// Programmer: xml2atts
// Creation: Thu Dec 20 09:40:36 PDT 2007
// Creation: Tue Feb 19 10:29:09 PDT 2008
//
// Modifications:
//
......@@ -167,7 +169,7 @@ Expression::~Expression()
// Note: Autogenerated by xml2atts.
//
// Programmer: xml2atts
// Creation: Thu Dec 20 09:40:36 PDT 2007
// Creation: Tue Feb 19 10:29:09 PDT 2008
//
// Modifications:
//
......@@ -182,6 +184,7 @@ Expression::operator = (const Expression &obj)
hidden = obj.hidden;
type = obj.type;
fromDB = obj.fromDB;
fromOperator = obj.fromOperator;
dbName = obj.dbName;
autoExpression = obj.autoExpression;
......@@ -198,7 +201,7 @@ Expression::operator = (const Expression &obj)
// Note: Autogenerated by xml2atts.
//
// Programmer: xml2atts
// Creation: Thu Dec 20 09:40:36 PDT 2007
// Creation: Tue Feb 19 10:29:09 PDT 2008
//
// Modifications:
//
......@@ -213,6 +216,7 @@ Expression::operator == (const Expression &obj) const
(hidden == obj.hidden) &&
(type == obj.type) &&
(fromDB == obj.fromDB) &&
(fromOperator == obj.fromOperator) &&
(dbName == obj.dbName) &&
(autoExpression == obj.autoExpression));
}
......@@ -226,7 +230,7 @@ Expression::operator == (const Expression &obj) const
// Note: Autogenerated by xml2atts.
//
// Programmer: xml2atts
// Creation: Thu Dec 20 09:40:36 PDT 2007
// Creation: Tue Feb 19 10:29:09 PDT 2008
//
// Modifications:
//
......@@ -247,7 +251,7 @@ Expression::operator != (const Expression &obj) const
// Note: Autogenerated by xml2atts.
//
// Programmer: xml2atts
// Creation: Thu Dec 20 09:40:36 PDT 2007
// Creation: Tue Feb 19 10:29:09 PDT 2008
//
// Modifications:
//
......@@ -268,7 +272,7 @@ Expression::TypeName() const
// Note: Autogenerated by xml2atts.
//
// Programmer: xml2atts
// Creation: Thu Dec 20 09:40:36 PDT 2007
// Creation: Tue Feb 19 10:29:09 PDT 2008
//
// Modifications:
//
......@@ -296,7 +300,7 @@ Expression::CopyAttributes(const AttributeGroup *atts)
// Note: Autogenerated by xml2atts.
//
// Programmer: xml2atts
// Creation: Thu Dec 20 09:40:36 PDT 2007
// Creation: Tue Feb 19 10:29:09 PDT 2008
//
// Modifications:
//
......@@ -322,7 +326,7 @@ Expression::CreateCompatible(const std::string &tname) const
// Note: Autogenerated by xml2atts.
//
// Programmer: xml2atts
// Creation: Thu Dec 20 09:40:36 PDT 2007
// Creation: Tue Feb 19 10:29:09 PDT 2008
//
// Modifications:
//
......@@ -349,7 +353,7 @@ Expression::NewInstance(bool copy) const
// Note: Autogenerated by xml2atts.
//
// Programmer: xml2atts
// Creation: Thu Dec 20 09:40:36 PDT 2007
// Creation: Tue Feb 19 10:29:09 PDT 2008
//
// Modifications:
//
......@@ -363,6 +367,7 @@ Expression::SelectAll()
Select(ID_hidden, (void *)&hidden);
Select(ID_type, (void *)&type);
Select(ID_fromDB, (void *)&fromDB);
Select(ID_fromOperator, (void *)&fromOperator);
Select(ID_dbName, (void *)&dbName);
Select(ID_autoExpression, (void *)&autoExpression);
}
......@@ -380,7 +385,7 @@ Expression::SelectAll()
// Note: Autogenerated by xml2atts.
//
// Programmer: xml2atts
// Creation: Thu Dec 20 09:40:36 PDT 2007
// Creation: Tue Feb 19 10:29:09 PDT 2008
//
// Modifications:
//
......@@ -427,6 +432,12 @@ Expression::CreateNode(DataNode *parentNode, bool completeSave, bool forceAdd)
node->AddNode(new DataNode("fromDB", fromDB));
}
if(completeSave || !FieldsEqual(ID_fromOperator, &defaultObject))
{
addToParent = true;
node->AddNode(new DataNode("fromOperator", fromOperator));
}
if(completeSave || !FieldsEqual(ID_dbName, &defaultObject))
{
addToParent = true;
......@@ -458,7 +469,7 @@ Expression::CreateNode(DataNode *parentNode, bool completeSave, bool forceAdd)
// Note: Autogenerated by xml2atts.
//
// Programmer: xml2atts
// Creation: Thu Dec 20 09:40:36 PDT 2007
// Creation: Tue Feb 19 10:29:09 PDT 2008
//
// Modifications:
//
......@@ -500,6 +511,8 @@ Expression::SetFromNode(DataNode *parentNode)
}
if((node = searchNode->GetNode("fromDB")) != 0)
SetFromDB(node->AsBool());
if((node = searchNode->GetNode("fromOperator")) != 0)
SetFromOperator(node->AsBool());
if((node = searchNode->GetNode("dbName")) != 0)
SetDbName(node->AsString());
if((node = searchNode->GetNode("autoExpression")) != 0)
......@@ -545,6 +558,13 @@ Expression::SetFromDB(bool fromDB_)
Select(ID_fromDB, (void *)&fromDB);
}
void
Expression::SetFromOperator(bool fromOperator_)
{
fromOperator = fromOperator_;
Select(ID_fromOperator, (void *)&fromOperator);
}
void
Expression::SetDbName(const std::string &dbName_)
{
......@@ -605,6 +625,12 @@ Expression::GetFromDB() const
return fromDB;
}
bool
Expression::GetFromOperator() const
{
return fromOperator;
}
const std::string &
Expression::GetDbName() const
{
......@@ -658,7 +684,7 @@ Expression::SelectDbName()
// Note: Autogenerated by xml2atts.
//
// Programmer: xml2atts
// Creation: Thu Dec 20 09:40:36 PDT 2007
// Creation: Tue Feb 19 10:29:09 PDT 2008
//
// Modifications:
//
......@@ -674,6 +700,7 @@ Expression::GetFieldName(int index) const
case ID_hidden: return "hidden";
case ID_type: return "type";
case ID_fromDB: return "fromDB";
case ID_fromOperator: return "fromOperator";
case ID_dbName: return "dbName";
case ID_autoExpression: return "autoExpression";
default: return "invalid index";
......@@ -689,7 +716,7 @@ Expression::GetFieldName(int index) const
// Note: Autogenerated by xml2atts.
//
// Programmer: xml2atts
// Creation: Thu Dec 20 09:40:36 PDT 2007
// Creation: Tue Feb 19 10:29:09 PDT 2008
//
// Modifications:
//
......@@ -705,6 +732,7 @@ Expression::GetFieldType(int index) const
case ID_hidden: return FieldType_bool;
case ID_type: return FieldType_enum;
case ID_fromDB: return FieldType_bool;
case ID_fromOperator: return FieldType_bool;
case ID_dbName: return FieldType_string;
case ID_autoExpression: return FieldType_bool;
default: return FieldType_unknown;
......@@ -720,7 +748,7 @@ Expression::GetFieldType(int index) const
// Note: Autogenerated by xml2atts.
//
// Programmer: xml2atts
// Creation: Thu Dec 20 09:40:36 PDT 2007
// Creation: Tue Feb 19 10:29:09 PDT 2008
//
// Modifications:
//
......@@ -736,6 +764,7 @@ Expression::GetFieldTypeName(int index) const
case ID_hidden: return "bool";
case ID_type: return "enum";
case ID_fromDB: return "bool";
case ID_fromOperator: return "bool";
case ID_dbName: return "string";
case ID_autoExpression: return "bool";
default: return "invalid index";
......@@ -751,7 +780,7 @@ Expression::GetFieldTypeName(int index) const
// Note: Autogenerated by xml2atts.
//
// Programmer: xml2atts
// Creation: Thu Dec 20 09:40:36 PDT 2007
// Creation: Tue Feb 19 10:29:09 PDT 2008
//
// Modifications:
//
......@@ -789,6 +818,11 @@ Expression::FieldsEqual(int index_, const AttributeGroup *rhs) const
retval = (fromDB == obj.fromDB);
}
break;
case ID_fromOperator:
{ // new scope
retval = (fromOperator == obj.fromOperator);
}
break;
case ID_dbName:
{ // new scope
retval = (dbName == obj.dbName);
......
......@@ -51,7 +51,7 @@
// Notes: Autogenerated by xml2atts.
//
// Programmer: xml2atts
// Creation: Thu Dec 20 09:40:36 PDT 2007
// Creation: Tue Feb 19 10:29:09 PDT 2008
//
// Modifications:
//
......@@ -99,6 +99,7 @@ public:
void SetHidden(bool hidden_);
void SetType(ExprType type_);
void SetFromDB(bool fromDB_);
void SetFromOperator(bool fromOperator_);
void SetDbName(const std::string &dbName_);
void SetAutoExpression(bool autoExpression_);
......@@ -110,6 +111,7 @@ public:
bool GetHidden() const;
ExprType GetType() const;
bool GetFromDB() const;
bool GetFromOperator() const;
const std::string &GetDbName() const;
std::string &GetDbName();
bool GetAutoExpression() const;
......@@ -143,6 +145,7 @@ public:
ID_hidden,
ID_type,
ID_fromDB,
ID_fromOperator,
ID_dbName,
ID_autoExpression
};
......@@ -153,6 +156,7 @@ private:
bool hidden;
int type;