Commit dd39b9e4 authored by Brad King's avatar Brad King

ENH: Added progress implementation to rest of XML serial readers.

parent 380c0813
......@@ -23,7 +23,7 @@
#include "vtkUnsignedCharArray.h"
#include "vtkCellArray.h"
vtkCxxRevisionMacro(vtkXMLPolyDataReader, "1.2");
vtkCxxRevisionMacro(vtkXMLPolyDataReader, "1.3");
vtkStandardNewMacro(vtkXMLPolyDataReader);
//----------------------------------------------------------------------------
......@@ -184,6 +184,15 @@ void vtkXMLPolyDataReader::DestroyPieces()
this->Superclass::DestroyPieces();
}
//----------------------------------------------------------------------------
vtkIdType vtkXMLPolyDataReader::GetNumberOfCellsInPiece(int piece)
{
return (this->NumberOfVerts[piece]+
this->NumberOfLines[piece]+
this->NumberOfStrips[piece]+
this->NumberOfPolys[piece]);
}
//----------------------------------------------------------------------------
void vtkXMLPolyDataReader::SetupOutputData()
{
......@@ -276,10 +285,55 @@ void vtkXMLPolyDataReader::SetupNextPiece()
//----------------------------------------------------------------------------
int vtkXMLPolyDataReader::ReadPieceData()
{
// The amount of data read by the superclass's ReadPieceData comes
// from point/cell data and point specifications (we read cell
// specifications here).
vtkIdType superclassPieceSize =
((this->NumberOfPointArrays+1)*this->GetNumberOfPointsInPiece(this->Piece)+
this->NumberOfCellArrays*this->GetNumberOfCellsInPiece(this->Piece));
// Total amount of data in this piece comes from point/cell data
// arrays and the point/cell specifications themselves (cell
// specifications for vtkPolyData take two data arrays split across
// cell types).
vtkIdType totalPieceSize =
superclassPieceSize + 2*this->GetNumberOfCellsInPiece(this->Piece);
if(totalPieceSize == 0)
{
totalPieceSize = 1;
}
// Split the progress range based on the approximate fraction of
// data that will be read by each step in this method.
float progressRange[2] = {0,0};
this->GetProgressRange(progressRange);
float fractions[6] =
{
0,
float(superclassPieceSize) / totalPieceSize,
(float(superclassPieceSize)+
this->NumberOfVerts[this->Piece]) / totalPieceSize,
(float(superclassPieceSize)+
this->NumberOfVerts[this->Piece]+
this->NumberOfLines[this->Piece]) / totalPieceSize,
(float(superclassPieceSize)+
this->NumberOfVerts[this->Piece]+
this->NumberOfLines[this->Piece]+
this->NumberOfStrips[this->Piece]) / totalPieceSize,
1
};
// Set the range of progress for the superclass.
this->SetProgressRange(progressRange, 0, fractions);
// Let the superclass read its data.
if(!this->Superclass::ReadPieceData()) { return 0; }
vtkPolyData* output = this->GetOutput();
// Set the range of progress for the Verts.
this->SetProgressRange(progressRange, 1, fractions);
// Read the Verts.
if(!this->ReadCellArray(this->NumberOfVerts[this->Piece],
this->TotalNumberOfVerts,
......@@ -289,6 +343,9 @@ int vtkXMLPolyDataReader::ReadPieceData()
return 0;
}
// Set the range of progress for the Lines.
this->SetProgressRange(progressRange, 2, fractions);
// Read the Lines.
if(!this->ReadCellArray(this->NumberOfLines[this->Piece],
this->TotalNumberOfLines,
......@@ -298,6 +355,9 @@ int vtkXMLPolyDataReader::ReadPieceData()
return 0;
}
// Set the range of progress for the Strips.
this->SetProgressRange(progressRange, 3, fractions);
// Read the Strips.
if(!this->ReadCellArray(this->NumberOfStrips[this->Piece],
this->TotalNumberOfStrips,
......@@ -307,6 +367,9 @@ int vtkXMLPolyDataReader::ReadPieceData()
return 0;
}
// Set the range of progress for the Polys.
this->SetProgressRange(progressRange, 4, fractions);
// Read the Polys.
if(!this->ReadCellArray(this->NumberOfPolys[this->Piece],
this->TotalNumberOfPolys,
......@@ -323,8 +386,27 @@ int vtkXMLPolyDataReader::ReadPieceData()
int vtkXMLPolyDataReader::ReadArrayForCells(vtkXMLDataElement* da,
vtkDataArray* outArray)
{
// Split progress range according to the fraction of data that will
// be read for each type of cell.
float progressRange[2] = {0,0};
this->GetProgressRange(progressRange);
float fractions[5] =
{
0,
float(this->NumberOfVerts[this->Piece])/this->TotalNumberOfCells,
float(this->NumberOfVerts[this->Piece]+
this->NumberOfLines[this->Piece])/this->TotalNumberOfCells,
float(this->NumberOfVerts[this->Piece]+
this->NumberOfLines[this->Piece]+
this->NumberOfStrips[this->Piece])/this->TotalNumberOfCells,
1
};
vtkIdType components = outArray->GetNumberOfComponents();
// Set range of progress for the Verts.
this->SetProgressRange(progressRange, 0, fractions);
// Read the cell data for the Verts in the piece.
vtkIdType inStartCell = 0;
vtkIdType outStartCell = this->StartVert;
......@@ -333,6 +415,9 @@ int vtkXMLPolyDataReader::ReadArrayForCells(vtkXMLDataElement* da,
outArray->GetDataType(), inStartCell*components,
numCells*components)) { return 0; }
// Set range of progress for the Lines.
this->SetProgressRange(progressRange, 1, fractions);
// Read the cell data for the Lines in the piece.
inStartCell += numCells;
outStartCell = this->TotalNumberOfVerts + this->StartLine;
......@@ -341,6 +426,9 @@ int vtkXMLPolyDataReader::ReadArrayForCells(vtkXMLDataElement* da,
outArray->GetDataType(), inStartCell*components,
numCells*components)) { return 0; }
// Set range of progress for the Strips.
this->SetProgressRange(progressRange, 2, fractions);
// Read the cell data for the Strips in the piece.
inStartCell += numCells;
outStartCell = (this->TotalNumberOfVerts + this->TotalNumberOfLines +
......@@ -350,6 +438,9 @@ int vtkXMLPolyDataReader::ReadArrayForCells(vtkXMLDataElement* da,
outArray->GetDataType(), inStartCell*components,
numCells*components)) { return 0; }
// Set range of progress for the Polys.
this->SetProgressRange(progressRange, 3, fractions);
// Read the cell data for the Polys in the piece.
inStartCell += numCells;
outStartCell = (this->TotalNumberOfVerts + this->TotalNumberOfLines +
......
......@@ -71,6 +71,10 @@ protected:
// Read a data array whose tuples coorrespond to cells.
int ReadArrayForCells(vtkXMLDataElement* da, vtkDataArray* outArray);
// Get the number of cells in the given piece. Valid after
// UpdateInformation.
virtual vtkIdType GetNumberOfCellsInPiece(int piece);
// The size of the UpdatePiece.
int TotalNumberOfVerts;
int TotalNumberOfLines;
......
......@@ -32,7 +32,7 @@
#include <sys/stat.h>
vtkCxxRevisionMacro(vtkXMLReader, "1.9");
vtkCxxRevisionMacro(vtkXMLReader, "1.10");
//----------------------------------------------------------------------------
vtkXMLReader::vtkXMLReader()
......@@ -717,11 +717,12 @@ void vtkXMLReader::SetProgressRange(float* range, int curStep, int numSteps)
}
//----------------------------------------------------------------------------
void vtkXMLReader::SetProgressRange(float* range, float* fractions, int step)
void vtkXMLReader::SetProgressRange(float* range, int curStep,
float* fractions)
{
float width = range[1] - range[0];
this->ProgressRange[0] = range[0] + fractions[step]*width;
this->ProgressRange[1] = range[0] + fractions[step+1]*width;
this->ProgressRange[0] = range[0] + fractions[curStep]*width;
this->ProgressRange[1] = range[0] + fractions[curStep+1]*width;
this->UpdateProgressDiscrete(this->ProgressRange[0]);
}
......
......@@ -188,7 +188,7 @@ protected:
// incrementally fine-tuned progress updates.
virtual void GetProgressRange(float* range);
virtual void SetProgressRange(float* range, int curStep, int numSteps);
virtual void SetProgressRange(float* range, float* fractions, int step);
virtual void SetProgressRange(float* range, int curStep, float* fractions);
virtual void UpdateProgressDiscrete(float progress);
float ProgressRange[2];
......
......@@ -23,7 +23,7 @@
#include "vtkXMLDataElement.h"
#include "vtkXMLDataParser.h"
vtkCxxRevisionMacro(vtkXMLRectilinearGridReader, "1.7");
vtkCxxRevisionMacro(vtkXMLRectilinearGridReader, "1.8");
vtkStandardNewMacro(vtkXMLRectilinearGridReader);
//----------------------------------------------------------------------------
......@@ -189,23 +189,77 @@ void vtkXMLRectilinearGridReader::SetupOutputData()
//----------------------------------------------------------------------------
int vtkXMLRectilinearGridReader::ReadPieceData()
{
// The amount of data read by the superclass's ReadPieceData comes
// from point/cell data (we read point specifications here).
int dims[3] = {0,0,0};
this->ComputeDimensions(this->SubExtent, dims, 1);
vtkIdType superclassPieceSize =
(this->NumberOfPointArrays*dims[0]*dims[1]*dims[2]+
this->NumberOfCellArrays*(dims[0]-1)*(dims[1]-1)*(dims[2]-1));
// Total amount of data in this piece comes from point/cell data
// arrays and the point specifications themselves.
vtkIdType totalPieceSize =
superclassPieceSize + dims[0] + dims[1] + dims[2];
if(totalPieceSize == 0)
{
totalPieceSize = 1;
}
// Split the progress range based on the approximate fraction of
// data that will be read by each step in this method.
float progressRange[2] = {0,0};
this->GetProgressRange(progressRange);
float fractions[5] =
{
0,
float(superclassPieceSize) / totalPieceSize,
(float(superclassPieceSize)+dims[0]) / totalPieceSize,
(float(superclassPieceSize)+dims[1]+dims[2]) / totalPieceSize,
1
};
// Set the range of progress for the superclass.
this->SetProgressRange(progressRange, 0, fractions);
// Let the superclass read its data.
if(!this->Superclass::ReadPieceData()) { return 0; }
int index=this->Piece;
vtkXMLDataElement* xc = this->CoordinateElements[index]->GetNestedElement(0);
vtkXMLDataElement* yc = this->CoordinateElements[index]->GetNestedElement(1);
vtkXMLDataElement* zc = this->CoordinateElements[index]->GetNestedElement(2);
int* pieceExtent = this->PieceExtents + index*6;
vtkRectilinearGrid* output = this->GetOutput();
return
int result = 1;
// Set the range of progress for the X coordinates array.
this->SetProgressRange(progressRange, 1, fractions);
if(result)
{
this->ReadSubCoordinates(pieceExtent, this->UpdateExtent,
this->SubExtent, xc,
output->GetXCoordinates()) &&
output->GetXCoordinates());
}
// Set the range of progress for the Y coordinates array.
this->SetProgressRange(progressRange, 2, fractions);
if(result)
{
this->ReadSubCoordinates(pieceExtent+2, this->UpdateExtent+2,
this->SubExtent+2, yc,
output->GetYCoordinates()) &&
output->GetYCoordinates());
}
// Set the range of progress for the Z coordinates array.
this->SetProgressRange(progressRange, 3, fractions);
if(result)
{
this->ReadSubCoordinates(pieceExtent+4, this->UpdateExtent+4,
this->SubExtent+4, zc,
output->GetZCoordinates());
}
return result;
}
//----------------------------------------------------------------------------
......
......@@ -22,7 +22,7 @@
#include "vtkXMLDataElement.h"
#include "vtkXMLDataParser.h"
vtkCxxRevisionMacro(vtkXMLStructuredDataReader, "1.6");
vtkCxxRevisionMacro(vtkXMLStructuredDataReader, "1.7");
//----------------------------------------------------------------------------
vtkXMLStructuredDataReader::vtkXMLStructuredDataReader()
......@@ -213,6 +213,10 @@ void vtkXMLStructuredDataReader::ReadXMLData()
fractions[i+1] = fractions[i] + pieceDims[0]*pieceDims[1]*pieceDims[2];
}
}
if(fractions[this->NumberOfPieces] == 0)
{
fractions[this->NumberOfPieces] = 1;
}
for(i=1;i <= this->NumberOfPieces;++i)
{
fractions[i] = fractions[i] / fractions[this->NumberOfPieces];
......@@ -222,7 +226,7 @@ void vtkXMLStructuredDataReader::ReadXMLData()
for(i=0;i < this->NumberOfPieces;++i)
{
// Set the range of progress for this piece.
this->SetProgressRange(progressRange, fractions, i);
this->SetProgressRange(progressRange, i, fractions);
// Intersect the extents to get the part we need to read.
int* pieceExtent = this->PieceExtents + i*6;
......
......@@ -22,7 +22,7 @@
#include "vtkXMLDataElement.h"
#include "vtkXMLDataParser.h"
vtkCxxRevisionMacro(vtkXMLStructuredGridReader, "1.6");
vtkCxxRevisionMacro(vtkXMLStructuredGridReader, "1.7");
vtkStandardNewMacro(vtkXMLStructuredGridReader);
//----------------------------------------------------------------------------
......@@ -179,6 +179,38 @@ void vtkXMLStructuredGridReader::SetupOutputData()
//----------------------------------------------------------------------------
int vtkXMLStructuredGridReader::ReadPieceData()
{
// The amount of data read by the superclass's ReadPieceData comes
// from point/cell data (we read point specifications here).
int dims[3] = {0,0,0};
this->ComputeDimensions(this->SubExtent, dims, 1);
vtkIdType superclassPieceSize =
(this->NumberOfPointArrays*dims[0]*dims[1]*dims[2]+
this->NumberOfCellArrays*(dims[0]-1)*(dims[1]-1)*(dims[2]-1));
// Total amount of data in this piece comes from point/cell data
// arrays and the point specifications themselves.
vtkIdType totalPieceSize =
superclassPieceSize + dims[0]*dims[1]*dims[2];
if(totalPieceSize == 0)
{
totalPieceSize = 1;
}
// Split the progress range based on the approximate fraction of
// data that will be read by each step in this method.
float progressRange[2] = {0,0};
this->GetProgressRange(progressRange);
float fractions[3] =
{
0,
float(superclassPieceSize) / totalPieceSize,
1
};
// Set the range of progress for the superclass.
this->SetProgressRange(progressRange, 0, fractions);
// Let the superclass read its data.
if(!this->Superclass::ReadPieceData()) { return 0; }
if(!this->PointElements[this->Piece])
......@@ -187,6 +219,9 @@ int vtkXMLStructuredGridReader::ReadPieceData()
return 1;
}
// Set the range of progress for the points array.
this->SetProgressRange(progressRange, 1, fractions);
// Read the points array.
vtkStructuredGrid* output = this->GetOutput();
vtkXMLDataElement* ePoints = this->PointElements[this->Piece];
......
......@@ -24,7 +24,7 @@
#include "vtkCellArray.h"
#include "vtkPointSet.h"
vtkCxxRevisionMacro(vtkXMLUnstructuredDataReader, "1.6");
vtkCxxRevisionMacro(vtkXMLUnstructuredDataReader, "1.7");
//----------------------------------------------------------------------------
vtkXMLUnstructuredDataReader::vtkXMLUnstructuredDataReader()
......@@ -242,10 +242,35 @@ void vtkXMLUnstructuredDataReader::ReadXMLData()
// Let superclasses read data. This also allocates output data.
this->Superclass::ReadXMLData();
// Read the data needed from each piece.
// Split current progress range based on fraction contributed by
// each piece.
float progressRange[2] = {0,0};
this->GetProgressRange(progressRange);
// Calculate the cumulative fraction of data contributed by each
// piece (for progress).
float* fractions = new float[this->EndPiece-this->StartPiece+1];
int i;
fractions[0] = 0;
for(i=this->StartPiece; i < this->EndPiece; ++i)
{
int index = i-this->StartPiece;
fractions[index+1] = (fractions[index] +
this->GetNumberOfPointsInPiece(i) +
this->GetNumberOfCellsInPiece(i));
}
for(i=this->StartPiece; i < this->EndPiece; ++i)
{
int index = i-this->StartPiece;
fractions[index+1] = fractions[index+1] / fractions[this->EndPiece-this->StartPiece];
}
// Read the data needed from each piece.
for(i=this->StartPiece; i < this->EndPiece; ++i)
{
// Set the range of progress for this piece.
this->SetProgressRange(progressRange, i-this->StartPiece, fractions);
if(!this->Superclass::ReadPieceData(i))
{
// An error occurred while reading the piece.
......@@ -253,6 +278,8 @@ void vtkXMLUnstructuredDataReader::ReadXMLData()
}
this->SetupNextPiece();
}
delete [] fractions;
}
//----------------------------------------------------------------------------
......@@ -291,6 +318,12 @@ vtkIdType vtkXMLUnstructuredDataReader::GetNumberOfCells()
return this->TotalNumberOfCells;
}
//----------------------------------------------------------------------------
vtkIdType vtkXMLUnstructuredDataReader::GetNumberOfPointsInPiece(int piece)
{
return this->NumberOfPoints[piece];
}
//----------------------------------------------------------------------------
void vtkXMLUnstructuredDataReader::SetupOutputInformation()
{
......@@ -378,10 +411,43 @@ int vtkXMLUnstructuredDataReader::ReadPiece(vtkXMLDataElement* ePiece)
//----------------------------------------------------------------------------
int vtkXMLUnstructuredDataReader::ReadPieceData()
{
// The amount of data read by the superclass's ReadPieceData comes
// from point/cell data (we read point specifications here).
vtkIdType superclassPieceSize =
(this->NumberOfPointArrays*this->GetNumberOfPointsInPiece(this->Piece)+
this->NumberOfCellArrays*this->GetNumberOfCellsInPiece(this->Piece));
// Total amount of data in this piece comes from point/cell data
// arrays and the point specifications themselves.
vtkIdType totalPieceSize =
superclassPieceSize + 1*this->GetNumberOfPointsInPiece(this->Piece);
if(totalPieceSize == 0)
{
totalPieceSize = 1;
}
// Split the progress range based on the approximate fraction of
// data that will be read by each step in this method.
float progressRange[2] = {0,0};
this->GetProgressRange(progressRange);
float fractions[3] =
{
0,
float(superclassPieceSize)/totalPieceSize,
1
};
// Set the range of progress for the superclass.
this->SetProgressRange(progressRange, 0, fractions);
// Let the superclass read its data.
if(!this->Superclass::ReadPieceData()) { return 0; }
vtkPointSet* output = this->GetOutputAsPointSet();
// Set the range of progress for the Points.
this->SetProgressRange(progressRange, 1, fractions);
// Read the points array.
vtkXMLDataElement* ePoints = this->PointElements[this->Piece];
if(ePoints)
......@@ -414,6 +480,17 @@ int vtkXMLUnstructuredDataReader::ReadCellArray(vtkIdType numberOfCells,
}
}
// Split progress range into 1/5 for offsets array and 4/5 for
// connectivity array. This assumes an average of 4 points per
// cell. Unfortunately, we cannot know the length of the
// connectivity array ahead of time to calculate the real fraction.
float progressRange[2] = {0,0};
this->GetProgressRange(progressRange);
float fractions[3] = {0, 0.2, 1};
// Set range of progress for offsets array.
this->SetProgressRange(progressRange, 0, fractions);
// Read the cell offsets.
vtkXMLDataElement* eOffsets = this->FindDataArrayWithName(eCells, "offsets");
if(!eOffsets)
......@@ -451,7 +528,10 @@ int vtkXMLUnstructuredDataReader::ReadCellArray(vtkIdType numberOfCells,
return 0;
}
// Read the cell points.
// Set range of progress for connectivity array.
this->SetProgressRange(progressRange, 1, fractions);
// Read the cell point connectivity array.
vtkIdType cpLength = cellOffsets->GetValue(numberOfCells-1);
vtkXMLDataElement* eConn = this->FindDataArrayWithName(eCells, "connectivity");
if(!eConn)
......@@ -459,6 +539,7 @@ int vtkXMLUnstructuredDataReader::ReadCellArray(vtkIdType numberOfCells,
vtkErrorMacro("Cannot read cell connectivity from " << eCells->GetName()
<< " in piece " << this->Piece
<< " because the \"connectivity\" array could not be found.");
cellOffsets->Delete();
return 0;
}
vtkDataArray* c0 = this->CreateDataArray(eConn);
......@@ -468,6 +549,7 @@ int vtkXMLUnstructuredDataReader::ReadCellArray(vtkIdType numberOfCells,
<< " in piece " << this->Piece
<< " because the \"connectivity\" array could not be created"
<< " with one component.");
cellOffsets->Delete();
return 0;
}
c0->SetNumberOfTuples(cpLength);
......@@ -477,6 +559,7 @@ int vtkXMLUnstructuredDataReader::ReadCellArray(vtkIdType numberOfCells,
vtkErrorMacro("Cannot read cell connectivity from " << eCells->GetName()
<< " in piece " << this->Piece
<< " because the \"connectivity\" array is not long enough.");
cellOffsets->Delete();
return 0;
}
vtkIdTypeArray* cellPoints = this->ConvertToIdTypeArray(c0);
......@@ -486,6 +569,7 @@ int vtkXMLUnstructuredDataReader::ReadCellArray(vtkIdType numberOfCells,
<< " in piece " << this->Piece
<< " because the \"connectivity\" array could not be"
<< " converted to a vtkIdTypeArray.");
cellOffsets->Delete();
return 0;
}
......
......@@ -85,6 +85,11 @@ protected:
// Read a data array whose tuples coorrespond to points.
int ReadArrayForPoints(vtkXMLDataElement* da, vtkDataArray* outArray);
// Get the number of points/cells in the given piece. Valid after
// UpdateInformation.
virtual vtkIdType GetNumberOfPointsInPiece(int piece);
virtual vtkIdType GetNumberOfCellsInPiece(int piece)=0;
// The update request.
int UpdatePiece;
int UpdateNumberOfPieces;
......
......@@ -24,7 +24,7 @@
#include "vtkUnstructuredGrid.h"
#include "vtkXMLDataElement.h"
vtkCxxRevisionMacro(vtkXMLUnstructuredGridReader, "1.4");
vtkCxxRevisionMacro(vtkXMLUnstructuredGridReader, "1.5");
vtkStandardNewMacro(vtkXMLUnstructuredGridReader);
//----------------------------------------------------------------------------
......@@ -126,6 +126,12 @@ void vtkXMLUnstructuredGridReader::DestroyPieces()
this->Superclass::DestroyPieces();
}
//----------------------------------------------------------------------------
vtkIdType vtkXMLUnstructuredGridReader::GetNumberOfCellsInPiece(int piece)
{
return this->NumberOfCells[piece];
}
//----------------------------------------------------------------------------
void vtkXMLUnstructuredGridReader::SetupOutputData()
{
......@@ -194,6 +200,42 @@ void vtkXMLUnstructuredGridReader::SetupNextPiece()
//----------------------------------------------------------------------------
int vtkXMLUnstructuredGridReader::ReadPieceData()
{
// The amount of data read by the superclass's ReadPieceData comes
// from point/cell data and point specifications (we read cell
// specifications here).
vtkIdType superclassPieceSize =
((this->NumberOfPointArrays+1)*this->GetNumberOfPointsInPiece(this->Piece)+
this->NumberOfCellArrays*this->GetNumberOfCellsInPiece(this->Piece));
// Total amount of data in this piece comes from point/cell data
// arrays and the point/cell specifications themselves (cell
// specifications for vtkUnstructuredGrid take three data arrays).
vtkIdType totalPieceSize =
superclassPieceSize + 3*this->GetNumberOfCellsInPiece(this->Piece);
if(totalPieceSize == 0)
{
totalPieceSize = 1;
}
// Split the progress range based on the approximate fraction of