Commit 98a23692 authored by Ken Martin's avatar Ken Martin Committed by David E. DeMarle

fix issues with the array calc and string arrays

The old code did not correctly handle DataObjects
that had string arrays in them. It would cause
the index to be off after the string array. So it
might look liek it worked but the data would
be incorrect. Very bad. This fixes PV issue
paraview/paraview#12967

(cherry picked from commit 81f882c4)
parent f2510db3
......@@ -2448,6 +2448,22 @@ void vtkFunctionParser::UpdateNeededVariables()
}
}
//-----------------------------------------------------------------------------
int vtkFunctionParser::GetScalarVariableIndex(const char* inVariableName)
{
char* variableName = this->RemoveSpacesFrom(inVariableName);
for (int i = 0; i < static_cast<int>(this->ScalarVariableNames.size()); ++i)
{
if (this->ScalarVariableNames[i] == variableName)
{
delete [] variableName;
return i;
}
}
delete [] variableName;
return -1;
}
//-----------------------------------------------------------------------------
bool vtkFunctionParser::GetScalarVariableNeeded(int i)
{
......@@ -2465,9 +2481,9 @@ bool vtkFunctionParser::GetScalarVariableNeeded(const char* inVariableName)
std::vector<std::string>::const_iterator iter = std::find(
this->ScalarVariableNames.begin(), this->ScalarVariableNames.end(),
std::string(variableName));
delete [] variableName;
if (iter != this->ScalarVariableNames.end())
{
delete [] variableName;
return this->GetScalarVariableNeeded(
static_cast<int>(iter - this->ScalarVariableNames.begin()));
}
......@@ -2475,10 +2491,27 @@ bool vtkFunctionParser::GetScalarVariableNeeded(const char* inVariableName)
{
vtkErrorMacro("GetScalarVariableNeeded: scalar variable name " << variableName
<< " does not exist");
delete [] variableName;
return false;
}
}
//-----------------------------------------------------------------------------
int vtkFunctionParser::GetVectorVariableIndex(const char* inVariableName)
{
char* variableName = this->RemoveSpacesFrom(inVariableName);
for (int i = 0; i < static_cast<int>(this->VectorVariableNames.size()); ++i)
{
if (this->VectorVariableNames[i] == variableName)
{
delete [] variableName;
return i;
}
}
delete [] variableName;
return -1;
}
//-----------------------------------------------------------------------------
bool vtkFunctionParser::GetVectorVariableNeeded(int i)
{
......
......@@ -234,12 +234,22 @@ public:
int GetNumberOfScalarVariables()
{ return static_cast<int>(this->ScalarVariableNames.size()); }
/**
* Get scalar variable index or -1 if not found
*/
int GetScalarVariableIndex(const char *name);
/**
* Get the number of vector variables.
*/
int GetNumberOfVectorVariables()
{ return static_cast<int>(this->VectorVariableNames.size()); }
/**
* Get scalar variable index or -1 if not found
*/
int GetVectorVariableIndex(const char *name);
/**
* Get the ith scalar variable name.
*/
......
......@@ -427,18 +427,34 @@ int vtkArrayCalculator::RequestData(
// Save array pointers to avoid looking them up for each tuple.
std::vector<vtkDataArray*> scalarArrays(this->NumberOfScalarArrays);
std::vector<vtkDataArray*> vectorArrays(this->NumberOfVectorArrays);
std::vector<int> scalarArrayIndicies(this->NumberOfScalarArrays);
std::vector<int> vectorArrayIndicies(this->NumberOfVectorArrays);
for (int cc=0; cc < this->NumberOfScalarArrays; cc++)
{
if (this->FunctionParser->GetScalarVariableNeeded(cc))
int idx = this->FunctionParser->GetScalarVariableIndex(
this->ScalarArrayNames[cc]);
if (idx >= 0)
{
scalarArrays[cc] = inFD->GetArray(this->ScalarArrayNames[cc]);
if (this->FunctionParser->GetScalarVariableNeeded(idx))
{
scalarArrays[cc] = inFD->GetArray(this->ScalarArrayNames[cc]);
scalarArrayIndicies[cc] = idx;
}
}
}
for (int cc=0; cc < this->NumberOfVectorArrays; cc++)
{
if (this->FunctionParser->GetVectorVariableNeeded(cc))
int idx = this->FunctionParser->GetVectorVariableIndex(
this->VectorArrayNames[cc]);
if (idx >= 0)
{
vectorArrays[cc] = inFD->GetArray(this->VectorArrayNames[cc]);
if (this->FunctionParser->GetVectorVariableNeeded(idx))
{
vectorArrays[cc] = inFD->GetArray(this->VectorArrayNames[cc]);
vectorArrayIndicies[cc] = idx;
}
}
}
......@@ -449,16 +465,16 @@ int vtkArrayCalculator::RequestData(
if ((currentArray = scalarArrays[j]))
{
this->FunctionParser->
SetScalarVariableValue(
j, currentArray->GetComponent(i, this->SelectedScalarComponents[j]));
SetScalarVariableValue(scalarArrayIndicies[j],
currentArray->GetComponent(i, this->SelectedScalarComponents[j]));
}
}
for (j = 0; j < this->NumberOfVectorArrays; j++)
{
if ((currentArray = vectorArrays[j]))
{
this->FunctionParser->SetVectorVariableValue(
j, currentArray->GetComponent(i, this->SelectedVectorComponents[j][0]),
this->FunctionParser->SetVectorVariableValue(vectorArrayIndicies[j],
currentArray->GetComponent(i, this->SelectedVectorComponents[j][0]),
currentArray->GetComponent(
i, this->SelectedVectorComponents[j][1]),
currentArray->GetComponent(i, this->SelectedVectorComponents[j][2]));
......
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