Commit 20dca351 authored by hrchilds's avatar hrchilds

Change coordinate extrema finding expressions to support polar coordinates.


git-svn-id: http://visit.ilight.com/svn/visit/trunk/src@11839 18c085ea-50e0-402c-830e-de6fd14e8384
parent a46e3faa
......@@ -42,9 +42,15 @@
#include <avtCoordinateExtremaExpression.h>
#include <math.h>
#include <avtExprNode.h>
#include <vtkDataSet.h>
#include <vtkFloatArray.h>
#include <vtkRectilinearGrid.h>
#include <vtkIdList.h>
#include <ExpressionException.h>
// ****************************************************************************
......@@ -57,12 +63,17 @@
// Programmer: Hank Childs
// Creation: June 28, 2010
//
// Modifications:
//
// Hank Childs, Thu Jul 8 06:48:38 PDT 2010
// Add support for polar coordinates.
//
// ****************************************************************************
avtCoordinateExtremaExpression::avtCoordinateExtremaExpression()
{
getMinimum = true;
dim = 0;
coordinateType = CT_X;
}
......@@ -109,15 +120,154 @@ avtCoordinateExtremaExpression::DeriveVariable(vtkDataSet *in_ds)
vtkFloatArray *rv = vtkFloatArray::New();
rv->SetNumberOfComponents(1);
rv->SetNumberOfTuples(ncells);
for (int i = 0 ; i < ncells ; i++)
if (coordinateType == CT_X ||
coordinateType == CT_Y ||
coordinateType == CT_Z)
{
double bbox[6];
in_ds->GetCellBounds(i, bbox);
int idx = 2*dim + (getMinimum ? 0 : 1);
rv->SetTuple1(i, bbox[idx]);
int dim = 0;
if (coordinateType == CT_X)
dim = 0;
else if (coordinateType == CT_Y)
dim = 1;
else if (coordinateType == CT_Z)
dim = 2;
for (int i = 0 ; i < ncells ; i++)
{
double bbox[6];
in_ds->GetCellBounds(i, bbox);
int idx = 2*dim + (getMinimum ? 0 : 1);
rv->SetTuple1(i, bbox[idx]);
}
}
if (coordinateType == CT_Radius ||
coordinateType == CT_Theta ||
coordinateType == CT_Phi)
{
vtkIdList *ptIds = vtkIdList::New();
for (int i = 0 ; i < ncells ; i++)
{
double mostExtreme;
if (coordinateType == CT_Radius)
mostExtreme = (getMinimum ? 1e+40 : 0.);
else if (coordinateType == CT_Theta)
mostExtreme = (getMinimum ? 10 : 0.);
else if (coordinateType == CT_Phi)
mostExtreme = (getMinimum ? 10 : 0.);
in_ds->GetCellPoints(i, ptIds);
int nIds = ptIds->GetNumberOfIds();
for (int j = 0 ; j < nIds ; j++)
{
double pt[3];
in_ds->GetPoint(ptIds->GetId(j), pt);
double thisPointsValue;
if (coordinateType == CT_Radius)
thisPointsValue = sqrt(pt[0]*pt[0]+pt[1]*pt[1]+pt[2]*pt[2]);
else if (coordinateType == CT_Theta)
thisPointsValue = atan2(pt[1], pt[0]);
else if (coordinateType == CT_Phi)
{
double r = sqrt(pt[0]*pt[0]+pt[1]*pt[1]+pt[2]*pt[2]);
thisPointsValue = acos(pt[2]/r);
}
if (getMinimum)
mostExtreme = (thisPointsValue < mostExtreme ? thisPointsValue : mostExtreme);
else
mostExtreme = (thisPointsValue > mostExtreme ? thisPointsValue : mostExtreme);
}
rv->SetTuple1(i, mostExtreme);
}
ptIds->Delete();
}
return rv;
}
// ****************************************************************************
// Method: avtGradientExpression::ProcessArguments
//
// Purpose:
// Parses optional algorithm argument.
//
// Arguments:
// args Expression arguments
// state Expression pipeline state
//
// Programmer: Hank Childs
// Creation: July 8, 2010
//
// ****************************************************************************
void
avtCoordinateExtremaExpression::ProcessArguments(ArgsExpr *args,
ExprPipelineState *state)
{
// get the argument list and # of arguments
std::vector<ArgExpr*> *arguments = args->GetArgs();
int nargs = arguments->size();
// check for call with no args
if (nargs != 2)
{
EXCEPTION2(ExpressionException, outputVariableName,
"min_coords() Incorrect syntax.\n"
" usage: min_coords(meshname, axis)\n"
" The axis parameter "
"specifies which axis to find the minimum over.\n"
"Valid Options:\n"
" \"X\", "
" \"Y\", "
" \"Z\", "
" \"Radius\", "
" \"Theta\", "
" \"Phi\"\n");
}
// first argument is the var name, let it do its own magic
ArgExpr *first_arg = (*arguments)[0];
avtExprNode *first_tree = dynamic_cast<avtExprNode*>(first_arg->GetExpr());
first_tree->CreateFilters(state);
ArgExpr *second_arg= (*arguments)[1];
ExprParseTreeNode *second_tree= second_arg->GetExpr();
string second_type = second_tree->GetTypeName();
if ((second_type == "StringConst"))
{
string sval =
dynamic_cast<StringConstExpr*>(second_tree)->GetValue();
if (sval == "X")
coordinateType = CT_X;
else if (sval == "Y")
coordinateType = CT_Y;
else if (sval == "Z")
coordinateType = CT_Z;
else if (sval == "Radius")
coordinateType = CT_Radius;
else if (sval == "Theta")
coordinateType = CT_Theta;
else if (sval == "Phi")
coordinateType = CT_Phi;
else
{
EXCEPTION2(ExpressionException, outputVariableName,
"avtCoordinateExtremaExpression: Invalid second argument.\n"
" Valid options are: \"X\", \"Y\", \"Z\", \"Radius\", \"Theta\", "
" \"Phi\".");
}
}
else // invalid arg type
{
EXCEPTION2(ExpressionException, outputVariableName,
"avtCoordinateExtremaExpression: Expects a string second "
"argument.\n"
" Valid options are: \"X\", \"Y\", \"Z\", \"Radius\", \"Theta\", "
"\"Phi\".");
}
}
......@@ -46,6 +46,17 @@
#include <avtSingleInputExpressionFilter.h>
typedef enum
{
CT_X = 0,
CT_Y,
CT_Z,
CT_Radius,
CT_Theta,
CT_Phi,
} CoordinateType;
// ****************************************************************************
// Class: avtCoordinateExtremaExpression
//
......@@ -56,6 +67,11 @@
// Programmer: Hank Childs
// Creation: June 28, 2010
//
// Modifications:
//
// Hank Childs, Thu Jul 8 06:46:53 PDT 2010
// Add support for polar coordinates; add parsing of arguments.
//
// ****************************************************************************
class EXPRESSION_API avtCoordinateExtremaExpression
......@@ -70,12 +86,13 @@ class EXPRESSION_API avtCoordinateExtremaExpression
virtual const char *GetDescription(void)
{ return "Calculating coordinate extrema"; };
virtual void ProcessArguments(ArgsExpr*, ExprPipelineState *);
void SetGetMinimum(bool gm) { getMinimum = gm; };
void SetDimension(int d) { dim = d; };
protected:
bool getMinimum;
int dim;
CoordinateType coordinateType;
virtual vtkDataArray *DeriveVariable(vtkDataSet *);
virtual int GetVariableDimension() { return 1; }
......
......@@ -66,6 +66,9 @@
// Hank Childs, Mon Jun 28 06:43:20 PDT 2010
// Add avtCoordinateExtrema.
//
// Hank Childs, Thu Jul 8 08:11:06 PDT 2010
// Change coordinate extrema to include polar coordinates.
//
// ****************************************************************************
avtExpressionFilter *
......@@ -162,46 +165,16 @@ avtFunctionExpr::CreateMeshFilters(const string &functionName) const
{
return new avtZoneTypeExpression();
}
else if (functionName == "minx_coord")
{
avtCoordinateExtremaExpression *ce = new avtCoordinateExtremaExpression;
ce->SetGetMinimum(true);
ce->SetDimension(0);
return ce;
}
else if (functionName == "maxx_coord")
{
avtCoordinateExtremaExpression *ce = new avtCoordinateExtremaExpression;
ce->SetGetMinimum(false);
ce->SetDimension(0);
return ce;
}
else if (functionName == "miny_coord")
{
avtCoordinateExtremaExpression *ce = new avtCoordinateExtremaExpression;
ce->SetGetMinimum(true);
ce->SetDimension(1);
return ce;
}
else if (functionName == "maxy_coord")
{
avtCoordinateExtremaExpression *ce = new avtCoordinateExtremaExpression;
ce->SetGetMinimum(false);
ce->SetDimension(1);
return ce;
}
else if (functionName == "minz_coord")
else if (functionName == "min_coord")
{
avtCoordinateExtremaExpression *ce = new avtCoordinateExtremaExpression;
ce->SetGetMinimum(true);
ce->SetDimension(2);
return ce;
}
else if (functionName == "maxz_coord")
else if (functionName == "max_coord")
{
avtCoordinateExtremaExpression *ce = new avtCoordinateExtremaExpression;
ce->SetGetMinimum(false);
ce->SetDimension(1);
return ce;
}
......
......@@ -165,6 +165,11 @@
// Cyrus Harrison, Wed Jul 7 09:34:00 PDT 2010
// Added 'zonal_constant' and 'nodal_constant'
//
// Hank Childs, Thu Jul 8 08:12:26 PDT 2010
// Retire [min|max][x|y|z] coord, replaced with min_coord and max_coord.
// Adding polar coordinates and I really didn't think there should be
// 12 expressions for this minor functionality.
//
// ****************************************************************************
struct ExprNameList
......@@ -320,12 +325,8 @@ const char *expr_mesh[] = {
"external_node",
"global_nodeid",
"global_zoneid",
"maxx_coord",
"maxy_coord",
"maxz_coord",
"minx_coord",
"miny_coord",
"minz_coord",
"max_coord",
"min_coord",
"nodeid",
"polar",
"polar_radius",
......@@ -1566,6 +1567,9 @@ QvisExpressionsWindow::UpdateStandardExpressionEditor(const QString &expr_def)
// Dave Pugmire, Fri Jul 2 14:22:34 EDT 2010
// Added 'zonal_constant' & 'nodal_constant'.
//
// Hank Childs, Thu Jul 8 08:14:23 PDT 2010
// Added min_coord and max_coord.
//
// ****************************************************************************
QString
......@@ -1668,6 +1672,11 @@ QvisExpressionsWindow::ExpandFunction(const QString &func_name)
res += QString("(<var>, sX, sY, sZ)");
doParens = false;
}
else if (func_name == "min_coord" || func_name == "max_coord")
{
res += QString("(<mesh>, [\"X\", \"Y\", \"Z\", \"Radius\", \"Theta\", \"Phi\"])");
doParens = false;
}
else if(func_name == "value_for_material")
{
stdDefinitionEdit->insertPlainText("(<var>, <material-name-or-number>)");
......
......@@ -53,7 +53,7 @@ enhancements and bug-fixes that were added to this release.</p>
<ul>
<li>The <i>Volume</i> plot now displays a histogram in the transfer function editor when doing RayCasting, matching the behavior for the other rendering types.</li>
<li>The <i>Volume</i> plot is now more efficient in memory and execution time
when doing a ray casting with logarithmic scale with a minimum set.</li>
when doing a ray casting with logarithmic scale with a minimum value set.</li>
</ul>
<a name="Operator_changes"></a>
......@@ -64,6 +64,8 @@ enhancements and bug-fixes that were added to this release.</p>
<a name="Expression_changes"></a>
<p><b><font size="4">Changes to VisIt's expression language in version 2.1</font></b></p>
<ul>
<li>New expressions, min_coord and max_coord, can find the smallest or
largest coordinate value (X, Y, Z, radius, theta, phi) within a cell.</li>
</ul>
<a name="Query_changes"></a>
......
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