2015-07-16 19:10:01 +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 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.
|
|
|
|
//============================================================================
|
2016-05-26 22:02:30 +00:00
|
|
|
#ifndef vtk_m_cont_testing_TestingComputeRange_h
|
|
|
|
#define vtk_m_cont_testing_TestingComputeRange_h
|
2015-07-16 19:10:01 +00:00
|
|
|
|
|
|
|
#include <vtkm/Types.h>
|
2015-08-19 04:56:10 +00:00
|
|
|
#include <vtkm/cont/CoordinateSystem.h>
|
2015-07-16 19:10:01 +00:00
|
|
|
#include <vtkm/cont/Field.h>
|
|
|
|
#include <vtkm/cont/testing/Testing.h>
|
|
|
|
|
2017-02-24 00:12:14 +00:00
|
|
|
// Required for implementation of ArrayRangeCompute for "odd" arrays
|
|
|
|
#include <vtkm/cont/ArrayRangeCompute.hxx>
|
2015-07-16 19:10:01 +00:00
|
|
|
|
|
|
|
#include <algorithm>
|
|
|
|
#include <iostream>
|
|
|
|
|
|
|
|
namespace vtkm {
|
|
|
|
namespace cont {
|
|
|
|
namespace testing {
|
|
|
|
|
|
|
|
struct CustomTypeList : vtkm::ListTagBase<vtkm::Vec<Int32, 3>,
|
|
|
|
vtkm::Vec<Int64, 3>,
|
|
|
|
vtkm::Vec<Float32, 3>,
|
|
|
|
vtkm::Vec<Float64, 3>,
|
|
|
|
vtkm::Vec<Int32, 9>,
|
|
|
|
vtkm::Vec<Int64, 9>,
|
|
|
|
vtkm::Vec<Float32, 9>,
|
|
|
|
vtkm::Vec<Float64, 9> >
|
|
|
|
{};
|
|
|
|
|
|
|
|
template <typename DeviceAdapterTag>
|
2016-05-26 22:02:30 +00:00
|
|
|
class TestingComputeRange
|
2015-07-16 19:10:01 +00:00
|
|
|
{
|
|
|
|
private:
|
|
|
|
template <typename T>
|
|
|
|
static void TestScalarField()
|
|
|
|
{
|
|
|
|
const vtkm::Id nvals = 11;
|
|
|
|
T data[nvals] = { 1, 2, 3, 4, 5, -5, -4, -3, -2, -1, 0 };
|
|
|
|
std::random_shuffle(data, data + nvals);
|
2016-03-23 14:38:14 +00:00
|
|
|
vtkm::cont::Field field("TestField", vtkm::cont::Field::ASSOC_POINTS, data,
|
2015-07-16 19:10:01 +00:00
|
|
|
nvals);
|
|
|
|
|
2016-05-26 22:02:30 +00:00
|
|
|
vtkm::Range result;
|
|
|
|
field.GetRange(&result, DeviceAdapterTag());
|
2015-07-16 19:10:01 +00:00
|
|
|
|
2016-05-26 22:02:30 +00:00
|
|
|
std::cout << result << std::endl;
|
|
|
|
VTKM_TEST_ASSERT(
|
|
|
|
(test_equal(result.Min, -5.0) && test_equal(result.Max, 5.0)),
|
|
|
|
"Unexpected scalar field range.");
|
2015-07-16 19:10:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T, vtkm::Id NumberOfComponents>
|
|
|
|
static void TestVecField()
|
|
|
|
{
|
|
|
|
const vtkm::Id nvals = 11;
|
|
|
|
T data[nvals] = { 1, 2, 3, 4, 5, -5, -4, -3, -2, -1, 0 };
|
|
|
|
vtkm::Vec<T, NumberOfComponents> fieldData[nvals];
|
2015-07-23 13:06:20 +00:00
|
|
|
for (vtkm::IdComponent i = 0; i < NumberOfComponents; ++i)
|
2015-07-16 19:10:01 +00:00
|
|
|
{
|
|
|
|
std::random_shuffle(data, data + nvals);
|
|
|
|
for (vtkm::Id j = 0; j < nvals; ++j)
|
|
|
|
{
|
|
|
|
fieldData[j][i] = data[j];
|
|
|
|
}
|
|
|
|
}
|
2016-03-23 14:38:14 +00:00
|
|
|
vtkm::cont::Field field("TestField", vtkm::cont::Field::ASSOC_POINTS, fieldData,
|
2015-07-16 19:10:01 +00:00
|
|
|
nvals);
|
|
|
|
|
2016-05-26 22:02:30 +00:00
|
|
|
vtkm::Range result[NumberOfComponents];
|
|
|
|
field.GetRange(result,
|
|
|
|
DeviceAdapterTag(),
|
|
|
|
CustomTypeList(),
|
|
|
|
VTKM_DEFAULT_STORAGE_LIST_TAG());
|
2015-07-16 19:10:01 +00:00
|
|
|
|
2015-07-23 13:06:20 +00:00
|
|
|
for (vtkm::IdComponent i = 0; i < NumberOfComponents; ++i)
|
2015-07-16 19:10:01 +00:00
|
|
|
{
|
2016-05-26 22:02:30 +00:00
|
|
|
VTKM_TEST_ASSERT(
|
|
|
|
(test_equal(result[i].Min, -5.0) && test_equal(result[i].Max, 5.0)),
|
|
|
|
"Unexpected vector field range.");
|
2015-07-16 19:10:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-19 04:56:10 +00:00
|
|
|
static void TestUniformCoordinateField()
|
|
|
|
{
|
|
|
|
vtkm::cont::CoordinateSystem field(
|
|
|
|
"TestField",
|
|
|
|
vtkm::Id3(10, 20, 5),
|
|
|
|
vtkm::Vec<vtkm::FloatDefault,3>(0.0f,-5.0f,4.0f),
|
|
|
|
vtkm::Vec<vtkm::FloatDefault,3>(1.0f,0.5f,2.0f));
|
|
|
|
|
2016-05-26 22:02:30 +00:00
|
|
|
vtkm::Bounds result = field.GetBounds(DeviceAdapterTag());
|
2015-08-19 04:56:10 +00:00
|
|
|
|
2016-05-26 22:02:30 +00:00
|
|
|
VTKM_TEST_ASSERT(test_equal(result.X.Min, 0.0), "Min x wrong.");
|
|
|
|
VTKM_TEST_ASSERT(test_equal(result.X.Max, 9.0), "Max x wrong.");
|
|
|
|
VTKM_TEST_ASSERT(test_equal(result.Y.Min, -5.0), "Min y wrong.");
|
|
|
|
VTKM_TEST_ASSERT(test_equal(result.Y.Max, 4.5), "Max y wrong.");
|
|
|
|
VTKM_TEST_ASSERT(test_equal(result.Z.Min, 4.0), "Min z wrong.");
|
|
|
|
VTKM_TEST_ASSERT(test_equal(result.Z.Max, 12.0), "Max z wrong.");
|
2015-08-19 04:56:10 +00:00
|
|
|
}
|
|
|
|
|
2015-07-16 19:10:01 +00:00
|
|
|
struct TestAll
|
|
|
|
{
|
2016-10-19 22:42:58 +00:00
|
|
|
VTKM_CONT void operator()() const
|
2015-07-16 19:10:01 +00:00
|
|
|
{
|
|
|
|
std::cout << "Testing (Int32, 1)..." << std::endl;
|
2016-05-26 22:02:30 +00:00
|
|
|
TestingComputeRange::TestScalarField<vtkm::Int32>();
|
2015-07-16 19:10:01 +00:00
|
|
|
std::cout << "Testing (Int64, 1)..." << std::endl;
|
2016-05-26 22:02:30 +00:00
|
|
|
TestingComputeRange::TestScalarField<vtkm::Int64>();
|
2015-07-16 19:10:01 +00:00
|
|
|
std::cout << "Testing (Float32, 1)..." << std::endl;
|
2016-05-26 22:02:30 +00:00
|
|
|
TestingComputeRange::TestScalarField<vtkm::Float32>();
|
2015-07-16 19:10:01 +00:00
|
|
|
std::cout << "Testing (Float64, 1)..." << std::endl;
|
2016-05-26 22:02:30 +00:00
|
|
|
TestingComputeRange::TestScalarField<vtkm::Float64>();
|
2015-07-16 19:10:01 +00:00
|
|
|
|
|
|
|
std::cout << "Testing (Int32, 3)..." << std::endl;
|
2016-05-26 22:02:30 +00:00
|
|
|
TestingComputeRange::TestVecField<vtkm::Int32, 3>();
|
2015-07-16 19:10:01 +00:00
|
|
|
std::cout << "Testing (Int64, 3)..." << std::endl;
|
2016-05-26 22:02:30 +00:00
|
|
|
TestingComputeRange::TestVecField<vtkm::Int64, 3>();
|
2015-07-16 19:10:01 +00:00
|
|
|
std::cout << "Testing (Float32, 3)..." << std::endl;
|
2016-05-26 22:02:30 +00:00
|
|
|
TestingComputeRange::TestVecField<vtkm::Float32, 3>();
|
2015-07-16 19:10:01 +00:00
|
|
|
std::cout << "Testing (Float64, 3)..." << std::endl;
|
2016-05-26 22:02:30 +00:00
|
|
|
TestingComputeRange::TestVecField<vtkm::Float64, 3>();
|
2015-07-16 19:10:01 +00:00
|
|
|
|
|
|
|
std::cout << "Testing (Int32, 9)..." << std::endl;
|
2016-05-26 22:02:30 +00:00
|
|
|
TestingComputeRange::TestVecField<vtkm::Int32, 9>();
|
2015-07-16 19:10:01 +00:00
|
|
|
std::cout << "Testing (Int64, 9)..." << std::endl;
|
2016-05-26 22:02:30 +00:00
|
|
|
TestingComputeRange::TestVecField<vtkm::Int64, 9>();
|
2015-07-16 19:10:01 +00:00
|
|
|
std::cout << "Testing (Float32, 9)..." << std::endl;
|
2016-05-26 22:02:30 +00:00
|
|
|
TestingComputeRange::TestVecField<vtkm::Float32, 9>();
|
2015-07-16 19:10:01 +00:00
|
|
|
std::cout << "Testing (Float64, 9)..." << std::endl;
|
2016-05-26 22:02:30 +00:00
|
|
|
TestingComputeRange::TestVecField<vtkm::Float64, 9>();
|
2015-08-19 04:56:10 +00:00
|
|
|
|
|
|
|
std::cout << "Testing UniformPointCoords..." << std::endl;
|
2016-05-26 22:02:30 +00:00
|
|
|
TestingComputeRange::TestUniformCoordinateField();
|
2015-07-16 19:10:01 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
public:
|
2016-10-19 22:42:58 +00:00
|
|
|
static VTKM_CONT int Run()
|
2015-07-16 19:10:01 +00:00
|
|
|
{
|
|
|
|
return vtkm::cont::testing::Testing::Run(TestAll());
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} // namespace vtkm::cont::testing
|
|
|
|
|
2016-05-26 22:02:30 +00:00
|
|
|
#endif //vtk_m_cont_testing_TestingComputeRange_h
|