Copy Threshold output to a CellSetExplicit

Perhaps a better title for this change would be "Make the Threshold
filter not totally useless."

A long standing issue with the Threshold filter is that its output
CellSet was stored in a CellSetPermutation. This made Threshold hyper-
efficient because it required hardly any data movement to implement.
However, the problem was that any other unit that had to use the CellSet
failed. To have VTK-m handle that output correctly in other filters and
writers, they all would have to check for the existance of
CellSetPermutation. And CellSetPermutation is templated on the CellSet
type it is permuting, so all units would have to compile special cases
for all these combinations. This is not likely to be feasible in any
static solution.

The simple solution, implemented here, is to deep copy the cells to a
CellSetExplicit, which is a known type that is already used everywhere
in VTK-m. The solution is a bit disappointing since it requires more
memory and time to build. But it is on par with solutions in other
libraries (like VTK). And it really does not matter how efficient the
old solution was if it was useless.
This commit is contained in:
Kenneth Moreland 2019-08-20 16:01:01 -06:00
parent 1473c12e66
commit 42e8a9125d
3 changed files with 46 additions and 1 deletions

@ -0,0 +1,21 @@
# Copy Threshold output to a CellSetExplicit
Perhaps a better title for this change would be "Make the Threshold filter
not totally useless."
A long standing issue with the Threshold filter is that its output CellSet
was stored in a CellSetPermutation. This made Threshold hyper- efficient
because it required hardly any data movement to implement. However, the
problem was that any other unit that had to use the CellSet failed. To have
VTK-m handle that output correctly in other filters and writers, they all
would have to check for the existance of CellSetPermutation. And
CellSetPermutation is templated on the CellSet type it is permuting, so all
units would have to compile special cases for all these combinations. This
is not likely to be feasible in any static solution.
The simple solution, implemented here, is to deep copy the cells to a
CellSetExplicit, which is a known type that is already used everywhere in
VTK-m. The solution is a bit disappointing since it requires more memory
and time to build. But it is on par with solutions in other libraries (like
VTK). And it really does not matter how efficient the old solution was if
it was useless.

@ -11,6 +11,7 @@
#include <vtkm/cont/testing/MakeTestDataSet.h>
#include <vtkm/cont/testing/Testing.h>
#include <vtkm/filter/CleanGrid.h>
#include <vtkm/filter/Threshold.h>
using vtkm::cont::testing::MakeTestDataSet;
@ -43,6 +44,11 @@ public:
VTKM_TEST_ASSERT(cellFieldArray.GetNumberOfValues() == 1 &&
cellFieldArray.GetPortalConstControl().Get(0) == 200.1f,
"Wrong cell field data");
// Make sure that the resulting data set can be successfully passed to another
// simple filter using the cell set.
vtkm::filter::CleanGrid clean;
clean.Execute(output);
}
void TestRegular3D() const
@ -68,6 +74,11 @@ public:
cellFieldArray.GetPortalConstControl().Get(0) == 100.1f &&
cellFieldArray.GetPortalConstControl().Get(1) == 100.2f,
"Wrong cell field data");
// Make sure that the resulting data set can be successfully passed to another
// simple filter using the cell set.
vtkm::filter::CleanGrid clean;
clean.Execute(output);
}
void TestExplicit3D() const
@ -93,6 +104,11 @@ public:
cellFieldArray.GetPortalConstControl().Get(0) == 100.1f &&
cellFieldArray.GetPortalConstControl().Get(1) == 100.2f,
"Wrong cell field data");
// Make sure that the resulting data set can be successfully passed to another
// simple filter using the cell set.
vtkm::filter::CleanGrid clean;
clean.Execute(output);
}
void TestExplicit3DZeroResults() const
@ -115,6 +131,11 @@ public:
output.GetField("cellvar").GetData().CopyTo(cellFieldArray);
VTKM_TEST_ASSERT(cellFieldArray.GetNumberOfValues() == 0, "field should be empty");
// Make sure that the resulting data set can be successfully passed to another
// simple filter using the cell set.
vtkm::filter::CleanGrid clean;
clean.Execute(output);
}
void operator()() const

@ -10,6 +10,7 @@
#ifndef vtkm_m_worklet_Threshold_h
#define vtkm_m_worklet_Threshold_h
#include <vtkm/worklet/CellDeepCopy.h>
#include <vtkm/worklet/DispatcherMapTopology.h>
#include <vtkm/worklet/WorkletMapTopology.h>
@ -171,7 +172,9 @@ public:
template <typename CellSetType>
void operator()(const CellSetType& cellSet) const
{
this->Output = this->Worklet.Run(cellSet, this->Field, this->FieldType, this->Predicate);
// Copy output to an explicit grid so that other units can guess what this is.
this->Output = vtkm::worklet::CellDeepCopy::Run(
this->Worklet.Run(cellSet, this->Field, this->FieldType, this->Predicate));
}
};