mirror of
https://gitlab.kitware.com/vtk/vtk-m
synced 2024-09-16 17:22:55 +00:00
Back out of DataSet::CopyPartsFromExcept method
This method is too unwieldy. Instead go back to `CopyStructure` and other direct copy methods.
This commit is contained in:
parent
2d30e6d45a
commit
4ca64f0f09
@ -235,42 +235,27 @@ void DataSet::SetGhostCellField(const vtkm::cont::UnknownArrayHandle& field)
|
||||
this->SetGhostCellField(GetGlobalGhostCellFieldName(), field);
|
||||
}
|
||||
|
||||
void DataSet::CopyPartsFromExcept(const vtkm::cont::DataSet& source,
|
||||
vtkm::cont::DataSet::Parts partMask)
|
||||
void DataSet::CopyStructure(const vtkm::cont::DataSet& source)
|
||||
{
|
||||
if ((partMask & vtkm::cont::DataSet::Parts::CellSet) == vtkm::cont::DataSet::Parts::None)
|
||||
// Copy the cells.
|
||||
this->CellSet = source.CellSet;
|
||||
|
||||
// Copy the coordinate systems.
|
||||
this->CoordSystemNames.clear();
|
||||
vtkm::IdComponent numCoords = source.GetNumberOfCoordinateSystems();
|
||||
for (vtkm::IdComponent coordIndex = 0; coordIndex < numCoords; ++coordIndex)
|
||||
{
|
||||
this->CellSet = source.CellSet;
|
||||
}
|
||||
if ((partMask & vtkm::cont::DataSet::Parts::GhostCellName) == vtkm::cont::DataSet::Parts::None)
|
||||
{
|
||||
this->GhostCellName = source.GhostCellName;
|
||||
this->AddCoordinateSystem(source.GetCoordinateSystem(coordIndex));
|
||||
}
|
||||
|
||||
if ((partMask & vtkm::cont::DataSet::Parts::Fields) == vtkm::cont::DataSet::Parts::None)
|
||||
// Copy the ghost cells.
|
||||
// Note that we copy the GhostCellName separately from the field it points to
|
||||
// to preserve (or remove) the case where the ghost cell name follows the
|
||||
// global ghost cell name.
|
||||
this->GhostCellName = source.GhostCellName;
|
||||
if (source.HasGhostCellField())
|
||||
{
|
||||
vtkm::IdComponent numFields = source.GetNumberOfFields();
|
||||
for (vtkm::IdComponent fIndex = 0; fIndex < numFields; ++fIndex)
|
||||
{
|
||||
this->AddField(source.GetField(fIndex));
|
||||
}
|
||||
}
|
||||
|
||||
if ((partMask & vtkm::cont::DataSet::Parts::Coordinates) == vtkm::cont::DataSet::Parts::None)
|
||||
{
|
||||
vtkm::IdComponent numCoords = source.GetNumberOfCoordinateSystems();
|
||||
for (vtkm::IdComponent cIndex = 0; cIndex < numCoords; ++cIndex)
|
||||
{
|
||||
std::string coordName = source.GetCoordinateSystemName(cIndex);
|
||||
if (this->HasPointField(coordName))
|
||||
{
|
||||
this->AddCoordinateSystem(coordName);
|
||||
}
|
||||
else
|
||||
{
|
||||
this->AddCoordinateSystem(source.GetCoordinateSystem(cIndex));
|
||||
}
|
||||
}
|
||||
this->AddField(source.GetGhostCellField());
|
||||
}
|
||||
|
||||
CheckFieldSizes(this->CellSet, this->Fields);
|
||||
|
@ -44,19 +44,6 @@ public:
|
||||
|
||||
vtkm::cont::DataSet& operator=(const vtkm::cont::DataSet&) = default;
|
||||
|
||||
/// \brief An enumeration that can be used to refer to the parts of a `DataSet`.
|
||||
///
|
||||
/// The items can be or'ed together (`|`) to refer to multiple parts.
|
||||
enum struct Parts : vtkm::UInt32
|
||||
{
|
||||
None = 0x00,
|
||||
CellSet = 0x01,
|
||||
Fields = 0x02,
|
||||
Coordinates = 0x04,
|
||||
GhostCellName = 0x08,
|
||||
All = 0xFF
|
||||
};
|
||||
|
||||
VTKM_CONT void Clear();
|
||||
|
||||
/// Get the number of cells contained in this DataSet
|
||||
@ -332,32 +319,11 @@ public:
|
||||
return static_cast<vtkm::IdComponent>(this->CoordSystemNames.size());
|
||||
}
|
||||
|
||||
/// Copies the structure i.e. coordinates systems and cellset from the source
|
||||
/// dataset. The fields are left unchanged.
|
||||
VTKM_DEPRECATED(2.0, "Use CopyPartsFromExcept(source, vtkm::cont::DataSet::Parts::Fields)")
|
||||
/// Copies the structure from the source dataset. The structure includes the cellset,
|
||||
/// the coordinate systems, and any ghost layer information. The fields that are not
|
||||
/// part of a coordinate system or ghost layers are left unchanged.
|
||||
VTKM_CONT
|
||||
void CopyStructure(const vtkm::cont::DataSet& source)
|
||||
{
|
||||
this->CopyPartsFromExcept(source, vtkm::cont::DataSet::Parts::Fields);
|
||||
}
|
||||
|
||||
/// \brief Copy parts from a source data set.
|
||||
///
|
||||
/// Data from the `source` `DataSet` are copied into this `DataSet`. Where possible,
|
||||
/// parts like `Field`s and `CoordinateSystem`s from the source are added. Parts that
|
||||
/// only have one instance in the `DataSet`, such as the `CellSet`, are replaced.
|
||||
///
|
||||
/// By default, all parts are copied. A `partMask` is provided that
|
||||
/// specifies which parts _not_ to copy. For example, to copy only the structure
|
||||
/// but not any of the fields, specify to not copy the fields or coordinates as so.
|
||||
///
|
||||
/// ```cpp
|
||||
/// dest.CopyPartsFromExcept(
|
||||
/// src, vtkm::cont::DataSet::Parts::Fields | vtkm::cont::DataSet::Parts::Coordinates);
|
||||
/// ```
|
||||
///
|
||||
VTKM_CONT
|
||||
void CopyPartsFromExcept(const vtkm::cont::DataSet& source, vtkm::cont::DataSet::Parts partMask);
|
||||
void CopyStructure(const vtkm::cont::DataSet& source);
|
||||
|
||||
/// \brief Convert the structures in this data set to expected types.
|
||||
///
|
||||
@ -389,20 +355,6 @@ private:
|
||||
VTKM_CONT void SetCellSetImpl(const vtkm::cont::UnknownCellSet& cellSet);
|
||||
};
|
||||
|
||||
VTKM_CONT inline vtkm::cont::DataSet::Parts operator|(vtkm::cont::DataSet::Parts lhs,
|
||||
vtkm::cont::DataSet::Parts rhs)
|
||||
{
|
||||
using T = std::underlying_type_t<vtkm::cont::DataSet::Parts>;
|
||||
return static_cast<vtkm::cont::DataSet::Parts>(static_cast<T>(lhs) | static_cast<T>(rhs));
|
||||
}
|
||||
|
||||
VTKM_CONT inline vtkm::cont::DataSet::Parts operator&(vtkm::cont::DataSet::Parts lhs,
|
||||
vtkm::cont::DataSet::Parts rhs)
|
||||
{
|
||||
using T = std::underlying_type_t<vtkm::cont::DataSet::Parts>;
|
||||
return static_cast<vtkm::cont::DataSet::Parts>(static_cast<T>(lhs) & static_cast<T>(rhs));
|
||||
}
|
||||
|
||||
} // namespace cont
|
||||
} // namespace vtkm
|
||||
|
||||
|
@ -108,16 +108,10 @@ vtkm::cont::PartitionedDataSet NewFilter::Execute(const vtkm::cont::PartitionedD
|
||||
|
||||
vtkm::cont::DataSet NewFilter::CreateResult(const vtkm::cont::DataSet& inDataSet) const
|
||||
{
|
||||
vtkm::cont::DataSet clone;
|
||||
clone.CopyPartsFromExcept(
|
||||
inDataSet, vtkm::cont::DataSet::Parts::Fields | vtkm::cont::DataSet::Parts::Coordinates);
|
||||
this->MapFieldsOntoOutput(inDataSet,
|
||||
this->GetFieldsToPass(),
|
||||
clone,
|
||||
[](vtkm::cont::DataSet& out, const vtkm::cont::Field& fieldToPass) {
|
||||
out.AddField(fieldToPass);
|
||||
});
|
||||
return clone;
|
||||
auto fieldMapper = [](vtkm::cont::DataSet& out, const vtkm::cont::Field& fieldToPass) {
|
||||
out.AddField(fieldToPass);
|
||||
};
|
||||
return this->CreateResult(inDataSet, inDataSet.GetCellSet(), fieldMapper);
|
||||
}
|
||||
|
||||
vtkm::cont::PartitionedDataSet NewFilter::CreateResult(
|
||||
|
@ -407,10 +407,6 @@ protected:
|
||||
FieldMapper&& fieldMapper) const
|
||||
{
|
||||
vtkm::cont::DataSet outDataSet;
|
||||
outDataSet.CopyPartsFromExcept(inDataSet,
|
||||
vtkm::cont::DataSet::Parts::Fields |
|
||||
vtkm::cont::DataSet::Parts::Coordinates |
|
||||
vtkm::cont::DataSet::Parts::CellSet);
|
||||
outDataSet.SetCellSet(resultCellSet);
|
||||
this->MapFieldsOntoOutput(inDataSet, this->GetFieldsToPass(), outDataSet, fieldMapper);
|
||||
return outDataSet;
|
||||
@ -480,10 +476,6 @@ protected:
|
||||
FieldMapper&& fieldMapper) const
|
||||
{
|
||||
vtkm::cont::DataSet outDataSet;
|
||||
outDataSet.CopyPartsFromExcept(inDataSet,
|
||||
vtkm::cont::DataSet::Parts::Fields |
|
||||
vtkm::cont::DataSet::Parts::Coordinates |
|
||||
vtkm::cont::DataSet::Parts::CellSet);
|
||||
outDataSet.SetCellSet(resultCellSet);
|
||||
outDataSet.AddCoordinateSystem(resultCoordSystem);
|
||||
vtkm::filter::FieldSelection fieldSelection = this->GetFieldsToPass();
|
||||
@ -519,6 +511,7 @@ private:
|
||||
vtkm::cont::DataSet& output,
|
||||
FieldMapper&& fieldMapper) const
|
||||
{
|
||||
// Basic field mapping
|
||||
for (vtkm::IdComponent cc = 0; cc < input.GetNumberOfFields(); ++cc)
|
||||
{
|
||||
auto field = input.GetField(cc);
|
||||
@ -528,13 +521,22 @@ private:
|
||||
}
|
||||
}
|
||||
|
||||
// Check if the ghost levels have been copied. If so, set so on the output.
|
||||
if (input.HasGhostCellField())
|
||||
{
|
||||
const std::string& ghostFieldName = input.GetGhostCellFieldName();
|
||||
if (output.HasCellField(ghostFieldName) && (output.GetGhostCellFieldName() != ghostFieldName))
|
||||
{
|
||||
output.SetGhostCellFieldName(ghostFieldName);
|
||||
}
|
||||
}
|
||||
|
||||
for (vtkm::IdComponent csIndex = 0; csIndex < input.GetNumberOfCoordinateSystems(); ++csIndex)
|
||||
{
|
||||
auto coords = input.GetCoordinateSystem(csIndex);
|
||||
if (!output.HasCoordinateSystem(coords.GetName()))
|
||||
{
|
||||
if (!output.HasPointField(coords.GetName()) &&
|
||||
(this->GetPassCoordinateSystems() || this->GetFieldsToPass().IsFieldSelected(coords)))
|
||||
if (!output.HasPointField(coords.GetName()) && this->GetPassCoordinateSystems())
|
||||
{
|
||||
fieldMapper(output, coords);
|
||||
}
|
||||
|
@ -26,7 +26,7 @@ public:
|
||||
void SetGeometry(const vtkm::cont::DataSet& geometry)
|
||||
{
|
||||
this->Geometry = vtkm::cont::DataSet();
|
||||
this->Geometry.CopyPartsFromExcept(geometry, vtkm::cont::DataSet::Parts::Fields);
|
||||
this->Geometry.CopyStructure(geometry);
|
||||
}
|
||||
|
||||
VTKM_CONT
|
||||
|
Loading…
Reference in New Issue
Block a user