Merge topic 'add-point-index-start-unit-test-to-testing-extract-stuctured'

8f4d5fdf8 Remove some unneeded test comments and debug code
7bea5413c Revert from VOIIsGlobal to IncludeOffset. Add comment about deprecation reasoning.
523c8f3f2 Add test whether GlobalPointDimensions are preserved
84e719ae1 Set GlobalPointIndexStart correctly, copy GlobalPointDimensions
e55b700f7 Deprecate SetIncludeOffset and rename to SetVOIIsGlobal
e013ad126 Add test for GlobalPointIndexStart to TestingExtractStructured

Acked-by: Kitware Robot <kwrobot@kitware.com>
Acked-by: Abdelilah Essiari <aessiari@lbl.gov>
Merge-request: !3086
This commit is contained in:
Kenneth Moreland 2023-06-22 12:20:16 +00:00 committed by Kitware Robot
commit f67a9f29bf
3 changed files with 58 additions and 3 deletions

@ -78,6 +78,14 @@ public:
VTKM_CONT
void SetIncludeBoundary(bool value) { this->IncludeBoundary = value; }
/// Set if VOI is specified in global (rather than in local) point indices
/// (NOTE: Depracted this method since this does not seem to work as
/// expected and there are no tests for it. Furthermore, neither VTK-m nor
/// VTK-h/Ascent seem to use this method. If your are using this method
/// somewhere else and think it should remain, please open a merge request to
/// "de-deprecate" it and add a test and documentation of the expected
/// behavior.)
VTKM_DEPRECATED(2.1)
VTKM_CONT
void SetIncludeOffset(bool value) { this->IncludeOffset = value; }

@ -26,6 +26,14 @@ public:
std::cout << "Testing extract structured uniform" << std::endl;
vtkm::cont::DataSet dataset = MakeTestDataSet().Make2DUniformDataSet1();
// Change point index start from 0, 0 to 10, 14
vtkm::cont::CellSetStructured<2> cellSet;
dataset.GetCellSet().AsCellSet(cellSet);
cellSet.SetGlobalPointDimensions(vtkm::Id2{ 15, 19 });
cellSet.SetGlobalPointIndexStart(vtkm::Id2{ 10, 14 });
dataset.SetCellSet(cellSet);
dataset.PrintSummary(std::cout);
vtkm::RangeId3 range(1, 4, 1, 4, 0, 1);
vtkm::Id3 sample(1, 1, 1);
@ -39,6 +47,17 @@ public:
"Wrong result for ExtractStructured worklet");
VTKM_TEST_ASSERT(test_equal(output.GetNumberOfCells(), 4),
"Wrong result for ExtractStructured worklet");
vtkm::cont::CellSetStructured<2> outputCellSet;
output.GetCellSet().AsCellSet(outputCellSet);
VTKM_TEST_ASSERT(test_equal(outputCellSet.GetGlobalPointIndexStart()[0], 11),
"Wrong result for ExtractStructured PointIndexStart");
VTKM_TEST_ASSERT(test_equal(outputCellSet.GetGlobalPointIndexStart()[1], 15),
"Wrong result for ExtractStructured PointIndexStart");
VTKM_TEST_ASSERT(test_equal(outputCellSet.GetGlobalPointDimensions()[0], 15),
"Wrong result for ExtractStructured GlobalPointDimensions");
VTKM_TEST_ASSERT(test_equal(outputCellSet.GetGlobalPointDimensions()[1], 19),
"Wrong result for ExtractStructured GlobalPointDimensions");
vtkm::cont::ArrayHandle<vtkm::Float32> outPointData;
output.GetField("pointvar").GetData().AsArrayHandle(outPointData);

