(0027566)
|
Felipe Bordeu
|
2011-10-12 04:51
(edited on: 2011-12-08 08:16) |
|
A made this changes to add field data to the array calculator.
To make this changes to work some changes in VTK are needed:
please see http://paraview.org/Bug/view.php?id=12778 [^]
I tested the solution for scalar fielddata only but I think it is ready for vector also:
Felipe
diff --git a/ParaViewCore/VTKExtensions/vtkPVArrayCalculator.cxx b/ParaViewCore/VTKExtensions/vtkPVArrayCalculator.cxx
index 240289c..6332008 100644
--- a/ParaViewCore/VTKExtensions/vtkPVArrayCalculator.cxx
+++ b/ParaViewCore/VTKExtensions/vtkPVArrayCalculator.cxx
@@ -39,7 +39,7 @@ vtkPVArrayCalculator::~vtkPVArrayCalculator()
// ----------------------------------------------------------------------------
void vtkPVArrayCalculator::UpdateArrayAndVariableNames
- ( vtkDataObject * vtkNotUsed(theInputObj), vtkDataSetAttributes * inDataAttrs )
+ ( vtkDataObject * vtkNotUsed(theInputObj), vtkDataSetAttributes * inDataAttrs, vtkFieldData *inDataAttrsGlobal )
{
static char stringSufix[3][3] = { "_X", "_Y", "_Z" };
unsigned long mtime = this->GetMTime();
@@ -98,6 +98,50 @@ void vtkPVArrayCalculator::UpdateArrayAndVariableNames
}
}
+
+ // add non-coordinate scalar and vector variables for field arrays
+ numberArays = inDataAttrsGlobal->GetNumberOfArrays(); // the input
+ for (int j = 0; j < numberArays; j ++ )
+ {
+ vtkAbstractArray* array = inDataAttrsGlobal->GetAbstractArray(j);
+ const char* array_name = array->GetName();
+ int numberComps = array->GetNumberOfComponents();
+
+ if ( numberComps == 1 )
+ {
+ this->AddScalarVariable( array_name, array_name, 0 );
+ }
+ else
+ {
+ for (int i = 0; i < numberComps; i ++ )
+ {
+ if (i < 3)
+ {
+ vtksys_ios::ostringstream var_name;
+ var_name << array_name << stringSufix[i];
+ this->AddScalarVariable(var_name.str().c_str(), array_name, i );
+ }
+ vtksys_ios::ostringstream var_name2;
+ var_name2 << array_name << "_";
+ if (array->GetComponentName(i))
+ {
+ var_name2 << array->GetComponentName(i);
+ }
+ else
+ {
+ var_name2 << i;
+ }
+ this->AddScalarVariable(var_name2.str().c_str(), array_name, i );
+ }
+
+ if ( numberComps == 3 )
+ {
+ this->AddVectorArrayName(array_name, 0, 1, 2 );
+ }
+ }
+ }
+ // end add field arrays
+
assert(this->GetMTime() == mtime &&
"post: mtime cannot be changed in RequestData()");
static_cast<void>(mtime); // added so compiler won't complain im release mode.
@@ -115,6 +159,7 @@ int vtkPVArrayCalculator::RequestData
vtkGraph * graphInput = vtkGraph::SafeDownCast( input );
vtkDataSet * dsInput = vtkDataSet::SafeDownCast( input );
vtkDataSetAttributes * dataAttrs = NULL;
+ vtkFieldData * dataAttrsGlobal = NULL;
if ( dsInput )
{
@@ -129,6 +174,7 @@ int vtkPVArrayCalculator::RequestData
dataAttrs = dsInput->GetCellData();
numTuples = dsInput->GetNumberOfCells();
}
+ dataAttrsGlobal = dsInput->GetFieldData();
}
else
if ( graphInput )
@@ -144,6 +190,7 @@ int vtkPVArrayCalculator::RequestData
dataAttrs = graphInput->GetEdgeData();
numTuples = graphInput->GetNumberOfEdges();
}
+ dataAttrsGlobal = graphInput->GetFieldData();
}
if ( numTuples > 0 )
@@ -153,12 +200,13 @@ int vtkPVArrayCalculator::RequestData
// the scenarios where the user modifies the name of a calculator whose out-
// put is the input of a (some) subsequent calculator(s) or the user changes
// the input of a downstream calculator.
- this->UpdateArrayAndVariableNames( input, dataAttrs );
+ this->UpdateArrayAndVariableNames( input, dataAttrs, dataAttrsGlobal );
}
input = NULL;
dsInput = NULL;
dataAttrs = NULL;
+ dataAttrsGlobal = NULL;
graphInput = NULL;
return this->Superclass::RequestData( request, inputVector, outputVector );
diff --git a/ParaViewCore/VTKExtensions/vtkPVArrayCalculator.h b/ParaViewCore/VTKExtensions/vtkPVArrayCalculator.h
index 669c4f5..9ed980b 100644
--- a/ParaViewCore/VTKExtensions/vtkPVArrayCalculator.h
+++ b/ParaViewCore/VTKExtensions/vtkPVArrayCalculator.h
@@ -34,6 +34,7 @@
class vtkDataObject;
class vtkDataSetAttributes;
+class vtkFieldData;
class VTK_EXPORT vtkPVArrayCalculator : public vtkArrayCalculator
{
@@ -59,7 +60,8 @@ protected:
// to the attributes of the input dataset. This function should be called by
// RequestData() only.
void UpdateArrayAndVariableNames( vtkDataObject * theInputObj,
- vtkDataSetAttributes * inDataAttrs );
+ vtkDataSetAttributes * inDataAttrs,
+ vtkFieldData * inDataAttrsGlobal );
private:
vtkPVArrayCalculator( const vtkPVArrayCalculator & ); // Not implemented.
void operator = ( const vtkPVArrayCalculator & ); // Not implemented.
diff --git a/Qt/Components/pqCalculatorPanel.cxx b/Qt/Components/pqCalculatorPanel.cxx
index 37e38bd..3558ab9 100644
--- a/Qt/Components/pqCalculatorPanel.cxx
+++ b/Qt/Components/pqCalculatorPanel.cxx
@@ -546,6 +546,52 @@ void pqCalculatorPanel::updateVariables(const QString& mode)
this->Internal->VectorsMenu.addAction(name);
}
}
+
+ // to add field arrays to the calculator
+ fdi = f->getInput(f->getInputPortName(0), 0)->getDataInformation()
+ ->GetFieldDataInformation();
+
+ if(!fdi)
+ {
+ return;
+ }
+
+ for(int i=0; i<fdi->GetNumberOfArrays(); i++)
+ {
+ vtkPVArrayInformation* arrayInfo = fdi->GetArrayInformation(i);
+ if (arrayInfo->GetDataType() == VTK_STRING
+ || arrayInfo->GetDataType() == VTK_VARIANT )
+ {
+ continue;
+ }
+
+ int numComponents = arrayInfo->GetNumberOfComponents();
+ QString name = arrayInfo->GetName();
+
+ for(int j=0; j<numComponents; j++)
+ {
+ if(numComponents == 1)
+ {
+ this->Internal->ScalarsMenu.addAction(name);
+ }
+ else
+ {
+ QString compName(arrayInfo->GetComponentName( j ));
+ QString n = name + QString( "_%1").arg( compName );
+ QStringList d;
+ d.append(name);
+ d.append(QString("%1").arg(j));
+ QAction* a = new QAction(n, &this->Internal->ScalarsMenu);
+ a->setData(d);
+ this->Internal->ScalarsMenu.addAction(a);
+ }
+ }
+
+ if(numComponents == 3)
+ {
+ this->Internal->VectorsMenu.addAction(name);
+ }
+ }
}
void pqCalculatorPanel::variableChosen(QAction* a)
|
|