Skip to content
Snippets Groups Projects
Commit a64aa7d5 authored by Jeff Baumes's avatar Jeff Baumes
Browse files

Adding option to force numeric conversion to double

Added a ForceDouble flag to vtkStringToNumeric and expose
the same flag in vtkDelimitedTextReader.

Change-Id: I5b3e13272e8dc5589a96c8bd88cfcb8479b3a6c3
parent 486050c9
No related merge requests found
......@@ -109,6 +109,17 @@ int TestStringToNumeric(int argc, char* argv[])
++errors;
}
}
cerr << "Testing ForceDouble..." << endl;
numeric->ForceDoubleOn();
numeric->Update();
table = vtkTable::SafeDownCast(numeric->GetOutput());
if (!vtkDoubleArray::SafeDownCast(table->GetColumnByName("Age")))
{
cerr << "ERROR: ForceDouble did not force Age to double array" << endl;
++errors;
}
cerr << "...done testing" << endl;
cerr << errors << " errors found." << endl;
......
......@@ -398,6 +398,7 @@ vtkDelimitedTextReader::vtkDelimitedTextReader() :
this->StringDelimiter='"';
this->UseStringDelimiter = true;
this->DetectNumericColumns = false;
this->ForceDouble = false;
}
vtkDelimitedTextReader::~vtkDelimitedTextReader()
......@@ -436,6 +437,8 @@ void vtkDelimitedTextReader::PrintSelf(ostream& os, vtkIndent indent)
<< (this->UseStringDelimiter ? "true" : "false") << endl;
os << indent << "DetectNumericColumns: "
<< (this->DetectNumericColumns? "true" : "false") << endl;
os << indent << "ForceDouble: "
<< (this->ForceDouble ? "true" : "false") << endl;
os << indent << "GeneratePedigreeIds: "
<< this->GeneratePedigreeIds << endl;
os << indent << "PedigreeIdArrayName: "
......@@ -636,6 +639,7 @@ int vtkDelimitedTextReader::RequestData(
if (this->DetectNumericColumns && !this->UnicodeOutputArrays)
{
vtkStringToNumeric* convertor = vtkStringToNumeric::New();
convertor->SetForceDouble(this->ForceDouble);
vtkTable* clone = output_table->NewInstance();
clone->ShallowCopy(output_table);
convertor->SetInput(clone);
......
......@@ -163,6 +163,14 @@ public:
vtkGetMacro(DetectNumericColumns, bool);
vtkBooleanMacro(DetectNumericColumns, bool);
// Description:
// When set to true and DetectNumericColumns is also true, forces all
// numeric columns to vtkDoubleArray even if they contain only
// integer values. Default is off.
vtkSetMacro(ForceDouble, bool);
vtkGetMacro(ForceDouble, bool);
vtkBooleanMacro(ForceDouble, bool);
// Description:
// The name of the array for generating or assigning pedigree ids
// (default "id").
......@@ -214,6 +222,7 @@ protected:
vtkUnicodeString UnicodeWhitespace;
vtkUnicodeString UnicodeEscapeCharacter;
bool DetectNumericColumns;
bool ForceDouble;
char* FieldDelimiterCharacters;
char StringDelimiter;
bool UseStringDelimiter;
......
......@@ -43,6 +43,7 @@ vtkStringToNumeric::vtkStringToNumeric()
this->ConvertFieldData = true;
this->ConvertPointData = true;
this->ConvertCellData = true;
this->ForceDouble = false;
}
vtkStringToNumeric::~vtkStringToNumeric()
......@@ -251,7 +252,8 @@ void vtkStringToNumeric::ConvertArrays(vtkFieldData* fieldData)
if (allNumeric)
{
// Calling AddArray will replace the old array since the names match.
if (allInteger && (numTuples*numComps)) // Are they all ints, and did I test anything?
// Are they all ints, and did I test anything?
if (!this->ForceDouble && allInteger && (numTuples*numComps))
{
fieldData->AddArray(intArray);
}
......@@ -321,4 +323,6 @@ void vtkStringToNumeric::PrintSelf(ostream& os, vtkIndent indent)
<< (this->ConvertPointData ? "on" : "off") << endl;
os << indent << "ConvertCellData: "
<< (this->ConvertCellData ? "on" : "off") << endl;
os << indent << "ForceDouble: "
<< (this->ForceDouble ? "on" : "off") << endl;
}
......@@ -34,6 +34,13 @@ public:
static vtkStringToNumeric* New();
vtkTypeMacro(vtkStringToNumeric,vtkDataObjectAlgorithm);
void PrintSelf(ostream& os, vtkIndent indent);
// Description:
// Convert all numeric columns to vtkDoubleArray, even if they
// contain only integer values. Default is off.
vtkSetMacro(ForceDouble, bool);
vtkGetMacro(ForceDouble, bool);
vtkBooleanMacro(ForceDouble, bool);
// Description:
// Whether to detect and convert field data arrays. Default is on.
......@@ -100,6 +107,7 @@ protected:
bool ConvertFieldData;
bool ConvertPointData;
bool ConvertCellData;
bool ForceDouble;
// Description:
// Count the total number of items (array components) that will need
......
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