Skip to content
Snippets Groups Projects
Commit af303ddd authored by David Thompson's avatar David Thompson
Browse files

Add an option to cell-grid copy-query.

This way, cells can be skipped while cell-attributes are copied.
parent 20fed67d
No related merge requests found
......@@ -260,6 +260,11 @@ vtkCellAttribute* vtkCellGridCopyQuery::CopyOrUpdateAttributeRecord(
targetAttribute = amit->second;
}
if (!this->CopyCellTypes)
{
return targetAttribute;
}
// Regardless of whether the attribute pre-existed or not,
// add arrays for each cell type.
auto oldCellTypeInfo = srcAtt->GetCellTypeInfo(cellType);
......
......@@ -135,6 +135,14 @@ public:
///@name CopySetup Copy Style Setup.
///@{
/// Set/get whether to copy cell metadata instances
/// or leave target grid void of all cell types.
///
/// The default (true) is to copy cell types.
vtkGetMacro(CopyCellTypes, int);
vtkSetMacro(CopyCellTypes, int);
vtkBooleanMacro(CopyCellTypes, int);
/// Set/get whether to copy cell topology or leave each output instance
/// of cell metadata uninitialized.
///
......@@ -300,6 +308,7 @@ protected:
std::set<int> CellAttributeIds;
std::map<vtkAbstractArray*, vtkAbstractArray*> ArrayMap;
std::map<vtkCellAttribute*, vtkCellAttribute*> AttributeMap;
int CopyCellTypes{ 1 };
int CopyCells{ 1 };
int CopyOnlyShape{ 1 };
int CopyArrays{ 1 };
......
......@@ -80,32 +80,37 @@ bool vtkDGCopyResponder::Query(
vtkStringToken cellTypeName = cellType->GetClassName();
auto* sourceMetadata = vtkDGCell::SafeDownCast(query->GetSource()->GetCellType(cellTypeName));
auto targetMetadataBase = vtkCellMetadata::NewInstance(cellTypeName, query->GetTarget());
auto* targetMetadata = vtkDGCell::SafeDownCast(targetMetadataBase);
if (!sourceMetadata || !targetMetadata)
vtkDGCell* targetMetadata = nullptr;
if (query->GetCopyCellTypes())
{
vtkErrorMacro("Cannot copy non-DG cell with DG responder.");
return false;
}
auto targetMetadataBase = vtkCellMetadata::NewInstance(cellTypeName, query->GetTarget());
targetMetadata = vtkDGCell::SafeDownCast(targetMetadataBase);
// If we are copying cells, then ensure the connectivity is copied.
// If we are copying cells but not values, this will create an empty connectivity array.
this->CopySpecs(query, sourceMetadata, targetMetadata);
if (!sourceMetadata || !targetMetadata)
{
vtkErrorMacro("Cannot copy non-DG cell with DG responder.");
return false;
}
// Now, copy the arrays for any cell-attributes we are copying and then
// copy the cell-attribute (or at least update its arrays for the current cell-type).
if (query->GetCopyOnlyShape())
{
query->CopyAttributeArrays(query->GetSource()->GetShapeAttribute(), cellTypeName);
}
else
{
for (const auto& attId : query->GetCellAttributeIds())
// If we are copying cells, then ensure the connectivity is copied.
// If we are copying cells but not values, this will create an empty connectivity array.
this->CopySpecs(query, sourceMetadata, targetMetadata);
// Now, copy the arrays for any cell-attributes we are copying and then
// copy the cell-attribute (or at least update its arrays for the current cell-type).
if (query->GetCopyOnlyShape())
{
if (auto* cellAtt = query->GetSource()->GetCellAttributeById(attId))
query->CopyAttributeArrays(query->GetSource()->GetShapeAttribute(), cellTypeName);
}
else
{
for (const auto& attId : query->GetCellAttributeIds())
{
query->CopyAttributeArrays(cellAtt, cellTypeName);
if (auto* cellAtt = query->GetSource()->GetCellAttributeById(attId))
{
query->CopyAttributeArrays(cellAtt, cellTypeName);
}
}
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment