mirror of
https://gitlab.kitware.com/vtk/vtk-m
synced 2024-09-08 13:23:51 +00:00
Simplify threshold worklet
Removes code that is no longer used.
This commit is contained in:
parent
6e1de4fa8f
commit
e0c5500a22
@ -79,72 +79,18 @@ public:
|
|||||||
bool AllPointsMustPass;
|
bool AllPointsMustPass;
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename Operator>
|
template <typename CellSetType, typename ValueType, typename StorageType, typename UnaryPredicate>
|
||||||
class CombinePassFlagsWorklet : public vtkm::worklet::WorkletMapField
|
vtkm::cont::CellSetPermutation<CellSetType> RunImpl(
|
||||||
|
const CellSetType& cellSet,
|
||||||
|
const vtkm::cont::ArrayHandle<ValueType, StorageType>& field,
|
||||||
|
vtkm::cont::Field::Association fieldType,
|
||||||
|
const UnaryPredicate& predicate,
|
||||||
|
bool allPointsMustPass,
|
||||||
|
bool invert)
|
||||||
{
|
{
|
||||||
public:
|
using OutputType = vtkm::cont::CellSetPermutation<CellSetType>;
|
||||||
using ControlSignature = void(FieldInOut, FieldIn);
|
|
||||||
using ExecitionSignature = void(_1, _2);
|
|
||||||
|
|
||||||
VTKM_CONT
|
|
||||||
explicit CombinePassFlagsWorklet(const Operator& combine)
|
|
||||||
: Combine(combine)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
VTKM_EXEC void operator()(bool& combined, bool incoming) const
|
|
||||||
{
|
|
||||||
combined = this->Combine(combined, incoming);
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
Operator Combine;
|
|
||||||
};
|
|
||||||
|
|
||||||
template <typename Operator>
|
|
||||||
void CombinePassFlags(const vtkm::cont::ArrayHandle<bool>& passFlagsIn, const Operator& combine)
|
|
||||||
{
|
|
||||||
if (this->PassFlags.GetNumberOfValues() == 0) // Is initialization needed?
|
|
||||||
{
|
|
||||||
this->PassFlags = passFlagsIn;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
DispatcherMapField<CombinePassFlagsWorklet<Operator>> dispatcher(
|
|
||||||
CombinePassFlagsWorklet<Operator>{ combine });
|
|
||||||
dispatcher.Invoke(this->PassFlags, passFlagsIn);
|
|
||||||
}
|
|
||||||
this->PassFlagsModified = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// special no-op combine operator for combining `PassFlags` results of incremental runs
|
|
||||||
struct NoOp
|
|
||||||
{
|
|
||||||
};
|
|
||||||
|
|
||||||
void CombinePassFlags(const vtkm::cont::ArrayHandle<bool>& passFlagsIn, NoOp)
|
|
||||||
{
|
|
||||||
this->PassFlags = passFlagsIn;
|
|
||||||
this->PassFlagsModified = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Incrementally run the worklet on the given parameters. Each run should get the
|
|
||||||
/// same `cellSet`. An array of pass/fail flags is maintained internally. The `passFlagsCombine`
|
|
||||||
/// operator is used to combine the current result to the incremental results. Finally, use
|
|
||||||
/// `GenerateResultCellSet` to get the thresholded cellset.
|
|
||||||
template <typename ValueType,
|
|
||||||
typename StorageType,
|
|
||||||
typename UnaryPredicate,
|
|
||||||
typename PassFlagsCombineOp>
|
|
||||||
void RunIncremental(const vtkm::cont::UnknownCellSet& cellSet,
|
|
||||||
const vtkm::cont::ArrayHandle<ValueType, StorageType>& field,
|
|
||||||
vtkm::cont::Field::Association fieldType,
|
|
||||||
const UnaryPredicate& predicate,
|
|
||||||
bool allPointsMustPass, // only considered when field association is `Points`
|
|
||||||
const PassFlagsCombineOp& passFlagsCombineOp)
|
|
||||||
{
|
|
||||||
vtkm::cont::ArrayHandle<bool> passFlags;
|
vtkm::cont::ArrayHandle<bool> passFlags;
|
||||||
|
|
||||||
switch (fieldType)
|
switch (fieldType)
|
||||||
{
|
{
|
||||||
case vtkm::cont::Field::Association::Points:
|
case vtkm::cont::Field::Association::Points:
|
||||||
@ -166,40 +112,16 @@ public:
|
|||||||
throw vtkm::cont::ErrorBadValue("Expecting point or cell field.");
|
throw vtkm::cont::ErrorBadValue("Expecting point or cell field.");
|
||||||
}
|
}
|
||||||
|
|
||||||
this->CombinePassFlags(passFlags, passFlagsCombineOp);
|
if (invert)
|
||||||
}
|
|
||||||
|
|
||||||
vtkm::cont::ArrayHandle<vtkm::Id> GetValidCellIds() const
|
|
||||||
{
|
|
||||||
if (this->PassFlagsModified)
|
|
||||||
{
|
{
|
||||||
vtkm::cont::Algorithm::CopyIf(
|
vtkm::cont::Algorithm::Copy(
|
||||||
vtkm::cont::ArrayHandleIndex(this->PassFlags.GetNumberOfValues()),
|
vtkm::cont::make_ArrayHandleTransform(passFlags, vtkm::LogicalNot{}), passFlags);
|
||||||
this->PassFlags,
|
|
||||||
this->ValidCellIds);
|
|
||||||
this->PassFlagsModified = false;
|
|
||||||
}
|
}
|
||||||
return this->ValidCellIds;
|
|
||||||
}
|
|
||||||
|
|
||||||
vtkm::cont::UnknownCellSet GenerateResultCellSet(const vtkm::cont::UnknownCellSet& cellSet)
|
vtkm::cont::Algorithm::CopyIf(
|
||||||
{
|
vtkm::cont::ArrayHandleIndex(passFlags.GetNumberOfValues()), passFlags, this->ValidCellIds);
|
||||||
vtkm::cont::UnknownCellSet output;
|
|
||||||
|
|
||||||
CastAndCall(cellSet, [&](auto concrete) {
|
return OutputType(this->ValidCellIds, cellSet);
|
||||||
output = vtkm::worklet::CellDeepCopy::Run(
|
|
||||||
vtkm::cont::make_CellSetPermutation(this->GetValidCellIds(), concrete));
|
|
||||||
});
|
|
||||||
|
|
||||||
return output;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Invert the results stored in this worklet's state
|
|
||||||
void InvertResults()
|
|
||||||
{
|
|
||||||
vtkm::cont::Algorithm::Copy(
|
|
||||||
vtkm::cont::make_ArrayHandleTransform(this->PassFlags, vtkm::LogicalNot{}), this->PassFlags);
|
|
||||||
this->PassFlagsModified = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename ValueType, typename StorageType, typename UnaryPredicate>
|
template <typename ValueType, typename StorageType, typename UnaryPredicate>
|
||||||
@ -211,19 +133,18 @@ public:
|
|||||||
bool allPointsMustPass = false, // only considered when field association is `Points`
|
bool allPointsMustPass = false, // only considered when field association is `Points`
|
||||||
bool invert = false)
|
bool invert = false)
|
||||||
{
|
{
|
||||||
this->RunIncremental(cellSet, field, fieldType, predicate, allPointsMustPass, NoOp{});
|
vtkm::cont::UnknownCellSet output;
|
||||||
if (invert)
|
CastAndCall(cellSet, [&](auto concrete) {
|
||||||
{
|
output = vtkm::worklet::CellDeepCopy::Run(
|
||||||
this->InvertResults();
|
this->RunImpl(concrete, field, fieldType, predicate, allPointsMustPass, invert));
|
||||||
}
|
});
|
||||||
return this->GenerateResultCellSet(cellSet);
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
vtkm::cont::ArrayHandle<vtkm::Id> GetValidCellIds() const { return this->ValidCellIds; }
|
||||||
vtkm::cont::ArrayHandle<bool> PassFlags;
|
|
||||||
|
|
||||||
mutable bool PassFlagsModified = true;
|
private:
|
||||||
mutable vtkm::cont::ArrayHandle<vtkm::Id> ValidCellIds;
|
vtkm::cont::ArrayHandle<vtkm::Id> ValidCellIds;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
} // namespace vtkm::worklet
|
} // namespace vtkm::worklet
|
||||||
|
Loading…
Reference in New Issue
Block a user