Commit c49426a4 authored by Amy Squillacote's avatar Amy Squillacote

ENH: convert to using the new pipeline

parent 143e172f
......@@ -15,19 +15,23 @@
#include "vtkDataObjectReader.h"
#include "vtkObjectFactory.h"
#include "vtkExecutive.h"
#include "vtkInformation.h"
#include "vtkInformationVector.h"
#include "vtkFieldData.h"
#include "vtkDataObject.h"
vtkCxxRevisionMacro(vtkDataObjectReader, "1.18");
vtkCxxRevisionMacro(vtkDataObjectReader, "1.19");
vtkStandardNewMacro(vtkDataObjectReader);
vtkDataObjectReader::vtkDataObjectReader()
{
this->SetOutput(vtkDataObject::New());
vtkDataObject *output = vtkDataObject::New();
this->SetOutput(output);
// Releasing data for pipeline parallism.
// Filters will know it is empty.
this->Outputs[0]->ReleaseData();
this->Outputs[0]->Delete();
output->ReleaseData();
output->Delete();
}
vtkDataObjectReader::~vtkDataObjectReader()
......@@ -37,22 +41,29 @@ vtkDataObjectReader::~vtkDataObjectReader()
//----------------------------------------------------------------------------
vtkDataObject *vtkDataObjectReader::GetOutput()
{
if (this->NumberOfOutputs < 1)
{
return NULL;
}
return (vtkDataObject *)(this->Outputs[0]);
return this->GetOutput(0);
}
//----------------------------------------------------------------------------
vtkDataObject* vtkDataObjectReader::GetOutput(int port)
{
return vtkDataObject::SafeDownCast(this->GetOutputDataObject(port));
}
//----------------------------------------------------------------------------
void vtkDataObjectReader::SetOutput(vtkDataObject *output)
{
this->vtkSource::SetNthOutput(0, output);
this->GetExecutive()->SetOutputData(0, output);
}
void vtkDataObjectReader::Execute()
int vtkDataObjectReader::RequestData(
vtkInformation *,
vtkInformationVector **,
vtkInformationVector *outputVector)
{
vtkInformation *outInfo = outputVector->GetInformationObject(0);
vtkDataObject *output = outInfo->Get(vtkDataObject::DATA_OBJECT());
char line[256];
vtkFieldData *field=NULL;
......@@ -60,7 +71,7 @@ void vtkDataObjectReader::Execute()
if ( !(this->OpenVTKFile()) || !this->ReadHeader())
{
return;
return 1;
}
// Read field data until end-of-file
......@@ -72,7 +83,7 @@ void vtkDataObjectReader::Execute()
field = this->ReadFieldData(); //reads named field (or first found)
if ( field != NULL )
{
this->GetOutput()->SetFieldData(field);
output->SetFieldData(field);
field->Delete();
}
}
......@@ -81,19 +92,27 @@ void vtkDataObjectReader::Execute()
{
vtkErrorMacro(<<"Field reader cannot read datasets");
this->CloseVTKFile();
return;
return 1;
}
else
{
vtkErrorMacro(<< "Unrecognized keyword: " << line);
this->CloseVTKFile();
return;
return 1;
}
}
//while field not read
this->CloseVTKFile();
return 1;
}
int vtkDataObjectReader::FillOutputPortInformation(int, vtkInformation *info)
{
info->Set(vtkDataObject::DATA_TYPE_NAME(), "vtkDataObject");
return 1;
}
void vtkDataObjectReader::PrintSelf(ostream& os, vtkIndent indent)
......
......@@ -42,15 +42,16 @@ public:
// Description:
// Get the output field of this reader.
vtkDataObject *GetOutput();
vtkDataObject *GetOutput(int idx)
{return this->vtkSource::GetOutput(idx); };
vtkDataObject *GetOutput(int idx);
void SetOutput(vtkDataObject *);
protected:
vtkDataObjectReader();
~vtkDataObjectReader();
void Execute();
virtual int RequestData(vtkInformation *, vtkInformationVector **,
vtkInformationVector *);
virtual int FillOutputPortInformation(int, vtkInformation*);
private:
vtkDataObjectReader(const vtkDataObjectReader&); // Not implemented.
void operator=(const vtkDataObjectReader&); // Not implemented.
......
......@@ -22,6 +22,8 @@
#include "vtkErrorCode.h"
#include "vtkFieldData.h"
#include "vtkFloatArray.h"
#include "vtkInformation.h"
#include "vtkInformationVector.h"
#include "vtkIntArray.h"
#include "vtkLongArray.h"
#include "vtkLookupTable.h"
......@@ -30,6 +32,7 @@
#include "vtkPointSet.h"
#include "vtkRectilinearGrid.h"
#include "vtkShortArray.h"
#include "vtkStreamingDemandDrivenPipeline.h"
#include "vtkUnsignedCharArray.h"
#include "vtkUnsignedIntArray.h"
#include "vtkUnsignedLongArray.h"
......@@ -38,7 +41,7 @@
#include <ctype.h>
#include <sys/stat.h>
vtkCxxRevisionMacro(vtkDataReader, "1.132");
vtkCxxRevisionMacro(vtkDataReader, "1.133");
vtkStandardNewMacro(vtkDataReader);
vtkCxxSetObjectMacro(vtkDataReader, InputArray, vtkCharArray);
......@@ -98,6 +101,9 @@ vtkDataReader::vtkDataReader()
this->ReadAllColorScalars = 0;
this->ReadAllTCoords = 0;
this->ReadAllFields = 0;
this->SetNumberOfInputPorts(0);
this->SetNumberOfOutputPorts(1);
}
vtkDataReader::~vtkDataReader()
......@@ -2067,6 +2073,30 @@ const char *vtkDataReader::GetFieldDataNameInFile(int i)
}
}
int vtkDataReader::ProcessRequest(vtkInformation* request,
vtkInformationVector** inputVector,
vtkInformationVector* outputVector)
{
// generate the data
if(request->Has(vtkDemandDrivenPipeline::REQUEST_DATA()))
{
return this->RequestData(request, inputVector, outputVector);
}
if(request->Has(vtkStreamingDemandDrivenPipeline::REQUEST_UPDATE_EXTENT()))
{
return this->RequestUpdateExtent(request, inputVector, outputVector);
}
// execute information
if(request->Has(vtkDemandDrivenPipeline::REQUEST_INFORMATION()))
{
return this->RequestInformation(request, inputVector, outputVector);
}
return this->Superclass::ProcessRequest(request, inputVector, outputVector);
}
void vtkDataReader::PrintSelf(ostream& os, vtkIndent indent)
{
this->Superclass::PrintSelf(os,indent);
......
......@@ -26,7 +26,7 @@
#ifndef __vtkDataReader_h
#define __vtkDataReader_h
#include "vtkSource.h"
#include "vtkAlgorithm.h"
#define VTK_ASCII 1
#define VTK_BINARY 2
......@@ -39,11 +39,11 @@ class vtkFieldData;
class vtkPointSet;
class vtkRectilinearGrid;
class VTK_IO_EXPORT vtkDataReader : public vtkSource
class VTK_IO_EXPORT vtkDataReader : public vtkAlgorithm
{
public:
static vtkDataReader *New();
vtkTypeRevisionMacro(vtkDataReader,vtkSource);
vtkTypeRevisionMacro(vtkDataReader,vtkAlgorithm);
void PrintSelf(ostream& os, vtkIndent indent);
// Description:
......@@ -297,6 +297,11 @@ public:
istream *GetIStream() {return this->IS;};
//ETX
// Description:
// Read the meta information from the file. This needs to be public to it
// can be accessed by vtkDataSetReader.
virtual int ReadMetaData(vtkInformation *) { return 1; }
protected:
vtkDataReader();
~vtkDataReader();
......@@ -375,6 +380,18 @@ protected:
// vtkWriter::EncodeName.
void DecodeArrayName(char *resname, const char* name);
virtual int ProcessRequest(vtkInformation *, vtkInformationVector **,
vtkInformationVector *);
virtual int RequestData(vtkInformation *, vtkInformationVector **,
vtkInformationVector *)
{ return 1; }
virtual int RequestUpdateExtent(vtkInformation *, vtkInformationVector **,
vtkInformationVector *)
{ return 1; }
virtual int RequestInformation(vtkInformation *, vtkInformationVector **,
vtkInformationVector *)
{ return 1; }
private:
vtkDataReader(const vtkDataReader&); // Not implemented.
void operator=(const vtkDataReader&); // Not implemented.
......
......@@ -14,11 +14,14 @@
=========================================================================*/
#include "vtkDataSetReader.h"
#include "vtkInformation.h"
#include "vtkInformationVector.h"
#include "vtkObjectFactory.h"
#include "vtkPolyData.h"
#include "vtkPolyDataReader.h"
#include "vtkRectilinearGrid.h"
#include "vtkRectilinearGridReader.h"
#include "vtkStreamingDemandDrivenPipeline.h"
#include "vtkStructuredGrid.h"
#include "vtkStructuredGridReader.h"
#include "vtkStructuredPoints.h"
......@@ -26,11 +29,16 @@
#include "vtkUnstructuredGrid.h"
#include "vtkUnstructuredGridReader.h"
vtkCxxRevisionMacro(vtkDataSetReader, "1.65");
vtkCxxRevisionMacro(vtkDataSetReader, "1.66");
vtkStandardNewMacro(vtkDataSetReader);
vtkDataSetReader::vtkDataSetReader()
{
// need a default output, and can't create a vtkDataSet because it's an
// abstract class, so default must be a subclass of vtkDataSet
vtkPolyData *output = vtkPolyData::New();
this->GetExecutive()->SetOutputData(0, output);
output->Delete();
}
vtkDataSetReader::~vtkDataSetReader()
......@@ -39,37 +47,111 @@ vtkDataSetReader::~vtkDataSetReader()
vtkDataSet * vtkDataSetReader::GetOutput()
{
// check to see if an execute is necessary.
if (this->Outputs && this->Outputs[0] &&
this->Outputs[0]->GetUpdateTime() > this->GetMTime())
if (this->GetFileName() == NULL &&
(this->GetReadFromInputString() == 0 ||
(this->GetInputArray() == NULL && this->GetInputString() == NULL)))
{
return (vtkDataSet *)(this->Outputs[0]);
vtkWarningMacro(<< "FileName must be set");
return (vtkDataSet *) NULL;
}
// The filename might have changed (changing the output).
// We need to re execute.
if (this->GetFileName() == NULL &&
(this->GetReadFromInputString() == 0 ||
vtkDataObject *output = this->GetOutputDataObject(0);
int outputType = this->ReadOutputType();
if (output && (output->GetDataObjectType() == outputType))
{
return vtkDataSet::SafeDownCast(output);
}
switch (outputType)
{
case VTK_POLY_DATA:
output = vtkPolyData::New();
this->GetExecutive()->SetOutputData(0, output);
output->Delete();
break;
case VTK_STRUCTURED_POINTS:
output = vtkStructuredPoints::New();
output->Delete();
break;
case VTK_STRUCTURED_GRID:
output = vtkStructuredGrid::New();
this->GetExecutive()->SetOutputData(0, output);
output->Delete();
break;
case VTK_RECTILINEAR_GRID:
output = vtkRectilinearGrid::New();
this->GetExecutive()->SetOutputData(0, output);
output->Delete();
break;
case VTK_UNSTRUCTURED_GRID:
output = vtkUnstructuredGrid::New();
this->GetExecutive()->SetOutputData(0, output);
output->Delete();
break;
default:
return NULL;
}
return this->GetOutput(0);
}
int vtkDataSetReader::RequestInformation(
vtkInformation *,
vtkInformationVector **,
vtkInformationVector *outputVector)
{
vtkInformation *outInfo = outputVector->GetInformationObject(0);
if (this->GetFileName() == NULL &&
(this->GetReadFromInputString() == 0 ||
(this->GetInputArray() == NULL && this->GetInputString() == NULL)))
{
vtkWarningMacro(<< "FileName must be set");
return (vtkDataSet *) NULL;
return 0;
}
this->Execute();
if (this->Outputs == NULL)
vtkDataReader *reader = 0;
int retVal;
switch (this->ReadOutputType())
{
return NULL;
case VTK_POLY_DATA:
reader = vtkPolyDataReader::New();
break;
case VTK_STRUCTURED_POINTS:
reader = vtkStructuredPointsReader::New();
break;
case VTK_STRUCTURED_GRID:
reader = vtkStructuredGridReader::New();
break;
case VTK_RECTILINEAR_GRID:
reader = vtkRectilinearGridReader::New();
break;
case VTK_UNSTRUCTURED_GRID:
reader = vtkUnstructuredGridReader::New();
break;
default:
reader = NULL;
}
else
if (reader)
{
return (vtkDataSet *)this->Outputs[0];
reader->SetFileName(this->GetFileName());
reader->SetReadFromInputString(this->GetReadFromInputString());
reader->SetInputArray(this->GetInputArray());
reader->SetInputString(this->GetInputString());
retVal = reader->ReadMetaData(outInfo);
reader->Delete();
return retVal;
}
return 1;
}
void vtkDataSetReader::Execute()
int vtkDataSetReader::RequestData(
vtkInformation *,
vtkInformationVector **,
vtkInformationVector *outputVector)
{
vtkDataObject *output;
vtkInformation *outInfo = outputVector->GetInformationObject(0);
vtkDataObject *output = outInfo->Get(vtkDataObject::DATA_OBJECT());
vtkDebugMacro(<<"Reading vtk dataset...");
......@@ -99,20 +181,19 @@ void vtkDataSetReader::Execute()
preader->SetReadAllFields(this->GetReadAllFields());
preader->Update();
// Can we use the old output?
output = this->Outputs ? this->Outputs[0] : NULL;
if(!(output && strcmp(output->GetClassName(), "vtkPolyData") == 0))
{
// Hack to make sure that the object is not modified
// with SetNthOutput. Otherwise, extra executions occur.
vtkTimeStamp ts = this->MTime;
output = vtkPolyData::New();
this->SetNthOutput(0, output);
this->GetExecutive()->SetOutputData(0, output);
output->Delete();
this->MTime = ts;
}
output->ShallowCopy(preader->GetOutput());
preader->Delete();
return;
return 1;
}
case VTK_STRUCTURED_POINTS:
{
......@@ -138,20 +219,19 @@ void vtkDataSetReader::Execute()
preader->SetReadAllFields(this->GetReadAllFields());
preader->Update();
// Can we use the old output?
output = this->Outputs ? this->Outputs[0] : NULL;
if(!(output && strcmp(output->GetClassName(), "vtkStructuredPoints") == 0))
{
// Hack to make sure that the object is not modified
// with SetNthOutput. Otherwise, extra executions occur.
vtkTimeStamp ts = this->MTime;
output = vtkStructuredPoints::New();
this->SetNthOutput(0, output);
this->GetExecutive()->SetOutputData(0, output);
output->Delete();
this->MTime = ts;
}
output->ShallowCopy(preader->GetOutput());
preader->Delete();
return;
return 1;
}
case VTK_STRUCTURED_GRID:
{
......@@ -177,20 +257,19 @@ void vtkDataSetReader::Execute()
preader->SetReadAllFields(this->GetReadAllFields());
preader->Update();
// Can we use the old output?
output = this->Outputs ? this->Outputs[0] : NULL;
if(!(output && strcmp(output->GetClassName(), "vtkStructuredGrid") == 0))
{
// Hack to make sure that the object is not modified
// with SetNthOutput. Otherwise, extra executions occur.
vtkTimeStamp ts = this->MTime;
output = vtkStructuredGrid::New();
this->SetNthOutput(0, output);
this->GetExecutive()->SetOutputData(0, output);
output->Delete();
this->MTime = ts;
}
output->ShallowCopy(preader->GetOutput());
preader->Delete();
return;
return 1;
}
case VTK_RECTILINEAR_GRID:
{
......@@ -216,20 +295,19 @@ void vtkDataSetReader::Execute()
preader->SetReadAllFields(this->GetReadAllFields());
preader->Update();
// Can we use the old output?
output = this->Outputs ? this->Outputs[0] : NULL;
if(!(output && strcmp(output->GetClassName(), "vtkRectilinearGrid") == 0))
{
// Hack to make sure that the object is not modified
// with SetNthOutput. Otherwise, extra executions occur.
vtkTimeStamp ts = this->MTime;
output = vtkRectilinearGrid::New();
this->SetNthOutput(0, output);
this->GetExecutive()->SetOutputData(0, output);
output->Delete();
this->MTime = ts;
}
output->ShallowCopy(preader->GetOutput());
preader->Delete();
return;
return 1;
}
case VTK_UNSTRUCTURED_GRID:
{
......@@ -255,27 +333,26 @@ void vtkDataSetReader::Execute()
preader->SetReadAllFields(this->GetReadAllFields());
preader->Update();
// Can we use the old output?
output = this->Outputs ? this->Outputs[0] : NULL;
if(!(output && strcmp(output->GetClassName(), "vtkUnstructuredGrid") == 0))
{
// Hack to make sure that the object is not modified
// with SetNthOutput. Otherwise, extra executions occur.
vtkTimeStamp ts = this->MTime;
output = vtkUnstructuredGrid::New();
this->SetNthOutput(0, output);
this->GetExecutive()->SetOutputData(0, output);
output->Delete();
this->MTime = ts;
}
output->ShallowCopy(preader->GetOutput());
preader->Delete();
return;
return 1;
}
default:
vtkErrorMacro("Could not read file " << this->FileName);
}
return 0;
}
int vtkDataSetReader::ReadOutputType()
{
char line[256];
......@@ -333,12 +410,10 @@ int vtkDataSetReader::ReadOutputType()
return -1;
}
}
else if ( !strncmp(this->LowerCase(line),"field",(unsigned long)5) )
{
//vtkErrorMacro(<<"This object can only read datasets, not fields");
}
else
{
//vtkErrorMacro(<<"Expecting DATASET keyword, got " << line << " instead");
......@@ -347,10 +422,6 @@ int vtkDataSetReader::ReadOutputType()
return -1;
}
vtkPolyData *vtkDataSetReader::GetPolyDataOutput()
{
return vtkPolyData::SafeDownCast(this->GetOutput());
......@@ -376,7 +447,6 @@ vtkRectilinearGrid *vtkDataSetReader::GetRectilinearGridOutput()
return vtkRectilinearGrid::SafeDownCast(this->GetOutput());
}
//----------------------------------------------------------------------------
void vtkDataSetReader::Update()
{
......@@ -393,5 +463,11 @@ void vtkDataSetReader::PrintSelf(ostream& os, vtkIndent indent)
vtkDataSet *vtkDataSetReader::GetOutput(int idx)
{
return static_cast<vtkDataSet *>(this->vtkSource::GetOutput(idx));
return vtkDataSet::SafeDownCast(this->GetOutputDataObject(idx));
}
int vtkDataSetReader::FillOutputPortInformation(int, vtkInformation *info)
{
info->Set(vtkDataObject::DATA_TYPE_NAME(), "vtkDataSet");
return 1;
}
......@@ -79,8 +79,11 @@ protected:
vtkDataSetReader();
~vtkDataSetReader();
void Execute();
vtkDataReader *Reader;
virtual int RequestData(vtkInformation *, vtkInformationVector **,
vtkInformationVector *);
virtual int FillOutputPortInformation(int, vtkInformation *);
virtual int RequestInformation(vtkInformation *, vtkInformationVector **,
vtkInformationVector *);
private:
vtkDataSetReader(const vtkDataSetReader&); // Not implemented.
......
......@@ -17,19 +17,22 @@
#include "vtkCellArray.h"
#include "vtkFieldData.h"
#include "vtkInformation.h"
#include "vtkInformationVector.h"
#include "vtkObjectFactory.h"
#include "vtkPolyData.h"
#include "vtkStreamingDemandDrivenPipeline.h"
vtkCxxRevisionMacro(vtkPolyDataReader, "1.27");
vtkCxxRevisionMacro(vtkPolyDataReader, "1.28");
vtkStandardNewMacro(vtkPolyDataReader);
vtkPolyDataReader::vtkPolyDataReader()
{
this->vtkSource::SetNthOutput(0, vtkPolyData::New());
vtkPolyData *output = vtkPolyData::New();
this->SetOutput(output);
// Releasing data for pipeline parallism.
// Filters will know it is empty.
this->Outputs[0]->ReleaseData();
this->Outputs[0]->Delete();
output->ReleaseData();
output->Delete();
this->ExecutePiece = this->ExecuteNumberOfPieces = 0;
this->ExecuteGhostLevel = 0;
}
......@@ -47,43 +50,39 @@ vtkPolyData* vtkPolyDataReader::GetOutput()
//----------------------------------------------------------------------------
vtkPolyData* vtkPolyDataReader::GetOutput(int idx)
{
return static_cast<vtkPolyData*>(this->vtkSource::GetOutput(idx));
return vtkPolyData::SafeDownCast(this->GetOutputDataObject(idx));
}