diff --git a/docs/changelog/deprecate-arrayhandlevirtualcoordinates.md b/docs/changelog/deprecate-arrayhandlevirtualcoordinates.md new file mode 100644 index 000000000..7fbe67d83 --- /dev/null +++ b/docs/changelog/deprecate-arrayhandlevirtualcoordinates.md @@ -0,0 +1,39 @@ +# Deprecate ArrayHandleVirtualCoordinates + +As we port VTK-m to more types of accelerator architectures, supporting +virtual methods is becoming more problematic. Thus, we are working to back +out of using virtual methods in the execution environment. + +One of the most widespread users of virtual methods in the execution +environment is `ArrayHandleVirtual`. As a first step of deprecating this +class, we first deprecate the `ArrayHandleVirtualCoordinates` subclass. + +Not surprisingly, `ArrayHandleVirtualCoordinates` is used directly by +`CoordinateSystem`. The biggest change necessary was that the `GetData` +method returned an `ArrayHandleVirtualCoordinates`, which obviously would +not work if that class is deprecated. + +An oddness about this return type is that it is quite different from the +superclass's method of the same name. Rather, `Field` returns a +`VariantArrayHandle`. Since this had to be corrected anyway, it was decided +to change `CoordinateSystem`'s `GetData` to also return a +`VariantArrayHandle`, although its typelist is set to just `vtkm::Vec3f`. + +To try to still support old code that expects the deprecated behavior of +returning an `ArrayHandleVirtualCoordinates`, `CoordinateSystem::GetData` +actually returns a "hidden" subclass of `VariantArrayHandle` that +automatically converts itself to an `ArrayHandleVirtualCoordinates`. (A +deprecation warning is given if this is done.) + +This approach to support deprecated code is not perfect. The returned value +for `CoordinateSystem::GetData` can only be used as an `ArrayHandle` if a +method is directly called on it or if it is cast specifically to +`ArrayHandleVirtualCoordinates` or its superclass. For example, if passing +it to a method argument typed as `vtkm::cont::ArrayHandle` where `T` +and `S` are template parameters, then the conversion will fail. + +To continue to support ease of use, `CoordinateSystem` now has a method +named `GetDataAsMultiplexer` that returns the data as an +`ArrayHandleMultiplexer`. This can be employed to quickly use the +`CoordinateSystem` as an array without the overhead of a `CastAndCall`. + diff --git a/examples/multi_backend/IOGenerator.cxx b/examples/multi_backend/IOGenerator.cxx index 86e92496d..f14f345c5 100644 --- a/examples/multi_backend/IOGenerator.cxx +++ b/examples/multi_backend/IOGenerator.cxx @@ -42,7 +42,7 @@ vtkm::cont::DataSet make_test3DImageData(vtkm::Id3 dims) vtkm::cont::ArrayHandle field; vtkm::cont::Invoker invoke; - invoke(WaveField{}, ds.GetCoordinateSystem(), field); + invoke(WaveField{}, ds.GetCoordinateSystem().GetDataAsMultiplexer(), field); ds.AddPointField("vec_field", field); return ds; diff --git a/vtkm/cont/ArrayCopy.h b/vtkm/cont/ArrayCopy.h index 74ffb5023..ccbc52ad7 100644 --- a/vtkm/cont/ArrayCopy.h +++ b/vtkm/cont/ArrayCopy.h @@ -110,6 +110,39 @@ VTKM_CONT void ArrayCopy(const vtkm::cont::ArrayHandle& // Static dispatch cases 1 & 2 detail::ArrayCopyImpl(source, destination, JustCopyStorage{}); } + +// Forward declaration +// Cannot include VariantArrayHandle.h here due to circular dependency. +template +class VariantArrayHandleBase; + +namespace detail +{ + +struct ArrayCopyFunctor +{ + template + VTKM_CONT void operator()(const vtkm::cont::ArrayHandle& source, + vtkm::cont::ArrayHandle& destination) const + { + vtkm::cont::ArrayCopy(source, destination); + } +}; + +} // namespace detail + +/// \brief Deep copies data in a `VariantArrayHandle` to an array of a known type. +/// +/// This form of `ArrayCopy` can be used to copy data from an unknown array type to +/// an array of a known type. Note that regardless of the source type, the data will +/// be deep copied. +/// +template +VTKM_CONT void ArrayCopy(const vtkm::cont::VariantArrayHandleBase& source, + vtkm::cont::ArrayHandle& destination) +{ + source.CastAndCall(detail::ArrayCopyFunctor{}, destination); +} } } // namespace vtkm::cont diff --git a/vtkm/cont/ArrayHandle.h b/vtkm/cont/ArrayHandle.h index 465f4005b..448bd7d14 100644 --- a/vtkm/cont/ArrayHandle.h +++ b/vtkm/cont/ArrayHandle.h @@ -1409,8 +1409,8 @@ VTKM_NEVER_EXPORT VTKM_CONT inline void printSummary_ArrayHandle( vtkm::Id sz = array.GetNumberOfValues(); out << "valueType=" << vtkm::cont::TypeToString() - << " storageType=" << vtkm::cont::TypeToString() << sz << " values occupying " - << (static_cast(sz) * sizeof(T)) << " bytes ["; + << " storageType=" << vtkm::cont::TypeToString() << " " << sz + << " values occupying " << (static_cast(sz) * sizeof(T)) << " bytes ["; PortalType portal = array.ReadPortal(); if (full || sz <= 7) diff --git a/vtkm/cont/ArrayHandleVirtualCoordinates.h b/vtkm/cont/ArrayHandleVirtualCoordinates.h index 198a27df9..83153a54b 100644 --- a/vtkm/cont/ArrayHandleVirtualCoordinates.h +++ b/vtkm/cont/ArrayHandleVirtualCoordinates.h @@ -28,20 +28,24 @@ namespace cont { /// ArrayHandleVirtualCoordinates is a specialization of ArrayHandle. -class VTKM_ALWAYS_EXPORT ArrayHandleVirtualCoordinates final - : public vtkm::cont::ArrayHandleVirtual +class VTKM_ALWAYS_EXPORT VTKM_DEPRECATED(1.6, "Virtual ArrayHandles are being phased out.") + ArrayHandleVirtualCoordinates final : public vtkm::cont::ArrayHandleVirtual { public: VTKM_ARRAY_HANDLE_SUBCLASS_NT(ArrayHandleVirtualCoordinates, (vtkm::cont::ArrayHandleVirtual)); + VTKM_DEPRECATED_SUPPRESS_BEGIN template explicit ArrayHandleVirtualCoordinates(const vtkm::cont::ArrayHandle& ah) : vtkm::cont::ArrayHandleVirtual(vtkm::cont::make_ArrayHandleCast(ah)) { } + VTKM_DEPRECATED_SUPPRESS_END }; +VTKM_DEPRECATED_SUPPRESS_BEGIN + template void CastAndCall(const vtkm::cont::ArrayHandleVirtualCoordinates& coords, Functor&& f, @@ -66,6 +70,8 @@ struct SerializableTypeString static VTKM_CONT const std::string Get() { return "AH_VirtualCoordinates"; } }; +VTKM_DEPRECATED_SUPPRESS_END + } // namespace cont } // namespace vtkm @@ -75,6 +81,8 @@ struct SerializableTypeString namespace mangled_diy_namespace { +VTKM_DEPRECATED_SUPPRESS_BEGIN + template <> struct Serialization { @@ -173,6 +181,8 @@ public: } }; +VTKM_DEPRECATED_SUPPRESS_END + } // diy /// @endcond SERIALIZATION diff --git a/vtkm/cont/ArrayRangeCompute.h b/vtkm/cont/ArrayRangeCompute.h index 893948a1a..f9cd2dfec 100644 --- a/vtkm/cont/ArrayRangeCompute.h +++ b/vtkm/cont/ArrayRangeCompute.h @@ -16,7 +16,7 @@ #include #include #include -#include +#include #include namespace vtkm diff --git a/vtkm/cont/CMakeLists.txt b/vtkm/cont/CMakeLists.txt index 6e89655fe..60bd5b9df 100644 --- a/vtkm/cont/CMakeLists.txt +++ b/vtkm/cont/CMakeLists.txt @@ -128,7 +128,6 @@ set(template_sources CellSetExtrude.hxx CellSetStructured.hxx ColorTable.hxx - CoordinateSystem.hxx FieldRangeCompute.hxx FieldRangeGlobalCompute.hxx StorageVirtual.hxx diff --git a/vtkm/cont/CellLocatorBoundingIntervalHierarchy.cxx b/vtkm/cont/CellLocatorBoundingIntervalHierarchy.cxx index 6915e188b..9c675e010 100644 --- a/vtkm/cont/CellLocatorBoundingIntervalHierarchy.cxx +++ b/vtkm/cont/CellLocatorBoundingIntervalHierarchy.cxx @@ -234,7 +234,7 @@ void CellLocatorBoundingIntervalHierarchy::Build() vtkm::cont::DynamicCellSet cellSet = this->GetCellSet(); vtkm::Id numCells = cellSet.GetNumberOfCells(); vtkm::cont::CoordinateSystem coords = this->GetCoordinates(); - vtkm::cont::ArrayHandleVirtualCoordinates points = coords.GetData(); + auto points = coords.GetDataAsMultiplexer(); //std::cout << "No of cells: " << numCells << "\n"; //std::cout.precision(3); @@ -457,7 +457,7 @@ struct CellLocatorBIHPrepareForExecutionFunctor vtkm::cont::VirtualObjectHandle& bihExec, const vtkm::cont::ArrayHandle& nodes, const vtkm::cont::ArrayHandle& processedCellIds, - const vtkm::cont::ArrayHandleVirtualCoordinates& coords) const + const vtkm::cont::CoordinateSystem::MultiplexerArrayType& coords) const { using ExecutionType = vtkm::exec::CellLocatorBoundingIntervalHierarchyExec; @@ -501,7 +501,7 @@ const vtkm::exec::CellLocator* CellLocatorBoundingIntervalHierarchy::PrepareForE this->ExecutionObjectHandle, this->Nodes, this->ProcessedCellIds, - this->GetCoordinates().GetData()); + this->GetCoordinates().GetDataAsMultiplexer()); return this->ExecutionObjectHandle.PrepareForExecution(device, token); ; } diff --git a/vtkm/cont/CellLocatorUniformBins.h b/vtkm/cont/CellLocatorUniformBins.h index 1efbfe00a..c5a5d2791 100644 --- a/vtkm/cont/CellLocatorUniformBins.h +++ b/vtkm/cont/CellLocatorUniformBins.h @@ -94,9 +94,9 @@ private: using ArrayPortalConst = typename vtkm::cont::ArrayHandle::template ExecutionTypes::PortalConst; - using CoordsPortalType = decltype(vtkm::cont::ArrayHandleVirtualCoordinates{}.PrepareForInput( - DeviceAdapter{}, - std::declval())); + using CoordsPortalType = + typename vtkm::cont::CoordinateSystem::MultiplexerArrayType::ExecutionTypes< + DeviceAdapter>::PortalConst; using CellSetP2CExecType = decltype(std::declval().PrepareForInput(DeviceAdapter{}, @@ -150,7 +150,7 @@ public: vtkm::TopologyElementTagCell{}, vtkm::TopologyElementTagPoint{}, token)) - , Coords(coords.GetData().PrepareForInput(DeviceAdapter{}, token)) + , Coords(coords.GetDataAsMultiplexer().PrepareForInput(DeviceAdapter{}, token)) { } diff --git a/vtkm/cont/CellLocatorUniformGrid.cxx b/vtkm/cont/CellLocatorUniformGrid.cxx index d39535d2a..c82f6b5b3 100644 --- a/vtkm/cont/CellLocatorUniformGrid.cxx +++ b/vtkm/cont/CellLocatorUniformGrid.cxx @@ -81,12 +81,10 @@ struct CellLocatorUniformGridPrepareForExecutionFunctor template VTKM_CONT bool operator()(DeviceAdapter, vtkm::cont::VirtualObjectHandle& execLocator, - vtkm::cont::Token& token, Args&&... args) const { using ExecutionType = vtkm::exec::CellLocatorUniformGrid; - ExecutionType* execObject = - new ExecutionType(std::forward(args)..., DeviceAdapter(), token); + ExecutionType* execObject = new ExecutionType(std::forward(args)..., DeviceAdapter()); execLocator.Reset(execObject); return true; } @@ -103,26 +101,22 @@ const vtkm::exec::CellLocator* CellLocatorUniformGrid::PrepareForExecution( success = vtkm::cont::TryExecuteOnDevice(device, CellLocatorUniformGridPrepareForExecutionFunctor<3>(), this->ExecutionObjectHandle, - token, this->CellDims, this->PointDims, this->Origin, this->InvSpacing, - this->MaxPoint, - this->GetCoordinates().GetData()); + this->MaxPoint); } else { success = vtkm::cont::TryExecuteOnDevice(device, CellLocatorUniformGridPrepareForExecutionFunctor<2>(), this->ExecutionObjectHandle, - token, this->CellDims, this->PointDims, this->Origin, this->InvSpacing, - this->MaxPoint, - this->GetCoordinates().GetData()); + this->MaxPoint); } if (!success) { diff --git a/vtkm/cont/CoordinateSystem.cxx b/vtkm/cont/CoordinateSystem.cxx index ec43c7e95..271b85f13 100644 --- a/vtkm/cont/CoordinateSystem.cxx +++ b/vtkm/cont/CoordinateSystem.cxx @@ -10,22 +10,32 @@ #include #include -#include namespace vtkm { namespace cont { +namespace detail +{ + +VTKM_DEPRECATED_SUPPRESS_BEGIN +vtkm::cont::ArrayHandleVirtualCoordinates CoordDataDepWrapper::ToArray() const +{ + return this->Cast(); +} +VTKM_DEPRECATED_SUPPRESS_END + +} // namespace detail + VTKM_CONT CoordinateSystem::CoordinateSystem() : Superclass() { } -VTKM_CONT CoordinateSystem::CoordinateSystem( - std::string name, - const vtkm::cont::ArrayHandleVirtual& data) - : Superclass(name, Association::POINTS, data) +VTKM_CONT CoordinateSystem::CoordinateSystem(std::string name, + const vtkm::cont::VariantArrayHandleCommon& data) + : Superclass(name, Association::POINTS, vtkm::cont::VariantArrayHandle{ data }) { } @@ -38,21 +48,19 @@ CoordinateSystem::CoordinateSystem(std::string name, vtkm::Vec3f spacing) : Superclass(name, Association::POINTS, - vtkm::cont::ArrayHandleVirtualCoordinates( - vtkm::cont::ArrayHandleUniformPointCoordinates(dimensions, origin, spacing))) + vtkm::cont::ArrayHandleUniformPointCoordinates(dimensions, origin, spacing)) { } -VTKM_CONT -vtkm::cont::ArrayHandleVirtualCoordinates CoordinateSystem::GetData() const +VTKM_CONT vtkm::cont::detail::CoordDataDepWrapper CoordinateSystem::GetData() const { - return this->Superclass::GetData().Cast(); + return vtkm::cont::detail::CoordDataDepWrapper(this->Superclass::GetData()); } -VTKM_CONT -void CoordinateSystem::SetData(const vtkm::cont::ArrayHandleVirtual& newdata) +VTKM_CONT vtkm::cont::CoordinateSystem::MultiplexerArrayType +CoordinateSystem::GetDataAsMultiplexer() const { - this->Superclass::SetData(newdata); + return this->GetData().AsMultiplexer(); } VTKM_CONT @@ -103,14 +111,5 @@ template VTKM_CONT_EXPORT CoordinateSystem::CoordinateSystem( vtkm::cont::ArrayHandle, vtkm::cont::ArrayHandle, vtkm::cont::ArrayHandle>::StorageTag>&); - -template VTKM_CONT_EXPORT CoordinateSystem::CoordinateSystem(std::string name, - const vtkm::cont::VariantArrayHandle&); - -template VTKM_CONT_EXPORT void CoordinateSystem::SetData( - const vtkm::cont::ArrayHandle>&); -template VTKM_CONT_EXPORT void CoordinateSystem::SetData( - const vtkm::cont::ArrayHandle>&); -template VTKM_CONT_EXPORT void CoordinateSystem::SetData(const vtkm::cont::VariantArrayHandle&); } } // namespace vtkm::cont diff --git a/vtkm/cont/CoordinateSystem.h b/vtkm/cont/CoordinateSystem.h index 6e532c69d..7ad9c5e21 100644 --- a/vtkm/cont/CoordinateSystem.h +++ b/vtkm/cont/CoordinateSystem.h @@ -11,6 +11,7 @@ #define vtk_m_cont_CoordinateSystem_h #include +#include #include #include @@ -21,25 +22,116 @@ namespace vtkm { namespace cont { + +namespace detail +{ + +// CoordinateSystem::GetData used to return an ArrayHandleVirtualCoordinates. +// That behavior is deprecated, and CoordianteSystem::GetData now returns a +// VariantArrayHandle similar (although slightly different than) its superclass. +// This wrapper class supports the old deprecated behavior until it is no longer +// supported. Once the behavior is removed (probably when +// ArrayHandleVirtualCoordinates is removed), then this class should be removed. +class VTKM_ALWAYS_EXPORT CoordDataDepWrapper + : public vtkm::cont::VariantArrayHandleBase +{ + using Superclass = vtkm::cont::VariantArrayHandleBase; + + VTKM_DEPRECATED_SUPPRESS_BEGIN + VTKM_CONT_EXPORT VTKM_CONT vtkm::cont::ArrayHandleVirtualCoordinates ToArray() const; + VTKM_DEPRECATED_SUPPRESS_END + +public: + using Superclass::Superclass; + + // Make the return also behave as ArrayHandleVirtualCoordiantes + VTKM_DEPRECATED_SUPPRESS_BEGIN + + VTKM_CONT VTKM_DEPRECATED(1.6, "CoordinateSystem::GetData() now returns a VariantArrayHandle.") + operator vtkm::cont::ArrayHandleVirtualCoordinates() const + { + return this->ToArray(); + } + + VTKM_CONT VTKM_DEPRECATED(1.6, "CoordinateSystem::GetData() now returns a VariantArrayHandle.") + operator vtkm::cont::ArrayHandle() const + { + return this->ToArray(); + } + + using ValueType VTKM_DEPRECATED(1.6, + "CoordinateSystem::GetData() now returns a VariantArrayHandle.") = + vtkm::Vec3f; + + VTKM_CONT VTKM_DEPRECATED(1.6, "CoordinateSystem::GetData() now returns a VariantArrayHandle.") + ArrayHandleVirtualCoordinates::ReadPortalType ReadPortal() const + { + return this->ToArray().ReadPortal(); + } + + VTKM_CONT VTKM_DEPRECATED(1.6, "CoordinateSystem::GetData() now returns a VariantArrayHandle.") + ArrayHandleVirtualCoordinates::WritePortalType WritePortal() const + { + return this->ToArray().WritePortal(); + } + + template + VTKM_CONT VTKM_DEPRECATED(1.6, "CoordinateSystem::GetData() now returns a VariantArrayHandle.") + typename ArrayHandleVirtualCoordinates::ExecutionTypes::PortalConst + PrepareForInput(Device device, vtkm::cont::Token& token) const + { + return this->ToArray().PrepareForInput(device, token); + } + + template + VTKM_CONT VTKM_DEPRECATED(1.6, "CoordinateSystem::GetData() now returns a VariantArrayHandle.") + typename ArrayHandleVirtualCoordinates::ExecutionTypes::Portal + PrepareForInPlace(Device device, vtkm::cont::Token& token) const + { + return this->ToArray().PrepareForInPlace(device, token); + } + + template + VTKM_CONT VTKM_DEPRECATED(1.6, "CoordinateSystem::GetData() now returns a VariantArrayHandle.") + typename ArrayHandleVirtualCoordinates::ExecutionTypes::Portal + PrepareForOutput(vtkm::Id numberOfValues, Device device, vtkm::cont::Token& token) const + { + return this->ToArray().PrepareForOutput(numberOfValues, device, token); + } + + VTKM_DEPRECATED_SUPPRESS_END +}; + +} // namespace detail + +VTKM_DEPRECATED_SUPPRESS_BEGIN +VTKM_CONT VTKM_DEPRECATED( + 1.6, + "CoordinateSystem::GetData() now returns a " + "VariantArrayHandle.") inline void printSummary_ArrayHandle(const detail::CoordDataDepWrapper& + array, + std::ostream& out, + bool full = false) +{ + vtkm::cont::ArrayHandleVirtualCoordinates coordArray = array; + vtkm::cont::printSummary_ArrayHandle(coordArray, out, full); +} +VTKM_DEPRECATED_SUPPRESS_END + class VTKM_CONT_EXPORT CoordinateSystem : public vtkm::cont::Field { using Superclass = vtkm::cont::Field; - using CoordinatesTypeList = vtkm::List; + using CoordinatesTypeList = vtkm::List; public: VTKM_CONT CoordinateSystem(); - VTKM_CONT CoordinateSystem(std::string name, - const vtkm::cont::ArrayHandleVirtual& data); - - template - VTKM_CONT CoordinateSystem(std::string name, - const vtkm::cont::VariantArrayHandleBase& data); + VTKM_CONT CoordinateSystem(std::string name, const vtkm::cont::VariantArrayHandleCommon& data); template VTKM_CONT CoordinateSystem(std::string name, const ArrayHandle& data) - : Superclass(name, Association::POINTS, vtkm::cont::ArrayHandleVirtualCoordinates(data)) + : Superclass(name, Association::POINTS, data) { } @@ -54,17 +146,54 @@ public: VTKM_CONT vtkm::Id GetNumberOfPoints() const { return this->GetNumberOfValues(); } - VTKM_CONT - vtkm::cont::ArrayHandleVirtualCoordinates GetData() const; + VTKM_CONT detail::CoordDataDepWrapper GetData() const; - VTKM_CONT void SetData(const vtkm::cont::ArrayHandleVirtual& newdata); +private: +#ifdef VTKM_USE_DOUBLE_PRECISION + using FloatNonDefault = vtkm::Float32; +#else + using FloatNonDefault = vtkm::Float64; +#endif + using Vec3f_nd = vtkm::Vec; - template - VTKM_CONT void SetData(const vtkm::cont::ArrayHandle& newdata); + struct StorageToArrayDefault + { + template + using IsInvalid = vtkm::cont::internal::IsInvalidArrayHandle; - VTKM_CONT - template - void SetData(const vtkm::cont::VariantArrayHandleBase& newdata); + template + using Transform = vtkm::cont::ArrayHandle; + }; + + struct StorageToArrayNonDefault + { + template + using IsInvalid = vtkm::cont::internal::IsInvalidArrayHandle; + + template + using Transform = + vtkm::cont::ArrayHandleCast>; + }; + + using ArraysFloatDefault = vtkm::ListTransform< + vtkm::ListRemoveIf, + StorageToArrayDefault::Transform>; + using ArraysFloatNonDefault = vtkm::ListTransform< + vtkm::ListRemoveIf, + StorageToArrayNonDefault::Transform>; + +public: + using MultiplexerArrayType = // + vtkm::cont::ArrayHandleMultiplexerFromList< + vtkm::ListAppend>; + + /// \brief Returns the data for the coordinate system as an `ArrayHandleMultiplexer`. + /// + /// This array will handle all potential types supported by CoordinateSystem, so all types can be + /// handled with one compile pass. However, using this precludes specialization for special + /// arrays such as `ArrayHandleUniformPointCoordinates` that could have optimized code paths + /// + VTKM_CONT MultiplexerArrayType GetDataAsMultiplexer() const; VTKM_CONT void GetRange(vtkm::Range* range) const @@ -138,6 +267,12 @@ struct DynamicTransformTraits using DynamicTag = vtkm::cont::internal::DynamicTransformTagCastAndCall; }; +template <> +struct DynamicTransformTraits +{ + using DynamicTag = vtkm::cont::internal::DynamicTransformTagCastAndCall; +}; + } // namespace internal } // namespace cont } // namespace vtkm @@ -148,22 +283,32 @@ struct DynamicTransformTraits namespace mangled_diy_namespace { +template <> +struct Serialization + : public Serialization< + vtkm::cont::VariantArrayHandleBase>> +{ +}; + template <> struct Serialization { + using CoordinatesTypeList = vtkm::List; + static VTKM_CONT void save(BinaryBuffer& bb, const vtkm::cont::CoordinateSystem& cs) { vtkmdiy::save(bb, cs.GetName()); - vtkmdiy::save(bb, cs.GetData()); + vtkmdiy::save( + bb, static_cast>(cs.GetData())); } static VTKM_CONT void load(BinaryBuffer& bb, vtkm::cont::CoordinateSystem& cs) { std::string name; vtkmdiy::load(bb, name); - vtkm::cont::ArrayHandleVirtualCoordinates array; - vtkmdiy::load(bb, array); - cs = vtkm::cont::CoordinateSystem(name, array); + vtkm::cont::VariantArrayHandleBase data; + vtkmdiy::load(bb, data); + cs = vtkm::cont::CoordinateSystem(name, data); } }; diff --git a/vtkm/cont/CoordinateSystem.hxx b/vtkm/cont/CoordinateSystem.hxx deleted file mode 100644 index f846729fc..000000000 --- a/vtkm/cont/CoordinateSystem.hxx +++ /dev/null @@ -1,73 +0,0 @@ -//============================================================================ -// 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_cont_CoordinateSystem_hxx -#define vtk_m_cont_CoordinateSystem_hxx - -#include - -namespace vtkm -{ -namespace cont -{ -namespace detail -{ - -struct MakeArrayHandleVirtualCoordinatesFunctor -{ - template - VTKM_CONT void operator()(const vtkm::cont::ArrayHandle& array, - ArrayHandleVirtualCoordinates& output) const - { - output = vtkm::cont::ArrayHandleVirtualCoordinates(array); - } - - template - VTKM_CONT void operator()(const vtkm::cont::ArrayHandle& array, - ArrayHandleVirtualCoordinates& output) const - { - output = vtkm::cont::ArrayHandleVirtualCoordinates(array); - } -}; - -template -VTKM_CONT vtkm::cont::ArrayHandleVirtualCoordinates MakeArrayHandleVirtualCoordinates( - const vtkm::cont::VariantArrayHandleBase& array) -{ - vtkm::cont::ArrayHandleVirtualCoordinates output; - vtkm::cont::CastAndCall(array.ResetTypes(vtkm::TypeListFieldVec3{}), - MakeArrayHandleVirtualCoordinatesFunctor{}, - output); - return output; -} -} // namespace detail - -template -VTKM_CONT CoordinateSystem::CoordinateSystem( - std::string name, - const vtkm::cont::VariantArrayHandleBase& data) - : Superclass(name, Association::POINTS, detail::MakeArrayHandleVirtualCoordinates(data)) -{ -} - -template -VTKM_CONT void CoordinateSystem::SetData(const vtkm::cont::ArrayHandle& newdata) -{ - this->SetData(vtkm::cont::ArrayHandleVirtualCoordinates(newdata)); -} - -template -VTKM_CONT void CoordinateSystem::SetData( - const vtkm::cont::VariantArrayHandleBase& newdata) -{ - this->SetData(detail::MakeArrayHandleVirtualCoordinates(newdata)); -} -} -} -#endif diff --git a/vtkm/cont/DataSetBuilderExplicit.h b/vtkm/cont/DataSetBuilderExplicit.h index e69dd56b4..bf3c697a1 100644 --- a/vtkm/cont/DataSetBuilderExplicit.h +++ b/vtkm/cont/DataSetBuilderExplicit.h @@ -69,19 +69,29 @@ public: const std::string& coordsNm = "coords"); template - VTKM_CONT static vtkm::cont::DataSet Create( - const vtkm::cont::ArrayHandle& xVals, - const vtkm::cont::ArrayHandle& yVals, - const vtkm::cont::ArrayHandle& zVals, - const vtkm::cont::ArrayHandle& shapes, - const vtkm::cont::ArrayHandle& numIndices, - const vtkm::cont::ArrayHandle& connectivity, - const std::string& coordsNm = "coords") + VTKM_DEPRECATED(1.6, + "Combine point coordinate arrays using most appropriate array (e.g. " + "ArrayHandleCompositeVector, ArrayHandleSOA, ArrayHandleCartesianProduct") + VTKM_CONT static vtkm::cont::DataSet + Create(const vtkm::cont::ArrayHandle& xVals, + const vtkm::cont::ArrayHandle& yVals, + const vtkm::cont::ArrayHandle& zVals, + const vtkm::cont::ArrayHandle& shapes, + const vtkm::cont::ArrayHandle& numIndices, + const vtkm::cont::ArrayHandle& connectivity, + const std::string& coordsNm = "coords") { + VTKM_ASSERT(xVals.GetNumberOfValues() == yVals.GetNumberOfValues()); + VTKM_ASSERT(xVals.GetNumberOfValues() == zVals.GetNumberOfValues()); + auto offsets = vtkm::cont::ConvertNumIndicesToOffsets(numIndices); return DataSetBuilderExplicit::BuildDataSet( - xVals, yVals, zVals, shapes, offsets, connectivity, coordsNm); + vtkm::cont::make_ArrayHandleCompositeVector(xVals, yVals, zVals), + shapes, + offsets, + connectivity, + coordsNm); } template @@ -123,15 +133,6 @@ public: } private: - template - static vtkm::cont::DataSet BuildDataSet(const vtkm::cont::ArrayHandle& X, - const vtkm::cont::ArrayHandle& Y, - const vtkm::cont::ArrayHandle& Z, - const vtkm::cont::ArrayHandle& shapes, - const vtkm::cont::ArrayHandle& offsets, - const vtkm::cont::ArrayHandle& connectivity, - const std::string& coordsNm); - template VTKM_CONT static vtkm::cont::DataSet BuildDataSet( const vtkm::cont::ArrayHandle>& coords, @@ -161,9 +162,16 @@ inline VTKM_CONT vtkm::cont::DataSet DataSetBuilderExplicit::Create( { VTKM_ASSERT(xVals.size() == yVals.size() && yVals.size() == zVals.size() && xVals.size() > 0); - auto xArray = vtkm::cont::make_ArrayHandle(xVals, vtkm::CopyFlag::On); - auto yArray = vtkm::cont::make_ArrayHandle(yVals, vtkm::CopyFlag::On); - auto zArray = vtkm::cont::make_ArrayHandle(zVals, vtkm::CopyFlag::On); + vtkm::cont::ArrayHandle coordsArray; + coordsArray.Allocate(static_cast(xVals.size())); + auto coordsPortal = coordsArray.WritePortal(); + for (std::size_t index = 0; index < xVals.size(); ++index) + { + coordsPortal.Set(static_cast(index), + vtkm::make_Vec(static_cast(xVals[index]), + static_cast(yVals[index]), + static_cast(zVals[index]))); + } auto shapesArray = vtkm::cont::make_ArrayHandle(shapes, vtkm::CopyFlag::On); auto connArray = vtkm::cont::make_ArrayHandle(connectivity, vtkm::CopyFlag::On); @@ -172,33 +180,7 @@ inline VTKM_CONT vtkm::cont::DataSet DataSetBuilderExplicit::Create( vtkm::cont::make_ArrayHandle(numIndices, vtkm::CopyFlag::Off)); return DataSetBuilderExplicit::BuildDataSet( - xArray, yArray, zArray, shapesArray, offsetsArray, connArray, coordsNm); -} - -template -inline VTKM_CONT vtkm::cont::DataSet DataSetBuilderExplicit::BuildDataSet( - const vtkm::cont::ArrayHandle& X, - const vtkm::cont::ArrayHandle& Y, - const vtkm::cont::ArrayHandle& Z, - const vtkm::cont::ArrayHandle& shapes, - const vtkm::cont::ArrayHandle& offsets, - const vtkm::cont::ArrayHandle& connectivity, - const std::string& coordsNm) -{ - VTKM_ASSERT(X.GetNumberOfValues() == Y.GetNumberOfValues() && - Y.GetNumberOfValues() == Z.GetNumberOfValues() && X.GetNumberOfValues() > 0 && - shapes.GetNumberOfValues() + 1 == offsets.GetNumberOfValues()); - - vtkm::cont::DataSet dataSet; - dataSet.AddCoordinateSystem( - vtkm::cont::CoordinateSystem(coordsNm, make_ArrayHandleCompositeVector(X, Y, Z))); - vtkm::Id nPts = X.GetNumberOfValues(); - vtkm::cont::CellSetExplicit<> cellSet; - - cellSet.Fill(nPts, shapes, connectivity, offsets); - dataSet.SetCellSet(cellSet); - - return dataSet; + coordsArray, shapesArray, offsetsArray, connArray, coordsNm); } template diff --git a/vtkm/cont/Field.h b/vtkm/cont/Field.h index 20396905d..b039025ee 100644 --- a/vtkm/cont/Field.h +++ b/vtkm/cont/Field.h @@ -126,10 +126,10 @@ public: this->ModifiedFlag = true; } - VTKM_CONT - void SetData(const vtkm::cont::VariantArrayHandle& newdata) + template + VTKM_CONT void SetData(const vtkm::cont::VariantArrayHandleBase& newdata) { - this->Data = newdata; + this->Data = vtkm::cont::VariantArrayHandle(newdata); this->ModifiedFlag = true; } diff --git a/vtkm/cont/PointLocatorUniformGrid.cxx b/vtkm/cont/PointLocatorUniformGrid.cxx index f584fdf04..f3273256a 100644 --- a/vtkm/cont/PointLocatorUniformGrid.cxx +++ b/vtkm/cont/PointLocatorUniformGrid.cxx @@ -115,7 +115,7 @@ struct PointLocatorUniformGrid::PrepareExecutionObjectFunctor rmin, rmax, self.Dims, - self.GetCoordinates().GetData().PrepareForInput(DeviceAdapter(), token), + self.GetCoordinates().GetDataAsMultiplexer().PrepareForInput(DeviceAdapter(), token), self.PointIds.PrepareForInput(DeviceAdapter(), token), self.CellLower.PrepareForInput(DeviceAdapter(), token), self.CellUpper.PrepareForInput(DeviceAdapter(), token)); diff --git a/vtkm/cont/VariantArrayHandle.h b/vtkm/cont/VariantArrayHandle.h index f956a8e79..a836d1b74 100644 --- a/vtkm/cont/VariantArrayHandle.h +++ b/vtkm/cont/VariantArrayHandle.h @@ -84,7 +84,18 @@ public: template VTKM_CONT ArrayHandleType Cast() const { +// MSVC will issue deprecation warnings if this templated method is instantiated with +// a deprecated class here even if the method is called from a section of code where +// deprecation warnings are suppressed. This is annoying behavior since this templated +// method has no control over what class it is used from. To get around it, we have to +// suppress all deprecation warnings here. +#ifdef VTKM_MSVC + VTKM_DEPRECATED_SUPPRESS_BEGIN +#endif return internal::variant::Cast(this->ArrayContainer.get()); +#ifdef VTKM_MSVC + VTKM_DEPRECATED_SUPPRESS_END +#endif } /// \brief Call a functor using the underlying array type. @@ -202,7 +213,7 @@ public: /// \brief Holds an array handle without having to specify template parameters. /// -/// \c VariantArrayHandle holds an \c ArrayHandle or \c ArrayHandleVirtual +/// `VariantArrayHandle` holds an `ArrayHandle` /// object using runtime polymorphism to manage different value types and /// storage rather than compile-time templates. This adds a programming /// convenience that helps avoid a proliferation of templates. It also provides @@ -210,24 +221,23 @@ public: /// will not be known until runtime. /// /// To interface between the runtime polymorphism and the templated algorithms -/// in VTK-m, \c VariantArrayHandle contains a method named \c CastAndCall that -/// will determine the correct type from some known list of types. It returns -/// an ArrayHandleVirtual which type erases the storage type by using polymorphism. +/// in VTK-m, `VariantArrayHandle` contains a method named `CastAndCall` that +/// will determine the correct type from some known list of types. /// This mechanism is used internally by VTK-m's worklet invocation /// mechanism to determine the type when running algorithms. /// -/// By default, \c VariantArrayHandle will assume that the value type in the -/// array matches one of the types specified by \c VTKM_DEFAULT_TYPE_LIST -/// This list can be changed by using the \c ResetTypes. It is +/// By default, `VariantArrayHandle` will assume that the value type in the +/// array matches one of the types specified by `VTKM_DEFAULT_TYPE_LIST` +/// This list can be changed by using the `ResetTypes`. It is /// worthwhile to match these lists closely to the possible types that might be /// used. If a type is missing you will get a runtime error. If there are more /// types than necessary, then the template mechanism will create a lot of /// object code that is never used, and keep in mind that the number of -/// combinations grows exponentially when using multiple \c VariantArrayHandle +/// combinations grows exponentially when using multiple `VariantArrayHandle` /// objects. /// -/// The actual implementation of \c VariantArrayHandle is in a templated class -/// named \c VariantArrayHandleBase, which is templated on the list of +/// The actual implementation of `VariantArrayHandle` is in a templated class +/// named `VariantArrayHandleBase`, which is templated on the list of /// component types. /// template @@ -301,16 +311,12 @@ public: /// `CastAndCall` attempts to cast the held array to a specific value type, /// then call the given functor with the cast array. The types /// tried in the cast are those in the lists defined by the TypeList. - /// By default \c VariantArrayHandle set this to \c VTKM_DEFAULT_TYPE_LIST. + /// By default `VariantArrayHandle` set this to `VTKM_DEFAULT_TYPE_LIST`. /// - /// In addition to the value type, an \c ArrayHandle also requires a storage tag. - /// By default, \c CastAndCall attempts to cast the array using the storage tags - /// listed in \c VTKM_DEFAULT_STORAGE_LIST. You can optionally give a custom - /// list of storage tags as the second argument. If the storage of the underlying - /// array does not match any of the storage tags given, then the array will - /// be cast to an \c ArrayHandleVirtual, which can hold any array given the - /// appropriate value type. To always use \c ArrayHandleVirtual, pass - /// \c vtkm::ListEmpty as thefirst argument. + /// In addition to the value type, an `ArrayHandle` also requires a storage tag. + /// By default, `CastAndCall` attempts to cast the array using the storage tags + /// listed in `VTKM_DEFAULT_STORAGE_LIST`. You can optionally give a custom + /// list of storage tags as the second argument. /// /// As previous stated, if a storage tag list is provided, it is given in the /// first argument. The functor to call with the cast array is given as the next @@ -318,7 +324,7 @@ public: /// The remaning arguments, if any, are passed to the functor. /// /// The functor will be called with the cast array as its first argument. Any - /// remaining arguments are passed from the arguments to \c CastAndCall. + /// remaining arguments are passed from the arguments to `CastAndCall`. /// template VTKM_CONT void CastAndCall(FunctorOrStorageList&& functorOrStorageList, Args&&... args) const @@ -423,35 +429,6 @@ struct VariantArrayHandleTry } }; -struct VariantArrayHandleTryFallback -{ - template - void operator()(T, - Functor&& f, - bool& called, - const vtkm::cont::internal::VariantArrayHandleContainerBase& container, - Args&&... args) const - { - if (!called && vtkm::cont::internal::variant::IsValueType(&container)) - { - called = true; - const auto* derived = - static_cast*>(&container); - VTKM_LOG_CAST_SUCC(container, derived); - - // If you get a compile error here, it means that you have called CastAndCall for a - // vtkm::cont::VariantArrayHandle and the arguments of the functor do not match those - // being passed. This is often because it is calling the functor with an ArrayHandle - // type that was not expected. Either add overloads to the functor to accept all - // possible array types or constrain the types tried for the CastAndCall. Note that - // the functor will be called with an array of type vtkm::cont::ArrayHandle. - // Directly using a subclass of ArrayHandle (e.g. vtkm::cont::ArrayHandleConstant) - // might not work. - f(derived->Array, std::forward(args)...); - } - } -}; - template struct IsUndefinedStorage { @@ -484,16 +461,6 @@ VTKM_CONT void VariantArrayHandleCommon::CastAndCall(Functor&& f, Args&&... args ref, std::forward(args)...); if (!called) - { - // try to fall back to using ArrayHandleVirtual - vtkm::ListForEach(detail::VariantArrayHandleTryFallback{}, - TypeList{}, - std::forward(f), - called, - ref, - std::forward(args)...); - } - if (!called) { // throw an exception VTKM_LOG_CAST_FAIL(*this, TypeList); @@ -660,14 +627,14 @@ struct VariantArrayHandleSerializeFunctor struct VariantArrayHandleDeserializeFunctor { - template - void operator()(T, + template + void operator()(vtkm::List, vtkm::cont::VariantArrayHandleBase& dh, const std::string& typeString, bool& success, BinaryBuffer& bb) const { - using ArrayHandleType = vtkm::cont::ArrayHandleVirtual; + using ArrayHandleType = vtkm::cont::ArrayHandle; if (!success && (typeString == vtkm::cont::SerializableTypeString::Get())) { @@ -690,7 +657,7 @@ private: public: static VTKM_CONT void save(BinaryBuffer& bb, const Type& obj) { - obj.CastAndCall(vtkm::ListEmpty(), internal::VariantArrayHandleSerializeFunctor{}, bb); + obj.CastAndCall(internal::VariantArrayHandleSerializeFunctor{}, bb); } static VTKM_CONT void load(BinaryBuffer& bb, Type& obj) @@ -699,8 +666,12 @@ public: vtkmdiy::load(bb, typeString); bool success = false; - vtkm::ListForEach( - internal::VariantArrayHandleDeserializeFunctor{}, TypeList{}, obj, typeString, success, bb); + vtkm::ListForEach(internal::VariantArrayHandleDeserializeFunctor{}, + vtkm::cont::detail::ListDynamicTypes{}, + obj, + typeString, + success, + bb); if (!success) { diff --git a/vtkm/cont/internal/VariantArrayHandleContainer.cxx b/vtkm/cont/internal/VariantArrayHandleContainer.cxx index 9880a8ada..612e4a882 100644 --- a/vtkm/cont/internal/VariantArrayHandleContainer.cxx +++ b/vtkm/cont/internal/VariantArrayHandleContainer.cxx @@ -43,7 +43,7 @@ VTKM_CONT_EXPORT void ThrowCastAndCallException( const std::type_info& type) { std::ostringstream out; - out << "Could not find appropriate cast for array in CastAndCall1.\n" + out << "Could not find appropriate cast for array in CastAndCall.\n" "Array: "; ref.PrintSummary(out); out << "TypeList: " << type.name() << "\n"; diff --git a/vtkm/cont/internal/VariantArrayHandleContainer.h b/vtkm/cont/internal/VariantArrayHandleContainer.h index 2a93f59a7..d9cb87965 100644 --- a/vtkm/cont/internal/VariantArrayHandleContainer.h +++ b/vtkm/cont/internal/VariantArrayHandleContainer.h @@ -211,6 +211,14 @@ struct VTKM_ALWAYS_EXPORT Caster } }; +// MSVC will issue deprecation warnings here if this template is instantiated with +// a deprecated class even if the template is used from a section of code where +// deprecation warnings are suppressed. This is annoying behavior since this template +// has no control over what class it is used with. To get around it, we have to +// suppress all deprecation warnings here. +#ifdef VTKM_MSVC +VTKM_DEPRECATED_SUPPRESS_BEGIN +#endif template VTKM_CONT ArrayHandleType Cast(const VariantArrayHandleContainerBase* container) { //container could be nullptr @@ -220,6 +228,9 @@ VTKM_CONT ArrayHandleType Cast(const VariantArrayHandleContainerBase* container) auto ret = Caster{}(container); return ArrayHandleType(std::move(ret)); } +#ifdef VTKM_MSVC +VTKM_DEPRECATED_SUPPRESS_END +#endif struct ForceCastToVirtual { diff --git a/vtkm/cont/openmp/internal/FunctorsOpenMP.h b/vtkm/cont/openmp/internal/FunctorsOpenMP.h index 6a86e2969..9417ea89b 100644 --- a/vtkm/cont/openmp/internal/FunctorsOpenMP.h +++ b/vtkm/cont/openmp/internal/FunctorsOpenMP.h @@ -90,6 +90,21 @@ static void ComputeChunkSize(const vtkm::Id numVals, valuesPerChunk = CeilDivide(pagesPerChunk * VTKM_PAGE_SIZE, bytesPerValue); } +template +struct CleanArrayRefImpl +{ + using type = T; +}; + +template +struct CleanArrayRefImpl> +{ + using type = typename PortalType::ValueType; +}; + +template +using CleanArrayRef = typename CleanArrayRefImpl::type; + template static void DoCopy(T src, U dst, vtkm::Id numVals, std::true_type) { @@ -103,19 +118,24 @@ static void DoCopy(T src, U dst, vtkm::Id numVals, std::true_type) template static void DoCopy(InIterT inIter, OutIterT outIter, vtkm::Id numVals, std::false_type) { - using ValueType = typename std::iterator_traits::value_type; + using InValueType = CleanArrayRef::value_type>; + using OutValueType = CleanArrayRef::value_type>; for (vtkm::Id i = 0; i < numVals; ++i) { - *(outIter++) = static_cast(*(inIter++)); + // The conversion to InputType and then OutputType looks weird, but it is necessary. + // *inItr actually returns an ArrayPortalValueReference, which can automatically convert + // itself to InputType but not necessarily OutputType. Thus, we first convert to + // InputType, and then allow the conversion to OutputType. + *(outIter++) = static_cast(static_cast(*(inIter++))); } } template static void DoCopy(InIterT inIter, OutIterT outIter, vtkm::Id numVals) { - using InValueType = typename std::iterator_traits::value_type; - using OutValueType = typename std::iterator_traits::value_type; + using InValueType = CleanArrayRef::value_type>; + using OutValueType = CleanArrayRef::value_type>; DoCopy(inIter, outIter, numVals, std::is_same()); } diff --git a/vtkm/cont/serial/internal/DeviceAdapterAlgorithmSerial.h b/vtkm/cont/serial/internal/DeviceAdapterAlgorithmSerial.h index 7d3148549..8f12f4d11 100644 --- a/vtkm/cont/serial/internal/DeviceAdapterAlgorithmSerial.h +++ b/vtkm/cont/serial/internal/DeviceAdapterAlgorithmSerial.h @@ -46,22 +46,32 @@ private: // template calls std::copy if and only if the types match, otherwise falls // back to a iterative casting approach. Since std::copy can only really // optimize same-type copies, this shouldn't affect performance. - template - static void DoCopy(InIter src, InIter srcEnd, OutIter dst, std::false_type) + template + static void DoCopy(InPortal src, + OutPortal dst, + std::false_type, + vtkm::Id startIndex, + vtkm::Id numToCopy, + vtkm::Id outIndex) { - using OutputType = typename std::iterator_traits::value_type; - while (src != srcEnd) + using OutputType = typename OutPortal::ValueType; + for (vtkm::Id index = 0; index < numToCopy; ++index) { - *dst = static_cast(*src); - ++src; - ++dst; + dst.Set(index + startIndex, static_cast(src.Get(index + outIndex))); } } - template - static void DoCopy(InIter src, InIter srcEnd, OutIter dst, std::true_type) + template + static void DoCopy(InPortal src, + OutPortal dst, + std::true_type, + vtkm::Id startIndex, + vtkm::Id numToCopy, + vtkm::Id outIndex) { - std::copy(src, srcEnd, dst); + std::copy(vtkm::cont::ArrayPortalToIteratorBegin(src) + startIndex, + vtkm::cont::ArrayPortalToIteratorBegin(src) + startIndex + numToCopy, + vtkm::cont::ArrayPortalToIteratorBegin(dst) + outIndex); } public: @@ -85,10 +95,7 @@ public: using InputType = decltype(inputPortal.Get(0)); using OutputType = decltype(outputPortal.Get(0)); - DoCopy(vtkm::cont::ArrayPortalToIteratorBegin(inputPortal), - vtkm::cont::ArrayPortalToIteratorEnd(inputPortal), - vtkm::cont::ArrayPortalToIteratorBegin(outputPortal), - std::is_same()); + DoCopy(inputPortal, outputPortal, std::is_same{}, 0, inSize, 0); } template @@ -188,16 +195,16 @@ public: vtkm::cont::Token token; auto inputPortal = input.PrepareForInput(DeviceAdapterTagSerial(), token); auto outputPortal = output.PrepareForInPlace(DeviceAdapterTagSerial(), token); - auto inIter = vtkm::cont::ArrayPortalToIteratorBegin(inputPortal); - auto outIter = vtkm::cont::ArrayPortalToIteratorBegin(outputPortal); using InputType = decltype(inputPortal.Get(0)); using OutputType = decltype(outputPortal.Get(0)); - DoCopy(inIter + inputStartIndex, - inIter + inputStartIndex + numberOfElementsToCopy, - outIter + outputIndex, - std::is_same()); + DoCopy(inputPortal, + outputPortal, + std::is_same(), + inputStartIndex, + numberOfElementsToCopy, + outputIndex); return true; } diff --git a/vtkm/cont/tbb/internal/FunctorsTBB.h b/vtkm/cont/tbb/internal/FunctorsTBB.h index 46f605181..f1bdf2b69 100644 --- a/vtkm/cont/tbb/internal/FunctorsTBB.h +++ b/vtkm/cont/tbb/internal/FunctorsTBB.h @@ -107,10 +107,15 @@ struct CopyBody template void DoCopy(InIter src, InIter srcEnd, OutIter dst, std::false_type) const { - using OutputType = typename std::iterator_traits::value_type; + using InputType = typename InputPortalType::ValueType; + using OutputType = typename OutputPortalType::ValueType; while (src != srcEnd) { - *dst = static_cast(*src); + // The conversion to InputType and then OutputType looks weird, but it is necessary. + // *src actually returns an ArrayPortalValueReference, which can automatically convert + // itself to InputType but not necessarily OutputType. Thus, we first convert to + // InputType, and then allow the conversion to OutputType. + *dst = static_cast(static_cast(*src)); ++src; ++dst; } diff --git a/vtkm/cont/testing/MakeTestDataSet.h b/vtkm/cont/testing/MakeTestDataSet.h index 04c34435b..34db8abf6 100644 --- a/vtkm/cont/testing/MakeTestDataSet.h +++ b/vtkm/cont/testing/MakeTestDataSet.h @@ -364,8 +364,10 @@ inline vtkm::cont::DataSet MakeTestDataSet::Make3DUniformDataSet3(const vtkm::Id dataSet.AddPointField("pointvar", pointvar); vtkm::Id numCells = (dims[0] - 1) * (dims[1] - 1) * (dims[2] - 1); - dataSet.AddCellField( - "cellvar", vtkm::cont::make_ArrayHandleCounting(vtkm::Float64(0), vtkm::Float64(1), numCells)); + vtkm::cont::ArrayHandle cellvar; + vtkm::cont::ArrayCopy( + vtkm::cont::make_ArrayHandleCounting(vtkm::Float64(0), vtkm::Float64(1), numCells), cellvar); + dataSet.AddCellField("cellvar", cellvar); return dataSet; } diff --git a/vtkm/cont/testing/TestingArrayHandleVirtualCoordinates.h b/vtkm/cont/testing/TestingArrayHandleVirtualCoordinates.h index 5c58394ea..f80013fbb 100644 --- a/vtkm/cont/testing/TestingArrayHandleVirtualCoordinates.h +++ b/vtkm/cont/testing/TestingArrayHandleVirtualCoordinates.h @@ -10,6 +10,9 @@ #ifndef vtk_m_cont_testing_TestingArrayHandleVirtualCoordinates_h #define vtk_m_cont_testing_TestingArrayHandleVirtualCoordinates_h +// This is testing deprecated functionality. It is left to make sure that old code +// still works, but will be removed if ArrayHandleVirtualCoordinates is removed. + #include #include #include @@ -17,6 +20,8 @@ #include #include +VTKM_DEPRECATED_SUPPRESS_BEGIN + namespace vtkm { namespace cont @@ -142,5 +147,6 @@ public: } } // vtkm::cont::testing +VTKM_DEPRECATED_SUPPRESS_END #endif // vtk_m_cont_testing_TestingArrayHandleVirtualCoordinates_h diff --git a/vtkm/cont/testing/TestingCellLocatorUniformBins.h b/vtkm/cont/testing/TestingCellLocatorUniformBins.h index 0380f277a..8ea423f1e 100644 --- a/vtkm/cont/testing/TestingCellLocatorUniformBins.h +++ b/vtkm/cont/testing/TestingCellLocatorUniformBins.h @@ -76,10 +76,6 @@ vtkm::cont::DataSet MakeTestDataSet(const vtkm::Vec& dims) vtkm::Vec(0.0f), vtkm::Vec(1.0f)); - // copy points - vtkm::cont::ArrayHandle points; - vtkm::cont::ArrayCopy(uniformDs.GetCoordinateSystem().GetData(), points); - auto uniformCs = uniformDs.GetCellSet().template Cast>(); @@ -99,15 +95,21 @@ vtkm::cont::DataSet MakeTestDataSet(const vtkm::Vec& dims) // Warp the coordinates std::uniform_real_distribution warpFactor(-0.10f, 0.10f); - auto pointsPortal = points.WritePortal(); - for (vtkm::Id i = 0; i < pointsPortal.GetNumberOfValues(); ++i) + auto inPointsPortal = uniformDs.GetCoordinateSystem() + .GetData() + .template Cast() + .ReadPortal(); + vtkm::cont::ArrayHandle points; + points.Allocate(inPointsPortal.GetNumberOfValues()); + auto outPointsPortal = points.WritePortal(); + for (vtkm::Id i = 0; i < outPointsPortal.GetNumberOfValues(); ++i) { PointType warpVec(0); for (vtkm::IdComponent c = 0; c < DIMENSIONS; ++c) { warpVec[c] = warpFactor(RandomGenerator); } - pointsPortal.Set(i, pointsPortal.Get(i) + warpVec); + outPointsPortal.Set(i, inPointsPortal.Get(i) + warpVec); } // build dataset @@ -152,7 +154,8 @@ void GenerateRandomInput(const vtkm::cont::DataSet& ds, vtkm::worklet::DispatcherMapTopology dispatcher( ParametricToWorldCoordinates::MakeScatter(cellIds)); - dispatcher.Invoke(ds.GetCellSet(), ds.GetCoordinateSystem().GetData(), pcoords, wcoords); + dispatcher.Invoke( + ds.GetCellSet(), ds.GetCoordinateSystem().GetDataAsMultiplexer(), pcoords, wcoords); } class FindCellWorklet : public vtkm::worklet::WorkletMapField diff --git a/vtkm/cont/testing/TestingImplicitFunction.h b/vtkm/cont/testing/TestingImplicitFunction.h index e1aef5ae1..f3e804fda 100644 --- a/vtkm/cont/testing/TestingImplicitFunction.h +++ b/vtkm/cont/testing/TestingImplicitFunction.h @@ -69,7 +69,7 @@ void EvaluateOnCoordinates(vtkm::cont::CoordinateSystem points, EvaluateImplicitFunction eval(function.PrepareForExecution(device, token)); EvalDispatcher dispatcher(eval); dispatcher.SetDevice(DeviceAdapter()); - dispatcher.Invoke(points, values, gradients); + dispatcher.Invoke(points.GetDataAsMultiplexer(), values, gradients); } template diff --git a/vtkm/cont/testing/UnitTestCellLocatorGeneral.cxx b/vtkm/cont/testing/UnitTestCellLocatorGeneral.cxx index c90fee88e..1f283c933 100644 --- a/vtkm/cont/testing/UnitTestCellLocatorGeneral.cxx +++ b/vtkm/cont/testing/UnitTestCellLocatorGeneral.cxx @@ -61,7 +61,7 @@ vtkm::cont::DataSet MakeTestDataSetRectilinear() vtkm::cont::DataSet MakeTestDataSetCurvilinear() { auto recti = MakeTestDataSetRectilinear(); - auto coords = recti.GetCoordinateSystem().GetData(); + auto coords = recti.GetCoordinateSystem().GetDataAsMultiplexer(); vtkm::cont::ArrayHandle sheared; sheared.Allocate(coords.GetNumberOfValues()); @@ -140,7 +140,8 @@ void GenerateRandomInput(const vtkm::cont::DataSet& ds, vtkm::worklet::DispatcherMapTopology dispatcher( ParametricToWorldCoordinates::MakeScatter(cellIds)); - dispatcher.Invoke(ds.GetCellSet(), ds.GetCoordinateSystem().GetData(), pcoords, wcoords); + dispatcher.Invoke( + ds.GetCellSet(), ds.GetCoordinateSystem().GetDataAsMultiplexer(), pcoords, wcoords); } //----------------------------------------------------------------------------- diff --git a/vtkm/cont/testing/UnitTestDataSetBuilderExplicit.cxx b/vtkm/cont/testing/UnitTestDataSetBuilderExplicit.cxx index 5ccb84b56..e3b6a7674 100644 --- a/vtkm/cont/testing/UnitTestDataSetBuilderExplicit.cxx +++ b/vtkm/cont/testing/UnitTestDataSetBuilderExplicit.cxx @@ -105,6 +105,9 @@ vtkm::cont::DataSet CreateDataSetArr(bool useSeparatedCoords, { std::vector xvals(numPoints), yvals(numPoints), zvals(numPoints); std::vector varP(numPoints), varC(numCells); + std::vector shapevals(numCells); + std::vector indicesvals(numCells); + std::vector connvals(numConn); for (std::size_t i = 0; i < numPoints; i++, f++) { xvals[i] = coords[i * 3 + 0]; @@ -116,15 +119,18 @@ vtkm::cont::DataSet CreateDataSetArr(bool useSeparatedCoords, for (std::size_t i = 0; i < numCells; i++, f++) { varC[i] = static_cast(f * 1.1f); + shapevals[i] = shape[i]; + indicesvals[i] = indices[i]; } - vtkm::cont::ArrayHandle X, Y, Z, P, C; - DFA::Copy(vtkm::cont::make_ArrayHandle(xvals), X); - DFA::Copy(vtkm::cont::make_ArrayHandle(yvals), Y); - DFA::Copy(vtkm::cont::make_ArrayHandle(zvals), Z); + for (std::size_t i = 0; i < numConn; i++) + { + connvals[i] = conn[i]; + } + dataSet = dsb.Create(xvals, yvals, zvals, shapevals, indicesvals, connvals); + + vtkm::cont::ArrayHandle P, C; DFA::Copy(vtkm::cont::make_ArrayHandle(varP), P); DFA::Copy(vtkm::cont::make_ArrayHandle(varC), C); - dataSet = dsb.Create( - X, Y, Z, createAH(numCells, shape), createAH(numCells, indices), createAH(numConn, conn)); dataSet.AddPointField("pointvar", P); dataSet.AddCellField("cellvar", C); return dataSet; @@ -229,7 +235,6 @@ vtkm::cont::DataSet CreateDataSetVec(bool useSeparatedCoords, void TestDataSetBuilderExplicit() { - vtkm::cont::DataSetBuilderExplicit dsb; vtkm::cont::DataSet ds; vtkm::Bounds bounds; diff --git a/vtkm/cont/testing/UnitTestMoveConstructors.cxx b/vtkm/cont/testing/UnitTestMoveConstructors.cxx index 541c5abd1..d173053b4 100644 --- a/vtkm/cont/testing/UnitTestMoveConstructors.cxx +++ b/vtkm/cont/testing/UnitTestMoveConstructors.cxx @@ -141,7 +141,9 @@ void TestContDataTypesHaveMoveSemantics() is_noexcept_movable(); is_noexcept_movable(); is_noexcept_movable(); + VTKM_DEPRECATED_SUPPRESS_BEGIN is_noexcept_movable(); + VTKM_DEPRECATED_SUPPRESS_END //verify the CellSetStructured, and CellSetExplicit //have efficient storage in containers such as std::vector diff --git a/vtkm/cont/testing/UnitTestSerializationArrayHandle.cxx b/vtkm/cont/testing/UnitTestSerializationArrayHandle.cxx index a05450f92..7fd67a53e 100644 --- a/vtkm/cont/testing/UnitTestSerializationArrayHandle.cxx +++ b/vtkm/cont/testing/UnitTestSerializationArrayHandle.cxx @@ -132,30 +132,6 @@ struct TestArrayHandleCast } }; -struct TestArrayHandleCompositeVector -{ - template - void operator()(T) const - { - auto array = vtkm::cont::make_ArrayHandleCompositeVector(RandomArrayHandle::Make(ArraySize), - RandomArrayHandle::Make(ArraySize)); - RunTest(array); - RunTest(MakeTestVariantArrayHandle(array)); - } -}; - -struct TestArrayHandleConcatenate -{ - template - void operator()(T) const - { - auto array = vtkm::cont::make_ArrayHandleConcatenate(RandomArrayHandle::Make(ArraySize), - RandomArrayHandle::Make(ArraySize)); - RunTest(array); - RunTest(MakeTestVariantArrayHandle(array)); - } -}; - struct TestArrayHandleConstant { template @@ -181,19 +157,6 @@ struct TestArrayHandleCounting } }; -struct TestArrayHandleExtractComponent -{ - template - void operator()(T) const - { - auto numComps = vtkm::VecTraits::NUM_COMPONENTS; - auto array = vtkm::cont::make_ArrayHandleExtractComponent( - RandomArrayHandle::Make(ArraySize), RandomValue::Make(0, numComps - 1)); - RunTest(array); - RunTest(MakeTestVariantArrayHandle(array)); - } -}; - struct TestArrayHandleGroupVec { template @@ -253,37 +216,6 @@ struct TestArrayHandleGroupVecVariable } }; -struct TestArrayHandleImplicit -{ - template - struct ImplicitFunctor - { - ImplicitFunctor() = default; - - explicit ImplicitFunctor(const T& factor) - : Factor(factor) - { - } - - VTKM_EXEC_CONT T operator()(vtkm::Id index) const - { - return static_cast(this->Factor * - static_cast::ComponentType>(index)); - } - - T Factor; - }; - - template - void operator()(T) const - { - ImplicitFunctor functor(RandomValue::Make(2, 9)); - auto array = vtkm::cont::make_ArrayHandleImplicit(functor, ArraySize); - RunTest(array); - RunTest(MakeTestVariantArrayHandle(array)); - } -}; - void TestArrayHandleIndex() { auto size = RandomValue::Make(2, 10); @@ -321,86 +253,6 @@ struct TestArrayHandleReverse } }; -struct TestArrayHandleSwizzle -{ - template - void operator()(T) const - { - static const vtkm::IdComponent2 map2s[6] = { { 0, 1 }, { 0, 2 }, { 1, 0 }, - { 1, 2 }, { 2, 0 }, { 2, 1 } }; - static const vtkm::IdComponent3 map3s[6] = { { 0, 1, 2 }, { 0, 2, 1 }, { 1, 0, 2 }, - { 1, 2, 0 }, { 2, 0, 1 }, { 2, 1, 0 } }; - - auto numOutComps = RandomValue::Make(2, 3); - switch (numOutComps) - { - case 2: - { - auto array = make_ArrayHandleSwizzle(RandomArrayHandle>::Make(ArraySize), - map2s[RandomValue::Make(0, 5)]); - RunTest(array); - RunTest(MakeTestVariantArrayHandle(array)); - break; - } - case 3: - default: - { - auto array = make_ArrayHandleSwizzle(RandomArrayHandle>::Make(ArraySize), - map3s[RandomValue::Make(0, 5)]); - RunTest(array); - RunTest(MakeTestVariantArrayHandle(array)); - break; - } - } - } -}; - - -struct TestArrayHandleTransform -{ - struct TransformFunctor - { - template - VTKM_EXEC_CONT T operator()(const T& in) const - { - return static_cast(in * T{ 2 }); - } - }; - - struct InverseTransformFunctor - { - template - VTKM_EXEC_CONT T operator()(const T& in) const - { - return static_cast(in / T{ 2 }); - } - }; - - template - void TestType1() const - { - auto array = vtkm::cont::make_ArrayHandleTransform(RandomArrayHandle::Make(ArraySize), - TransformFunctor{}); - RunTest(array); - RunTest(MakeTestVariantArrayHandle(array)); - } - - template - void TestType2() const - { - auto array = vtkm::cont::make_ArrayHandleTransform( - RandomArrayHandle::Make(ArraySize), TransformFunctor{}, InverseTransformFunctor{}); - RunTest(array); - RunTest(MakeTestVariantArrayHandle(array)); - } - - template - void operator()(T) const - { - this->TestType1(); - this->TestType2(); - } -}; vtkm::cont::ArrayHandleUniformPointCoordinates MakeRandomArrayHandleUniformPointCoordinates() { @@ -417,46 +269,6 @@ void TestArrayHandleUniformPointCoordinates() RunTest(MakeTestVariantArrayHandle(array)); } -void TestArrayHandleVirtualCoordinates() -{ - int type = RandomValue::Make(0, 2); - - vtkm::cont::ArrayHandleVirtualCoordinates array; - switch (type) - { - case 0: - array = - vtkm::cont::ArrayHandleVirtualCoordinates(MakeRandomArrayHandleUniformPointCoordinates()); - break; - case 1: - array = - vtkm::cont::ArrayHandleVirtualCoordinates(vtkm::cont::make_ArrayHandleCartesianProduct( - RandomArrayHandle::Make(ArraySize), - RandomArrayHandle::Make(ArraySize), - RandomArrayHandle::Make(ArraySize))); - break; - default: - array = - vtkm::cont::ArrayHandleVirtualCoordinates(RandomArrayHandle::Make(ArraySize)); - break; - } - - RunTest(array); - RunTest(MakeTestVariantArrayHandle(array)); -} - -struct TestArrayHandleZip -{ - template - void operator()(T) const - { - auto array = vtkm::cont::make_ArrayHandleZip(RandomArrayHandle::Make(ArraySize), - vtkm::cont::ArrayHandleIndex(ArraySize)); - RunTest(array); - RunTest(MakeTestVariantArrayHandle(array)); - } -}; - //----------------------------------------------------------------------------- void TestArrayHandleSerialization() @@ -464,62 +276,81 @@ void TestArrayHandleSerialization() std::cout << "Testing ArrayHandleBasic\n"; vtkm::testing::Testing::TryTypes(TestArrayHandleBasic(), TestTypesList()); - std::cout << "Testing ArrayHandleSOA\n"; - vtkm::testing::Testing::TryTypes(TestArrayHandleSOA(), TestTypesList()); + if (vtkm::ListHas::value) + { + std::cout << "Testing ArrayHandleSOA\n"; + vtkm::testing::Testing::TryTypes(TestArrayHandleSOA(), TestTypesList()); + } - std::cout << "Testing ArrayHandleCartesianProduct\n"; - vtkm::testing::Testing::TryTypes(TestArrayHandleCartesianProduct(), TestTypesList()); + if (vtkm::ListHas>::value) + { + std::cout << "Testing ArrayHandleCartesianProduct\n"; + vtkm::testing::Testing::TryTypes(TestArrayHandleCartesianProduct(), TestTypesList()); + } - std::cout << "Testing TestArrayHandleCast\n"; - vtkm::testing::Testing::TryTypes(TestArrayHandleCast(), TestTypesList()); + if (vtkm::ListHas>::value) + { + std::cout << "Testing TestArrayHandleCast\n"; + vtkm::testing::Testing::TryTypes(TestArrayHandleCast(), TestTypesList()); + } - std::cout << "Testing ArrayHandleCompositeVector\n"; - vtkm::testing::Testing::TryTypes(TestArrayHandleCompositeVector(), TestTypesList()); + if (vtkm::ListHas::value) + { + std::cout << "Testing ArrayHandleConstant\n"; + vtkm::testing::Testing::TryTypes(TestArrayHandleConstant(), TestTypesList()); + } - std::cout << "Testing ArrayHandleConcatenate\n"; - vtkm::testing::Testing::TryTypes(TestArrayHandleConcatenate(), TestTypesList()); + if (vtkm::ListHas::value) + { + std::cout << "Testing ArrayHandleCounting\n"; + vtkm::testing::Testing::TryTypes(TestArrayHandleCounting(), TestTypesList()); + } - std::cout << "Testing ArrayHandleConstant\n"; - vtkm::testing::Testing::TryTypes(TestArrayHandleConstant(), TestTypesList()); + if (vtkm::ListHas>::value) + { + std::cout << "Testing ArrayHandleGroupVec\n"; + vtkm::testing::Testing::TryTypes(TestArrayHandleGroupVec(), TestTypesList()); + } - std::cout << "Testing ArrayHandleCounting\n"; - vtkm::testing::Testing::TryTypes(TestArrayHandleCounting(), TestTypesList()); + if (vtkm::ListHas>::value) + { + std::cout << "Testing ArrayHandleGroupVecVariable\n"; + vtkm::testing::Testing::TryTypes(TestArrayHandleGroupVecVariable(), TestTypesList()); + } - std::cout << "Testing ArrayHandleExtractComponent\n"; - vtkm::testing::Testing::TryTypes(TestArrayHandleExtractComponent(), TestTypesList()); + if (vtkm::ListHas::value) + { + std::cout << "Testing ArrayHandleIndex\n"; + TestArrayHandleIndex(); + } - std::cout << "Testing ArrayHandleGroupVec\n"; - vtkm::testing::Testing::TryTypes(TestArrayHandleGroupVec(), TestTypesList()); + if (vtkm::ListHas>::value) + { + std::cout << "Testing ArrayHandlePermutation\n"; + vtkm::testing::Testing::TryTypes(TestArrayHandlePermutation(), TestTypesList()); + } - std::cout << "Testing ArrayHandleGroupVecVariable\n"; - vtkm::testing::Testing::TryTypes(TestArrayHandleGroupVecVariable(), TestTypesList()); + if (vtkm::ListHas>::value) + { + std::cout << "Testing ArrayHandleReverse\n"; + vtkm::testing::Testing::TryTypes(TestArrayHandleReverse(), TestTypesList()); + } - std::cout << "Testing ArrayHandleImplicit\n"; - vtkm::testing::Testing::TryTypes(TestArrayHandleImplicit(), TestTypesList()); - - std::cout << "Testing ArrayHandleIndex\n"; - TestArrayHandleIndex(); - - std::cout << "Testing ArrayHandlePermutation\n"; - vtkm::testing::Testing::TryTypes(TestArrayHandlePermutation(), TestTypesList()); - - std::cout << "Testing ArrayHandleReverse\n"; - vtkm::testing::Testing::TryTypes(TestArrayHandleReverse(), TestTypesList()); - - std::cout << "Testing ArrayHandleSwizzle\n"; - vtkm::testing::Testing::TryTypes(TestArrayHandleSwizzle(), TestTypesList()); - - std::cout << "Testing ArrayHandleTransform\n"; - vtkm::testing::Testing::TryTypes(TestArrayHandleTransform(), TestTypesList()); - - std::cout << "Testing ArrayHandleUniformPointCoordinates\n"; - TestArrayHandleUniformPointCoordinates(); - - std::cout << "Testing ArrayHandleVirtualCoordinates\n"; - TestArrayHandleVirtualCoordinates(); - - std::cout << "Testing ArrayHandleZip\n"; - vtkm::testing::Testing::TryTypes(TestArrayHandleZip(), TestTypesList()); + if (vtkm::ListHas::value) + { + std::cout << "Testing ArrayHandleUniformPointCoordinates\n"; + TestArrayHandleUniformPointCoordinates(); + } } } // anonymous namespace @@ -540,37 +371,3 @@ int UnitTestSerializationArrayHandle(int argc, char* argv[]) return vtkm::cont::testing::Testing::Run(TestArrayHandleSerialization, argc, argv); } - -//----------------------------------------------------------------------------- -namespace vtkm -{ -namespace cont -{ - -template -struct SerializableTypeString> -{ - static VTKM_CONT const std::string& Get() - { - static std::string name = - "TestArrayHandleImplicit::ImplicitFunctor<" + SerializableTypeString::Get() + ">"; - return name; - } -}; - -template <> -struct SerializableTypeString -{ - static VTKM_CONT const std::string Get() { return "TestArrayHandleTransform::TransformFunctor"; } -}; - -template <> -struct SerializableTypeString -{ - static VTKM_CONT const std::string Get() - { - return "TestArrayHandleTransform::InverseTransformFunctor"; - } -}; -} -} // vtkm::cont diff --git a/vtkm/cont/testing/UnitTestVariantArrayHandle.cxx b/vtkm/cont/testing/UnitTestVariantArrayHandle.cxx index 37831dad4..ec57c9939 100644 --- a/vtkm/cont/testing/UnitTestVariantArrayHandle.cxx +++ b/vtkm/cont/testing/UnitTestVariantArrayHandle.cxx @@ -187,6 +187,9 @@ void CheckArrayVariant(const vtkm::cont::VariantArrayHandleBase& array VTKM_TEST_ASSERT(!calledUnusual, "The array somehow got cast to an unusual storage."); } +#if 0 + // Test disabled. CastAndCall no longer casts to ArrayHandleVirtual because + // that is getting deprecated. std::cout << " CastAndCall with no storage" << std::endl; calledBasic = false; calledUnusual = false; @@ -197,6 +200,7 @@ void CheckArrayVariant(const vtkm::cont::VariantArrayHandleBase& array "The functor was never called (and apparently a bad value exception not thrown)."); VTKM_TEST_ASSERT(!calledBasic, "The array somehow got cast to a basic storage."); VTKM_TEST_ASSERT(!calledUnusual, "The array somehow got cast to an unusual storage."); +#endif std::cout << " CastAndCall with extra storage" << std::endl; calledBasic = false; @@ -469,6 +473,9 @@ void TryUnusualType() std::cout << " Found type when type list was reset." << std::endl; } +#if 0 + // It is now requred to know the storage used (no longer wrapping in ArrayHandleVirtual), + // so disable this test. void TryUnusualStorage() { vtkm::cont::VariantArrayHandle array = ArrayHandleWithUnusualStorage(); @@ -506,6 +513,7 @@ void TryUnusualTypeAndStorage() VTKM_TEST_FAIL("CastAndCall with Variant failed to handle unusual storage."); } } +#endif template void TryCastToArrayHandle(const ArrayHandleType& array) @@ -586,11 +594,15 @@ void TestVariantArrayHandle() std::cout << "Try unusual type." << std::endl; TryUnusualType(); +#if 0 + // It is now requred to know the storage used (no longer wrapping in ArrayHandleVirtual), + // so disable this test. std::cout << "Try unusual storage." << std::endl; TryUnusualStorage(); std::cout << "Try unusual type in unusual storage." << std::endl; TryUnusualTypeAndStorage(); +#endif std::cout << "Try CastToArrayHandle" << std::endl; TryCastToArrayHandle(); diff --git a/vtkm/exec/CellLocatorBoundingIntervalHierarchyExec.h b/vtkm/exec/CellLocatorBoundingIntervalHierarchyExec.h index 3f53b54d4..3a26b3ce2 100644 --- a/vtkm/exec/CellLocatorBoundingIntervalHierarchyExec.h +++ b/vtkm/exec/CellLocatorBoundingIntervalHierarchyExec.h @@ -13,7 +13,7 @@ #include #include #include -#include +#include #include #include #include @@ -74,12 +74,13 @@ public: CellLocatorBoundingIntervalHierarchyExec() {} VTKM_CONT - CellLocatorBoundingIntervalHierarchyExec(const NodeArrayHandle& nodes, - const CellIdArrayHandle& cellIds, - const CellSetType& cellSet, - const vtkm::cont::ArrayHandleVirtualCoordinates& coords, - DeviceAdapter, - vtkm::cont::Token& token) + CellLocatorBoundingIntervalHierarchyExec( + const NodeArrayHandle& nodes, + const CellIdArrayHandle& cellIds, + const CellSetType& cellSet, + const vtkm::cont::CoordinateSystem::MultiplexerArrayType& coords, + DeviceAdapter, + vtkm::cont::Token& token) : Nodes(nodes.PrepareForInput(DeviceAdapter(), token)) , CellIds(cellIds.PrepareForInput(DeviceAdapter(), token)) , CellSet(cellSet.PrepareForInput(DeviceAdapter(), VisitType(), IncidentType(), token)) @@ -277,8 +278,9 @@ private: using CellSetPortal = typename CellSetType::template ExecutionTypes::ExecObjectType; - using CoordsPortal = typename vtkm::cont::ArrayHandleVirtualCoordinates::template ExecutionTypes< - DeviceAdapter>::PortalConst; + using CoordsPortal = + typename vtkm::cont::CoordinateSystem::MultiplexerArrayType::template ExecutionTypes< + DeviceAdapter>::PortalConst; NodePortal Nodes; CellIdPortal CellIds; diff --git a/vtkm/exec/CellLocatorUniformGrid.h b/vtkm/exec/CellLocatorUniformGrid.h index 52f3aefd7..2dd498905 100644 --- a/vtkm/exec/CellLocatorUniformGrid.h +++ b/vtkm/exec/CellLocatorUniformGrid.h @@ -34,8 +34,6 @@ private: using VisitType = vtkm::TopologyElementTagCell; using IncidentType = vtkm::TopologyElementTagPoint; using CellSetPortal = vtkm::exec::ConnectivityStructured; - using CoordsPortal = typename vtkm::cont::ArrayHandleVirtualCoordinates::template ExecutionTypes< - DeviceAdapter>::PortalConst; public: VTKM_CONT @@ -44,15 +42,12 @@ public: const vtkm::Vec3f origin, const vtkm::Vec3f invSpacing, const vtkm::Vec3f maxPoint, - const vtkm::cont::ArrayHandleVirtualCoordinates& coords, - DeviceAdapter, - vtkm::cont::Token& token) + DeviceAdapter) : CellDims(cellDims) , PointDims(pointDims) , Origin(origin) , InvSpacing(invSpacing) , MaxPoint(maxPoint) - , Coords(coords.PrepareForInput(DeviceAdapter(), token)) { } @@ -120,7 +115,6 @@ private: vtkm::Vec3f Origin; vtkm::Vec3f InvSpacing; vtkm::Vec3f MaxPoint; - CoordsPortal Coords; }; } } diff --git a/vtkm/exec/PointLocatorUniformGrid.h b/vtkm/exec/PointLocatorUniformGrid.h index 8cd22af38..1984a4aae 100644 --- a/vtkm/exec/PointLocatorUniformGrid.h +++ b/vtkm/exec/PointLocatorUniformGrid.h @@ -10,6 +10,7 @@ #ifndef vtk_m_exec_PointLocatorUniformGrid_h #define vtk_m_exec_PointLocatorUniformGrid_h +#include #include #include #include @@ -29,7 +30,7 @@ class VTKM_ALWAYS_EXPORT PointLocatorUniformGrid final : public vtkm::exec::Poin { public: using CoordPortalType = - typename vtkm::cont::ArrayHandleVirtualCoordinates::template ExecutionTypes< + typename vtkm::cont::CoordinateSystem::MultiplexerArrayType::template ExecutionTypes< DeviceAdapter>::PortalConst; using IdPortalType = typename vtkm::cont::ArrayHandle::template ExecutionTypes::PortalConst; diff --git a/vtkm/filter/CellMeasures.h b/vtkm/filter/CellMeasures.h index 0dd7a7e5f..8ca5017f4 100644 --- a/vtkm/filter/CellMeasures.h +++ b/vtkm/filter/CellMeasures.h @@ -35,7 +35,7 @@ public: VTKM_CONT CellMeasures(); - /// Set/Get the name of the cell measure field. If empty, "measure" is used. + /// Set/Get the name of the cell measure field. If not set, "measure" is used. void SetCellMeasureName(const std::string& name) { this->SetOutputFieldName(name); } const std::string& GetCellMeasureName() const { return this->GetOutputFieldName(); } diff --git a/vtkm/filter/CellMeasures.hxx b/vtkm/filter/CellMeasures.hxx index 8812ead91..248432246 100644 --- a/vtkm/filter/CellMeasures.hxx +++ b/vtkm/filter/CellMeasures.hxx @@ -25,6 +25,7 @@ inline VTKM_CONT CellMeasures::CellMeasures() : vtkm::filter::FilterCell>() { this->SetUseCoordinateSystemAsField(true); + this->SetCellMeasureName("measure"); } //----------------------------------------------------------------------------- diff --git a/vtkm/filter/ClipWithField.h b/vtkm/filter/ClipWithField.h index 5477b2504..d71211ef5 100644 --- a/vtkm/filter/ClipWithField.h +++ b/vtkm/filter/ClipWithField.h @@ -108,6 +108,8 @@ VTKM_FILTER_EXPORT_EXECUTE_METHOD(ClipWithField); } } // namespace vtkm::filter +#ifndef vtk_m_filter_ClipWithField_hxx #include +#endif #endif // vtk_m_filter_ClipWithField_h diff --git a/vtkm/filter/ClipWithField.hxx b/vtkm/filter/ClipWithField.hxx index 3a724b9e3..9d85b2e14 100644 --- a/vtkm/filter/ClipWithField.hxx +++ b/vtkm/filter/ClipWithField.hxx @@ -11,6 +11,8 @@ #ifndef vtk_m_filter_ClipWithField_hxx #define vtk_m_filter_ClipWithField_hxx +#include + #include #include #include @@ -21,6 +23,26 @@ namespace vtkm { namespace filter { + +namespace detail +{ + +struct ClipWithFieldProcessCoords +{ + template + VTKM_CONT void operator()(const vtkm::cont::ArrayHandle& inCoords, + const std::string& coordsName, + const vtkm::worklet::Clip& worklet, + vtkm::cont::DataSet& output) const + { + vtkm::cont::ArrayHandle outArray = worklet.ProcessPointField(inCoords); + vtkm::cont::CoordinateSystem outCoords(coordsName, outArray); + output.AddCoordinateSystem(outCoords); + } +}; + +} // namespace detail + //----------------------------------------------------------------------------- template inline VTKM_CONT vtkm::cont::DataSet ClipWithField::DoExecute( @@ -37,9 +59,6 @@ inline VTKM_CONT vtkm::cont::DataSet ClipWithField::DoExecute( //get the cells and coordinates of the dataset const vtkm::cont::DynamicCellSet& cells = input.GetCellSet(); - const vtkm::cont::CoordinateSystem& inputCoords = - input.GetCoordinateSystem(this->GetActiveCoordinateSystemIndex()); - vtkm::cont::CellSetExplicit<> outputCellSet = this->Worklet.Run( vtkm::filter::ApplyPolicyCellSet(cells, policy, *this), field, this->ClipValue, this->Invert); @@ -48,9 +67,14 @@ inline VTKM_CONT vtkm::cont::DataSet ClipWithField::DoExecute( output.SetCellSet(outputCellSet); // Compute the new boundary points and add them to the output: - auto outputCoordsArray = this->Worklet.ProcessPointField(inputCoords.GetData()); - vtkm::cont::CoordinateSystem outputCoords(inputCoords.GetName(), outputCoordsArray); - output.AddCoordinateSystem(outputCoords); + for (vtkm::IdComponent coordSystemId = 0; coordSystemId < input.GetNumberOfCoordinateSystems(); + ++coordSystemId) + { + vtkm::cont::CoordinateSystem coords = input.GetCoordinateSystem(coordSystemId); + coords.GetData().CastAndCall( + detail::ClipWithFieldProcessCoords{}, coords.GetName(), this->Worklet, output); + } + return output; } } diff --git a/vtkm/filter/ClipWithImplicitFunction.h b/vtkm/filter/ClipWithImplicitFunction.h index 087c6e159..b9d538c31 100644 --- a/vtkm/filter/ClipWithImplicitFunction.h +++ b/vtkm/filter/ClipWithImplicitFunction.h @@ -105,6 +105,8 @@ VTKM_FILTER_EXPORT_EXECUTE_METHOD(ClipWithImplicitFunction); } } // namespace vtkm::filter +#ifndef vtk_m_filter_ClipWithImplicitFunction_hxx #include +#endif #endif // vtk_m_filter_ClipWithImplicitFunction_h diff --git a/vtkm/filter/ClipWithImplicitFunction.hxx b/vtkm/filter/ClipWithImplicitFunction.hxx index 57b32616f..fbb892670 100644 --- a/vtkm/filter/ClipWithImplicitFunction.hxx +++ b/vtkm/filter/ClipWithImplicitFunction.hxx @@ -11,6 +11,8 @@ #ifndef vtk_m_filter_ClipWithImplicitFunction_hxx #define vtk_m_filter_ClipWithImplicitFunction_hxx +#include + #include #include #include @@ -19,6 +21,26 @@ namespace vtkm { namespace filter { + +namespace detail +{ + +struct ClipWithImplicitFunctionProcessCoords +{ + template + VTKM_CONT void operator()(const vtkm::cont::ArrayHandle& inCoords, + const std::string& coordsName, + const vtkm::worklet::Clip& worklet, + vtkm::cont::DataSet& output) const + { + vtkm::cont::ArrayHandle outArray = worklet.ProcessPointField(inCoords); + vtkm::cont::CoordinateSystem outCoords(coordsName, outArray); + output.AddCoordinateSystem(outCoords); + } +}; + +} // namespace detail + //----------------------------------------------------------------------------- template inline vtkm::cont::DataSet ClipWithImplicitFunction::DoExecute( @@ -37,14 +59,18 @@ inline vtkm::cont::DataSet ClipWithImplicitFunction::DoExecute( inputCoords, this->Invert); - // compute output coordinates - auto outputCoordsArray = this->Worklet.ProcessPointField(inputCoords.GetData()); - vtkm::cont::CoordinateSystem outputCoords(inputCoords.GetName(), outputCoordsArray); - //create the output data vtkm::cont::DataSet output; output.SetCellSet(outputCellSet); - output.AddCoordinateSystem(outputCoords); + + // compute output coordinates + for (vtkm::IdComponent coordSystemId = 0; coordSystemId < input.GetNumberOfCoordinateSystems(); + ++coordSystemId) + { + vtkm::cont::CoordinateSystem coords = input.GetCoordinateSystem(coordSystemId); + coords.GetData().CastAndCall( + detail::ClipWithImplicitFunctionProcessCoords{}, coords.GetName(), this->Worklet, output); + } return output; } diff --git a/vtkm/filter/SplitSharpEdges.hxx b/vtkm/filter/SplitSharpEdges.hxx index 7f28b0b55..6806f49a4 100644 --- a/vtkm/filter/SplitSharpEdges.hxx +++ b/vtkm/filter/SplitSharpEdges.hxx @@ -47,7 +47,7 @@ inline VTKM_CONT vtkm::cont::DataSet SplitSharpEdges::DoExecute( this->Worklet.Run(vtkm::filter::ApplyPolicyCellSet(cells, policy, *this), this->FeatureAngle, field, - input.GetCoordinateSystem().GetData(), + input.GetCoordinateSystem().GetDataAsMultiplexer(), newCoords, newCellset); diff --git a/vtkm/filter/SurfaceNormals.hxx b/vtkm/filter/SurfaceNormals.hxx index ddd29f91c..62fc698f9 100644 --- a/vtkm/filter/SurfaceNormals.hxx +++ b/vtkm/filter/SurfaceNormals.hxx @@ -85,7 +85,8 @@ inline vtkm::cont::DataSet SurfaceNormals::DoExecute( const auto cellset = vtkm::filter::ApplyPolicyCellSetUnstructured(input.GetCellSet(), policy, *this); - const auto& coords = input.GetCoordinateSystem(this->GetActiveCoordinateSystemIndex()).GetData(); + const auto coords = + input.GetCoordinateSystem(this->GetActiveCoordinateSystemIndex()).GetDataAsMultiplexer(); vtkm::cont::ArrayHandle faceNormals; vtkm::worklet::FacetedSurfaceNormals faceted; diff --git a/vtkm/filter/testing/UnitTestCellMeasuresFilter.cxx b/vtkm/filter/testing/UnitTestCellMeasuresFilter.cxx index f56a450ae..f0a0cc8e1 100644 --- a/vtkm/filter/testing/UnitTestCellMeasuresFilter.cxx +++ b/vtkm/filter/testing/UnitTestCellMeasuresFilter.cxx @@ -18,6 +18,25 @@ namespace { +struct CheckCellMeasuresFunctor +{ + template + void operator()(const ArrayType& resultArrayHandle, + const std::vector& expected) const + { + VTKM_TEST_ASSERT(resultArrayHandle.GetNumberOfValues() == + static_cast(expected.size()), + "Wrong number of entries in the output dataset"); + + auto portal = resultArrayHandle.ReadPortal(); + for (std::size_t i = 0; i < expected.size(); ++i) + { + VTKM_TEST_ASSERT(test_equal(portal.Get(static_cast(i)), expected[i]), + "Wrong result for CellMeasure filter"); + } + } +}; + template void TestCellMeasuresFilter(vtkm::cont::DataSet& dataset, const char* msg, @@ -29,28 +48,19 @@ void TestCellMeasuresFilter(vtkm::cont::DataSet& dataset, vtkm::filter::CellMeasures vols; vtkm::cont::DataSet outputData = vols.Execute(dataset); - VTKM_TEST_ASSERT(vols.GetCellMeasureName().empty(), "Default output field name should be empty."); + VTKM_TEST_ASSERT(vols.GetCellMeasureName() == "measure"); VTKM_TEST_ASSERT(outputData.GetNumberOfCoordinateSystems() == 1, "Wrong number of coordinate systems in the output dataset"); VTKM_TEST_ASSERT(outputData.GetNumberOfCells() == static_cast(expected.size()), "Wrong number of cells in the output dataset"); // Check that the empty measure name above produced a field with the expected name. - vols.SetCellMeasureName("measure"); - auto temp = outputData.GetField(vols.GetCellMeasureName()).GetData(); - VTKM_TEST_ASSERT(temp.GetNumberOfValues() == static_cast(expected.size()), + auto result = outputData.GetField(vols.GetCellMeasureName()).GetData(); + VTKM_TEST_ASSERT(result.GetNumberOfValues() == static_cast(expected.size()), "Output field could not be found or was improper."); - vtkm::cont::ArrayHandle resultArrayHandle; - temp.CopyTo(resultArrayHandle); - VTKM_TEST_ASSERT(resultArrayHandle.GetNumberOfValues() == static_cast(expected.size()), - "Wrong number of entries in the output dataset"); - - for (unsigned int i = 0; i < static_cast(expected.size()); ++i) - { - VTKM_TEST_ASSERT(test_equal(resultArrayHandle.ReadPortal().Get(vtkm::Id(i)), expected[i]), - "Wrong result for CellMeasure filter"); - } + vtkm::cont::CastAndCall( + result.ResetTypes(vtkm::TypeListFieldScalar{}), CheckCellMeasuresFunctor{}, expected); } void TestCellMeasures() diff --git a/vtkm/filter/testing/UnitTestCleanGrid.cxx b/vtkm/filter/testing/UnitTestCleanGrid.cxx index e52a9118d..6c98e7bc8 100644 --- a/vtkm/filter/testing/UnitTestCleanGrid.cxx +++ b/vtkm/filter/testing/UnitTestCleanGrid.cxx @@ -75,7 +75,7 @@ void TestPointMerging() //Convert the baseData implicit points to explicit points, since the contour //filter for uniform data always does point merging vtkm::cont::ArrayHandle newcoords; - vtkm::cont::Algorithm::Copy(baseData.GetCoordinateSystem().GetData(), newcoords); + vtkm::cont::ArrayCopy(baseData.GetCoordinateSystem().GetData(), newcoords); baseData.GetCoordinateSystem().SetData(newcoords); vtkm::filter::Contour marchingCubes; diff --git a/vtkm/filter/testing/UnitTestCoordinateSystemTransform.cxx b/vtkm/filter/testing/UnitTestCoordinateSystemTransform.cxx index ab7cde08c..472558c5d 100644 --- a/vtkm/filter/testing/UnitTestCoordinateSystemTransform.cxx +++ b/vtkm/filter/testing/UnitTestCoordinateSystemTransform.cxx @@ -102,8 +102,8 @@ void ValidateCoordTransform(const vtkm::cont::DataSet& ds, const vtkm::cont::DataSet& dsTrn, const std::vector& isAngle) { - auto points = ds.GetCoordinateSystem().GetData(); - auto pointsTrn = dsTrn.GetCoordinateSystem().GetData(); + auto points = ds.GetCoordinateSystem().GetDataAsMultiplexer(); + auto pointsTrn = dsTrn.GetCoordinateSystem().GetDataAsMultiplexer(); VTKM_TEST_ASSERT(points.GetNumberOfValues() == pointsTrn.GetNumberOfValues(), "Incorrect number of points in point transform"); diff --git a/vtkm/filter/testing/UnitTestGhostCellRemove.cxx b/vtkm/filter/testing/UnitTestGhostCellRemove.cxx index 876749641..4e5b119d6 100644 --- a/vtkm/filter/testing/UnitTestGhostCellRemove.cxx +++ b/vtkm/filter/testing/UnitTestGhostCellRemove.cxx @@ -172,7 +172,7 @@ static vtkm::cont::DataSet MakeExplicit(vtkm::Id numI, vtkm::Id numJ, vtkm::Id n vtkm::cont::DataSet dsUniform = MakeUniform(numI, numJ, numK, numLayers); - auto coordData = dsUniform.GetCoordinateSystem(0).GetData(); + auto coordData = dsUniform.GetCoordinateSystem(0).GetDataAsMultiplexer(); vtkm::Id numPts = coordData.GetNumberOfValues(); vtkm::cont::ArrayHandle explCoords; diff --git a/vtkm/filter/testing/UnitTestMeshQualityFilter.cxx b/vtkm/filter/testing/UnitTestMeshQualityFilter.cxx index cbda5dfee..0dacdc00a 100644 --- a/vtkm/filter/testing/UnitTestMeshQualityFilter.cxx +++ b/vtkm/filter/testing/UnitTestMeshQualityFilter.cxx @@ -122,7 +122,7 @@ bool TestMeshQualityFilter(const vtkm::cont::DataSet& input, //Test the computed metric values (for all cells) and expected metric //values for equality. - vtkm::cont::ArrayHandle values; + vtkm::cont::ArrayHandle values; output.GetField(outputname).GetData().CopyTo(values); auto portal1 = values.ReadPortal(); if (portal1.GetNumberOfValues() != (vtkm::Id)expectedVals.size()) diff --git a/vtkm/filter/testing/UnitTestParticleAdvectionFilter.cxx b/vtkm/filter/testing/UnitTestParticleAdvectionFilter.cxx index 5ff7a599d..a4947b2a2 100644 --- a/vtkm/filter/testing/UnitTestParticleAdvectionFilter.cxx +++ b/vtkm/filter/testing/UnitTestParticleAdvectionFilter.cxx @@ -101,7 +101,7 @@ void TestFile(const std::string& fname, particleAdvection.SetActiveField("vec"); auto output = particleAdvection.Execute(ds); - auto coords = output.GetCoordinateSystem().GetData(); + auto coords = output.GetCoordinateSystem().GetDataAsMultiplexer(); vtkm::cont::DynamicCellSet dcells = output.GetCellSet(); VTKM_TEST_ASSERT(dcells.GetNumberOfCells() == numPoints, "Wrong number of cells"); VTKM_TEST_ASSERT(dcells.IsType>(), "Wrong cell type"); diff --git a/vtkm/filter/testing/UnitTestPointElevationFilter.cxx b/vtkm/filter/testing/UnitTestPointElevationFilter.cxx index 25e516a16..2f4fa1c6d 100644 --- a/vtkm/filter/testing/UnitTestPointElevationFilter.cxx +++ b/vtkm/filter/testing/UnitTestPointElevationFilter.cxx @@ -76,12 +76,13 @@ void TestPointElevationNoPolicy() vtkm::cont::ArrayHandle resultArrayHandle; result.GetPointField("height").GetData().CopyTo(resultArrayHandle); - auto coordinates = inputData.GetCoordinateSystem().GetData(); + auto coordinates = inputData.GetCoordinateSystem().GetDataAsMultiplexer(); + auto coordsPortal = coordinates.ReadPortal(); + auto resultPortal = resultArrayHandle.ReadPortal(); for (vtkm::Id i = 0; i < resultArrayHandle.GetNumberOfValues(); ++i) { - VTKM_TEST_ASSERT( - test_equal(coordinates.ReadPortal().Get(i)[1] * 2.0, resultArrayHandle.ReadPortal().Get(i)), - "Wrong result for PointElevation worklet"); + VTKM_TEST_ASSERT(test_equal(coordsPortal.Get(i)[1] * 2.0, resultPortal.Get(i)), + "Wrong result for PointElevation worklet"); } } @@ -106,12 +107,13 @@ void TestPointElevationWithPolicy() vtkm::cont::ArrayHandle resultArrayHandle; result.GetPointField("elevation").GetData().CopyTo(resultArrayHandle); - auto coordinates = inputData.GetCoordinateSystem().GetData(); + auto coordinates = inputData.GetCoordinateSystem().GetDataAsMultiplexer(); + auto coordsPortal = coordinates.ReadPortal(); + auto resultPortal = resultArrayHandle.ReadPortal(); for (vtkm::Id i = 0; i < resultArrayHandle.GetNumberOfValues(); ++i) { - VTKM_TEST_ASSERT( - test_equal(coordinates.ReadPortal().Get(i)[1] * 2.0, resultArrayHandle.ReadPortal().Get(i)), - "Wrong result for PointElevation worklet"); + VTKM_TEST_ASSERT(test_equal(coordsPortal.Get(i)[1] * 2.0, resultPortal.Get(i)), + "Wrong result for PointElevation worklet"); } } diff --git a/vtkm/filter/testing/UnitTestPointTransform.cxx b/vtkm/filter/testing/UnitTestPointTransform.cxx index 8a1a2414d..768468688 100644 --- a/vtkm/filter/testing/UnitTestPointTransform.cxx +++ b/vtkm/filter/testing/UnitTestPointTransform.cxx @@ -74,10 +74,9 @@ void ValidatePointTransform(const vtkm::cont::CoordinateSystem& coords, .GetData() .CopyTo(resultArrayHandle); - vtkm::cont::ArrayHandleVirtualCoordinates outPointsArrayHandle = - result.GetCoordinateSystem().GetData(); + auto outPointsArrayHandle = result.GetCoordinateSystem().GetDataAsMultiplexer(); - auto points = coords.GetData(); + auto points = coords.GetDataAsMultiplexer(); VTKM_TEST_ASSERT(points.GetNumberOfValues() == resultArrayHandle.GetNumberOfValues(), "Incorrect number of points in point transform"); diff --git a/vtkm/filter/testing/UnitTestSplitSharpEdgesFilter.cxx b/vtkm/filter/testing/UnitTestSplitSharpEdgesFilter.cxx index 9dd4d565d..7864659d6 100644 --- a/vtkm/filter/testing/UnitTestSplitSharpEdgesFilter.cxx +++ b/vtkm/filter/testing/UnitTestSplitSharpEdgesFilter.cxx @@ -132,7 +132,7 @@ void TestSplitSharpEdgesFilterSplitEveryEdge(vtkm::cont::DataSet& simpleCubeWith splitSharpEdgesFilter.SetActiveField("Normals", vtkm::cont::Field::Association::CELL_SET); vtkm::cont::DataSet result = splitSharpEdgesFilter.Execute(simpleCubeWithSN); - auto newCoords = result.GetCoordinateSystem().GetData(); + auto newCoords = result.GetCoordinateSystem().GetDataAsMultiplexer(); auto newCoordsP = newCoords.ReadPortal(); vtkm::cont::ArrayHandle newPointvarField; result.GetField("pointvar").GetData().CopyTo(newPointvarField); @@ -165,7 +165,7 @@ void TestSplitSharpEdgesFilterNoSplit(vtkm::cont::DataSet& simpleCubeWithSN, splitSharpEdgesFilter.SetActiveField("Normals", vtkm::cont::Field::Association::CELL_SET); vtkm::cont::DataSet result = splitSharpEdgesFilter.Execute(simpleCubeWithSN); - auto newCoords = result.GetCoordinateSystem().GetData(); + auto newCoords = result.GetCoordinateSystem().GetDataAsMultiplexer(); vtkm::cont::CellSetExplicit<>& newCellset = result.GetCellSet().Cast>(); auto newCoordsP = newCoords.ReadPortal(); diff --git a/vtkm/filter/testing/UnitTestStreamlineFilter.cxx b/vtkm/filter/testing/UnitTestStreamlineFilter.cxx index 8d359e872..a3cb943fc 100644 --- a/vtkm/filter/testing/UnitTestStreamlineFilter.cxx +++ b/vtkm/filter/testing/UnitTestStreamlineFilter.cxx @@ -139,7 +139,7 @@ void TestStreamlineFile(const std::string& fname, streamline.SetActiveField("vec"); auto output = streamline.Execute(ds); - auto coords = output.GetCoordinateSystem().GetData(); + auto coords = output.GetCoordinateSystem().GetDataAsMultiplexer(); vtkm::cont::DynamicCellSet dcells = output.GetCellSet(); VTKM_TEST_ASSERT(dcells.GetNumberOfCells() == numPoints, "Wrong number of cells"); VTKM_TEST_ASSERT(dcells.IsType>(), "Wrong cell type"); diff --git a/vtkm/filter/testing/UnitTestVertexClusteringFilter.cxx b/vtkm/filter/testing/UnitTestVertexClusteringFilter.cxx index 11ddccb55..f487045f8 100644 --- a/vtkm/filter/testing/UnitTestVertexClusteringFilter.cxx +++ b/vtkm/filter/testing/UnitTestVertexClusteringFilter.cxx @@ -60,7 +60,7 @@ void TestVertexClustering() } { - auto pointArray = output.GetCoordinateSystem(0).GetData(); + auto pointArray = output.GetCoordinateSystem(0).GetDataAsMultiplexer(); std::cerr << "output_points = " << pointArray.GetNumberOfValues() << "\n"; std::cerr << "output_point[] = "; vtkm::cont::printSummary_ArrayHandle(pointArray, std::cerr, true); @@ -70,7 +70,7 @@ void TestVertexClustering() vtkm::cont::printSummary_ArrayHandle(cellvar, std::cerr, true); using PointType = vtkm::Vec3f_64; - auto pointArray = output.GetCoordinateSystem(0).GetData(); + auto pointArray = output.GetCoordinateSystem(0).GetDataAsMultiplexer(); VTKM_TEST_ASSERT(pointArray.GetNumberOfValues() == output_points, "Number of output points mismatch"); auto pointArrayPortal = pointArray.ReadPortal(); diff --git a/vtkm/internal/FunctionInterface.h b/vtkm/internal/FunctionInterface.h index 21df44c17..7b2393fa4 100644 --- a/vtkm/internal/FunctionInterface.h +++ b/vtkm/internal/FunctionInterface.h @@ -10,6 +10,7 @@ #ifndef vtk_m_internal_FunctionInterface_h #define vtk_m_internal_FunctionInterface_h +#include #include #include @@ -237,8 +238,19 @@ VTKM_EXEC_CONT auto ParameterGet(const FunctionInterface& fIn template FunctionInterface make_FunctionInterface(const Args&... args) { +// MSVC will issue deprecation warnings if this templated method is instantiated with +// a deprecated class here even if the method is called from a section of code where +// deprecation warnings are suppressed. This is annoying behavior since this templated +// method has no control over what class it is used from. To get around it, we have to +// suppress all deprecation warnings here. +#ifdef VTKM_MSVC + VTKM_DEPRECATED_SUPPRESS_BEGIN +#endif detail::ParameterContainer container = { args... }; return FunctionInterface{ container }; +#ifdef VTKM_MSVC + VTKM_DEPRECATED_SUPPRESS_END +#endif } } } // namespace vtkm::internal diff --git a/vtkm/io/VTKDataSetWriter.cxx b/vtkm/io/VTKDataSetWriter.cxx index 43b3aaffa..64bb79f73 100644 --- a/vtkm/io/VTKDataSetWriter.cxx +++ b/vtkm/io/VTKDataSetWriter.cxx @@ -159,11 +159,13 @@ void WritePoints(std::ostream& out, const vtkm::cont::DataSet& dataSet) int cindex = 0; auto cdata = dataSet.GetCoordinateSystem(cindex).GetData(); - vtkm::Id npoints = cdata.GetNumberOfValues(); - out << "POINTS " << npoints << " " << vtkm::io::internal::DataTypeName::Name() - << " " << '\n'; + std::string typeName; + vtkm::cont::CastAndCall(cdata, GetDataTypeName(typeName)); - OutputPointsFunctor{ out }(cdata); + vtkm::Id npoints = cdata.GetNumberOfValues(); + out << "POINTS " << npoints << " " << typeName << " " << '\n'; + + cdata.CastAndCall(OutputPointsFunctor{ out }); } template @@ -381,7 +383,7 @@ void WriteDataSetAsStructured(std::ostream& out, ///\todo: support rectilinear // Type of structured grid (uniform, rectilinear, curvilinear) is determined by coordinate system - vtkm::cont::ArrayHandleVirtualCoordinates coordSystem = dataSet.GetCoordinateSystem().GetData(); + auto coordSystem = dataSet.GetCoordinateSystem().GetData(); if (coordSystem.IsType()) { // uniform is written as "structured points" diff --git a/vtkm/io/testing/UnitTestVTKDataSetWriter.cxx b/vtkm/io/testing/UnitTestVTKDataSetWriter.cxx index 1e94e778b..562b09e59 100644 --- a/vtkm/io/testing/UnitTestVTKDataSetWriter.cxx +++ b/vtkm/io/testing/UnitTestVTKDataSetWriter.cxx @@ -44,6 +44,13 @@ struct CheckSameCoordinateSystem CheckSameField{}(originalArray, fileCoords); } + template + void operator()(const vtkm::cont::ArrayHandleVirtual& originalArray, + const vtkm::cont::CoordinateSystem& fileCoords) const + { + CheckSameField{}(originalArray, fileCoords); + } + void operator()(const vtkm::cont::ArrayHandleUniformPointCoordinates& originalArray, const vtkm::cont::CoordinateSystem& fileCoords) const { @@ -57,16 +64,19 @@ struct CheckSameCoordinateSystem VTKM_TEST_ASSERT(test_equal(originalPortal.GetRange3(), filePortal.GetRange3())); } - using ArrayHandleRectilinearCoords = - vtkm::cont::ArrayHandleCartesianProduct, - vtkm::cont::ArrayHandle, - vtkm::cont::ArrayHandle>; - void operator()(const ArrayHandleRectilinearCoords& originalArray, + template + using ArrayHandleRectilinearCoords = vtkm::cont::ArrayHandle< + T, + typename vtkm::cont::ArrayHandleCartesianProduct, + vtkm::cont::ArrayHandle, + vtkm::cont::ArrayHandle>::StorageTag>; + template + void operator()(const ArrayHandleRectilinearCoords& originalArray, const vtkm::cont::CoordinateSystem& fileCoords) const { - VTKM_TEST_ASSERT(fileCoords.GetData().IsType()); - ArrayHandleRectilinearCoords fileArray = - fileCoords.GetData().Cast(); + VTKM_TEST_ASSERT(fileCoords.GetData().IsType>()); + ArrayHandleRectilinearCoords fileArray = + fileCoords.GetData().Cast>(); auto originalPortal = originalArray.ReadPortal(); auto filePortal = fileArray.ReadPortal(); VTKM_TEST_ASSERT( @@ -76,23 +86,6 @@ struct CheckSameCoordinateSystem VTKM_TEST_ASSERT( test_equal_portals(originalPortal.GetThirdPortal(), filePortal.GetThirdPortal())); } - - void operator()(const vtkm::cont::ArrayHandleVirtualCoordinates& originalArray, - const vtkm::cont::CoordinateSystem& fileCoords) const - { - if (originalArray.IsType()) - { - (*this)(originalArray.Cast(), fileCoords); - } - else if (originalArray.IsType()) - { - (*this)(originalArray.Cast(), fileCoords); - } - else - { - CheckSameField{}(originalArray, fileCoords); - } - } }; void CheckWrittenReadData(const vtkm::cont::DataSet& originalData, @@ -111,8 +104,9 @@ void CheckWrittenReadData(const vtkm::cont::DataSet& originalData, } VTKM_TEST_ASSERT(fileData.GetNumberOfCoordinateSystems() > 0); - CheckSameCoordinateSystem{}(originalData.GetCoordinateSystem().GetData(), - fileData.GetCoordinateSystem()); + vtkm::cont::CastAndCall(originalData.GetCoordinateSystem().GetData(), + CheckSameCoordinateSystem{}, + fileData.GetCoordinateSystem()); } void TestVTKWriteTestData(const std::string& methodName, const vtkm::cont::DataSet& data) diff --git a/vtkm/rendering/raytracing/MeshConnectivityBuilder.cxx b/vtkm/rendering/raytracing/MeshConnectivityBuilder.cxx index 57789c8f0..da086a41b 100644 --- a/vtkm/rendering/raytracing/MeshConnectivityBuilder.cxx +++ b/vtkm/rendering/raytracing/MeshConnectivityBuilder.cxx @@ -509,12 +509,13 @@ public: template + typename OffsetsHandleType, + typename CoordsType> VTKM_CONT void GenerateFaceConnnectivity(const CellSetType cellSet, const ShapeHandleType shapes, const ConnHandleType conn, const OffsetsHandleType shapeOffsets, - const vtkm::cont::ArrayHandleVirtualCoordinates& coords, + const CoordsType& coords, vtkm::cont::ArrayHandle& faceConnectivity, vtkm::cont::ArrayHandle& cellFaceId, vtkm::Float32 BoundingBox[6], @@ -662,7 +663,7 @@ MeshConnectivityBuilder::~MeshConnectivityBuilder() VTKM_CONT void MeshConnectivityBuilder::BuildConnectivity( vtkm::cont::CellSetSingleType<>& cellSetUnstructured, - const vtkm::cont::ArrayHandleVirtualCoordinates& coordinates, + const vtkm::cont::CoordinateSystem::MultiplexerArrayType& coordinates, vtkm::Bounds coordsBounds) { Logger* logger = Logger::GetInstance(); @@ -725,7 +726,7 @@ void MeshConnectivityBuilder::BuildConnectivity( VTKM_CONT void MeshConnectivityBuilder::BuildConnectivity( vtkm::cont::CellSetExplicit<>& cellSetUnstructured, - const vtkm::cont::ArrayHandleVirtualCoordinates& coordinates, + const vtkm::cont::CoordinateSystem::MultiplexerArrayType& coordinates, vtkm::Bounds coordsBounds) { Logger* logger = Logger::GetInstance(); @@ -902,14 +903,14 @@ MeshConnContainer* MeshConnectivityBuilder::BuildConnectivity( if (type == Unstructured) { vtkm::cont::CellSetExplicit<> cells = cellset.Cast>(); - this->BuildConnectivity(cells, coordinates.GetData(), coordBounds); + this->BuildConnectivity(cells, coordinates.GetDataAsMultiplexer(), coordBounds); meshConn = new UnstructuredContainer(cells, coordinates, FaceConnectivity, FaceOffsets, Triangles); } else if (type == UnstructuredSingle) { vtkm::cont::CellSetSingleType<> cells = cellset.Cast>(); - this->BuildConnectivity(cells, coordinates.GetData(), coordBounds); + this->BuildConnectivity(cells, coordinates.GetDataAsMultiplexer(), coordBounds); meshConn = new UnstructuredSingleContainer(cells, coordinates, FaceConnectivity, Triangles); } else if (type == Structured) diff --git a/vtkm/rendering/raytracing/MeshConnectivityBuilder.h b/vtkm/rendering/raytracing/MeshConnectivityBuilder.h index 0b24cb112..102615fda 100644 --- a/vtkm/rendering/raytracing/MeshConnectivityBuilder.h +++ b/vtkm/rendering/raytracing/MeshConnectivityBuilder.h @@ -43,12 +43,12 @@ public: protected: VTKM_CONT void BuildConnectivity(vtkm::cont::CellSetSingleType<>& cellSetUnstructured, - const vtkm::cont::ArrayHandleVirtualCoordinates& coordinates, + const vtkm::cont::CoordinateSystem::MultiplexerArrayType& coordinates, vtkm::Bounds coordsBounds); VTKM_CONT void BuildConnectivity(vtkm::cont::CellSetExplicit<>& cellSetUnstructured, - const vtkm::cont::ArrayHandleVirtualCoordinates& coordinates, + const vtkm::cont::CoordinateSystem::MultiplexerArrayType& coordinates, vtkm::Bounds coordsBounds); vtkm::cont::ArrayHandle FaceConnectivity; diff --git a/vtkm/rendering/raytracing/VolumeRendererStructured.cxx b/vtkm/rendering/raytracing/VolumeRendererStructured.cxx index b44daf501..9191ce301 100644 --- a/vtkm/rendering/raytracing/VolumeRendererStructured.cxx +++ b/vtkm/rendering/raytracing/VolumeRendererStructured.cxx @@ -737,7 +737,7 @@ void VolumeRendererStructured::SetData(const vtkm::cont::CoordinateSystem& coord IsUniformDataSet = !coords.GetData().IsType(); IsSceneDirty = true; SpatialExtent = coords.GetBounds(); - Coordinates = coords.GetData(); + Coordinates = coords; ScalarField = &scalarField; Cellset = cellset; ScalarRange = scalarRange; @@ -829,7 +829,7 @@ void VolumeRendererStructured::RenderOnDevice(vtkm::rendering::raytracing::Ray

