diff --git a/Infovis/vtkStringToNumeric.cxx b/Infovis/vtkStringToNumeric.cxx index db1f10b90f8d0c4dd859f8df0ffd6d8378e5827b..211b863d1b9af97e3d2ac3fcdb04d75c54dccf26 100644 --- a/Infovis/vtkStringToNumeric.cxx +++ b/Infovis/vtkStringToNumeric.cxx @@ -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) { diff --git a/Infovis/vtkStringToNumeric.h b/Infovis/vtkStringToNumeric.h index 8a692873b09cdf502907cf858ac2758b5bcc3a94..367111262d22eb86881653cb79dee9f1bea65374 100644 --- a/Infovis/vtkStringToNumeric.h +++ b/Infovis/vtkStringToNumeric.h @@ -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**,