diff --git a/Common/DataModel/vtkDataSetCellIterator.cxx b/Common/DataModel/vtkDataSetCellIterator.cxx index 1d18866091625b62896726eb258aa5e953063fef..de233f50c710892c92d3e96898e717b00bfe3483 100644 --- a/Common/DataModel/vtkDataSetCellIterator.cxx +++ b/Common/DataModel/vtkDataSetCellIterator.cxx @@ -15,13 +15,105 @@ #include "vtkDataSetCellIterator.h" -#include "vtkDataSet.h" +#include "vtkHyperTreeGrid.h" +#include "vtkIdList.h" #include "vtkObjectFactory.h" #include "vtkPoints.h" -#include "vtkIdList.h" +#include "vtkRectilinearGrid.h" vtkStandardNewMacro(vtkDataSetCellIterator) +namespace +{ + template + void SetArrayType(T* grid, vtkPoints* points) + { + // check all directions to see if any of them are doubles and + // if they are we set the points data type to double. If the + // data types are all the same then we set it to the common + // data type. Otherwise we give up and just keep the default + // float data type. + int xType = -1, yType = -1, zType = -1; + if (vtkDataArray* x = grid->GetXCoordinates()) + { + xType = x->GetDataType(); + if (xType == VTK_DOUBLE) + { + points->SetDataType(VTK_DOUBLE); + return; + } + } + if (vtkDataArray* y = grid->GetYCoordinates()) + { + yType = y->GetDataType(); + if (yType == VTK_DOUBLE) + { + points->SetDataType(VTK_DOUBLE); + return; + } + } + if (vtkDataArray* z = grid->GetZCoordinates()) + { + zType = z->GetDataType(); + if (zType == VTK_DOUBLE) + { + points->SetDataType(VTK_DOUBLE); + return; + } + } + if (xType != -1 || yType != -1 || zType != -1) + { + if(xType == yType && xType == zType) + { + points->SetDataType(xType); + return; + } + if (xType == -1) + { + if (yType == -1) + { + points->SetDataType(zType); + return; + } + else if (zType == -1 || yType == zType) + { + points->SetDataType(yType); + return; + } + } + if (yType == -1) + { + if (xType == -1) + { + points->SetDataType(zType); + return; + } + else if (zType == -1 || xType == zType) + { + points->SetDataType(xType); + return; + } + } + if (zType == -1) + { + if (xType == -1) + { + points->SetDataType(yType); + return; + } + else if (yType == -1 || xType == yType) + { + points->SetDataType(xType); + return; + } + } + } + + // Set it to the default since it may have gotten set to something else + points->SetDataType(VTK_FLOAT); + } +} + //------------------------------------------------------------------------------ void vtkDataSetCellIterator::PrintSelf(ostream &os, vtkIndent indent) { @@ -35,6 +127,21 @@ void vtkDataSetCellIterator::SetDataSet(vtkDataSet *ds) { this->DataSet = ds; this->CellId = 0; + cerr << "setting data set\n"; + if (vtkRectilinearGrid* rg = vtkRectilinearGrid::SafeDownCast(ds)) + { + SetArrayType(rg, this->Points); + } + else if (vtkHyperTreeGrid* htg = vtkHyperTreeGrid::SafeDownCast(ds)) + { + SetArrayType(htg, this->Points); + } + else if (ds->IsA("vtkImageData") || ds->IsA("vtkHyperOctree")) + { + // ImageData and HyperOctree Origin and Spacing are doubles so + // the data type for this should also be double + this->Points->SetDataType(VTK_DOUBLE); + } } //------------------------------------------------------------------------------