Commit 1ac01a6e authored by pugmire's avatar pugmire

Add resample expression.



git-svn-id: http://visit.ilight.com/svn/visit/trunk/src@11810 18c085ea-50e0-402c-830e-de6fd14e8384
parent 7e21177f
......@@ -146,6 +146,7 @@ General/avtRandomExpression.C
General/avtRecenterExpression.C
General/avtRectilinearLaplacianExpression.C
General/avtRelativeDifferenceExpression.C
General/avtResampleExpression.C
General/avtResradExpression.C
General/avtSpecMFExpression.C
General/avtSurfaceNormalExpression.C
......
/*****************************************************************************
*
* Copyright (c) 2000 - 2010, 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.
*
*****************************************************************************/
// ************************************************************************* //
// avtResampleExpression.C //
// ************************************************************************* //
#include <avtResampleExpression.h>
#include <math.h>
#include <vtkCellData.h>
#include <vtkDataSet.h>
#include <vtkFloatArray.h>
#include <vtkPointData.h>
#include <avtResampleFilter.h>
#include <InternalResampleAttributes.h>
#include <avtSourceFromAVTDataset.h>
#include <avtExprNode.h>
#include <avtDatasetExaminer.h>
#include <DebugStream.h>
#include <ExpressionException.h>
// ****************************************************************************
// Method: avtResampleExpression constructor
//
// Purpose:
// Defines the constructor. Note: this should not be inlined in the
// header because it causes problems for certain compilers.
//
// Programmer: Dave Pugmire
// Creation: Fri Jul 2 14:10:45 EDT 2010
//
// Modifications:
//
// ****************************************************************************
avtResampleExpression::avtResampleExpression()
{
samplesX = 1;
samplesY = 1;
samplesZ = 1;
}
// ****************************************************************************
// Method: avtResampleExpression destructor
//
// Purpose:
// Defines the destructor. Note: this should not be inlined in the header
// because it causes problems for certain compilers.
//
// Programmer: Dave Pugmire
// Creation: Fri Jul 2 14:10:45 EDT 2010
//
// ****************************************************************************
avtResampleExpression::~avtResampleExpression()
{
}
// ****************************************************************************
// Method: avtResampleExpression::ProcessArguments
//
// Purpose:
// Parses optional centering argument.
//
// Arguments:
// args Expression arguments
// state Expression pipeline state
//
// Programmer: Dave Pugmire
// Creation: Fri Jul 2 14:10:45 EDT 2010
//
// ****************************************************************************
void
avtResampleExpression::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 != 4)
{
EXCEPTION2(ExpressionException, outputVariableName,
"resample(): Incorrect syntax.\n"
" usage: resample(varname, samplesX, samplesY, samplesZ)\n");
}
//Variable.
ArgExpr *firstArg = (*arguments)[0];
avtExprNode *firstTree = dynamic_cast<avtExprNode*>(firstArg->GetExpr());
firstTree->CreateFilters(state);
for (int i = 0; i < 3; i++)
{
ArgExpr *samp = (*arguments)[i+1];
ExprParseTreeNode *sampTree = samp->GetExpr();
string secondType = sampTree->GetTypeName();
if (secondType == "IntegerConst")
{
int val = dynamic_cast<IntegerConstExpr*>(sampTree)->GetValue();
if (val <= 0)
EXCEPTION2(ExpressionException, outputVariableName,
"avtResampleExpression: Invalid resample argument.\n"
"Must be > 0.");
if (i == 0)
samplesX = val;
else if (i == 1)
samplesY = val;
else
samplesZ = val;
}
}
}
// ****************************************************************************
// Method: avtResampleExpression::Execute
//
// Purpose:
// Execute
//
//
// Programmer: Dave Pugmire
// Creation: Fri Jul 2 14:10:45 EDT 2010
//
// ****************************************************************************
void
avtResampleExpression::Execute()
{
InternalResampleAttributes resampleAtts;
resampleAtts.SetUseBounds(false);
resampleAtts.SetDistributedResample(true);
resampleAtts.SetWidth(samplesX);
resampleAtts.SetHeight(samplesY);
resampleAtts.SetDepth(samplesZ);
avtResampleFilter *resample = new avtResampleFilter(&resampleAtts);
resample->SetInput(GetInput());
avtContract_p spec = GetInput()->GetOriginatingSource()->GetGeneralContract();
avtDataObject_p dob = resample->GetOutput();
dob->Update(spec);
//Need to rename the output variable.
avtDataTree_p tree = resample->GetTypedOutput()->GetDataTree();
int nLeaves;
vtkDataSet **leaves = tree->GetAllLeaves(nLeaves);
string inputVarname = GetInput()->GetInfo().GetAttributes().GetVariableName();
string outputVarname = GetOutputVariableName();
avtDataTree_p newTree = NULL;
for (int i = 0; i < nLeaves; i++)
{
vtkDataSet *ds = leaves[i];
vtkFloatArray *newVar = vtkFloatArray::New();
vtkFloatArray *oldVar = (vtkFloatArray *)ds->GetPointData()->GetArray(inputVarname.c_str());
newVar->SetNumberOfComponents(oldVar->GetNumberOfComponents());
newVar->SetNumberOfTuples(oldVar->GetNumberOfTuples());
for (int j = 0; j < newVar->GetNumberOfTuples(); j++)
newVar->SetTuple(j, oldVar->GetTuple(j));
newVar->SetName(outputVarname.c_str());
ds->GetPointData()->RemoveArray(inputVarname.c_str());
ds->GetPointData()->AddArray(newVar);
newVar->Delete();
if (i == 0)
newTree = new avtDataTree(ds, i);
else
newTree->Merge(new avtDataTree(ds, i));
}
delete [] leaves;
if (*newTree != NULL)
SetOutputDataTree(newTree);
}
// ****************************************************************************
// Method: avtResampleExpression::IsPointVariable
//
// Purpose:
// Switch the centering of the point variable.
//
// Programmer: Dave Pugmire
// Creation: Fri Jul 2 14:10:45 EDT 2010
//
// Modifications:
//
//
// ****************************************************************************
bool
avtResampleExpression::IsPointVariable(void)
{
bool isPoint = true;
bool foundOne = false;
avtDataAttributes &atts = GetInput()->GetInfo().GetAttributes();
if (activeVariable != NULL)
{
if (atts.ValidVariable(activeVariable))
{
isPoint = (atts.GetCentering(activeVariable) != AVT_ZONECENT);
foundOne = true;
}
}
if (!foundOne)
if (atts.ValidActiveVariable())
isPoint = (atts.GetCentering() != AVT_ZONECENT);
return (!isPoint);
}
// ****************************************************************************
// Method: avtResampleExpression::GetVariableDimension
//
// Purpose:
// Determines what the variable dimension of the output is.
//
// Programmer: Dave Pugmire
// Creation: Fri Jul 2 14:10:45 EDT 2010
//
// ****************************************************************************
int
avtResampleExpression::GetVariableDimension(void)
{
if (*(GetInput()) == NULL)
return avtExpressionFilter::GetVariableDimension();
//
// The base class will set the variable of interest to be the
// 'activeVariable'. This is a by-product of how the base class sets its
// input. If that method should change (SetActiveVariable), this
// technique for inferring the variable name may stop working.
//
const char *varname = activeVariable;
if (varname == NULL)
return avtExpressionFilter::GetVariableDimension();
avtDataAttributes &atts = GetInput()->GetInfo().GetAttributes();
if (! atts.ValidVariable(varname))
return avtExpressionFilter::GetVariableDimension();
int ncomp = atts.GetVariableDimension(varname);
return ncomp;
}
/*****************************************************************************
*
* Copyright (c) 2000 - 2010, 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.
*
*****************************************************************************/
// ************************************************************************* //
// avtResampleExpression.h //
// ************************************************************************* //
#ifndef AVT_RESAMPLE_EXPRESSION_H
#define AVT_RESAMPLE_EXPRESSION_H
#include <avtSingleInputExpressionFilter.h>
#include <string>
// ****************************************************************************
// Class: avtResampleExpression
//
// Purpose:
// Resamples a variable.
//
// Programmer: Dave Pugmire
// Creation: Fri Jul 2 14:10:45 EDT 2010
//
// Modifications:
//
//
// ****************************************************************************
class EXPRESSION_API avtResampleExpression : public avtExpressionFilter
{
public:
avtResampleExpression();
virtual ~avtResampleExpression();
virtual const char *GetType(void) { return "avtResampleExpression"; };
virtual const char *GetDescription(void) {return "Resampling";};
virtual void ProcessArguments(ArgsExpr*, ExprPipelineState *);
protected:
virtual void Execute(void);
virtual int NumVariableArguments(){ return 0; }
virtual int GetVariableDimension(void);
virtual bool CanHandleSingletonConstants(void) {return true;}
virtual bool IsPointVariable(void);
int samplesX, samplesY, samplesZ;
};
#endif
......@@ -83,6 +83,7 @@
#include <avtRecenterExpression.h>
#include <avtRectilinearLaplacianExpression.h>
#include <avtRelativeDifferenceExpression.h>
#include <avtResampleExpression.h>
#include <avtResradExpression.h>
#include <avtTimeExpression.h>
#include <avtUnaryMinusExpression.h>
......@@ -459,6 +460,9 @@ avtVectorExpr::CreateFilters(ExprPipelineState *state)
// Cyrus Harrison, Tue Feb 2 14:54:25 PST 2010
// Added the "python" expression.
//
// Dave Pugmire, Fri Jul 2 14:22:34 EDT 2010
// Added the "resample" expression.
//
// ****************************************************************************
avtExpressionFilter *
......@@ -498,6 +502,8 @@ avtFunctionExpr::CreateFilters(string functionName)
return new avtLocalizedCompactnessExpression();
if (functionName == "recenter")
return new avtRecenterExpression();
if (functionName == "resample")
return new avtResampleExpression();
if (functionName == "displacement")
return new avtDisplacementExpression();
if (functionName == "degree")
......
......@@ -129,6 +129,9 @@ class avtWebpage;
// Hank Childs, Sun Feb 15 10:12:22 PST 2009
// Add friend status for avtTimeIteratorExpression.
//
// Dave Pugmire, Fri Jul 2 14:22:34 EDT 2010
// Add friend status for avtResampleExpression.
//
// ****************************************************************************
class PIPELINE_API avtDataset : public avtDataObject
......@@ -145,6 +148,7 @@ class PIPELINE_API avtDataset : public avtDataObject
friend class avtExecuteThenTimeLoopFilter;
friend class avtNamedSelectionManager;
friend class avtTimeIteratorExpression;
friend class avtResampleExpression;
public:
avtDataset(avtDataObjectSource *);
......
......@@ -159,6 +159,9 @@
// Hank Childs, Mon Jun 28 06:49:16 PDT 2010
// Add [min|max][x|y|z]_coord.
//
// Dave Pugmire, Fri Jul 2 14:22:34 EDT 2010
// Add resample expression.
//
// ****************************************************************************
struct ExprNameList
......@@ -348,6 +351,7 @@ const char *expr_misc[] = {
"mean_curvature",
"point_constant",
"recenter",
"resample",
"resrad",
"surface_normal",
" point_surface_normal",
......@@ -1546,6 +1550,9 @@ QvisExpressionsWindow::UpdateStandardExpressionEditor(const QString &expr_def)
//
// Modifications:
//
// Dave Pugmire, Fri Jul 2 14:22:34 EDT 2010
// Add resample expression.
//
// ****************************************************************************
QString
......@@ -1643,6 +1650,11 @@ QvisExpressionsWindow::ExpandFunction(const QString &func_name)
res += QString("(<var>, [\"nodal\", \"zonal\", \"toggle\"])");
doParens = false;
}
else if (func_name == "resample")
{
res += QString("(<var>, sX, sY, sZ)");
doParens = false;
}
else if(func_name == "value_for_material")
{
stdDefinitionEdit->insertPlainText("(<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