//============================================================================ // Copyright (c) Kitware, Inc. // All rights reserved. // See LICENSE.txt for details. // // This software is distributed WITHOUT ANY WARRANTY; without even // the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR // PURPOSE. See the above copyright notice for more information. //============================================================================ #ifndef vtk_m_filter_PolicyBase_h #define vtk_m_filter_PolicyBase_h #include #include #include #include #include #include #include #include #include #include namespace vtkm { namespace filter { template struct PolicyBase { using FieldTypeList = vtkm::ListUniversal; using StorageList = VTKM_DEFAULT_STORAGE_LIST; using StructuredCellSetList = VTKM_DEFAULT_CELL_SET_LIST_STRUCTURED; using UnstructuredCellSetList = VTKM_DEFAULT_CELL_SET_LIST_UNSTRUCTURED; using AllCellSetList = VTKM_DEFAULT_CELL_SET_LIST; }; namespace internal { namespace detail { // Given a base type, forms a list of all types with the same Vec structure but with the // base component replaced with each of the basic C types. template struct AllCastingTypes { using VTraits = vtkm::VecTraits; using type = vtkm::List, typename VTraits::template ReplaceBaseComponentType, typename VTraits::template ReplaceBaseComponentType, typename VTraits::template ReplaceBaseComponentType, typename VTraits::template ReplaceBaseComponentType, typename VTraits::template ReplaceBaseComponentType, typename VTraits::template ReplaceBaseComponentType, typename VTraits::template ReplaceBaseComponentType, typename VTraits::template ReplaceBaseComponentType, typename VTraits::template ReplaceBaseComponentType>; }; // Provides a transform template that builds a cast from an array of some source type to a // cast array to a specific target type. template struct CastArrayTransform { template using Transform = vtkm::cont::ArrayHandleCast>; }; // Provides a predicate for a particular storage that resolves to std::true_type if a given // type cannot be used with the storage. template struct ArrayValidPredicate { template using Predicate = vtkm::cont::internal::IsInvalidArrayHandle; }; template struct AllCastArraysForStorageImpl; template struct ValidCastingTypes { using type = vtkm::ListRemoveIf::type, ArrayValidPredicate::template Predicate>; }; template struct AllCastArraysForStorageImpl { using SourceTypes = typename ValidCastingTypes::type; using CastArrays = vtkm::ListTransform::template Transform>; using type = vtkm::ListAppend>, CastArrays>; }; template struct AllCastArraysForStorageImpl { using SourceTypes = typename ValidCastingTypes::type; using type = vtkm::ListTransform::template Transform>; }; // Special cases for known storage with limited type support. template <> struct AllCastArraysForStorageImpl { using type = vtkm::List; }; template struct AllCastArraysForStorageImpl, vtkm::cont::ArrayHandleUniformPointCoordinates::StorageTag, false> { using type = vtkm::List, vtkm::cont::ArrayHandle>>; }; template struct AllCastArraysForStorageImpl { using type = vtkm::ListEmpty; }; template struct AllCastArraysForStorageImpl, vtkm::cont::StorageTagCartesianProduct, true> { using type = vtkm::List, vtkm::cont::ArrayHandle, vtkm::cont::ArrayHandle>>; }; template struct AllCastArraysForStorageImpl, false> { using type = vtkm::ListEmpty; }; #ifdef VTKM_ADD_XGC_DEFAULT_TYPES template struct AllCastArraysForStorageImpl, vtkm::cont::StorageTagXGCCoordinates, true> { using type = vtkm::List>; }; template struct AllCastArraysForStorageImpl { using type = vtkm::ListEmpty; }; #endif // Given a target type and storage of an array handle, provides a list this array handle plus all // array handles that can be cast to the target type wrapped in an ArrayHandleCast that does so. template struct AllCastArraysForStorage { using type = typename AllCastArraysForStorageImpl< TargetT, Storage, vtkm::cont::internal::IsValidArrayHandle::value>::type; }; // Provides a transform template that converts a storage type to a list of all arrays that come // from that storage type and can be cast to a target type (wrapped in an ArrayHandleCast as // appropriate). template struct AllCastArraysTransform { template using Transform = typename AllCastArraysForStorage::type; }; // Given a target type and a list of storage types, provides a joined list of all possible arrays // of any of these storage cast to the target type. template struct AllCastArraysForStorageList { VTKM_IS_LIST(StorageList); using listOfLists = vtkm::ListTransform::template Transform>; using type = vtkm::ListApply; }; } // detail template using ArrayHandleMultiplexerForStorageList = vtkm::cont::ArrayHandleMultiplexerFromList< typename detail::AllCastArraysForStorageList::type>; } // namespace internal //----------------------------------------------------------------------------- /// \brief Get an array from a `Field` that is not the active field. /// /// Use this form for getting a `Field` when you don't know the type and it is not /// (necessarily) the "active" field of the filter. It is generally used for arrays /// passed to the `DoMapField` method of filters. /// template VTKM_CONT vtkm::cont::UncertainArrayHandle< typename std::conditional< std::is_same::value, VTKM_DEFAULT_TYPE_LIST, typename DerivedPolicy::FieldTypeList>::type, typename DerivedPolicy::StorageList> ApplyPolicyFieldNotActive(const vtkm::cont::Field& field, vtkm::filter::PolicyBase) { // 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{}, typename DerivedPolicy::StorageList{}); } //----------------------------------------------------------------------------- /// \brief Get an `ArrayHandle` of a specific type from a `Field`. /// /// Use this form of `ApplyPolicy` when you know what the value type of a field is or /// (more likely) there is a type you are going to cast it to anyway. /// template VTKM_CONT internal::ArrayHandleMultiplexerForStorageList< T, vtkm::ListAppend::AdditionalFieldStorage, typename DerivedPolicy::StorageList>> ApplyPolicyFieldOfType(const vtkm::cont::Field& field, vtkm::filter::PolicyBase, const FilterType&) { using ArrayHandleMultiplexerType = internal::ArrayHandleMultiplexerForStorageList< T, vtkm::ListAppend>; return field.GetData().AsArrayHandle(); } //----------------------------------------------------------------------------- /// \brief Get an array from a `Field` that follows the types of an active field. /// /// Use this form for getting a `Field` to build the types that are appropriate for /// the active field of this filter. /// template VTKM_CONT vtkm::cont::UncertainArrayHandle< typename vtkm::filter::DeduceFilterFieldTypes< DerivedPolicy, typename vtkm::filter::FilterTraits::InputFieldTypeList>::TypeList, typename vtkm::filter::DeduceFilterFieldStorage< DerivedPolicy, typename vtkm::filter::FilterTraits::AdditionalFieldStorage>::StorageList> ApplyPolicyFieldActive(const vtkm::cont::Field& field, vtkm::filter::PolicyBase, vtkm::filter::FilterTraits) { using FilterTypes = typename vtkm::filter::FilterTraits::InputFieldTypeList; using TypeList = typename vtkm::filter::DeduceFilterFieldTypes::TypeList; using FilterStorage = typename vtkm::filter::FilterTraits::AdditionalFieldStorage; using StorageList = typename vtkm::filter::DeduceFilterFieldStorage::StorageList; return field.GetData().ResetTypes(TypeList{}, StorageList{}); } //----------------------------------------------------------------------------- /// \brief Ge a cell set from a `DynamicCellSet` object. /// /// Adjusts the types of `CellSet`s to support those types specified in a policy. /// template VTKM_CONT vtkm::cont::DynamicCellSetBase> ApplyPolicyCellSet(const vtkm::cont::DynamicCellSet& cellset, vtkm::filter::PolicyBase, const vtkm::filter::Filter&) { using CellSetList = vtkm::ListAppend; return cellset.ResetCellSetList(CellSetList()); } template VTKM_DEPRECATED(1.6, "ApplyPolicyCellSet now takes the filter as an argument.") VTKM_CONT vtkm::cont::DynamicCellSetBase ApplyPolicyCellSet( const vtkm::cont::DynamicCellSet& cellset, vtkm::filter::PolicyBase) { using CellSetList = typename DerivedPolicy::AllCellSetList; return cellset.ResetCellSetList(CellSetList()); } //----------------------------------------------------------------------------- /// \brief Get a structured cell set from a `DynamicCellSet` object. /// /// Adjusts the types of `CellSet`s to support those structured cell set types /// specified in a policy. /// template VTKM_CONT vtkm::cont::DynamicCellSetBase< vtkm::ListAppend> ApplyPolicyCellSetStructured(const vtkm::cont::DynamicCellSet& cellset, vtkm::filter::PolicyBase, const vtkm::filter::Filter&) { using CellSetList = vtkm::ListAppend; return cellset.ResetCellSetList(CellSetList()); } template VTKM_DEPRECATED(1.6, "ApplyPolicyCellSetStructured now takes the filter as an argument.") VTKM_CONT vtkm::cont:: DynamicCellSetBase ApplyPolicyCellSetStructured( const vtkm::cont::DynamicCellSet& cellset, vtkm::filter::PolicyBase) { using CellSetList = typename DerivedPolicy::StructuredCellSetList; return cellset.ResetCellSetList(CellSetList()); } //----------------------------------------------------------------------------- /// \brief Get an unstructured cell set from a `DynamicCellSet` object. /// /// Adjusts the types of `CellSet`s to support those unstructured cell set types /// specified in a policy. /// template VTKM_CONT vtkm::cont::DynamicCellSetBase< vtkm::ListAppend> ApplyPolicyCellSetUnstructured(const vtkm::cont::DynamicCellSet& cellset, vtkm::filter::PolicyBase, const vtkm::filter::Filter&) { using CellSetList = vtkm::ListAppend; return cellset.ResetCellSetList(CellSetList()); } template VTKM_DEPRECATED(1.6, "ApplyPolicyCellSetUnstructured now takes the filter as an argument.") VTKM_CONT vtkm::cont::DynamicCellSetBase< typename DerivedPolicy:: UnstructuredCellSetList> ApplyPolicyCellSetUnstructured(const vtkm::cont::DynamicCellSet& cellset, vtkm::filter::PolicyBase) { using CellSetList = typename DerivedPolicy::UnstructuredCellSetList; return cellset.ResetCellSetList(CellSetList()); } //----------------------------------------------------------------------------- VTKM_DEPRECATED_SUPPRESS_BEGIN template VTKM_DEPRECATED(1.6, "MakeSerializableField is no longer needed.") VTKM_CONT vtkm::cont::SerializableField MakeSerializableField( vtkm::filter::PolicyBase) { return {}; } template VTKM_DEPRECATED(1.6, "MakeSerializableField is no longer needed.") VTKM_CONT vtkm::cont::SerializableField MakeSerializableField( const vtkm::cont::Field& field, vtkm::filter::PolicyBase) { return vtkm::cont::SerializableField{ field }; } VTKM_DEPRECATED_SUPPRESS_END template VTKM_DEPRECATED(1.6, "MakeSerializableDataSet now takes the filter as an argument.") VTKM_CONT vtkm::cont::SerializableDataSet< typename DerivedPolicy::FieldTypeList, typename DerivedPolicy::AllCellSetList> MakeSerializableDataSet(vtkm::filter:: PolicyBase) { return {}; } template VTKM_CONT vtkm::cont::SerializableDataSet> MakeSerializableDataSet(vtkm::filter::PolicyBase, const vtkm::filter::Filter&) { return {}; } template VTKM_CONT vtkm::cont::SerializableDataSet MakeSerializableDataSet(const vtkm::filter::Filter&) { return {}; } template VTKM_DEPRECATED(1.6, "MakeSerializableDataSet now takes the filter as an argument.") VTKM_CONT vtkm::cont::SerializableDataSet< typename DerivedPolicy::FieldTypeList, typename DerivedPolicy::AllCellSetList> MakeSerializableDataSet(const vtkm::cont::DataSet& dataset, vtkm::filter::PolicyBase< DerivedPolicy>) { return vtkm::cont::SerializableDataSet{ dataset }; } template VTKM_CONT vtkm::cont::SerializableDataSet> MakeSerializableDataSet(const vtkm::cont::DataSet& dataset, vtkm::filter::PolicyBase, const vtkm::filter::Filter&) { return vtkm::cont::SerializableDataSet>{ dataset }; } template VTKM_CONT vtkm::cont::SerializableDataSet MakeSerializableDataSet(const vtkm::cont::DataSet& dataset, const vtkm::filter::Filter&) { return vtkm::cont::SerializableDataSet{ dataset }; } } } // vtkm::filter #endif //vtk_m_filter_PolicyBase_h