vtk-m/vtkm/worklet/testing/UnitTestExtractStructured.cxx

271 lines
11 KiB
C++
Raw Normal View History

//============================================================================
// 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.
//============================================================================
#include <vtkm/worklet/ExtractStructured.h>
#include <vtkm/cont/DataSet.h>
#include <vtkm/cont/testing/MakeTestDataSet.h>
#include <vtkm/cont/testing/Testing.h>
using vtkm::cont::testing::MakeTestDataSet;
class TestingExtractStructured
{
public:
void TestUniform2D() const
{
std::cout << "Testing extract structured uniform 2D" << std::endl;
2018-02-22 13:29:13 +00:00
using CellSetType = vtkm::cont::CellSetStructured<2>;
2017-05-18 14:29:41 +00:00
// Create the input uniform cell set
vtkm::cont::DataSet dataSet = MakeTestDataSet().Make2DUniformDataSet1();
CellSetType cellSet;
dataSet.GetCellSet(0).CopyTo(cellSet);
// RangeId3 and subsample
vtkm::RangeId3 range(1, 4, 1, 4, 0, 1);
2017-05-18 14:29:41 +00:00
vtkm::Id3 sample(1, 1, 1);
2017-04-27 20:53:51 +00:00
bool includeBoundary = false;
2019-04-18 03:13:36 +00:00
bool includeOffset = true;
2017-05-18 14:29:41 +00:00
vtkm::worklet::ExtractStructured worklet;
2019-04-18 03:13:36 +00:00
auto outCellSet = worklet.Run(cellSet, range, sample, includeBoundary, includeOffset);
2017-05-18 14:29:41 +00:00
VTKM_TEST_ASSERT(test_equal(outCellSet.GetNumberOfPoints(), 9),
2017-04-06 20:11:49 +00:00
"Wrong result for ExtractStructured worklet");
VTKM_TEST_ASSERT(test_equal(outCellSet.GetNumberOfCells(), 4),
2017-04-06 20:11:49 +00:00
"Wrong result for ExtractStructured worklet");
}
void TestUniform3D() const
{
std::cout << "Testing extract structured uniform 3D" << std::endl;
2018-02-22 13:29:13 +00:00
using CellSetType = vtkm::cont::CellSetStructured<3>;
2017-05-18 14:29:41 +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;
vtkm::worklet::ExtractStructured::DynamicCellSetStructured outCellSet;
// RangeId3 within dataset
vtkm::RangeId3 range0(1, 4, 1, 4, 1, 4);
2017-05-18 14:29:41 +00:00
vtkm::Id3 sample(1, 1, 1);
2017-04-27 20:53:51 +00:00
bool includeBoundary = false;
2019-04-18 03:13:36 +00:00
bool includeOffset = true;
2017-04-27 20:53:51 +00:00
2019-04-18 03:13:36 +00:00
outCellSet = worklet.Run(cellSet, range0, sample, includeBoundary, includeOffset);
VTKM_TEST_ASSERT(test_equal(outCellSet.GetNumberOfPoints(), 27),
"Wrong result for ExtractStructured worklet");
VTKM_TEST_ASSERT(test_equal(outCellSet.GetNumberOfCells(), 8),
"Wrong result for ExtractStructured worklet");
// RangeId3 surrounds dataset
vtkm::RangeId3 range1(-1, 8, -1, 8, -1, 8);
2019-04-18 03:13:36 +00:00
outCellSet = worklet.Run(cellSet, range1, sample, includeBoundary, includeOffset);
VTKM_TEST_ASSERT(test_equal(outCellSet.GetNumberOfPoints(), 125),
"Wrong result for ExtractStructured worklet");
VTKM_TEST_ASSERT(test_equal(outCellSet.GetNumberOfCells(), 64),
"Wrong result for ExtractStructured worklet");
// RangeId3 intersects dataset on near boundary
vtkm::RangeId3 range2(-1, 3, -1, 3, -1, 3);
2019-04-18 03:13:36 +00:00
outCellSet = worklet.Run(cellSet, range2, sample, includeBoundary, includeOffset);
VTKM_TEST_ASSERT(test_equal(outCellSet.GetNumberOfPoints(), 27),
2017-04-13 18:36:53 +00:00
"Wrong result for ExtractStructured worklet");
VTKM_TEST_ASSERT(test_equal(outCellSet.GetNumberOfCells(), 8),
2017-04-13 18:36:53 +00:00
"Wrong result for ExtractStructured worklet");
// RangeId3 intersects dataset on far boundary
vtkm::RangeId3 range3(1, 8, 1, 8, 1, 8);
2019-04-18 03:13:36 +00:00
outCellSet = worklet.Run(cellSet, range3, sample, includeBoundary, includeOffset);
VTKM_TEST_ASSERT(test_equal(outCellSet.GetNumberOfPoints(), 64),
"Wrong result for ExtractStructured worklet");
VTKM_TEST_ASSERT(test_equal(outCellSet.GetNumberOfCells(), 27),
"Wrong result for ExtractStructured worklet");
// RangeId3 intersects dataset without corner
vtkm::RangeId3 range4(2, 8, 1, 4, 1, 4);
2019-04-18 03:13:36 +00:00
outCellSet = worklet.Run(cellSet, range4, sample, includeBoundary, includeOffset);
VTKM_TEST_ASSERT(test_equal(outCellSet.GetNumberOfPoints(), 27),
"Wrong result for ExtractStructured worklet");
VTKM_TEST_ASSERT(test_equal(outCellSet.GetNumberOfCells(), 8),
"Wrong result for ExtractStructured worklet");
// RangeId3 intersects dataset with plane
vtkm::RangeId3 range5(2, 8, 1, 2, 1, 4);
2019-04-18 03:13:36 +00:00
outCellSet = worklet.Run(cellSet, range5, sample, includeBoundary, includeOffset);
VTKM_TEST_ASSERT(test_equal(outCellSet.GetNumberOfPoints(), 9),
"Wrong result for ExtractStructured worklet");
VTKM_TEST_ASSERT(test_equal(outCellSet.GetNumberOfCells(), 4),
"Wrong result for ExtractStructured worklet");
2017-04-13 18:36:53 +00:00
}
void TestUniform3D1() const
{
std::cout << "Testing extract structured uniform with sampling" << std::endl;
2018-02-22 13:29:13 +00:00
using CellSetType = vtkm::cont::CellSetStructured<3>;
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);
vtkm::worklet::ExtractStructured worklet;
vtkm::worklet::ExtractStructured::DynamicCellSetStructured outCellSet;
// RangeId3 within data set with sampling
vtkm::RangeId3 range0(0, 5, 0, 5, 1, 4);
2017-05-18 14:29:41 +00:00
vtkm::Id3 sample0(2, 2, 1);
2017-04-27 20:53:51 +00:00
bool includeBoundary0 = false;
2019-04-17 00:18:24 +00:00
outCellSet = worklet.Run(cellSet, range0, sample0, includeBoundary0, false);
2017-04-27 20:53:51 +00:00
VTKM_TEST_ASSERT(test_equal(outCellSet.GetNumberOfPoints(), 27),
2017-04-06 20:11:49 +00:00
"Wrong result for ExtractStructured worklet");
VTKM_TEST_ASSERT(test_equal(outCellSet.GetNumberOfCells(), 8),
2017-04-06 20:11:49 +00:00
"Wrong result for ExtractStructured worklet");
2017-04-13 18:36:53 +00:00
// RangeId3 and subsample
vtkm::RangeId3 range1(0, 5, 0, 5, 1, 4);
2017-05-18 14:29:41 +00:00
vtkm::Id3 sample1(3, 3, 2);
2017-04-27 20:53:51 +00:00
bool includeBoundary1 = false;
2019-04-17 00:18:24 +00:00
outCellSet = worklet.Run(cellSet, range1, sample1, includeBoundary1, false);
2017-04-27 20:53:51 +00:00
VTKM_TEST_ASSERT(test_equal(outCellSet.GetNumberOfPoints(), 8),
2017-04-13 18:36:53 +00:00
"Wrong result for ExtractStructured worklet");
VTKM_TEST_ASSERT(test_equal(outCellSet.GetNumberOfCells(), 1),
2017-04-13 18:36:53 +00:00
"Wrong result for ExtractStructured worklet");
2017-04-27 20:53:51 +00:00
// RangeId3 and subsample
vtkm::RangeId3 range2(0, 5, 0, 5, 1, 4);
2017-05-18 14:29:41 +00:00
vtkm::Id3 sample2(3, 3, 2);
2017-04-27 20:53:51 +00:00
bool includeBoundary2 = true;
2019-04-18 03:13:36 +00:00
bool includeOffset = true;
2017-04-27 20:53:51 +00:00
2019-04-18 03:13:36 +00:00
outCellSet = worklet.Run(cellSet, range2, sample2, includeBoundary2, includeOffset);
2017-04-27 20:53:51 +00:00
VTKM_TEST_ASSERT(test_equal(outCellSet.GetNumberOfPoints(), 18),
2017-04-27 20:53:51 +00:00
"Wrong result for ExtractStructured worklet");
VTKM_TEST_ASSERT(test_equal(outCellSet.GetNumberOfCells(), 4),
2017-04-27 20:53:51 +00:00
"Wrong result for ExtractStructured worklet");
2017-04-13 18:36:53 +00:00
}
void TestRectilinear2D() const
{
std::cout << "Testing extract structured rectilinear" << std::endl;
2018-02-22 13:29:13 +00:00
using CellSetType = vtkm::cont::CellSetStructured<2>;
2017-05-18 14:29:41 +00:00
// Create the input uniform cell set
vtkm::cont::DataSet dataSet = MakeTestDataSet().Make2DRectilinearDataSet0();
CellSetType cellSet;
dataSet.GetCellSet(0).CopyTo(cellSet);
// RangeId3 and subsample
vtkm::RangeId3 range(0, 2, 0, 2, 0, 1);
2017-05-18 14:29:41 +00:00
vtkm::Id3 sample(1, 1, 1);
2017-04-27 20:53:51 +00:00
bool includeBoundary = false;
2019-04-18 03:13:36 +00:00
bool includeOffset = false;
2017-05-18 14:29:41 +00:00
// Extract subset
vtkm::worklet::ExtractStructured worklet;
2019-04-18 03:13:36 +00:00
auto outCellSet = worklet.Run(cellSet, range, sample, includeBoundary, includeOffset);
2017-05-18 14:29:41 +00:00
VTKM_TEST_ASSERT(test_equal(outCellSet.GetNumberOfPoints(), 4),
2017-04-06 20:11:49 +00:00
"Wrong result for ExtractStructured worklet");
VTKM_TEST_ASSERT(test_equal(outCellSet.GetNumberOfCells(), 1),
2017-04-06 20:11:49 +00:00
"Wrong result for ExtractStructured worklet");
}
void TestRectilinear3D() const
{
std::cout << "Testing extract structured rectilinear" << std::endl;
2018-02-22 13:29:13 +00:00
using CellSetType = vtkm::cont::CellSetStructured<3>;
2017-05-18 14:29:41 +00:00
// Create the input uniform cell set
vtkm::cont::DataSet dataSet = MakeTestDataSet().Make3DRectilinearDataSet0();
CellSetType cellSet;
dataSet.GetCellSet(0).CopyTo(cellSet);
// RangeId3 and subsample
vtkm::RangeId3 range(0, 2, 0, 2, 0, 2);
2017-05-18 14:29:41 +00:00
vtkm::Id3 sample(1, 1, 1);
2017-04-27 20:53:51 +00:00
bool includeBoundary = false;
2019-04-18 03:13:36 +00:00
bool includeOffset = false;
2017-05-18 14:29:41 +00:00
// Extract subset
vtkm::worklet::ExtractStructured worklet;
2019-04-18 03:13:36 +00:00
auto outCellSet = worklet.Run(cellSet, range, sample, includeBoundary, includeOffset);
2017-05-18 14:29:41 +00:00
VTKM_TEST_ASSERT(test_equal(outCellSet.GetNumberOfPoints(), 8),
2017-04-06 20:11:49 +00:00
"Wrong result for ExtractStructured worklet");
VTKM_TEST_ASSERT(test_equal(outCellSet.GetNumberOfCells(), 1),
2017-04-06 20:11:49 +00:00
"Wrong result for ExtractStructured worklet");
}
2019-04-18 03:13:36 +00:00
void TestOffset3D() const
{
std::cout << "Testing structured rectilinear" << std::endl;
using CellSetType = vtkm::cont::CellSetStructured<3>;
// Create the input uniform cell set
vtkm::cont::DataSet dataSet = MakeTestDataSet().Make3DRectilinearDataSet0();
CellSetType cellSet;
dataSet.GetCellSet(0).CopyTo(cellSet);
// RangeID3 and subsample
vtkm::RangeId3 range(0, 2, 0, 2, 0, 2);
vtkm::Id3 sample(1, 1, 1);
vtkm::Id3 test_offset(1, 1, 1);
vtkm::Id3 origin_offset(1, 1, 1);
vtkm::Id3 no_offset(0, 0, 0);
bool includeBoundary = false;
bool includeOffset = true;
// Extract subset
vtkm::worklet::ExtractStructured worklet;
auto outCellSet = worklet.Run(cellSet, range, sample, includeBoundary, includeOffset);
cellSet.SetGlobalPointIndexStart(test_offset);
//VTKM_TEST_ASSERT(test_equal(outCellSet.GetGlobelPointIndexStart(), offset));
//VTKM_TEST_ASSERT(test_equal(outCellSet.GetIncludeOffset(), offset));
VTKM_TEST_ASSERT(test_equal(worklet.GetIncludeOffset(), includeOffset));
//VTKM_TEST_ASSERT(test_equal(outCellSet.GetIncludeOffset(), false));
}
void operator()() const
{
TestUniform2D();
TestUniform3D();
2017-04-13 18:36:53 +00:00
TestUniform3D1();
TestRectilinear2D();
2017-04-06 20:11:49 +00:00
TestRectilinear3D();
2019-04-18 03:13:36 +00:00
TestOffset3D();
}
};
int UnitTestExtractStructured(int argc, char* argv[])
{
return vtkm::cont::testing::Testing::Run(TestingExtractStructured(), argc, argv);
}