mirror of
https://gitlab.kitware.com/vtk/vtk-m
synced 2024-09-08 21:33:55 +00:00
Address comments from Ken, Ollie.
This commit is contained in:
parent
71c6f034d9
commit
00b6657689
@ -144,7 +144,7 @@ void PartitionedDataSet::ReplacePartition(vtkm::Id index, const vtkm::cont::Data
|
||||
}
|
||||
|
||||
VTKM_CONT
|
||||
void PartitionedDataSet::CopyStructure(const vtkm::cont::PartitionedDataSet& source)
|
||||
void PartitionedDataSet::CopyPartitions(const vtkm::cont::PartitionedDataSet& source)
|
||||
{
|
||||
this->Partitions = source.Partitions;
|
||||
}
|
||||
|
@ -218,9 +218,9 @@ public:
|
||||
}
|
||||
//@}
|
||||
|
||||
/// Copies the structure i.e. partitions from the source. The fields are left unchanged.
|
||||
/// Copies the partitions from the source. The fields on the PartitionedDataSet are not copied.
|
||||
VTKM_CONT
|
||||
void CopyStructure(const vtkm::cont::PartitionedDataSet& source);
|
||||
void CopyPartitions(const vtkm::cont::PartitionedDataSet& source);
|
||||
|
||||
VTKM_CONT
|
||||
void PrintSummary(std::ostream& stream) const;
|
||||
|
@ -119,10 +119,10 @@ vtkm::cont::DataSet NewFilter::CreateResult(const vtkm::cont::DataSet& inDataSet
|
||||
|
||||
vtkm::cont::PartitionedDataSet NewFilter::CreateResult(
|
||||
const vtkm::cont::PartitionedDataSet& input,
|
||||
const vtkm::cont::PartitionedDataSet& output) const
|
||||
const vtkm::cont::PartitionedDataSet& resultPartitions) const
|
||||
{
|
||||
vtkm::cont::PartitionedDataSet clone;
|
||||
clone.CopyStructure(output);
|
||||
clone.CopyPartitions(resultPartitions);
|
||||
this->MapFieldsOntoOutput(
|
||||
input, clone, [](vtkm::cont::PartitionedDataSet& out, const vtkm::cont::Field& fieldToPass) {
|
||||
out.AddField(fieldToPass);
|
||||
|
@ -326,9 +326,48 @@ protected:
|
||||
/// fields of `inDataSet` (as selected by the `FieldsToPass` state of the filter).
|
||||
///
|
||||
VTKM_CONT vtkm::cont::DataSet CreateResult(const vtkm::cont::DataSet& inDataSet) const;
|
||||
|
||||
|
||||
/// \brief Create the output data set for `DoExecute`.
|
||||
///
|
||||
/// This form of `CreateResult` will create an output PartitionedDataSet with the
|
||||
/// same partitions and pass all PartitionedDataSet fields (as requested by the
|
||||
/// `Filter` state).
|
||||
///
|
||||
/// \param[in] input The input data set being modified (usually the one passed into
|
||||
/// `DoExecute`).
|
||||
/// \param[in] resultPartitions The output data created by the filter. Fields from the input are
|
||||
/// passed onto the return result partition as requested by the `Filter` state.
|
||||
///
|
||||
VTKM_CONT vtkm::cont::PartitionedDataSet CreateResult(
|
||||
const vtkm::cont::PartitionedDataSet& input,
|
||||
const vtkm::cont::PartitionedDataSet& output) const;
|
||||
const vtkm::cont::PartitionedDataSet& resultPartitions) const;
|
||||
|
||||
/// \brief Create the output data set for `DoExecute`.
|
||||
///
|
||||
/// This form of `CreateResult` will create an output PartitionedDataSet with the
|
||||
/// same partitions and pass all PartitionedDataSet fields (as requested by the
|
||||
/// `Filter` state).
|
||||
///
|
||||
/// \param[in] input The input data set being modified (usually the one passed into
|
||||
/// `DoExecute`).
|
||||
/// \param[in] resultPartitions The output data created by the filter. Fields from the input are
|
||||
/// passed onto the return result partition as requested by the `Filter` state.
|
||||
/// \param[in] fieldMapper A function or functor that takes a `PartitionedDataSet` as its first
|
||||
/// argument and a `Field` as its second argument. The `PartitionedDataSet` is the data being
|
||||
/// created and will eventually be returned by `CreateResult`. The `Field` comes from `input`.
|
||||
///
|
||||
|
||||
template <typename FieldMapper>
|
||||
VTKM_CONT vtkm::cont::PartitionedDataSet CreateResult(
|
||||
const vtkm::cont::PartitionedDataSet& input,
|
||||
const vtkm::cont::PartitionedDataSet& resultPartitions,
|
||||
FieldMapper&& fieldMapper) const
|
||||
{
|
||||
vtkm::cont::PartitionedDataSet output(resultPartitions.GetPartitions);
|
||||
this->MapFieldsOntoOutput(input, output, fieldMapper);
|
||||
return output;
|
||||
}
|
||||
|
||||
/// \brief Create the output data set for `DoExecute`.
|
||||
///
|
||||
@ -434,9 +473,9 @@ protected:
|
||||
const vtkm::cont::PartitionedDataSet& inData);
|
||||
|
||||
private:
|
||||
template <typename DataType, typename FieldMapper>
|
||||
VTKM_CONT void MapFieldsOntoOutput(const DataType& input,
|
||||
DataType& output,
|
||||
template <typename DataSetType, typename FieldMapper>
|
||||
VTKM_CONT void MapFieldsOntoOutput(const DataSetType& input,
|
||||
DataSetType& output,
|
||||
FieldMapper&& fieldMapper) const
|
||||
{
|
||||
for (vtkm::IdComponent cc = 0; cc < input.GetNumberOfFields(); ++cc)
|
||||
|
@ -116,6 +116,15 @@ void TestPartitionedDataSetFilters()
|
||||
Result_Verify<vtkm::FloatDefault>(result, cellAverage, partitions, std::string("pointvar"));
|
||||
|
||||
//Make sure that any Fields are propagated to the output.
|
||||
//Test it with and without using SetFieldsToPass
|
||||
std::vector<std::vector<std::string>> fieldsToPass;
|
||||
fieldsToPass.push_back({});
|
||||
fieldsToPass.push_back({ "ids" });
|
||||
fieldsToPass.push_back({ "scalar" });
|
||||
fieldsToPass.push_back({ "ids", "scalar" });
|
||||
|
||||
for (auto& fields : fieldsToPass)
|
||||
{
|
||||
partitionNum = 3;
|
||||
partitions = PartitionedDataSetBuilder<vtkm::FloatDefault>(partitionNum, "pointvar");
|
||||
std::vector<vtkm::Id> ids = { 0, 1, 2 };
|
||||
@ -123,16 +132,35 @@ void TestPartitionedDataSetFilters()
|
||||
partitions.AddPartitionsField("ids", ids);
|
||||
partitions.AddAllPartitionsField("scalar", scalar);
|
||||
|
||||
//On second iteration, only allow "ids" to pass through.
|
||||
cellAverage.GetFieldsToPass().ClearFields();
|
||||
if (!fields.empty())
|
||||
{
|
||||
cellAverage.GetFieldsToPass().SetMode(vtkm::filter::FieldSelection::Mode::Select);
|
||||
for (auto& f : fields)
|
||||
cellAverage.GetFieldsToPass().AddField(f);
|
||||
}
|
||||
|
||||
result = cellAverage.Execute(partitions);
|
||||
|
||||
if (fields.empty() || std::find(fields.begin(), fields.end(), "ids") != fields.end())
|
||||
{
|
||||
VTKM_TEST_ASSERT(result.HasPartitionsField("ids"), "Missing field on result");
|
||||
auto field0 = result.GetField("ids");
|
||||
auto portal0 = field0.GetData().AsArrayHandle<vtkm::cont::ArrayHandle<vtkm::Id>>().ReadPortal();
|
||||
auto portal0 =
|
||||
field0.GetData().AsArrayHandle<vtkm::cont::ArrayHandle<vtkm::Id>>().ReadPortal();
|
||||
VTKM_TEST_ASSERT(portal0.GetNumberOfValues() == static_cast<vtkm::Id>(ids.size()),
|
||||
"Wrong number of field values.");
|
||||
for (std::size_t i = 0; i < ids.size(); i++)
|
||||
VTKM_TEST_ASSERT(portal0.Get(static_cast<vtkm::Id>(i)) == ids[i], "Wrong field value.");
|
||||
}
|
||||
else
|
||||
{
|
||||
VTKM_TEST_ASSERT(!result.HasPartitionsField("ids"), "Field should not be on result");
|
||||
}
|
||||
|
||||
if (fields.empty() || std::find(fields.begin(), fields.end(), "scalar") != fields.end())
|
||||
{
|
||||
VTKM_TEST_ASSERT(result.HasAllPartitionsField("scalar"), "Missing field on result");
|
||||
auto field1 = result.GetField("scalar");
|
||||
auto portal1 =
|
||||
@ -141,6 +169,12 @@ void TestPartitionedDataSetFilters()
|
||||
"Wrong number of field values.");
|
||||
VTKM_TEST_ASSERT(portal1.Get(0) == scalar[0], "Wrong field value.");
|
||||
}
|
||||
else
|
||||
{
|
||||
VTKM_TEST_ASSERT(!result.HasAllPartitionsField("scalar"), "Field should not be on result");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int UnitTestPartitionedDataSetFilters(int argc, char* argv[])
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user