adding inverted clip unit tests

This commit is contained in:
Matt Larsen 2018-03-09 13:51:28 -08:00
parent 2daba82188
commit 0d671bcb22
2 changed files with 102 additions and 0 deletions

@ -93,10 +93,53 @@ void TestClipStructured()
}
}
void TestClipStructuredInverted()
{
std::cout << "Testing ClipWithImplicitFunctionInverted Filter on Structured data" << std::endl;
vtkm::cont::DataSet ds = MakeTestDatasetStructured();
vtkm::Vec<vtkm::FloatDefault, 3> center(1, 1, 0);
vtkm::FloatDefault radius(0.5);
vtkm::filter::Result result;
vtkm::filter::ClipWithImplicitFunction clip;
clip.SetImplicitFunction(vtkm::cont::make_ImplicitFunctionHandle(vtkm::Sphere(center, radius)));
bool invert = true;
clip.SetInvertClip(invert);
result = clip.Execute(ds);
clip.MapFieldOntoOutput(result, ds.GetField("scalars"));
const vtkm::cont::DataSet& outputData = result.GetDataSet();
VTKM_TEST_ASSERT(outputData.GetNumberOfCellSets() == 1,
"Wrong number of cellsets in the output dataset");
VTKM_TEST_ASSERT(outputData.GetNumberOfCoordinateSystems() == 1,
"Wrong number of coordinate systems in the output dataset");
VTKM_TEST_ASSERT(outputData.GetNumberOfFields() == 1,
"Wrong number of fields in the output dataset");
VTKM_TEST_ASSERT(outputData.GetCellSet().GetNumberOfCells() == 4,
"Wrong number of cells in the output dataset");
vtkm::cont::DynamicArrayHandle temp = outputData.GetField("scalars").GetData();
vtkm::cont::ArrayHandle<vtkm::Float32> resultArrayHandle;
temp.CopyTo(resultArrayHandle);
VTKM_TEST_ASSERT(resultArrayHandle.GetNumberOfValues() == 13,
"Wrong number of points in the output dataset");
vtkm::Float32 expected[13] = { 1, 1, 1, 1, 0, 1, 1, 1, 1, 0.25, 0.25, 0.25, 0.25 };
for (int i = 0; i < 13; ++i)
{
VTKM_TEST_ASSERT(test_equal(resultArrayHandle.GetPortalConstControl().Get(i), expected[i]),
"Wrong result for ClipWithImplicitFunction fliter on sturctured quads data");
}
}
void TestClip()
{
//todo: add more clip tests
TestClipStructured();
TestClipStructuredInverted();
}
} // anonymous namespace

@ -300,6 +300,64 @@ void TestClippingWithImplicitFunction()
"Got incorrect cellvar");
}
template <typename DeviceAdapter>
void TestClippingWithImplicitFunctionInverted()
{
vtkm::Vec<vtkm::FloatDefault, 3> center(1, 1, 0);
vtkm::FloatDefault radius(0.5);
vtkm::cont::DataSet ds = MakeTestDatasetStructured();
bool invertClip = true;
vtkm::worklet::Clip clip;
vtkm::cont::CellSetExplicit<> outputCellSet =
clip.Run(ds.GetCellSet(0),
vtkm::cont::make_ImplicitFunctionHandle<vtkm::Sphere>(center, radius),
ds.GetCoordinateSystem("coords"),
invertClip,
DeviceAdapter());
auto coordsIn = ds.GetCoordinateSystem("coords").GetData();
vtkm::cont::ArrayHandle<Coord3D> coords = clip.ProcessPointField(coordsIn, DeviceAdapter());
vtkm::cont::ArrayHandle<vtkm::Float32> scalarsIn;
ds.GetField("scalars").GetData().CopyTo(scalarsIn);
vtkm::cont::ArrayHandle<vtkm::Float32> scalars =
clip.ProcessPointField(scalarsIn, DeviceAdapter());
vtkm::cont::ArrayHandle<vtkm::Float32> cellvarIn;
ds.GetField("cellvar").GetData().CopyTo(cellvarIn);
vtkm::cont::ArrayHandle<vtkm::Float32> cellvar =
clip.ProcessCellField(cellvarIn, DeviceAdapter());
vtkm::Id connectivitySize = 12;
vtkm::Id fieldSize = 13;
vtkm::Id expectedConnectivity[] = { 4, 10, 9, 4, 9, 11, 4, 12, 10, 4, 11, 12 };
Coord3D expectedCoords[] = {
Coord3D(0.0f, 0.0f, 0.0f), Coord3D(1.0f, 0.0f, 0.0f), Coord3D(2.0f, 0.0f, 0.0f),
Coord3D(0.0f, 1.0f, 0.0f), Coord3D(1.0f, 1.0f, 0.0f), Coord3D(2.0f, 1.0f, 0.0f),
Coord3D(0.0f, 2.0f, 0.0f), Coord3D(1.0f, 2.0f, 0.0f), Coord3D(2.0f, 2.0f, 0.0f),
Coord3D(1.0f, 0.75f, 0.0f), Coord3D(0.75f, 1.0f, 0.0f), Coord3D(1.25f, 1.0f, 0.0f),
Coord3D(1.0f, 1.25f, 0.0f),
};
vtkm::Float32 expectedScalars[] = { 1, 1, 1, 1, 0, 1, 1, 1, 1, 0.25, 0.25, 0.25, 0.25 };
std::vector<vtkm::Float32> expectedCellvar = { -100.f, 100.f, 30.f, -30.f };
VTKM_TEST_ASSERT(
TestArrayHandle(outputCellSet.GetConnectivityArray(vtkm::TopologyElementTagPoint(),
vtkm::TopologyElementTagCell()),
expectedConnectivity,
connectivitySize),
"Got incorrect conectivity");
VTKM_TEST_ASSERT(TestArrayHandle(coords, expectedCoords, fieldSize), "Got incorrect coordinates");
VTKM_TEST_ASSERT(TestArrayHandle(scalars, expectedScalars, fieldSize), "Got incorrect scalars");
VTKM_TEST_ASSERT(
TestArrayHandle(cellvar, expectedCellvar.data(), static_cast<vtkm::Id>(expectedCellvar.size())),
"Got incorrect cellvar");
}
template <typename DeviceAdapter>
void TestClipping()
{
@ -309,6 +367,7 @@ void TestClipping()
TestClippingStrucutred<DeviceAdapter>();
std::cout << "Testing clipping with implicit function (sphere):" << std::endl;
TestClippingWithImplicitFunction<DeviceAdapter>();
TestClippingWithImplicitFunctionInverted<DeviceAdapter>();
}
int UnitTestClipping(int, char* [])