mirror of
https://gitlab.kitware.com/vtk/vtk-m
synced 2024-10-05 18:08:59 +00:00
be7f06bbe7
`CoordinateSystem` differed from `Field` in that its `GetData` method returned an `ArrayHandleVirtualCoordinates` instead of a `VariantArrayHandle`. This is probably confusing since `CoordianteSystem` inherits `Field` and has a pretty dramatic difference in this behavior. In preparation to deprecate `ArrayHandleVirtualCoordinates`, this changes `CoordiantSystem` to be much more like `Field`. (In the future, we may change the `CoordinateSystem` to point to a `Field` rather than be a special `Field`.) A method named `GetDataAsMultiplexer` has been added to `CoordinateSystem`. This method allows you to get data from `CoordinateSystem` as a single array type without worrying about creating functors to handle different types and without needing virtual methods.
95 lines
3.0 KiB
C++
95 lines
3.0 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.
|
|
//============================================================================
|
|
|
|
#include <vtkm/worklet/DispatcherMapField.h>
|
|
#include <vtkm/worklet/PointElevation.h>
|
|
|
|
#include <vtkm/cont/CellSetExplicit.h>
|
|
#include <vtkm/cont/DataSet.h>
|
|
|
|
#include <vtkm/cont/testing/Testing.h>
|
|
|
|
#include <vector>
|
|
|
|
namespace
|
|
{
|
|
|
|
vtkm::cont::DataSet MakePointElevationTestDataSet()
|
|
{
|
|
vtkm::cont::DataSet dataSet;
|
|
|
|
std::vector<vtkm::Vec3f_32> coordinates;
|
|
const vtkm::Id dim = 5;
|
|
for (vtkm::Id j = 0; j < dim; ++j)
|
|
{
|
|
vtkm::Float32 z = static_cast<vtkm::Float32>(j) / static_cast<vtkm::Float32>(dim - 1);
|
|
for (vtkm::Id i = 0; i < dim; ++i)
|
|
{
|
|
vtkm::Float32 x = static_cast<vtkm::Float32>(i) / static_cast<vtkm::Float32>(dim - 1);
|
|
vtkm::Float32 y = (x * x + z * z) / 2.0f;
|
|
coordinates.push_back(vtkm::make_Vec(x, y, z));
|
|
}
|
|
}
|
|
|
|
vtkm::Id numCells = (dim - 1) * (dim - 1);
|
|
dataSet.AddCoordinateSystem(
|
|
vtkm::cont::make_CoordinateSystem("coordinates", coordinates, vtkm::CopyFlag::On));
|
|
|
|
vtkm::cont::CellSetExplicit<> cellSet;
|
|
cellSet.PrepareToAddCells(numCells, numCells * 4);
|
|
for (vtkm::Id j = 0; j < dim - 1; ++j)
|
|
{
|
|
for (vtkm::Id i = 0; i < dim - 1; ++i)
|
|
{
|
|
cellSet.AddCell(vtkm::CELL_SHAPE_QUAD,
|
|
4,
|
|
vtkm::make_Vec<vtkm::Id>(
|
|
j * dim + i, j * dim + i + 1, (j + 1) * dim + i + 1, (j + 1) * dim + i));
|
|
}
|
|
}
|
|
cellSet.CompleteAddingCells(vtkm::Id(coordinates.size()));
|
|
|
|
dataSet.SetCellSet(cellSet);
|
|
return dataSet;
|
|
}
|
|
}
|
|
|
|
void TestPointElevation()
|
|
{
|
|
std::cout << "Testing PointElevation Worklet" << std::endl;
|
|
|
|
vtkm::cont::DataSet dataSet = MakePointElevationTestDataSet();
|
|
|
|
vtkm::cont::ArrayHandle<vtkm::Float32> result;
|
|
|
|
vtkm::worklet::PointElevation pointElevationWorklet;
|
|
pointElevationWorklet.SetLowPoint(vtkm::make_Vec<vtkm::Float64>(0.0, 0.0, 0.0));
|
|
pointElevationWorklet.SetHighPoint(vtkm::make_Vec<vtkm::Float64>(0.0, 1.0, 0.0));
|
|
pointElevationWorklet.SetRange(0.0, 2.0);
|
|
|
|
vtkm::worklet::DispatcherMapField<vtkm::worklet::PointElevation> dispatcher(
|
|
pointElevationWorklet);
|
|
dispatcher.Invoke(dataSet.GetCoordinateSystem(), result);
|
|
|
|
auto coordinates = dataSet.GetCoordinateSystem().GetDataAsMultiplexer();
|
|
auto coordinatesPortal = coordinates.ReadPortal();
|
|
auto resultPortal = result.ReadPortal();
|
|
for (vtkm::Id i = 0; i < result.GetNumberOfValues(); ++i)
|
|
{
|
|
VTKM_TEST_ASSERT(test_equal(coordinatesPortal.Get(i)[1] * 2.0, resultPortal.Get(i)),
|
|
"Wrong result for PointElevation worklet");
|
|
}
|
|
}
|
|
|
|
int UnitTestPointElevation(int argc, char* argv[])
|
|
{
|
|
return vtkm::cont::testing::Testing::Run(TestPointElevation, argc, argv);
|
|
}
|