mirror of
https://gitlab.kitware.com/vtk/vtk-m
synced 2024-09-08 13:23:51 +00:00
Enable any scalar field in ParticleDensity filters
This is done using the `CastAndCallScalarField` from `FilterField`, which uses a cast-and-call with a float fallback.
This commit is contained in:
parent
d38efa87f2
commit
0ba818e907
@ -1,4 +1,4 @@
|
|||||||
# Update filters' field map to work on any field type
|
# Update filters' field map and execute to work on any field type
|
||||||
|
|
||||||
Several filters implemented their map field by checking for common field
|
Several filters implemented their map field by checking for common field
|
||||||
types and interpolated those. Although there was a float fallback to catch
|
types and interpolated those. Although there was a float fallback to catch
|
||||||
@ -10,7 +10,8 @@ so it is still possible to drop fields.
|
|||||||
The map field functions for these filters have been changed to support all
|
The map field functions for these filters have been changed to support all
|
||||||
possible types. This is done by using the extract component functionality
|
possible types. This is done by using the extract component functionality
|
||||||
to get data from any type of array. The following filters have been
|
to get data from any type of array. The following filters have been
|
||||||
updated.
|
updated. In some circumstances where it makes sense, a simple float
|
||||||
|
fallback is used.
|
||||||
|
|
||||||
* `CleanGrid`
|
* `CleanGrid`
|
||||||
* `CellAverage`
|
* `CellAverage`
|
||||||
@ -20,3 +21,5 @@ updated.
|
|||||||
* `MIRFilter`
|
* `MIRFilter`
|
||||||
* `PointAverage`
|
* `PointAverage`
|
||||||
* `NDHistogram`
|
* `NDHistogram`
|
||||||
|
* `ParticleDensityCloudInCell`
|
||||||
|
* `ParticleDensityNearestGridPoint`
|
||||||
|
@ -111,28 +111,15 @@ VTKM_CONT vtkm::cont::DataSet ParticleDensityCloudInCell::DoExecute(const cont::
|
|||||||
uniform.AddField(vtkm::cont::make_FieldPoint("density", density));
|
uniform.AddField(vtkm::cont::make_FieldPoint("density", density));
|
||||||
};
|
};
|
||||||
|
|
||||||
// Note: This is the so called Immediately-Invoked Function Expression (IIFE). Here we define
|
if (this->ComputeNumberDensity)
|
||||||
// a lambda expression and immediately call it at the end. This allows us to not declare an
|
{
|
||||||
// UnknownArrayHandle first and then assign it in the if-else statement. If I really want to
|
resolveType(
|
||||||
// show-off, I can even inline the `fieldArray` variable and turn it into a long expression.
|
vtkm::cont::make_ArrayHandleConstant(vtkm::FloatDefault{ 1 }, input.GetNumberOfPoints()));
|
||||||
auto fieldArray = [&]() -> vtkm::cont::UnknownArrayHandle {
|
}
|
||||||
if (this->ComputeNumberDensity)
|
else
|
||||||
{
|
{
|
||||||
return vtkm::cont::make_ArrayHandleConstant(vtkm::FloatDefault{ 1 },
|
this->CastAndCallScalarField(this->GetFieldFromDataSet(input), resolveType);
|
||||||
input.GetNumberOfPoints());
|
}
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return this->GetFieldFromDataSet(input).GetData();
|
|
||||||
}
|
|
||||||
}();
|
|
||||||
fieldArray.CastAndCallForTypes<
|
|
||||||
vtkm::TypeListFieldScalar,
|
|
||||||
vtkm::ListAppend<VTKM_DEFAULT_STORAGE_LIST, vtkm::List<vtkm::cont::StorageTagConstant>>>(
|
|
||||||
resolveType);
|
|
||||||
|
|
||||||
// Deposition of the input field to the output field is already mapping. No need to map other
|
|
||||||
// fields.
|
|
||||||
return uniform;
|
return uniform;
|
||||||
}
|
}
|
||||||
} // namespace density_estimate
|
} // namespace density_estimate
|
||||||
|
@ -95,25 +95,15 @@ VTKM_CONT vtkm::cont::DataSet ParticleDensityNearestGridPoint::DoExecute(
|
|||||||
uniform.AddField(vtkm::cont::make_FieldCell("density", density));
|
uniform.AddField(vtkm::cont::make_FieldCell("density", density));
|
||||||
};
|
};
|
||||||
|
|
||||||
// Note: This is the so called Immediately-Invoked Function Expression (IIFE). Here we define
|
if (this->ComputeNumberDensity)
|
||||||
// a lambda expression and immediately call it at the end. This allows us to not declare an
|
{
|
||||||
// UnknownArrayHandle first and then assign it in the if-else statement. If I really want to
|
resolveType(
|
||||||
// show-off, I can even inline the `fieldArray` variable and turn it into a long expression.
|
vtkm::cont::make_ArrayHandleConstant(vtkm::FloatDefault{ 1 }, input.GetNumberOfPoints()));
|
||||||
auto fieldArray = [&]() -> vtkm::cont::UnknownArrayHandle {
|
}
|
||||||
if (this->ComputeNumberDensity)
|
else
|
||||||
{
|
{
|
||||||
return vtkm::cont::make_ArrayHandleConstant(vtkm::FloatDefault{ 1 },
|
this->CastAndCallScalarField(this->GetFieldFromDataSet(input), resolveType);
|
||||||
input.GetNumberOfPoints());
|
}
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return this->GetFieldFromDataSet(input).GetData();
|
|
||||||
}
|
|
||||||
}();
|
|
||||||
fieldArray.CastAndCallForTypes<
|
|
||||||
vtkm::TypeListFieldScalar,
|
|
||||||
vtkm::ListAppend<VTKM_DEFAULT_STORAGE_LIST, vtkm::List<vtkm::cont::StorageTagConstant>>>(
|
|
||||||
resolveType);
|
|
||||||
|
|
||||||
// Deposition of the input field to the output field is already mapping. No need to map other
|
// Deposition of the input field to the output field is already mapping. No need to map other
|
||||||
// fields.
|
// fields.
|
||||||
|
Loading…
Reference in New Issue
Block a user