2017-04-04 20:00:04 +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.
|
|
|
|
//============================================================================
|
|
|
|
|
|
|
|
#include <vtkm/worklet/ExtractStructured.h>
|
|
|
|
|
2017-04-13 20:45:53 +00:00
|
|
|
#include <vtkm/Bounds.h>
|
2017-04-04 20:00:04 +00:00
|
|
|
#include <vtkm/cont/DataSet.h>
|
|
|
|
#include <vtkm/cont/testing/MakeTestDataSet.h>
|
|
|
|
#include <vtkm/cont/testing/Testing.h>
|
|
|
|
|
|
|
|
using vtkm::cont::testing::MakeTestDataSet;
|
|
|
|
|
|
|
|
template <typename DeviceAdapter>
|
|
|
|
class TestingExtractStructured
|
|
|
|
{
|
|
|
|
public:
|
2017-04-05 15:36:25 +00:00
|
|
|
void TestUniform2D() const
|
|
|
|
{
|
|
|
|
std::cout << "Testing extract structured uniform" << std::endl;
|
|
|
|
typedef vtkm::cont::CellSetStructured<2> CellSetType;
|
2017-05-18 14:29:41 +00:00
|
|
|
|
2017-04-05 15:36:25 +00:00
|
|
|
// Create the input uniform cell set
|
|
|
|
vtkm::cont::DataSet dataSet = MakeTestDataSet().Make2DUniformDataSet1();
|
|
|
|
CellSetType cellSet;
|
|
|
|
dataSet.GetCellSet(0).CopyTo(cellSet);
|
|
|
|
|
2017-04-13 18:36:53 +00:00
|
|
|
// Bounds and subsample
|
2017-05-18 14:29:41 +00:00
|
|
|
vtkm::Bounds bounds(1, 3, 1, 3, 0, 0);
|
|
|
|
vtkm::Id3 sample(1, 1, 1);
|
2017-04-27 20:53:51 +00:00
|
|
|
bool includeBoundary = false;
|
2017-05-18 14:29:41 +00:00
|
|
|
|
2017-04-05 15:36:25 +00:00
|
|
|
vtkm::worklet::ExtractStructured worklet;
|
2017-05-26 17:53:28 +00:00
|
|
|
vtkm::cont::DataSet outDataSet = worklet.Run(
|
|
|
|
cellSet, dataSet.GetCoordinateSystem(0), bounds, sample, includeBoundary, DeviceAdapter());
|
2017-05-18 14:29:41 +00:00
|
|
|
|
2017-04-06 20:11:49 +00:00
|
|
|
VTKM_TEST_ASSERT(test_equal(outDataSet.GetCellSet(0).GetNumberOfPoints(), 9),
|
|
|
|
"Wrong result for ExtractStructured worklet");
|
|
|
|
VTKM_TEST_ASSERT(test_equal(outDataSet.GetCellSet(0).GetNumberOfCells(), 4),
|
|
|
|
"Wrong result for ExtractStructured worklet");
|
2017-04-05 15:36:25 +00:00
|
|
|
}
|
|
|
|
|
2017-04-14 19:34:51 +00:00
|
|
|
void TestUniform3D() const
|
2017-04-04 20:00:04 +00:00
|
|
|
{
|
2017-04-27 20:53:51 +00:00
|
|
|
std::cout << "Testing extract structured uniform" << std::endl;
|
2017-04-04 20:00:04 +00:00
|
|
|
typedef vtkm::cont::CellSetStructured<3> CellSetType;
|
2017-05-18 14:29:41 +00:00
|
|
|
|
2017-04-04 20:00:04 +00:00
|
|
|
// Create the input uniform cell set
|
|
|
|
vtkm::cont::DataSet dataSet = MakeTestDataSet().Make3DUniformDataSet1();
|
|
|
|
CellSetType cellSet;
|
|
|
|
dataSet.GetCellSet(0).CopyTo(cellSet);
|
|
|
|
|
2017-04-13 18:36:53 +00:00
|
|
|
vtkm::worklet::ExtractStructured worklet;
|
2017-04-14 19:34:51 +00:00
|
|
|
vtkm::cont::DataSet outDataSet;
|
|
|
|
|
|
|
|
// Bounding box within dataset
|
2017-05-18 14:29:41 +00:00
|
|
|
vtkm::Bounds bounds0(1, 3, 1, 3, 1, 3);
|
|
|
|
vtkm::Id3 sample(1, 1, 1);
|
2017-04-27 20:53:51 +00:00
|
|
|
bool includeBoundary = false;
|
|
|
|
|
2017-05-26 17:53:28 +00:00
|
|
|
outDataSet = worklet.Run(
|
|
|
|
cellSet, dataSet.GetCoordinateSystem(0), bounds0, sample, includeBoundary, DeviceAdapter());
|
2017-04-14 19:34:51 +00:00
|
|
|
VTKM_TEST_ASSERT(test_equal(outDataSet.GetCellSet(0).GetNumberOfPoints(), 27),
|
|
|
|
"Wrong result for ExtractStructured worklet");
|
|
|
|
VTKM_TEST_ASSERT(test_equal(outDataSet.GetCellSet(0).GetNumberOfCells(), 8),
|
|
|
|
"Wrong result for ExtractStructured worklet");
|
|
|
|
|
|
|
|
// Bounding box surrounds dataset
|
2017-05-18 14:29:41 +00:00
|
|
|
vtkm::Bounds bounds1(-1, 7, -1, 7, -1, 7);
|
2017-05-26 17:53:28 +00:00
|
|
|
outDataSet = worklet.Run(
|
|
|
|
cellSet, dataSet.GetCoordinateSystem(0), bounds1, sample, includeBoundary, DeviceAdapter());
|
2017-04-14 19:34:51 +00:00
|
|
|
VTKM_TEST_ASSERT(test_equal(outDataSet.GetCellSet(0).GetNumberOfPoints(), 125),
|
|
|
|
"Wrong result for ExtractStructured worklet");
|
|
|
|
VTKM_TEST_ASSERT(test_equal(outDataSet.GetCellSet(0).GetNumberOfCells(), 64),
|
|
|
|
"Wrong result for ExtractStructured worklet");
|
|
|
|
|
|
|
|
// Bounding box intersects dataset on near boundary
|
2017-05-18 14:29:41 +00:00
|
|
|
vtkm::Bounds bounds2(-1, 2, -1, 2, -1, 2);
|
2017-05-26 17:53:28 +00:00
|
|
|
outDataSet = worklet.Run(
|
|
|
|
cellSet, dataSet.GetCoordinateSystem(0), bounds2, sample, includeBoundary, DeviceAdapter());
|
2017-04-13 18:36:53 +00:00
|
|
|
VTKM_TEST_ASSERT(test_equal(outDataSet.GetCellSet(0).GetNumberOfPoints(), 27),
|
|
|
|
"Wrong result for ExtractStructured worklet");
|
|
|
|
VTKM_TEST_ASSERT(test_equal(outDataSet.GetCellSet(0).GetNumberOfCells(), 8),
|
|
|
|
"Wrong result for ExtractStructured worklet");
|
2017-04-14 19:34:51 +00:00
|
|
|
|
|
|
|
// Bounding box intersects dataset on far boundary
|
2017-05-18 14:29:41 +00:00
|
|
|
vtkm::Bounds bounds3(1, 7, 1, 7, 1, 7);
|
2017-05-26 17:53:28 +00:00
|
|
|
outDataSet = worklet.Run(
|
|
|
|
cellSet, dataSet.GetCoordinateSystem(0), bounds3, sample, includeBoundary, DeviceAdapter());
|
2017-04-14 19:34:51 +00:00
|
|
|
VTKM_TEST_ASSERT(test_equal(outDataSet.GetCellSet(0).GetNumberOfPoints(), 64),
|
|
|
|
"Wrong result for ExtractStructured worklet");
|
|
|
|
VTKM_TEST_ASSERT(test_equal(outDataSet.GetCellSet(0).GetNumberOfCells(), 27),
|
|
|
|
"Wrong result for ExtractStructured worklet");
|
|
|
|
|
|
|
|
// Bounding box intersects dataset without corner
|
2017-05-18 14:29:41 +00:00
|
|
|
vtkm::Bounds bounds4(2, 7, 1, 3, 1, 3);
|
2017-05-26 17:53:28 +00:00
|
|
|
outDataSet = worklet.Run(
|
|
|
|
cellSet, dataSet.GetCoordinateSystem(0), bounds4, sample, includeBoundary, DeviceAdapter());
|
2017-04-14 19:34:51 +00:00
|
|
|
VTKM_TEST_ASSERT(test_equal(outDataSet.GetCellSet(0).GetNumberOfPoints(), 27),
|
|
|
|
"Wrong result for ExtractStructured worklet");
|
|
|
|
VTKM_TEST_ASSERT(test_equal(outDataSet.GetCellSet(0).GetNumberOfCells(), 8),
|
|
|
|
"Wrong result for ExtractStructured worklet");
|
|
|
|
|
|
|
|
// Bounding box intersects dataset with plane
|
2017-05-18 14:29:41 +00:00
|
|
|
vtkm::Bounds bounds5(2, 7, 1, 1, 1, 3);
|
2017-05-26 17:53:28 +00:00
|
|
|
outDataSet = worklet.Run(
|
|
|
|
cellSet, dataSet.GetCoordinateSystem(0), bounds5, sample, includeBoundary, DeviceAdapter());
|
2017-04-14 19:34:51 +00:00
|
|
|
VTKM_TEST_ASSERT(test_equal(outDataSet.GetCellSet(0).GetNumberOfPoints(), 9),
|
|
|
|
"Wrong result for ExtractStructured worklet");
|
|
|
|
VTKM_TEST_ASSERT(test_equal(outDataSet.GetCellSet(0).GetNumberOfCells(), 4),
|
|
|
|
"Wrong result for ExtractStructured worklet");
|
2017-04-13 18:36:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void TestUniform3D1() const
|
|
|
|
{
|
2017-04-14 19:34:51 +00:00
|
|
|
std::cout << "Testing extract structured uniform with sampling" << std::endl;
|
2017-04-13 18:36:53 +00:00
|
|
|
typedef vtkm::cont::CellSetStructured<3> CellSetType;
|
2017-05-18 14:29:41 +00:00
|
|
|
|
2017-04-13 18:36:53 +00:00
|
|
|
// Create the input uniform cell set
|
|
|
|
vtkm::cont::DataSet dataSet = MakeTestDataSet().Make3DUniformDataSet1();
|
|
|
|
CellSetType cellSet;
|
|
|
|
dataSet.GetCellSet(0).CopyTo(cellSet);
|
|
|
|
|
2017-04-04 20:00:04 +00:00
|
|
|
vtkm::worklet::ExtractStructured worklet;
|
2017-04-14 19:34:51 +00:00
|
|
|
vtkm::cont::DataSet outDataSet;
|
|
|
|
|
|
|
|
// Bounding box within data set with sampling
|
2017-05-18 14:29:41 +00:00
|
|
|
vtkm::Bounds bounds0(0, 4, 0, 4, 1, 3);
|
|
|
|
vtkm::Id3 sample0(2, 2, 1);
|
2017-04-27 20:53:51 +00:00
|
|
|
bool includeBoundary0 = false;
|
|
|
|
|
2017-05-26 17:53:28 +00:00
|
|
|
outDataSet = worklet.Run(
|
|
|
|
cellSet, dataSet.GetCoordinateSystem(0), bounds0, sample0, includeBoundary0, DeviceAdapter());
|
2017-04-27 20:53:51 +00:00
|
|
|
|
2017-04-14 19:34:51 +00:00
|
|
|
VTKM_TEST_ASSERT(test_equal(outDataSet.GetCellSet(0).GetNumberOfPoints(), 27),
|
2017-04-06 20:11:49 +00:00
|
|
|
"Wrong result for ExtractStructured worklet");
|
2017-04-14 19:34:51 +00:00
|
|
|
VTKM_TEST_ASSERT(test_equal(outDataSet.GetCellSet(0).GetNumberOfCells(), 8),
|
2017-04-06 20:11:49 +00:00
|
|
|
"Wrong result for ExtractStructured worklet");
|
2017-04-13 18:36:53 +00:00
|
|
|
|
|
|
|
// Bounds and subsample
|
2017-05-18 14:29:41 +00:00
|
|
|
vtkm::Bounds bounds1(0, 4, 0, 4, 1, 3);
|
|
|
|
vtkm::Id3 sample1(3, 3, 2);
|
2017-04-27 20:53:51 +00:00
|
|
|
bool includeBoundary1 = false;
|
|
|
|
|
2017-05-26 17:53:28 +00:00
|
|
|
outDataSet = worklet.Run(
|
|
|
|
cellSet, dataSet.GetCoordinateSystem(0), bounds1, sample1, includeBoundary1, DeviceAdapter());
|
2017-04-27 20:53:51 +00:00
|
|
|
|
2017-04-14 19:34:51 +00:00
|
|
|
VTKM_TEST_ASSERT(test_equal(outDataSet.GetCellSet(0).GetNumberOfPoints(), 8),
|
2017-04-13 18:36:53 +00:00
|
|
|
"Wrong result for ExtractStructured worklet");
|
2017-04-14 19:34:51 +00:00
|
|
|
VTKM_TEST_ASSERT(test_equal(outDataSet.GetCellSet(0).GetNumberOfCells(), 1),
|
2017-04-13 18:36:53 +00:00
|
|
|
"Wrong result for ExtractStructured worklet");
|
2017-04-27 20:53:51 +00:00
|
|
|
|
|
|
|
// Bounds and subsample
|
2017-05-18 14:29:41 +00:00
|
|
|
vtkm::Bounds bounds2(0, 4, 0, 4, 1, 3);
|
|
|
|
vtkm::Id3 sample2(3, 3, 2);
|
2017-04-27 20:53:51 +00:00
|
|
|
bool includeBoundary2 = true;
|
|
|
|
|
2017-05-26 17:53:28 +00:00
|
|
|
outDataSet = worklet.Run(
|
|
|
|
cellSet, dataSet.GetCoordinateSystem(0), bounds2, sample2, includeBoundary2, DeviceAdapter());
|
2017-04-27 20:53:51 +00:00
|
|
|
|
|
|
|
VTKM_TEST_ASSERT(test_equal(outDataSet.GetCellSet(0).GetNumberOfPoints(), 18),
|
|
|
|
"Wrong result for ExtractStructured worklet");
|
|
|
|
VTKM_TEST_ASSERT(test_equal(outDataSet.GetCellSet(0).GetNumberOfCells(), 4),
|
|
|
|
"Wrong result for ExtractStructured worklet");
|
2017-04-13 18:36:53 +00:00
|
|
|
}
|
|
|
|
|
2017-04-05 15:36:25 +00:00
|
|
|
void TestRectilinear2D() const
|
|
|
|
{
|
|
|
|
std::cout << "Testing extract structured rectilinear" << std::endl;
|
|
|
|
typedef vtkm::cont::CellSetStructured<2> CellSetType;
|
2017-05-18 14:29:41 +00:00
|
|
|
|
2017-04-05 15:36:25 +00:00
|
|
|
// Create the input uniform cell set
|
|
|
|
vtkm::cont::DataSet dataSet = MakeTestDataSet().Make2DRectilinearDataSet0();
|
|
|
|
CellSetType cellSet;
|
|
|
|
dataSet.GetCellSet(0).CopyTo(cellSet);
|
|
|
|
|
2017-04-10 21:56:00 +00:00
|
|
|
// Bounds and subsample
|
2017-05-18 14:29:41 +00:00
|
|
|
vtkm::Bounds bounds(0, 1, 0, 1, 0, 0);
|
|
|
|
vtkm::Id3 sample(1, 1, 1);
|
2017-04-27 20:53:51 +00:00
|
|
|
bool includeBoundary = false;
|
2017-05-18 14:29:41 +00:00
|
|
|
|
2017-04-05 15:36:25 +00:00
|
|
|
// Extract subset
|
|
|
|
vtkm::worklet::ExtractStructured worklet;
|
2017-05-26 17:53:28 +00:00
|
|
|
vtkm::cont::DataSet outDataSet = worklet.Run(
|
|
|
|
cellSet, dataSet.GetCoordinateSystem(0), bounds, sample, includeBoundary, DeviceAdapter());
|
2017-05-18 14:29:41 +00:00
|
|
|
|
2017-04-06 20:11:49 +00:00
|
|
|
VTKM_TEST_ASSERT(test_equal(outDataSet.GetCellSet(0).GetNumberOfPoints(), 4),
|
|
|
|
"Wrong result for ExtractStructured worklet");
|
|
|
|
VTKM_TEST_ASSERT(test_equal(outDataSet.GetCellSet(0).GetNumberOfCells(), 1),
|
|
|
|
"Wrong result for ExtractStructured worklet");
|
2017-04-04 20:00:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void TestRectilinear3D() const
|
|
|
|
{
|
|
|
|
std::cout << "Testing extract structured rectilinear" << std::endl;
|
|
|
|
typedef vtkm::cont::CellSetStructured<3> CellSetType;
|
2017-05-18 14:29:41 +00:00
|
|
|
|
2017-04-04 20:00:04 +00:00
|
|
|
// Create the input uniform cell set
|
|
|
|
vtkm::cont::DataSet dataSet = MakeTestDataSet().Make3DRectilinearDataSet0();
|
|
|
|
CellSetType cellSet;
|
|
|
|
dataSet.GetCellSet(0).CopyTo(cellSet);
|
|
|
|
|
2017-04-13 18:36:53 +00:00
|
|
|
// Bounds and subsample
|
2017-05-18 14:29:41 +00:00
|
|
|
vtkm::Bounds bounds(0, 1, 0, 1, 0, 1);
|
|
|
|
vtkm::Id3 sample(1, 1, 1);
|
2017-04-27 20:53:51 +00:00
|
|
|
bool includeBoundary = false;
|
2017-05-18 14:29:41 +00:00
|
|
|
|
2017-04-04 20:00:04 +00:00
|
|
|
// Extract subset
|
|
|
|
vtkm::worklet::ExtractStructured worklet;
|
2017-05-26 17:53:28 +00:00
|
|
|
vtkm::cont::DataSet outDataSet = worklet.Run(
|
|
|
|
cellSet, dataSet.GetCoordinateSystem(0), bounds, sample, includeBoundary, DeviceAdapter());
|
2017-05-18 14:29:41 +00:00
|
|
|
|
2017-04-06 20:11:49 +00:00
|
|
|
VTKM_TEST_ASSERT(test_equal(outDataSet.GetCellSet(0).GetNumberOfPoints(), 8),
|
|
|
|
"Wrong result for ExtractStructured worklet");
|
|
|
|
VTKM_TEST_ASSERT(test_equal(outDataSet.GetCellSet(0).GetNumberOfCells(), 1),
|
|
|
|
"Wrong result for ExtractStructured worklet");
|
2017-04-04 20:00:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void operator()() const
|
|
|
|
{
|
2017-04-05 15:36:25 +00:00
|
|
|
TestUniform2D();
|
2017-04-14 19:34:51 +00:00
|
|
|
TestUniform3D();
|
2017-04-13 18:36:53 +00:00
|
|
|
TestUniform3D1();
|
2017-04-05 15:36:25 +00:00
|
|
|
TestRectilinear2D();
|
2017-04-06 20:11:49 +00:00
|
|
|
TestRectilinear3D();
|
2017-04-04 20:00:04 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
int UnitTestExtractStructured(int, char* [])
|
2017-04-04 20:00:04 +00:00
|
|
|
{
|
|
|
|
return vtkm::cont::testing::Testing::Run(
|
|
|
|
TestingExtractStructured<VTKM_DEFAULT_DEVICE_ADAPTER_TAG>());
|
|
|
|
}
|