mirror of
https://gitlab.kitware.com/vtk/vtk-m
synced 2024-09-19 18:45:43 +00:00
2d30e6d45a
Previously, `DataSet` managed `CoordinateSystem`s separately from `Field`s. However, a `CoordinateSystem` is really just a `Field` with some special attributes. Thus, coordiante systems are now just listed along with the rest of the fields, and the coordinate systems are simply strings that point back to the appropriate field. (This was actually the original concept for `DataSet`, but the coordinate systems were separated from fields for some now obsolete reasons.)
68 lines
2.1 KiB
C++
68 lines
2.1 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/cont/ErrorBadValue.h>
|
|
#include <vtkm/filter/field_transform/CylindricalCoordinateTransform.h>
|
|
#include <vtkm/filter/field_transform/worklet/CoordinateSystemTransform.h>
|
|
|
|
namespace vtkm
|
|
{
|
|
namespace filter
|
|
{
|
|
namespace field_transform
|
|
{
|
|
|
|
CylindricalCoordinateTransform::CylindricalCoordinateTransform()
|
|
{
|
|
this->SetUseCoordinateSystemAsField(true);
|
|
}
|
|
|
|
vtkm::cont::DataSet CylindricalCoordinateTransform::DoExecute(const vtkm::cont::DataSet& inDataSet)
|
|
{
|
|
vtkm::cont::UnknownArrayHandle outArray;
|
|
|
|
const vtkm::cont::Field& inField = this->GetFieldFromDataSet(inDataSet);
|
|
if (!inField.IsPointField())
|
|
{
|
|
throw vtkm::cont::ErrorBadValue("CylindricalCoordinateTransform only applies to point data.");
|
|
}
|
|
|
|
auto resolveType = [&](const auto& concrete) {
|
|
// use std::decay to remove const ref from the decltype of concrete.
|
|
using T = typename std::decay_t<decltype(concrete)>::ValueType;
|
|
vtkm::cont::ArrayHandle<T> result;
|
|
if (this->CartesianToCylindrical)
|
|
this->Invoke(vtkm::worklet::CarToCyl{}, concrete, result);
|
|
else
|
|
this->Invoke(vtkm::worklet::CylToCar{}, concrete, result);
|
|
outArray = result;
|
|
};
|
|
this->CastAndCallVecField<3>(inField, resolveType);
|
|
|
|
std::string coordinateName = this->GetOutputFieldName();
|
|
if (coordinateName.empty())
|
|
{
|
|
coordinateName = inField.GetName();
|
|
}
|
|
|
|
vtkm::cont::DataSet outDataSet = this->CreateResultCoordinateSystem(
|
|
inDataSet,
|
|
inDataSet.GetCellSet(),
|
|
vtkm::cont::CoordinateSystem(coordinateName, outArray),
|
|
[](vtkm::cont::DataSet& out, const vtkm::cont::Field& fieldToPass) {
|
|
out.AddField(fieldToPass);
|
|
});
|
|
return outDataSet;
|
|
}
|
|
|
|
} // namespace field_transform
|
|
} // namespace filter
|
|
} // namespace vtkm
|