Commit f04cf077 authored by Andrew Bauer's avatar Andrew Bauer Committed by Kitware Robot

Merge topic 'gradient_optional_output'

26ee6f22 Making vtkGradientFilter more efficient.
Acked-by: Kitware Robot's avatarKitware Robot <kwrobot@kitware.com>
Acked-by: Kenneth Moreland's avatarKenneth Moreland <kmorel@sandia.gov>
Reviewed-by: default avatarDavid E DeMarle <dave.demarle@kitware.com>
Merge-request: !942
parents 98af77a1 26ee6f22
......@@ -185,7 +185,7 @@ namespace
//-----------------------------------------------------------------------------
// we assume that the gradients are correct and so we can compute the "real"
// vorticity from it
// Q criterion from it
int IsQCriterionCorrect(vtkDoubleArray* gradients, vtkDoubleArray* qCriterion)
{
if(gradients->GetNumberOfComponents() != 9 ||
......@@ -220,6 +220,34 @@ namespace
return 1;
}
//-----------------------------------------------------------------------------
// we assume that the gradients are correct and so we can compute the "real"
// divergence from it
int IsDivergenceCorrect(vtkDoubleArray* gradients, vtkDoubleArray* divergence)
{
if(gradients->GetNumberOfComponents() != 9 ||
divergence->GetNumberOfComponents() != 1)
{
vtkGenericWarningMacro("Bad number of components.");
return 0;
}
for(vtkIdType i=0;i<gradients->GetNumberOfTuples();i++)
{
double* g = gradients->GetTuple(i);
double div = divergence->GetValue(i);
double gValue = g[0]+g[4]+g[8];
if(!ArePointsWithinTolerance(div, gValue))
{
vtkGenericWarningMacro("Bad divergence value " << div << " " <<
gValue << " difference is " << (div-gValue));
return 0;
}
}
return 1;
}
//-----------------------------------------------------------------------------
int PerformTest(vtkDataSet* grid)
{
......@@ -288,6 +316,7 @@ namespace
pointVorticity->SetResultArrayName(resultName);
pointVorticity->SetComputeVorticity(1);
pointVorticity->SetComputeQCriterion(1);
pointVorticity->SetComputeDivergence(1);
pointVorticity->Update();
// cell stuff
......@@ -309,6 +338,14 @@ namespace
{
return EXIT_FAILURE;
}
vtkDoubleArray* divergencePointArray = vtkDoubleArray::SafeDownCast(
vtkDataSet::SafeDownCast(
pointVorticity->GetOutput())->GetPointData()->GetArray("Divergence"));
if(!IsDivergenceCorrect(gradPointArray, divergencePointArray))
{
return EXIT_FAILURE;
}
vtkDoubleArray* qCriterionPointArray = vtkDoubleArray::SafeDownCast(
vtkDataSet::SafeDownCast(
pointVorticity->GetOutput())->GetPointData()->GetArray("Q-criterion"));
......
This diff is collapsed.
......@@ -53,11 +53,19 @@ public:
virtual void SetInputScalars(int fieldAssociation, int fieldAttributeType);
// Description:
// Get/Set the name of the gradient array to create. If NULL (the
// Get/Set the name of the gradient array to create. This is only
// used if ComputeGradient is non-zero. If NULL (the
// default) then the output array will be named "Gradients".
vtkGetStringMacro(ResultArrayName);
vtkSetStringMacro(ResultArrayName);
// Description:
// Get/Set the name of the divergence array to create. This is only
// used if ComputeDivergence is non-zero. If NULL (the
// default) then the output array will be named "Divergence".
vtkGetStringMacro(DivergenceArrayName);
vtkSetStringMacro(DivergenceArrayName);
// Description:
// Get/Set the name of the vorticity array to create. This is only
// used if ComputeVorticity is non-zero. If NULL (the
......@@ -85,18 +93,37 @@ public:
vtkBooleanMacro(FasterApproximation, int);
// Description:
// Set the resultant array to be vorticity/curl of the input
// array. The input array must have 3 components.
// Add the gradient to the output field data. The name of the array
// will be ResultArrayName and will be the same type as the input
// array. The default is on.
vtkSetMacro(ComputeGradient, int);
vtkGetMacro(ComputeGradient, int);
vtkBooleanMacro(ComputeGradient, int);
// Description:
// Add divergence to the output field data. The name of the array
// will be DivergenceArrayName and will be the same type as the input
// array. The input array must have 3 components in order to
// compute this. The default is off.
vtkSetMacro(ComputeDivergence, int);
vtkGetMacro(ComputeDivergence, int);
vtkBooleanMacro(ComputeDivergence, int);
// Description:
// Add voriticity/curl to the output field data. The name of the array
// will be VorticityArrayName and will be the same type as the input
// array. The input array must have 3 components in order to
// compute this. The default is off.
vtkSetMacro(ComputeVorticity, int);
vtkGetMacro(ComputeVorticity, int);
vtkBooleanMacro(ComputeVorticity, int);
// Description:
// Add Q-criterion to the output field data. The name of the array
// will be "Q-Criterion" and will be the same type as the input
// will be QCriterionArrayName and will be the same type as the input
// array. The input array must have 3 components in order to
// compute this. Note that Q-citerion is a balance of the rate
// of vorticity and the rate of strain.
// of vorticity and the rate of strain. The default is off.
vtkSetMacro(ComputeQCriterion, int);
vtkGetMacro(ComputeQCriterion, int);
vtkBooleanMacro(ComputeQCriterion, int);
......@@ -117,7 +144,8 @@ protected:
// Returns non-zero if the operation was successful.
virtual int ComputeUnstructuredGridGradient(
vtkDataArray* Array, int fieldAssociation, vtkDataSet* input,
bool computeVorticity, bool computeQCriterion, vtkDataSet* output);
bool computeVorticity, bool computeQCriterion, bool computeDivergence,
vtkDataSet* output);
// Description:
// Compute the gradients for either a vtkImageData, vtkRectilinearGrid or
......@@ -125,13 +153,18 @@ protected:
// Returns non-zero if the operation was successful.
virtual int ComputeRegularGridGradient(
vtkDataArray* Array, int fieldAssociation, bool computeVorticity,
bool computeQCriterion, vtkDataSet* output);
bool computeQCriterion, bool computeDivergence, vtkDataSet* output);
// Description:
// If non-null then it contains the name of the outputted gradient array.
// By derault it is "Gradients".
char *ResultArrayName;
// Description:
// If non-null then it contains the name of the outputted divergence array.
// By derault it is "Divergence".
char *DivergenceArrayName;
// Description:
// If non-null then it contains the name of the outputted vorticity array.
// By derault it is "Vorticity".
......@@ -152,6 +185,17 @@ protected:
// vtkPolyData.
int FasterApproximation;
// Description:
// Flag to indicate that the gradient of the input vector is to
// be computed. By default ComputeDivergence is on.
int ComputeGradient;
// Description:
// Flag to indicate that the divergence of the input vector is to
// be computed. The input array to be processed must have
// 3 components. By default ComputeDivergence is off.
int ComputeDivergence;
// Description:
// Flag to indicate that the Q-criterion of the input vector is to
// be computed. The input array to be processed must have
......
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