Commit 835fb264 authored by ahern's avatar ahern
Browse files

Added an optional parameter to the recenter() function, allowing the user to

specify the target centering.


git-svn-id: http://visit.ilight.com/svn/visit/trunk/src@5174 18c085ea-50e0-402c-830e-de6fd14e8384
parent a2e8de8d
......@@ -624,7 +624,8 @@ avtExpressionFilter::GetVariableDimension(void)
// Arguments:
// ds The mesh the variable lays on.
// arr The variable to recenter.
// currCent The current centering of the variable -- NOT the desired centering.
// currCent The current centering of the variable
// targCent The desires centering of the variable
//
// Returns: The array recentered. Note: the calling routine will then
// be responsible for deleting the returned object.
......@@ -636,15 +637,34 @@ avtExpressionFilter::GetVariableDimension(void)
// Sean Ahern, Mon Dec 10 09:59:27 EST 2007
// Added a variable for error messages.
//
// Sean Ahern, Wed Sep 10 12:22:13 EDT 2008
// Added a target centering. Defaults to toggling if not set
// (AVT_UNKNOWN_CENT).
//
// ****************************************************************************
vtkDataArray *
avtExpressionFilter::Recenter(vtkDataSet *ds, vtkDataArray *arr,
avtCentering currCent, std::string name)
avtExpressionFilter::Recenter(vtkDataSet *ds, vtkDataArray *arr,
avtCentering currCent,
std::string name, avtCentering targCent)
{
vtkDataSet *ds2 = ds->NewInstance();
ds2->CopyStructure(ds);
if (targCent == AVT_UNKNOWN_CENT)
{
if (currCent == AVT_NODECENT)
targCent = AVT_ZONECENT;
if (currCent == AVT_ZONECENT)
targCent = AVT_NODECENT;
}
if (currCent == targCent)
{
// Nothing to do. Return the original array.
return arr;
}
vtkDataArray *outv = NULL;
if (currCent == AVT_NODECENT)
{
......@@ -654,6 +674,12 @@ avtExpressionFilter::Recenter(vtkDataSet *ds, vtkDataArray *arr,
"variable that is not nodal.");
}
if (targCent != AVT_ZONECENT)
{
EXCEPTION2(ExpressionException, name, "Asked to re-center a nodal "
"variable to something other than zonal.");
}
ds2->GetPointData()->SetScalars(arr);
vtkPointDataToCellData *pd2cd = vtkPointDataToCellData::New();
......@@ -672,6 +698,12 @@ avtExpressionFilter::Recenter(vtkDataSet *ds, vtkDataArray *arr,
"variable that is not zonal.");
}
if (targCent != AVT_NODECENT)
{
EXCEPTION2(ExpressionException, name, "Asked to re-center a zonal "
"variable to something other than nodal.");
}
ds2->GetCellData()->SetScalars(arr);
vtkCellDataToPointData *cd2pd = vtkCellDataToPointData::New();
......
......@@ -108,6 +108,9 @@ class ExprPipelineState;
// Hank Childs, Sun Jan 13 13:46:15 PST 2008
// Add method for handling singleton constants.
//
// Sean Ahern, Wed Sep 10 12:21:41 EDT 2008
// Added a target centering.
//
// ****************************************************************************
class EXPRESSION_API avtExpressionFilter : virtual public
......@@ -125,8 +128,9 @@ class EXPRESSION_API avtExpressionFilter : virtual public
virtual void ProcessArguments(ArgsExpr *, ExprPipelineState *);
virtual int NumVariableArguments() = 0;
static vtkDataArray *Recenter(vtkDataSet*, vtkDataArray*,
avtCentering, std::string name);
static vtkDataArray *Recenter(vtkDataSet*, vtkDataArray*,
avtCentering, std::string name,
avtCentering targCent = AVT_UNKNOWN_CENT);
protected:
char *outputVariableName;
......
......@@ -49,6 +49,8 @@
#include <vtkFloatArray.h>
#include <vtkPointData.h>
#include <avtExprNode.h>
#include <DebugStream.h>
#include <ExpressionException.h>
......@@ -63,11 +65,15 @@
// Programmer: Hank Childs
// Creation: February 5, 2004
//
// Modifications:
// Sean Ahern, Wed Sep 10 12:15:05 EDT 2008
// Set the default recentering to "toggle".
//
// ****************************************************************************
avtRecenterExpression::avtRecenterExpression()
{
;
recenterMode = Toggle;
}
......@@ -89,6 +95,89 @@ avtRecenterExpression::~avtRecenterExpression()
}
// ****************************************************************************
// Method: avtRecenterExpression::ProcessArguments
//
// Purpose:
// Parses optional centering argument.
//
// Arguments:
// args Expression arguments
// state Expression pipeline state
//
// Programmer: Sean Ahern
// Creation: Wed Sep 10 12:04:12 EDT 2008
//
// ****************************************************************************
void
avtRecenterExpression::ProcessArguments(ArgsExpr *args,
ExprPipelineState *state)
{
// Get the argument list and number of arguments.
std::vector<ArgExpr*> *arguments = args->GetArgs();
int nargs = arguments->size();
// Check for a call with no arguments.
if (nargs == 0)
{
EXCEPTION2(ExpressionException, outputVariableName,
"recenter(): Incorrect syntax.\n"
" usage: recenter(varname, [centering])\n"
" The centering parameter is optional "
" and specifies nodal or zonal centering.\n"
" Valid values of centering: \"nodal\", \"zonal\", and \"toggle\".\n"
" The default centering is to toggle, that is, to convert "
" nodal to zonal or zonal to nodal.");
}
// Grab off the first argument.
ArgExpr *firstArg = (*arguments)[0];
avtExprNode *firstTree = dynamic_cast<avtExprNode*>(firstArg->GetExpr());
firstTree->CreateFilters(state);
// Check if we have a second optional argument that tells us how to
// center.
//
// Options:
// nodal: Recenter to nodes
// zonal: Recenter to zones
// toggle: Toggle centering
// Default: toggle
if (nargs > 1)
{
ArgExpr *secondArg = (*arguments)[1];
ExprParseTreeNode *secondTree = secondArg->GetExpr();
string secondType = secondTree->GetTypeName();
// Check for argument passed as string
if (secondType == "StringConst")
{
string sval = dynamic_cast<StringConstExpr*>(secondTree)->GetValue();
if (sval == "toggle")
recenterMode = Toggle;
else if (sval == "nodal")
recenterMode = Nodal;
else if (sval == "zonal")
recenterMode = Zonal;
else
{
EXCEPTION2(ExpressionException, outputVariableName,
"avtRecenterExpression: Invalid second argument.\n"
" Valid options are: \"nodal\", \"zonal\", or \"toggle\".");
}
}
else // Invalid argument type
{
EXCEPTION2(ExpressionException, outputVariableName,
"avtRecenterExpression: Invalid second argument type.\n"
"Must be a string with one of: \"nodal\", \"zonal\", \"toggle\".");
}
}
}
// ****************************************************************************
// Method: avtRecenterExpression::DeriveVariable
//
......@@ -115,19 +204,37 @@ avtRecenterExpression::DeriveVariable(vtkDataSet *in_ds)
"specify which variable to recenter");
}
debug5 << "avtRecenterExpression: recentering mode: ";
if (recenterMode == Toggle)
debug5 << "toggle" << endl;
if (recenterMode == Nodal)
debug5 << "nodal" << endl;
if (recenterMode == Zonal)
debug5 << "zonal" << endl;
vtkDataArray *cell_data = in_ds->GetCellData()->GetArray(activeVariable);
vtkDataArray *pt_data = in_ds->GetPointData()->GetArray(activeVariable);
vtkDataArray *rv = NULL;
if (cell_data != NULL)
avtCentering target;
switch(recenterMode)
{
rv = Recenter(in_ds, cell_data, AVT_ZONECENT, outputVariableName);
case Nodal:
target = AVT_NODECENT;
break;
case Toggle:
target = AVT_UNKNOWN_CENT;
break;
case Zonal:
target = AVT_ZONECENT;
break;
}
if (cell_data != NULL)
rv = Recenter(in_ds, cell_data, AVT_ZONECENT, outputVariableName, target);
else if (pt_data != NULL)
{
rv = Recenter(in_ds, pt_data, AVT_NODECENT, outputVariableName);
}
rv = Recenter(in_ds, pt_data, AVT_NODECENT, outputVariableName, target);
else
{
EXCEPTION2(ExpressionException, outputVariableName, "Was not able to locate variable to "
......@@ -211,5 +318,3 @@ avtRecenterExpression::GetVariableDimension(void)
int ncomp = atts.GetVariableDimension(varname);
return ncomp;
}
......@@ -63,6 +63,9 @@
//
// Hank Childs, Thu Oct 6 15:41:21 PDT 2005
// Added support for recentering vectors ['6637].
//
// Sean Ahern, Wed Sep 10 12:01:43 EDT 2008
// Added optional argument to specify explicit centering.
//
// ****************************************************************************
......@@ -74,11 +77,20 @@ class EXPRESSION_API avtRecenterExpression : public avtSingleInputExpressionFilt
virtual const char *GetType(void) { return "avtRecenterExpression"; };
virtual const char *GetDescription(void) {return "Recentering";};
virtual void ProcessArguments(ArgsExpr*, ExprPipelineState *);
typedef enum {
Toggle,
Nodal,
Zonal,
} RecenterType;
protected:
virtual vtkDataArray *DeriveVariable(vtkDataSet *);
virtual bool IsPointVariable(void);
virtual int GetVariableDimension(void);
RecenterType recenterMode;
};
......
......@@ -1120,6 +1120,9 @@ QvisExpressionsWindow::displayAllVarsChanged()
//
// Mark C. Miller, Mon Apr 14 15:41:21 PDT 2008
// Added support for '&' bitwise binary and operation
//
// Sean Ahern, Wed Sep 10 12:44:22 EDT 2008
// Added support for recenter with optional argument.
// ****************************************************************************
void
......@@ -1214,6 +1217,11 @@ QvisExpressionsWindow::insertFunction(int id)
definitionEdit->insert("(<var1>, <var2>, <var3>)");
doParens = false;
}
else if (str == "recenter")
{
definitionEdit->insert("(<var>, [\"nodal\", \"zonal\", \"toggle\"])");
doParens = false;
}
else if(str == "value_for_material")
{
definitionEdit->insert("(<var>, <material-name-or-number>)");
......
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