Commit 3148b3a8 authored by Andrew Bauer's avatar Andrew Bauer

Making DataSetCellIterators have proper point data type.

For accuracy the vtkDataSetCellIterator should have
the same floating point accuracy as the input data set. For
ImageData and HyperOctree it will be double since that is
their native data type for storing point locations. For
RectilinearGrid and HyperTreeGrid we do the best we can
but there are 3 arrays which store the point locations
for these grids so it's not always clear which one to use.
This was already done for the other data set cell iterators.
parent 3cfc1eb4
Pipeline #27433 passed with stage
......@@ -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<typename T>
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);
}
}
//------------------------------------------------------------------------------
......
Markdown is supported
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