vtk-m/vtkm/filter/contour/ClipWithImplicitFunction.cxx

81 lines
2.5 KiB
C++
Raw Normal View History

2022-01-11 12:58:47 +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.
//============================================================================
#include <vtkm/cont/CoordinateSystem.h>
#include <vtkm/cont/UnknownCellSet.h>
#include <vtkm/filter/MapFieldPermutation.h>
#include <vtkm/filter/contour/ClipWithImplicitFunction.h>
#include <vtkm/filter/contour/worklet/Clip.h>
namespace vtkm
{
namespace filter
{
namespace contour
{
namespace
{
bool DoMapField(vtkm::cont::DataSet& result,
const vtkm::cont::Field& field,
vtkm::worklet::Clip& worklet)
2022-01-11 12:58:47 +00:00
{
if (field.IsPointField())
2022-01-11 12:58:47 +00:00
{
auto resolve = [&](const auto& concrete) {
// use std::decay to remove const ref from the decltype of concrete.
using T = typename std::decay_t<decltype(concrete)>::ValueType;
2022-01-11 12:58:47 +00:00
vtkm::cont::ArrayHandle<T> outputArray;
worklet.ProcessPointField(concrete, outputArray);
2022-01-11 12:58:47 +00:00
result.AddPointField(field.GetName(), outputArray);
};
2022-02-02 19:44:00 +00:00
field.GetData()
.CastAndCallForTypesWithFloatFallback<VTKM_DEFAULT_TYPE_LIST, VTKM_DEFAULT_STORAGE_LIST>(
2022-02-02 19:44:00 +00:00
resolve);
2022-01-11 12:58:47 +00:00
return true;
}
else if (field.IsCellField())
2022-01-11 12:58:47 +00:00
{
// Use the precompiled field permutation function.
vtkm::cont::ArrayHandle<vtkm::Id> permutation = worklet.GetCellMapOutputToInput();
2022-01-11 12:58:47 +00:00
return vtkm::filter::MapFieldPermutation(field, permutation, result);
}
else if (field.IsWholeDataSetField())
2022-01-11 12:58:47 +00:00
{
result.AddField(field);
return true;
}
else
{
return false;
}
}
} // anonymous namespace
//-----------------------------------------------------------------------------
vtkm::cont::DataSet ClipWithImplicitFunction::DoExecute(const vtkm::cont::DataSet& input)
{
2022-01-28 15:48:26 +00:00
const vtkm::cont::UnknownCellSet& inputCellSet = input.GetCellSet();
2022-01-11 12:58:47 +00:00
const vtkm::cont::CoordinateSystem& inputCoords =
input.GetCoordinateSystem(this->GetActiveCoordinateSystemIndex());
2022-01-28 15:48:26 +00:00
vtkm::worklet::Clip worklet;
2022-01-11 12:58:47 +00:00
vtkm::cont::CellSetExplicit<> outputCellSet =
worklet.Run(inputCellSet, this->Function, this->Offset, inputCoords, this->Invert);
2022-01-11 12:58:47 +00:00
2022-01-28 15:48:26 +00:00
auto mapper = [&](auto& result, const auto& f) { DoMapField(result, f, worklet); };
return this->CreateResult(input, outputCellSet, mapper);
2022-01-11 12:58:47 +00:00
}
} // namespace contour
} // namespace filter
} // namespace vtkm