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.
......
This diff is collapsed.
......@@ -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));
}
//----------------------------------------------------------------------------
void vtkPolyDataReader::SetOutput(vtkPolyData *output)
{
this->vtkSource::SetNthOutput(0, output);
this->GetExecutive()->SetOutputData(0, output);
}
//----------------------------------------------------------------------------
void vtkPolyDataReader::ComputeInputUpdateExtents(vtkDataObject *data)
int vtkPolyDataReader::RequestUpdateExtent(
vtkInformation *,
vtkInformationVector **,
vtkInformationVector *outputVector)
{
vtkInformation *outInfo = outputVector->GetInformationObject(0);
int piece, numPieces, ghostLevel;
vtkPolyData *output = (vtkPolyData *)data;
int idx;
output->GetUpdateExtent(piece, numPieces, ghostLevel);
piece = outInfo->Get(vtkStreamingDemandDrivenPipeline::UPDATE_PIECE_NUMBER());
numPieces = outInfo->Get(vtkStreamingDemandDrivenPipeline::UPDATE_NUMBER_OF_PIECES());
ghostLevel = outInfo->Get(vtkStreamingDemandDrivenPipeline::UPDATE_NUMBER_OF_GHOST_LEVELS());
// make sure piece is valid
if (piece < 0 || piece >= numPieces)
{
return;
return 1;
}
if (ghostLevel < 0)
{
return;
}
// just copy the Update extent as default behavior.
for (idx = 0; idx < this->NumberOfInputs; ++idx)
{
if (this->Inputs[idx])
{
this->Inputs[idx]->SetUpdateExtent(piece, numPieces, ghostLevel);
}
return 1;
}
// Save the piece so execute can use this information.
......@@ -91,15 +90,22 @@ void vtkPolyDataReader::ComputeInputUpdateExtents(vtkDataObject *data)
this->ExecuteNumberOfPieces = numPieces;
this->ExecuteGhostLevel = ghostLevel;
return 1;
}
void vtkPolyDataReader::Execute()
int vtkPolyDataReader::RequestData(
vtkInformation *,
vtkInformationVector **,
vtkInformationVector *outputVector)
{
vtkInformation *outInfo = outputVector->GetInformationObject(0);
int numPts=0;
char line[256];
int npts, size, ncells, i;
int done=0;
vtkPolyData *output = this->GetOutput();
vtkPolyData *output = vtkPolyData::SafeDownCast(
outInfo->Get(vtkDataObject::DATA_OBJECT()));
int *tempArray;
vtkIdType *idArray;
......@@ -107,7 +113,7 @@ void vtkPolyDataReader::Execute()
if ( !(this->OpenVTKFile()) || !this->ReadHeader())
{
return;
return 1;
}
//
// Read polygonal data specific stuff
......@@ -116,7 +122,7 @@ void vtkPolyDataReader::Execute()
{
vtkErrorMacro(<<"Data file ends prematurely!");
this->CloseVTKFile ();
return;
return 1;
}
if ( !strncmp(this->LowerCase(line),"dataset",(unsigned long)7) )
......@@ -128,14 +134,14 @@ void vtkPolyDataReader::Execute()
{
vtkErrorMacro(<<"Data file ends prematurely!");
this->CloseVTKFile ();
return;
return 1;
}
if ( strncmp(this->LowerCase(line),"polydata",8) )
{
vtkErrorMacro(<< "Cannot read dataset type: " << line);
this->CloseVTKFile ();
return;
return 1;
}
//
// Might find points, vertices, lines, polygons, or triangle strips
......@@ -159,7 +165,7 @@ void vtkPolyDataReader::Execute()
{
vtkErrorMacro(<<"Cannot read number of points!");
this->CloseVTKFile ();
return;
return 1;
}
this->ReadPoints(output, numPts);
......@@ -172,7 +178,7 @@ void vtkPolyDataReader::Execute()
{
vtkErrorMacro(<<"Cannot read vertices!");
this->CloseVTKFile ();
return;
return 1;
}
tempArray = new int[size];
......@@ -196,7 +202,7 @@ void vtkPolyDataReader::Execute()
{
vtkErrorMacro(<<"Cannot read lines!");
this->CloseVTKFile ();
return;
return 1;
}
tempArray = new int[size];
idArray = lines->WritePointer(ncells, size);
......@@ -220,7 +226,7 @@ void vtkPolyDataReader::Execute()
{
vtkErrorMacro(<<"Cannot read polygons!");
this->CloseVTKFile ();
return;
return 1;
}
tempArray = new int[size];
......@@ -244,7 +250,7 @@ void vtkPolyDataReader::Execute()
{
vtkErrorMacro(<<"Cannot read triangle strips!");
this->CloseVTKFile ();
return;
return 1;
}
tempArray = new int[size];
......@@ -267,13 +273,13 @@ void vtkPolyDataReader::Execute()
{
vtkErrorMacro(<<"Cannot read cell data!");
this->CloseVTKFile ();
return;
return 1;
}
if ( ncells != output->GetNumberOfCells() )
{
vtkErrorMacro(<<"Number of cells don't match number data values!");
return;
return 1;
}
this->ReadCellData(output, ncells);
......@@ -286,13 +292,13 @@ void vtkPolyDataReader::Execute()
{
vtkErrorMacro(<<"Cannot read point data!");
this->CloseVTKFile ();
return;
return 1;
}
if ( npts != numPts )
{
vtkErrorMacro(<<"Number of points don't match number data values!");
return;
return 1;
}
this->ReadPointData(output, npts);
......@@ -303,7 +309,7 @@ void vtkPolyDataReader::Execute()
{
vtkErrorMacro(<< "Unrecognized keyword: " << line);
this->CloseVTKFile ();
return;
return 1;
}
}
......@@ -320,7 +326,7 @@ void vtkPolyDataReader::Execute()
{
vtkErrorMacro(<<"Cannot read cell data!");
this->CloseVTKFile ();
return;
return 1;
}
this->ReadCellData(output, ncells);
......@@ -333,7 +339,7 @@ void vtkPolyDataReader::Execute()
{
vtkErrorMacro(<<"Cannot read point data!");
this->CloseVTKFile ();
return;
return 1;
}
this->ReadPointData(output, numPts);
......@@ -344,16 +350,14 @@ void vtkPolyDataReader::Execute()
vtkErrorMacro(<< "Unrecognized keyword: " << line);
}
this->CloseVTKFile ();
return 1;
}
//----------------------------------------------------------------------------
int vtkPolyDataReader::FillOutputPortInformation(int port,
int vtkPolyDataReader::FillOutputPortInformation(int,
vtkInformation* info)
{
if(!this->Superclass::FillOutputPortInformation(port, info))
{
return 0;
}
info->Set(vtkDataObject::DATA_TYPE_NAME(), "vtkPolyData");
return 1;
}
......
......@@ -49,12 +49,14 @@ protected:
vtkPolyDataReader();
~vtkPolyDataReader();
void Execute();
virtual int RequestData(vtkInformation *, vtkInformationVector **,
vtkInformationVector *);
// Update extent of PolyData is specified in pieces.
// Since all DataObjects should be able to set UpdateExent as pieces,
// just copy output->UpdateExtent all Inputs.
void ComputeInputUpdateExtents(vtkDataObject *output);
virtual int RequestUpdateExtent(vtkInformation *, vtkInformationVector **,
vtkInformationVector *);
virtual int FillOutputPortInformation(int, vtkInformation*);
......
......@@ -17,20 +17,23 @@
#include "vtkDataArray.h"
#include "vtkFieldData.h"
#include "vtkInformation.h"
#include "vtkInformationVector.h"
#include "vtkObjectFactory.h"
#include "vtkRectilinearGrid.h"
#include "vtkStreamingDemandDrivenPipeline.h"
vtkCxxRevisionMacro(vtkRectilinearGridReader, "1.32");
vtkCxxRevisionMacro(vtkRectilinearGridReader, "1.33");
vtkStandardNewMacro(vtkRectilinearGridReader);
//----------------------------------------------------------------------------
vtkRectilinearGridReader::vtkRectilinearGridReader()
{
this->vtkSource::SetNthOutput(0,vtkRectilinearGrid::New());
vtkRectilinearGrid *output = vtkRectilinearGrid::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();
}
//----------------------------------------------------------------------------
......@@ -47,26 +50,35 @@ vtkRectilinearGrid* vtkRectilinearGridReader::GetOutput()
//----------------------------------------------------------------------------
vtkRectilinearGrid* vtkRectilinearGridReader::GetOutput(int idx)
{
return static_cast<vtkRectilinearGrid*>(this->vtkSource::GetOutput(idx));
return vtkRectilinearGrid::SafeDownCast(this->GetOutputDataObject(idx));
}
//----------------------------------------------------------------------------
void vtkRectilinearGridReader::SetOutput(vtkRectilinearGrid *output)
{
this->vtkSource::SetNthOutput(0, output);
this->GetExecutive()->SetOutputData(0, output);
}
//----------------------------------------------------------------------------
void vtkRectilinearGridReader::ExecuteInformation()
int vtkRectilinearGridReader::RequestInformation(
vtkInformation *,
vtkInformationVector **,
vtkInformationVector *outputVector)
{
vtkInformation *outInfo = outputVector->GetInformationObject(0);
return this->ReadMetaData(outInfo);
}
//----------------------------------------------------------------------------
int vtkRectilinearGridReader::ReadMetaData(vtkInformation *outInfo)
{
char line[256];
vtkRectilinearGrid *output = this->GetOutput();
vtkDebugMacro(<<"Reading vtk rectilinear grid file info...");
if (!this->OpenVTKFile() || !this->ReadHeader())
{
return;
return 1;
}
// Read rectilinear grid specific stuff
......@@ -75,7 +87,7 @@ void vtkRectilinearGridReader::ExecuteInformation()
{
vtkErrorMacro(<<"Data file ends prematurely!");
this->CloseVTKFile ();
return;
return 1;
}
if ( !strncmp(this->LowerCase(line),"dataset",(unsigned long)7) )
......@@ -86,14 +98,14 @@ void vtkRectilinearGridReader::ExecuteInformation()
{
vtkErrorMacro(<<"Data file ends prematurely!");
this->CloseVTKFile ();
return;
return 1;
}
if ( strncmp(this->LowerCase(line),"rectilinear_grid",16) )
{
vtkErrorMacro(<< "Cannot read dataset type: " << line);
this->CloseVTKFile ();
return;
return 1;
}
// Read keyword and number of points
......@@ -114,29 +126,35 @@ void vtkRectilinearGridReader::ExecuteInformation()
{
vtkErrorMacro(<<"Error reading dimensions!");
this->CloseVTKFile ();
return;
return 1;
}
output->SetWholeExtent(0, dim[0]-1, 0, dim[1]-1, 0, dim[2]-1);
outInfo->Set(vtkStreamingDemandDrivenPipeline::WHOLE_EXTENT(),
0, dim[0]-1, 0, dim[1]-1, 0, dim[2]-1);
// We got what we want. Now return.
this->CloseVTKFile ();
return;
return 1;
}
}
}
this->CloseVTKFile ();
return 1;
}
//----------------------------------------------------------------------------
void vtkRectilinearGridReader::Execute()
int vtkRectilinearGridReader::RequestData(
vtkInformation *,
vtkInformationVector **,
vtkInformationVector *outputVector)
{
vtkInformation *outInfo = outputVector->GetInformationObject(0);
int numPts=0, npts, ncoords, numCells=0, ncells;
char line[256];
int dimsRead=0;
int done=0;
vtkRectilinearGrid *output = this->GetOutput();
vtkRectilinearGrid *output = vtkRectilinearGrid::SafeDownCast(
outInfo->Get(vtkDataObject::DATA_OBJECT()));
vtkDebugMacro(<<"Reading vtk rectilinear grid file...");
if ( this->Debug )
......@@ -150,7 +168,7 @@ void vtkRectilinearGridReader::Execute()
if (!this->OpenVTKFile() || !this->ReadHeader())
{
return;
return 1;
}
// Read rectilinear grid specific stuff
......@@ -159,7 +177,7 @@ void vtkRectilinearGridReader::Execute()
{
vtkErrorMacro(<<"Data file ends prematurely!");
this->CloseVTKFile ();
return;
return 1;
}
if ( !strncmp(this->LowerCase(line),"dataset",(unsigned long)7) )
......@@ -170,14 +188,14 @@ void vtkRectilinearGridReader::Execute()
{
vtkErrorMacro(<<"Data file ends prematurely!");
this->CloseVTKFile ();
return;
}
return 1;
}
if ( strncmp(this->LowerCase(line),"rectilinear_grid",16) )
{
vtkErrorMacro(<< "Cannot read dataset type: " << line);
this->CloseVTKFile ();
return;
return 1;
}
// Read keyword and number of points
......@@ -204,7 +222,7 @@ void vtkRectilinearGridReader::Execute()
{
vtkErrorMacro(<<"Error reading dimensions!");
this->CloseVTKFile ();
return;
return 1;
}
numPts = dim[0] * dim[1] * dim[2];
......@@ -219,7 +237,7 @@ void vtkRectilinearGridReader::Execute()
{
vtkErrorMacro(<<"Error reading x coordinates!");
this->CloseVTKFile ();
return;
return 1;
}
this->ReadCoordinates(output, 0, ncoords);
......@@ -231,7 +249,7 @@ void vtkRectilinearGridReader::Execute()
{
vtkErrorMacro(<<"Error reading y coordinates!");
this->CloseVTKFile ();
return;
return 1;
}
this->ReadCoordinates(output, 1, ncoords);
......@@ -243,7 +261,7 @@ void vtkRectilinearGridReader::Execute()
{
vtkErrorMacro(<<"Error reading z coordinates!");
this->CloseVTKFile ();
return;
return 1;
}
this->ReadCoordinates(output, 2, ncoords);
......@@ -255,14 +273,14 @@ void vtkRectilinearGridReader::Execute()
{