@ -136,6 +136,7 @@ private:
static UncertainCellSetStructured MakeCellSetStructured(
const vtkm::Id3& inputPointDims,
const vtkm::Id3& inputOffsets,
const vtkm::Id3& inputGlobalPointDims,
vtkm::IdComponent forcedDimensionality = 0)
{
// when the point dimension for a given axis is 1 we
@ -146,12 +147,22 @@ private:
vtkm::IdComponent dimensionality = forcedDimensionality;
vtkm::Id3 dimensions = inputPointDims;
vtkm::Id3 offset = inputOffsets;
vtkm::Id3 globalDimensions = inputGlobalPointDims;
for (int i = 0; i < 3 && (forcedDimensionality == 0); ++i)
{
if (inputPointDims[i] > 1)
{
dimensions[dimensionality] = inputPointDims[i];
offset[dimensionality] = inputOffsets[i];
// TODO/FIXME: This may not be the correct way to handle global point dims.
// E.g., if we preserve the input global point dims (default) then they may
// have a higher dimensionility than the returned data set. In that case,
// the approach here will result in an incorrect value for GlobalPointDimensions.
// This is the simplest approach, which should work in most use cases for this
// filter, but if this choice causes further problems down the way, we may need
// to rethink it.
globalDimensions[dimensionality] = inputGlobalPointDims[i];
++dimensionality;
}
}
@ -163,6 +174,7 @@ private:
vtkm::cont::CellSetStructured<1> outCs;
outCs.SetPointDimensions(dimensions[0]);
outCs.SetGlobalPointIndexStart(offset[0]);
outCs.SetGlobalPointDimensions(globalDimensions[0]);
return outCs;
}
case 2:
@ -170,6 +182,7 @@ private:
vtkm::cont::CellSetStructured<2> outCs;
outCs.SetPointDimensions(vtkm::Id2(dimensions[0], dimensions[1]));
outCs.SetGlobalPointIndexStart(vtkm::Id2(offset[0], offset[1]));
outCs.SetGlobalPointDimensions(vtkm::Id2(globalDimensions[0], globalDimensions[1]));
return outCs;
}
case 3:
@ -177,6 +190,7 @@ private:
vtkm::cont::CellSetStructured<3> outCs;
outCs.SetPointDimensions(dimensions);
outCs.SetGlobalPointIndexStart(offset);
outCs.SetGlobalPointDimensions(globalDimensions);
return outCs;
}
default:
@ -193,9 +207,11 @@ public:
{
vtkm::Id pdims = cellset.GetPointDimensions();
vtkm::Id offsets = cellset.GetGlobalPointIndexStart();
vtkm::Id gpdims = cellset.GetGlobalPointDimensions();
return this->Compute(1,
vtkm::Id3{ pdims, 1, 1 },
vtkm::Id3{ offsets, 0, 0 },
vtkm::Id3{ gpdims, 1, 1 },
voi,
sampleRate,
includeBoundary,
@ -210,9 +226,11 @@ public:
{
vtkm::Id2 pdims = cellset.GetPointDimensions();
vtkm::Id2 offsets = cellset.GetGlobalPointIndexStart();
vtkm::Id2 gpdims = cellset.GetGlobalPointDimensions();
return this->Compute(2,
vtkm::Id3{ pdims[0], pdims[1], 1 },
vtkm::Id3{ offsets[0], offsets[1], 0 },
vtkm::Id3{ gpdims[0], gpdims[1], 1 },
voi,
sampleRate,
includeBoundary,
@ -227,12 +245,15 @@ public:
{
vtkm::Id3 pdims = cellset.GetPointDimensions();
vtkm::Id3 offsets = cellset.GetGlobalPointIndexStart();
return this->Compute(3, pdims, offsets, voi, sampleRate, includeBoundary, includeOffset);
vtkm::Id3 gpdims = cellset.GetGlobalPointDimensions();
return this->Compute(
3, pdims, offsets, gpdims, voi, sampleRate, includeBoundary, includeOffset);
}
UncertainCellSetStructured Compute(const int dimensionality,
const vtkm::Id3& ptdim,
const vtkm::Id3& offsets,
const vtkm::Id3& gpdims,
const vtkm::RangeId3& voi,
const vtkm::Id3& sampleRate,
bool includeBoundary,
@ -241,6 +262,7 @@ public:
// Verify input parameters
vtkm::Id3 offset_vec(0, 0, 0);
vtkm::Id3 globalOffset(0, 0, 0);
vtkm::Id3 globalPointDimensions = gpdims;
this->InputDimensions = ptdim;
this->InputDimensionality = dimensionality;
@ -315,7 +337,7 @@ public:
if (!this->VOI.IsNonEmpty())
{
vtkm::Id3 empty = { 0, 0, 0 };
return MakeCellSetStructured(empty, empty, dimensionality);
return MakeCellSetStructured(empty, empty, globalPointDimensions, dimensionality);
}
if (!includeOffset)
{
@ -354,9 +376,15 @@ public:
MakeAxisIndexArrayCells(vtkm::Max(vtkm::Id(1), this->OutputDimensions[2] - 1),
this->VOI.Z.Min,
this->SampleRate[2]));
// compute global point origin
for (int i = 0; i < dimensionality; ++i)
{
globalOffset[i] = offsets[i] + this->VOI[i].Min;
}
}
return MakeCellSetStructured(this->OutputDimensions, globalOffset);
return MakeCellSetStructured(this->OutputDimensions, globalOffset, globalPointDimensions);
}