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_testing_TestingArrayHandleVirtualCoordinates_h
|
|
|
|
#define vtk_m_cont_testing_TestingArrayHandleVirtualCoordinates_h
|
|
|
|
|
|
|
|
#include <vtkm/cont/ArrayHandleCartesianProduct.h>
|
|
|
|
#include <vtkm/cont/ArrayHandleUniformPointCoordinates.h>
|
|
|
|
#include <vtkm/cont/ArrayHandleVirtualCoordinates.h>
|
|
|
|
#include <vtkm/cont/testing/Testing.h>
|
|
|
|
#include <vtkm/worklet/DispatcherMapField.h>
|
|
|
|
#include <vtkm/worklet/WorkletMapField.h>
|
|
|
|
|
|
|
|
namespace vtkm
|
|
|
|
{
|
|
|
|
namespace cont
|
|
|
|
{
|
|
|
|
namespace testing
|
|
|
|
{
|
|
|
|
|
|
|
|
namespace
|
|
|
|
{
|
|
|
|
|
|
|
|
struct CopyWorklet : public vtkm::worklet::WorkletMapField
|
|
|
|
{
|
|
|
|
typedef void ControlSignature(FieldIn<FieldCommon> in, FieldOut<FieldCommon> out);
|
|
|
|
typedef _2 ExecutionSignature(_1);
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
VTKM_EXEC T operator()(const T& in) const
|
|
|
|
{
|
|
|
|
return in;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-05-01 20:19:22 +00:00
|
|
|
template <typename T, typename S, typename DeviceAdapter>
|
|
|
|
inline void TestVirtualAccess(const vtkm::cont::ArrayHandle<T, S>& in,
|
|
|
|
vtkm::cont::ArrayHandle<T>& out,
|
|
|
|
DeviceAdapter)
|
|
|
|
{
|
|
|
|
vtkm::worklet::DispatcherMapField<CopyWorklet, DeviceAdapter>().Invoke(
|
|
|
|
vtkm::cont::ArrayHandleVirtualCoordinates(in), vtkm::cont::ArrayHandleVirtualCoordinates(out));
|
|
|
|
|
|
|
|
VTKM_TEST_ASSERT(test_equal_portals(in.GetPortalConstControl(), out.GetPortalConstControl()),
|
|
|
|
"Input and output portals don't match");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-12 15:15:20 +00:00
|
|
|
} // anonymous namespace
|
|
|
|
|
|
|
|
template <typename DeviceAdapter>
|
|
|
|
class TestingArrayHandleVirtualCoordinates
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
using ArrayHandleRectilinearCoords =
|
|
|
|
vtkm::cont::ArrayHandleCartesianProduct<vtkm::cont::ArrayHandle<vtkm::FloatDefault>,
|
|
|
|
vtkm::cont::ArrayHandle<vtkm::FloatDefault>,
|
|
|
|
vtkm::cont::ArrayHandle<vtkm::FloatDefault>>;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void TestAll()
|
|
|
|
{
|
|
|
|
using PointType = vtkm::Vec<vtkm::FloatDefault, 3>;
|
2018-02-27 14:25:25 +00:00
|
|
|
static constexpr vtkm::Id length = 64;
|
2017-12-12 15:15:20 +00:00
|
|
|
|
|
|
|
vtkm::cont::ArrayHandle<PointType> out;
|
|
|
|
|
|
|
|
std::cout << "Testing basic ArrayHandle as input\n";
|
|
|
|
vtkm::cont::ArrayHandle<PointType> a1;
|
|
|
|
a1.Allocate(length);
|
|
|
|
for (vtkm::Id i = 0; i < length; ++i)
|
|
|
|
{
|
|
|
|
a1.GetPortalControl().Set(i, TestValue(i, PointType()));
|
|
|
|
}
|
2018-05-01 20:19:22 +00:00
|
|
|
TestVirtualAccess(a1, out, DeviceAdapter{});
|
2017-12-12 15:15:20 +00:00
|
|
|
|
|
|
|
std::cout << "Testing ArrayHandleUniformPointCoordinates as input\n";
|
2018-05-01 20:19:22 +00:00
|
|
|
auto t = vtkm::cont::ArrayHandleUniformPointCoordinates(vtkm::Id3(4, 4, 4));
|
|
|
|
TestVirtualAccess(t, out, DeviceAdapter{});
|
2017-12-12 15:15:20 +00:00
|
|
|
|
|
|
|
std::cout << "Testing ArrayHandleCartesianProduct as input\n";
|
|
|
|
vtkm::cont::ArrayHandle<vtkm::FloatDefault> c1, c2, c3;
|
|
|
|
c1.Allocate(length);
|
|
|
|
c2.Allocate(length);
|
|
|
|
c3.Allocate(length);
|
|
|
|
for (vtkm::Id i = 0; i < length; ++i)
|
|
|
|
{
|
|
|
|
auto p = a1.GetPortalConstControl().Get(i);
|
|
|
|
c1.GetPortalControl().Set(i, p[0]);
|
|
|
|
c2.GetPortalControl().Set(i, p[1]);
|
|
|
|
c3.GetPortalControl().Set(i, p[2]);
|
|
|
|
}
|
2018-05-01 20:19:22 +00:00
|
|
|
TestVirtualAccess(
|
|
|
|
vtkm::cont::make_ArrayHandleCartesianProduct(c1, c2, c3), out, DeviceAdapter{});
|
2017-12-12 15:15:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public:
|
|
|
|
static int Run() { return vtkm::cont::testing::Testing::Run(TestAll); }
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} // vtkm::cont::testing
|
|
|
|
|
|
|
|
|
|
|
|
#endif // vtk_m_cont_testing_TestingArrayHandleVirtualCoordinates_h
|