Commit 9e96c49f authored by Rusty Blue's avatar Rusty Blue

ENH: Converted XML Readers to new pipline

parent a9b0503b
......@@ -18,19 +18,19 @@ proc rtOtherTest { fileid } {
#actual test
set all [lsort [info command vtk*]]
foreach a $all {
if {$a == "vtkIndent"} {
continue
}
if {$a == "vtkOutputPort"} {
continue
}
if {$a == "vtkTimeStamp"} {
continue
}
if {$a == "vtkIndent"} {
continue
}
if {$a == "vtkOutputPort"} {
continue
}
if {$a == "vtkTimeStamp"} {
continue
}
if {$a == "vtkOutputWindow"} {
continue
}
catch {
catch {
$a b
b Print
if {[b IsA $a] == 0} {puts stderr "$a failed IsA test!!!"}
......@@ -38,14 +38,14 @@ proc rtOtherTest { fileid } {
b GetClassName
b Delete
}
catch {
catch {
$a b
$a c
set d [b SafeDownCast c]
b Delete
c Delete
}
catch {
catch {
b Delete
c Delete
}
......
......@@ -22,7 +22,7 @@
#include "vtkXMLDataElement.h"
#include "vtkXMLDataParser.h"
vtkCxxRevisionMacro(vtkXMLDataReader, "1.10");
vtkCxxRevisionMacro(vtkXMLDataReader, "1.11");
//----------------------------------------------------------------------------
vtkXMLDataReader::vtkXMLDataReader()
......@@ -140,116 +140,79 @@ void vtkXMLDataReader::DestroyPieces()
this->NumberOfPieces = 0;
}
//----------------------------------------------------------------------------
void vtkXMLDataReader::SetupOutputInformation()
void vtkXMLDataReader::SetupOutputData()
{
this->Superclass::SetupOutputInformation();
if(!this->NumberOfPieces) { return; }
this->Superclass::SetupOutputData();
int i;
// Use the configuration of the first piece since all are the same.
vtkXMLDataElement* ePointData = this->PointDataElements[0];
vtkXMLDataElement* eCellData = this->CellDataElements[0];
vtkPointData* pointData = this->GetOutputAsDataSet(0)->GetPointData();
vtkCellData* cellData = this->GetOutputAsDataSet(0)->GetCellData();
vtkCellData* cellData = this->GetOutputAsDataSet(0)->GetCellData();
// Setup the point and cell data arrays without allocation.
// Get the size of the output arrays.
unsigned long pointTuples = this->GetNumberOfPoints();
unsigned long cellTuples = this->GetNumberOfCells();
// Allocate the arrays in the output. We only need the information
// from one piece because all pieces have the same set of arrays.
vtkXMLDataElement* ePointData = this->PointDataElements[0];
vtkXMLDataElement* eCellData = this->CellDataElements[0];
int i;
this->NumberOfPointArrays = 0;
this->SetDataArraySelections(ePointData, this->PointDataArraySelection);
if(ePointData)
if (ePointData)
{
for(i=0;i < ePointData->GetNumberOfNestedElements();++i)
for (i = 0; i < ePointData->GetNumberOfNestedElements(); i++)
{
vtkXMLDataElement* eNested = ePointData->GetNestedElement(i);
if(this->PointDataArrayIsEnabled(eNested))
if (this->PointDataArrayIsEnabled(eNested))
{
++this->NumberOfPointArrays;
this->NumberOfPointArrays++;
vtkDataArray* array = this->CreateDataArray(eNested);
if(array)
if (array)
{
array->SetNumberOfTuples(pointTuples);
pointData->AddArray(array);
array->Delete();
}
else
{
this->InformationError = 1;
this->DataError = 1;
}
}
}
}
this->NumberOfCellArrays = 0;
this->SetDataArraySelections(eCellData, this->CellDataArraySelection);
if(eCellData)
if (eCellData)
{
for(i=0;i < eCellData->GetNumberOfNestedElements();++i)
for (i = 0; i < eCellData->GetNumberOfNestedElements(); i++)
{
vtkXMLDataElement* eNested = eCellData->GetNestedElement(i);
if(this->CellDataArrayIsEnabled(eNested))
if (this->CellDataArrayIsEnabled(eNested))
{
++this->NumberOfCellArrays;
this->NumberOfCellArrays++;
vtkDataArray* array = this->CreateDataArray(eNested);
if(array)
if (array)
{
array->SetNumberOfTuples(cellTuples);
cellData->AddArray(array);
array->Delete();
}
else
{
this->InformationError = 1;
this->DataError = 1;
}
}
}
}
// Setup attribute indices for the point data and cell data.
this->ReadAttributeIndices(ePointData, pointData);
this->ReadAttributeIndices(eCellData, cellData);
}
//----------------------------------------------------------------------------
void vtkXMLDataReader::SetupOutputData()
{
this->Superclass::SetupOutputData();
vtkDataSet* output = this->GetOutputAsDataSet(0);
vtkPointData* pointData = output->GetPointData();
vtkCellData* cellData = output->GetCellData();
// Get the size of the output arrays.
unsigned long pointTuples = this->GetNumberOfPoints();
unsigned long cellTuples = this->GetNumberOfCells();
// Allocate the arrays in the output. We only need the information
// from one piece because all pieces have the same set of arrays.
vtkXMLDataElement* ePointData = this->PointDataElements[0];
vtkXMLDataElement* eCellData = this->CellDataElements[0];
int i;
if(ePointData)
{
int a=0;
for(i=0;i < ePointData->GetNumberOfNestedElements();++i)
{
vtkXMLDataElement* eNested = ePointData->GetNestedElement(i);
if(this->PointDataArrayIsEnabled(eNested))
{
pointData->GetArray(a++)->SetNumberOfTuples(pointTuples);
}
}
}
if(eCellData)
{
int a=0;
for(i=0;i < eCellData->GetNumberOfNestedElements();++i)
{
vtkXMLDataElement* eNested = eCellData->GetNestedElement(i);
if(this->CellDataArrayIsEnabled(eNested))
{
cellData->GetArray(a++)->SetNumberOfTuples(cellTuples);
}
}
}
}
//----------------------------------------------------------------------------
int vtkXMLDataReader::ReadPiece(vtkXMLDataElement* ePiece, int piece)
{
......
......@@ -48,7 +48,6 @@ protected:
virtual void CreateXMLParser();
virtual void DestroyXMLParser();
int ReadPrimaryElement(vtkXMLDataElement* ePrimary);
void SetupOutputInformation();
void SetupOutputData();
// Setup the reader for a given number of pieces.
......
......@@ -19,19 +19,21 @@
#include "vtkObjectFactory.h"
#include "vtkPointData.h"
#include "vtkXMLDataElement.h"
#include "vtkInformation.h"
#include "vtkStreamingDemandDrivenPipeline.h"
vtkCxxRevisionMacro(vtkXMLImageDataReader, "1.4");
vtkCxxRevisionMacro(vtkXMLImageDataReader, "1.5");
vtkStandardNewMacro(vtkXMLImageDataReader);
//----------------------------------------------------------------------------
vtkXMLImageDataReader::vtkXMLImageDataReader()
{
// Copied from vtkImageDataReader constructor:
this->SetOutput(vtkImageData::New());
vtkImageData *output = vtkImageData::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();
}
//----------------------------------------------------------------------------
......@@ -48,23 +50,19 @@ void vtkXMLImageDataReader::PrintSelf(ostream& os, vtkIndent indent)
//----------------------------------------------------------------------------
void vtkXMLImageDataReader::SetOutput(vtkImageData *output)
{
this->Superclass::SetNthOutput(0, output);
this->GetExecutive()->SetOutputData(0, output);
}
//----------------------------------------------------------------------------
vtkImageData* vtkXMLImageDataReader::GetOutput()
{
if(this->NumberOfOutputs < 1)
{
return 0;
}
return static_cast<vtkImageData*>(this->Outputs[0]);
return this->GetOutput(0);
}
//----------------------------------------------------------------------------
vtkImageData* vtkXMLImageDataReader::GetOutput(int idx)
{
return static_cast<vtkImageData*>(this->Superclass::GetOutput(idx));
return vtkImageData::SafeDownCast( this->GetOutputDataObject(idx) );
}
......@@ -105,20 +103,45 @@ int vtkXMLImageDataReader::ReadPrimaryElement(vtkXMLDataElement* ePrimary)
}
//----------------------------------------------------------------------------
void vtkXMLImageDataReader::SetupOutputInformation()
void vtkXMLImageDataReader::SetupOutputInformation(vtkInformation *outInfo)
{
this->Superclass::SetupOutputInformation();
this->Superclass::SetupOutputInformation(outInfo);
outInfo->Set(vtkDataObject::ORIGIN(), this->Origin, 3);
outInfo->Set(vtkDataObject::SPACING(), this->Spacing, 3);
// Backward-compatability support for scalar information in output.
vtkImageData* output = this->GetOutput();
output->SetOrigin(this->Origin);
output->SetSpacing(this->Spacing);
vtkDataArray* scalars = output->GetPointData()->GetScalars();
if(scalars)
if (this->PointDataElements[0])
{
output->SetScalarType(scalars->GetDataType());
output->SetNumberOfScalarComponents(scalars->GetNumberOfComponents());
}
int components, dataType, i;
for(i = 0; i < this->PointDataElements[0]->GetNumberOfNestedElements(); i++)
{
vtkXMLDataElement* eNested = this->PointDataElements[0]->GetNestedElement(i);
if ( eNested->GetAttribute( "Scalars" ) )
{
if(!eNested->GetWordTypeAttribute("type", dataType))
{
this->InformationError = 1;
return;
}
if(!eNested->GetScalarAttribute("NumberOfComponents", components))
{
this->InformationError = 1;
return;
}
outInfo->Set(vtkDataObject::SCALAR_TYPE(), dataType);
outInfo->Set(vtkDataObject::SCALAR_NUMBER_OF_COMPONENTS(), components);
break;
}
}
}
}
//----------------------------------------------------------------------------
int vtkXMLImageDataReader::FillOutputPortInformation(int, vtkInformation* info)
{
info->Set(vtkDataObject::DATA_TYPE_NAME(), "vtkImageData");
return 1;
}
......@@ -53,7 +53,8 @@ protected:
const char* GetDataSetName();
void SetOutputExtent(int* extent);
int ReadPrimaryElement(vtkXMLDataElement* ePrimary);
void SetupOutputInformation();
void SetupOutputInformation(vtkInformation *outInfo);
virtual int FillOutputPortInformation(int, vtkInformation*);
private:
vtkXMLImageDataReader(const vtkXMLImageDataReader&); // Not implemented.
......
......@@ -22,8 +22,9 @@
#include "vtkPointData.h"
#include "vtkXMLDataElement.h"
#include "vtkXMLDataReader.h"
#include "vtkStreamingDemandDrivenPipeline.h"
vtkCxxRevisionMacro(vtkXMLPDataReader, "1.10");
vtkCxxRevisionMacro(vtkXMLPDataReader, "1.11");
//----------------------------------------------------------------------------
vtkXMLPDataReader::vtkXMLPDataReader()
......@@ -65,23 +66,28 @@ vtkDataSet* vtkXMLPDataReader::GetPieceInputAsDataSet(int piece)
{
vtkXMLDataReader* reader = this->PieceReaders[piece];
if(!reader) { return 0; }
if(reader->GetNumberOfOutputs() < 1) { return 0; }
return static_cast<vtkDataSet*>(reader->GetOutputs()[0]);
if(reader->GetNumberOfOutputPorts() < 1) { return 0; }
return static_cast<vtkDataSet*>(reader->GetExecutive()->GetOutputData(0));
}
//----------------------------------------------------------------------------
void vtkXMLPDataReader::SetupOutputInformation()
void vtkXMLPDataReader::SetupOutputData()
{
this->Superclass::SetupOutputInformation();
int i;
this->Superclass::SetupOutputData();
// Setup the output arrays.
vtkXMLDataElement* ePointData = this->PPointDataElement;
vtkXMLDataElement* eCellData = this->PCellDataElement;
vtkPointData* pointData = this->GetOutputAsDataSet(0)->GetPointData();
vtkCellData* cellData = this->GetOutputAsDataSet(0)->GetCellData();
vtkCellData* cellData = this->GetOutputAsDataSet(0)->GetCellData();
// Setup the point and cell data arrays without allocation.
// Get the size of the output arrays.
unsigned long pointTuples = this->GetNumberOfPoints();
unsigned long cellTuples = this->GetNumberOfCells();
// Allocate data in the arrays.
int i;
this->SetDataArraySelections(ePointData, this->PointDataArraySelection);
if(ePointData)
{
......@@ -93,20 +99,22 @@ void vtkXMLPDataReader::SetupOutputInformation()
vtkDataArray* array = this->CreateDataArray(eNested);
if(array)
{
array->SetNumberOfTuples(pointTuples);
pointData->AddArray(array);
array->Delete();
}
else
{
this->InformationError = 1;
this->DataError = 1;
}
}
}
}
this->SetDataArraySelections(eCellData, this->CellDataArraySelection);
if(eCellData)
{
for(i=0;i < eCellData->GetNumberOfNestedElements();++i)
for(i = 0; i < eCellData->GetNumberOfNestedElements(); i++)
{
vtkXMLDataElement* eNested = eCellData->GetNestedElement(i);
if(this->CellDataArrayIsEnabled(eNested))
......@@ -114,73 +122,32 @@ void vtkXMLPDataReader::SetupOutputInformation()
vtkDataArray* array = this->CreateDataArray(eNested);
if(array)
{
array->SetNumberOfTuples(cellTuples);
cellData->AddArray(array);
array->Delete();
}
else
{
this->InformationError = 1;
this->DataError = 1;
}
}
}
}
// Setup attribute indices for the point data and cell data.
this->ReadAttributeIndices(ePointData, pointData);
this->ReadAttributeIndices(eCellData, cellData);
}
//----------------------------------------------------------------------------
void vtkXMLPDataReader::SetupOutputData()
{
this->Superclass::SetupOutputData();
vtkDataSet* output = this->GetOutputAsDataSet(0);
vtkXMLDataElement* ePointData = this->PPointDataElement;
vtkXMLDataElement* eCellData = this->PCellDataElement;
vtkPointData* pointData = output->GetPointData();
vtkCellData* cellData = output->GetCellData();
// Get the size of the output arrays.
unsigned long pointTuples = this->GetNumberOfPoints();
unsigned long cellTuples = this->GetNumberOfCells();
// Allocate data in the arrays.
int i;
if(ePointData)
{
int a=0;
for(i=0;i < ePointData->GetNumberOfNestedElements();++i)
{
vtkXMLDataElement* eNested = ePointData->GetNestedElement(i);
if(this->PointDataArrayIsEnabled(eNested))
{
pointData->GetArray(a++)->SetNumberOfTuples(pointTuples);
}
}
}
if(eCellData)
{
int a=0;
for(i=0;i < eCellData->GetNumberOfNestedElements();++i)
{
vtkXMLDataElement* eNested = eCellData->GetNestedElement(i);
if(this->CellDataArrayIsEnabled(eNested))
{
cellData->GetArray(a++)->SetNumberOfTuples(cellTuples);
}
}
}
}
//----------------------------------------------------------------------------
void vtkXMLPDataReader::ReadXMLInformation()
int vtkXMLPDataReader::ReadXMLInformation()
{
// First setup the filename components.
this->SplitFileName();
// Now proceed with reading the information.
this->Superclass::ReadXMLInformation();
return this->Superclass::ReadXMLInformation();
}
//----------------------------------------------------------------------------
......
......@@ -45,11 +45,10 @@ protected:
~vtkXMLPDataReader();
// Pipeline execute information driver. Called by vtkXMLReader.
void ReadXMLInformation();
int ReadXMLInformation();
int ReadPrimaryElement(vtkXMLDataElement* ePrimary);
vtkDataSet* GetPieceInputAsDataSet(int piece);
void SetupOutputInformation();
void SetupOutputData();
virtual vtkXMLDataReader* CreatePieceReader()=0;
......
......@@ -20,19 +20,21 @@
#include "vtkPointData.h"
#include "vtkXMLDataElement.h"
#include "vtkXMLImageDataReader.h"
#include "vtkInformation.h"
#include "vtkStreamingDemandDrivenPipeline.h"
vtkCxxRevisionMacro(vtkXMLPImageDataReader, "1.4");
vtkCxxRevisionMacro(vtkXMLPImageDataReader, "1.5");
vtkStandardNewMacro(vtkXMLPImageDataReader);
//----------------------------------------------------------------------------
vtkXMLPImageDataReader::vtkXMLPImageDataReader()
{
// Copied from vtkImageDataReader constructor:
this->SetOutput(vtkImageData::New());
vtkImageData *output = vtkImageData::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();
}
//----------------------------------------------------------------------------
......@@ -49,23 +51,19 @@ void vtkXMLPImageDataReader::PrintSelf(ostream& os, vtkIndent indent)
//----------------------------------------------------------------------------
void vtkXMLPImageDataReader::SetOutput(vtkImageData *output)
{
this->Superclass::SetNthOutput(0, output);
this->GetExecutive()->SetOutputData(0, output);
}
//----------------------------------------------------------------------------
vtkImageData* vtkXMLPImageDataReader::GetOutput()
{
if(this->NumberOfOutputs < 1)
{
return 0;
}
return static_cast<vtkImageData*>(this->Outputs[0]);
return this->GetOutput(0);
}
//----------------------------------------------------------------------------
vtkImageData* vtkXMLPImageDataReader::GetOutput(int idx)
{
return static_cast<vtkImageData*>(this->Superclass::GetOutput(idx));
return vtkImageData::SafeDownCast( this->GetOutputDataObject(idx) );
}
//----------------------------------------------------------------------------
......@@ -119,21 +117,38 @@ int vtkXMLPImageDataReader::ReadPrimaryElement(vtkXMLDataElement* ePrimary)
}
//----------------------------------------------------------------------------
void vtkXMLPImageDataReader::SetupOutputInformation()
void vtkXMLPImageDataReader::SetupOutputInformation(vtkInformation *outInfo)
{
this->Superclass::SetupOutputInformation();
vtkImageData* output = this->GetOutput();
output->SetOrigin(this->Origin);
output->SetSpacing(this->Spacing);
this->Superclass::SetupOutputInformation(outInfo);
// Backward-compatability support for scalar information in output.
vtkDataArray* scalars = output->GetPointData()->GetScalars();
if(scalars)
outInfo->Set(vtkDataObject::ORIGIN(), this->Origin, 3);
outInfo->Set(vtkDataObject::SPACING(), this->Spacing, 3);
// Backward-compatability support for scalar information in output.
if (this->PPointDataElement)
{
output->SetScalarType(scalars->GetDataType());
output->SetNumberOfScalarComponents(scalars->GetNumberOfComponents());
}
int i, components, dataType;
for(i = 0; i < this->PPointDataElement->GetNumberOfNestedElements(); i++)
{
vtkXMLDataElement* eNested = this->PPointDataElement->GetNestedElement(i);
if ( eNested->GetAttribute( "Scalars" ) )
{
if (!eNested->GetWordTypeAttribute("type", dataType))
{
this->InformationError = 1;
return;
}
if (!eNested->GetScalarAttribute("NumberOfComponents", components))
{
this->InformationError = 1;
return;
}
outInfo->Set(vtkDataObject::SCALAR_TYPE(), dataType);
outInfo->Set(vtkDataObject::SCALAR_NUMBER_OF_COMPONENTS(), components);
break;
}
}
}
}
//----------------------------------------------------------------------------
......
......@@ -56,7 +56,7 @@ protected:
void SetOutputExtent(int* extent);
void GetPieceInputExtent(int index, int* extent);
int ReadPrimaryElement(vtkXMLDataElement* ePrimary);
void SetupOutputInformation();
void SetupOutputInformation(vtkInformation *outInfo);
vtkXMLDataReader* CreatePieceReader();
private:
......
......@@ -19,19 +19,21 @@
#include "vtkPolyData.h"
#include "vtkUnsignedCharArray.h"
#include "vtkCellArray.h"
#include "vtkStreamingDemandDrivenPipeline.h"
vtkCxxRevisionMacro(vtkXMLPPolyDataReader, "1.4");
vtkCxxRevisionMacro(vtkXMLPPolyDataReader, "1.5");
vtkStandardNewMacro(vtkXMLPPolyDataReader);
//----------------------------------------------------------------------------
vtkXMLPPolyDataReader::vtkXMLPPolyDataReader()
{
// Copied from vtkPolyDataReader constructor:
this->SetOutput(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();
}
//----------------------------------------------------------------------------
......@@ -48,23 +50,19 @@ void vtkXMLPPolyDataReader::PrintSelf(ostream& os, vtkIndent indent)
//----------------------------------------------------------------------------
void vtkXMLPPolyDataReader::SetOutput(vtkPolyData *output)
{
this->Superclass::SetNthOutput(0, output);
this->GetExecutive()->SetOutputData(0, output);
}
//----------------------------------------------------------------------------
vtkPolyData* vtkXMLPPolyDataReader::GetOutput()
{
if(this->NumberOfOutputs < 1)
{
return 0;
}
return static_cast<vtkPolyData*>(this->Outputs[0]);
return this->GetOutput(0);
}
//----------------------------------------------------------------------------
vtkPolyData* vtkXMLPPolyDataReader::GetOutput(int idx)
{
return static_cast<vtkPolyData*>(this->Superclass::GetOutput(idx));
return vtkPolyData::SafeDownCast( this->GetOutputDataObject(idx) );
}
//----------------------------------------------------------------------------
......
......@@ -19,19 +19,21 @@
#include "vtkRectilinearGrid.h"
#include "vtkXMLDataElement.h"
#include "vtkXMLRectilinearGridReader.h"
#include "vtkStreamingDemandDrivenPipeline.h"
vtkCxxRevisionMacro(vtkXMLPRectilinearGridReader, "1.8");
vtkCxxRevisionMacro(vtkXMLPRectilinearGridReader, "1.9");
vtkStandardNewMacro(vtkXMLPRectilinearGridReader);
//----------------------------------------------------------------------------
vtkXMLPRectilinearGridReader::vtkXMLPRectilinearGridReader()
{
// Copied from vtkRectilinearGridReader constructor:
this->SetOutput(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();
}
//----------------------------------------------------------------------------
......@@ -48,23 +50,19 @@ void vtkXMLPRectilinearGridReader::PrintSelf(ostream& os, vtkIndent indent)
//----------------------------------------------------------------------------
void vtkXMLPRectilinearGridReader::SetOutput(vtkRectilinearGrid *output)
{
this->Superclass::SetNthOutput(0, output);
this->GetExecutive()->SetOutputData(0, output);
}
//----------------------------------------------------------------------------
vtkRectilinearGrid* vtkXMLPRectilinearGridReader::GetOutput()
{
if(this->NumberOfOutputs < 1)
{
return 0;
}
return static_cast<vtkRectilinearGrid*>(this->Outputs[0]);
return this->GetOutput(0);
}
//----------------------------------------------------------------------------
vtkRectilinearGrid* vtkXMLPRectilinearGridReader::GetOutput(int idx)
{
return static_cast<vtkRectilinearGrid*>(this->Superclass::GetOutput(idx));
return vtkRectilinearGrid::SafeDownCast( this->GetOutputDataObject(idx) );
}
//----------------------------------------------------------------------------
......@@ -129,27 +127,34 @@ vtkXMLPRectilinearGridReader::ReadPrimaryElement(vtkXMLDataElement* ePrimary)