Commit 8f4abc01 authored by Brad King's avatar Brad King 💬
Browse files

ENH: Moved ghost level array generation in structured output from duplicated...

ENH: Moved ghost level array generation in structured output from duplicated UpdateData methods in the structured data objects to a single GenerateGhostLevelArray method in vtkDataSet.  This is now possible because the extent is stored in the information object on each data object.  This code is now called by vtkSource at the end of UpdateData.  Similarly the call to Crop() was moved from vtkDataObject::UpdateData to the end of vtkSource::UpdateData.
parent fd852c30
......@@ -28,7 +28,7 @@
#include "vtkInformationIntegerVectorKey.h"
#include "vtkInformationStringKey.h"
vtkCxxRevisionMacro(vtkDataObject, "1.116");
vtkCxxRevisionMacro(vtkDataObject, "1.117");
vtkStandardNewMacro(vtkDataObject);
vtkCxxSetObjectMacro(vtkDataObject,Information,vtkInformation);
......@@ -413,12 +413,6 @@ void vtkDataObject::UpdateData()
this->Source->UpdateData(this);
}
}
// Filters, that can't handle more data than they request, set this flag.
if (this->RequestExactExtent)
{ // clip the data down to the UpdateExtent.
this->Crop();
}
#endif
}
......
......@@ -17,15 +17,17 @@
#include "vtkCell.h"
#include "vtkCellData.h"
#include "vtkCellTypes.h"
#include "vtkExtentTranslator.h"
#include "vtkGenericCell.h"
#include "vtkIdList.h"
#include "vtkInformation.h"
#include "vtkMath.h"
#include "vtkPointData.h"
#include "vtkSource.h"
#include <math.h>
vtkCxxRevisionMacro(vtkDataSet, "1.94");
vtkCxxRevisionMacro(vtkDataSet, "1.95");
//----------------------------------------------------------------------------
// Constructor with default bounds (0,1, 0,1, 0,1).
......@@ -415,6 +417,208 @@ int vtkDataSet::CheckAttributes()
return 0;
}
//----------------------------------------------------------------------------
void vtkDataSet::GenerateGhostLevelArray()
{
// Make sure this is a structured data set.
if(this->GetExtentType() != VTK_3D_EXTENT)
{
return;
}
if (this->UpdateNumberOfPieces == 1)
{
// Either the piece has not been used to set the update extent,
// or the whole image was requested.
return;
}
int piece = this->Information->Get(vtkDataObject::DATA_PIECE_NUMBER());
int numberOfPieces =
this->Information->Get(vtkDataObject::DATA_NUMBER_OF_PIECES());
int ghostLevel =
this->Information->Get(vtkDataObject::DATA_NUMBER_OF_GHOST_LEVELS());
// Try to avoid generating these if the input has generated them,
// or the image data is already up to date.
// I guess we relly need an MTime check.
if(piece != this->UpdatePiece ||
numberOfPieces != this->UpdateNumberOfPieces ||
ghostLevel != this->UpdateGhostLevel ||
!this->PointData->GetArray("vtkGhostLevels"))
{ // Create ghost levels for cells and points.
vtkUnsignedCharArray *levels;
int zeroExt[6], extent[6];
int i, j, k, di, dj, dk, dist;
this->Information->Get(vtkDataObject::DATA_EXTENT(), extent);
// Get the extent with ghost level 0.
this->ExtentTranslator->SetWholeExtent(this->WholeExtent);
this->ExtentTranslator->SetPiece(this->UpdatePiece);
this->ExtentTranslator->SetNumberOfPieces(this->UpdateNumberOfPieces);
this->ExtentTranslator->SetGhostLevel(0);
this->ExtentTranslator->PieceToExtent();
this->ExtentTranslator->GetExtent(zeroExt);
// ---- POINTS ----
// Allocate the appropriate number levels (number of points).
levels = vtkUnsignedCharArray::New();
levels->Allocate((extent[1]-extent[0] + 1) *
(extent[3]-extent[2] + 1) *
(extent[5]-extent[4] + 1));
//cerr << "max: " << extent[0] << ", " << extent[1] << ", "
// << extent[2] << ", " << extent[3] << ", "
// << extent[4] << ", " << extent[5] << endl;
//cerr << "zero: " << zeroExt[0] << ", " << zeroExt[1] << ", "
// << zeroExt[2] << ", " << zeroExt[3] << ", "
// << zeroExt[4] << ", " << zeroExt[5] << endl;
// Loop through the points in this image.
for (k = extent[4]; k <= extent[5]; ++k)
{
dk = 0;
if (k < zeroExt[4])
{
dk = zeroExt[4] - k;
}
if (k >= zeroExt[5] && k < this->WholeExtent[5])
{ // Special case for last tile.
dk = k - zeroExt[5] + 1;
}
for (j = extent[2]; j <= extent[3]; ++j)
{
dj = 0;
if (j < zeroExt[2])
{
dj = zeroExt[2] - j;
}
if (j >= zeroExt[3] && j < this->WholeExtent[3])
{ // Special case for last tile.
dj = j - zeroExt[3] + 1;
}
for (i = extent[0]; i <= extent[1]; ++i)
{
di = 0;
if (i < zeroExt[0])
{
di = zeroExt[0] - i;
}
if (i >= zeroExt[1] && i < this->WholeExtent[1])
{ // Special case for last tile.
di = i - zeroExt[1] + 1;
}
// Compute Manhatten distance.
dist = di;
if (dj > dist)
{
dist = dj;
}
if (dk > dist)
{
dist = dk;
}
//cerr << " " << i << ", " << j << ", " << k << endl;
//cerr << " " << di << ", " << dj << ", " << dk << endl;
//cerr << dist << endl;
levels->InsertNextValue((unsigned char)dist);
}
}
}
levels->SetName("vtkGhostLevels");
this->PointData->AddArray(levels);
levels->Delete();
// Only generate ghost call levels if zero levels are requested.
// (Although we still need ghost points.)
if (this->UpdateGhostLevel == 0)
{
return;
}
// ---- CELLS ----
// Allocate the appropriate number levels (number of cells).
levels = vtkUnsignedCharArray::New();
levels->Allocate((extent[1]-extent[0]) *
(extent[3]-extent[2]) *
(extent[5]-extent[4]));
// Loop through the cells in this image.
// Cells may be 2d or 1d ... Treat all as 3D
if (extent[0] == extent[1])
{
++extent[1];
++zeroExt[1];
}
if (extent[2] == extent[3])
{
++extent[3];
++zeroExt[3];
}
if (extent[4] == extent[5])
{
++extent[5];
++zeroExt[5];
}
// Loop
for (k = extent[4]; k < extent[5]; ++k)
{ // Determine the Manhatten distances to zero extent.
dk = 0;
if (k < zeroExt[4])
{
dk = zeroExt[4] - k;
}
if (k >= zeroExt[5])
{
dk = k - zeroExt[5] + 1;
}
for (j = extent[2]; j < extent[3]; ++j)
{
dj = 0;
if (j < zeroExt[2])
{
dj = zeroExt[2] - j;
}
if (j >= zeroExt[3])
{
dj = j - zeroExt[3] + 1;
}
for (i = extent[0]; i < extent[1]; ++i)
{
di = 0;
if (i < zeroExt[0])
{
di = zeroExt[0] - i;
}
if (i >= zeroExt[1])
{
di = i - zeroExt[1] + 1;
}
// Compute Manhatten distance.
dist = di;
if (dj > dist)
{
dist = dj;
}
if (dk > dist)
{
dist = dk;
}
levels->InsertNextValue((unsigned char)dist);
}
}
}
levels->SetName("vtkGhostLevels");
this->CellData->AddArray(levels);
levels->Delete();
}
}
//----------------------------------------------------------------------------
void vtkDataSet::PrintSelf(ostream& os, vtkIndent indent)
{
......
......@@ -45,6 +45,7 @@ class vtkCellTypes;
class vtkGenericCell;
class vtkIdList;
class vtkPointData;
class vtkSourceToDataSetFriendship;
class VTK_COMMON_EXPORT vtkDataSet : public vtkDataObject
{
......@@ -323,8 +324,12 @@ protected:
double ScalarRange[2];
double Center[3];
virtual void GenerateGhostLevelArray();
private:
void InternalDataSetCopy(vtkDataSet *src);
//BTX
friend class vtkSourceToDataSetFriendship;
//ETX
private:
vtkDataSet(const vtkDataSet&); // Not implemented.
void operator=(const vtkDataSet&); // Not implemented.
......
......@@ -39,7 +39,7 @@
#include "vtkVertex.h"
#include "vtkVoxel.h"
vtkCxxRevisionMacro(vtkImageData, "1.151");
vtkCxxRevisionMacro(vtkImageData, "1.152");
vtkStandardNewMacro(vtkImageData);
//----------------------------------------------------------------------------
......@@ -1108,221 +1108,6 @@ void vtkImageData::SetUpdateExtent(int piece, int numPieces, int ghostLevel)
this->UpdateGhostLevel = ghostLevel;
}
//----------------------------------------------------------------------------
void vtkImageData::UpdateData()
{
this->vtkDataObject::UpdateData();
// This stuff should really be ImageToStructuredPoints ....
if (this->UpdateNumberOfPieces == 1)
{
// Either the piece has not been used to set the update extent,
// or the whole image was requested.
return;
}
//if (this->Extent[0] < this->UpdateExtent[0] ||
// this->Extent[1] > this->UpdateExtent[1] ||
// this->Extent[2] < this->UpdateExtent[2] ||
// this->Extent[3] > this->UpdateExtent[3] ||
// this->Extent[4] < this->UpdateExtent[4] ||
// this->Extent[5] > this->UpdateExtent[5])
// {
// vtkImageData *image = vtkImageData::New();
// image->DeepCopy(this);
// this->SetExtent(this->UpdateExtent);
// this->AllocateScalars();
// this->CopyAndCastFrom(image, this->UpdateExtent);
// image->Delete();
// }
int piece = this->Information->Get(vtkDataObject::DATA_PIECE_NUMBER());
int numberOfPieces =
this->Information->Get(vtkDataObject::DATA_NUMBER_OF_PIECES());
int ghostLevel =
this->Information->Get(vtkDataObject::DATA_NUMBER_OF_GHOST_LEVELS());
// Try to avoid generating these if the input has generated them,
// or the image data is already up to date.
// I guess we relly need an MTime check.
if(piece != this->UpdatePiece ||
numberOfPieces != this->UpdateNumberOfPieces ||
ghostLevel != this->UpdateGhostLevel ||
!this->PointData->GetArray("vtkGhostLevels"))
{ // Create ghost levels for cells and points.
vtkUnsignedCharArray *levels;
int zeroExt[6], extent[6];
int i, j, k, di, dj, dk, dist;
this->GetExtent(extent);
// Get the extent with ghost level 0.
this->ExtentTranslator->SetWholeExtent(this->WholeExtent);
this->ExtentTranslator->SetPiece(this->UpdatePiece);
this->ExtentTranslator->SetNumberOfPieces(this->UpdateNumberOfPieces);
this->ExtentTranslator->SetGhostLevel(0);
this->ExtentTranslator->PieceToExtent();
this->ExtentTranslator->GetExtent(zeroExt);
// ---- POINTS ----
// Allocate the appropriate number levels (number of points).
levels = vtkUnsignedCharArray::New();
levels->Allocate((extent[1]-extent[0] + 1) *
(extent[3]-extent[2] + 1) *
(extent[5]-extent[4] + 1));
//cerr << "max: " << extent[0] << ", " << extent[1] << ", "
// << extent[2] << ", " << extent[3] << ", "
// << extent[4] << ", " << extent[5] << endl;
//cerr << "zero: " << zeroExt[0] << ", " << zeroExt[1] << ", "
// << zeroExt[2] << ", " << zeroExt[3] << ", "
// << zeroExt[4] << ", " << zeroExt[5] << endl;
// Loop through the points in this image.
for (k = extent[4]; k <= extent[5]; ++k)
{
dk = 0;
if (k < zeroExt[4])
{
dk = zeroExt[4] - k;
}
if (k >= zeroExt[5] && k < this->WholeExtent[5])
{ // Special case for last tile.
dk = k - zeroExt[5] + 1;
}
for (j = extent[2]; j <= extent[3]; ++j)
{
dj = 0;
if (j < zeroExt[2])
{
dj = zeroExt[2] - j;
}
if (j >= zeroExt[3] && j < this->WholeExtent[3])
{ // Special case for last tile.
dj = j - zeroExt[3] + 1;
}
for (i = extent[0]; i <= extent[1]; ++i)
{
di = 0;
if (i < zeroExt[0])
{
di = zeroExt[0] - i;
}
if (i >= zeroExt[1] && i < this->WholeExtent[1])
{ // Special case for last tile.
di = i - zeroExt[1] + 1;
}
// Compute Manhatten distance.
dist = di;
if (dj > dist)
{
dist = dj;
}
if (dk > dist)
{
dist = dk;
}
//cerr << " " << i << ", " << j << ", " << k << endl;
//cerr << " " << di << ", " << dj << ", " << dk << endl;
//cerr << dist << endl;
levels->InsertNextValue((unsigned char)dist);
}
}
}
levels->SetName("vtkGhostLevels");
this->PointData->AddArray(levels);
levels->Delete();
// Only generate ghost call levels if zero levels are requested.
// (Although we still need ghost points.)
if (this->UpdateGhostLevel == 0)
{
return;
}
// ---- CELLS ----
// Allocate the appropriate number levels (number of cells).
levels = vtkUnsignedCharArray::New();
levels->Allocate((extent[1]-extent[0]) *
(extent[3]-extent[2]) *
(extent[5]-extent[4]));
// Loop through the cells in this image.
// Cells may be 2d or 1d ... Treat all as 3D
if (extent[0] == extent[1])
{
++extent[1];
++zeroExt[1];
}
if (extent[2] == extent[3])
{
++extent[3];
++zeroExt[3];
}
if (extent[4] == extent[5])
{
++extent[5];
++zeroExt[5];
}
// Loop
for (k = extent[4]; k < extent[5]; ++k)
{ // Determine the Manhatten distances to zero extent.
dk = 0;
if (k < zeroExt[4])
{
dk = zeroExt[4] - k;
}
if (k >= zeroExt[5])
{
dk = k - zeroExt[5] + 1;
}
for (j = extent[2]; j < extent[3]; ++j)
{
dj = 0;
if (j < zeroExt[2])
{
dj = zeroExt[2] - j;
}
if (j >= zeroExt[3])
{
dj = j - zeroExt[3] + 1;
}
for (i = extent[0]; i < extent[1]; ++i)
{
di = 0;
if (i < zeroExt[0])
{
di = zeroExt[0] - i;
}
if (i >= zeroExt[1])
{
di = i - zeroExt[1] + 1;
}
// Compute Manhatten distance.
dist = di;
if (dj > dist)
{
dist = dj;
}
if (dk > dist)
{
dist = dk;
}
levels->InsertNextValue((unsigned char)dist);
}
}
}
levels->SetName("vtkGhostLevels");
this->CellData->AddArray(levels);
levels->Delete();
}
}
//----------------------------------------------------------------------------
void vtkImageData::SetNumberOfScalarComponents(int num)
......
......@@ -49,10 +49,6 @@ public:
// Return what type of dataset this is.
int GetDataObjectType() {return VTK_IMAGE_DATA;};
// Description:
// This update method will supply the ghost level arrays if they are requested.
void UpdateData();
// Description:
// Standard vtkDataSet API methods. See vtkDataSet for more information.
vtkIdType GetNumberOfCells();
......
......@@ -29,7 +29,7 @@
#include "vtkVertex.h"
#include "vtkVoxel.h"
vtkCxxRevisionMacro(vtkRectilinearGrid, "1.64");
vtkCxxRevisionMacro(vtkRectilinearGrid, "1.65");
vtkStandardNewMacro(vtkRectilinearGrid);
vtkCxxSetObjectMacro(vtkRectilinearGrid,XCoordinates,vtkDataArray);
......@@ -1123,229 +1123,6 @@ void vtkRectilinearGrid::Crop()
}
}
//----------------------------------------------------------------------------
void vtkRectilinearGrid::UpdateData()
{
this->vtkDataObject::UpdateData();
// This stuff should really be ImageToStructuredPoints ....
if (this->UpdateNumberOfPieces == 1)
{
// Either the piece has not been used to set the update extent,
// or the whole image was requested.
return;
}
//if (this->Extent[0] < this->UpdateExtent[0] ||
// this->Extent[1] > this->UpdateExtent[1] ||
// this->Extent[2] < this->UpdateExtent[2] ||
// this->Extent[3] > this->UpdateExtent[3] ||
// this->Extent[4] < this->UpdateExtent[4] ||
// this->Extent[5] > this->UpdateExtent[5])
// {
// vtkImageData *image = vtkImageData::New();
// image->DeepCopy(this);
// this->SetExtent(this->UpdateExtent);
// this->AllocateScalars();
// this->CopyAndCastFrom(image, this->UpdateExtent);
// image->Delete();
// }
int piece = this->Information->Get(vtkDataObject::DATA_PIECE_NUMBER());
int numberOfPieces =
this->Information->Get(vtkDataObject::DATA_NUMBER_OF_PIECES());
int ghostLevel =
this->Information->Get(vtkDataObject::DATA_NUMBER_OF_GHOST_LEVELS());
// Try to avoid generating these if the input has generated them,
// or the image data is already up to date.
// I guess we relly need an MTime check.
if(piece != this->UpdatePiece ||
numberOfPieces != this->UpdateNumberOfPieces ||
ghostLevel != this->UpdateGhostLevel ||
!this->PointData->GetArray("vtkGhostLevels") ||
!this->CellData->GetArray("vtkGhostLevels"))
{ // Create ghost levels for cells and points.
vtkUnsignedCharArray *levels;
int zeroExt[6], extent[6];
int i, j, k, di, dj, dk, dist;
this->GetExtent(extent);
// Get the extent with ghost level 0.
this->ExtentTranslator->SetWholeExtent(this->WholeExtent);
this->ExtentTranslator->SetPiece(this->UpdatePiece);
this->ExtentTranslator->SetNumberOfPieces(this->UpdateNumberOfPieces);
this->ExtentTranslator->SetGhostLevel(0);
this->ExtentTranslator->PieceToExtent();
this->ExtentTranslator->GetExtent(zeroExt);
// ---- POINTS ----
// Allocate the appropriate number levels (number of points).
levels = vtkUnsignedCharArray::New();
levels->Allocate((extent[1]-extent[0] + 1) *
(extent[3]-extent[2] + 1) *
(extent[5]-extent[4] + 1));
//cerr << "max: " << extent[0] << ", " << extent[1] << ", "
// << extent[2] << ", " << extent[3] << ", "
// << extent[4] << ", " << extent[5] << endl;
//cerr << "zero: " << zeroExt[0] << ", " << zeroExt[1] << ", "
// << zeroExt[2] << ", " << zeroExt[3] << ", "
// << zeroExt[4] << ", " << zeroExt[5] << endl;
// Loop through the points in this image.
for (k = extent[4]; k <= extent[5]; ++k)
{
dk = 0;
if (k < zeroExt[4])
{
dk = zeroExt[4] - k;
}
if (k >= zeroExt[5] && k < this->WholeExtent[5])
{ // Special case for last tile.
dk = k - zeroExt[5] + 1;
}
<