2015-02-13 06:24:43 +00:00
|
|
|
//=============================================================================
|
|
|
|
//
|
|
|
|
// 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.
|
|
|
|
//
|
|
|
|
// Copyright 2015 Sandia Corporation.
|
|
|
|
// Copyright 2015 UT-Battelle, LLC.
|
2015-05-21 12:09:22 +00:00
|
|
|
// Copyright 2015 Los Alamos National Security.
|
2015-02-13 06:24:43 +00:00
|
|
|
//
|
|
|
|
// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
|
|
|
|
// the U.S. Government retains certain rights in this software.
|
|
|
|
// Under the terms of Contract DE-AC52-06NA25396 with Los Alamos National
|
|
|
|
// Laboratory (LANL), the U.S. Government retains certain rights in
|
|
|
|
// this software.
|
|
|
|
//
|
|
|
|
//=============================================================================
|
|
|
|
#ifndef vtk_m_cont_ArrayHandleImplicit_h
|
|
|
|
#define vtk_m_cont_ArrayHandleImplicit_h
|
|
|
|
|
|
|
|
#include <vtkm/cont/ArrayHandle.h>
|
|
|
|
#include <vtkm/cont/StorageImplicit.h>
|
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
namespace vtkm
|
|
|
|
{
|
|
|
|
namespace cont
|
|
|
|
{
|
2015-02-13 06:24:43 +00:00
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
namespace detail
|
|
|
|
{
|
2015-02-13 06:24:43 +00:00
|
|
|
/// \brief An array portal that returns the result of a functor
|
|
|
|
///
|
|
|
|
/// This array portal is similar to an implicit array i.e an array that is
|
|
|
|
/// defined functionally rather than actually stored in memory. The array
|
|
|
|
/// comprises a functor that is called for each index.
|
|
|
|
///
|
|
|
|
/// The \c ArrayPortalImplicit is used in an ArrayHandle with an
|
|
|
|
/// \c StorageImplicit container.
|
|
|
|
///
|
2017-05-18 14:29:41 +00:00
|
|
|
template <class ValueType_, class FunctorType_>
|
2016-12-19 19:39:17 +00:00
|
|
|
class VTKM_ALWAYS_EXPORT ArrayPortalImplicit
|
2015-02-13 06:24:43 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
typedef ValueType_ ValueType;
|
|
|
|
typedef FunctorType_ FunctorType;
|
|
|
|
|
2016-10-19 22:42:58 +00:00
|
|
|
VTKM_EXEC_CONT
|
2017-05-18 14:29:41 +00:00
|
|
|
ArrayPortalImplicit()
|
|
|
|
: Functor()
|
|
|
|
, NumberOfValues(0)
|
|
|
|
{
|
|
|
|
}
|
2015-02-13 06:24:43 +00:00
|
|
|
|
2016-10-19 22:42:58 +00:00
|
|
|
VTKM_EXEC_CONT
|
2017-05-18 14:29:41 +00:00
|
|
|
ArrayPortalImplicit(FunctorType f, vtkm::Id numValues)
|
|
|
|
: Functor(f)
|
|
|
|
, NumberOfValues(numValues)
|
|
|
|
{
|
|
|
|
}
|
2015-02-13 06:24:43 +00:00
|
|
|
|
2016-10-19 22:42:58 +00:00
|
|
|
VTKM_EXEC_CONT
|
2015-02-13 06:24:43 +00:00
|
|
|
vtkm::Id GetNumberOfValues() const { return this->NumberOfValues; }
|
|
|
|
|
2017-01-31 19:13:45 +00:00
|
|
|
VTKM_SUPPRESS_EXEC_WARNINGS
|
2016-10-19 22:42:58 +00:00
|
|
|
VTKM_EXEC_CONT
|
2015-02-13 06:24:43 +00:00
|
|
|
ValueType Get(vtkm::Id index) const { return this->Functor(index); }
|
|
|
|
|
2017-01-31 19:13:45 +00:00
|
|
|
VTKM_EXEC_CONT
|
2017-05-18 14:29:41 +00:00
|
|
|
void Set(vtkm::Id vtkmNotUsed(index), const ValueType& vtkmNotUsed(value)) const
|
2017-01-31 19:13:45 +00:00
|
|
|
{
|
2017-02-02 15:04:35 +00:00
|
|
|
#if !(defined(VTKM_MSVC) && defined(VTKM_CUDA))
|
2017-01-31 19:13:45 +00:00
|
|
|
VTKM_ASSERT(false && "Cannot write to read-only implicit array.");
|
2017-02-02 15:04:35 +00:00
|
|
|
#endif
|
2017-01-31 19:13:45 +00:00
|
|
|
}
|
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
typedef vtkm::cont::internal::IteratorFromArrayPortal<ArrayPortalImplicit<ValueType, FunctorType>>
|
|
|
|
IteratorType;
|
2015-07-31 10:58:05 +00:00
|
|
|
|
2016-10-19 22:42:58 +00:00
|
|
|
VTKM_CONT
|
2017-05-18 14:29:41 +00:00
|
|
|
IteratorType GetIteratorBegin() const { return IteratorType(*this); }
|
2015-07-31 10:58:05 +00:00
|
|
|
|
2015-02-13 06:24:43 +00:00
|
|
|
private:
|
|
|
|
FunctorType Functor;
|
|
|
|
vtkm::Id NumberOfValues;
|
|
|
|
};
|
|
|
|
|
|
|
|
/// A convenience class that provides a typedef to the appropriate tag for
|
|
|
|
/// a implicit array container.
|
2017-05-18 14:29:41 +00:00
|
|
|
template <typename ValueType, typename FunctorType>
|
2015-02-13 06:24:43 +00:00
|
|
|
struct ArrayHandleImplicitTraits
|
|
|
|
{
|
|
|
|
typedef vtkm::cont::StorageTagImplicit<
|
2017-05-18 14:29:41 +00:00
|
|
|
vtkm::cont::detail::ArrayPortalImplicit<ValueType, FunctorType>>
|
|
|
|
StorageTag;
|
|
|
|
typedef vtkm::cont::ArrayHandle<ValueType, StorageTag> Superclass;
|
2015-02-13 06:24:43 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace detail
|
|
|
|
|
|
|
|
/// \brief An \c ArrayHandle that computes values on the fly.
|
|
|
|
///
|
|
|
|
/// \c ArrayHandleImplicit is a specialization of ArrayHandle.
|
|
|
|
/// It takes a user defined functor which is called with a given index value.
|
|
|
|
/// The functor returns the result of the functor as the value of this
|
|
|
|
/// array at that position.
|
|
|
|
///
|
2017-05-18 14:29:41 +00:00
|
|
|
template <typename T, class FunctorType>
|
|
|
|
class ArrayHandleImplicit : public detail::ArrayHandleImplicitTraits<T, FunctorType>::Superclass
|
2015-02-13 06:24:43 +00:00
|
|
|
{
|
|
|
|
private:
|
2017-05-18 14:29:41 +00:00
|
|
|
typedef typename detail::ArrayHandleImplicitTraits<T, FunctorType> ArrayTraits;
|
2015-02-13 06:24:43 +00:00
|
|
|
|
2015-07-31 10:58:05 +00:00
|
|
|
public:
|
2017-05-18 14:29:41 +00:00
|
|
|
VTKM_ARRAY_HANDLE_SUBCLASS(ArrayHandleImplicit, (ArrayHandleImplicit<T, FunctorType>),
|
|
|
|
(typename ArrayTraits::Superclass));
|
2015-10-21 13:11:38 +00:00
|
|
|
|
2016-10-19 22:42:58 +00:00
|
|
|
VTKM_CONT
|
2015-02-13 06:24:43 +00:00
|
|
|
ArrayHandleImplicit(FunctorType functor, vtkm::Id length)
|
2017-05-18 14:29:41 +00:00
|
|
|
: Superclass(typename Superclass::PortalConstControl(functor, length))
|
|
|
|
{
|
|
|
|
}
|
2015-02-13 06:24:43 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/// make_ArrayHandleImplicit is convenience function to generate an
|
|
|
|
/// ArrayHandleImplicit. It takes a functor and the virtual length of the
|
|
|
|
/// arry.
|
|
|
|
|
|
|
|
template <typename T, typename FunctorType>
|
2017-05-18 14:29:41 +00:00
|
|
|
VTKM_CONT vtkm::cont::ArrayHandleImplicit<T, FunctorType> make_ArrayHandleImplicit(
|
|
|
|
FunctorType functor, vtkm::Id length)
|
2015-02-13 06:24:43 +00:00
|
|
|
{
|
2017-05-18 14:29:41 +00:00
|
|
|
return ArrayHandleImplicit<T, FunctorType>(functor, length);
|
2015-02-13 06:24:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} // namespace vtkm::cont
|
|
|
|
|
|
|
|
#endif //vtk_m_cont_ArrayHandleImplicit_h
|