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,
|
2023-01-13 16:45:25 +00:00
|
|
|
vtkm::worklet::Clip& worklet)
|
2022-01-11 12:58:47 +00:00
|
|
|
{
|
2022-08-29 18:42:02 +00:00
|
|
|
if (field.IsPointField())
|
2022-01-11 12:58:47 +00:00
|
|
|
{
|
2022-01-28 19:20:01 +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;
|
2023-01-13 16:45:25 +00:00
|
|
|
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()
|
2022-10-13 16:14:45 +00:00
|
|
|
.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;
|
|
|
|
}
|
2022-08-29 18:42:02 +00:00
|
|
|
else if (field.IsCellField())
|
2022-01-11 12:58:47 +00:00
|
|
|
{
|
|
|
|
// Use the precompiled field permutation function.
|
2023-01-13 16:45:25 +00:00
|
|
|
vtkm::cont::ArrayHandle<vtkm::Id> permutation = worklet.GetCellMapOutputToInput();
|
2022-01-11 12:58:47 +00:00
|
|
|
return vtkm::filter::MapFieldPermutation(field, permutation, result);
|
|
|
|
}
|
2022-08-29 18:42:02 +00:00
|
|
|
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 =
|
2022-09-12 13:40:08 +00:00
|
|
|
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); };
|
2023-01-13 16:45:25 +00:00
|
|
|
return this->CreateResult(input, outputCellSet, mapper);
|
2022-01-11 12:58:47 +00:00
|
|
|
}
|
|
|
|
} // namespace contour
|
|
|
|
} // namespace filter
|
|
|
|
} // namespace vtkm
|