2017-12-12 15:15:20 +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 2014 National Technology & Engineering Solutions of Sandia, LLC (NTESS).
|
|
|
|
// Copyright 2014 UT-Battelle, LLC.
|
|
|
|
// Copyright 2014 Los Alamos National Security.
|
|
|
|
//
|
|
|
|
// Under the terms of Contract DE-NA0003525 with NTESS,
|
|
|
|
// 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_ArrayHandleVirtualCoordinates_h
|
|
|
|
#define vtk_m_cont_ArrayHandleVirtualCoordinates_h
|
|
|
|
|
2018-11-06 16:40:39 +00:00
|
|
|
#include <vtkm/cont/ArrayHandleAny.h>
|
|
|
|
#include <vtkm/cont/ArrayHandleVirtual.h>
|
|
|
|
|
2018-06-08 15:56:40 +00:00
|
|
|
#include <vtkm/cont/ArrayHandleCartesianProduct.h>
|
2018-11-06 16:40:39 +00:00
|
|
|
#include <vtkm/cont/ArrayHandleCast.h>
|
2017-12-12 15:15:20 +00:00
|
|
|
#include <vtkm/cont/ArrayHandleUniformPointCoordinates.h>
|
2018-11-06 16:40:39 +00:00
|
|
|
|
2018-07-18 13:11:10 +00:00
|
|
|
#include <vtkm/cont/ErrorBadType.h>
|
2018-08-30 17:29:36 +00:00
|
|
|
#include <vtkm/cont/Logging.h>
|
2018-08-08 18:53:28 +00:00
|
|
|
#include <vtkm/cont/TryExecute.h>
|
2017-12-12 15:15:20 +00:00
|
|
|
|
|
|
|
#include <memory>
|
|
|
|
#include <type_traits>
|
|
|
|
|
|
|
|
namespace vtkm
|
|
|
|
{
|
|
|
|
namespace cont
|
|
|
|
{
|
|
|
|
|
2018-11-06 16:40:39 +00:00
|
|
|
/// ArrayHandleVirtualCoordinates is a specialization of ArrayHandle.
|
|
|
|
class VTKM_CONT_EXPORT ArrayHandleVirtualCoordinates final
|
|
|
|
: public vtkm::cont::ArrayHandleVirtual<vtkm::Vec<vtkm::FloatDefault, 3>>
|
2017-12-12 15:15:20 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
using ValueType = vtkm::Vec<vtkm::FloatDefault, 3>;
|
2018-11-06 16:40:39 +00:00
|
|
|
using StorageTag = vtkm::cont::StorageTagVirtual;
|
2017-12-12 15:15:20 +00:00
|
|
|
|
2018-11-06 16:40:39 +00:00
|
|
|
using NonDefaultCoord = typename std::conditional<std::is_same<vtkm::FloatDefault, float>::value,
|
|
|
|
vtkm::Vec<double, 3>,
|
|
|
|
vtkm::Vec<float, 3>>::type;
|
2017-12-12 15:15:20 +00:00
|
|
|
|
2018-11-06 16:40:39 +00:00
|
|
|
ArrayHandleVirtualCoordinates()
|
|
|
|
: vtkm::cont::ArrayHandleVirtual<ValueType>()
|
2017-12-12 15:15:20 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
explicit ArrayHandleVirtualCoordinates(
|
2018-11-06 16:40:39 +00:00
|
|
|
const vtkm::cont::ArrayHandle<ValueType, vtkm::cont::StorageTagVirtual>& ah)
|
|
|
|
: vtkm::cont::ArrayHandleVirtual<ValueType>(ah)
|
2017-12-12 15:15:20 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2018-11-06 16:40:39 +00:00
|
|
|
template <typename S>
|
|
|
|
explicit ArrayHandleVirtualCoordinates(const vtkm::cont::ArrayHandle<ValueType, S>& ah)
|
|
|
|
: vtkm::cont::ArrayHandleVirtual<ValueType>(
|
|
|
|
std::make_shared<vtkm::cont::StorageAny<ValueType, S>>(ah))
|
2017-12-12 15:15:20 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2018-11-06 16:40:39 +00:00
|
|
|
template <typename S>
|
|
|
|
explicit ArrayHandleVirtualCoordinates(const vtkm::cont::ArrayHandle<NonDefaultCoord, S>& ah)
|
|
|
|
: vtkm::cont::ArrayHandleVirtual<ValueType>()
|
2017-12-12 15:15:20 +00:00
|
|
|
{
|
2018-11-06 16:40:39 +00:00
|
|
|
auto castedHandle = vtkm::cont::make_ArrayHandleCast<ValueType>(ah);
|
|
|
|
using ST = typename decltype(castedHandle)::StorageTag;
|
|
|
|
this->Storage = std::make_shared<vtkm::cont::StorageAny<ValueType, ST>>(castedHandle);
|
2017-12-12 15:15:20 +00:00
|
|
|
}
|
|
|
|
|
2018-11-06 16:40:39 +00:00
|
|
|
/// Returns this array cast to the given \c ArrayHandle type. Throws \c
|
|
|
|
/// ErrorBadType if the cast does not work. Use \c IsType
|
|
|
|
/// to check if the cast can happen.
|
|
|
|
///
|
2017-12-12 15:15:20 +00:00
|
|
|
template <typename ArrayHandleType>
|
2018-11-06 16:40:39 +00:00
|
|
|
VTKM_CONT ArrayHandleType Cast() const
|
2017-12-12 15:15:20 +00:00
|
|
|
{
|
2018-11-06 16:40:39 +00:00
|
|
|
using T = typename ArrayHandleType::ValueType;
|
|
|
|
using S = typename ArrayHandleType::StorageTag;
|
|
|
|
const vtkm::cont::StorageVirtual* storage = this->GetStorage();
|
|
|
|
const auto* any = storage->Cast<vtkm::cont::StorageAny<T, S>>();
|
|
|
|
return any->GetHandle();
|
2017-12-12 15:15:20 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
template <typename Functor, typename... Args>
|
|
|
|
void CastAndCall(const vtkm::cont::ArrayHandleVirtualCoordinates& coords,
|
|
|
|
Functor&& f,
|
|
|
|
Args&&... args)
|
|
|
|
{
|
2018-11-06 16:40:39 +00:00
|
|
|
using HandleType = ArrayHandleUniformPointCoordinates;
|
|
|
|
if (coords.IsType<HandleType>())
|
2017-12-12 15:15:20 +00:00
|
|
|
{
|
2018-11-06 16:40:39 +00:00
|
|
|
HandleType uniform = coords.Cast<HandleType>();
|
|
|
|
f(uniform, std::forward<Args>(args)...);
|
2017-12-12 15:15:20 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
f(coords, std::forward<Args>(args)...);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-06-08 15:56:40 +00:00
|
|
|
|
|
|
|
template <>
|
|
|
|
struct TypeString<vtkm::cont::ArrayHandleVirtualCoordinates>
|
|
|
|
{
|
|
|
|
static VTKM_CONT const std::string Get() { return "AH_VirtualCoordinates"; }
|
|
|
|
};
|
|
|
|
}
|
|
|
|
} // vtkm::cont
|
|
|
|
|
|
|
|
namespace diy
|
|
|
|
{
|
|
|
|
|
|
|
|
template <>
|
|
|
|
struct Serialization<vtkm::cont::ArrayHandleVirtualCoordinates>
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
using Type = vtkm::cont::ArrayHandleVirtualCoordinates;
|
|
|
|
using BaseType = vtkm::cont::ArrayHandle<typename Type::ValueType, typename Type::StorageTag>;
|
|
|
|
|
|
|
|
using BasicCoordsType = vtkm::cont::ArrayHandle<vtkm::Vec<vtkm::FloatDefault, 3>>;
|
|
|
|
using RectilinearCoordsArrayType =
|
|
|
|
vtkm::cont::ArrayHandleCartesianProduct<vtkm::cont::ArrayHandle<vtkm::FloatDefault>,
|
|
|
|
vtkm::cont::ArrayHandle<vtkm::FloatDefault>,
|
|
|
|
vtkm::cont::ArrayHandle<vtkm::FloatDefault>>;
|
|
|
|
|
|
|
|
public:
|
|
|
|
static VTKM_CONT void save(BinaryBuffer& bb, const BaseType& obj)
|
|
|
|
{
|
|
|
|
const auto& virtArray = static_cast<const vtkm::cont::ArrayHandleVirtualCoordinates&>(obj);
|
2018-11-06 16:40:39 +00:00
|
|
|
const vtkm::cont::StorageVirtual* storage = virtArray.GetStorage();
|
2018-06-08 15:56:40 +00:00
|
|
|
if (virtArray.IsType<vtkm::cont::ArrayHandleUniformPointCoordinates>())
|
|
|
|
{
|
2018-11-06 16:40:39 +00:00
|
|
|
using HandleType = vtkm::cont::ArrayHandleUniformPointCoordinates;
|
|
|
|
using T = typename HandleType::ValueType;
|
|
|
|
using S = typename HandleType::StorageTag;
|
|
|
|
auto array = storage->Cast<vtkm::cont::StorageAny<T, S>>();
|
|
|
|
diy::save(bb, vtkm::cont::TypeString<HandleType>::Get());
|
2018-06-08 15:56:40 +00:00
|
|
|
diy::save(bb, array);
|
|
|
|
}
|
|
|
|
else if (virtArray.IsType<RectilinearCoordsArrayType>())
|
|
|
|
{
|
2018-11-06 16:40:39 +00:00
|
|
|
using HandleType = RectilinearCoordsArrayType;
|
|
|
|
using T = typename HandleType::ValueType;
|
|
|
|
using S = typename HandleType::StorageTag;
|
|
|
|
auto array = storage->Cast<vtkm::cont::StorageAny<T, S>>();
|
|
|
|
diy::save(bb, vtkm::cont::TypeString<HandleType>::Get());
|
2018-06-08 15:56:40 +00:00
|
|
|
diy::save(bb, array);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
diy::save(bb, vtkm::cont::TypeString<BasicCoordsType>::Get());
|
|
|
|
vtkm::cont::internal::ArrayHandleDefaultSerialization(bb, virtArray);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static VTKM_CONT void load(BinaryBuffer& bb, BaseType& obj)
|
|
|
|
{
|
|
|
|
std::string typeString;
|
|
|
|
diy::load(bb, typeString);
|
|
|
|
|
|
|
|
if (typeString == vtkm::cont::TypeString<vtkm::cont::ArrayHandleUniformPointCoordinates>::Get())
|
|
|
|
{
|
|
|
|
vtkm::cont::ArrayHandleUniformPointCoordinates array;
|
|
|
|
diy::load(bb, array);
|
|
|
|
obj = vtkm::cont::ArrayHandleVirtualCoordinates(array);
|
|
|
|
}
|
|
|
|
else if (typeString == vtkm::cont::TypeString<RectilinearCoordsArrayType>::Get())
|
|
|
|
{
|
|
|
|
RectilinearCoordsArrayType array;
|
|
|
|
diy::load(bb, array);
|
|
|
|
obj = vtkm::cont::ArrayHandleVirtualCoordinates(array);
|
|
|
|
}
|
|
|
|
else if (typeString == vtkm::cont::TypeString<BasicCoordsType>::Get())
|
|
|
|
{
|
|
|
|
BasicCoordsType array;
|
|
|
|
diy::load(bb, array);
|
|
|
|
obj = vtkm::cont::ArrayHandleVirtualCoordinates(array);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
throw vtkm::cont::ErrorBadType(
|
|
|
|
"Error deserializing ArrayHandleVirtualCoordinates. TypeString: " + typeString);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
} // diy
|
|
|
|
|
2017-12-12 15:15:20 +00:00
|
|
|
#endif // vtk_m_cont_ArrayHandleVirtualCoordinates_h
|