Skip to content
Snippets Groups Projects
Commit 87ba5434 authored by Andy Wilson's avatar Andy Wilson
Browse files

ENH: Before execution, count how many items need to be converted. This lets...

ENH: Before execution, count how many items need to be converted.  This lets us emit ProgressEvent with meaningful values.
parent adc69a28
No related branches found
No related tags found
No related merge requests found
......@@ -36,7 +36,7 @@
#include "vtkUnicodeStringArray.h"
#include "vtkVariant.h"
vtkCxxRevisionMacro(vtkStringToNumeric, "1.8");
vtkCxxRevisionMacro(vtkStringToNumeric, "1.9");
vtkStandardNewMacro(vtkStringToNumeric);
vtkStringToNumeric::vtkStringToNumeric()
......@@ -50,6 +50,28 @@ vtkStringToNumeric::~vtkStringToNumeric()
{
}
int vtkStringToNumeric::CountItemsToConvert(vtkFieldData *fieldData)
{
int count = 0;
for (int arr = 0; arr < fieldData->GetNumberOfArrays(); arr++)
{
vtkAbstractArray *array = fieldData->GetAbstractArray(arr);
vtkStringArray* stringArray = vtkStringArray::SafeDownCast(array);
vtkUnicodeStringArray* unicodeArray =
vtkUnicodeStringArray::SafeDownCast(array);
if (!stringArray && !unicodeArray)
{
continue;
}
else
{
count += array->GetNumberOfTuples() * array->GetNumberOfComponents();
}
}
return count;
}
int vtkStringToNumeric::RequestData(
vtkInformation*,
vtkInformationVector** inputVector,
......@@ -63,12 +85,45 @@ int vtkStringToNumeric::RequestData(
vtkDataObject* input = inInfo->Get(vtkDataObject::DATA_OBJECT());
vtkDataObject* output = outInfo->Get(vtkDataObject::DATA_OBJECT());
output->ShallowCopy(input);
vtkDataSet* outputDataSet = vtkDataSet::SafeDownCast(output);
vtkGraph* outputGraph = vtkGraph::SafeDownCast(output);
vtkTable* outputTable = vtkTable::SafeDownCast(output);
// Figure out how many items we have to process
int itemCount = 0;
if (this->ConvertFieldData)
{
itemCount += this->CountItemsToConvert(output->GetFieldData());
}
if (outputDataSet && this->ConvertPointData)
{
itemCount += this->CountItemsToConvert(outputDataSet->GetPointData());
}
if (outputDataSet && this->ConvertCellData)
{
itemCount += this->CountItemsToConvert(outputDataSet->GetCellData());
}
if (outputGraph && this->ConvertPointData)
{
itemCount += this->CountItemsToConvert(outputGraph->GetVertexData());
}
if (outputGraph && this->ConvertCellData)
{
itemCount += this->CountItemsToConvert(outputGraph->GetEdgeData());
}
if (outputTable && this->ConvertPointData)
{
itemCount += this->CountItemsToConvert(outputTable->GetRowData());
}
this->ItemsToConvert = itemCount;
this->ItemsConverted = 0;
if (this->ConvertFieldData)
{
this->ConvertArrays(output->GetFieldData());
}
vtkDataSet* outputDataSet = vtkDataSet::SafeDownCast(output);
if (outputDataSet && this->ConvertPointData)
{
this->ConvertArrays(outputDataSet->GetPointData());
......@@ -77,7 +132,6 @@ int vtkStringToNumeric::RequestData(
{
this->ConvertArrays(outputDataSet->GetCellData());
}
vtkGraph *outputGraph = vtkGraph::SafeDownCast(output);
if (outputGraph && this->ConvertPointData)
{
this->ConvertArrays(outputGraph->GetVertexData());
......@@ -86,7 +140,6 @@ int vtkStringToNumeric::RequestData(
{
this->ConvertArrays(outputGraph->GetEdgeData());
}
vtkTable *outputTable = vtkTable::SafeDownCast(output);
if (outputTable && this->ConvertPointData)
{
this->ConvertArrays(outputTable->GetRowData());
......@@ -140,6 +193,13 @@ void vtkStringToNumeric::ConvertArrays(vtkFieldData* fieldData)
bool allNumeric = true;
for (vtkIdType i = 0; i < numTuples*numComps; i++)
{
++ this->ItemsConverted;
if (this->ItemsConverted % 100 == 0)
{
this->UpdateProgress(static_cast<double>(this->ItemsConverted) /
static_cast<double>(this->ItemsToConvert));
}
vtkStdString str;
if (stringArray)
{
......
......@@ -101,6 +101,16 @@ protected:
bool ConvertPointData;
bool ConvertCellData;
// Description:
// Count the total number of items (array components) that will need
// to be converted in the given vtkFieldData. This lets us emit
// ProgressEvent.
int CountItemsToConvert(vtkFieldData *fieldData);
// These keep track of our progress
int ItemsToConvert;
int ItemsConverted;
int RequestData(
vtkInformation*,
vtkInformationVector**,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment