Use of Fielddata in the VTKArrayCalculator
This issue was created automatically from an original Mantis Issue. Further discussion may take place here.
I came with this solution to use field data in the vtkArrayCalculator:
the idea is very simple:
we retrieve the field data and we put it into the inFieldData variable, Then If a field is not found in the point/cell data, then we search in the fielddata.
diff --git a/Graphics/vtkArrayCalculator.cxx b/Graphics/vtkArrayCalculator.cxx index a2db7ae..d7c53eb 100644 --- a/Graphics/vtkArrayCalculator.cxx +++ b/Graphics/vtkArrayCalculator.cxx @@ -225,6 +225,7 @@ int vtkArrayCalculator::RequestData( double scalarResult[1]; vtkDataArray* resultArray = 0; vtkPoints* resultPoints = 0;
-
vtkFieldData* inFieldData = 0;
this->FunctionParser->SetReplaceInvalidValues(this->ReplaceInvalidValues); this->FunctionParser->SetReplacementValue(this->ReplacementValue); @@ -252,6 +253,7 @@ int vtkArrayCalculator::RequestData( attributeDataType = 1; numTuples = dsInput->GetNumberOfCells(); }
-
inFieldData = dsInput->GetFieldData();
} else if (graphInput) { @@ -270,6 +272,7 @@ int vtkArrayCalculator::RequestData( attributeDataType = 1; numTuples = graphInput->GetNumberOfEdges(); }
-
inFieldData = graphInput->GetFieldData();
}
if (numTuples < 1) @@ -301,8 +304,30 @@ int vtkArrayCalculator::RequestData( } else {
-
vtkErrorMacro("Invalid array name: " << this->ScalarArrayNames[i]);
-
return 1;
-
// now we search in the fielddata for the array
-
currentArray = inFieldData->GetArray(this->ScalarArrayNames[i]);
-
if (currentArray)
-
{
-
if (currentArray->GetNumberOfComponents() >
-
this->SelectedScalarComponents[i])
-
{
-
this->FunctionParser->
-
SetScalarVariableValue(
-
this->ScalarVariableNames[i],
-
currentArray->GetComponent(0, this->SelectedScalarComponents[i]));
-
}
-
else
-
{
-
vtkErrorMacro("Array " << this->ScalarArrayNames[i]
-
<< " does not contain the selected component.");
-
return 1;
-
}
-
}
-
else
-
{
-
vtkErrorMacro("Invalid array name: " << this->ScalarArrayNames[i]);
-
return 1;
-
} }
@@ -334,8 +359,36 @@ int vtkArrayCalculator::RequestData( } else {
-
vtkErrorMacro("Invalid array name: " << this->VectorArrayNames[i]);
-
return 1;
-
// now we search in the fielddata for the array
-
currentArray = inFieldData->GetArray(this->VectorArrayNames[i]);
-
if (currentArray)
-
{
-
if ((currentArray->GetNumberOfComponents() >
-
this->SelectedVectorComponents[i][0]) &&
-
(currentArray->GetNumberOfComponents() >
-
this->SelectedVectorComponents[i][1]) &&
-
(currentArray->GetNumberOfComponents() >
-
this->SelectedVectorComponents[i][2]))
-
{
-
this->FunctionParser->
-
SetVectorVariableValue(
-
this->VectorVariableNames[i],
-
currentArray->GetComponent(0, this->SelectedVectorComponents[i][0]),
-
currentArray->GetComponent(0, this->SelectedVectorComponents[i][1]),
-
currentArray->GetComponent(0, this->SelectedVectorComponents[i][2]));
-
}
-
else
-
{
-
vtkErrorMacro("Array " << this->VectorArrayNames[i]
-
<< " does not contain the selected component.");
-
return 1;
-
}
-
}
-
else
-
{
-
vtkErrorMacro("Invalid array name: " << this->VectorArrayNames[i]);
-
return 1;
-
} }
@@ -448,19 +501,21 @@ int vtkArrayCalculator::RequestData( for (j = 0; j < this->NumberOfScalarArrays; j++) { currentArray = inFD->GetArray(this->ScalarArrayNames[j]);
-
this->FunctionParser->
-
SetScalarVariableValue(
-
j, currentArray->GetComponent(i, this->SelectedScalarComponents[j]));
-
if (currentArray)
-
this->FunctionParser->
-
SetScalarVariableValue(
-
j, currentArray->GetComponent(i, this->SelectedScalarComponents[j])); }
-
this->FunctionParser->
-
SetVectorVariableValue(
-
j, currentArray->GetComponent(i, this->SelectedVectorComponents[j][0]),
-
currentArray->GetComponent(
-
i, this->SelectedVectorComponents[j][1]),
-
currentArray->GetComponent(i, this->SelectedVectorComponents[j][2]));
-
if (currentArray)
-
this->FunctionParser->
-
SetVectorVariableValue(
-
j, currentArray->GetComponent(i, this->SelectedVectorComponents[j][0]),
-
currentArray->GetComponent(
-
i, this->SelectedVectorComponents[j][1]),
-
currentArray->GetComponent(i, this->SelectedVectorComponents[j][2])); }