(); + vertices = Coordinates.GetData().Cast(); UniformLocator locator(vertices, Cellset, token); if (isAssocPoints) @@ -872,7 +872,7 @@ void VolumeRendererStructured::RenderOnDevice(vtkm::rendering::raytracing::Ray

(); + vertices = Coordinates.GetData().Cast(); RectilinearLocator locator(vertices, Cellset, token); if (isAssocPoints) { diff --git a/vtkm/rendering/raytracing/VolumeRendererStructured.h b/vtkm/rendering/raytracing/VolumeRendererStructured.h index 1fdadf426..b203604f8 100644 --- a/vtkm/rendering/raytracing/VolumeRendererStructured.h +++ b/vtkm/rendering/raytracing/VolumeRendererStructured.h @@ -66,7 +66,7 @@ protected: bool IsSceneDirty; bool IsUniformDataSet; vtkm::Bounds SpatialExtent; - vtkm::cont::ArrayHandleVirtualCoordinates Coordinates; + vtkm::cont::CoordinateSystem Coordinates; vtkm::cont::CellSetStructured<3> Cellset; const vtkm::cont::Field* ScalarField; vtkm::cont::ArrayHandle ColorMap; diff --git a/vtkm/worklet/AverageByKey.h b/vtkm/worklet/AverageByKey.h index a16d06eaa..6cc2eeb8d 100644 --- a/vtkm/worklet/AverageByKey.h +++ b/vtkm/worklet/AverageByKey.h @@ -65,10 +65,10 @@ struct AverageByKey /// This method uses an existing \c Keys object to collected values by those keys and find /// the average of those groups. /// - template + template VTKM_CONT static void Run(const vtkm::worklet::internal::KeysBase& keys, - const vtkm::cont::ArrayHandle& inValues, - vtkm::cont::ArrayHandle& outAverages) + const InArrayType& inValues, + OutArrayType& outAverages) { vtkm::worklet::DispatcherReduceByKey dispatcher; diff --git a/vtkm/worklet/Contour.h b/vtkm/worklet/Contour.h index c28c5ec09..d72f0f6cb 100644 --- a/vtkm/worklet/Contour.h +++ b/vtkm/worklet/Contour.h @@ -41,10 +41,11 @@ struct DeduceCoordType } template - void operator()(const vtkm::cont::ArrayHandleUniformPointCoordinates& coords, - const vtkm::cont::CellSetStructured<3>& cells, - vtkm::cont::CellSetSingleType<>& result, - Args&&... args) const + void operator()( + const vtkm::cont::ArrayHandle& coords, + const vtkm::cont::CellSetStructured<3>& cells, + vtkm::cont::CellSetSingleType<>& result, + Args&&... args) const { result = flying_edges::execute(cells, coords, std::forward(args)...); } diff --git a/vtkm/worklet/ExtractStructured.h b/vtkm/worklet/ExtractStructured.h index d00891ec1..17a16497f 100644 --- a/vtkm/worklet/ExtractStructured.h +++ b/vtkm/worklet/ExtractStructured.h @@ -424,8 +424,7 @@ private: vtkm::cont::ArrayHandle>::Superclass; - vtkm::cont::ArrayHandleVirtualCoordinates MapCoordinatesUniform( - const UniformCoordinatesArrayHandle& coords) + UniformCoordinatesArrayHandle MapCoordinatesUniform(const UniformCoordinatesArrayHandle& coords) { using CoordsArray = vtkm::cont::ArrayHandleUniformPointCoordinates; using CoordType = CoordsArray::ValueType; @@ -441,11 +440,10 @@ private: inOrigin[2] + static_cast(this->VOI.Z.Min) * inSpacing[2]); CoordType outSpacing = inSpacing * static_cast(this->SampleRate); - auto out = CoordsArray(this->OutputDimensions, outOrigin, outSpacing); - return vtkm::cont::ArrayHandleVirtualCoordinates(out); + return CoordsArray(this->OutputDimensions, outOrigin, outSpacing); } - vtkm::cont::ArrayHandleVirtualCoordinates MapCoordinatesRectilinear( + RectilinearCoordinatesArrayHandle MapCoordinatesRectilinear( const RectilinearCoordinatesArrayHandle& coords) { // For structured datasets, the cellsets are of different types based on @@ -478,28 +476,43 @@ private: } VTKM_ASSERT(dim == this->InputDimensionality); - auto out = vtkm::cont::make_ArrayHandleCartesianProduct(xyzs[0], xyzs[1], xyzs[2]); - return vtkm::cont::ArrayHandleVirtualCoordinates(out); + return vtkm::cont::make_ArrayHandleCartesianProduct(xyzs[0], xyzs[1], xyzs[2]); } + struct MapCoordinatesFunctor + { + template + VTKM_CONT void operator()(const vtkm::cont::ArrayHandle& coords, + ExtractStructured& self, + vtkm::cont::VariantArrayHandleCommon& output) const + { + output = self.ProcessPointField(coords); + } + + VTKM_CONT void operator()(const UniformCoordinatesArrayHandle& coords, + ExtractStructured& self, + vtkm::cont::VariantArrayHandleCommon& output) const + { + output = self.MapCoordinatesUniform(coords); + } + + VTKM_CONT void operator()(const RectilinearCoordinatesArrayHandle& coords, + ExtractStructured& self, + vtkm::cont::VariantArrayHandleCommon& output) const + { + output = self.MapCoordinatesRectilinear(coords); + } + }; + + friend MapCoordinatesFunctor; + public: - vtkm::cont::ArrayHandleVirtualCoordinates MapCoordinates( + vtkm::cont::VariantArrayHandleCommon MapCoordinates( const vtkm::cont::CoordinateSystem& coordinates) { - auto coArray = coordinates.GetData(); - if (coArray.IsType()) - { - return this->MapCoordinatesUniform(coArray.Cast()); - } - else if (coArray.IsType()) - { - return this->MapCoordinatesRectilinear(coArray.Cast()); - } - else - { - auto out = this->ProcessPointField(coArray); - return vtkm::cont::ArrayHandleVirtualCoordinates(out); - } + vtkm::cont::VariantArrayHandleCommon output; + vtkm::cont::CastAndCall(coordinates, MapCoordinatesFunctor{}, *this, output); + return output; } public: diff --git a/vtkm/worklet/PointMerge.h b/vtkm/worklet/PointMerge.h index 1575f1043..ce897a203 100644 --- a/vtkm/worklet/PointMerge.h +++ b/vtkm/worklet/PointMerge.h @@ -25,6 +25,7 @@ #include #include #include +#include #include #include @@ -419,17 +420,18 @@ public: points = uniquePointCoordinates; } + template VTKM_CONT void Run( - vtkm::Float64 delta, // Distance to consider two points coincident - bool fastCheck, // If true, approximate distances are used - const vtkm::Bounds& bounds, // Bounds of points - vtkm::cont::ArrayHandleVirtualCoordinates& points) // coordinates, modified to merge close + vtkm::Float64 delta, // Distance to consider two points coincident + bool fastCheck, // If true, approximate distances are used + const vtkm::Bounds& bounds, // Bounds of points + vtkm::cont::VariantArrayHandleBase& points) // coordinates, modified to merge close { // Get a cast to a concrete set of point coordiantes so that it can be modified in place vtkm::cont::ArrayHandle concretePoints; - if (points.IsType()) + if (points.template IsType()) { - concretePoints = points.Cast(); + concretePoints = points.template Cast(); } else { @@ -439,7 +441,7 @@ public: Run(delta, fastCheck, bounds, concretePoints); // Make sure that the modified points are reflected back in the virtual array. - points = vtkm::cont::ArrayHandleVirtualCoordinates(concretePoints); + points = concretePoints; } template @@ -452,27 +454,46 @@ public: inCellSet, this->PointInputToOutputMap, this->MergeKeys.GetInputRange()); } +private: + struct MapPointFieldFunctor + { + template + VTKM_CONT void operator()(const vtkm::cont::ArrayHandle& inArray, + vtkm::cont::VariantArrayHandleCommon& outHolder, + const PointMerge& self) const + { + vtkm::cont::ArrayHandle outArray; + self.MapPointField(inArray, outArray); + outHolder = vtkm::cont::VariantArrayHandleCommon(outArray); + } + }; + +public: template VTKM_CONT void MapPointField(const InArrayHandle& inArray, OutArrayHandle& outArray) const { - VTKM_IS_ARRAY_HANDLE(InArrayHandle); - VTKM_IS_ARRAY_HANDLE(OutArrayHandle); - vtkm::worklet::AverageByKey::Run(this->MergeKeys, inArray, outArray); } - template - VTKM_CONT vtkm::cont::ArrayHandle MapPointField( - const InArrayHandle& inArray) const + template + VTKM_CONT vtkm::cont::ArrayHandle MapPointField( + const vtkm::cont::ArrayHandle& inArray) const { - VTKM_IS_ARRAY_HANDLE(InArrayHandle); - - vtkm::cont::ArrayHandle outArray; + vtkm::cont::ArrayHandle outArray; this->MapPointField(inArray, outArray); return outArray; } + template + VTKM_CONT vtkm::cont::VariantArrayHandleBase MapPointField( + const vtkm::cont::VariantArrayHandleBase& inArray) const + { + vtkm::cont::VariantArrayHandleBase outArray; + vtkm::cont::CastAndCall(inArray, MapPointFieldFunctor{}, outArray, *this); + return outArray; + } + vtkm::worklet::Keys GetMergeKeys() const { return this->MergeKeys; } private: diff --git a/vtkm/worklet/RemoveUnusedPoints.h b/vtkm/worklet/RemoveUnusedPoints.h index 1979da67d..83c61599f 100644 --- a/vtkm/worklet/RemoveUnusedPoints.h +++ b/vtkm/worklet/RemoveUnusedPoints.h @@ -194,12 +194,37 @@ public: VTKM_CONT vtkm::cont::ArrayHandlePermutation, InArrayHandle> MapPointFieldShallow(const InArrayHandle& inArray) const { + VTKM_IS_ARRAY_HANDLE(InArrayHandle); VTKM_ASSERT(this->PointScatter); return vtkm::cont::make_ArrayHandlePermutation(this->PointScatter->GetOutputToInputMap(), inArray); } +private: + struct MapPointFieldDeepFunctor + { + template + VTKM_CONT void operator()(const vtkm::cont::ArrayHandle& inArray, + vtkm::cont::ArrayHandle& outArray, + const RemoveUnusedPoints& self) const + { + self.MapPointFieldDeep(inArray, outArray); + } + + template + VTKM_CONT void operator()(const vtkm::cont::ArrayHandle& inArray, + vtkm::cont::VariantArrayHandleCommon& outHolder, + const RemoveUnusedPoints& self) const + { + vtkm::cont::ArrayHandle outArray; + (*this)(inArray, outArray, self); + outHolder = vtkm::cont::VariantArrayHandleCommon{ outArray }; + } + }; + +public: + ///@{ /// \brief Maps a point field from the original points to the new reduced points /// /// Given an array handle that holds the values for a point field of the @@ -209,36 +234,41 @@ public: /// This version of point mapping performs a deep copy into the destination /// array provided. /// - template - VTKM_CONT void MapPointFieldDeep(const InArrayHandle& inArray, OutArrayHandle& outArray) const + template + VTKM_CONT void MapPointFieldDeep(const vtkm::cont::ArrayHandle& inArray, + vtkm::cont::ArrayHandle& outArray) const { - VTKM_IS_ARRAY_HANDLE(InArrayHandle); - VTKM_IS_ARRAY_HANDLE(OutArrayHandle); - vtkm::cont::ArrayCopy(this->MapPointFieldShallow(inArray), outArray); } - /// \brief Maps a point field from the original points to the new reduced points - /// - /// Given an array handle that holds the values for a point field of the - /// original data set, returns a new array handle containing field values - /// rearranged to the new indices of the reduced point set. - /// - /// This version of point mapping performs a deep copy into an array that is - /// returned. - /// - template - vtkm::cont::ArrayHandle MapPointFieldDeep( - const InArrayHandle& inArray) const + template + VTKM_CONT vtkm::cont::ArrayHandle MapPointFieldDeep( + const vtkm::cont::ArrayHandle& inArray) const { - VTKM_IS_ARRAY_HANDLE(InArrayHandle); - - vtkm::cont::ArrayHandle outArray; + vtkm::cont::ArrayHandle outArray; this->MapPointFieldDeep(inArray, outArray); return outArray; } + template + VTKM_CONT void MapPointFieldDeep(const vtkm::cont::VariantArrayHandleBase& inArray, + OutArrayHandle& outArray) const + { + vtkm::cont::CastAndCall(inArray, MapPointFieldDeepFunctor{}, outArray, *this); + } + + template + VTKM_CONT vtkm::cont::VariantArrayHandleBase MapPointFieldDeep( + const vtkm::cont::VariantArrayHandleBase& inArray) const + { + vtkm::cont::VariantArrayHandleBase outArray; + vtkm::cont::CastAndCall(inArray, MapPointFieldDeepFunctor{}, outArray, *this); + + return outArray; + } + ///@} + const vtkm::worklet::ScatterCounting& GetPointScatter() const { return *this->PointScatter.get(); diff --git a/vtkm/worklet/SurfaceNormals.h b/vtkm/worklet/SurfaceNormals.h index 24f5a9443..33dde10f6 100644 --- a/vtkm/worklet/SurfaceNormals.h +++ b/vtkm/worklet/SurfaceNormals.h @@ -131,9 +131,9 @@ public: } } - template + template void Run(const CellSetType& cellset, - const vtkm::cont::VariantArrayHandleBase& points, + const PointsType& points, vtkm::cont::ArrayHandle>& normals) { if (this->Normalize) diff --git a/vtkm/worklet/TriangleWinding.h b/vtkm/worklet/TriangleWinding.h index c41394523..2968ac170 100644 --- a/vtkm/worklet/TriangleWinding.h +++ b/vtkm/worklet/TriangleWinding.h @@ -164,17 +164,11 @@ public: vtkm::cont::DynamicCellSet Result; // Generic handler: - template - VTKM_CONT void operator()( - const CellSetType& cellSet, - const vtkm::cont::ArrayHandle, PointStorageType>& coords, - const vtkm::cont::ArrayHandle, CellNormalStorageType>& - cellNormals, - ...) + template + VTKM_CONT void operator()(const CellSetType& cellSet, + const CoordsType& coords, + const CellNormalsType& cellNormals, + ...) { const auto numCells = cellSet.GetNumberOfCells(); if (numCells == 0) @@ -257,19 +251,11 @@ public: } // Specialization for CellSetExplicit - template - VTKM_CONT void operator()( - const vtkm::cont::CellSetExplicit& cellSet, - const vtkm::cont::ArrayHandle, PointStorageType>& coords, - const vtkm::cont::ArrayHandle, CellNormalStorageType>& - cellNormals, - int) + template + VTKM_CONT void operator()(const vtkm::cont::CellSetExplicit& cellSet, + const CoordsType& coords, + const CellNormalsType& cellNormals, + int) { using WindToCellNormals = vtkm::worklet::DispatcherMapField; @@ -303,17 +289,11 @@ public: } // Specialization for CellSetSingleType - template - VTKM_CONT void operator()( - const vtkm::cont::CellSetSingleType& cellSet, - const vtkm::cont::ArrayHandle, PointStorageType>& coords, - const vtkm::cont::ArrayHandle, CellNormalStorageType>& - cellNormals, - int) + template + VTKM_CONT void operator()(const vtkm::cont::CellSetSingleType& cellSet, + const CoordsType& coords, + const CellNormalsType& cellNormals, + int) { using WindToCellNormals = vtkm::worklet::DispatcherMapField; @@ -348,16 +328,10 @@ public: } }; - template - VTKM_CONT static vtkm::cont::DynamicCellSet Run( - const CellSetType& cellSet, - const vtkm::cont::ArrayHandle, PointStorageType>& coords, - const vtkm::cont::ArrayHandle, CellNormalStorageType>& - cellNormals) + template + VTKM_CONT static vtkm::cont::DynamicCellSet Run(const CellSetType& cellSet, + const CoordsType& coords, + const CellNormalsType& cellNormals) { Launcher launcher; // The last arg is just to help with overload resolution on the templated diff --git a/vtkm/worklet/testing/UnitTestBoundingIntervalHierarchy.cxx b/vtkm/worklet/testing/UnitTestBoundingIntervalHierarchy.cxx index e77673d41..267074c77 100644 --- a/vtkm/worklet/testing/UnitTestBoundingIntervalHierarchy.cxx +++ b/vtkm/worklet/testing/UnitTestBoundingIntervalHierarchy.cxx @@ -65,7 +65,7 @@ void TestBoundingIntervalHierarchy(vtkm::cont::DataSet dataSet, vtkm::IdComponen using Timer = vtkm::cont::Timer; vtkm::cont::DynamicCellSet cellSet = dataSet.GetCellSet(); - vtkm::cont::ArrayHandleVirtualCoordinates vertices = dataSet.GetCoordinateSystem().GetData(); + auto vertices = dataSet.GetCoordinateSystem().GetDataAsMultiplexer(); std::cout << "Using numPlanes: " << numPlanes << "\n"; std::cout << "Building Bounding Interval Hierarchy Tree" << std::endl; diff --git a/vtkm/worklet/testing/UnitTestCellMeasure.cxx b/vtkm/worklet/testing/UnitTestCellMeasure.cxx index a03eaa0bc..a6561abc7 100644 --- a/vtkm/worklet/testing/UnitTestCellMeasure.cxx +++ b/vtkm/worklet/testing/UnitTestCellMeasure.cxx @@ -27,7 +27,8 @@ void TestCellMeasureUniform3D() vtkm::cont::ArrayHandle result; vtkm::worklet::DispatcherMapTopology> dispatcher; - dispatcher.Invoke(dataSet.GetCellSet(), dataSet.GetCoordinateSystem(), result); + dispatcher.Invoke( + dataSet.GetCellSet(), dataSet.GetCoordinateSystem().GetDataAsMultiplexer(), result); vtkm::Float32 expected[4] = { 1.f, 1.f, 1.f, 1.f }; for (int i = 0; i < 4; ++i) @@ -48,7 +49,8 @@ void TestCellMeasureWorklet(vtkm::cont::DataSet& dataset, vtkm::cont::ArrayHandle result; vtkm::worklet::DispatcherMapTopology> dispatcher; - dispatcher.Invoke(dataset.GetCellSet(), dataset.GetCoordinateSystem(), result); + dispatcher.Invoke( + dataset.GetCellSet(), dataset.GetCoordinateSystem().GetDataAsMultiplexer(), result); VTKM_TEST_ASSERT(result.GetNumberOfValues() == static_cast(expected.size()), "Wrong number of values in the output array"); diff --git a/vtkm/worklet/testing/UnitTestClipping.cxx b/vtkm/worklet/testing/UnitTestClipping.cxx index 9301b4f65..f133f9c1e 100644 --- a/vtkm/worklet/testing/UnitTestClipping.cxx +++ b/vtkm/worklet/testing/UnitTestClipping.cxx @@ -120,7 +120,7 @@ void TestClippingExplicit() clipValue, invertClip); - auto coordsIn = ds.GetCoordinateSystem("coords").GetData(); + auto coordsIn = ds.GetCoordinateSystem("coords").GetDataAsMultiplexer(); vtkm::cont::ArrayHandle coords = clip.ProcessPointField(coordsIn); vtkm::cont::ArrayHandle scalarsIn; @@ -176,7 +176,7 @@ void TestClippingStructured() clipValue, invertClip); - auto coordsIn = ds.GetCoordinateSystem("coords").GetData(); + auto coordsIn = ds.GetCoordinateSystem("coords").GetDataAsMultiplexer(); CoordsOutType coords = clip.ProcessPointField(coordsIn); vtkm::cont::ArrayHandle scalarsIn; @@ -238,7 +238,7 @@ void TestClippingWithImplicitFunction() ds.GetCoordinateSystem("coords"), invertClip); - auto coordsIn = ds.GetCoordinateSystem("coords").GetData(); + auto coordsIn = ds.GetCoordinateSystem("coords").GetDataAsMultiplexer(); vtkm::cont::ArrayHandle coords = clip.ProcessPointField(coordsIn); vtkm::cont::ArrayHandle scalarsIn; @@ -297,7 +297,7 @@ void TestClippingWithImplicitFunctionInverted() ds.GetCoordinateSystem("coords"), invertClip); - auto coordsIn = ds.GetCoordinateSystem("coords").GetData(); + auto coordsIn = ds.GetCoordinateSystem("coords").GetDataAsMultiplexer(); vtkm::cont::ArrayHandle coords = clip.ProcessPointField(coordsIn); vtkm::cont::ArrayHandle scalarsIn; diff --git a/vtkm/worklet/testing/UnitTestCoordinateSystemTransform.cxx b/vtkm/worklet/testing/UnitTestCoordinateSystemTransform.cxx index 19a73da5a..1274363c1 100644 --- a/vtkm/worklet/testing/UnitTestCoordinateSystemTransform.cxx +++ b/vtkm/worklet/testing/UnitTestCoordinateSystemTransform.cxx @@ -107,7 +107,7 @@ void ValidateCoordTransform(const vtkm::cont::CoordinateSystem& coords, const vtkm::cont::ArrayHandle& doubleTransform, const std::vector& isAngle) { - auto points = coords.GetData(); + auto points = coords.GetDataAsMultiplexer(); VTKM_TEST_ASSERT(points.GetNumberOfValues() == transform.GetNumberOfValues() && points.GetNumberOfValues() == doubleTransform.GetNumberOfValues(), "Incorrect number of points in point transform"); diff --git a/vtkm/worklet/testing/UnitTestOrientNormals.cxx b/vtkm/worklet/testing/UnitTestOrientNormals.cxx index 41483e783..490753940 100644 --- a/vtkm/worklet/testing/UnitTestOrientNormals.cxx +++ b/vtkm/worklet/testing/UnitTestOrientNormals.cxx @@ -85,7 +85,7 @@ struct ValidateNormals using NormalType = vtkm::Vec; using NormalsArrayType = vtkm::cont::ArrayHandleVirtual; using NormalsPortalType = decltype(std::declval().ReadPortal()); - using PointsType = decltype(std::declval().GetData().ReadPortal()); + using PointsType = decltype(std::declval().GetDataAsMultiplexer()); vtkm::cont::CoordinateSystem Coords; CellSetType Cells; @@ -139,7 +139,7 @@ struct ValidateNormals const vtkm::cont::Field& cellNormalsField) : Coords{ dataset.GetCoordinateSystem() } , Cells{ dataset.GetCellSet().Cast() } - , Points{ this->Coords.GetData().ReadPortal() } + , Points{ this->Coords.GetDataAsMultiplexer() } , CheckPoints(checkPoints) , CheckCells(checkCells) { @@ -170,7 +170,8 @@ struct ValidateNormals // Locate a point with the minimum x coordinate: const vtkm::Id startPoint = [&]() -> vtkm::Id { const vtkm::Float64 xMin = this->Coords.GetBounds().X.Min; - const auto points = this->Coords.GetData().ReadPortal(); + const auto pointArray = this->Coords.GetDataAsMultiplexer(); + const auto points = pointArray.ReadPortal(); const vtkm::Id numPoints = points.GetNumberOfValues(); vtkm::Id resultIdx = -1; for (vtkm::Id pointIdx = 0; pointIdx < numPoints; ++pointIdx) @@ -240,6 +241,7 @@ private: vtkm::TopologyElementTagCell{}, token); + auto points = this->Points.ReadPortal(); while (!queue.empty()) { const vtkm::Id curPtIdx = queue.back().first; @@ -251,7 +253,7 @@ private: const NormalType curNormal = this->PointNormals.Get(curPtIdx); if (!this->SameHemisphere(curNormal, refNormal)) { - const auto coord = this->Points.Get(curPtIdx); + const auto coord = points.Get(curPtIdx); std::cerr << "BadPointNormal PtId: " << curPtIdx << "\n\t" << "- Normal: {" << curNormal[0] << ", " << curNormal[1] << ", " << curNormal[2] << "}\n\t" @@ -343,7 +345,7 @@ void TestOrientNormals(bool testPoints, bool testCells) } // modify normals in place - const auto coords = dataset.GetCoordinateSystem().GetData(); + const auto coords = dataset.GetCoordinateSystem().GetDataAsMultiplexer(); const auto cells = dataset.GetCellSet(); if (testPoints && testCells) { diff --git a/vtkm/worklet/testing/UnitTestPointElevation.cxx b/vtkm/worklet/testing/UnitTestPointElevation.cxx index 487ccc61c..bcf90b6b4 100644 --- a/vtkm/worklet/testing/UnitTestPointElevation.cxx +++ b/vtkm/worklet/testing/UnitTestPointElevation.cxx @@ -78,12 +78,13 @@ void TestPointElevation() pointElevationWorklet); dispatcher.Invoke(dataSet.GetCoordinateSystem(), result); - auto coordinates = dataSet.GetCoordinateSystem().GetData(); + auto coordinates = dataSet.GetCoordinateSystem().GetDataAsMultiplexer(); + auto coordinatesPortal = coordinates.ReadPortal(); + auto resultPortal = result.ReadPortal(); for (vtkm::Id i = 0; i < result.GetNumberOfValues(); ++i) { - VTKM_TEST_ASSERT( - test_equal(coordinates.ReadPortal().Get(i)[1] * 2.0, result.ReadPortal().Get(i)), - "Wrong result for PointElevation worklet"); + VTKM_TEST_ASSERT(test_equal(coordinatesPortal.Get(i)[1] * 2.0, resultPortal.Get(i)), + "Wrong result for PointElevation worklet"); } } diff --git a/vtkm/worklet/testing/UnitTestPointTransform.cxx b/vtkm/worklet/testing/UnitTestPointTransform.cxx index d90df3066..159d20389 100644 --- a/vtkm/worklet/testing/UnitTestPointTransform.cxx +++ b/vtkm/worklet/testing/UnitTestPointTransform.cxx @@ -66,7 +66,7 @@ void ValidatePointTransform(const vtkm::cont::CoordinateSystem& coords, const vtkm::cont::ArrayHandle& result, const vtkm::Matrix& matrix) { - auto points = coords.GetData(); + auto points = coords.GetDataAsMultiplexer(); VTKM_TEST_ASSERT(points.GetNumberOfValues() == result.GetNumberOfValues(), "Incorrect number of points in point transform"); diff --git a/vtkm/worklet/testing/UnitTestSplitSharpEdges.cxx b/vtkm/worklet/testing/UnitTestSplitSharpEdges.cxx index 206a32572..7ff5a6ea8 100644 --- a/vtkm/worklet/testing/UnitTestSplitSharpEdges.cxx +++ b/vtkm/worklet/testing/UnitTestSplitSharpEdges.cxx @@ -121,7 +121,7 @@ void TestSplitSharpEdgesSplitEveryEdge(vtkm::cont::DataSet& simpleCube, splitSharpEdges.Run(simpleCube.GetCellSet(), featureAngle, faceNormals, - simpleCube.GetCoordinateSystem().GetData(), + simpleCube.GetCoordinateSystem().GetDataAsMultiplexer(), newCoords, newCellset); @@ -166,7 +166,7 @@ void TestSplitSharpEdgesNoSplit(vtkm::cont::DataSet& simpleCube, splitSharpEdges.Run(simpleCube.GetCellSet(), featureAngle, faceNormals, - simpleCube.GetCoordinateSystem().GetData(), + simpleCube.GetCoordinateSystem().GetDataAsMultiplexer(), newCoords, newCellset); @@ -213,7 +213,8 @@ void TestSplitSharpEdges() vtkm::cont::DataSet simpleCube = Make3DExplicitSimpleCube(); NormalsArrayHandle faceNormals; vtkm::worklet::FacetedSurfaceNormals faceted; - faceted.Run(simpleCube.GetCellSet(), simpleCube.GetCoordinateSystem().GetData(), faceNormals); + faceted.Run( + simpleCube.GetCellSet(), simpleCube.GetCoordinateSystem().GetDataAsMultiplexer(), faceNormals); vtkm::worklet::SplitSharpEdges splitSharpEdges; diff --git a/vtkm/worklet/testing/UnitTestTriangleWinding.cxx b/vtkm/worklet/testing/UnitTestTriangleWinding.cxx index 6afc9e364..905284822 100644 --- a/vtkm/worklet/testing/UnitTestTriangleWinding.cxx +++ b/vtkm/worklet/testing/UnitTestTriangleWinding.cxx @@ -53,7 +53,7 @@ vtkm::cont::DataSet GenerateDataSet() void Validate(vtkm::cont::DataSet dataSet) { const auto cellSet = dataSet.GetCellSet().Cast>(); - const auto coordsArray = dataSet.GetCoordinateSystem().GetData(); + const auto coordsArray = dataSet.GetCoordinateSystem().GetDataAsMultiplexer(); const auto conn = cellSet.GetConnectivityArray(vtkm::TopologyElementTagCell{}, vtkm::TopologyElementTagPoint{}); const auto offsets = diff --git a/vtkm/worklet/testing/UnitTestVertexClustering.cxx b/vtkm/worklet/testing/UnitTestVertexClustering.cxx index 7f079b6b9..140f43c60 100644 --- a/vtkm/worklet/testing/UnitTestVertexClustering.cxx +++ b/vtkm/worklet/testing/UnitTestVertexClustering.cxx @@ -69,7 +69,7 @@ void TestVertexClustering() auto pointArray = outDataSet.GetCoordinateSystem(0).GetData(); std::cerr << "output_points = " << pointArray.GetNumberOfValues() << "\n"; std::cerr << "output_point[] = "; - vtkm::cont::printSummary_ArrayHandle(pointArray, std::cerr, true); + pointArray.PrintSummary(std::cerr); } vtkm::cont::printSummary_ArrayHandle(pointvar, std::cerr, true); @@ -78,7 +78,7 @@ void TestVertexClustering() VTKM_TEST_ASSERT(outDataSet.GetNumberOfCoordinateSystems() == 1, "Number of output coordinate systems mismatch"); using PointType = vtkm::Vec3f_64; - auto pointArray = outDataSet.GetCoordinateSystem(0).GetData(); + auto pointArray = outDataSet.GetCoordinateSystem(0).GetDataAsMultiplexer(); VTKM_TEST_ASSERT(pointArray.GetNumberOfValues() == output_points, "Number of output points mismatch"); for (vtkm::Id i = 0; i < pointArray.GetNumberOfValues(); ++i) diff --git a/vtkm/worklet/testing/UnitTestWarpScalar.cxx b/vtkm/worklet/testing/UnitTestWarpScalar.cxx index e6f39e85a..e6f4260b2 100644 --- a/vtkm/worklet/testing/UnitTestWarpScalar.cxx +++ b/vtkm/worklet/testing/UnitTestWarpScalar.cxx @@ -60,7 +60,7 @@ void TestWarpScalar() vecType normal = vtkm::make_Vec(static_cast(0.0), static_cast(0.0), static_cast(1.0)); - auto coordinate = ds.GetCoordinateSystem().GetData(); + auto coordinate = ds.GetCoordinateSystem().GetDataAsMultiplexer(); vtkm::Id nov = coordinate.GetNumberOfValues(); vtkm::cont::ArrayHandleConstant normalAH = vtkm::cont::make_ArrayHandleConstant(normal, nov); @@ -70,7 +70,8 @@ void TestWarpScalar() scaleFactor.CopyTo(scaleFactorArray); vtkm::worklet::WarpScalar warpWorklet; - warpWorklet.Run(ds.GetCoordinateSystem(), normalAH, scaleFactor, scaleAmount, result); + warpWorklet.Run( + ds.GetCoordinateSystem().GetDataAsMultiplexer(), normalAH, scaleFactor, scaleAmount, result); auto sFAPortal = scaleFactorArray.ReadPortal(); auto resultPortal = result.ReadPortal(); diff --git a/vtkm/worklet/testing/UnitTestWarpVector.cxx b/vtkm/worklet/testing/UnitTestWarpVector.cxx index 787a30252..fa10aa4c6 100644 --- a/vtkm/worklet/testing/UnitTestWarpVector.cxx +++ b/vtkm/worklet/testing/UnitTestWarpVector.cxx @@ -73,7 +73,7 @@ void TestWarpVector() vecType vector = vtkm::make_Vec(static_cast(0.0), static_cast(0.0), static_cast(2.0)); - auto coordinate = ds.GetCoordinateSystem().GetData(); + auto coordinate = ds.GetCoordinateSystem().GetDataAsMultiplexer(); vtkm::Id nov = coordinate.GetNumberOfValues(); vtkm::cont::ArrayHandleConstant vectorAH = vtkm::cont::make_ArrayHandleConstant(vector, nov);