Commit bcc45bd9 authored by Amy Squillacote's avatar Amy Squillacote
Browse files

ENH: The VTK writers should take advantage of the pipeline doing data type checking.

parent 454b7206
......@@ -16,10 +16,12 @@
#include "vtkCommand.h"
#include "vtkDataObject.h"
#include "vtkDemandDrivenPipeline.h"
#include "vtkErrorCode.h"
#include "vtkExecutive.h"
#include "vtkInformation.h"
#include "vtkInformationVector.h"
vtkCxxRevisionMacro(vtkWriter, "1.42");
vtkCxxRevisionMacro(vtkWriter, "1.43");
// Construct with no start and end write methods or arguments.
vtkWriter::vtkWriter()
......@@ -67,7 +69,38 @@ vtkDataObject *vtkWriter::GetInput(int port)
// Write data to output. Method executes subclasses WriteData() method, as
// well as StartMethod() and EndMethod() methods.
void vtkWriter::Write()
int vtkWriter::Write()
{
// Make sure we have input.
if (this->GetNumberOfInputConnections(0) < 1)
{
vtkErrorMacro("No input provided!");
return 0;
}
// always write even if the data hasn't changed
this->Modified();
this->UpdateWholeExtent();
return 1;
}
int vtkWriter::ProcessRequest(vtkInformation *request,
vtkInformationVector **inputVector,
vtkInformationVector *outputVector)
{
// generate the data
if(request->Has(vtkDemandDrivenPipeline::REQUEST_DATA()))
{
return this->RequestData(request, inputVector, outputVector);
}
return this->Superclass::ProcessRequest(request, inputVector, outputVector);
}
int vtkWriter::RequestData(
vtkInformation *,
vtkInformationVector **,
vtkInformationVector *)
{
this->SetErrorCode(vtkErrorCode::NoError);
......@@ -78,7 +111,7 @@ void vtkWriter::Write()
if ( !input )
{
vtkErrorMacro(<< "No input!");
return;
return 0;
}
for (idx = 0; idx < this->GetNumberOfInputPorts(); ++idx)
......@@ -102,7 +135,7 @@ void vtkWriter::Write()
if (lastUpdateTime < this->WriteTime && this->GetMTime() < this->WriteTime)
{
// we are up to date
return;
return 1;
}
this->InvokeEvent(vtkCommand::StartEvent,NULL);
......@@ -119,12 +152,8 @@ void vtkWriter::Write()
}
this->WriteTime.Modified();
}
// Convenient alias for Write() method.
void vtkWriter::Update()
{
this->Write();
return 1;
}
void vtkWriter::PrintSelf(ostream& os, vtkIndent indent)
......
......@@ -49,11 +49,8 @@ public:
// Description:
// Write data to output. Method executes subclasses WriteData() method, as
// well as StartMethod() and EndMethod() methods.
virtual void Write();
// Description:
// Convenient alias for Write() method.
void Update();
// Returns 1 on success and 0 on failure.
virtual int Write();
// Description:
// Encode the name so that the reader will not have problems.
......@@ -71,7 +68,14 @@ public:
protected:
vtkWriter();
~vtkWriter();
virtual int ProcessRequest(vtkInformation *request,
vtkInformationVector **inputVector,
vtkInformationVector *outputVector);
virtual int RequestData(vtkInformation *request,
vtkInformationVector **inputVector,
vtkInformationVector *outputVector);
virtual void WriteData() = 0; //internal method subclasses must respond to
vtkTimeStamp WriteTime;
private:
......
......@@ -22,7 +22,7 @@
#include "vtkRectilinearGrid.h"
#include "vtkErrorCode.h"
vtkCxxRevisionMacro(vtkPDataSetWriter, "1.14");
vtkCxxRevisionMacro(vtkPDataSetWriter, "1.15");
vtkStandardNewMacro(vtkPDataSetWriter);
//----------------------------------------------------------------------------
......@@ -62,7 +62,7 @@ void vtkPDataSetWriter::SetNumberOfPieces(int num)
}
//----------------------------------------------------------------------------
void vtkPDataSetWriter::Write()
int vtkPDataSetWriter::Write()
{
int i;
int length;
......@@ -75,7 +75,7 @@ void vtkPDataSetWriter::Write()
if (this->FileName == NULL)
{
vtkErrorMacro("No file name.");
return;
return 0;
}
if (this->StartPiece < 0)
......@@ -85,17 +85,15 @@ void vtkPDataSetWriter::Write()
if (this->NumberOfPieces < 0 || this->EndPiece < this->StartPiece)
{
vtkWarningMacro("No pieces to write.");
return;
return 1;
}
// Only one piece? The just write one vtk file.
if (this->StartPiece == 0 && this->NumberOfPieces == 1)
{
this->vtkDataSetWriter::Write();
return;
return this->vtkDataSetWriter::Write();
}
// Lets compute the file root from the file name supplied by the user.
length = static_cast<int>(strlen(this->FileName));
fileRoot = new char [length+1];
......@@ -147,7 +145,7 @@ void vtkPDataSetWriter::Write()
{
delete [] fileRoot;
delete [] fileName;
return;
return 0;
}
// Write a tag so that we know this file type.
*fptr << "<File version=\"pvtk-1.0\"\n";
......@@ -161,7 +159,7 @@ void vtkPDataSetWriter::Write()
delete [] fileName;
delete fptr;
this->SetErrorCode(vtkErrorCode::OutOfDiskSpaceError);
return;
return 0;
}
input->UpdateInformation();
......@@ -177,7 +175,7 @@ void vtkPDataSetWriter::Write()
delete [] fileName;
delete fptr;
this->SetErrorCode(vtkErrorCode::OutOfDiskSpaceError);
return;
return 0;
}
break;
case VTK_IMAGE_DATA:
......@@ -191,7 +189,7 @@ void vtkPDataSetWriter::Write()
delete [] fileName;
delete fptr;
this->SetErrorCode(vtkErrorCode::OutOfDiskSpaceError);
return;
return 0;
}
break;
case VTK_RECTILINEAR_GRID:
......@@ -204,7 +202,7 @@ void vtkPDataSetWriter::Write()
delete [] fileName;
delete fptr;
this->SetErrorCode(vtkErrorCode::OutOfDiskSpaceError);
return;
return 0;
}
break;
case VTK_STRUCTURED_GRID:
......@@ -217,7 +215,7 @@ void vtkPDataSetWriter::Write()
delete [] fileName;
delete fptr;
this->SetErrorCode(vtkErrorCode::OutOfDiskSpaceError);
return;
return 0;
}
break;
}
......@@ -272,8 +270,9 @@ void vtkPDataSetWriter::Write()
writer = NULL;
delete [] fileName;
delete [] fileRoot;
}
return 1;
}
//----------------------------------------------------------------------------
int vtkPDataSetWriter::WriteUnstructuredMetaData(vtkDataSet *input,
......
......@@ -36,7 +36,7 @@ public:
// Description:
// Write the pvtk file and cooresponding vtk files.
virtual void Write();
virtual int Write();
// Description:
// This is how many pieces the whole data set will be divided into.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment