vtk-m/vtkm/cont/testing/UnitTestPointCoordinates.cxx
Kenneth Moreland 0cc9d27e26 Expand the list of types to include multiple widths.
Since we want our code to generally handle data of different precision
(for example either float or double) expand the types in our list types
to include multiple precision.
2014-10-08 15:40:20 -06:00

134 lines
4.3 KiB
C++

//============================================================================
// 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 Sandia Corporation.
// Copyright 2014 UT-Battelle, LLC.
// Copyright 2014. Los Alamos National Security
//
// 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.
//============================================================================
// Make sure nothing relies on default storage or device adapter.
#define VTKM_STORAGE VTKM_STORAGE_ERROR
#define VTKM_DEVICE_ADAPTER VTKM_DEVICE_ADAPTER_ERROR
// Make sure nothing relies on default lists.
#define VTKM_DEFAULT_TYPE_LIST_TAG ::vtkm::ListTagEmpty
#define VTKM_DEFAULT_STORAGE_LIST_TAG ::vtkm::ListTagEmpty
#include <vtkm/cont/PointCoordinatesArray.h>
#include <vtkm/cont/PointCoordinatesUniform.h>
#include <vtkm/Extent.h>
#include <vtkm/TypeListTag.h>
#include <vtkm/cont/DeviceAdapterSerial.h>
#include <vtkm/cont/StorageBasic.h>
#include <vtkm/cont/testing/Testing.h>
#include <vector>
namespace {
const vtkm::Extent3 EXTENT = vtkm::Extent3(vtkm::Id3(0,0,0), vtkm::Id3(9,9,9));
const vtkm::Vector3 ORIGIN = vtkm::Vector3(0, 0, 0);
const vtkm::Vector3 SPACING = vtkm::Vector3(1, 1, 1);
const vtkm::Id3 DIMENSION = vtkm::ExtentPointDimensions(EXTENT);
const vtkm::Id ARRAY_SIZE = DIMENSION[0]*DIMENSION[1]*DIMENSION[2];
typedef vtkm::cont::StorageTagBasic StorageTag;
struct StorageListTag : vtkm::cont::StorageListTagBasic { };
vtkm::Vector3 TestValue(vtkm::Id index)
{
vtkm::Id3 index3d = vtkm::ExtentPointFlatIndexToTopologyIndex(index, EXTENT);
return vtkm::Vector3(vtkm::Scalar(index3d[0]),
vtkm::Scalar(index3d[1]),
vtkm::Scalar(index3d[2]));
}
struct CheckArray
{
template<typename ArrayType>
void operator()(const ArrayType &array) const
{
std::cout << " In CastAndCall functor" << std::endl;
typename ArrayType::PortalConstControl portal =
array.GetPortalConstControl();
VTKM_TEST_ASSERT(portal.GetNumberOfValues() == ARRAY_SIZE,
"Array has wrong number of values.");
for (vtkm::Id index = 0; index < ARRAY_SIZE; index++)
{
const vtkm::Vector3 receivedValue = portal.Get(index);
const vtkm::Vector3 expectedValue = TestValue(index);
VTKM_TEST_ASSERT(receivedValue == expectedValue,
"Got bad value in array.");
}
}
};
void TestPointCoordinatesArray()
{
std::cout << "Testing PointCoordinatesArray" << std::endl;
std::cout << " Creating buffer of data values" << std::endl;
std::vector<vtkm::Vector3> buffer(ARRAY_SIZE);
for (vtkm::Id index = 0; index < ARRAY_SIZE; index++)
{
buffer[index] = TestValue(index);
}
std::cout << " Creating and checking array handle" << std::endl;
vtkm::cont::ArrayHandle<vtkm::Vector3,StorageTag> array =
vtkm::cont::make_ArrayHandle(buffer, StorageTag());
CheckArray()(array);
std::cout << " Creating and checking PointCoordinatesArray" << std::endl;
vtkm::cont::PointCoordinatesArray pointCoordinates =
vtkm::cont::PointCoordinatesArray(array);
pointCoordinates.CastAndCall(
CheckArray(),
vtkm::ListTagEmpty(), // Internally sets to Vector3
vtkm::cont::StorageListTagBasic());
}
void TestPointCoordinatesUniform()
{
std::cout << "Testing PointCoordinatesUniform" << std::endl;
vtkm::cont::PointCoordinatesUniform pointCoordinates =
vtkm::cont::PointCoordinatesUniform(EXTENT, ORIGIN, SPACING);
pointCoordinates.CastAndCall(
CheckArray(),
vtkm::ListTagEmpty(), // Not used
vtkm::ListTagEmpty()); // Not used
}
void PointCoordinatesTests()
{
TestPointCoordinatesArray();
TestPointCoordinatesUniform();
}
} // anonymous namespace
int UnitTestPointCoordinates(int, char *[])
{
return vtkm::cont::testing::Testing::Run(PointCoordinatesTests);
}