From 882dcacca47ec6979d9da275e2f8da997b543335 Mon Sep 17 00:00:00 2001 From: Kenneth Moreland Date: Tue, 28 Apr 2020 10:31:44 -0600 Subject: [PATCH] Have filter specify its own field types Previously, the policy specified which field types the filter should operate on. The filter could remove some types, but it was not able to add any types. This is backward. Instead, the filter should specify what types its supports and the policy may cull out some of those. --- vtkm/List.h | 2 ++ vtkm/cont/Field.h | 2 ++ vtkm/cont/FieldRangeCompute.h | 2 ++ vtkm/cont/VariantArrayHandle.h | 3 +++ vtkm/filter/Filter.h | 2 +- vtkm/filter/Histogram.hxx | 7 ++++++- vtkm/filter/PolicyBase.h | 14 +++++++++++--- 7 files changed, 27 insertions(+), 5 deletions(-) diff --git a/vtkm/List.h b/vtkm/List.h index e2a73f6e6..16af49644 100644 --- a/vtkm/List.h +++ b/vtkm/List.h @@ -523,6 +523,8 @@ VTKM_SUPPRESS_EXEC_WARNINGS template VTKM_EXEC_CONT void ListForEachImpl(Functor&& f, vtkm::List, Args&&... args) { + VTKM_STATIC_ASSERT_MSG((!std::is_same, vtkm::ListUniversal>::value), + "Cannot call ListFor on vtkm::ListUniversal."); auto init_list = { ListForEachCallThrough( std::forward(f), Ts{}, std::forward(args)...)... }; (void)init_list; diff --git a/vtkm/cont/Field.h b/vtkm/cont/Field.h index 2a3d27b6d..81b51b2f0 100644 --- a/vtkm/cont/Field.h +++ b/vtkm/cont/Field.h @@ -101,6 +101,8 @@ public: template VTKM_CONT const vtkm::cont::ArrayHandle& GetRange(TypeList) const { + VTKM_STATIC_ASSERT_MSG((!std::is_same::value), + "Cannot get the field range with vtkm::ListUniversal."); return this->GetRangeImpl(TypeList()); } diff --git a/vtkm/cont/FieldRangeCompute.h b/vtkm/cont/FieldRangeCompute.h index 4ebc856f5..aa6d9422c 100644 --- a/vtkm/cont/FieldRangeCompute.h +++ b/vtkm/cont/FieldRangeCompute.h @@ -75,6 +75,8 @@ VTKM_CONT vtkm::cont::ArrayHandle FieldRangeCompute( TypeList) { VTKM_IS_LIST(TypeList); + VTKM_STATIC_ASSERT_MSG((!std::is_same::value), + "Cannot use vtkm::ListUniversal with FieldRangeCompute."); return vtkm::cont::detail::FieldRangeComputeImpl(pds, name, assoc, TypeList()); } diff --git a/vtkm/cont/VariantArrayHandle.h b/vtkm/cont/VariantArrayHandle.h index 837f6e8d0..a6ed7dd3c 100644 --- a/vtkm/cont/VariantArrayHandle.h +++ b/vtkm/cont/VariantArrayHandle.h @@ -63,6 +63,9 @@ namespace cont template class VTKM_ALWAYS_EXPORT VariantArrayHandleBase { + VTKM_STATIC_ASSERT_MSG((!std::is_same::value), + "Cannot use vtkm::ListUniversal with VariantArrayHandle."); + public: VTKM_CONT VariantArrayHandleBase() = default; diff --git a/vtkm/filter/Filter.h b/vtkm/filter/Filter.h index 2312be9cb..dee4e13e4 100644 --- a/vtkm/filter/Filter.h +++ b/vtkm/filter/Filter.h @@ -184,7 +184,7 @@ public: /// A filter is able to state what subset of types it supports /// by default. By default we use ListUniversal to represent that the /// filter accepts all types specified by the users provided policy - using SupportedTypes = vtkm::ListUniversal; + using SupportedTypes = VTKM_DEFAULT_TYPE_LIST; /// \brief Specify which additional field storage to support. /// diff --git a/vtkm/filter/Histogram.hxx b/vtkm/filter/Histogram.hxx index a81412e85..5244e64a2 100644 --- a/vtkm/filter/Histogram.hxx +++ b/vtkm/filter/Histogram.hxx @@ -212,7 +212,12 @@ template inline VTKM_CONT void Histogram::PreExecute(const vtkm::cont::PartitionedDataSet& input, const vtkm::filter::PolicyBase&) { - using TypeList = typename DerivedPolicy::FieldTypeList; + // Policies are on their way out, but until they are we want to respect them. In the mean + // time, respect the policy if it is defined. + using TypeList = typename std::conditional< + std::is_same::value, + VTKM_DEFAULT_TYPE_LIST, + typename DerivedPolicy::FieldTypeList>::type; if (this->Range.IsNonEmpty()) { this->ComputedRange = this->Range; diff --git a/vtkm/filter/PolicyBase.h b/vtkm/filter/PolicyBase.h index f4cbbc551..613771a68 100644 --- a/vtkm/filter/PolicyBase.h +++ b/vtkm/filter/PolicyBase.h @@ -32,7 +32,7 @@ namespace filter template struct PolicyBase { - using FieldTypeList = VTKM_DEFAULT_TYPE_LIST; + using FieldTypeList = vtkm::ListUniversal; using StorageList = VTKM_DEFAULT_STORAGE_LIST; using StructuredCellSetList = VTKM_DEFAULT_CELL_SET_LIST_STRUCTURED; @@ -201,10 +201,18 @@ using ArrayHandleMultiplexerForStorageList = vtkm::cont::ArrayHandleMultiplexerF /// passed to the `DoMapField` method of filters. /// template -VTKM_CONT vtkm::cont::VariantArrayHandleBase +VTKM_CONT vtkm::cont::VariantArrayHandleBase::value, + VTKM_DEFAULT_TYPE_LIST, + typename DerivedPolicy::FieldTypeList>::type> ApplyPolicyFieldNotActive(const vtkm::cont::Field& field, vtkm::filter::PolicyBase) { - using TypeList = typename DerivedPolicy::FieldTypeList; + // Policies are on their way out, but until they are we want to respect them. In the mean + // time, respect the policy if it is defined. + using TypeList = typename std::conditional< + std::is_same::value, + VTKM_DEFAULT_TYPE_LIST, + typename DerivedPolicy::FieldTypeList>::type; return field.GetData().ResetTypes(TypeList()); }