vtk-m2/vtkm/filter/NewFilterField.cxx
Kenneth Moreland 5bd60a0b77 Add CreateResult to NewFilter and absorb field mapping
The original version of `Filter` classes had a helper header file named
`CreateResult.h` that had several forms of a `CreateResult` function that
helped correctly create the `DataSet` to be returned from a filter's
`DoExecute`. With the move to the `NewFilter` structure, these functions
did not line up very well with how `DataSet`s should actually be created.

A replacement for these functions have been added as protected helper
methods to `NewFilter` and `NewFilterField`. In addition to moving them
into the filter themselves, the behavior of `CreateResult` has been merged
with the map field to output functionality. The original implementation of
`Filter` did this mapping internally in a different step. The first design
of `NewFilter` required the filter implementer to call a
`MapFieldsOntoOutput` themselves. This new implementation wraps the
functionality of `CreateResult` and `MapFieldsOntoOutput` together so that
the `DataSet` will be created correctly with a single call to
`CreateResult`. This makes it easier to correctly create the output.
2022-01-27 13:27:39 -07:00

47 lines
1.6 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/filter/NewFilterField.h>
namespace vtkm
{
namespace filter
{
vtkm::cont::DataSet NewFilterField::CreateResultField(const vtkm::cont::DataSet& inDataSet,
const vtkm::cont::Field& resultField) const
{
vtkm::cont::DataSet outDataSet = this->CreateResult(inDataSet);
outDataSet.AddField(resultField);
VTKM_ASSERT(!resultField.GetName().empty());
VTKM_ASSERT(outDataSet.HasField(resultField.GetName(), resultField.GetAssociation()));
return outDataSet;
}
void NewFilterField::ResizeIfNeeded(size_t index_st)
{
if (this->ActiveFieldNames.size() <= index_st)
{
auto oldSize = this->ActiveFieldNames.size();
this->ActiveFieldNames.resize(index_st + 1);
this->ActiveFieldAssociation.resize(index_st + 1);
this->UseCoordinateSystemAsField.resize(index_st + 1);
this->ActiveCoordinateSystemIndices.resize(index_st + 1);
for (std::size_t i = oldSize; i <= index_st; ++i)
{
this->ActiveFieldAssociation[i] = cont::Field::Association::ANY;
this->UseCoordinateSystemAsField[i] = false;
this->ActiveCoordinateSystemIndices[i] = 0;
}
}
}
} // namespace filter
} // namespace vtkm