2016-08-17 18:23:53 +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.
|
|
|
|
//
|
2017-09-20 21:33:44 +00:00
|
|
|
// Copyright 2014 National Technology & Engineering Solutions of Sandia, LLC (NTESS).
|
2016-08-17 18:23:53 +00:00
|
|
|
// Copyright 2014 UT-Battelle, LLC.
|
|
|
|
// Copyright 2014 Los Alamos National Security.
|
|
|
|
//
|
2017-09-20 21:33:44 +00:00
|
|
|
// Under the terms of Contract DE-NA0003525 with NTESS,
|
2016-08-17 18:23:53 +00:00
|
|
|
// 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_ArrayHandleStreaming_h
|
|
|
|
#define vtk_m_cont_ArrayHandleStreaming_h
|
|
|
|
|
2016-08-03 21:34:43 +00:00
|
|
|
#include <vtkm/cont/ArrayHandle.h>
|
|
|
|
#include <vtkm/cont/ArrayPortal.h>
|
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
namespace vtkm
|
|
|
|
{
|
|
|
|
namespace cont
|
|
|
|
{
|
|
|
|
namespace internal
|
|
|
|
{
|
2016-08-03 21:34:43 +00:00
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
template <typename P>
|
2016-12-19 19:39:17 +00:00
|
|
|
class VTKM_ALWAYS_EXPORT ArrayPortalStreaming
|
2016-08-03 21:34:43 +00:00
|
|
|
{
|
|
|
|
public:
|
2017-06-23 18:50:34 +00:00
|
|
|
using PortalType = P;
|
|
|
|
using ValueType = typename PortalType::ValueType;
|
2016-08-03 21:34:43 +00:00
|
|
|
|
2016-11-15 07:12:20 +00:00
|
|
|
VTKM_CONT
|
2017-05-18 14:29:41 +00:00
|
|
|
ArrayPortalStreaming()
|
|
|
|
: InputPortal()
|
|
|
|
, BlockIndex(0)
|
|
|
|
, BlockSize(0)
|
|
|
|
, CurBlockSize(0)
|
|
|
|
{
|
|
|
|
}
|
2016-08-03 21:34:43 +00:00
|
|
|
|
2016-11-15 07:12:20 +00:00
|
|
|
VTKM_CONT
|
2017-05-26 17:53:28 +00:00
|
|
|
ArrayPortalStreaming(const PortalType& inputPortal,
|
|
|
|
vtkm::Id blockIndex,
|
|
|
|
vtkm::Id blockSize,
|
2017-05-18 14:29:41 +00:00
|
|
|
vtkm::Id curBlockSize)
|
|
|
|
: InputPortal(inputPortal)
|
|
|
|
, BlockIndex(blockIndex)
|
|
|
|
, BlockSize(blockSize)
|
|
|
|
, CurBlockSize(curBlockSize)
|
|
|
|
{
|
|
|
|
}
|
2016-08-03 21:34:43 +00:00
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
template <typename OtherP>
|
|
|
|
VTKM_CONT ArrayPortalStreaming(const ArrayPortalStreaming<OtherP>& src)
|
|
|
|
: InputPortal(src.GetPortal())
|
|
|
|
, BlockIndex(src.GetBlockIndex())
|
|
|
|
, BlockSize(src.GetBlockSize())
|
|
|
|
, CurBlockSize(src.GetCurBlockSize())
|
|
|
|
{
|
|
|
|
}
|
2016-08-03 21:34:43 +00:00
|
|
|
|
2016-11-15 07:12:20 +00:00
|
|
|
VTKM_CONT
|
2017-05-18 14:29:41 +00:00
|
|
|
vtkm::Id GetNumberOfValues() const { return this->CurBlockSize; }
|
2016-08-03 21:34:43 +00:00
|
|
|
|
2016-11-15 07:12:20 +00:00
|
|
|
VTKM_CONT
|
2017-05-18 14:29:41 +00:00
|
|
|
ValueType Get(vtkm::Id index) const
|
|
|
|
{
|
|
|
|
return this->InputPortal.Get(this->BlockIndex * this->BlockSize + index);
|
2016-08-03 21:34:43 +00:00
|
|
|
}
|
|
|
|
|
2016-11-15 07:12:20 +00:00
|
|
|
VTKM_CONT
|
2017-05-18 14:29:41 +00:00
|
|
|
void Set(vtkm::Id index, const ValueType& value) const
|
|
|
|
{
|
|
|
|
this->InputPortal.Set(this->BlockIndex * this->BlockSize + index, value);
|
2016-08-03 21:34:43 +00:00
|
|
|
}
|
|
|
|
|
2016-11-15 07:12:20 +00:00
|
|
|
VTKM_CONT
|
2017-05-18 14:29:41 +00:00
|
|
|
const PortalType& GetPortal() const { return this->InputPortal; }
|
2016-08-03 21:34:43 +00:00
|
|
|
|
2016-11-15 07:12:20 +00:00
|
|
|
VTKM_CONT
|
|
|
|
void SetBlockSize(vtkm::Id blockSize) { this->BlockSize = blockSize; }
|
2016-08-03 21:34:43 +00:00
|
|
|
|
2016-11-15 07:12:20 +00:00
|
|
|
VTKM_CONT
|
|
|
|
void SetBlockIndex(vtkm::Id blockIndex) { this->BlockIndex = blockIndex; }
|
2016-08-03 21:34:43 +00:00
|
|
|
|
2016-11-15 07:12:20 +00:00
|
|
|
VTKM_CONT
|
|
|
|
void SetCurBlockSize(vtkm::Id curBlockSize) { this->CurBlockSize = curBlockSize; }
|
2016-08-03 21:34:43 +00:00
|
|
|
|
2016-11-15 07:12:20 +00:00
|
|
|
VTKM_CONT
|
2016-08-03 21:34:43 +00:00
|
|
|
vtkm::Id GetBlockSize() { return this->BlockSize; }
|
|
|
|
|
2016-11-15 07:12:20 +00:00
|
|
|
VTKM_CONT
|
2016-08-03 21:34:43 +00:00
|
|
|
vtkm::Id GetBlockIndex() { return this->BlockIndex; }
|
|
|
|
|
2016-11-15 07:12:20 +00:00
|
|
|
VTKM_CONT
|
2016-08-03 21:34:43 +00:00
|
|
|
vtkm::Id GetCurBlockSize() { return this->CurBlockSize; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
PortalType InputPortal;
|
|
|
|
vtkm::Id BlockIndex;
|
2016-08-19 19:47:44 +00:00
|
|
|
vtkm::Id BlockSize;
|
2016-08-03 21:34:43 +00:00
|
|
|
vtkm::Id CurBlockSize;
|
|
|
|
};
|
|
|
|
|
2016-09-23 16:12:37 +00:00
|
|
|
} // internal
|
2016-08-03 21:34:43 +00:00
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
template <typename ArrayHandleInputType>
|
|
|
|
struct VTKM_ALWAYS_EXPORT StorageTagStreaming
|
|
|
|
{
|
|
|
|
};
|
2016-08-03 21:34:43 +00:00
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
namespace internal
|
|
|
|
{
|
2016-08-03 21:34:43 +00:00
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
template <typename ArrayHandleInputType>
|
|
|
|
class Storage<typename ArrayHandleInputType::ValueType, StorageTagStreaming<ArrayHandleInputType>>
|
2016-08-03 21:34:43 +00:00
|
|
|
{
|
|
|
|
public:
|
2017-06-23 18:50:34 +00:00
|
|
|
using ValueType = typename ArrayHandleInputType::ValueType;
|
2016-08-03 21:34:43 +00:00
|
|
|
|
2017-06-23 18:50:34 +00:00
|
|
|
using PortalType =
|
|
|
|
vtkm::cont::internal::ArrayPortalStreaming<typename ArrayHandleInputType::PortalControl>;
|
|
|
|
using PortalConstType =
|
|
|
|
vtkm::cont::internal::ArrayPortalStreaming<typename ArrayHandleInputType::PortalConstControl>;
|
2016-08-03 21:34:43 +00:00
|
|
|
|
2016-10-19 22:42:58 +00:00
|
|
|
VTKM_CONT
|
2017-05-18 14:29:41 +00:00
|
|
|
Storage()
|
|
|
|
: Valid(false)
|
|
|
|
{
|
|
|
|
}
|
2016-08-03 21:34:43 +00:00
|
|
|
|
2016-10-19 22:42:58 +00:00
|
|
|
VTKM_CONT
|
2017-05-26 17:53:28 +00:00
|
|
|
Storage(const ArrayHandleInputType inputArray,
|
|
|
|
vtkm::Id blockSize,
|
|
|
|
vtkm::Id blockIndex,
|
2017-05-18 14:29:41 +00:00
|
|
|
vtkm::Id curBlockSize)
|
|
|
|
: InputArray(inputArray)
|
|
|
|
, BlockSize(blockSize)
|
|
|
|
, BlockIndex(blockIndex)
|
|
|
|
, CurBlockSize(curBlockSize)
|
|
|
|
, Valid(true)
|
|
|
|
{
|
|
|
|
}
|
2016-08-03 21:34:43 +00:00
|
|
|
|
2016-10-19 22:42:58 +00:00
|
|
|
VTKM_CONT
|
2017-05-18 14:29:41 +00:00
|
|
|
PortalType GetPortal()
|
|
|
|
{
|
2016-08-03 21:34:43 +00:00
|
|
|
VTKM_ASSERT(this->Valid);
|
2017-05-18 14:29:41 +00:00
|
|
|
return PortalType(this->InputArray.GetPortalControl(), BlockSize, BlockIndex, CurBlockSize);
|
2016-08-03 21:34:43 +00:00
|
|
|
}
|
|
|
|
|
2016-10-19 22:42:58 +00:00
|
|
|
VTKM_CONT
|
2017-05-18 14:29:41 +00:00
|
|
|
PortalConstType GetPortalConst() const
|
|
|
|
{
|
2016-08-03 21:34:43 +00:00
|
|
|
VTKM_ASSERT(this->Valid);
|
2017-05-26 17:53:28 +00:00
|
|
|
return PortalConstType(
|
|
|
|
this->InputArray.GetPortalConstControl(), BlockSize, BlockIndex, CurBlockSize);
|
2016-08-03 21:34:43 +00:00
|
|
|
}
|
|
|
|
|
2016-10-19 22:42:58 +00:00
|
|
|
VTKM_CONT
|
2017-05-18 14:29:41 +00:00
|
|
|
vtkm::Id GetNumberOfValues() const
|
|
|
|
{
|
2016-08-03 21:34:43 +00:00
|
|
|
VTKM_ASSERT(this->Valid);
|
2016-12-16 22:04:58 +00:00
|
|
|
return CurBlockSize;
|
2016-08-03 21:34:43 +00:00
|
|
|
}
|
|
|
|
|
2016-10-19 22:42:58 +00:00
|
|
|
VTKM_CONT
|
2017-05-18 14:29:41 +00:00
|
|
|
void Allocate(vtkm::Id numberOfValues) const
|
|
|
|
{
|
2016-08-19 19:47:44 +00:00
|
|
|
(void)numberOfValues;
|
2016-08-03 21:34:43 +00:00
|
|
|
// Do nothing, since we only allocate a streaming array once at the beginning
|
|
|
|
}
|
|
|
|
|
2016-10-19 22:42:58 +00:00
|
|
|
VTKM_CONT
|
2017-05-18 14:29:41 +00:00
|
|
|
void AllocateFullArray(vtkm::Id numberOfValues)
|
|
|
|
{
|
2016-08-03 21:34:43 +00:00
|
|
|
VTKM_ASSERT(this->Valid);
|
|
|
|
this->InputArray.Allocate(numberOfValues);
|
|
|
|
}
|
|
|
|
|
2016-10-19 22:42:58 +00:00
|
|
|
VTKM_CONT
|
2017-05-18 14:29:41 +00:00
|
|
|
void Shrink(vtkm::Id numberOfValues)
|
|
|
|
{
|
2016-08-03 21:34:43 +00:00
|
|
|
VTKM_ASSERT(this->Valid);
|
|
|
|
this->InputArray.Shrink(numberOfValues);
|
|
|
|
}
|
|
|
|
|
2016-10-19 22:42:58 +00:00
|
|
|
VTKM_CONT
|
2017-05-18 14:29:41 +00:00
|
|
|
void ReleaseResources()
|
|
|
|
{
|
2016-08-03 21:34:43 +00:00
|
|
|
VTKM_ASSERT(this->Valid);
|
|
|
|
this->InputArray.ReleaseResources();
|
|
|
|
}
|
|
|
|
|
2016-10-19 22:42:58 +00:00
|
|
|
VTKM_CONT
|
2017-05-18 14:29:41 +00:00
|
|
|
const ArrayHandleInputType& GetArray() const
|
|
|
|
{
|
2016-08-03 21:34:43 +00:00
|
|
|
VTKM_ASSERT(this->Valid);
|
|
|
|
return this->InputArray;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
ArrayHandleInputType InputArray;
|
|
|
|
vtkm::Id BlockSize;
|
|
|
|
vtkm::Id BlockIndex;
|
|
|
|
vtkm::Id CurBlockSize;
|
2016-08-19 19:47:44 +00:00
|
|
|
bool Valid;
|
2016-08-03 21:34:43 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
namespace vtkm
|
|
|
|
{
|
|
|
|
namespace cont
|
|
|
|
{
|
2016-08-03 21:34:43 +00:00
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
template <typename ArrayHandleInputType>
|
2016-08-03 21:34:43 +00:00
|
|
|
class ArrayHandleStreaming
|
2017-05-18 14:29:41 +00:00
|
|
|
: public vtkm::cont::ArrayHandle<typename ArrayHandleInputType::ValueType,
|
|
|
|
StorageTagStreaming<ArrayHandleInputType>>
|
2016-08-03 21:34:43 +00:00
|
|
|
{
|
|
|
|
public:
|
2017-05-26 17:53:28 +00:00
|
|
|
VTKM_ARRAY_HANDLE_SUBCLASS(ArrayHandleStreaming,
|
|
|
|
(ArrayHandleStreaming<ArrayHandleInputType>),
|
2017-05-18 14:29:41 +00:00
|
|
|
(vtkm::cont::ArrayHandle<typename ArrayHandleInputType::ValueType,
|
|
|
|
StorageTagStreaming<ArrayHandleInputType>>));
|
2016-08-03 21:34:43 +00:00
|
|
|
|
|
|
|
private:
|
2017-08-16 15:34:21 +00:00
|
|
|
using StorageType = vtkm::cont::internal::Storage<ValueType, StorageTag>;
|
2016-08-03 21:34:43 +00:00
|
|
|
|
|
|
|
public:
|
2016-10-19 22:42:58 +00:00
|
|
|
VTKM_CONT
|
2017-05-26 17:53:28 +00:00
|
|
|
ArrayHandleStreaming(const ArrayHandleInputType& inputArray,
|
|
|
|
const vtkm::Id blockIndex,
|
|
|
|
const vtkm::Id blockSize,
|
|
|
|
const vtkm::Id curBlockSize)
|
2017-05-18 14:29:41 +00:00
|
|
|
: Superclass(StorageType(inputArray, blockIndex, blockSize, curBlockSize))
|
2016-12-16 22:04:58 +00:00
|
|
|
{
|
2016-08-03 21:34:43 +00:00
|
|
|
this->GetPortalConstControl().SetBlockIndex(blockIndex);
|
|
|
|
this->GetPortalConstControl().SetBlockSize(blockSize);
|
|
|
|
this->GetPortalConstControl().SetCurBlockSize(curBlockSize);
|
|
|
|
}
|
|
|
|
|
2016-10-19 22:42:58 +00:00
|
|
|
VTKM_CONT
|
2017-05-18 14:29:41 +00:00
|
|
|
void AllocateFullArray(vtkm::Id numberOfValues)
|
|
|
|
{
|
2016-08-03 21:34:43 +00:00
|
|
|
this->ReleaseResourcesExecutionInternal();
|
|
|
|
this->Internals->ControlArray.AllocateFullArray(numberOfValues);
|
|
|
|
this->Internals->ControlArrayValid = true;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
2016-08-17 18:23:53 +00:00
|
|
|
|
|
|
|
#endif //vtk_m_cont_ArrayHandleStreaming_h
|