Skip to content
Snippets Groups Projects
Commit c97ff3e4 authored by Utkarsh Ayachit's avatar Utkarsh Ayachit
Browse files

ENH: Added logic to vtkDelimitedTextReader to detect numeric columns. Also

vtkDelimitedTextReader now only reads data on the root node when running in
parallel.

All these improvements make the ParaView's vtkCSVReader class obsolete and hence
removing it.
parent fa080a89
No related branches found
No related tags found
No related merge requests found
......@@ -23,20 +23,23 @@
#include "vtkCommand.h"
#include "vtkDataSetAttributes.h"
#include "vtkIdTypeArray.h"
#include "vtkTable.h"
#include "vtkVariantArray.h"
#include "vtkInformation.h"
#include "vtkInformationVector.h"
#include "vtkObjectFactory.h"
#include "vtkPointData.h"
#include "vtkInformation.h"
#include "vtkSmartPointer.h"
#include "vtkStringArray.h"
#include "vtkStdString.h"
#include "vtkStreamingDemandDrivenPipeline.h"
#include "vtkStringArray.h"
#include "vtkStringToNumeric.h"
#include "vtkTable.h"
#include "vtkVariantArray.h"
#include <vtkstd/algorithm>
#include <vtkstd/vector>
#include <vtkstd/string>
vtkCxxRevisionMacro(vtkDelimitedTextReader, "1.22");
vtkCxxRevisionMacro(vtkDelimitedTextReader, "1.23");
vtkStandardNewMacro(vtkDelimitedTextReader);
struct vtkDelimitedTextReaderInternals
......@@ -77,6 +80,7 @@ vtkDelimitedTextReader::vtkDelimitedTextReader()
this->UseStringDelimiter = true;
this->MaxRecords = 0;
this->MergeConsecutiveDelimiters = false;
this->DetectNumericColumns = false;
}
// ----------------------------------------------------------------------
......@@ -115,6 +119,8 @@ void vtkDelimitedTextReader::PrintSelf(ostream& os, vtkIndent indent)
<< (this->MergeConsecutiveDelimiters ? "true" : "false") << endl;
os << indent << "MaxRecords: " << this->MaxRecords
<< endl;
os << indent << "DetectNumericColumns: "
<< (this->DetectNumericColumns? "true" : "false") << endl;
}
// ----------------------------------------------------------------------
......@@ -149,6 +155,15 @@ int vtkDelimitedTextReader::RequestData(
vtkInformationVector**,
vtkInformationVector* outputVector)
{
// Check piece request. If requested anything but the 0-th piece, nothing to
// read.
vtkInformation *outInfo = outputVector->GetInformationObject(0);
if (outInfo->Has(vtkStreamingDemandDrivenPipeline::UPDATE_PIECE_NUMBER()) &&
outInfo->Get(vtkStreamingDemandDrivenPipeline::UPDATE_PIECE_NUMBER()) > 0)
{
return 1;
}
int line_count = 0;
// Check that the filename has been specified
......@@ -302,6 +317,18 @@ int vtkDelimitedTextReader::RequestData(
{
table->GetRowData()->SetPedigreeIds(pedIds);
}
if (this->DetectNumericColumns)
{
vtkStringToNumeric* convertor = vtkStringToNumeric::New();
vtkTable* clone = table->NewInstance();
clone->ShallowCopy(table);
convertor->SetInput(clone);
convertor->Update();
clone->Delete();
table->ShallowCopy(convertor->GetOutputDataObject(0));
convertor->Delete();
}
return 1;
}
......
......@@ -100,6 +100,14 @@ public:
vtkGetMacro(MaxRecords, int);
vtkSetMacro(MaxRecords, int);
// Description:
// When set to true, the reader will detect numeric columns and create
// vtkDoubleArray or vtkIntArray for those instead of vtkStringArray. Default
// is off.
vtkSetMacro(DetectNumericColumns, bool);
vtkGetMacro(DetectNumericColumns, bool);
vtkBooleanMacro(DetectNumericColumns, bool);
protected:
vtkDelimitedTextReader();
~vtkDelimitedTextReader();
......@@ -121,6 +129,7 @@ public:
bool MergeConsecutiveDelimiters;
char *ReadBuffer;
int MaxRecords;
bool DetectNumericColumns;
private:
vtkDelimitedTextReader(const vtkDelimitedTextReader&); // Not implemented
......
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