mirror of
https://gitlab.kitware.com/vtk/vtk-m
synced 2024-09-08 13:23:51 +00:00
Fix the passing of fields in filters
While updating the user's guide, I noticed a couple of minor problems with how filters map fields. First, if a filter was using `CreateResultCoordinateSystem`, it did not respect the `PassCoordinateSystems` flag. Second, if both an `initializer_list` and a mode was given to `SetFieldsToPass`, the mode was captured incorrectly. Both problems are corrected.
This commit is contained in:
parent
48059d0de3
commit
5a141349a9
26
docs/changelog/fix-filter-pass-fields.md
Normal file
26
docs/changelog/fix-filter-pass-fields.md
Normal file
@ -0,0 +1,26 @@
|
||||
# Fix setting fields to pass in `Filter` when setting mode
|
||||
|
||||
The `Filter` class has several version of the `SetFieldsToPass` method that
|
||||
works in conjunction with the `FieldSelection` object to specify which
|
||||
fields are mapped. For example, the user might have code like this to pass
|
||||
all fields except those named `pointvar` and `cellvar`:
|
||||
|
||||
``` cpp
|
||||
filter.SetFieldsToPass({ "pointvar", "cellvar" },
|
||||
vtkm::filter::FieldSelection::Mode::Exclude);
|
||||
```
|
||||
|
||||
This previously worked by implicitly creating a `FieldSelection` object
|
||||
using the `std::initializer_list` filled with the 2 strings. This would
|
||||
then be passed to the `SetFieldsToPass` method, which would capture the
|
||||
`FieldSelection` object and change the mode.
|
||||
|
||||
This stopped working in a recent change to `FieldSelection` where each
|
||||
entry is given its own mode. With this new class, the `FieldSelection`
|
||||
constructor would capture each field in the default mode (`Select`) and
|
||||
then change the default mode to `Exclude`. However, the already set modes
|
||||
kept their `Select` status, which is not what is intended.
|
||||
|
||||
This behavior is fixed by adding `SetFieldToPass` overloads that capture
|
||||
both the `initializer_list` and the `Mode` and then constructs the
|
||||
`FieldSelection` correctly.
|
9
docs/changelog/fix-pass-coords.md
Normal file
9
docs/changelog/fix-pass-coords.md
Normal file
@ -0,0 +1,9 @@
|
||||
# Respect `Filter::PassCoordinateSystem` flag in filters creating coordinate systems
|
||||
|
||||
The `Filter` class has a `PassCoordinateSystem` flag that specifies whether
|
||||
coordinate systems should be passed regardless of whether the associated
|
||||
field is passed. However, if a filter created its output with the
|
||||
`CreateResultCoordinateSystem` method this flag was ignored, and the
|
||||
provided coordinate system was always passed. This might not be what the
|
||||
user intended, so this method has been fixed to first check the
|
||||
`PassCoordinateSystem` flag before setting the coordinates on the output.
|
@ -40,7 +40,7 @@ void RunFilter(Filter* self, vtkm::filter::DataSetQueue& input, vtkm::filter::Da
|
||||
tracker.SetThreadFriendlyMemAlloc(prevVal);
|
||||
}
|
||||
|
||||
}
|
||||
} // anonymous namespace
|
||||
|
||||
Filter::~Filter() = default;
|
||||
|
||||
@ -49,6 +49,45 @@ bool Filter::CanThread() const
|
||||
return true;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
void Filter::SetFieldsToPass(const vtkm::filter::FieldSelection& fieldsToPass)
|
||||
{
|
||||
this->FieldsToPass = fieldsToPass;
|
||||
}
|
||||
|
||||
void Filter::SetFieldsToPass(vtkm::filter::FieldSelection&& fieldsToPass)
|
||||
{
|
||||
this->FieldsToPass = std::move(fieldsToPass);
|
||||
}
|
||||
|
||||
void Filter::SetFieldsToPass(const vtkm::filter::FieldSelection& fieldsToPass,
|
||||
vtkm::filter::FieldSelection::Mode mode)
|
||||
{
|
||||
this->FieldsToPass = fieldsToPass;
|
||||
this->FieldsToPass.SetMode(mode);
|
||||
}
|
||||
|
||||
VTKM_CONT void Filter::SetFieldsToPass(std::initializer_list<std::string> fields,
|
||||
vtkm::filter::FieldSelection::Mode mode)
|
||||
{
|
||||
this->SetFieldsToPass(vtkm::filter::FieldSelection{ fields, mode });
|
||||
}
|
||||
|
||||
void Filter::SetFieldsToPass(
|
||||
std::initializer_list<std::pair<std::string, vtkm::cont::Field::Association>> fields,
|
||||
vtkm::filter::FieldSelection::Mode mode)
|
||||
{
|
||||
this->SetFieldsToPass(vtkm::filter::FieldSelection{ fields, mode });
|
||||
}
|
||||
|
||||
void Filter::SetFieldsToPass(const std::string& fieldname,
|
||||
vtkm::cont::Field::Association association,
|
||||
vtkm::filter::FieldSelection::Mode mode)
|
||||
{
|
||||
this->SetFieldsToPass(vtkm::filter::FieldSelection{ fieldname, association, mode });
|
||||
}
|
||||
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
vtkm::cont::PartitionedDataSet Filter::DoExecutePartitions(
|
||||
const vtkm::cont::PartitionedDataSet& input)
|
||||
|
@ -263,27 +263,31 @@ public:
|
||||
///
|
||||
/// By default, all fields are passed during execution.
|
||||
///
|
||||
VTKM_CONT
|
||||
void SetFieldsToPass(const vtkm::filter::FieldSelection& fieldsToPass)
|
||||
{
|
||||
this->FieldsToPass = fieldsToPass;
|
||||
}
|
||||
VTKM_CONT void SetFieldsToPass(const vtkm::filter::FieldSelection& fieldsToPass);
|
||||
VTKM_CONT void SetFieldsToPass(vtkm::filter::FieldSelection&& fieldsToPass);
|
||||
|
||||
VTKM_CONT
|
||||
void SetFieldsToPass(const vtkm::filter::FieldSelection& fieldsToPass,
|
||||
vtkm::filter::FieldSelection::Mode mode)
|
||||
{
|
||||
this->FieldsToPass = fieldsToPass;
|
||||
this->FieldsToPass.SetMode(mode);
|
||||
}
|
||||
VTKM_DEPRECATED(2.0)
|
||||
VTKM_CONT void SetFieldsToPass(const vtkm::filter::FieldSelection& fieldsToPass,
|
||||
vtkm::filter::FieldSelection::Mode mode);
|
||||
|
||||
VTKM_CONT
|
||||
void SetFieldsToPass(
|
||||
VTKM_CONT void SetFieldsToPass(
|
||||
std::initializer_list<std::string> fields,
|
||||
vtkm::filter::FieldSelection::Mode mode = vtkm::filter::FieldSelection::Mode::Select);
|
||||
|
||||
VTKM_CONT void SetFieldsToPass(
|
||||
std::initializer_list<std::pair<std::string, vtkm::cont::Field::Association>> fields,
|
||||
vtkm::filter::FieldSelection::Mode mode = vtkm::filter::FieldSelection::Mode::Select);
|
||||
|
||||
|
||||
VTKM_CONT void SetFieldsToPass(
|
||||
const std::string& fieldname,
|
||||
vtkm::cont::Field::Association association,
|
||||
vtkm::filter::FieldSelection::Mode mode = vtkm::filter::FieldSelection::Mode::Select)
|
||||
vtkm::filter::FieldSelection::Mode mode = vtkm::filter::FieldSelection::Mode::Select);
|
||||
|
||||
VTKM_CONT void SetFieldsToPass(const std::string& fieldname,
|
||||
vtkm::filter::FieldSelection::Mode mode)
|
||||
{
|
||||
this->SetFieldsToPass({ fieldname, association }, mode);
|
||||
this->SetFieldsToPass(fieldname, vtkm::cont::Field::Association::Any, mode);
|
||||
}
|
||||
|
||||
VTKM_CONT
|
||||
@ -442,9 +446,12 @@ protected:
|
||||
{
|
||||
vtkm::cont::DataSet outDataSet;
|
||||
outDataSet.SetCellSet(resultCellSet);
|
||||
outDataSet.AddCoordinateSystem(resultCoordSystem);
|
||||
vtkm::filter::FieldSelection fieldSelection = this->GetFieldsToPass();
|
||||
fieldSelection.AddField(resultCoordSystem, vtkm::filter::FieldSelection::Mode::Exclude);
|
||||
if (this->GetPassCoordinateSystems() || fieldSelection.HasField(resultCoordSystem))
|
||||
{
|
||||
outDataSet.AddCoordinateSystem(resultCoordSystem);
|
||||
fieldSelection.AddField(resultCoordSystem, vtkm::filter::FieldSelection::Mode::Exclude);
|
||||
}
|
||||
this->MapFieldsOntoOutput(inDataSet, fieldSelection, outDataSet, fieldMapper);
|
||||
return outDataSet;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user