Commit df378240 authored by Brad King's avatar Brad King 💬
Browse files

ENH: Updated vtkTableExtentTranslator to support providing a different number...

ENH: Updated vtkTableExtentTranslator to support providing a different number of extents than are in the table.  Currently this may not work well when the number of pieces requested is greater than one but less than the number of pieces in the table.  Not all data will be returned in this case.
parent 531e8af0
......@@ -15,7 +15,7 @@
#include "vtkTableExtentTranslator.h"
#include "vtkObjectFactory.h"
vtkCxxRevisionMacro(vtkTableExtentTranslator, "1.5");
vtkCxxRevisionMacro(vtkTableExtentTranslator, "1.6");
vtkStandardNewMacro(vtkTableExtentTranslator);
//----------------------------------------------------------------------------
......@@ -83,26 +83,27 @@ void vtkTableExtentTranslator::PrintSelf(ostream& os, vtkIndent indent)
//----------------------------------------------------------------------------
void vtkTableExtentTranslator::SetNumberOfPieces(int pieces)
{
// Make sure we are really changing the number of pieces.
if(this->NumberOfPieces == pieces)
// Allocate a table for this number of pieces.
if(this->NumberOfPiecesInTable == 0)
{
return;
this->SetNumberOfPiecesInTable(pieces);
}
// Cannot change the number of pieces between two non-zero values.
// If a pipeline tries to use this extent translator with any number
// of pieces but that stored in our table, it is an error, and
// another extent translator should be used.
if((this->NumberOfPieces != 0) && (pieces != 0))
this->Superclass::SetNumberOfPieces(pieces);
}
//----------------------------------------------------------------------------
void vtkTableExtentTranslator::SetNumberOfPiecesInTable(int pieces)
{
// Make sure we are really changing the number of pieces.
if(this->NumberOfPiecesInTable == pieces)
{
vtkErrorMacro("Cannot change the number of pieces from "
<< this->NumberOfPieces << " to " << pieces);
return;
}
// Actually set the NumberOfPieces data member.
}
// The default number of pieces returned is the real number of
// pieces.
this->Superclass::SetNumberOfPieces(pieces);
// Clean out any old extent table.
if(this->ExtentTable)
{
......@@ -117,12 +118,12 @@ void vtkTableExtentTranslator::SetNumberOfPieces(int pieces)
// Create and initialize a new extent table if there are any pieces.
// Assume all pieces are available.
if(this->NumberOfPieces > 0)
if(this->NumberOfPiecesInTable > 0)
{
this->ExtentTable = new int[this->NumberOfPieces*6];
this->PieceAvailable = new int[this->NumberOfPieces*6];
this->ExtentTable = new int[this->NumberOfPiecesInTable*6];
this->PieceAvailable = new int[this->NumberOfPiecesInTable];
int i;
for(i=0;i < this->NumberOfPieces;++i)
for(i=0;i < this->NumberOfPiecesInTable;++i)
{
int* extent = this->ExtentTable + i*6;
extent[0] = extent[2] = extent[4] = 0;
......@@ -135,7 +136,8 @@ void vtkTableExtentTranslator::SetNumberOfPieces(int pieces)
//----------------------------------------------------------------------------
void vtkTableExtentTranslator::SetExtentForPiece(int piece, int* extent)
{
if((!this->ExtentTable) || (piece < 0) || (piece >= this->NumberOfPieces))
if((!this->ExtentTable) || (piece < 0) ||
(piece >= this->NumberOfPiecesInTable))
{
vtkErrorMacro("Piece " << piece << " does not exist.");
return;
......@@ -146,7 +148,8 @@ void vtkTableExtentTranslator::SetExtentForPiece(int piece, int* extent)
//----------------------------------------------------------------------------
void vtkTableExtentTranslator::GetExtentForPiece(int piece, int* extent)
{
if((!this->ExtentTable) || (piece < 0) || (piece >= this->NumberOfPieces))
if((!this->ExtentTable) || (piece < 0) ||
(piece >= this->NumberOfPiecesInTable))
{
vtkErrorMacro("Piece " << piece << " does not exist.");
extent[0] = extent[2] = extent[4] = 0;
......@@ -160,7 +163,8 @@ void vtkTableExtentTranslator::GetExtentForPiece(int piece, int* extent)
int* vtkTableExtentTranslator::GetExtentForPiece(int piece)
{
static int emptyExtent[6] = {0,-1,0,-1,0,-1};
if((!this->ExtentTable) || (piece < 0) || (piece >= this->NumberOfPieces))
if((!this->ExtentTable) || (piece < 0) ||
(piece >= this->NumberOfPiecesInTable))
{
vtkErrorMacro("Piece " << piece << " does not exist.");
return emptyExtent;
......@@ -171,7 +175,8 @@ int* vtkTableExtentTranslator::GetExtentForPiece(int piece)
//----------------------------------------------------------------------------
void vtkTableExtentTranslator::SetPieceAvailable(int piece, int available)
{
if((!this->ExtentTable) || (piece < 0) || (piece >= this->NumberOfPieces))
if((!this->ExtentTable) || (piece < 0) ||
(piece >= this->NumberOfPiecesInTable))
{
vtkErrorMacro("Piece " << piece << " does not exist.");
}
......@@ -181,7 +186,8 @@ void vtkTableExtentTranslator::SetPieceAvailable(int piece, int available)
//----------------------------------------------------------------------------
int vtkTableExtentTranslator::GetPieceAvailable(int piece)
{
if((!this->ExtentTable) || (piece < 0) || (piece >= this->NumberOfPieces))
if((!this->ExtentTable) || (piece < 0) ||
(piece >= this->NumberOfPiecesInTable))
{
vtkErrorMacro("Piece " << piece << " does not exist.");
return 0;
......@@ -225,9 +231,28 @@ vtkTableExtentTranslator::PieceToExtentThreadSafe(int piece, int numPieces,
<< this->MaximumGhostLevel << ". Using the maximum.");
ghostLevel = this->MaximumGhostLevel;
}
memcpy(resultExtent, this->ExtentTable+piece*6, sizeof(int)*6);
if(numPieces == 1)
{
// The number of pieces requested is one. Return the whole extent.
memcpy(resultExtent, wholeExtent, sizeof(int)*6);
}
else if(piece < this->NumberOfPiecesInTable)
{
// The requested piece is beyond the table. Return an empty extent.
resultExtent[0] = 0;
resultExtent[1] = -1;
resultExtent[2] = 0;
resultExtent[3] = -1;
resultExtent[4] = 0;
resultExtent[5] = -1;
}
else
{
// Return the extent from the table entry.
memcpy(resultExtent, this->ExtentTable+piece*6, sizeof(int)*6);
}
if(((resultExtent[1] - resultExtent[0] + 1)*
(resultExtent[3] - resultExtent[2] + 1)*
(resultExtent[5] - resultExtent[4] + 1)) == 0)
......
......@@ -34,12 +34,19 @@ public:
static vtkTableExtentTranslator* New();
// Description:
// Set the number of pieces in the extent table. Once set to a
// non-zero value, this can only be called to change back to zero,
// or with the same number of pieces. This prevents a pipeline from
// using this extent translator to get any pieces that don't match
// the table.
// Set the number of pieces into which the whole extent will be
// split. If this is 1 then the whole extent will be returned. If
// this is more than the number of pieces in the table then the
// extra pieces will be empty data. If this is more than one but
// less than the number of pieces in the table then only this many
// pieces will be returned (FIXME).
void SetNumberOfPieces(int pieces);
// Description:
// Set the real number of pieces in the extent table.
void SetNumberOfPiecesInTable(int pieces);
vtkGetMacro(NumberOfPiecesInTable, int);
// Description:
// Called to translate the current piece into an extent. This is
......@@ -88,6 +95,7 @@ protected:
// Store the extent table in a single array. Every 6 values form an extent.
int* ExtentTable;
int NumberOfPiecesInTable;
int MaximumGhostLevel;
// Store a flag for the availability of each piece.
......
......@@ -21,7 +21,7 @@
#include "vtkXMLDataElement.h"
#include "vtkXMLStructuredDataReader.h"
vtkCxxRevisionMacro(vtkXMLPStructuredDataReader, "1.13");
vtkCxxRevisionMacro(vtkXMLPStructuredDataReader, "1.14");
//----------------------------------------------------------------------------
vtkXMLPStructuredDataReader::vtkXMLPStructuredDataReader()
......@@ -201,7 +201,7 @@ void vtkXMLPStructuredDataReader::SetupEmptyOutput()
void vtkXMLPStructuredDataReader::SetupPieces(int numPieces)
{
this->Superclass::SetupPieces(numPieces);
this->ExtentTranslator->SetNumberOfPieces(this->NumberOfPieces);
this->ExtentTranslator->SetNumberOfPiecesInTable(this->NumberOfPieces);
this->ExtentTranslator->SetMaximumGhostLevel(this->GhostLevel);
this->PieceExtents = new int[6*this->NumberOfPieces];
int i;
......
Supports Markdown
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